; ===================================================== ; ; Table of Contents Generator for AutoIt ; ; ; ; Author: Jeff Davis ; ; E-Mail: xwinterx@roadrunner.com ; ; ; ; ===================================================== ; ; Summary: ; ; ; ; Creates a "Table of Contents" to be appended at the ; ; end of your code. Utilizing a "key", you can place ; ; bookmarks or headings to be compiled into the TOC ; ; for quick and easy reference. ; ; ===================================================== ; #include #include #include Global $Version = "0.1" Global $key = ";~>" MsgBox(64, "TOC Gen v" & $Version, "Author: Jeff Davis" & @CRLF & @CRLF _ & "E-Mail: xwinterx@roadrunner.com" & @CRLF & @CRLF & "(c) 2007.", 8) Sleep(2000) GuiCreate("TOC Gen", 460, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GuiCtrlCreateGroup(" Target AU3 ", 10, 40, 440, 60) $INP_FILE = GuiCtrlCreateInput("", 20, 60, 350, 20, $ES_READONLY) GUICtrlSetTip(-1, "Currently selected .au3 file to create TOC for") $BTN_BROWSE = GuiCtrlCreateButton("Browse", 380, 60, 60, 20) GuiCtrlCreateLabel("Line Count:", 20, 120, 60, 20) $LBL_COUNT = GuiCtrlCreateLabel("----", 80, 120, 50, 20) GUICtrlSetTip(-1, "Total line count for currently selected .au3 file") GUICtrlSetColor(-1, 0xFF0000) $CB_SPACES = GUICtrlCreateCheckbox("Double Space TOC", 30, 160, 150, 20) GUICtrlSetTip(-1, "Check this option to double space the TOC contents") $BTN_PROCESS = GUICtrlCreateButton("Process", 200, 160, 60, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $BTN_BROWSE OPEN_FILE() Case $msg = $BTN_PROCESS If GUICtrlRead($INP_FILE) = "" Then MsgBox(4096, "Input Error!", "Please select a file to process.") Else PROCESS_TOC() EndIf Case Else ;;; EndSelect WEnd Func OPEN_FILE() Local $Temp = FileOpenDialog("Choose AU3 File", @ScriptDir, "AU3(*.au3)") GUICtrlSetData($INP_FILE, $Temp) GUICtrlSetData($LBL_COUNT, _FileCountLines($Temp)) EndFunc Func PROCESS_TOC() Dim $Index[1] Dim $Comment[1] Local $File = FileOpen(GUICtrlRead($INP_FILE), 0) Local $Temp, $Line, $i Local $Counter = 1 Local $TOC_File = StringTrimRight(GUICtrlRead($INP_FILE), 4) & "_TOC.au3" Local $Temp2 = StringSplit(GUICtrlRead($INP_FILE), "\") Local $FileName = $Temp2[$Temp2[0]] Local $Progress_Set = 100 / GUICtrlRead($LBL_COUNT) Local $Entry_Count = 0 ; Delete TOC file if already exists for fresh file. If FileExists($TOC_File) Then FileDelete($TOC_File) ProgressOn("Scanning TOC Entries...", "Complete: 0 %", "Entries Found: " & $Entry_Count) ; Separates TOC Contents into arrays. While 1 $Line = FileReadLine($File) If @error = -1 Then ExitLoop If StringInStr($Line, $key) Then $Temp = StringSplit($Line, $key) _ArrayAdd($Index, $Counter) _ArrayAdd($Comment, StringTrimLeft($Line, 3)) $Entry_Count += 1 EndIf $Counter += 1 ProgressSet(Round($Counter * $Progress_Set, 0), "Entries Found: " & $Entry_Count, "Complete: " & Round($Counter * $Progress_Set, 0) & " %") Sleep(10) WEnd ProgressSet(100, "Entries Found: " & $Entry_Count, "Complete 100 %") Sleep(2000) ProgressOff() ; Header. FileWriteLine($TOC_File, "; Copy and Paste the Region below at the end of your script.") FileWriteLine($TOC_File, " ") FileWriteLine($TOC_File, "#region - Table of Contents for: " & $FileName) FileWriteLine($TOC_File, ";") FileWriteLine($TOC_File, "; Line" & @TAB & @TAB & " Content") FileWriteLine($TOC_File, ";") $Progress_Set = 100 / (UBound($Index) - 1) ProgressOn("Building TOC...", "Percent Complete: 0 %", "Writing: ----") For $i = 1 to (UBound($Index) - 1) If StringLen($Index[$i]) = 1 Then FileWriteLine($TOC_File,"; " & $Index[$i] & @TAB & @TAB & @TAB & "- " & $Comment[$i]) Elseif StringLen($Index[$i]) > 1 And StringLen($Index[$i]) < 6 Then FileWriteLine($TOC_File,"; " & $Index[$i] & @TAB & @TAB & "- " & $Comment[$i]) Else FileWriteLine($TOC_File,"; " & $Index[$i] & @TAB & "- " & $Comment[$i]) EndIf If GUICtrlRead($CB_SPACES) = $GUI_CHECKED and $i <> (UBound($Index) - 1) Then FileWriteLine($TOC_File, ";") ProgressSet(Round($i * $Progress_Set, 0), "Writing: " & $Comment[$i], "Complete: " & Round($i * $Progress_Set, 0) & " %") Sleep(10) Next FileWriteLine($TOC_File, ";") FileWriteLine($TOC_File, "#endregion - Generated by TOC Gen v" & $Version) ProgressSet(100, "Writing: ----", "Complete 100 %") Sleep(2000) ProgressOff() MsgBox(4096, "Table of Contents Complete!", "TOC Located at:" & @CRLF & @CRLF & $TOC_File) EndFunc