mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Hi there. I was a bit interested in Sparkz' post about making ini files in alphabetic order, so I decided to give it a try.
I have no idea how to work with /window or /filter so I can't create something like the famous Top 10 script:
Click to reveal..
Code:
on *:TEXT:!top5:#:{ 
  top10 #
}
alias top10 {
  window -h @. | var %i 1
  while $ini(casino.ini,%i) {
  aline @. $v1 $readini(casino.ini,$v1,money)
  inc %i
}
  filter -cetuww 2 32 @. @.
  var %i 1 | while %i <= 5 {
    var %list $addtok(%list,$line(@.,%i),44)
    inc %i
  }
  echo -agt msg # Top 5: $replace(%list,$chr(44),$+($chr(44),$chr(32)))
  window -c @.
}
Thus I decided to use files and use the built-in windows alphabetical system.

Here's the script I made:
Code:
on *:text:!organize &:#Nillen: { set %call # | organize $2- }

;Usage: /organize <file>
;/fill is used to rewrite the test.ini file to values used

alias organize {
  if (!$1) { act Please specify a file. | halt }
  var %file $qt($1-)
  if (.ini !isin %file) { act This script only works with ini files. | halt }
  if ($ini(%file,0)) var %secs $v1
  else { act Couldn't find specified file. %file | halt }
  if (!$isdir(temp)) mkdir temp

  handle_ini temp %file 

  noop $findfile(temp\,*.ini,0,handle_ini %file $qt($1-))

  unset %call
}

alias act {
  if (%call) msg $v1 $1-
  else echo -a $1-
}

alias fill {
  .remove test.ini
  writeini test.ini Loka Water Lemon
  writeini test.ini Bonaqua Water Natural Light Carbonation
  writeini test.ini Ramlösa Water Natural
}

alias handle_ini {
  tokenize 32 $1-
  var %file $2
  var %secs $ini(%file,0)
  while (%secs) { 
    var %sec $ini(%file,%secs) 
    var %destination $iif($1 == temp,$+(temp\,%sec,.ini),$v1) 
    var %items $ini(%file,%sec,0)
    while (%items) {
      var %item $ini(%file,%sec,%items)
      var %value $readini(%file,%sec,%item)
      writeini %destination %sec %item %value
      act wrote %destination %sec %item %value
      dec %items
    }
    dec %secs
  }
  .remove %file
}

Result:
Quote:
[13:40] <Eepa> !organize test.ini
[13:40] <~Nillen> wrote temp\Loka.ini Loka Water Lemon
[13:40] <~Nillen> wrote temp\Ramlösa.ini Ramlösa Water Natural
[13:40] <~Nillen> wrote temp\Bonaqua.ini Bonaqua Water Natural Light Carbonation
Expected result:
Quote:
[13:40] <Eepa> !organize test.ini
[13:40] <~Nillen> wrote temp\Loka.ini Loka Water Lemon
[13:40] <~Nillen> wrote temp\Ramlösa.ini Ramlösa Water Natural
[13:40] <~Nillen> wrote temp\Bonaqua.ini Bonaqua Water Natural Light Carbonation
[13:40] <~Nillen> wrote test.ini Bonaqua Water Natural Light Carbonation
[13:40] <~Nillen> wrote test.ini Loka Water Lemon
[13:40] <~Nillen> wrote test.ini Ramlösa Water Natural
Note that this is accomplishable if I manually enter the 13th line replacing %file with the proper value.
Code:
//noop $findfile(temp\,*.ini,0,handle_ini test.ini $qt($1-))
With this information I figured that there's probably a bug with $findfile not properly working when the same script created the file.

Tested using a fresh portable client as well, same result:
Quote:
7 7.36 0b98d50ad3b148e7dbe78a90ae8e3f2f ok 1 1 0 0


Now, if anyone would like to post a "real" version of this script using /filter and /window, I'd definitely appreciate it. I'd like to first and foremost study it and create scripts around it, as well as actually use the script.


Edit: I have tried using the script with a timer 1 5 before the $findfile without success as well. The timer starts and halts properly but nothing comes out of it.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Jul 2006
Posts: 4,187
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,187
$findfile is probably fine there, the problem is that /writeini doesn't create a file, it writes to the RAM somewhere where all $*ini identifiers read from that place as well and eventually, the content gets written to a file on the disk. Previous version of mIRC were so that the file was almost always created *as expected*. But any script relying on this was making assumptions, newer version of mIRC don't seem to flush the file the same way as before, $findfile doesn't find the files because they do not exist on the disk, you must use /flushini to write the content to the disk.

If it works manually after the script ran, that's because meanwhile, mIRC flushed the file laugh

And sorting the sections of an INI file alphabetically cannot really be done efficiently with /filter because you're not sorting all lines but just some matching a specific format, and then you have to copy over the item/data. I think you would be better of $sorttoking() a list of section's name and then copy sections in order, here is a try:
Code:
alias testsort {
  var %file test.ini,%a 1,%s
  while ($ini(%file,%a) != $null) var %l = %l $v1,%a %a + 1
  ;note 'a' is alphanumeric
  %s = $sorttok(%l,32,a)
  .fopen main $qt(%file)
  .fopen -no sort sorted_test.ini
  %a = 1
  while ($gettok(%s,%a,32) != $null) {
    .fwrite -n sort $+([,$v1,])
    .fseek -w main $+([,$v1,])
    .fseek -n main
    while ([*] !iswm $fread(main)) && (!$feof) .fwrite sort $v2 $+ $crlf
    .fseek main 0
    inc %a
  }
  .fclose main
  .fclose sort
}

Last edited by Wims; 14/11/14 06:45 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2013
Posts: 779
N
Nillen Offline OP
Hoopy frood
OP Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
Oh, I see. That makes sense now, thanks for clearing that out.

I can also see that I will never be at your level of scripting, hehe. But at least I gave it a shot! smile

Thanks for the help mate, I'll see if I can re-create your code into different usages in other scripts, appreciate it smile


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net

Link Copied to Clipboard