AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Updating a compiled application

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Thalon



Joined: 12 Jul 2005
Posts: 640

PostPosted: Mon Jul 18, 2005 10:27 am    Post subject: Updating a compiled application Reply with quote

Hi!

I do not know if anyone else needs it, but I wrote an Exe-File, which takes Sourcecode from other files and if they change it is updated automatically by simply starting it (works without AHK installed)..
I thought it as a nice feature for other users for some of my applications..
Maybe someone else likes it...

You can download a sample-application (1 MB, I know quite big! Sad ), where Font and controls can be changed (in source) also by users which do not have ahk!:
Download Update-exe.zip (see below) and press <dl>

I know it is just a little example, but so it is possible to create applications which can be completely cah

Short description:
On starting EXE the modifydates of include-files are compared with the dates in an ini-file. If nothing has changed -> Start Application.
If an Include-file has been changed the script is decompiled (Include-Code is removed in decompiled file), recompiled and started again.
If user did anything wrong when changing an Includefile and the exe can't be started any more run Recover.exe, which resets Updating-exe.exe and sets all Includes to modified.

The Zip-File contains a list of files so here is the description (Sourcecode see below):
Updating-exe.exe - This is the application itself, which updates it's sourcecode if any Includefile changes
DS-Tool.ico - The Icon which is used for the application
Recover.exe - Recovers the tool if an error occured after changing Include-file
Sub-Folder Compiler:
Re-Compile.exe - Manages decompile, sourcecleaning, recompile and restarting
Other Files to decompile and compile (Can be also found in AutoHotkey-Folder and Homepage)
Subfolder Includes:
IncludeColor.myinc - Testincludefile for changing font-settings
IncludeControls.myinc - Testincludefile for changing/adding controls
IncludeEvents.myinc - Testincludefile for events (like pressing a button)
Includes.ini - Contains include-modify-dates for comparing


Here is the little commented source-code:
Updating-exe.exe:
Code:
;Reading modifydates of includes, which were actual last time starting application (for comparing with 'real' modify-dates)
IniRead, Last_IncludeColor_Date, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeColor
IniRead, Last_IncludeControls_Date, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeControls
IniRead, Last_IncludeEvents_Date, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeEvents
;Reading modifydates of includes
FileGetTime, IncludeColor_Date, %A_ScriptDir%\Includes\IncludeColor.myinc, M
FileGetTime, IncludeControls_Date, %A_ScriptDir%\Includes\IncludeControls.myinc, M
FileGetTime, IncludeEvents_Date, %A_ScriptDir%\Includes\IncludeEvents.myinc, M


;If dates differe set flag to recompile and update timestamp in ini-file
if Last_IncludeColor_Date != %IncludeColor_Date%
{
   IniWrite, %IncludeColor_Date%, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeColor
   IncludesChanged = 1
}

if Last_IncludeControls_Date != %IncludeControls_Date%
{
   IniWrite, %IncludeControls_Date%, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeControls
   IncludesChanged = 1
}

if Last_IncludeEvents_Date != %IncludeEvents_Date%
{
   IniWrite, %IncludeEvents_Date%, %A_ScriptDir%\Includes\Includes.ini, IncludeDates, IncludeEvents
   IncludesChanged = 1
}



if IncludesChanged = 1   ;If any include-file changed the application has to be recompiled for update
{
   OnExit, Recompile
   StringReplace, Ahk_Name, A_Scriptname, .exe, .ahk, All
   ExitApp
}


;Change Font
#include %A_ScriptDir%\Includes\IncludeColor.myinc

;Adding Controls
#include %A_ScriptDir%\Includes\IncludeControls.myinc

Gui, Show
return

;Adding Events
#include %A_ScriptDir%\Includes\IncludeEvents.myinc


Recompile:   ;Starts the application to recompile script
Run, %A_ScriptDir%\Compiler\Re-Compile.exe "%A_ScriptFullPath%" "%A_ScriptDir%\%Ahk_Name%" "%A_ScriptDir%\DS-Tool.ico"
GuiClose:
ExitApp


Recompile.exe:
Code:
;Path of exe to decompile = %1%
;Path of decompiled ahk = %2%
;Icon-Path = %3%

;Decompile, for testing purposes maybe comment password out!
RunWait, %A_ScriptDir%\Exe2Ahk.exe "%1%" "Password with spaces"

;Remove Include-Contents, ReEnable #Include
FileRead, FileContents, %2%
FileDelete, %2%      ;Delete file - will be created new...

;In the decompiled ahk the text of the includes is written into ahk-file and original '#include file' is commented out.
;To load changed contents of include you have to delete old contents and remove ';' before '#include file'
Loop, Parse, FileContents, `n, `r
{
   LoopFieldContent = %A_LoopField%
   IfInString, LoopFieldContent, BeginInclude
      RemoveLines = 1      ;Set Flag to delete all following lines, until commented out #include is found (see below)

   IfInString, A_LoopField, `; #include
   {
      StringReplace, LoopFieldContent, LoopFieldContent, `; #include, #include
      RemoveLines = 0
   }
   if RemoveLines != 1
      FileAppend, %LoopFieldContent%`n, %2%
      
}

;Recompile, for testing purposes maybe comment password out!
RunWait,"%A_ScriptDir%\Ahk2Exe.exe" /in "%2%" /icon "%3%" /pass "Password with spaces"


;ReRun updated exe
Run, %1%

;Delete not needed ahk-file
FileDelete, %2%
ExitApp


Recover.exe:
Code:
FileInstall, C:\Dokumente und Einstellungen\Mareschg.BRATEGGE\Desktop\Updating-Exe.exe\Updating-Exe.exe, %A_ScriptDir%\Updating-exe.exe, 1
FileInstall, C:\Dokumente und Einstellungen\Mareschg.BRATEGGE\Desktop\Updating-Exe.exe\Includes\Includes.ini, %A_ScriptDir%\Includes\Includes.ini, 1

Little comment for the first line of all includes:
I think you wonder why the includes start with something like: 'BeginIncludeColor = BeginIncludeColor'.
This line doesn't anything, but is needed to find the begin of the include in decompiled ahk-file.

I know the description is short, so feel free to ask if there is interest!

Thalon
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group