Sign in to follow this  
Followers 0
willichan

New AU3 Project Folder (utility)

13 posts in this topic

#1 ·  Posted (edited)

After using a version of this utility for myself for some time, I decided it was time to generalize it, and make it available to the AutoIt community. The utility adds itself to the "New" right-click shell menu to create a folder containing everything needed to start working on a new AU3 project, based on template files.

Download here

Just download the .ZIP file, unpack it, and run the install. It will take care of all the registry entries, as well as install the utility itself.

See the readme.pdf file for customization instructions.

---- EDIT ----

I have gone ahead with the newer utility that is more generalized, and supports multiple templates and profiles. Take a look at it here.

In conjunction with the release of the new utility, I am posting the source for this one below.

Please keep in mind that this version was a quick and dirty solution for my own needs, and in no way represents what I consider clean code. The new utility linked above, though conceptually evolved from this utility, is a complete rewrite.

Edited by willichan

Share this post


Link to post
Share on other sites



Great program.

Looking forward to the source.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is a good idea. Yesterday I actually thought about doing something similar, but never got to it. I was thinking of a context menu entry which would popup an inputbox asking for projectname(foldername) and create the folder then go ahead and put the projectname.au3 project file in it.

Edited by Datenshi

Share this post


Link to post
Share on other sites

Any updates ?

I'd like to see a non-reg version, portable...

Share this post


Link to post
Share on other sites

Very interesting! I am currently writing a utility myself (plogger) thats going to provide a simple way to create a project logs witha simple dialog. maybe when its done I'll look at creating an all in one project manager...

Mat

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If there isn't a uninstaller I'm going to rage like TheSaint did when DBaK released Advanced Media Player 3. For one reason that I don't feel like going into the registry and removing it by myself.

Edited by X42Negative

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I am working on the new version, that will also have an uninstaller. I should be able to post it within a few days. I do not have a standalone version at this time, but I will add that to my todo list.

Edited by willichan

Share this post


Link to post
Share on other sites

Alright. The new version is available for download. I have modified the top post with the download information.

This new version contains better documentation, and an uninstall.

Share this post


Link to post
Share on other sites

The new version is available for download. I have modified the top post with the download information.

This new version contains better documentation, and an uninstall.

Thx!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Here is the source for this utility, as promised.

This was a quick and dirty, so it is not the best example of code, but you can tinker with it.

Please see the first post above for a link to the new and improved utility.

MyAU3Project.au3

Global Const $debug = False

AutoItSetOption("TrayAutoPause", 0)

#include <frm_main.au3>
#include <date.au3>

Global $outpath
Global $inifile
Global $vars
Global $processlist
Global $renamelist
Global $delimiter
Global $mymutex
Global Const $includedir = "include"

If $debug Then
    $outpath = @DesktopDir & "\"
Else
    Switch $CmdLine[0]
        Case 0
            MsgBox(16, "New AU3 Project ERROR", "No path was provided")
            Exit (2)
        Case 1
            $outpath = $CmdLine[1]
        Case Else
            $outpath = $CmdLine[2]
    EndSwitch
    $outpath = StringLeft($outpath, StringInStr($outpath, "\", 0, -1))
EndIf
frm_main()
SRandom(@YDAY & @MSEC)
$mymutex = Hex(Random(0, 65535, 1), 4) & Hex(Random(0, 65535, 1), 4) & Hex(Random(0, 65535, 1), 4) & Hex(Random(0, 65535, 1), 4)
$inifile = StringLeft(@ScriptFullPath, StringInStr(@ScriptFullPath, ".", 0, -1)) & "ini"
If Not FileExists($inifile) Then
    MsgBox(0, "ERROR", "Missing ini file: " & $inifile)
    Exit (3)
EndIf
$delimiter = IniRead($inifile, "config", "variablemarker", "__")
$vars = IniReadSection($inifile, "variables")
If @error = 1 Then
    Dim $vars[1][1]
    $vars[0][0] = 0
EndIf
$processlist = IniReadSection($inifile, "process")
If @error = 1 Then
    Dim $processlist[1][1]
    $processlist[0][0] = 0
EndIf
$renamelist = IniReadSection($inifile, "rename")
If @error = 1 Then
    Dim $renamelist[1][1]
    $renamelist[0][0] = 0
EndIf
DoFolder()

Func DoVariables($thestring)
    Local $newstring = $thestring
    Local $i
    $newstring = StringReplace($newstring, Delimited("nameshort"), $shortname, 0, 1)
    $newstring = StringReplace($newstring, Delimited("namelong"), $longname, 0, 1)
    $newstring = StringReplace($newstring, Delimited("autoitver"), RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "Version"), 0, 1)
    $newstring = StringReplace($newstring, Delimited("date"), _NowDate(), 0, 1)
    $newstring = StringReplace($newstring, Delimited("description"), $description, 0, 1)
    $newstring = StringReplace($newstring, Delimited("mutex"), $mymutex, 0, 1)
    If $vars[0][0] > 0 Then
        For $i = 1 To $vars[0][0]
            $newstring = StringReplace($newstring, Delimited($vars[$i][0]), $vars[$i][1], 0, 1)
        Next
    EndIf
    Return $newstring
EndFunc   ;==>DoVariables

Func Delimited($thestring)
    Return $delimiter & $thestring & $delimiter
EndFunc   ;==>Delimited

Func DoFolder($folderpath = "")
    Local $renameme = False
    Local $sourcedir
    Local $targetdir
    Local $i
    Local $file
    Local $search

    If $folderpath = "" Then
        $sourcedir = @ScriptDir & "\" & $includedir
        $targetdir = $outpath & $shortname
    Else
        $sourcedir = @ScriptDir & "\" & $includedir & "\" & $folderpath
        If $renamelist[0][0] > 0 Then
            For $i = 1 To $renamelist[0][0]
                If $folderpath = $renamelist[$i][1] Then $renameme = True
            Next
        EndIf
        If $renameme Then
            $targetdir = $outpath & $shortname & "\" & DoVariables($folderpath)
        Else
            $targetdir = $outpath & $shortname & "\" & $folderpath
        EndIf
    EndIf
    If Not FileExists($targetdir) Then DirCreate($targetdir)
    If $targetdir = ($outpath & $shortname) Then FileSetAttrib($targetdir, "+r", 0)
    $search = FileFindFirstFile($sourcedir & "\*.*")
    If $search <> -1 Then
        While 1
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If StringInStr(FileGetAttrib($sourcedir & "\" & $file), "D") Then
                DoFolder(TruncDir($sourcedir & "\" & $file))
            Else
                DoFile(TruncDir($sourcedir & "\" & $file))
            EndIf
        WEnd
        FileClose($search)
    EndIf
EndFunc   ;==>DoFolder

Func TruncDir($thepath)
    Return StringRight($thepath, StringLen($thepath) - (StringLen(@ScriptDir & $includedir) + 2))
EndFunc   ;==>TruncDir

Func DoFile($filepath)
    Local $renameme = False
    Local $processme = False
    Local $sourcefile
    Local $targetfile
    Local $i
    Local $line
    $sourcefile = @ScriptDir & "\" & $includedir & "\" & $filepath
    If $renamelist[0][0] > 0 Then
        For $i = 1 To $renamelist[0][0]
            If $filepath = $renamelist[$i][1] Then $renameme = True
        Next
    EndIf
    If $renameme Then
        $targetfile = $outpath & $shortname & "\" & DoVariables($filepath)
    Else
        $targetfile = $outpath & $shortname & "\" & $filepath
    EndIf
    If $processlist[0][0] > 0 Then
        For $i = 1 To $processlist[0][0]
            If $filepath = $processlist[$i][1] Then $processme = True
        Next
    EndIf
    If $processme Then
        Local $infile = FileOpen($sourcefile, 0)
        Local $outfile = FileOpen($targetfile, 2)
        While 1
            $line = FileReadLine($infile)
            If @error = -1 Then ExitLoop
            FileWriteLine($outfile, DoVariables($line))
        WEnd
        FileClose($outfile)
        FileClose($infile)
    Else
        FileCopy($sourcefile, $targetfile, 0)
    EndIf
    FileSetAttrib($targetfile, "+" & FileGetAttrib($sourcefile))
EndFunc   ;==>DoFile

frm_main.au3

#include-once
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $longname=""
Global $shortname=""
Global $description=""
Global $frm_main_loop=True

Func frm_main()
    Opt("GUIOnEventMode", 1)
    Global $frm_main = GUICreate("New AU3 Project", 139, 243, 192, 114)
    GUISetOnEvent($GUI_EVENT_CLOSE, "frm_mainClose")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "frm_mainMinimize")
    GUISetOnEvent($GUI_EVENT_RESTORE, "frm_mainRestore")
    Global $frm_main_input1 = GUICtrlCreateInput("", 8, 32, 121, 21)
    GUICtrlSetOnEvent($frm_main_input1, "frm_main_input1Change")
    Global $frm_main_input2 = GUICtrlCreateInput("", 8, 88, 121, 21)
    Global $frm_main_input3 = GUICtrlCreateInput("", 8, 144, 121, 21)
    Global $frm_main_btn1 = GUICtrlCreateButton("OK", 8, 176, 123, 25, $BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent($frm_main_btn1, "frm_main_btn1Click")
    Global $frm_main_btn2 = GUICtrlCreateButton("Cancel", 8, 208, 123, 25, 0)
    GUICtrlSetOnEvent($frm_main_btn2, "frm_main_btn2Click")
    Global $frm_main_lbl1 = GUICtrlCreateLabel("Project Title:", 8, 8, 63, 17)
    Global $frm_main_lbl2 = GUICtrlCreateLabel("Project Short Title:", 8, 64, 91, 17)
    Global $frm_main_lbl3 = GUICtrlCreateLabel("Description:", 8, 120, 60, 17)
    GUISetState(@SW_SHOW,$frm_main)
    
    $frm_main_loop=True
    While $frm_main_loop
        Sleep(100)
    WEnd
    GUISetState(@SW_HIDE,$frm_main)
EndFunc

Func frm_main_input1Change()
    Local $tt=GUICtrlRead($frm_main_input1)
    $tt=StringStripWS($tt,8)
    GUICtrlSetData($frm_main_input2,$tt)
EndFunc

Func frm_main_btn1Click()
    $frm_main_loop=False
    $longname=GUICtrlRead($frm_main_input1)
    $shortname=GUICtrlRead($frm_main_input2)
    $description=GUICtrlRead($frm_main_input3)
    GUIDelete($frm_main)
EndFunc

Func frm_main_btn2Click()
    $frm_main_loop=False
    GUIDelete($frm_main)
    Exit(1)
EndFunc

Func frm_mainClose()
    frm_main_btn2Click()
EndFunc

Func frm_mainMinimize()
EndFunc

Func frm_mainRestore()
EndFunc
Edited by willichan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0