Skip to content

Instantly share code, notes, and snippets.

@westor7
Last active April 18, 2023 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westor7/f09c5319da70993683dd3f96722f47d4 to your computer and use it in GitHub Desktop.
Save westor7/f09c5319da70993683dd3f96722f47d4 to your computer and use it in GitHub Desktop.
JSON Installation
; Usage: Right click in "Status" window or click in "Menubar" then click on "JSON Installation" and follow the instructions.
menu status,menubar {
$str($chr(9679),3) JSON Installation (by westor) $str($chr(9679),3): { json_install_check_internet_init }
}
alias -l json_install_check_internet_init { noop $urlget(https://api.github.com,gbik,&data,json_install_check_internet_init_cb) }
alias -l json_install_check_internet_init_cb {
if ($urlget($1).state !== ok) { .timer -ho 1 0 noop $input(You are NOT connected to internet! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | return }
json_install
}
alias -l json_install {
; /json_install [-r]
; -r = Resume the rest installation after tsc64.dll will be installed (adiirc 64bits only).
var %mrc_url = https://raw.githubusercontent.com/SReject/JSON-For-Mirc/master/src/JSON%20For%20mIRC.mrc
var %js_url = https://raw.githubusercontent.com/SReject/JSON-For-Mirc/master/src/JSON%20For%20mIRC.js
var %tsc_git_repo_url = https://api.github.com/repos/tablacus/TablacusScriptControl/releases
var %mrc_loc = $scriptdir $+ JSON\JSON For mIRC.mrc
var %js_loc = $scriptdir $+ JSON\JSON For mIRC.js
var %dll_use = $envvar(windir) $+ \System32\tsc64.dll
if ($1) && ($1 == -r) { goto resume }
if ($hget(JSON_INSTALL,START)) { .timer -ho 1 0 noop $input(The JSON installation progress is already running $+ $chr(44) please wait...,houdbk60,JSON Installation - Error) | return }
if ($json_ver) { .timer -ho 1 0 noop $input(You have already installed the JSON code. $crlf $crlf $+ $+ Version: $json_ver $crlf $+ Created: $asctime($file($isalias(jsonversion).fname).ctime) $crlf $+ Path: $isalias(jsonversion).fname $crlf $crlf $+ $+ Installation failed!,houdbk60,JSON Installation - Error) | return }
if ($~adiircexe) {
if ($version < 4.3) { .timer -ho 1 0 noop $input(Your AdiIRC version ( $+ $version $+ ) is outdated $+ $chr(44) please update your client version to the latest $+ $chr(44) try use $qt(/update) command. $crlf $crlf $+ $+ Installation failed!,houdbk60,JSON Installation - Error) | return }
if ($readini($adiircini,n,Misc,InitScriptsWarning) == $null) || ($readini($adiircini,n,Misc,InitScriptsWarning) == True) { hadd -mu60 JSON_INSTALL INIT_WARN 1 | .setconfig Misc InitScriptsWarning False }
if ($bits == 64) {
if ($osbits !== 64) { .timer -ho 1 0 noop $input(You are using AdiIRC 64bits client but your OS (Operating System) supporting only 32bits AdiIRC version $+ $chr(44) the JSON code will NOT work correctly $+ $chr(44) please re-download and replace the $qt($nopath($adiircexe)) with the 32bits version. $crlf $crlf $+ $+ Installation failed!,houdbk60,JSON Installation - Error) | return }
if (!$file(%dll_use)) || (!$json_dlltest) {
var %ask = $input(You are using AdiIRC $bits bits version and you need first to install an extra DLL $qt(tsc64.dll) file $+ $chr(44) if you select $qt(Yes) it will automatically download and install $+ $chr(44) if you refuse to install that extra DLL then JSON installation will stop and the JSON code will not work $+ $chr(44) the AdiIRC needs that DLL in order to work in the 64bits version! $crlf $crlf $+ $+ $iif(!$isadmin,NOTE: In order to install that DLL after download completes you need to accept the UAC prompt to give the permission to install the DLL correctly!),yuwdbk60,JSON Installation - Warning)
if (!%ask) { return }
noop $urlget(%tsc_git_repo_url,gbik,&data,json_get_tsc_dll_url_cb)
return
}
}
}
elseif (!$~adiircexe) {
if ($version < 7.64) { .timer -ho 1 0 noop $input(Your mIRC version ( $+ $version $+ ) is outdated $+ $chr(44) please update your client version to the latest. $crlf $crlf $+ $+ Installation failed!,houdbk60,JSON Installation - Error) | return }
if ($gettok($readini($mircini,n,options,n5),27,44)) { .timer -ho 1 0 noop $input(You have to disable "Initialization Warning" from the scripts editor "Options" menu. $crlf $crlf $+ $+ Installation failed!,houdbk60,JSON Installation - Error) | return }
}
:resume
if (!$isdir($scriptdir $+ JSON)) { mkdir $qt($scriptdir $+ JSON) }
if ($isfile(%mrc_loc)) { .remove $qt(%mrc_loc) }
if ($isfile(%js_loc)) { .remove $qt(%js_loc) }
hadd -mu60 JSON_INSTALL START $ticks
noop $urlget(%mrc_url,gfik,%mrc_loc,json_download)
noop $urlget(%js_url,gfik,%js_loc,json_download)
}
alias -l json_download {
; /json_download
var %url = $urget($1).url
var %file = $urlget($1).target
if ($urlget($1).state !== ok) { .timer -ho 1 0 noop $input(There was a error while trying to download the $qt($nopath(%file)) file from $qt(%url) website! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear | return }
if (!$file(%file)) { .timer -ho 1 0 noop $input(There was a corruption error while trying to download the $qt($nopath(%file)) file from $qt(%url) website! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear | return }
hadd -mu60 JSON_INSTALL DOWNLOADED $addtok($hget(JSON_INSTALL,DOWNLOADED),%file,166)
if ($numtok($hget(JSON_INSTALL,DOWNLOADED),166) >= 2) {
var %load = $wildtok($hget(JSON_INSTALL,DOWNLOADED),*.mrc,1,166)
.load -rs1 $qt(%load)
if (!$script($nopath(%load))) { .timer -ho 1 0 noop $input(There was a error while trying to install the $qt($nopath(%load)) file! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear | return }
if (!$json_dlltest) { .timer -ho 1 0 noop $input(There was an error while trying to execute some DLL tests! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear | return }
if (!$json_apitest) { .timer -ho 1 0 noop $input(There was an error while trying to execute some JSON code tests! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear | return }
.timer -ho 1 0 noop $input(The JSON installation has been successfully completed. $crlf $crlf $+ $+ Took: $calc(($ticks - $hget(JSON_INSTALL,START)) / 1000) second(s) $crlf $+ Version: $json_ver $crlf $+ Created: $asctime($file($isalias(jsonversion).fname).ctime) $crlf $+ Path: $isalias(jsonversion).fname,ouidbk60,JSON Installation - OK)
json_install_clear
var %ask = $input(Do you want to remove the JSON installation code and delete the file from the disk?,yuqdbk60,JSON Installation - Question)
if (%ask) { .timer -ho 1 1 .remove $qt($script) | .unload -rs $qt($script) }
}
}
alias -l json_download_dll {
; /json_download_dll
var %url = $urget($1).url
var %file = $urlget($1).target
if ($urlget($1).state !== ok) { .timer -ho 1 0 noop $input(There was a error while trying to download the $qt($nopath(%file)) file from $qt(%url) website!,houdbk60,JSON Installation - Error) | json_install_clear | return }
if (!$file(%file)) { .timer -ho 1 0 noop $input(There was a corruption error while trying to download the $qt($nopath(%file)) file from $qt(%url) website!,houdbk60,JSON Installation - Error) | json_install_clear | return }
var %status = $zip(%file,eo,$envvar(temp) $+ \TSC)
if (!%status) { .timer -ho 1 0 noop $input(There was a corruption error while trying to unzip the downloaded $qt($nopath(%file)) file!,houdbk60,JSON Installation - Error) | json_install_clear | return }
run $iif(!$isadmin,-a) cmd.exe /c xcopy /q /Y $qt($envvar(temp) $+ \TSC\tsc64.dll) $qt($envvar(windir) $+ \System32) $str($chr(38),2) regsvr32 $qt($envvar(windir) $+ \System32\tsc64.dll) /s
.timer 1 2 json_install -r
return
:error
if ($error) && (*unable to open file* iswm $error) { .timer -ho 1 0 noop $input(You've refused to give administrator access to install the extra DLL (tsc64.dll) file! $crlf $crlf $+ $+ Installation failed.,houdbk60,JSON Installation - Error) | json_install_clear }
reseterror
}
alias -l json_install_clear {
; /json_install_clear
if ($hget(JSON_INSTALL,INIT_WARN)) { .setconfig Misc InitScriptsWarning True }
if ($hget(JSON_INSTALL)) { hfree $v1 }
noop $findfile($envvar(temp) $+ \TSC,*,0,.remove $qt($1-))
if ($isdir($envvar(temp) $+ \TSC)) { .rmdir $qt($envvar(temp) $+ \TSC) }
if ($isfile($envvar(temp) $+ \tsc64.zip)) { .remove $qt($envvar(temp) $+ \tsc64.zip) }
}
alias -l json_get_tsc_dll_url_cb {
; $json_get_tsc_dll_url_cb
var %dll_loc = $envvar(temp) $+ \tsc64.zip
var %dll_url = https://github.com/tablacus/TablacusScriptControl/releases/download/1.2.5.2/tsc64_1252.zip
if ($isfile(%dll_loc)) { .remove $qt(%dll_loc) }
if ($urlget($1).state !== ok) { noop $urlget(%dll_url,gfik,%dll_loc,json_download_dll) | return }
var %t = $urlget($1).target
var %n1 = $bfind(%t, 1, "browser_download_url":)
var %n2 = $bfind(%t, %n1, "tarball_url":)
var %u = $gettok($bvar(%t,%n1 $+ - $+ %n2).text,3,34)
if (%u) && (%u isurl) && (*.zip iswm %u) { noop $urlget(%u,gfik,%dll_loc,json_download_dll) }
else { noop $urlget(%dll_url,gfik,%dll_loc,json_download_dll) }
}
alias json_ver {
; $json_ver
if (!$isid) { return }
if (!$isalias(jsonversion)) { return 0 }
return $gettok($jsonversion,2,118)
}
alias json_apitest {
; $json_apitest
if (!$isid) { return }
if (!$isalias(jsonopen)) || (!$isalias(jsonerror)) { return 0 }
jsonopen -ud json_apitest https://api.github.com/repos/tablacus/TablacusScriptControl/releases
if ($jsonerror) { return 0 }
return 1
}
alias json_dlltest {
; $json_dlltest
if (!$isid) { return }
.comopen JSON_TEST ScriptControl
if ($com(JSON_TEST) && !$comerr) { var %status = 1 }
if ($com(JSON_TEST)) { .comclose JSON_TEST }
return $iif(%status,1,0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment