mIRC Home    About    Download    Register    News    Help

Print Thread
Getting write error - Need assistance #267689 05/09/20 02:14 PM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Can anyone take a look at the code below and assist me in correcting the error?

Error:

* /write: error writing 'C:\Users\Profile Name\AppData\Roaming\mIRC\scripts\data\AutoJoin.mrk' (line 65, script1.ini)
NOTE: Profile Name is where my full name is


alias find_cboxai {
if $dialog(autos) {
var %c = $read($_doc(AutoID),$calc(%_i -1)),%g = $gettok(%c,2-,42)
THIS IS LINE 65 write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
inc %_i
}
}

alias rconf {
if $dialog(autos) {
if ($1-2) { return $readini($+(",$mircdirscripts\data\autos.ini,"),$1,$2) }
}
}

alias conf {
if $dialog(autos) {
if ($1) && ($2) && ($3) { writeini $+(",$mircdirscripts\data\autos.ini,") $1 $2 $3- } | else { return }
}
}

alias _doc { return $+(",$mircdirscripts\data\,$1,.mrk,") }

Button 6 = Dialog Close Button

on *:dialog:autos:sclick:6: {
conf Autos Join $iif($did($dname,3).state = 1,on,off)
conf Autos Identify $iif($did($dname,9).state = 1,on,off)
conf Autos IDEvent $iif($did($dname,13).sel = 1,connect,notice)
set %_i 2
filter -k $_doc(AutoJoin) find_cboxaj
set %_i 2
filter -k $_doc(AutoID) find_cboxai
unset %_i
}

Re: Getting write error - Need assistance [Re: Darkmnm] #267692 05/09/20 07:14 PM
Joined: Jan 2004
Posts: 1,407
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,407
I'm not seeing something that would cause this. The 'error writing' message is ambiguous. "error opening" would mean either the foldername or filename doesn't yet exist, but "error writing" means the filename does exist. There are a couple of causes I can think of, but they shouldn't be happening in this context.

The file could have the 'read only' attribute set, but this is unlikely unless it was specifically set due to being copied off a CD/DVD media where it was set, or if you specifically set it. You can verify this isn't the case by doing:

/run cmd /k attrib scripts\data\AutoJoin.mrk

Typically there would only be the A attribute to the left of the filename, and there should not be the "R" for read-only.

If there is the R attribute, you can remove it like
/run cmd /c attrib -r scripts\data\AutoJoin.mrk

The error could be caused by not having write permissions to the file, but this shouldn't happen unless you're doing something like writing to a subfolder beneath c:\program files\ or c:\windows\
It's still possible for a file to have blocked write permissions if you used a utility to 'move' the filename from another folder where you didn't have write permissions. If that's the case, you'd want to *move* it back there, then *copy* it here.

==

A couple other suggestions for your script:

+ Use relative pathnames, so you don't need to put quotes around everything to protect against $mircdir having a space in it. By default, if the pathfilename doesn't begin with \ or driveletter:\ then it carries an implied $mircdir in front of it, so you could change _doc to

alias _doc { return $+(scripts\data\,$1,.mrk) }

Also, you want to get in the habit of using switches with $read.

If you don't want to have it evaluate %variable or $identifier contained in the returned text, nor for it to waste time looking for it, then use the r switch.

If you don't want to have it waste time checking if line#1 is numeric, and if that's so, to have it treat that as if it's the number of lines in the file, then use the t switch.

Since you're using a .ini format the 't' issue isn't probably going to affect you, and you're probably not reading/writing strings containing words that being with $ or %, but it's good practice to be in the habit of using switches rt unless you DO want that behavior, and have taken steps to ensure that any text has been sanitized before being written to that file.

Re: Getting write error - Need assistance [Re: maroon] #267708 06/09/20 07:36 PM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Thank you for your response however I've checked and the files are not write protected. Basically when clicking on the Close button that error occurs and is related to the check/uncheck of the checkbox in the list of nicks/passwords and/or list of auto join channels. The boxes are checked by default and when unchecked they do not uncheck.

; ## On CONNECT

on *:connect: {
if ($rconf(Autos,Join) = on) { .timer 1 1 _aj }
if ($rconf(Autos,Identify) = on) && ($rconf(Autos,IDevent) = connect) && ($network != UnderNet) && ($network != QuakeNet) { _id $cid }
elseif ($rconf(Autos,Identify) = on) && ($network = QuakeNet) || ($network = UnderNet) { _id $cid }
}

; ## on NOTICE

on *:notice:*:*: {
if ($rconf(Autos,Identify) = on && $rconf(Autos,IDEvent) = notice) {
if ($nick = Nickserv) {
if (*identify* iswm $1-) { _id $cid }
}
}
}

; ## Join channels on active network

alias _aj {
var %i = 1,%n = $network
while %i <= $lines($_doc(Autojoin)) {
var %r = $read($_doc(Autojoin),%i)
if ($gettok(%r,3,42) = %n) && ($gettok(%r,1,42) = 2) {
join $gettok(%r,2,42) $iif($gettok(%r,4,42),$ifmatch)
}
inc %i
}
}

; ## Identify to active nickname on active network

alias _id {
var %cid = $1
var %i = 1
while (%i <= $lines($_doc(AutoID))) {
if ($me = $gettok($read($_doc(AutoID),%i),2,42) && $network = $gettok($read($_doc(AutoID),%i),3,42)) && ($gettok($read($_doc(AutoID),%i),1,42) = 2) {
if (%cid) scid %cid $gettok($read($_doc(AutoID),%i),5-,42) $gettok($read($_doc(AutoID),%i),4,42))
else { $gettok($read($_doc(AutoID),%i),5-,42) $gettok($read($_doc(AutoID),%i),4,42)) }
}
inc %i
}
unset %cid
}

; ## Call module dialog

alias _autos { dodialog autos }

; ## Check if state is on or off (autojoin)

alias conf { if ($1) && ($2) && ($3) { writeini $+(scripts\data\autos.ini) $1 $2 $3- } | else { return } }
alias rconf { if ($1-2) { return $readini($+(scripts\data\autos.ini),$1,$2) } }
alias _doc { return $+(scripts\data\,$1,.ini) }

alias find_cboxaj {
if $dialog(autos) {
var %c = $read($_doc(AutoJoin),$calc(%_i -1)),%g = $gettok(%c,2-,42)
write -l $+ $calc(%_i -1) $_doc(AutoJoin) $gettok($did(autos,2,%_i),5,32) $+ * $+ %g
inc %_i
}
}

; ## Load autojoin information to list

alias load_aj {
if $dialog(autos) {
did -a autos 2 $gettok($1-,2,42) $chr(9) $gettok($1-,3,42) $chr(9) $iif($gettok($1-,4,42),$ifmatch,-)
did -o autos 2 %_i 0 0 0 $gettok($1-,1,42) $gettok($did(autos,2,%_i),6-,32))
inc %_i
}
}

; ## Load auto identify information to list

alias load_ai {
if $dialog(autos) {
did -a autos 8 $gettok($1-,2,42) $chr(9) $gettok($1-,3,42) $chr(9) $str(*,$len($gettok($1-,4,42))) $chr(9) $gettok($1-,5-,42)
did -o autos 8 %_i 0 0 0 $gettok($1-,1,42) $gettok($did(autos,8,%_i),6-,32))
inc %_i
}
}

; ## Check if state is on or off (auto identify)

alias find_cboxai {
if $dialog(autos) {
var %c = $read($_doc(AutoID),$calc(%_i -1)),%g = $gettok(%c,2-,42)
write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g
inc %_i
}
}

; ## Auto join/identify dialog table/events

dialog autos {
title "Auto Join/Identify"
size -1 -1 169 167
option dbu notheme
tab "Auto Join", 1, 2 31 164 117
list 2, 5 51 158 79, tab 1 size
check "Enable", 3, 5 133 37 12, tab 1 push
button "Add", 4, 86 133 37 12, tab 1
button "Delete", 5, 126 133 37 12, tab 1
tab "Auto Identify", 7
list 8, 5 51 158 79, tab 7 size
check "Enable", 9, 5 133 37 12, tab 7 push
button "Add", 10, 86 133 37 12, tab 7
button "Delete", 11, 126 133 37 12, tab 7
text "Identify on:", 12, 3 155 29 8, tab 7
combo 13, 35 153 43 50, tab 7 size drop
button "&Done", 6, 130 153 37 12, ok
text "", 14, 2 3 165 26
list 15, 143 6 21 18, disable size
text " - set up channels to join and nicknames to identify to on connect", 16, 3 13 121 13
text " Auto Join/Identify", 17, 3 5 68 7
}

on *:dialog:autos:init:0: {
dicon $dname $script
$iif(!$isfile($_doc(AutoID)),.write -c $_doc(AutoID))
$iif(!$isfile($_doc(AutoJoin)),.write -c $_doc(AutoJoin))
mdx.load
mdx SetFont $dname 2,4,5,6,8,10,11,12,13 12 550 Verdana
mdx SetFont $dname 3,9 12 700 Verdana

mdx SetFont $dname 17 -11 700 Tahoma
mdx SetColor $dname 17 text $rgb(255,255,255)

mdx SetColor $dname 14,16,17 background $rgb(111,132,161)
mdx SetColor $dname 14,16,17 textbg $rgb(111,132,161)
mdx SetBorderStyle $dname 14 staticedge

mdx SetControlMDX $dname 15 Toolbar flat wrap nodivider list > $bars
mdx SetBorderStyle $dname 15

mdx SetColor $dname 15 background $rgb(111,132,161)
did -i $dname 15 1 bmpsize 32 32
did -i $dname 15 1 setimage icon large $icon1
did -a $dname 15 +a 1 $chr(9) Nothing

mdx SetControlMDX $dname 2,8 Listview report single rowselect checkboxes > $views
did -i $dname 2 1 headerdims 130 110 72
did -i $dname 2 1 headertext Channel $chr(9) Network $chr(9) Key
did -i $dname 8 1 headerdims 100 100 90 100
did -i $dname 8 1 headertext Nickname $chr(9) Network $chr(9) Password $chr(9) String

didtok $dname 13 32 Connect Notice
$iif($rconf(Autos,Join) = on,did -c $dname 3)
$iif($rconf(Autos,Identify) = on,did -c $dname 9)
$iif($rconf(Autos,IDEvent) = connect,did -c $dname 13 1,did -c $dname 13 2)
set %_i 2
.filter -k $_doc(AutoJoin) load_aj
set %_i 2
.filter -k $_doc(AutoID) load_ai
unset %_i
}

on *:dialog:autos:sclick:4: {
var %c = $$?="Enter channel:",%n = $$?="Enter network:"
if %c && %n {
var %k = $?!="Is there a key?"
if %k = $true {
%k = $$?="Enter channel key"
write $_doc(AutoJoin) $+(2,*,%c,*,%n,*,%k)
}
else {
write $_doc(AutoJoin) $+(2,*,%c,*,%n)
}
did -r autos 2
set %_i 2
.filter -k $_doc(AutoJoin) load_aj
unset %_i
}
}

on *:dialog:autos:sclick:5: {
if $did($dname,2).sel {
var %s = $calc($ifmatch -1)
write -dl $+ %s $_doc(AutoJoin)
did -r autos 2
set %_i 2
filter -k $_doc(AutoJoin) load_aj
unset %_i
}
}

on *:dialog:autos:sclick:6: {
conf Autos Join $iif($did($dname,3).state = 1,on,off)
conf Autos Identify $iif($did($dname,9).state = 1,on,off)
conf Autos IDEvent $iif($did($dname,13).sel = 1,connect,notice)
set %_i 2
filter -k $_doc(AutoJoin) find_cboxaj
set %_i 2
filter -k $_doc(AutoID) find_cboxai
unset %_i
}

on *:dialog:autos:sclick:10: {
var %c = $$?="Enter nickname:",%n = $$?="Enter network:",%p = $$?="Enter password:",%s = $$?="Enter string to identify:"
if %c && %n && %p && %s {
write $_doc(AutoID) $+(2,*,%c,*,%n,*,%p,*,%s)
did -r autos 8
set %_i 2
.filter -k $_doc(AutoID) load_ai
unset %_i
}
}

on *:dialog:autos:sclick:11: {
if $did($dname,8).sel {
var %s = $calc($ifmatch -1)
write -dl $+ %s $_doc(AutoID)
did -r autos 8
set %_i 2
filter -k $_doc(AutoID) load_ai
unset %_i
}
}

Re: Getting write error - Need assistance [Re: Darkmnm] #267710 07/09/20 09:44 PM
Joined: Jan 2004
Posts: 1,407
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,407
I'm not seeing a problem. When you have trouble with a script, it's often helpful to insert debug messages so you can see what the parameters are as of that line. In this case, with your error happening on this line:

write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g

Then insert a line above it like:

echo -s debug: $_doc(AutoID) $lines($_doc(AutoID)) //write -l $+ $calc(%_i -1) $_doc(AutoID) $gettok($did(autos,8,%_i),5,32) $+ * $+ %g

this lets you see how many lines were in the file at the time of the write attempt, and whether the filename existed. It shows the command that you can try repeating from the command line.

Something else to try:
I notice you're trying to mix /writeini and /write to the same filename. See if it helps if you place above the offending /write commands:

flushini $_doc(AutoID)

Re: Getting write error - Need assistance [Re: maroon] #267711 07/09/20 11:32 PM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Adding your debug code inline returned the following:

debug: scripts\data\AutoID.ini 2 //write -l1 scripts\data\AutoID.ini 2*#Outlawz*MircScripts

Basically the 2 = Checked Box (active) * #Outlawz = Channel to join on connect * MircScripts = Network connecting to

the 2 should change to a 1 if I uncheck the channel #Outlawz to join on the network MircScripts but whenever I close the Close button on the dialog the error occurs and the 2 (checked/active) in the file does not change to a 1 (unchecked/inactive)

The close button is number 6. When clicked it should check the options for checked/unchecked boxes and if unchecked set value 2 to 1 (inactive) and if checked set 1 to 2 (active) which enables that nickname to be identified to that network on connect.

on *:dialog:autos:sclick:6: {
conf Autos Join $iif($did($dname,3).state = 1,on,off)
conf Autos Identify $iif($did($dname,9).state = 1,on,off)
conf Autos IDEvent $iif($did($dname,13).sel = 1,connect,notice)
set %_i 2
filter -k $_doc(AutoJoin) find_cboxaj
set %_i 2
filter -k $_doc(AutoID) find_cboxai
unset %_i
}

Re: Getting write error - Need assistance [Re: maroon] #267712 08/09/20 05:02 AM
Joined: Jan 2004
Posts: 1,407
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,407
Update. The problem is that you're using the -k switch with filter to write to the input file, which isn't permitted.

Run this alias and the red echo shows there is only 1 line. However remove either of the semi-colons, and the red echo now shows 3 lines. That means my debug command which includes the command to show the number of lines in the file could alter the effect of a script because it flushes the cache to disk.

//.remove test.ini | writeini test.ini section item value | writeini test.ini section item2 value2 | ;flushini test.ini | ;echo 3 -a $lines(test.ini) | write -l3 test.ini foo | echo 4 -a $lines(test.ini)

now insert this alias into a remote script:

alias foofilter {
if (!%inc_i) set -u99 %inc_i 2
flushini test.ini
echo -a $1-
write -l $+ %inc_i test.ini value $+ %inc_i $+ = $+ %inc_i
inc %inc_i
}

and then run the command:

/filter -k test.ini foofilter

and your error message will display. Inserting a "flushini test.ini" won't hold the error at bay either. Instead, your -k alias needs to examine the $1 to decide whether to /return $1 unchanged, or to return altered contents.

Re: Getting write error - Need assistance [Re: maroon] #267716 08/09/20 06:57 PM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Update: I've added the alias and run the commands with the following return.

1
foo
-
* /write: error writing 'C:\Users\User Name\AppData\Roaming\mIRC\test.ini' (line 100, AutoIJ_Remote.ini)

I appreciate your assistance but I haven't done anything with scripting in such a long time so I may just end up scraping it.

Re: Getting write error - Need assistance [Re: Darkmnm] #267717 08/09/20 10:44 PM
Joined: Dec 2002
Posts: 4,824
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,824
Quote
* /write: error writing 'C:\Users\User Name\AppData\Roaming\mIRC\test.ini' (line 100, AutoIJ_Remote.ini)

Run mIRC and, in the status window, type //run $mircdir and press the enter key. This will open the mIRC AppData folder in an explorer window. Now try copying a file in explorer. For example, right-click mirc.ini, select copy, and then right-click in the folder and select paste. Does it create a copy of the mirc.ini file? If it does, then it probably is not a permissions or read-only issue.

Are you running anti-virus software? If so, it could be blocking mIRC. If you disable your anti-virus software, or add an exception for mIRC, does that resolve the issue?

Re: Getting write error - Need assistance [Re: Khaled] #267718 08/09/20 11:37 PM
Joined: Jan 2004
Posts: 1,407
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,407
His issue was executing my sample alias. When the /filter -k alias is using the /write command to write back to the input file, that's when this error happens. Nothing related to the folder's write permissions.

Re: Getting write error - Need assistance [Re: maroon] #267719 09/09/20 12:32 AM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Yes, Maroon explains it perfectly. Not sure exactly why it is not writing/updating the ini file once it's created. When there is a 2* in the ini file the checkbox in the edit box of the dialog is checked and if I manually change the 2* to a 1* in the ini file then open the dialog the checkbox is now unchecked. For some odd reason there is something in the code I cannot see that is not allowing the write/update to the ini file via the dialog.

Re: Getting write error - Need assistance [Re: Khaled] #267720 09/09/20 12:43 AM
Joined: Mar 2004
Posts: 155
D
Darkmnm Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Mar 2004
Posts: 155
Hey Khaled, thanks for the reply. Great piece of software and I have loved the updates throughout the years. I have confirmed all permissions and antivirus aren't causing this issue.