SReject / JSON-For-Mirc

JSON parser for mIRC
19 stars 6 forks source link

/JSONUpdate: Auto-updating to the latest version #57

Closed westor7 closed 3 years ago

westor7 commented 3 years ago

Hello,

I saw that a lot of users keeps using an outdated version of JSON For mIRC so i had an idea to create an auto-update feature so the project can self update via a command, i made an example of a code but i am not sure if you like that style, i keep using $urlget and $zip identifiers that both clients support them.

mIRC minimum required version must be change to: 7.56 AdiIRC minimum required version must be change to: 3.7

alias JSONUpdate {
  var %SourceUrl = https://github.com/SReject/JSON-For-Mirc/releases/download/3.0.1001-beta/JSON.For.mIRC.v3.0.1001.zip
  var %SourceFile = $scriptdir $+ JSONUpdate.zip

  if ($isfile(%SourceFile)) { .remove $qt(%SourceFile) }

  echo $color(info) -age * /JSONUpdate: Start updating now to the latest version..

  noop $urlget(%SourceUrl,gf,%SourceFile,jfm_update_download_callback)
}

alias -l jfm_update_download_callback {
  var %Id = $1
  var %State = $urlget(%Id).state
  var %Target = $urlget(%Id).target

  if (%State !== ok) || (!$file(%Target)) { echo $color(info) -age * /JSONUpdate: Error while trying to download the ZIP file from server for update! | return }

  echo $color(info) -age * /JSONUpdate: Download completed, extracting now the downloaded ZIP file..

  var %Extract = $zip(%Target,eo,$scriptdir)

  if (!%Extract) { echo $color(info) -age * /JSONUpdate: Error while trying to extract the downloaded ZIP file for update! | return }

  .remove $qt(%Target)
  .unload -rs $qt($script)
  .timer -o 1 0 .load -rs $qt($script)

  echo $color(info) -age * /JSONUpdate: Update has been completed.
}

I know it can be better coded and check first if needs an update or not via $JSONVersion() and the latest online available version, but i found that feature really helpful especially for users that have no idea how to update.

SReject commented 3 years ago

The reason I haven't added an auto updated is that the script isn't backwards compatible with itself. each major version 0.x, 1.x, 2.x, 3.x breaks backwards compatibilities with the version before it.

I don't want to add an auto updater and end up breaking someone's script because they jumped up to a version that isn't compatible with what they are using