Posted: Mon Feb 11, 2002 7:19 am
Restored from previous forum. Originally posted by Roxxler.
Hi,
here once again the procedure OwnWBStartup() with a little change.
For information how the procedure works see the old one.
Changes in the procedure:
1. the line "Shared MyWBArg" is replaced with "Shared MyWBArg, oldlockbefore"
another shared variable to store the old dir which was the current dir
before we change it
2. the line "CurrentDir_(MyWBArg()\filelock)" is replaced with this one:
"oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)"
this command sets our programdir as currentdir and stores the dir which
was the old currentdir in our variable
Changes in the example program:
1. the line "CurrentDir_(oldlockbefore)" is insert before the line
"ReplyMsg_(message)"
with this we set the currentdir back to the dir which was the current dir
before our program runs and changed it
Why this ?
You know this: download a program archive from aminet etc. unpacking it
and start the program to have a look. after that you want delete the
program directory and this failed with an error like "Cannot delete,
because object is in use". In many many times the reason is that
the program dir ist still the currentdir.
To avoid this i have changed the procedure.
Procedure.l OwnWBStartup()
owntask.l=FindTask_(0)
prcli.l=PeekL(owntask+172)
If prcli=0
messageport.l=owntask+92
WaitPort_(messageport)
wbstartupmessage.l=GetMsg_(messageport)
If wbstartupmessage0
Structure WBArgs
filelock.l
namearg.s
EndStructure
NewList MyWBArg.WBArgs()
Shared MyWBArg, oldlockbefore
numargs.l=PeekL(wbstartupmessage+28)
ptrwbarg.l=PeekL(wbstartupmessage+36)
For i.w=1 To numargs
AddElement(MyWBArg())
MyWBArg()\filelock=PeekL(ptrwbarg)
MyWBArg()\namearg=PeekS(PeekL(ptrwbarg+4))
ptrwbarg+8
Next i
FirstElement(MyWBArg())
oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)
EndIf
Else
ProcedureReturn 0
EndIf
ProcedureReturn wbstartupmessage
EndProcedure
ExecBase.l=OpenExecLibrary_(36)
DosBase.l=OpenDosLibrary_(36)
If ExecBase0 And DosBase0
message.l=OwnWBStartup()
If message=0
PrintN("This program ist started from CLI")
Else
numofarg.w=CountList(MyWBArg())
text$="The program is started from WB"+Chr(10)
text$+"Program name is »"+MyWBArg()\namearg+"«"+Chr(10)
text$+"There are "+Str(numofarg)+" argument(s) (the first is the started program)."+Chr(10)+Chr(10)
text$+"Here the arguments:"+Chr(10)
Repeat
text$+MyWBArg()\namearg+Chr(10)
Until NextElement(MyWBArg())=0
EasyRequester("Info",text$,"ok")
CurrentDir_(oldlockbefore)
ReplyMsg_(message)
EndIf
Else
PrintN("Cannot open exec/dos.library")
EndIf
End
Greetings ..
Roxxler
Hi,
here once again the procedure OwnWBStartup() with a little change.
For information how the procedure works see the old one.
Changes in the procedure:
1. the line "Shared MyWBArg" is replaced with "Shared MyWBArg, oldlockbefore"
another shared variable to store the old dir which was the current dir
before we change it
2. the line "CurrentDir_(MyWBArg()\filelock)" is replaced with this one:
"oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)"
this command sets our programdir as currentdir and stores the dir which
was the old currentdir in our variable
Changes in the example program:
1. the line "CurrentDir_(oldlockbefore)" is insert before the line
"ReplyMsg_(message)"
with this we set the currentdir back to the dir which was the current dir
before our program runs and changed it
Why this ?
You know this: download a program archive from aminet etc. unpacking it
and start the program to have a look. after that you want delete the
program directory and this failed with an error like "Cannot delete,
because object is in use". In many many times the reason is that
the program dir ist still the currentdir.
To avoid this i have changed the procedure.
Procedure.l OwnWBStartup()
owntask.l=FindTask_(0)
prcli.l=PeekL(owntask+172)
If prcli=0
messageport.l=owntask+92
WaitPort_(messageport)
wbstartupmessage.l=GetMsg_(messageport)
If wbstartupmessage0
Structure WBArgs
filelock.l
namearg.s
EndStructure
NewList MyWBArg.WBArgs()
Shared MyWBArg, oldlockbefore
numargs.l=PeekL(wbstartupmessage+28)
ptrwbarg.l=PeekL(wbstartupmessage+36)
For i.w=1 To numargs
AddElement(MyWBArg())
MyWBArg()\filelock=PeekL(ptrwbarg)
MyWBArg()\namearg=PeekS(PeekL(ptrwbarg+4))
ptrwbarg+8
Next i
FirstElement(MyWBArg())
oldlockbefore.l=CurrentDir_(MyWBArg()\filelock)
EndIf
Else
ProcedureReturn 0
EndIf
ProcedureReturn wbstartupmessage
EndProcedure
ExecBase.l=OpenExecLibrary_(36)
DosBase.l=OpenDosLibrary_(36)
If ExecBase0 And DosBase0
message.l=OwnWBStartup()
If message=0
PrintN("This program ist started from CLI")
Else
numofarg.w=CountList(MyWBArg())
text$="The program is started from WB"+Chr(10)
text$+"Program name is »"+MyWBArg()\namearg+"«"+Chr(10)
text$+"There are "+Str(numofarg)+" argument(s) (the first is the started program)."+Chr(10)+Chr(10)
text$+"Here the arguments:"+Chr(10)
Repeat
text$+MyWBArg()\namearg+Chr(10)
Until NextElement(MyWBArg())=0
EasyRequester("Info",text$,"ok")
CurrentDir_(oldlockbefore)
ReplyMsg_(message)
EndIf
Else
PrintN("Cannot open exec/dos.library")
EndIf
End
Greetings ..
Roxxler