get_prefs_file -> get_synced_prefs_file

This commit is contained in:
pentarctagon 2024-07-04 11:50:32 -05:00 committed by Pentarctagon
parent 3f3c7628e8
commit a6a27ef947
5 changed files with 23 additions and 19 deletions

View file

@ -652,8 +652,8 @@ static void setup_user_data_dir()
create_directory_if_missing(get_wml_persist_dir());
create_directory_if_missing(get_logs_dir());
if(file_exists(get_unsynced_prefs_file()) && !file_exists(get_prefs_file())) {
copy_file(get_unsynced_prefs_file(), get_prefs_file());
if(file_exists(get_unsynced_prefs_file()) && !file_exists(get_synced_prefs_file())) {
copy_file(get_unsynced_prefs_file(), get_synced_prefs_file());
}
lg::move_log_file();

View file

@ -134,8 +134,12 @@ void get_files_in_dir(const std::string &dir,
std::string get_dir(const std::string &dir);
// The location of various important files/folders:
std::string get_prefs_file();
/** location of preferences file before it was moved to the sync directory */
/**
* location of preferences file containing preferences that are synced between computers
* note that wesnoth does not provide the syncing functionality itself
*/
std::string get_synced_prefs_file();
/** location of preferences file containing preferences that aren't synced between computers */
std::string get_unsynced_prefs_file();
std::string get_credentials_file();
std::string get_default_prefs_file();

View file

@ -122,7 +122,7 @@ bool blacklist_pattern_list::match_dir(const std::string& name) const
std::bind(&utils::wildcard_string_match, std::ref(name), std::placeholders::_1));
}
std::string get_prefs_file()
std::string get_synced_prefs_file()
{
return get_sync_dir() + "/preferences";
}

View file

@ -92,8 +92,8 @@ void migrate_version_selection::post_show(window& window)
std::string migrate_addons_dir
= boost::replace_all_copy(filesystem::get_addons_dir(), current_version_str, selected);
std::string migrate_prefs_file
= boost::replace_all_copy(filesystem::get_prefs_file(), current_version_str, selected);
std::string migrate_synced_prefs_file
= boost::replace_all_copy(filesystem::get_synced_prefs_file(), current_version_str, selected);
std::string migrate_unsynced_prefs_file
= boost::replace_all_copy(filesystem::get_unsynced_prefs_file(), current_version_str, selected);
std::string migrate_credentials_file
@ -135,7 +135,7 @@ void migrate_version_selection::post_show(window& window)
#endif
{
prefs::get().migrate_preferences(migrate_unsynced_prefs_file);
prefs::get().migrate_preferences(migrate_prefs_file);
prefs::get().migrate_preferences(migrate_synced_prefs_file);
migrate_credentials(migrate_credentials_file);
}

View file

@ -182,21 +182,21 @@ void prefs::load_advanced_prefs(const game_config_view& gc)
void prefs::migrate_preferences(const std::string& migrate_prefs_file)
{
if(migrate_prefs_file != filesystem::get_prefs_file() && filesystem::file_exists(migrate_prefs_file)) {
if(migrate_prefs_file != filesystem::get_synced_prefs_file() && filesystem::file_exists(migrate_prefs_file)) {
// if the file doesn't exist, just copy the file over
// else need to merge the preferences file
if(!filesystem::file_exists(filesystem::get_prefs_file())) {
filesystem::copy_file(migrate_prefs_file, filesystem::get_prefs_file());
if(!filesystem::file_exists(filesystem::get_synced_prefs_file())) {
filesystem::copy_file(migrate_prefs_file, filesystem::get_synced_prefs_file());
} else {
config current_cfg;
filesystem::scoped_istream current_stream = filesystem::istream_file(filesystem::get_prefs_file(), false);
filesystem::scoped_istream current_stream = filesystem::istream_file(filesystem::get_synced_prefs_file(), false);
read(current_cfg, *current_stream);
config old_cfg;
filesystem::scoped_istream old_stream = filesystem::istream_file(migrate_prefs_file, false);
read(old_cfg, *old_stream);
// when both files have the same attribute, use the one from whichever was most recently modified
bool current_prefs_are_older = filesystem::file_modified_time(filesystem::get_prefs_file()) < filesystem::file_modified_time(migrate_prefs_file);
bool current_prefs_are_older = filesystem::file_modified_time(filesystem::get_synced_prefs_file()) < filesystem::file_modified_time(migrate_prefs_file);
for(const config::attribute& val : old_cfg.attribute_range()) {
if(current_prefs_are_older || !current_cfg.has_attribute(val.first)) {
preferences_[val.first] = val.second;
@ -253,7 +253,7 @@ void prefs::load_preferences()
}
{
filesystem::scoped_istream stream = filesystem::istream_file(filesystem::get_prefs_file(), false);
filesystem::scoped_istream stream = filesystem::istream_file(filesystem::get_synced_prefs_file(), false);
read(synced_prefs, *stream);
}
@ -337,7 +337,7 @@ void prefs::load_preferences()
void prefs::write_preferences()
{
#ifndef _WIN32
bool synced_prefs_file_existed = filesystem::file_exists(filesystem::get_prefs_file());
bool synced_prefs_file_existed = filesystem::file_exists(filesystem::get_synced_prefs_file());
bool unsynced_prefs_file_existed = filesystem::file_exists(filesystem::get_unsynced_prefs_file());
#endif
@ -386,10 +386,10 @@ void prefs::write_preferences()
}
try {
filesystem::scoped_ostream synced_prefs_file = filesystem::ostream_file(filesystem::get_prefs_file());
filesystem::scoped_ostream synced_prefs_file = filesystem::ostream_file(filesystem::get_synced_prefs_file());
write(*synced_prefs_file, synced);
} catch(const filesystem::io_exception&) {
ERR_FS << "error writing to synced preferences file '" << filesystem::get_prefs_file() << "'";
ERR_FS << "error writing to synced preferences file '" << filesystem::get_synced_prefs_file() << "'";
}
try {
@ -403,8 +403,8 @@ void prefs::write_preferences()
#ifndef _WIN32
if(!synced_prefs_file_existed) {
if(chmod(filesystem::get_prefs_file().c_str(), 0600) == -1) {
ERR_FS << "error setting permissions of preferences file '" << filesystem::get_prefs_file() << "'";
if(chmod(filesystem::get_synced_prefs_file().c_str(), 0600) == -1) {
ERR_FS << "error setting permissions of preferences file '" << filesystem::get_synced_prefs_file() << "'";
}
}
if(!unsynced_prefs_file_existed) {