AHK Studio

Editor for AutoHotkey written completely in AutoHotkey.

Moderator: maestrith

User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

AHK Studio

16 Oct 2013, 14:14

Image
Special thanks to tidbit for the logo

New GUI design and updated indent system.
NOTICE!
Requires AHK v1.1.23.03 or any version of 1.x greater than 23.03
I am still working on getting all of the functionality back into it from the previous version but it is stable enough to use.
Download:
Currently it is only in AHK 1.1 un-compiled.
also a Zip can be downloaded here.

Videos:
A Short Demo
Video tutorial on how to use the Personal Variable List
Using Replacements

The second two videos require plugins that can be downloaded from the Tools/Download Plugins menu

Image

If you are having trouble getting Studio to download I have a mirror on Github. Github

Usage:
If you wish to use this software, great.

If you wish to use this as a part of your project I require payment.

If you wish to donate to help me with my living expenses donations are always welcome

PLEASE let me know if there is anything I should work on getting back in.


Sorry I have been away and I will do what I can to update/add some screenshots.

AHK Studio uses SciLexer.dll to provide a quick and easy way to program AutoHotkey scripts.

Features:
  1. Run scripts from the File/Run or File/Run x64 (for those who use the 32 bit install).
  2. Easy customization of themes Edit/Theme with a few that have been created by users. I will gladly add any themes that are submitted to me.
  3. Automatic help text for most commands (eg MsgBox, Control, SplashText...etc).
  4. Code Vault for adding code snippets to the program.
  5. Version Tracker with Github upload.
  6. Gist post your scripts.
  7. Split up projects into Segments to keep things neat under File/New Segment. (makes an include file)
  8. Special functions (Move Selected Lines Down, Create Comment Block, Character Count...etc)
  9. Msgbox Creator for easily creating more complex msgboxs.
  10. Personal Variable List: You can add anything to this list and it will come up with the list of other commands as you type them.
  11. Custom Highlight List: You can add anything to this list as well and it will change the color that it appears in the program.
  12. Customize every action with a hotkey, many of them are already assigned but they can be changed under Edit/Settings.
  13. FTP integration.
  14. Auto Insert: by default it will add, <> for <, [] for [, {} for {, () for (, and '' for '
  15. Quite a few more.
Let me know what you think. I am always interested in hearing ideas to add to the script or any bugs. Thank you.
Online Documentation
Last edited by maestrith on 21 Apr 2016, 02:20, edited 33 times in total.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

16 Oct 2013, 19:03

welcome maestrith! ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

16 Oct 2013, 19:34

welcome maestrith! ;)
Thanks joedf. I have forgotten how to use the default forum :)
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: AHK Studio

25 Oct 2013, 07:45

Very nice.
I am going to take a look. :)

Are working fine the themes? When I try download one I get this message

Image

Then, I get this when I select the downloaded theme

Image

For example, in what colour has the command msgbox appear?

Thanks!
Everything is possible!
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

03 Nov 2013, 09:14

In the theme Hat Of God I believe that all of the colors are the same. you can change them by clicking on any word in line 12 after Commands = and it will allow you to change the colors. Just be sure to use Save As and create a new theme or it will forget if you happen to click on the Hat Of God theme again. Thank you for trying out the program :) I hope that it is helpful.

As far as the error, I will try to write the program not using the class. Thank you for pointing this out.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

03 Nov 2013, 09:50

Yeah, i think i have to update my themes for ahk studio also,
They are a bit out of date :P i will make Monokai & PlasticCodeWrap available
And functioning properly for the current version of AHK Studio. ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

03 Nov 2013, 09:54

Yeah, i think i have to update my themes for ahk studio also,
They are a bit out of date :P i will make Monokai & PlasticCodeWrap available
And functioning properly for the current version of AHK Studio. ;)
Thank you for the help! I am always looking for new themes to use and also to add them to the list available to everyone to use. I think that I am going to re-write a bit of the download code so that it does not need to have an image preview, rather it will just change the currently used theme to the one on the server.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

03 Nov 2013, 09:55

Cool! :D
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

03 Nov 2013, 11:06

0.001.52
Changed: Thanks to the bug reported by empardopo
-Removed the preview for downloading themes and just made them automatically add when you click on them.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

03 Nov 2013, 13:58

The theme xml settings are so confusing :(
Could i have a list of all the style numbers?
eg. 33 is LineNumbers, etc. ?
also i prefer saving the colors only as Hexadecimal , not Decimal...
Thanks, also, why store the colors as BGR and not RGB that is also very confusing...

Anyways, i did get it to sorta work, the closest possible that i could get ..
Monokai: https://github.com/joedf/PlasticCodeWra ... onokai.xml
PlasticCodeWrap: https://github.com/joedf/PlasticCodeWra ... deWrap.xml

cheers ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: AHK Studio

03 Nov 2013, 14:13

0.001.52
Changed: Thanks to the bug reported by empardopo
-Removed the preview for downloading themes and just made them automatically add when you click on them.
Oh Perfect!
Congratulations! Very good job! :)
Everything is possible!
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

03 Nov 2013, 15:27

The theme xml settings are so confusing :(
Could i have a list of all the style numbers?
eg. 33 is LineNumbers, etc. ?
also i prefer saving the colors only as Hexadecimal , not Decimal...
Thanks, also, why store the colors as BGR and not RGB that is also very confusing...

Anyways, i did get it to sorta work, the closest possible that i could get ..
Monokai: https://github.com/joedf/PlasticCodeWra ... onokai.xml
PlasticCodeWrap: https://github.com/joedf/PlasticCodeWra ... deWrap.xml

cheers ;)
As far as the BGR rather than RGB storage goes SciLexer.dll uses the codes in BGR format and I guess I am lazy ;) I love the new themes! They are now online to be downloaded through the program. I will see if I can make an easy way to add RGB colors with Hex codes. If it requires a total re-write to do so I do not know if I will be able to change it though.

As far as the color codes I will have to compile a list because honestly I forget what they all are. I have been moving and under a lot of stress and that has pretty much triggered a reset in my brain so I will have to figure out what all of the codes are.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

03 Nov 2013, 17:16

rgb2bgr : vice versa (an old post by you: http://www.autohotkey.com/board/topic/6 ... rgb-issue/)
  • here's a fork:

    Code: Select all

    color:=0xAABBCC
    msgbox % color:=FlipBlueAndRed(color) ;should print 0xCCBBAA
    msgbox % color:=FlipBlueAndRed(color) ;should print 0xAABBCC
    
    FlipBlueAndRed(c)
    {
       oldfrmt := A_FormatInteger
       SetFormat integer , Hex
       x:=(c&255)<<16 | (c&65280) | (c>>16)
       SetFormat, Integer, %oldfrmt%
       return x
    }
Color codes : ill figure them out... one by one... if there's ever an issue ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

23 Jan 2014, 08:35

Sorry this took so long joedf.

Code: Select all

msgbox % rgb(0xff00cc) ;Displays 0xCC00FF
msgbox % rgb(16711935) ;Displays 0xFF00FF
rgb(c){
	setformat,IntegerFast,H
	c:=(c&255)<<16|(c&65280)|(c>>16),c:=SubStr(c,1)
	SetFormat, integerfast,D
	return c
}
That was some old code that I had. Works the same as the one above just a bit smaller. Anyway I hope that it helps. I had my hard drive crash and I lost all of my scripts. I have spent the last few weeks re-writing a lot of what I had from scratch. :/
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: AHK Studio

23 Jan 2014, 11:34

I suggest backing up continuously to a flash drive using the script below:
I had my hard drive crash and I lost all of my scripts. I have spent the last few weeks re-writing a lot of what I had from scratch. :/

Code: Select all

; http://ahkscript.org/boards/viewtopic.php?f=6&t=1288

/*
this is an old script, from the old forum, that allows to synchronize (mirroring or not) two directories. I ported it to Unicode adding support for long paths. It's FAST and has a lot of features:

    Normal synchronization
    Mirror synchronization (deleted source files are deleted on destination)
    Gracefully stoppable synchronization
    Exclusions of absolute paths and file/directory names for both the sync operations
    Logging
    Simulation
    Stacking GUI for multiple scripts running
    Low priority mode
    Quiet mode

The ANSI CopyFileEx has a limit of MAX_PATH = 260 chars. With the Unicode version the limit is 32,767 chars.

This is the code, give it a couple of test run before using it for important stuff.

The copy should work correctly, but I don't know if commands like FileDelete, FileRemoveDir, etc. support it. I will do some tests...
*/

; ----------------------------------------------------------------------------------------------------------------------
; Name .........: SuperSynchronizer
; Description ..: A little script for incremental/mirror directory backup.
; AHK Version ..: AHK_L 1.1.13.01 x32 Unicode
; Author .......: Cyruz - http://ciroprincipe.info
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Oct. 20, 2011 - v0.1 - Fixed some inconsistences with reverse check exclusions.
; ..............: Oct. 26, 2011 - v0.2 - Fixed a parenthesis glitch and a problem with the reverse check routine where a
; ..............:                        file in destination side doesn't get updated if it's newer than the source side
; ..............:                        causing an incorrect mirroring. Adjusted some comments.
; ..............: May  25, 2013 - v1.0 - Code refactoring, improved logging, stacking gui, multiscript capabilities,
; ..............:                        large files handling.
; ..............: Jan. 06, 2014 - v1.1 - Code refactoring, Unicode and long path support, added simulation feature.
; ..............: Jan. 07, 2014 - v1.1 - Added exclusions by file extension.
; Functioning ..: The script is structured in two phases:
; ..............: 1. REPLICATION CHECK
; ..............:    The files on the DESTINATION SIDE are synchronized with the files on the SOURCE SIDE.
; ..............: 2. REVERSE CHECK
; ..............:    The files on the DESTINATION SIDE that don't exist on SOURCE SIDE are deleted.
; ..............:    The script can be instantiated multiple times, and the GUI will stack automatically starting from
; ..............:    the TOP-RIGHT corner. A detailed log file is createad by default in A_ScriptDir.
; How to use ...: [] Set the source and destination directory, set copy mode (enable/disable mirroring) and logging.
; ..............: [] To exclude files from the replication or reverse check, add them to the exclusion lists.
; ..............: [] Run the script. If you need to stop the script, flag "Sure?" checkbox and click "Stop" button.
; ..............: [] [] If you stop the script, the the actual processed file is deleted to allow a clean restart.
; ..............: [] The script can be run avoiding any user interaction passing the "-quiet" parameter on command line.
; ..............: [] [] If you close/exit/kill the script it will behave like if the script is stopped.
; ----------------------------------------------------------------------------------------------------------------------

;#NoTrayIcon
#Persistent
#SingleInstance Off
DetectHiddenWindows, On
SetTitleMatchMode, 2

; ======================================================================================================================
; ===[ VARIABLES SECTION ]==============================================================================================
; ======================================================================================================================

; SOURCE DIRECTORY
; [ STRING, ABSOLUTE PATH, NO QUOTES ]
SOURCE_DIR = D:\Test

; DESTINATION DIRECTORIES
; [ STRING, ABSOLUTE PATH, NO QUOTES ]
DESTIN_DIR = D:\TestDest

; MIRRORING - DELETE DESTINATION FILE NOT PRESENT ON SOURCE
; [ 1: ENABLED, 0: DISABLED ]
MIRRORING := 1

; SIMULATION - JUST SIMULATE THE SYNC AND UPDATE THE LOG FILE
; [ 1: ENABLED, 0: DISABLED ]
SIMULATION := 1

; LOGGING
; [ 1: ENABLED, 0: DISABLED ]
LOG_ENABLED := 1

; LOG FILE - ONLY IF LOG_ENABLED == 1, DEFAULT TO %A_ScriptDir%\%A_ScriptName%.log
; [ STRING, ABSOLUTE PATH, NO QUOTES ]
LOG_FILE =

; INTERACTIVE FLAG - USER INTERACTIVE GUI, OVERRIDE WITH "-quiet" PARAMETER
; [ 1: ENABLED, 0: DISABLED ]
INTERACTIVE := 1

; LOW PRIORITY
; [ 1: ENABLED, 0: DISABLED ]
LOW_PRIORITY := 0

; REPLICATION CHECK GLOBAL EXCLUSIONS - ITEMS NOT TO BE COPIED ON DESTINATION SIDE
; [ CONTINUATION SECTION, NEWLINE SEPARATED, NO QUOTES, SURROUNDED BY <>, FULL PATH OR NAME ]
; Excluded directories.
EX_REPLICATION_DIRS =
( LTrim
)
; Excluded files.
EX_REPLICATION_FILES =
( LTrim
)
; Excluded extensions.
EX_REPLICATION_EXT =
( LTrim
)

; REVERSE CHECK GLOBAL EXCLUSIONS - ITEMS NOT TO BE DELETED ON DESTINATION SIDE
; [ CONTINUATION SECTION, NEWLINE SEPARATED, NO QUOTES, SURROUNDED BY <>, FULL PATH OR NAME ]
; Excluded directories.
EX_REVERSE_DIRS =
( LTrim
)
; Excluded files.
EX_REVERSE_FILES =
( LTrim
)
; Excluded extensions.
EX_REVERSE_EXT =
( LTrim
)

; ======================================================================================================================
; ===[ MAIN SECTION ]===================================================================================================
; ======================================================================================================================

; Parameters check.
param0 = %0%
param1 = %1%
If ( param0 == 0 )
    INTERACTIVE := 1
Else If ( param0 == 1 && param1 == "-quiet" )
    INTERACTIVE := 0
Else
{
    MsgBox,, SuperSynchronizer, Usage:`t<AutoHotkey.exe SuperSynchronizer.ahk>`n`t-quiet :: Suppress any message
    ExitApp
}

; Script start check.
If ( INTERACTIVE )
{
    Msgbox, 0x4, SuperSynchronizer, FROM:`t%SOURCE_DIR%`nTO:`t%DESTIN_DIR%`n`nStart Synchronizing?
    IfMsgBox, No
        ExitApp
}

; Source folder check.
If ( !InStr(FileExist(SOURCE_DIR), "D") )
{
    If ( INTERACTIVE )
        MsgBox,, SuperSynchronizer, Source folder doesn't exists!
    ExitApp ; Fail if source folder doesn't exists.
}

; Destination folder check.
If ( !InStr(FileExist(DESTIN_DIR), "D") )
{
    If ( SIMULATION )
    {
            MsgBox,, SuperSynchronizer, Cannot simulate if destination directory is not existing.
            ExitApp
    }
    If (INTERACTIVE)
    {
        Msgbox, 0x4, SuperSynchronizer, Destination folder doesn't exists, create it?
        IfMsgBox, No
            ExitApp
        FileCreateDir, %DESTIN_DIR%
    }
    Else ExitApp ; Fail silently if destination folder doesn't exists and !INTERACTIVE.
}

; If SIMULATION == 1, force the LOGGING to 1.
(SIMULATION) ? LOG_ENABLED := 1

; Modify the OnExit so that the "Stop" feature is correctly handled.
OnExit, STOPSYNC

; Adjust the priority of the current process.
nPid := DllCall("GetCurrentProcessId")
Process, Priority, %nPid%, % (LOW_PRIORITY) ? "L" : "N"

; Create the callback for the stop feature.
COPY_CALLBACK := RegisterCallback("CopyCallback", "Fast")

; Set STOP_SYNC = 0 to start the copy operation (flag "Sure?" and press "Stop" to turn STOP_SYNC = 1).
STOP_SYNC := 0

If ( INTERACTIVE )
{   ; Get monitor resolution and previous windows to calculate the coordinates.
    SysGet, Mon, Monitor
    _X := MonRight - 388
    WinGet, hWndList, LIST, SuperSynchronizer ahk_class AutoHotkeyGUI
    _Y := (75 * hWndList) + 1

    ; Gui management.
    Gui, +LastFound +Hwndh_GUI
    WinSet, Transparent, 240, ahk_id %h_GUI%
    Gui, Margin, 10, 10
    Gui, Add, Text, vSyncText Left w300 h55, Replicating...`n`nFROM:`t%SOURCE_DIR%`nTO:`t%DESTIN_DIR%
    GuiControl, -Wrap, SyncText
    Gui, Add, Checkbox, vAreYouSure x+15 y22, Sure?
    Gui, Add, Button, gSTOPSYNC vSyncButton w50 h20 y+10, &Stop
    Gui, -Caption +Border
    Gui, Show, X%_X% Y%_Y% Autosize, SuperSynchronizer
}

; Get start timestamp.
START_TIMESTAMP = %A_Now%

; !!! REPLICATION CHECK START !!!
; ----------------------------------------------------------------------------------------------------------------------
If ( LOG_ENABLED ) ; Log management.
    WriteLog(1, "REPLICATION CHECK STARTED`n****************************************************************`n")

SetWorkingDir, %SOURCE_DIR%
bSyncStopped := ReplicationCheck("*.*")
; ----------------------------------------------------------------------------------------------------------------------

; !!! REVERSE CHECK START !!!
; ----------------------------------------------------------------------------------------------------------------------
If ( MIRRORING && !bSyncStopped )
{
    If ( INTERACTIVE )
        GuiControl,, SyncText, Mirroring...`n`nFROM:`t%SOURCE_DIR%`nTO:`t%DESTIN_DIR%

    If ( LOG_ENABLED ) ; Log management.
        WriteLog(0, "`n")
      , WriteLog(1, "REVERSE CHECK STARTED`n****************************************************************`n")
   
    SetWorkingDir, %DESTIN_DIR%
    bSyncStopped := ReverseCheck("*.*")
}
; ----------------------------------------------------------------------------------------------------------------------

; Get end timestamp and calculate elapsed time.
END_TIMESTAMP = %A_Now%
EnvSub, END_TIMESTAMP, START_TIMESTAMP, Seconds
VarSetCapacity(TIME_ELAPSED, 18) ; XX:XX:XX + string terminator = 9 chars (UNICODE: 9*2 bytes).
DllCall( "msvcrt\swprintf", Str,TIME_ELAPSED, Str,"%02d:%02d:%02d", Int,Floor(END_TIMESTAMP/3600)
                         , Int,Mod(END_TIMESTAMP/60,60), Int,Mod(END_TIMESTAMP,60) )

If ( INTERACTIVE )
{   ; Gui management.
    Gui, Cancel
    GuiControl,, SyncText, % ((bSyncStopped) ? "Synchronization Stopped!"
                                             : "Done!") "`n`nTime Elapsed: " TIME_ELAPSED
    GuiControl, Hide, AreYouSure
    GuiControl,, SyncButton, &Ok
    GuiControl, +Default -g gGUIDESTROY, SyncButton
    Gui, Show, X%_X% Y%_Y% Autosize, SuperSynchronizer
    WinWaitClose, ahk_id %h_GUI%
}

If ( LOG_ENABLED )
{   ; Log management - append log to the file.
    If ( !LOG_FILE )
        LOG_FILE := A_ScriptDir "\" SubStr(A_ScriptName, 1, -3) "log"
    SplitPath, LOG_FILE,, sFilePath, sFileExt, sFileName
    Loop
    {   ; If file exists loop until it finds a not existing filename.
        If ( FileExist(LOG_FILE) )
            LOG_FILE = %sFilePath%\%sFileName%_%A_Index%.%sFileExt%
        Else Break
    }
    WriteLog(0, "`n****************************************************************`n")
    WriteLog(1, "SINCHRONIZATION FINISHED IN " TIME_ELAPSED, LOG_FILE)
}

; Restore correct OnExit behaviour and exit from the script.
OnExit, REALQUIT
ExitApp

; ======================================================================================================================
; ===[ LABELS SECTION ]=================================================================================================
; ======================================================================================================================

 STOPSYNC:
GUICLOSE:
    If ( !INTERACTIVE )
    {   ; Stop synchronization if the script is not interactive.
        STOP_SYNC := 1
        Return
    }
    If ( A_GuiControl == "SyncButton" )
    {   ; "Stop" button pressed, check the "AreYouSure" flag before stopping sync.
        GuiControlGet, AreYouSure,, AreYouSure
        STOP_SYNC := (AreYouSure) ? 1 : 0
    }
    Else
    {   ; Script or GUI closed, stop synchronization.
        STOP_SYNC := 1
    }
    Return
;GUICLOSE
;STOPSYNC

 GUIDESTROY:
    Gui, Destroy
    Return
;GUIDESTROY

 REALQUIT:
    ExitApp
;REALQUIT

; ======================================================================================================================
; ===[ FUNCTIONS SECTION ]==============================================================================================
; ======================================================================================================================

ReplicationCheck(sPattern) {
    Global SOURCE_DIR, DESTIN_DIR, EX_REPLICATION_DIRS, EX_REPLICATION_FILES, SIMULATION, LOG_ENABLED, COPY_CALLBACK
         , STOP_SYNC

    Loop, %sPattern%, 1
    {
        ; Return 1 if STOP_SYNC is set.
        If ( STOP_SYNC )
            Return 1
       
        If ( InStr(FileExist(A_LoopFileFullPath), "D") )
        {   ; It's a directory.
            If ( !InStr(EX_REPLICATION_DIRS, "<" A_LoopFileLongPath ">") )
            && ( !InStr(EX_REPLICATION_DIRS, "<" A_LoopFileName     ">") )
            {   ; If directory isn't in exlusion list.
                If ( !InStr(FileExist(DESTIN_DIR "\" A_LoopFileFullPath), "D") )
                {   ; If source directory doesn't exists on destination, create it.
                    If ( !SIMULATION )
                    {   ; If SIMULATION is disabled.
                        ; Try to delete an "eventually present" file that has the same name of the source directory.
                        FileDelete, %DESTIN_DIR%\%A_LoopFileFullPath%
                        ; Create the source directory on destination.
                        FileCreateDir, %DESTIN_DIR%\%A_LoopFileFullPath%
                    }
                    If ( LOG_ENABLED ) ; Log management
                        WriteLog( 1, (!SIMULATION && ErrorLevel)
                                ? "ERROR >> Could not create directory: <" DESTIN_DIR "\" A_LoopFileFullPath "> $`n"
                                : "SUCCESS >> Directory created: <" DESTIN_DIR "\" A_LoopFileFullPath "> $`n" )
                }
                ; Recursion into current directory.
                bStopFlag := ReplicationCheck(A_LoopFileFullPath "\*.*")
                ; If bStopFlag is set, return 1 (it means that STOP_SYNC == 1).
                If ( bStopFlag )
                    Return 1
            }
            Else
            {   ; Directory skipped.
                If ( LOG_ENABLED ) ; Log management.
                    WriteLog(1, "SKIPPED >> Directory excluded: <" A_LoopFileLongPath "> $`n")
            }
        }
        Else
        {   ; It's a file.
            bCopyFlag := 0
            If ( !InStr(EX_REPLICATION_FILES, "<" A_LoopFileLongPath ">") )
            && ( !InStr(EX_REPLICATION_FILES, "<" A_LoopFileName     ">") )
            && ( !InStr(EX_REPLICATION_EXT,   "<" A_LoopFileExt      ">") )
            {   ; If file isn't in exlusion lists.
                If ( !sFileAttr := FileExist(DESTIN_DIR "\" A_LoopFileFullPath) || InStr(sFileAttr, "D") )
                {   ; If it doesn't exists on destination or it exists and is a directory on destination, set copy flag.
                    If ( !SIMULATION )
                    {   ; If SIMULATION is disabled.
                        ; Try to delete an "eventually present" directory that has the same name of the source file.
                        FileRemoveDir, %DESTIN_DIR%\%A_LoopFileFullPath%, 1
                    }
                    ; Set copy flag.
                    bCopyFlag := 1
                }
                Else
                {   ; Else it exists and is a file with the same name of the source file.
                    ; Get modification time of the destination file.
                    FileGetTime, sFileTime, %DESTIN_DIR%\%A_LoopFileFullPath%
                    ; Calculate the difference with the modification time of the source file.
                    EnvSub, sFileTime, %A_LoopFileTimeModified%, seconds
                    If ( sFileTime < 0 )
                    {   ; If source file is more recent than destination file.
                        If ( !SIMULATION )
                        {   ; If SIMULATION is disabled.
                            ; Remove attributes to destination file, because CopyFileEx fails if readonly or hidden.
                            FileSetAttrib, -RH, %DESTIN_DIR%\%A_LoopFileFullPath%
                        }
                        ; Set copy flag.
                        bCopyFlag := 1
                    }
                }
            }
            Else
            {   ; File skipped.
                If ( LOG_ENABLED ) ; Log management.
                    WriteLog(1, "SKIPPED >> File excluded: <" A_LoopFileLongPath "> $`n")
            }
            If ( bCopyFlag )
            {   ; File copy.
                sDestFileLongPath = %DESTIN_DIR%\%A_LoopFileFullPath%
                If ( !SIMULATION )
                {   ; If SIMULATION is disabled.
                    nReturn := DllCall( "CopyFileEx", Str,"\\?\" A_LoopFileLongPath, Str,"\\?\" sDestFileLongPath
                                                    , UInt,COPY_CALLBACK, UInt,0, UInt,0, UInt,0 )
                    If ( !nReturn && A_LastError == 1235 )
                    {   ; If CopyFileEx failed and GetLastError == ERROR_REQUEST_ABORTED == 1235.
                        If ( LOG_ENABLED ) ; Log management.
                            WriteLog(1, "STOPPED >> Copy stopped: <" A_LoopFileLongPath "> not copied $`n" )
                        ; Return 1 (it means that STOP_SYNC == 1).
                        Return 1
                    }
                }
                If ( LOG_ENABLED ) ; Log management.
                    WriteLog( 1, (!SIMULATION && !nReturn)
                            ? "ERROR >> Error copying <" A_LoopFileLongPath "> to <" sDestFileLongPath "> $`n"
                            : "SUCCESS >> Copied <" A_LoopFileLongPath "> to <" sDestFileLongPath "> $`n" )
            }
        }
    }
    Return 0
}

ReverseCheck(sPattern) {
    Global SOURCE_DIR, DESTIN_DIR, EX_REVERSE_DIRS, EX_REVERSE_FILES, SIMULATION, LOG_ENABLED, COPY_CALLBACK, STOP_SYNC

    bDontDeleteDirFlag := 0
    Loop, %sPattern%, 1
    {
        ; Return 1 if STOP_SYNC is set.
        If ( STOP_SYNC )
            Return 1
   
        If ( InStr(FileExist(A_LoopFileFullPath), "D") )
        {   ; It's a directory.
            If ( !FileExist(SOURCE_DIR "\" A_LoopFileFullPath) )
            {   ; If directory doesn't exist on source side.
                If ( !InStr(EX_REVERSE_DIRS, "<" A_LoopFileLongPath ">") )
                && ( !InStr(EX_REVERSE_DIRS, "<" A_LoopFileName     ">") )
                {   ; If directory isn't in exlusion lists.
                    ; Recurse into the directory.
                    ReverseCheck(A_LoopFileFullPath "\*.*")
                    If ( !FileExist(A_LoopFileFullPath "\*") )
                    {   ; Remove directory only if empty.
                        If ( !SIMULATION )
                        {   ; If SIMULATION is disabled.
                            FileRemoveDir,  %A_LoopFileFullPath%
                        }
                        If ( LOG_ENABLED ) ; Log management.
                            WriteLog( 1, (!SIMULATION && ErrorLevel)
                                    ? "ERROR >> Could not remove <" A_LoopFileLongPath "> $`n"
                                    : "SUCCESS >> Directory removed: <" A_LoopFileLongPath "> $`n" )
                    }
                    Else
                    {   ; Directory excluded because not empty.
                        If ( LOG_ENABLED ) ; Log management.
                            WriteLog(1, "SKIPPED >> Directory excluded because not empty: <" A_LoopFileLongPath "> $`n")
                    }
                }
                Else
                {   ; Directory skipped.
                    If ( LOG_ENABLED ) ; Log management.
                        WriteLog(1, "SKIPPED >> Directory excluded: <" A_LoopFileLongPath "> $`n")
                }
            }
            Else
            {   ; Else directory exists in source side.
                bStopFlag := ReverseCheck(A_LoopFileFullPath "\*.*")
                ; If bStopFlag is set, return 1 (it means that STOP_SYNC == 1).
                If ( bStopFlag )
                    Return 1
            }
        }
        Else
        {   ; It's a file.
            If ( !FileExist(SOURCE_DIR "\" A_LoopFileFullPath) )
            {   ; If file doesn't exists on source side.
                If ( !InStr(EX_REVERSE_FILES, "<" A_LoopFileLongPath ">") )
                && ( !InStr(EX_REVERSE_FILES, "<" A_LoopFileName     ">") )
                && ( !InStr(EX_REVERSE_EXT,   "<" A_LoopFileExt      ">") )
                {   ; If file isn't in exclusion lists.
                    If ( !SIMULATION )
                    {   ; If SIMULATION is disabled.
                        FileDelete, %A_LoopFileFullPath%
                    }
                    If ( LOG_ENABLED ) ; Log management.
                        WriteLog( 1, (!SIMULATION && ErrorLevel)
                                ? "ERROR >> Could not delete <" A_LoopFileLongPath "> $`n"
                                : "SUCCESS >> File deleted: <" A_LoopFileLongPath "> $`n" )
                }
                Else
                {   ; File skipped
                    If ( LOG_ENABLED ) ; Log management.
                        WriteLog(1, "SKIPPED >> File excluded: <" A_LoopFileLongPath "> $`n")
                }
            }
            Else
            {   ; Else file exists on source side.
                If ( !InStr(EX_REVERSE_FILES, "<" A_LoopFileLongPath ">") )
                && ( !InStr(EX_REVERSE_FILES, "<" A_LoopFileName ">") )
                {   ; If file isn't in exclusion lists.
                    FileGetTime, sFileTime, %SOURCE_DIR%\%A_LoopFileFullPath%
                    EnvSub, sFileTime, %A_LoopFileTimeModified%, seconds
                    If ( sFileTime != 0 )
                    {   ; Check if destination file differs from source file, if yes overwrite destination file.
                        sSourceFileLongPath = %SOURCE_DIR%\%A_LoopFileFullPath%
                        If ( !SIMULATION )
                        {   ; If SIMULATION is disabled.
                            ; Remove attributes to destination file, because CopyFileEx fails if readonly or hidden.
                            FileSetAttrib, -RH, %A_LoopFileLongPath%
                            nReturn := DllCall( "CopyFileEx", Str,"\\?\" sSourceFileLongPath
                                              , Str,"\\?\" A_LoopFileLongPath, UInt,COPY_CALLBACK, UInt,0, UInt,0
                                              , UInt,0 )
                            If ( !nReturn && A_LastError == 1235 )
                            {   ; If CopyFileEx failed and GetLastError == ERROR_REQUEST_ABORTED == 1235.
                                If ( LOG_ENABLED ) ; Log management.
                                    WriteLog(1, "STOPPED >> Copy stopped: <" A_LoopFileLongPath "> not copied $`n" )
                                ; Return 1 (it means that STOP_SYNC == 1).
                                Return 1
                            }
                        }
                        If ( LOG_ENABLED ) ; Log management.
                            WriteLog( 1, (!SIMULATION && !nReturn)
                            ? "ERROR >> Error copying <" sSourceFileLongPath "> to <" A_LoopFileLongPath "> $`n"
                            : "SUCCESS >> Copied <" sSourceFileLongPath "> to <" A_LoopFileLongPath "> $`n" )
                    }
                }
                Else
                {   ; File skipped.
                    If ( LOG_ENABLED ) ; Log management.
                        WriteLog(1, "SKIPPED >> File excluded: <" A_LoopFileLongPath "> $`n")
                }
            }
        }
    }
    Return 0
}

WriteLog(bAppendTime, sLogEntry, sAppendLogTo:="") {
    Static sLogData
    If ( bAppendTime )
        sLogData .= "[" A_YYYY "." A_MM "." A_DD "]" A_Hour ":" A_Min ":" A_Sec " - " sLogEntry
    Else
        sLogData .= sLogEntry
    If ( sAppendLogTo )
        FileAppend, %sLogData%, %sAppendLogTo%
}

CopyCallback(var1lo, var1hi, var2lo, var2hi, var3lo, var3hi, var4lo, var4hi, var5, var6, var7, var8, var9) {
    ; 13 dummy parameters to conform to the CopyProgressRoutine
    ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa363854%28v=vs.85%29.aspx
    Global STOP_SYNC
    Return STOP_SYNC
}
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

23 Jan 2014, 12:18

The Cloud storage is your friend, Luke! ;)
LOL so true.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32
User avatar
joedf
Posts: 6608
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: AHK Studio

23 Jan 2014, 12:42

Haha fff...rrrieeeeennnn...ddd :)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
ahk7
Posts: 118
Joined: 06 Nov 2013, 16:35

Re: AHK Studio

23 Jan 2014, 17:31

I had my hard drive crash and I lost all of my scripts. I have spent the last few weeks re-writing a lot of what I had from scratch.
Why not try Git(Hub)? With windows.github.com it is very easy to update your repository - http://www.sourcetreeapp.com/ is also pretty neat (but does require registration to continue to use it after 30 days, remains free though)
User avatar
maestrith
Posts: 735
Joined: 16 Oct 2013, 13:52

Re: AHK Studio

23 Jan 2014, 17:33

I had my hard drive crash and I lost all of my scripts. I have spent the last few weeks re-writing a lot of what I had from scratch.
Why not try Git(Hub)? With windows.github.com it is very easy to update your repository - http://www.sourcetreeapp.com/ is also pretty neat (but does require registration to continue to use it after 30 days, remains free though)
I will look into it.
AHK Studio OSD GUI Creator
Donations
Discord
All code is done on a Windows 10 PC Running x64 and AutoHotkey x32

Return to “AHK Studio”

Who is online

Users browsing this forum: No registered users and 1 guest