Module: Lich::Util::Update

Defined in:
documented/update.rb,
documented/common/update/file_writer.rb,
documented/common/update/script_sync.rb,
documented/common/update/custom_repos.rb,
documented/common/update/file_updater.rb,
documented/common/update/github_client.rb,
documented/common/update/status_reporter.rb,
documented/common/update/tracked_scripts.rb,
documented/common/update/branch_installer.rb,
documented/common/update/channel_resolver.rb,
documented/common/update/snapshot_manager.rb,
documented/common/update/release_installer.rb

Defined Under Namespace

Modules: FileWriter, StatusReporter Classes: BranchInstaller, ChannelResolver, CustomRepos, FileUpdater, GitHubClient, ReleaseInstaller, ScriptSync, SnapshotManager, TrackedScripts

Constant Summary collapse

STABLE_REF =

Update channel constants

'main'
BETA_BRANCH_PREFIX =
'pre/beta'
ASSET_TARBALL_NAME =
'lich-5.tar.gz'
GITHUB_REPO =
'elanthia-online/lich-5'
SCRIPT_REPOS =

Script repository registry

{
  'dr-scripts' => {
    display_name: 'DR Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/dr-scripts/git/trees/main?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/dr-scripts/main',
    tracking_mode: :all,
    script_pattern: /^[^\/]+\.lic$/,
    game_filter: /^DR/,
    subdirs: {
      'profiles' => { pattern: /^profiles\/base(?:-empty)?\.yaml$/, dest: File.join(SCRIPT_DIR, 'profiles') },
      'data'     => { pattern: /^data\/base.+yaml$/, dest: File.join(SCRIPT_DIR, 'data') }
    }
  }.freeze,
  'scripts'    => {
    display_name: 'Core Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/scripts/git/trees/master?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/scripts/master',
    tracking_mode: :explicit,
    script_pattern: /^scripts\/[^\/]+\.lic$/,
    script_prefix: 'scripts',
    game_filter: nil,
    default_tracked: %w[
      alias.lic autostart.lic go2.lic jinx.lic log.lic
      logxml.lic map.lic repository.lic vars.lic version.lic
    ].freeze,
    subdirs: {}
  }.freeze,
  'gs-scripts' => {
    display_name: 'GS Scripts',
    api_url: 'https://api.github.com/repos/elanthia-online/scripts/git/trees/master?recursive=1',
    raw_base_url: 'https://raw.githubusercontent.com/elanthia-online/scripts/master',
    tracking_mode: :explicit,
    script_pattern: /^scripts\/[^\/]+\.lic$/,
    script_prefix: 'scripts',
    game_filter: /^GS/,
    default_tracked: %w[
      ewaggle.lic
    ].freeze,
    subdirs: {
      'data' => { pattern: /^scripts\/(gameobj-data|effect-list)\.xml$/, dest: DATA_DIR, glob: '*.xml' }
    }
  }.freeze
}.freeze

Class Method Summary collapse

Class Method Details

.clear_branch_trackingvoid

This method returns an undefined value.

Clears the branch tracking information from the version file.



282
283
284
285
286
287
288
289
290
# File 'documented/update.rb', line 282

def self.clear_branch_tracking
  version_file_path = File.join(LIB_DIR, "version.rb")
  return unless File.exist?(version_file_path)

  version_content = File.read(version_file_path)
  version_content.gsub!(/\n# Branch tracking \(added by lich5-update --branch\).*?\n(?:LICH_BRANCH[^\n]*\n)*/m, '')
  version_content = version_content.rstrip + "\n"
  File.write(version_file_path, version_content)
end

.get_branch_infoHash?

Retrieves information about the currently tracked branch.

Returns:

  • (Hash, nil)

    a hash containing branch information or nil if not set



295
296
297
298
299
300
301
302
303
# File 'documented/update.rb', line 295

def self.get_branch_info
  if defined?(LICH_BRANCH) && LICH_BRANCH && !LICH_BRANCH.empty?
    {
      branch_name: LICH_BRANCH,
      repository: (defined?(LICH_BRANCH_REPO) ? LICH_BRANCH_REPO : nil),
      updated_at: (defined?(LICH_BRANCH_UPDATED_AT) ? LICH_BRANCH_UPDATED_AT : nil)
    }
  end
end

.helpObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'documented/update.rb', line 171

def self.help
  respond "
    --help                   Display this message
    --announce               Get summary of changes for next version
    --update                 Update all changes for next version
    --branch=<name>          Update to a specific GitHub branch
    --status                 Show current version and branch tracking info
    --snapshot               Grab current snapshot of Lich5 ecosystem and put in backup
    --revert                 Roll the Lich5 ecosystem back to the most recent snapshot

  [Script repository sync]
    #{$clean_lich_char}lich5-update --sync                              Sync all repos for current game
    #{$clean_lich_char}lich5-update --sync=dr-scripts                   Sync only dr-scripts repo
    #{$clean_lich_char}lich5-update --sync=scripts                      Sync only EO/scripts repo
    #{$clean_lich_char}lich5-update --tracked                           List tracked scripts for all repos
    #{$clean_lich_char}lich5-update --tracked=scripts                   List tracked scripts for one repo
    #{$clean_lich_char}lich5-update --track=scripts:bigshot.lic         Add a script to tracked list
    #{$clean_lich_char}lich5-update --untrack=scripts:bigshot.lic       Remove from tracked list

  [Custom 3rd-party repositories]
    #{$clean_lich_char}lich5-update --add-custom=owner/repo             Register a custom repo (default branch)
    #{$clean_lich_char}lich5-update --add-custom=owner/repo:branch      Register with specific branch
    #{$clean_lich_char}lich5-update --remove-custom=owner/repo          Unregister a custom repo
    #{$clean_lich_char}lich5-update --custom-repos                      List registered custom repos
    #{$clean_lich_char}lich5-update --track=owner/repo:script.lic       Track a script from custom repo
    #{$clean_lich_char}lich5-update --sync=owner/repo                   Sync a custom repo
    Custom scripts are installed to #{$clean_lich_char}scripts/custom/<owner-repo>/

  [Individual file updates]
    #{$clean_lich_char}lich5-update --script=<name>                     Update script (auto-detects repo)
    #{$clean_lich_char}lich5-update --script=dr-scripts:<name>          Update script from specific repo
    #{$clean_lich_char}lich5-update --data=dr-scripts:base-hunting.yaml Update data file from specific repo
    #{$clean_lich_char}lich5-update --library=<name>                    Update library file from lich-5

  [One time suggestions]
    #{$clean_lich_char}autostart add --global lich5-update --announce    Check for new version at login

  [On demand suggestions]
    #{$clean_lich_char}lich5-update --status                    Show current version and branch info
    #{$clean_lich_char}lich5-update --announce                  Check to see if a new version is available
    #{$clean_lich_char}lich5-update --update                    Update the Lich5 ecosystem to the current release
    #{$clean_lich_char}lich5-update --branch=<name>             Update to a specific GitHub branch (advanced)
    #{$clean_lich_char}lich5-update --revert                    Roll the Lich5 ecosystem back to latest snapshot

  [Branch update examples]
    #{$clean_lich_char}lich5-update --branch=main               Update to the main stable branch
    #{$clean_lich_char}lich5-update --branch=some_branch_name   Update to a different branch
    #{$clean_lich_char}lich5-update --branch=owner:branch_name  Update to a fork's branch

    *NOTE* Script repos sync automatically on login for both DR and GS.
    "
end

.request(type = '--announce') ⇒ void

Note:

This method handles various update commands.

This method returns an undefined value.

Processes update requests based on the provided type.

Parameters:

  • type (String) (defaults to: '--announce')

    the type of request to process



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'documented/update.rb', line 96

def self.request(type = '--announce')
  case type
  when /^(?:--announce|-a)\b/
    release_installer.announce
  when /^--branch=(.+)$/
    branch_installer.download_branch_update($1)
  when /^--(?:beta|test)(?: --(?:(script|library|data))=(.+))?\b/
    release_installer.prep_betatest($1&.dup, $2&.dup)
  when /^(?:--help|-h)\b/
    help
  when /^--status\b/
    show_status
  when /^(?:--update|-u)\b/
    release_installer.download_release_update
  when /^--refresh\b/
    respond
    respond "This command has been removed."
  when /^(?:--revert|-r)\b/
    snapshot_manager.revert
  when /^--add-custom=(\S+?)(?::(\S+))?$/
    custom_repos_manager.add_custom_repo($1, $2)
  when /^--remove-custom=(\S+)$/
    custom_repos_manager.remove_custom_repo($1)
  when /^--custom-repos$/
    custom_repos_manager.list_custom_repos
  when /^--sync(?:=(\S+))?$/
    if $1
      script_sync.sync_repo($1)
    else
      script_sync.sync_all_repos
    end
  when /^--track=(\S+):(\S+)$/
    tracked_scripts_manager.track_script($1, $2)
  when /^--untrack=(\S+):(\S+)$/
    tracked_scripts_manager.untrack_script($1, $2)
  when /^--tracked(?:=(\S+))?$/
    tracked_scripts_manager.show_tracked($1)
  when /^--(?:(script|library|data))=(?:(\S+):)?(.+)\b/
    type_name = $1&.dup
    repo = $2&.dup
    file = $3&.dup
    if repo
      file_updater.update_file_from_repo(type_name, repo, file)
    else
      file_updater.update_file(type_name, file)
    end
  when /^(?:--snapshot|-s)\b/
    snapshot_manager.snapshot
  else
    respond
    respond "Command '#{type}' unknown, illegitimate and ignored.  Exiting . . ."
    respond
  end
end

.show_statusvoid

This method returns an undefined value.

Displays the current status of the Lich5 ecosystem.

Examples:

Show the current status

Lich::Util::Update.show_status


229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'documented/update.rb', line 229

def self.show_status
  respond
  respond "Lich5 Version Information:"
  respond "  Version: #{LICH_VERSION}"

  branch_info = get_branch_info
  if branch_info
    respond "  Type: Branch (Development)"
    respond "  Branch: #{branch_info[:branch_name]}"
    respond "  Repository: #{branch_info[:repository] || GITHUB_REPO}"
    if branch_info[:updated_at]
      updated = Time.at(branch_info[:updated_at])
      days_ago = ((Time.now - updated) / 86400).to_i
      respond "  Updated: #{updated.strftime('%Y-%m-%d %H:%M:%S')} (#{days_ago} day#{days_ago == 1 ? '' : 's'} ago)"
    end
    respond
    respond "You are running a development branch, not a release package."
  else
    respond "  Type: Release Package"
    respond
    respond "To check for updates: #{$clean_lich_char}lich5-update --announce"
  end
  respond
end

.store_branch_tracking(branch_name, repo, _version) ⇒ void

This method returns an undefined value.

Stores the branch tracking information in the version file.

Parameters:

  • branch_name (String)

    the name of the branch being tracked

  • repo (String)

    the repository associated with the branch

  • version (String)

    the version of the branch (not used)



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'documented/update.rb', line 261

def self.store_branch_tracking(branch_name, repo, _version)
  version_file_path = File.join(LIB_DIR, "version.rb")
  version_content = File.read(version_file_path)

  version_content.gsub!(/\n# Branch tracking \(added by lich5-update --branch\).*?\n(?:LICH_BRANCH[^\n]*\n)*/m, '')

  branch_tracking = <<~RUBY

    # Branch tracking (added by lich5-update --branch)
    LICH_BRANCH = #{branch_name.dump}
    LICH_BRANCH_REPO = #{repo.dump}
    LICH_BRANCH_UPDATED_AT = #{Time.now.to_i}
  RUBY

  version_content = version_content.rstrip + branch_tracking
  File.write(version_file_path, version_content)
end

.sync_all_reposvoid

This method returns an undefined value.

Syncs all script repositories for the current game.

Examples:

Sync all repositories

Lich::Util::Update.sync_all_repos


156
157
158
# File 'documented/update.rb', line 156

def self.sync_all_repos
  script_sync.sync_all_repos
end

.update_core_data_and_scripts(version = LICH_VERSION) ⇒ void

This method returns an undefined value.

Updates the core data and scripts to the specified version.

Examples:

Update to a specific version

Lich::Util::Update.update_core_data_and_scripts("1.0.0")

Parameters:

  • version (String) (defaults to: LICH_VERSION)

    the version to update to (default is LICH_VERSION)



166
167
168
# File 'documented/update.rb', line 166

def self.update_core_data_and_scripts(version = LICH_VERSION)
  file_updater.update_core_data_and_scripts(version)
end