|
15 | 15 | #include "app_check/src/desktop/debug_provider_desktop.h" |
16 | 16 |
|
17 | 17 | #include <cerrno> |
| 18 | +#include <codecvt> |
18 | 19 | #include <cstdint> |
19 | 20 | #include <cstdio> |
20 | 21 | #include <cstdlib> |
21 | 22 | #include <fstream> |
22 | 23 | #include <iterator> |
| 24 | +#include <locale> |
23 | 25 | #include <map> |
24 | 26 | #include <memory> |
25 | 27 | #include <string> |
@@ -60,9 +62,23 @@ std::string GenerateUuidString() { |
60 | 62 | return std::string(uuid_str); |
61 | 63 | } |
62 | 64 |
|
| 65 | +#if FIREBASE_PLATFORM_WINDOWS |
| 66 | +// Windows paths can contain characters outside the ANSI code page, so the |
| 67 | +// environment is read and files are opened through the UTF-16 APIs. A failed |
| 68 | +// conversion yields an empty string instead of throwing. |
| 69 | +using Utf8Utf16Converter = |
| 70 | + std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>>; |
| 71 | +#endif // FIREBASE_PLATFORM_WINDOWS |
| 72 | + |
63 | 73 | std::string GetNonEmptyEnv(const char* name) { |
| 74 | +#if FIREBASE_PLATFORM_WINDOWS |
| 75 | + Utf8Utf16Converter converter("", L""); |
| 76 | + const wchar_t* val = _wgetenv(converter.from_bytes(name).c_str()); |
| 77 | + return val != nullptr ? converter.to_bytes(val) : ""; |
| 78 | +#else |
64 | 79 | const char* val = std::getenv(name); |
65 | 80 | return val != nullptr ? std::string(val) : ""; |
| 81 | +#endif // FIREBASE_PLATFORM_WINDOWS |
66 | 82 | } |
67 | 83 |
|
68 | 84 | std::vector<std::string> ResolveConfigstorePaths() { |
@@ -93,7 +109,12 @@ std::string ResolveDebugTokenFromConfig(const std::string& config_path, |
93 | 109 | const std::string& app_id) { |
94 | 110 | if (config_path.empty() || app_id.empty()) return ""; |
95 | 111 | errno = 0; |
| 112 | +#if FIREBASE_PLATFORM_WINDOWS |
| 113 | + std::ifstream infile(Utf8Utf16Converter("", L"").from_bytes(config_path), |
| 114 | + std::ios::binary); |
| 115 | +#else |
96 | 116 | std::ifstream infile(config_path.c_str(), std::ios::binary); |
| 117 | +#endif // FIREBASE_PLATFORM_WINDOWS |
97 | 118 | if (!infile.is_open()) { |
98 | 119 | // ENOENT (file not created yet) stays silent so apps not using the CLI |
99 | 120 | // flow do not log errors; other I/O failures are surfaced. |
|
0 commit comments