AAPT2: Fix windows unicode path issues

Mingw64 was being difficult, so instead of defining a wmain entrypoint,
the command line parameters are parsed manually using built-in Windows
methods that support Unicode. The results are converted to UTF8 and
handled just like the rest of the linux/mac version of the code.

This also removes dependencies on std::istream in favour of a
FileInputStream which calls the appropriate unicode version of
open to read a file.

No speed regressions found on Linux or MacOS.

Bug: 62336414
Bug: 63830502
Test: manual
Change-Id: I597da51e33729ed1b98bf246e7e773337fd3fee8
diff --git a/tools/aapt2/flatten/Archive.cpp b/tools/aapt2/flatten/Archive.cpp
index 826f91b..5f8bd06 100644
--- a/tools/aapt2/flatten/Archive.cpp
+++ b/tools/aapt2/flatten/Archive.cpp
@@ -23,12 +23,14 @@
 
 #include "android-base/errors.h"
 #include "android-base/macros.h"
+#include "android-base/utf8.h"
 #include "androidfw/StringPiece.h"
 #include "ziparchive/zip_writer.h"
 
 #include "util/Files.h"
 
-using android::StringPiece;
+using ::android::StringPiece;
+using ::android::base::SystemErrorCodeToString;
 
 namespace aapt {
 
@@ -58,11 +60,11 @@
 
     std::string full_path = dir_;
     file::AppendPath(&full_path, path);
-    file::mkdirs(file::GetStem(full_path));
+    file::mkdirs(file::GetStem(full_path).to_string());
 
-    file_ = {fopen(full_path.data(), "wb"), fclose};
+    file_ = {::android::base::utf8::fopen(full_path.c_str(), "wb"), fclose};
     if (!file_) {
-      error_ = android::base::SystemErrorCodeToString(errno);
+      error_ = SystemErrorCodeToString(errno);
       return false;
     }
     return true;
@@ -74,7 +76,7 @@
     }
 
     if (fwrite(data, 1, len, file_.get()) != static_cast<size_t>(len)) {
-      error_ = android::base::SystemErrorCodeToString(errno);
+      error_ = SystemErrorCodeToString(errno);
       file_.reset(nullptr);
       return false;
     }
@@ -121,9 +123,9 @@
   ZipFileWriter() = default;
 
   bool Open(const StringPiece& path) {
-    file_ = {fopen(path.data(), "w+b"), fclose};
+    file_ = {::android::base::utf8::fopen(path.to_string().c_str(), "w+b"), fclose};
     if (!file_) {
-      error_ = android::base::SystemErrorCodeToString(errno);
+      error_ = SystemErrorCodeToString(errno);
       return false;
     }
     writer_ = util::make_unique<ZipWriter>(file_.get());