Class: Factorix::CLI::Commands::MOD::Sync
- Includes:
- DownloadSupport, PortalSupport
- Defined in:
- lib/factorix/cli/commands/mod/sync.rb
Overview
Sync MOD states and startup settings from a save file
Instance Method Summary collapse
-
#call(save_file:, jobs: "4", keep_unlisted: false, strict_version: false) ⇒ void
Execute the sync command.
Methods inherited from Base
backup_support!, confirmable!, inherited, require_game_stopped!
Instance Method Details
#call(save_file:, jobs: "4", keep_unlisted: false, strict_version: false) ⇒ void
This method returns an undefined value.
Execute the sync command
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/factorix/cli/commands/mod/sync.rb', line 47 def call(save_file:, jobs: "4", keep_unlisted: false, strict_version: false, **) jobs = Integer(jobs) say "Loading save file: #{save_file}", prefix: :info save_data = SaveFile.load(Pathname(save_file)) say "Loaded save file (version: #{save_data.version}, MOD(s): #{save_data.mods.size})", prefix: :info mod_list = MODList.load presenter = Progress::Presenter.new(title: "\u{1F50D}\u{FE0E} Scanning MOD(s)", output: err) handler = Progress::ScanHandler.new(presenter) installed_mods = InstalledMOD.all(handler:) graph = Dependency::Graph::Builder.build(installed_mods:, mod_list:) raise DirectoryNotFoundError, "MOD directory does not exist: #{runtime.mod_dir}" unless runtime.mod_dir.exist? # Plan phase (no side effects) mods_to_install = find_mods_to_install(save_data.mods, installed_mods, strict_version:) install_targets = mods_to_install.any? ? plan_installation(mods_to_install, graph, jobs, strict_version:) : [] enrich_install_targets_with_current_version(install_targets, installed_mods) mods_to_delete = strict_version ? find_mods_to_delete(save_data.mods, installed_mods) : [] conflict_mods = find_conflict_mods(mod_list, save_data.mods, graph) changes = plan_mod_list_changes(mod_list, save_data.mods, installed_mods, strict_version:) unlisted_mods = keep_unlisted ? [] : find_unlisted_mods(mod_list, save_data.mods, conflict_mods) mod_list_changed = needs_confirmation?(install_targets, conflict_mods, changes, unlisted_mods) has_changes = mod_list_changed || mods_to_delete.any? settings_changed = startup_settings_changed?(save_data.startup_settings) # Show combined plan and ask once unless has_changes || settings_changed say "Nothing to change", prefix: :info return end show_sync_plan(install_targets, mods_to_delete, conflict_mods, changes, unlisted_mods, settings_changed) return unless confirm?("Do you want to apply these changes?") # Execute phase if mods_to_delete.any? execute_deletions(mods_to_delete) say "Deleted #{mods_to_delete.size} MOD package(s)", prefix: :success end if install_targets.any? execute_installation(install_targets, jobs) say "Installed #{install_targets.size} MOD(s)", prefix: :success end if mod_list_changed apply_mod_list_changes(mod_list, conflict_mods, changes, unlisted_mods) backup_if_exists(runtime.mod_list_path) mod_list.save say "Updated mod-list.json", prefix: :success end if settings_changed update_mod_settings(save_data.startup_settings, save_data.version) say "Updated mod-settings.dat", prefix: :success end say "Sync completed successfully", prefix: :success end |