mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2017
Posts: 57
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
Sorry if someone else has already suggested this. I searched the Feature Suggestions for "wildcard", but I didn't see anything.

I have a lot of scripts, over twenty for sure.
In particular, I have a miniature RPG Adventure in my chat, and it uses fifteen or so separate remote files for simplicity of navigation. If I want to alter how to fight monsters, I open the Attack remote. Pretty simple.

The only issue is if I want to remove/rename all remotes, or even a select few, I have to name them individually in the script. Here's a quick pic of my current setup(as of time of writing OP):


It's a little clunky, and rather hard to read through. I put a block-comment on my RPG scripts because I'm rebuilding the whole thing, but I'm debating whether to make several remotes, same as before, or whether I should put it all into one remote, simply for ease of loading/unloading. Thus, I propose support for wildcards in the load/unload command.

For example, the below code would be a lot easier to use than naming each remote in the script.
Code:
on *:TEXT:!scripts*:#: {
  if ($nick == KubosKube) {

    msg $chan /me ⚙️ Scripts $2 [ $+ [ ed. ] ]
    $2 -rsN scripts/Streaming/remote*.ini


The only problem I can think of off the top of my head is if a filename contained an asterisk in it, which, at this point in time, Windows does not allow, so there is no immediate concern from what I can tell.

I think this would be a very neat addition to mIRC, and it would help users with a massive number of remote files such as myself.

Joined: Jul 2014
Posts: 34
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Jul 2014
Posts: 34
couldn't you just use $findfile ?

Code:
noop $findfile(some/path,some*Name.*,0,echo $1-)

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
1. $findfile works, but remember to include the depth to avoid mIRC's default of recursing through all subfolders.
2. Also, by using the same number to load at a specific position, the scripts end up being loaded in reverse order.
3. $findfilen gives the sequential number found, so you can use that to load the files in FIFO order.
4. $findfile shows the entire drive letter and pathname, so you can use $remove to chop the beginning to make it a relative path.
5. Not sure how much of a problem it will be to load a lot of scripts at the same time, especially if they have ON LOAD activities, so can use a timer to spread it out a little.

Code:
//noop $findfile(StartDir,wildstring*.ini,1,0,.timer 1 $findfilen load -rs $+ $calc(5+ $findfilen) $remove($1-,c:\Base\Path\To\Remove))

Joined: Jan 2017
Posts: 57
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
Major thanks to both of you! Didn't know that /noop nor $findfile even existed. I got this to work just fine with your help. laugh

For anyone else who has this issue, here is my dialog with this workaround built-in.
I capitalized the parts that need to be edited to fit your specific setup, but this seems overall useable.

Code:
;Big thanks to SykO and Maroon for helping me create this!
alias scripts_dialog {
  dialog -m scripts_dialog scripts_dialog
}

dialog scripts_dialog {
  title "Scripts"
  size -1 -1 80 26
  option dbu
  button "Load", 1, 2 2 37 12
  button "Unload", 2, 41 2 37 12
  text "Scripts <placeholder>", 3, 2 16 76 8, center
}

on *:dialog:scripts_dialog:sclick:1-2:{
  noop $findfile(YOUR/FILEPATH,YOUR_FILE.NAME,0,.timer 1 $findfilen $did($dname, $did).text -rs $+ $calc(5+ $findfilen) $1-)
  did -a scripts_dialog 3 Scripts $did($dname, $did).text $+ ed.
}



Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
You should be careful with this, loading a full directory or even just all files matching a simple wildcard like remote*.ini in a directory is potentially dangerous, if a malicious user can get a file matching in that directory you would load that file.
What you were doing originally is much safer, and you can easily reduce the size of the code.
maroon's code with the timer will cause a double evaluation of the parameter, there should be an $unsafe in there, also the $calc(5+) should be used on the timer's delay parameter rather than the N of /load (maybe this was intended but it makes no sense to me).
Also you probably want to /reload instead of /load (and even /unload), /reload just won't trigger on load and on start in the file. I don't think there is a need for -rsN, /reload will keep the same position.
I'd recommend to avoid the $findfile loop and just loop over your list of known files like you had first:
Code:
var %files remote1.ini remote2.ini remoteN.ini,%a 1
while ($gettok(%files,%a,32) != $null) {
.reload -rs $qt(path\to\ $+ $v1)
inc %a
}
just add script files to %files, space seperated


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2017
Posts: 57
Babel fish
OP Offline
Babel fish
Joined: Jan 2017
Posts: 57
So I've done a lot of thinking and coding...
-----

Quote:
You should be careful with this, loading a full directory or even just all files matching a simple wildcard like remote*.ini in a directory is potentially dangerous, if a malicious user can get a file matching in that directory you would load that file.


This is true. The script before this post was completely blind. It loaded all remotes without a safeguard.
-----
Quote:
What you were doing originally is much safer, and you can easily reduce the size of the code.


Safe? Yes. Easy? Kinda. Fun? No. Also, it wasn't the size of the code that was daunting. I was put off by the copy/pasting.
-----
Quote:
I'd recommend to avoid the $findfile loop and just loop over your list of known files like you had first:
Code:
var %files remote1.ini remote2.ini remoteN.ini,%a 1
while ($gettok(%files,%a,32) != $null) {
.reload -rs $qt(path\to\ $+ $v1)
inc %a
}

just add script files to %files, space seperated

This sounds simple, but it's basically a re-skin of my old code. It would nearly be easier to keep copy/pasting like I was before, because anytime I rename a file, I have to change it manually in the main remote.
-----

So, here is what I think to be the easiest "safe" code possible to a novice scripter such as myself.
In short, it loads all files in your C:User\Filepath\Roaming\mIRC\Scripts folder and counts them on the first pass. You'll want to manually check to make sure there's nothing dangerous in those folders.
On successive Unloads/Loads, it compares the number of old files to the number of new files.(I plan to figure out a way to make it remember file names and update here with what I come up with.)
If there is a discrepency between the old files and the new files, it will bring up a dialog to decide what you want to do.
I'm off to work right now, but I'll be back in a few hours to read your input.
Code:
;Script loader
alias scripts_dialog {
  dialog -m scripts_dialog scripts_dialog
}
;Warning dialog
alias unknown_script {
  echo -a $dialog(unknown_script,unknown_script)
}

;Script-loading dialog
dialog scripts_dialog {
  title "Scripts"
  size -1 -1 80 26
  option dbu
  button "Load", 1, 2 2 37 12
  button "Unload", 2, 41 2 37 12
  text "Scripts <placeholder>", 3, 2 16 76 8, center
}
;Buttons to load/unload all remote.*.ini files
on *:dialog:scripts_dialog:sclick:1-2:{
  set %scriptsCountNew $findfile(scripts,remote.*.ini,0,echo $1-)
  ;If a new file is found or an old file is missing
  if (%scriptsCountNew != %scriptsCountOld) {
    echo -a FOUND SCRIPT DISCREPENCY
    set %continue $dialog(unknown_script,unknown_script)
    echo -a Decided to %continue
    ;complete break in sequence at operator discretion
    if (%continue == Cancel) {
      echo -a Aborting script loader.
      halt
    }
  }
  noop $findfile(scripts,remote.*.ini,0,timerload1 1 $findfilen did -a scripts_dialog 3 Scripts $did($dname,$did) $+ ed.)
  echo -a Found %scriptsCountNew scripts.
  echo -a Attempting to $did($dname, $did).text scripts. . .
  noop $findfile(scripts,remote.*.ini,0,.timer 1 $findfilen $did($dname, $did).text -rs $+ $calc(5 + $findfilen) $1-)
  noop $findfile(scripts,remote.*.ini,0,.timer_notice 1 $findfilen echo -a Scripts $did($dname, $did).text $+ ed! )
  did -a scripts_dialog 3 Scripts $did($dname, $did).text $+ ing. . .
  set %scriptsCountOld %scriptsCountNew
}

;Dialog for unknown scripts
dialog unknown_script {
  title "Warning! Unexpected Scripts!"
  size -1 -1 275 98
  option dbu
  list 1, 2 2 271 80, radio
  button "Delete Selected", 2, 2 84 67 12
  radio "Continue", 3, 71 85 67 10
  radio "Cancel", 4, 140 85 67 10
  button "Go", 5, 209 84 64 12, ok
  edit "",6, 1 1 1 1, result hide
}

;populate list with found remote.*.ini files
on *:dialog:unknown_script:init:0: { did -c $dname 4 | did -o $dname 6 1 Cancel | noop $findfile(scripts,remote.*.ini,0,did -a unknown_script 1 $remove($1-,%System..filepath)) }
;Click a radio on the list and click "Delete Selected" to send it to Recycle Bin
on *:DIALOG:unknown_script:sclick:2:{ remove -b %System..filepath $+ $did($dname, 1).seltext | did -r $dname 1 | noop $findfile(scripts,remote.*.ini,0,did -a unknown_script 1 $remove($1-,%System..filepath)) }
;set hidden result, the edit box, to Continue/Cancel
on *:DIALOG:unknown_script:sclick:3:{ did -o $dname 6 1 Continue }
on *:DIALOG:unknown_script:sclick:4:{ did -o $dname 6 1 Cancel }

PS- The Variable "%System..filepath" is the same as "C:\file\path\" leading up to, but not including, mIRC's folder.

Last edited by KubosKube; 08/05/17 07:31 PM.

Link Copied to Clipboard