Skip to content

Commit

Permalink
Add a button to the build info dialog to rerun the migrator. (#8791)
Browse files Browse the repository at this point in the history
Add-ons: checks for any that exist in the chosen other version but not in the current version.
Preferences: adds attributes that don't exist from the chosen other version's preferences that aren't in the current version's preferences. for attributes that exist in both, use the attributes from the file that was modified most recently.
Credentials: move if the credentials file doesn't exist.

Fixes #7936
  • Loading branch information
Pentarctagon committed Apr 27, 2024
1 parent cfb2ca9 commit 4dfb946
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 8 deletions.
1 change: 1 addition & 0 deletions boost_test_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test_gui2/modal_dialog_test_log_settings
test_gui2/modal_dialog_test_message
test_gui2/modal_dialog_test_mp_alerts_options
test_gui2/modal_dialog_test_mp_connect
test_gui2/modal_dialog_test_migrate_version_selection_dialog
test_gui2/modal_dialog_test_mp_join_game_password_prompt
test_gui2/modal_dialog_test_mp_login
test_gui2/modal_dialog_test_mp_method_selection
Expand Down
12 changes: 12 additions & 0 deletions data/gui/window/game_version.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,18 @@
[/button]
[/column]

[column]
horizontal_alignment = left
border = all
border_size = 5

[button]
id = "run_migrator"
#po: button to open the version migration dialog manually to re-migrate add-ons and the preferences file
label = _ "Migrate"
[/button]
[/column]

[column]
grow_factor = 1
horizontal_alignment = right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
172E48A5BD149999CE64EDF8 /* prompt.hpp in Headers */ = {isa = PBXBuildFile; fileRef = D4594633BF3F8A06D6AE752F /* prompt.hpp */; };
179D4E93A08C5A67B071C6C1 /* spinner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4214F3DA80B54080C4B548F /* spinner.cpp */; };
285C4E7A9E891E1DCB215683 /* back_edge_detector.hpp in Headers */ = {isa = PBXBuildFile; fileRef = DA034C90BB2E6C060B0A0B93 /* back_edge_detector.hpp */; };
365D4F89BD511BC074E639D7 /* migrate_version_selection.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B3DE4F95AF72C6F6BC37E695 /* migrate_version_selection.hpp */; };
36B146FAA79A55E9F43723B1 /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84234C54BB84519421FD4136 /* general.cpp */; };
36D74F7F8D7655ACCABE562D /* edit_pbl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6FA542D78393E8FF067775DA /* edit_pbl.cpp */; };
3C254DF5B7DF196F2041955F /* mp_report.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 58C649488B3014E6F7254B62 /* mp_report.cpp */; };
Expand Down Expand Up @@ -620,6 +621,7 @@
49478714172FF6F8002B7ABA /* tristate_button.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49478712172FF6F8002B7ABA /* tristate_button.cpp */; };
4B5D4FBB98B2ADF26EC50D9D /* community_dialog.hpp in Headers */ = {isa = PBXBuildFile; fileRef = CD5045B9A988F034F8D17C85 /* community_dialog.hpp */; };
4E19429E82899A42A73BBE91 /* choose_addon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E644DC98F26C756364EC2C /* choose_addon.cpp */; };
4E4A4DBC9F44444A5867EC2B /* migrate_version_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */; };
508C40A885166B2E3F4245F4 /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84234C54BB84519421FD4136 /* general.cpp */; };
529242A8856DE8D00988B9BD /* test_schema_self_validator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */; };
620A386E15E9364E00A4F513 /* attack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386215E9364E00A4F513 /* attack.cpp */; };
Expand Down Expand Up @@ -663,6 +665,7 @@
62D24F321519987400350848 /* context_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F311519987400350848 /* context_manager.cpp */; };
62D24F351519995200350848 /* palette_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F341519995200350848 /* palette_manager.cpp */; };
6D574EACA3483ABEE72819F0 /* statistics_record.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 27764FB68F02032F1C0B6748 /* statistics_record.cpp */; };
7A0347D48BDB52B1430D9E79 /* migrate_version_selection.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B3DE4F95AF72C6F6BC37E695 /* migrate_version_selection.hpp */; };
7A7146D7893AA09891352019 /* test_schema_validator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CF14AB694764953E2CB3AF7 /* test_schema_validator.cpp */; };
77D94146A5FA29849D1A9BD8 /* multiline_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B0F48CE9CF65D9813BE6CDC /* multiline_text.cpp */; };
7BFC4DF5BFF8CF75855BA662 /* prompt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67044415B63F5888193BD7A6 /* prompt.cpp */; };
Expand Down Expand Up @@ -1274,6 +1277,7 @@
C93048A9AE576B6AD016DFA4 /* tod_new_schedule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C61F473D9AC43768A445E218 /* tod_new_schedule.cpp */; };
C9D14DC39B87182A00397A3D /* choose_addon.hpp in Headers */ = {isa = PBXBuildFile; fileRef = D9A141EAAE90E98B6F6171D6 /* choose_addon.hpp */; };
D1254FCA82471825B83AA786 /* multiline_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0B0F48CE9CF65D9813BE6CDC /* multiline_text.cpp */; };
D2E9440BBCDCE2A75C93F85D /* migrate_version_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */; };
DF974010BB46B844E83F7DDA /* tod_new_schedule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C61F473D9AC43768A445E218 /* tod_new_schedule.cpp */; };
E1DA41878F0C255769B8239D /* scroll_text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 755D4555A1DEA29125E7F338 /* scroll_text.cpp */; };
E2F24C0CBC863C3DC8A041EF /* edit_pbl.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B2CC45FEA71445AE817CAA6B /* edit_pbl.hpp */; };
Expand Down Expand Up @@ -1375,7 +1379,6 @@
EC84246D18F30D9100FC1EEF /* synced_commands.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC84246218F30D9100FC1EEF /* synced_commands.cpp */; };
EC84246E18F30D9100FC1EEF /* synced_context.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC84246418F30D9100FC1EEF /* synced_context.cpp */; };
EC84247118F30DB700FC1EEF /* exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC84246F18F30DB700FC1EEF /* exception.cpp */; };
EC86E1F42691568200209B49 /* migrate_version_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC86E1F32691568200209B49 /* migrate_version_selection.cpp */; };
ECA1E0F21A1271AC00426E00 /* lua_gui2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ECA1E0F11A1271AC00426E00 /* lua_gui2.cpp */; };
ECA1E1011A12755B00426E00 /* mapgen_lua_kernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ECA1E1001A12755B00426E00 /* mapgen_lua_kernel.cpp */; };
ECA4A67B1A1EC319006BCCF2 /* lua_fileops.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ECA4A6781A1EC319006BCCF2 /* lua_fileops.cpp */; };
Expand Down Expand Up @@ -2401,6 +2404,7 @@
95EB8A53287A02EC00B09F95 /* top_level_drawable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = top_level_drawable.hpp; path = gui/core/top_level_drawable.hpp; sourceTree = "<group>"; };
95EB8A54287A02EC00B09F95 /* top_level_drawable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = top_level_drawable.cpp; path = gui/core/top_level_drawable.cpp; sourceTree = "<group>"; };
B2CC45FEA71445AE817CAA6B /* edit_pbl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = edit_pbl.hpp; sourceTree = "<group>"; };
B3DE4F95AF72C6F6BC37E695 /* migrate_version_selection.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = migrate_version_selection.hpp; path = migrate_version_selection.hpp; sourceTree = "<group>"; };
B508D191100146E300B12852 /* engine_fai.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = engine_fai.cpp; sourceTree = "<group>"; };
B508D192100146E300B12852 /* engine_fai.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = engine_fai.hpp; sourceTree = "<group>"; };
B513B2270ED36BFB0006E551 /* libcairo.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcairo.2.dylib; path = lib/libcairo.2.dylib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2854,7 +2858,6 @@
EC84246518F30D9100FC1EEF /* synced_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = synced_context.hpp; sourceTree = "<group>"; };
EC84246F18F30DB700FC1EEF /* exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = exception.cpp; sourceTree = "<group>"; };
EC84247018F30DB700FC1EEF /* exception.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = exception.hpp; sourceTree = "<group>"; };
EC86E1F32691568200209B49 /* migrate_version_selection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = migrate_version_selection.cpp; sourceTree = "<group>"; };
EC89A1061879D17D00A3B0B1 /* lapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lapi.c; sourceTree = "<group>"; };
EC89A1071879D17D00A3B0B1 /* lauxlib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lauxlib.c; sourceTree = "<group>"; };
EC89A1081879D17D00A3B0B1 /* lbaselib.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lbaselib.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2983,6 +2986,7 @@
F4E4E0B01367241E001C7528 /* suppose_dead.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = suppose_dead.hpp; sourceTree = "<group>"; };
F4E4E0B21367244F001C7528 /* image_modifications.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = image_modifications.cpp; sourceTree = "<group>"; };
F4E4E0B31367244F001C7528 /* image_modifications.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = image_modifications.hpp; sourceTree = "<group>"; };
F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = migrate_version_selection.cpp; path = migrate_version_selection.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -3796,7 +3800,6 @@
46F92CB02174F6A300602C1C /* lua_interpreter.hpp */,
46F92C662174F6A300602C1C /* message.cpp */,
46F92CF42174F6A300602C1C /* message.hpp */,
EC86E1F32691568200209B49 /* migrate_version_selection.cpp */,
46F92C752174F6A300602C1C /* modal_dialog.cpp */,
46F92C902174F6A300602C1C /* modal_dialog.hpp */,
46F92C722174F6A300602C1C /* modeless_dialog.cpp */,
Expand Down Expand Up @@ -3854,6 +3857,8 @@
D4594633BF3F8A06D6AE752F /* prompt.hpp */,
63B64397BB28593D879A67BE /* community_dialog.cpp */,
CD5045B9A988F034F8D17C85 /* community_dialog.hpp */,
F7B1444E9B79504502208B82 /* migrate_version_selection.cpp */,
B3DE4F95AF72C6F6BC37E695 /* migrate_version_selection.hpp */,
);
path = dialogs;
sourceTree = "<group>";
Expand Down Expand Up @@ -5142,6 +5147,7 @@
FC66414CB2E3F0E8B0B747B6 /* tod_new_schedule.hpp in Headers */,
285C4E7A9E891E1DCB215683 /* back_edge_detector.hpp in Headers */,
4B5D4FBB98B2ADF26EC50D9D /* community_dialog.hpp in Headers */,
365D4F89BD511BC074E639D7 /* migrate_version_selection.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -5156,6 +5162,7 @@
7FDF4E8D9C94E7DA8F41F7BB /* tod_new_schedule.hpp in Headers */,
F96A40219A964A8022910D73 /* back_edge_detector.hpp in Headers */,
00324A11ACB0DB64FBD97896 /* community_dialog.hpp in Headers */,
7A0347D48BDB52B1430D9E79 /* migrate_version_selection.hpp in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -5415,7 +5422,6 @@
46F92E252174F6A400602C1C /* faction_select.cpp in Sources */,
F4D2DECB14DCA1D000CAFF31 /* client.cpp in Sources */,
EC49A38219F34F1200E78528 /* clipboard.cpp in Sources */,
EC86E1F42691568200209B49 /* migrate_version_selection.cpp in Sources */,
EC179B891E91475300B4178C /* variant_value.cpp in Sources */,
B5599B7E0EC62181008DD061 /* color_range.cpp in Sources */,
ECFA82E3184E59F3006782FB /* command_executor.cpp in Sources */,
Expand Down Expand Up @@ -5912,6 +5918,7 @@
77D94146A5FA29849D1A9BD8 /* multiline_text.cpp in Sources */,
E1DA41878F0C255769B8239D /* scroll_text.cpp in Sources */,
F213406695CCC6ECE7254B38 /* community_dialog.cpp in Sources */,
D2E9440BBCDCE2A75C93F85D /* migrate_version_selection.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -6596,6 +6603,7 @@
529242A8856DE8D00988B9BD /* test_schema_self_validator.cpp in Sources */,
7A7146D7893AA09891352019 /* test_schema_validator.cpp in Sources */,
F0A74F75B197FC7C57528FF8 /* community_dialog.cpp in Sources */,
4E4A4DBC9F44444A5867EC2B /* migrate_version_selection.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 8 additions & 0 deletions src/gui/dialogs/game_version_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "formula/string_utils.hpp"
#include "game_config.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/dialogs/migrate_version_selection.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/styled_widget.hpp"
#include "gui/widgets/listbox.hpp"
Expand Down Expand Up @@ -146,6 +147,8 @@ void game_version::pre_show(window& window)
connect_signal_mouse_left_click(stderr_button, std::bind(&game_version::browse_directory_callback, this, log_path_));
stderr_button.set_active(!log_path_.empty() && filesystem::file_exists(log_path_));

connect_signal_mouse_left_click(find_widget<button>(&window, "run_migrator", false), std::bind(&game_version::run_migrator, this));

//
// Build info tab.
//
Expand Down Expand Up @@ -235,6 +238,11 @@ void game_version::browse_directory_callback(const std::string& path)
desktop::open_object(path);
}

void game_version::run_migrator()
{
migrate_version_selection::execute();
}

void game_version::copy_to_clipboard_callback(const std::string& path)
{
desktop::clipboard::copy_to_clipboard(path, false);
Expand Down
5 changes: 5 additions & 0 deletions src/gui/dialogs/game_version_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class game_version : public modal_dialog
* @param path Filesystem path associated with the widget.
*/
void browse_directory_callback(const std::string& path);

/**
* Callback function to re-run the version migration dialog.
*/
void run_migrator();
};
} // namespace dialogs
} // namespace gui2
39 changes: 35 additions & 4 deletions src/gui/dialogs/migrate_version_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gui/widgets/window.hpp"
#include "preferences/credentials.hpp"
#include "preferences/game.hpp"
#include "serialization/parser.hpp"

#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -98,19 +99,49 @@ void migrate_version_selection::post_show(window& window)
// given self-compilation and linux distros being able to do whatever they want plus command line options to
// alter locations make sure the directories/files are actually different before doing anything with them
if(migrate_addons_dir != filesystem::get_addons_dir()) {
std::vector<std::string> old_addons;
std::vector<std::string> current_addons;
std::vector<std::string> migrate_addons;
filesystem::get_files_in_dir(migrate_addons_dir, nullptr, &migrate_addons);

filesystem::get_files_in_dir(migrate_addons_dir, nullptr, &old_addons);
filesystem::get_files_in_dir(filesystem::get_addons_dir(), nullptr, &current_addons);

std::set_difference(old_addons.begin(), old_addons.end(), current_addons.begin(), current_addons.end(), std::back_inserter(migrate_addons));

if(migrate_addons.size() > 0) {
ad_hoc_addon_fetch_session(migrate_addons);
}
}

if(migrate_prefs_file != filesystem::get_prefs_file() && filesystem::file_exists(migrate_prefs_file)) {
filesystem::copy_file(migrate_prefs_file, filesystem::get_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());
} else {
config current_cfg;
filesystem::scoped_istream current_stream = filesystem::istream_file(filesystem::get_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);
for(const config::attribute& val : old_cfg.attribute_range()) {
if(current_prefs_are_older || !current_cfg.has_attribute(val.first)) {
preferences::set(val.first, val.second);
}
}

// don't touch child tags

preferences::write_preferences();
}
}

if(migrate_credentials_file != filesystem::get_credentials_file()
&& filesystem::file_exists(migrate_credentials_file)) {
// don't touch the credentials file on migrator re-run if it already exists
if(migrate_credentials_file != filesystem::get_credentials_file() && filesystem::file_exists(migrate_credentials_file) && !filesystem::file_exists(filesystem::get_credentials_file())) {
filesystem::copy_file(migrate_credentials_file, filesystem::get_credentials_file());
}

Expand Down
14 changes: 14 additions & 0 deletions src/tests/gui/test_gui2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "gui/dialogs/log_settings.hpp"
#include "gui/dialogs/lua_interpreter.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/migrate_version_selection.hpp"
#include "gui/dialogs/multiplayer/faction_select.hpp"
#include "gui/dialogs/multiplayer/lobby.hpp"
#include "gui/dialogs/multiplayer/mp_alerts_options.hpp"
Expand Down Expand Up @@ -631,6 +632,10 @@ BOOST_AUTO_TEST_CASE(modal_dialog_test_mp_match_history_dialog)
{
test<mp_match_history>();
}
BOOST_AUTO_TEST_CASE(modal_dialog_test_migrate_version_selection_dialog)
{
test<migrate_version_selection>();
}
BOOST_AUTO_TEST_CASE(modeless_dialog_test_debug_clock)
{
test_popup<debug_clock>();
Expand Down Expand Up @@ -1074,6 +1079,15 @@ struct dialog_tester<mp_match_history>
}
};

template<>
struct dialog_tester<migrate_version_selection>
{
migrate_version_selection* create()
{
return new migrate_version_selection();
}
};

class fake_chat_handler : public events::chat_handler {
void add_chat_message(const std::time_t&,
const std::string&, int, const std::string&,
Expand Down

0 comments on commit 4dfb946

Please sign in to comment.