mIRC Home    About    Download    Register    News    Help

Print Thread
#265912 13/08/19 06:54 PM
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
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)
  }
}


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
kap #265925 16/08/19 10:04 PM
Joined: Aug 2019
Posts: 3
C
Self-satisified door
Offline
Self-satisified door
C
Joined: Aug 2019
Posts: 3
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

Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
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.


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
kap #265933 17/08/19 01:53 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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


I am SReject
My Stuff

Link Copied to Clipboard