Skip to content

Commit e239450

Browse files
authored
On Windows desktop, use wide path strings in Remote Config. (#1316)
* On Windows desktop, use wide path strings in Remote Config. * Move header to below platform.h. * Format code. * On desktop, move Remote Config data into the AppDataDir instead of the current directory. * Remove extraneous forward reference. * Format code. * For debugging, add an international path to Windows runs. * Fix Mkdir. * Clean up data directory and make suffix optional. * Fix usage of AppDataDir without app name. * Slash. * Re-add app data prefix. * Change / to . * Fix include. * Fix string. * Fix string usage * Remove temporary international directory for testing. * Add international characters to path. * Format code.
1 parent a395148 commit e239450

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

app/src/filesystem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <string>
2121

2222
namespace firebase {
23-
2423
/**
2524
* Returns a system-defined best directory in which to create application
2625
* data. Values vary wildly across platforms. They include:

remote_config/src/desktop/file_manager.cc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,33 @@
2121
#include <string>
2222
#include <utility>
2323

24+
#include "app/src/filesystem.h"
25+
#include "app/src/include/firebase/internal/platform.h"
2426
#include "remote_config/src/desktop/config_data.h"
2527

28+
#if FIREBASE_PLATFORM_WINDOWS
29+
#include <codecvt>
30+
#include <locale>
31+
#endif
32+
2633
namespace firebase {
2734
namespace remote_config {
2835
namespace internal {
2936

30-
RemoteConfigFileManager::RemoteConfigFileManager(const std::string& file_path)
31-
: file_path_(file_path) {}
37+
RemoteConfigFileManager::RemoteConfigFileManager(const std::string& filename,
38+
const firebase::App& app) {
39+
std::string app_data_prefix = std::string(app.options().package_name()) +
40+
"/" + app.name() + "/" + "TẽstPạth";
41+
std::string file_path =
42+
AppDataDir(app_data_prefix.c_str(), /*should_create=*/true) + "/" +
43+
filename;
44+
#if FIREBASE_PLATFORM_WINDOWS
45+
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_to_wstring;
46+
file_path_ = utf8_to_wstring.from_bytes(file_path);
47+
#else
48+
file_path_ = file_path;
49+
#endif
50+
}
3251

3352
bool RemoteConfigFileManager::Load(LayeredConfigs* configs) const {
3453
std::fstream input(file_path_, std::ios::in | std::ios::binary);

remote_config/src/desktop/file_manager.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <string>
1919

20+
#include "app/src/include/firebase/app.h"
21+
#include "app/src/include/firebase/internal/platform.h"
2022
#include "remote_config/src/desktop/config_data.h"
2123

2224
namespace firebase {
@@ -27,7 +29,8 @@ namespace internal {
2729
// load from file.
2830
class RemoteConfigFileManager {
2931
public:
30-
explicit RemoteConfigFileManager(const std::string& file_path);
32+
RemoteConfigFileManager(const std::string& file_path,
33+
const firebase::App& app);
3134

3235
// Load `configs` from file. Will return `true` if success.
3336
bool Load(LayeredConfigs* configs) const;
@@ -36,8 +39,12 @@ class RemoteConfigFileManager {
3639
bool Save(const LayeredConfigs& configs) const;
3740

3841
private:
39-
// Path to file with data.
42+
// Path to file with data. On Windows, use a UTF-16 path string.
43+
#if FIREBASE_PLATFORM_WINDOWS
44+
std::wstring file_path_;
45+
#else
4046
std::string file_path_;
47+
#endif
4148
};
4249

4350
} // namespace internal

remote_config/src/desktop/remote_config_desktop.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <vector>
2626

2727
#include "app/src/callback.h"
28+
#include "app/src/include/firebase/internal/platform.h"
2829
#include "app/src/time.h"
2930
#include "remote_config/src/common.h"
3031
#include "remote_config/src/include/firebase/remote_config.h"
@@ -78,7 +79,7 @@ RemoteConfigInternal::RemoteConfigInternal(
7879

7980
RemoteConfigInternal::RemoteConfigInternal(const firebase::App& app)
8081
: app_(app),
81-
file_manager_(kFilePathSuffix),
82+
file_manager_(kFilePathSuffix, app),
8283
is_fetch_process_have_task_(false),
8384
future_impl_(kRemoteConfigFnCount),
8485
safe_this_(this),

0 commit comments

Comments
 (0)