/* * -- Get image paths from glife.txt -- * * Requires images subfolder to exist in current directory * * OutAllFile - List of All unprocessed file names from glife.txt that are not marked missing in the code * OutUsedFile - List of Found file names from glife.txt and Auto List * OutMissFile - List of Missing file names from glife.txt that are marked missing in the code. * OutAutoFile - List of file paths from glife.txt that were added to Output file using code in this script * OutManFile - List of file paths from glife.txt that will have to be added manualy checked either in glife code or added to OutUsedFile * * * WD: Jul 2015 * * */ #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. SourceFile = glife.txt OutAllFile = Image List - All.txt OutUsedFile = Image List - Used.txt OutMissFile = Image List - Missing.txt OutAutoFile = Image Paths - Auto List.txt OutManFile = Image Paths - Manual List.txt SearchRegEx = i)>") ;; BDSM Club { BDSMRegEx := "i)(_\d+)\.jpg" BDSMPos := RegExMatch(Match1, BDSMRegEx , BDSMatch) if (ErrorLevel) { MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %Match1%`n`nusing search: %BDSMRegEx% break } BDSMRegEx := "i)[rg]?\d+" . BDSMatch1 . "\.jpg" if GetImageFiles("images\BDSM_Club", "*.jpg", OutUsed, BDSMRegEx) { OutAuto .= Spacer(Match1) . "- Found 'images\BDSM_Club*.jpg'`n" } else { OutMan .= Spacer(Match1) . "- no files found in 'images\BDSM_Club*.jpg' " . IdxTxt . "`n" } } else if inStr(Match1, "FUNC") ;; Unknown Function - Manual { OutMan .= Spacer(Match1) . "- Unknown Function " . IdxTxt . "`n" } else if inStr(Match1, "$") ;; Uses String variable - Manual { OutMan .= Spacer(Match1) . "- Used String Variable " . IdxTxt . "`n" } else if GetImagefromPath(Match1, OutUsed) ;; Try to find images { OutAuto .= Spacer(Match1) . "- Found image files`n" } else { OutMan .= Spacer(Match1) . "- Files not found " . IdxTxt . "`n" } } ; -- Image path is just a file name -- else { IfExist %Match1% { OutUsed .= Match1 . "`n" ;; Normal file found } else { OutMan .= Spacer(Match1) . "- File not found " . IdxTxt . "`n" } } FoundPos += 8 + StrLen(Match1) ;; Increment Search Position } } ; -- VIEW images -- FoundPos := 1 Haystack := A_LoopField Loop, 200 { ; -- Find Image File Path -- FoundPos := RegExMatch(Haystack, Search2RegEx, Match, FoundPos) ;; Search for 'view' cmd path if (ErrorLevel) { MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %Haystack%`n`nusing search: %Search2RegEx% break } if (FoundPos = 0) ;; Not Found exit loop { break } else ; if (FoundPos) ;; Found File { IdxTxt := " (L:" . LineNo . ", P:" . FoundPos . ")" Match1 := StrReplace(Match1, "/", "\") ;; Use correct Win path seperator OutAll .= Match1 . "`n" ; -- Image Path Contains Code -- if inStr(Match1, "<<") ;; String contains expression { if inStr(Match1, "FUNC") ;; Unknown Function - Manual { OutMan .= Spacer(Match1) . "- Unknown Function " . IdxTxt . "`n" } else if inStr(Match1, "$") ;; Uses String variable - Manual { OutMan .= Spacer(Match1) . "- Used String Variable " . IdxTxt . "`n" } else if GetImagefromPath(Match1, OutUsed) ;; Try to find images { OutAuto .= Spacer(Match1) . "- Found image files`n" } else { OutMan .= Spacer(Match1) . "- Files not found " . IdxTxt . "`n" } } ; -- Image path is just a file name -- else { IfExist %Match1% { OutUsed .= Match1 . "`n" ;; Normal file found } else { OutMan .= Spacer(Match1) . "- File not found " . IdxTxt . "`n" } } FoundPos += 5 + StrLen(Match1) ;; Increment Search Position } } } ; -- Set path to use / seperators -- OutAll := StrReplace(OutAll, "\", "/") OutUsed := StrReplace(OutUsed, "\", "/") OutMiss := StrReplace(OutMiss, "\", "/") OutAuto := StrReplace(OutAuto, "\", "/") OutMan := StrReplace(OutMan, "\", "/") ; -- sort filenames and remove dupes -- Sort, OutAll, U Sort, OutUsed, U Sort, OutMiss, U Sort, OutAuto, U Sort, OutMan, U ;-- save files -- FileAppend, %OutAll%, %OutAllFile% FileAppend, %OutUsed%, %OutUsedFile% FileAppend, %OutMiss%, %OutMissFile% FileAppend, %OutAuto%, %OutAutoFile% FileAppend, %OutMan%, %OutManFile% Exit ; ########## Functions ########## Spacer(TxtStr = "") { Static SpaceFill := " " ;~ ps := strlen(TxtStr) + 1 ;; allow empty string = 1 ;~ ss := TxtStr . SubStr(SpaceFill, ps) . "`t" return TxtStr . SubStr(SpaceFill, strlen(TxtStr)+1) . "`t" } GetImageFiles(FilePath, FileName, ByRef Output, FileNameRegEx := "", FileLoopMode := "F") { ;; Get image paths in filepath using filepattern FileName ;~ msgbox GetImageFiles()`nFilePath := %FilePath%`nFileName := %FileName%`nFileNameRegEx := %FileNameRegEx%`nFileLoopMode := %FileLoopMode% IfNotExist, %FilePath% { MsgBox, 48, Get Image Paths, Error in GetImageFiles()`n`nUnable to locate "%FilePath%" folder, Filename '%FileName%'.`n`nCurrent working dir is "%A_WorkingDir%" return false } SaveWorkDir := A_WorkingDir Setworkingdir, %FilePath% found := false ; -- Loop with or Without recursion -- Loop, Files, %FileName%, %FileLoopMode% ;; Find files in FilePath using Filepattern FileName { if(FileNameRegEx) ;; Can we test file name { FndPos := RegExMatch(A_LoopFileName, FileNameRegEx) ;; File Found matches if (ErrorLevel) { MsgBox, 48, Get Image Paths, RegExMatch Error in function GetImageFiles()`n`nruntime error: %ErrorLevel%`n`nFound searching string: %A_LoopFileName%`n`nusing search: %FileNameRegEx% break } if (not FndPos) ;; Filename not matches skip { continue } } fp := FilePath . "\" . A_LoopFileFullPath Output .= fp . "`n" found := true } Setworkingdir, %SaveWorkDir% return found } GetImagefromPath(FilePath, ByRef Output) { ;; Try to get Images from path FindRegEx := "<<.*?>>" ReplaceStr := "*" fp := StrReplace(FilePath, "/", "\") fp := RegExReplace(fp, FindRegEx, ReplaceStr) splitpath, fp, FileName, Dir, Ext ;; -- Manual if wildcard in path -- if inStr(Dir, "*") { ; MsgBox, 64, Get Image Path, GetImageFromPath() error: Path contains wildcard`n `nPath : '%fp%'`nDir : '%Dir%' return false } FileNameRegEx := StrReplace(FileName, "*", "\d+") ; set up test for filename wildcard to be numbers only FileNameRegEx := "i)" . StrReplace(FileNameRegEx, ".", "\.") return GetImageFiles(Dir, FileName, Output, FileNameRegEx) }