Class: Nauvisian::CLI::Commands::Save::Mod::Sync

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
DownloadHelper, MessageHelper
Defined in:
lib/nauvisian/cli/commands/save/mod/sync.rb

Defined Under Namespace

Classes: ExistingMods

Instance Method Summary collapse

Instance Method Details

#call(save_file:, **options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nauvisian/cli/commands/save/mod/sync.rb', line 22

def call(save_file:, **options)
  save_file_path = Pathname(save_file)
  save = Nauvisian::Save.load(save_file_path)
  mods_in_save = save.mods.sort # [[mod, version]]

  options[:mod_directory] = Pathname(options[:mod_directory])
  existing_mods = ExistingMods.new(**options)

  downloader = Nauvisian::Downloader.new(credential: find_credential, progress: options[:verbose] ? Nauvisian::Progress::Bar : Nauvisian::Progress::Null)

  mods_in_save.each do |mod, version|
    next if mod.base?

    release = existing_mods.release_to_download(mod, version)
    next unless release

    downloader.download(release, options[:mod_directory] / release.file_name)
  end

  list = Nauvisian::ModList.new(mods_in_save.map {|mod, _version| [mod, true] })
  list.save(options[:mod_directory] / "mod-list.json")

  settings = Nauvisian::ModSettings.load(options[:mod_directory] / "mod-settings.dat")
  settings["startup"] = save.startup_settings
  settings.save(options[:mod_directory] / "mod-settings.dat")
rescue => e
  message(e)
  exit 1
end