Sign in to follow this  
Followers 0

V3 to V2 Conversion? :)

6 posts in this topic

Posted

I just wanted to create a smaller version of an executable i wrote in AutoIT3. If anyone can convert the following into v2 syntax, I'd be very grateful :)

#NoTrayIcon
Sleep ( 10 )
FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" )
If @Error=1 Then
	MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" )
	Exit
EndIf
If ProcessExists ( "GameLauncherTRAY.exe" ) Then
	Sleep ( 10 )
	Run ( @ScriptDir & "\GameLauncherTRAY.exe" )
Else
	Run ( @ScriptDir & "\GameLauncherTRAY.exe" )
EndIf
Exit

Share this post


Link to post
Share on other sites



Posted

I just wanted to create a smaller version of an executable i wrote in AutoIT3. If anyone can convert the following into v2 syntax, I'd be very grateful :)

#NoTrayIcon
 Sleep ( 10 )
 FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" )
 If @Error=1 Then
	 MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" )
	 Exit
 EndIf
 If ProcessExists ( "GameLauncherTRAY.exe" ) Then
	 Sleep ( 10 )
	 Run ( @ScriptDir & "\GameLauncherTRAY.exe" )
 Else
	 Run ( @ScriptDir & "\GameLauncherTRAY.exe" )
 EndIf
 Exit
How about converting it into a non-retarded script first?

  • Let's start at the top. You have a sleep so small it does no good, and it's the first line of the script. Why?
  • You want to know if a file exists but you check it's attributes instead of using FileExists(). Why?
  • The If ProcessExists() block is really bad. First, you have duplicate code. You don't need 2 run statements, you only need 1. The only thing you want to do if the process exists is sleep a little. That brings me to the second point, the sleep statement is so short it does nothing. The If structure can be removed and just use a Run() statement.
  • You used Exit as the line line of the script. Why? What else can the script do?
You have about a 4-line script you've inflated to 14. Maybe if you cut it down to the 3 or 4 lines it should be, you can convert it yourself?

Share this post


Link to post
Share on other sites

Posted (edited)

I'm sorry if i'm very new to AutoIT Valik, but calling my script retarded, even though it serves its purpose very well, isn't the best way to introduce someone to the forum ...

For the sake of receiving some sort of response, i cut the script down for you ...

#NoTrayIcon
FileGetAttrib ( @ScriptDir & "\GameLauncherTRAY.exe" )
If @Error=1 Then
	 MsgBox ( 48 , "Error!" , "GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to 'GameLauncherTRAY.exe'" )
	 Exit
ElseIf ProcessExists ( "GameLauncherTRAY.exe" ) Then
	 Sleep ( 10 )
EndIf
Run ( @ScriptDir & "\GameLauncherTRAY.exe" )

The sleep is there to give the program time to terminate Valik, i tested the script multiple times without the sleep and sometimes GameLauncherTRAY won't run because it's already running (i have a statement at the start of the GameLauncherTRAY script which detects if it's running and if it is, it terminates with a MsgBox saying it's already running).

I've also converted some of it into v2 syntax, but i'm just wondering ... how do i use the A_SCRIPTDIR special variable in the run statement? Is it the same as @ScriptDir? e.g. Run ( @ScriptDir & "\MyFile.exe" )

Edited by SxyfrG

Share this post


Link to post
Share on other sites

Posted

You only listened to half of what I said. You changed the code around, it's not really any better. And you're trying to wait on a process to close with a sleep time so small that it's pure luck that it works.

#NoTrayIcon
Local Const $sExe = "GameLauncherTRAY.exe"
Local Const $sFile = @ScriptDir & "\" & $sExe
If FileExists($sFile) Then
	If ProcessExists($Exe) Then ProcessWaitClose($sExe)
	Run($sFile)
Else
	 MsgBox ( 48 , "Error!" , $sExe & " not found! Please make sure you have not renamed it. If you have, rename it back to '" & $sExe & "'" )
EndIf

It's ironic to me that you want a small executable but aren't concerned about code that takes a round-about way to it's destination.

Share this post


Link to post
Share on other sites

Posted

I see what you're saying, and i thank you for the supplied code, but i still haven't figured out how to use the A_SCRIPTDIR special variable for v2 syntax :S

Share this post


Link to post
Share on other sites

Posted (edited)

Here is base syntax (not tested):

HideAutoItWin, on
HideAutoItDebug, on

IfNotExist, %A_SCRIPTDIR%\\GameLauncherTRAY.exe, Goto, Error1
;If ProcessExists($Exe) Then ProcessWaitClose($sExe)
;Run, GameLauncherTRAY.exe
Run, %A_SCRIPTDIR%\\GameLauncherTRAY.exe
Exit

Error1:
MsgBox, 48, Error!, GameLauncherTRAY.exe not found! Please make sure you have not renamed it. If you have, rename it back to GameLauncherTRAY.exe
Exit

There is no alternative for ProcessExists as far as I know. You can use only similar IfWinNotExist.

Edited by Zedna

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0