This alias replicates the /writeini command using $ini and /write
Basically, we know that remini and writeini have constraints of doing what they're suppose to do in files larger than 64kb. From reading the mIRC Help File, this doesn't seem to affect $readini or $ini - from what I can tell anyway, as I didn't see any references.
I coded this as a Bot I created had to add sections to a file much larger than 64kb, and was encountering issues while attempting to do so.
This snippet works exactly the same as writeini, except it utilizes other mIRC commands to perform the function.
Usage: /_writeini
alias _writeini {
;Is the <inifile> larger than 64kb?
if ($file($1).size > 65536) {
;Does the <section> exist?
var %x = $iif($read($1,w,$+(*,$chr(91),$2,$chr(93),*)),$readn), %y = 0
if (%x) {
;How many items are located within the <section>?
var %b = $ini($1,$ini($1,$ini($1,$2)),0), %c = $+($3,$chr(61),$4-)
while (%b) {
;<item> was found in the <section>
if ($ini($1,$ini($1,$ini($1,$2)),%b) == $3) {
inc %y
;Let's overwrite the <item> and data on line %w with new <value>
var %w = $calc(%x + %b)
write $+(-l,%w) $1 %c
}
;Keep searching <section> for the <item>
dec %b
}
if (!%y) {
;<item> wasn't found in the <section>, let's add <item> and <value> within
var %d = $calc((%x + $ini($1,$ini($1,$ini($1,$2)),0)) + 1)
write $+(-il,%d) $1 %c
}
}
else {
;<section> wasn't located at all, let's add it to the end of the file
write $1 $+($chr(91),$2,$chr(93))
write $1 $+($3,$chr(61),$4-)
}
}
;File size isn't larger than 64kb, so we invoke standard command
else { writeini -n $1- }
}
I hate to break it to you, but if you're storing that much data in an INI file, perhaps the access is frequent enough to warrant the use of a set of hash-tables.
Besides that grudge, there are two areas in which this could be improved greatly:
1) Obfuscation of variable names makes life difficult. %y, %x, %d, and %b could be a little more descriptive.
2) If I were you, I'd have written it using /fopen, /fseek, and /fwrite. Much faster and more powerful.
Other than that, it looks useful and well written. :]