mIRC Homepage
Posted By: kap getJFM - feedback? - 13/08/19 06:54 PM
As an exercise I wrote this, but I'd like feedback!

Code
alias getJFM {

  ; sha-512 of JSON For mIRC.mrc v1.0.4000
  var %sha512 b29de8c964b002d089fa030a9a5357e3c737f17cd16309c0fa82142120a590db2223d4703cafe97f37b65de170bb4d9dbf7bb508f4052a47a2127fc74c10a6d6

  ; check if JSON For mIRC is loaded
  if ($isalias(JSONVersion)) {
    var %file $isalias(JSONVersion).fname
    if ($sha512(%file,2) != %sha512) .unload -rs $qt(%file) | return $getJFM
    else return 0
  }
  elseif ($1 isnum) {
    if ($urlget($1).state == fail) { echo -a Downloading failed. Are you connected to the internet? | halt }
    elseif ($zip($urlget($1).target,eo,scripts)) { 
      var %dir $+(scripts\,JSON-For-Mirc-1.0.4000)
      var %file $qt($findfile(%dir,JSON For mIRC.mrc,1))
      if (($sha512(%file,2) == %sha512) && ($input(Would you like to load $nopath(%file) $+ ?,yq))) .load -rs %file
      .remove $urlget($1).target
    }
    else { echo -a Something went wrong unzipping $urlget($1).target }
  }
  else { 
    var %url https://github.com/SReject/JSON-For-Mirc/archive/v1.0.4000.zip
    var %target JFM.zip
    return $urlget(%url,gf,%target,getJFM)
  }
}
Posted By: Chokehold Re: getJFM - feedback? - 16/08/19 10:04 PM
I think this code looks quite well written and concise.

I am however curious as to why the use of %dir, when its only purpose as far as I can see is to be put in another var. Aside from managability of the code of course. smile
Since the content of %dir seems to be quite static as well and its only use is to be put to use inside the $findfile, why not just put the written out dir there?
So instead of:
Code
      var %dir $+(scripts\,JSON-For-Mirc-1.0.4000)
      var %file $qt($findfile(%dir,JSON For mIRC.mrc,1))

You can make it:
Code
      var %file $qt($findfile(scripts\JSON-For-Mirc-1.0.4000,JSON For mIRC.mrc,1))


Another smaller related point: for the static info you have in %dir, there's no need to put the content within a $+().
Code
//var %test $+(scripts\,JSON-For-Mirc-1.0.4000) | echo -a Result: %test
Result: scripts\JSON-For-Mirc-1.0.4000

Code
//var %test scripts\JSON-For-Mirc-1.0.4000 | echo -a Result: %test
Result: scripts\JSON-For-Mirc-1.0.4000


And now, I'm going to go read up on $urlget smile
Posted By: kap Re: getJFM - feedback? - 17/08/19 12:46 PM
Ah cheers! Yes I suppose I wrote it like that, because in previous versions I was toying with variables. Cleaned it up a bit and forgot to change %dir.

maroon and Ouims also pointed out that if the file to check has groups in it, it will change the hash of the file so part of my code will fail. So, I could also check for the existance of this group (SReject/JSONForMirc/CompatMode) and check hashes based on its status.

This will be in the next version.
Posted By: FroggieDaFrog Re: getJFM - feedback? - 17/08/19 01:53 PM
1. you can't recursively call aliases

Code
// doesn't call getJFM and returns $null
return $getJFM


2. You can't use $input() from any events so be careful with it.If getJFM is called from the editbox its fine, if called from something like onload its not
© mIRC Discussion Forums