4
1

Get Image Paths.ahk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. * -- Get image paths from glife.txt --
  3. *
  4. * Requires images subfolder to exist in current directory
  5. *
  6. * OutAllFile - List of All unprocessed file names from glife.txt that are not marked missing in the code
  7. * OutUsedFile - List of Found file names from glife.txt and Auto List
  8. * OutMissFile - List of Missing file names from glife.txt that are marked missing in the code.
  9. * OutAutoFile - List of file paths from glife.txt that were added to Output file using code in this script
  10. * OutManFile - List of file paths from glife.txt that will have to be added manualy checked either in glife code or added to OutUsedFile
  11. *
  12. *
  13. * WD: Jul 2015
  14. *
  15. *
  16. */
  17. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  18. #Warn ; Enable warnings to assist with detecting common errors.
  19. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  20. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  21. SourceFile = glife.txt
  22. OutAllFile = Image List - All.txt
  23. OutUsedFile = Image List - Used.txt
  24. OutMissFile = Image List - Missing.txt
  25. OutAutoFile = Image Paths - Auto List.txt
  26. OutManFile = Image Paths - Manual List.txt
  27. SearchRegEx = i)<img\s+src\s*=\s*"(.*?)"
  28. Search2RegEx = i)\bview\s*'+(.*?)'+
  29. CommentRegEx = ^\s*!
  30. MarkMissRegEx = i)!.*?:\s+IMAGE NEEDED\s*~\s*.*?<img\s+src\s*=\s*"(.*?)"
  31. FileEncoding, UTF-16
  32. ;-- backup files and delete --
  33. IfNotExist %SourceFile%
  34. {
  35. MsgBox, 16, Get Image Paths, Unable to locate "%SourceFile%" in "%A_WorkingDir%", 10
  36. Exit
  37. }
  38. ifExist %OutAllFile% ;; Backup File
  39. {
  40. FileMove, %OutAllFile%, %OutAllFile%.bak, 1
  41. FileDelete, %OutAllFile%
  42. }
  43. ifExist %OutUsedFile% ;; Backup File
  44. {
  45. FileMove, %OutUsedFile%, %OutUsedFile%.bak, 1
  46. FileDelete, %OutUsedFile%
  47. }
  48. ifExist %OutMissFile% ;; Backup File
  49. {
  50. FileMove, %OutMissFile%, %OutMissFile%.bak, 1
  51. FileDelete, %OutMissFile%
  52. }
  53. ifExist %OutAutoFile% ;; Backup File
  54. {
  55. FileMove, %OutAutoFile%, %OutAutoFile%.bak, 1
  56. FileDelete, %OutAutoFile%
  57. }
  58. ifExist %OutManFile% ;; Backup File
  59. {
  60. FileMove, %OutManFile%, %OutManFile%.bak, 1
  61. FileDelete, %OutManFile%
  62. }
  63. ; -- load data from file --
  64. FileRead, Source, %SourceFile%
  65. ; -- vars need plenty of space to work with --
  66. VarSetCapacity(OutAll, 4194304) ;; 4mb
  67. VarSetCapacity(OutUsed, 4194304) ;; 4mb
  68. VarSetCapacity(OutMiss, 4194304) ;; 4mb
  69. VarSetCapacity(OutAuto, 1048576) ;; 1mb
  70. VarSetCapacity(OutMan, 1048576) ;; 1mb
  71. ; -- Parse data one line at a time --
  72. Loop, Parse, Source, `n, `r ; Specifying `n prior to `r allows both Windows and Unix files to be parsed.
  73. {
  74. if trim(A_LoopField) = "" ;; Skip blank line
  75. continue
  76. ; -- Check is Comment line --
  77. FoundCmntPos := RegExMatch(A_LoopField, CommentRegEx)
  78. if (ErrorLevel)
  79. {
  80. MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %A_LoopField%`n`nusing search: %CommentRegEx%
  81. break
  82. }
  83. if (FoundCmntPos) ;; comment found
  84. {
  85. FoundPos := RegExMatch(A_LoopField, MarkMissRegEx, Match) ;; Check for known missing file
  86. if (ErrorLevel)
  87. {
  88. MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %A_LoopField%`n`nusing search: %MarkMissRegEx%
  89. break
  90. }
  91. if (FoundPos) ;; Found File
  92. {
  93. Match1 := StrReplace(Match1, "/", "\") ;; Use correct Win path seperator
  94. IfExist %Match1%
  95. {
  96. OutMiss .= Spacer(Match1) . "- Missing file exists`n" ;; Missing File found
  97. }
  98. else
  99. {
  100. OutMiss .= Match1 . "`n" ;; Missing file Not found
  101. }
  102. }
  103. Continue
  104. }
  105. LineNo := A_index ;; Save line no
  106. ; -- HTML images --
  107. FoundPos := 1
  108. Haystack := A_LoopField
  109. Loop, 200
  110. {
  111. ; -- Find Image File Path --
  112. FoundPos := RegExMatch(Haystack, SearchRegEx, Match, FoundPos) ;; Search for image path in html
  113. if (ErrorLevel)
  114. {
  115. MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %Haystack%`n`nusing search: %SearchRegEx%
  116. break
  117. }
  118. if (FoundPos = 0) ;; Not Found exit loop
  119. {
  120. break
  121. }
  122. else
  123. ; if (FoundPos) ;; Found File
  124. {
  125. IdxTxt := " (L:" . LineNo . ", P:" . FoundPos . ")"
  126. Match1 := StrReplace(Match1, "/", "\") ;; Use correct Win path seperator
  127. OutAll .= Match1 . "`n"
  128. ; -- Image Path Contains Code --
  129. if inStr(Match1, "<<") ;; String contains expression
  130. {
  131. if inStr(Match1, "FUNC(''$face_image''") ;; Hairstyle images Function - only use JPG files
  132. {
  133. if GetImageFiles("images\body\hairstyles", "hcol*.jpg", OutUsed, "", "FR")
  134. {
  135. OutAuto .= Spacer(Match1) . "- Found 'images\body\hairstyles\*\hcol*.jpg'`n"
  136. }
  137. else
  138. {
  139. OutMan .= Spacer(Match1) . "- no files found in 'images\body\hairstyles\*\hcol*.jpg' " . IdxTxt . "`n"
  140. }
  141. }
  142. else if inStr(Match1, "FUNC(''$clothing_image''") ;; Clothing images Function - only use JPG files
  143. {
  144. if GetImageFiles("images\clothes", "vatnik.jpg", OutUsed)
  145. {
  146. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\vatnik.jpg'`n"
  147. }
  148. else
  149. {
  150. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\vatnik.jpg' " . IdxTxt . "`n"
  151. }
  152. ; GetImageFiles("images\clothes\newclo", "131.jpg", OutUsed) ;; Dupe See below
  153. if GetImageFiles("images\clothes", "jeans*.jpg", OutUsed, "i)jeans\d+\.jpg")
  154. {
  155. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\jeans*.jpg'`n"
  156. }
  157. else
  158. {
  159. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\jeans*.jpg' " . IdxTxt . "`n"
  160. }
  161. if GetImageFiles("images\clothes", "yoga*.jpg", OutUsed, "i)yoga\d+\.jpg")
  162. {
  163. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\yoga*.jpg'`n"
  164. }
  165. else
  166. {
  167. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\yoga*.jpg' " . IdxTxt . "`n"
  168. }
  169. if GetImageFiles("images\clothes", "sarafan*.jpg", OutUsed, "i)sarafan\d+\.jpg")
  170. {
  171. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\sarafan*.jpg'`n"
  172. }
  173. else
  174. {
  175. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\sarafan*.jpg' " . IdxTxt . "`n"
  176. }
  177. if GetImageFiles("images\clothes", "short*.jpg", OutUsed, "i)short\d+\.jpg")
  178. {
  179. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\short*.jpg'`n"
  180. }
  181. else
  182. {
  183. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\short*.jpg' " . IdxTxt . "`n"
  184. }
  185. if GetImageFiles("images\clothes", "skirt*.jpg", OutUsed, "i)skirt\d+\.jpg")
  186. {
  187. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\skirt*.jpg'`n"
  188. }
  189. else
  190. {
  191. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\skirt*.jpg' " . IdxTxt . "`n"
  192. }
  193. if GetImageFiles("images\clothes", "dress*.jpg", OutUsed, "i)dress\d+\.jpg")
  194. {
  195. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\dress*.jpg'`n"
  196. }
  197. else
  198. {
  199. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\dress*.jpg' " . IdxTxt . "`n"
  200. }
  201. if GetImageFiles("images\clothes", "profi*.jpg", OutUsed, "i)profi\d+\.jpg")
  202. {
  203. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\profi*.jpg'`n"
  204. }
  205. else
  206. {
  207. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\profi*.jpg' " . IdxTxt . "`n"
  208. }
  209. if GetImageFiles("images\clothes", "pants*.jpg", OutUsed "i)pants\d+\.jpg")
  210. {
  211. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\pants*.jpg'`n"
  212. }
  213. else
  214. {
  215. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\pants*.jpg' " . IdxTxt . "`n"
  216. }
  217. if GetImageFiles("images\clothes", "latex*.jpg", OutUsed, "i)latex\d+\.jpg")
  218. {
  219. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\latex*.jpg'`n"
  220. }
  221. else
  222. {
  223. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\latex*.jpg' " . IdxTxt . "`n"
  224. }
  225. if GetImageFiles("images\clothes", "hooker*.jpg", OutUsed, "i)hooker\d+\.jpg")
  226. {
  227. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\hooker*.jpg'`n"
  228. }
  229. else
  230. {
  231. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\hooker*.jpg' " . IdxTxt . "`n"
  232. }
  233. if GetImageFiles("images\clothes", "k*.jpg", OutUsed, "i)k\d+\.jpg")
  234. {
  235. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\k*.jpg'`n"
  236. }
  237. else
  238. {
  239. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\k*.jpg' " . IdxTxt . "`n"
  240. }
  241. if GetImageFiles("images\clothes\newclo", "*.jpg", OutUsed, "i)\d+\.jpg")
  242. {
  243. OutAuto .= Spacer(Match1) . "- Found 'images\clothes\newclo\*.jpg'`n"
  244. }
  245. else
  246. {
  247. OutMan .= Spacer(Match1) . "- no files found in 'images\clothes\newclo\*.jpg' " . IdxTxt . "`n"
  248. }
  249. if GetImageFiles("images\img\dress", "ero*.jpg", OutUsed, "i)ero\d+\.jpg")
  250. {
  251. OutAuto .= Spacer(Match1) . "- Found 'images\img\dress\ero*.jpg'`n"
  252. }
  253. else
  254. {
  255. OutMan .= Spacer(Match1) . "- no files found in 'images\img\dress\ero*.jpg' " . IdxTxt . "`n"
  256. }
  257. }
  258. else if inStr(Match1, "images\qwest\card") ;; Playingcard Images - only use JPG files
  259. {
  260. if GetImageFiles("images\qwest\card", "*.jpg", OutUsed, "", "FR")
  261. {
  262. OutAuto .= Spacer(Match1) . "- Found 'images\qwest\card\*\*.jpg'`n"
  263. }
  264. else
  265. {
  266. OutMan .= Spacer(Match1) . "- No files found in 'images\qwest\card\*\*.jpg' " . IdxTxt . "`n"
  267. }
  268. }
  269. else if inStr(Match1, "images\BDSM_Club\<<$BDSMrole>>") ;; BDSM Club
  270. {
  271. BDSMRegEx := "i)(_\d+)\.jpg"
  272. BDSMPos := RegExMatch(Match1, BDSMRegEx , BDSMatch)
  273. if (ErrorLevel)
  274. {
  275. MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %Match1%`n`nusing search: %BDSMRegEx%
  276. break
  277. }
  278. BDSMRegEx := "i)[rg]?\d+" . BDSMatch1 . "\.jpg"
  279. if GetImageFiles("images\BDSM_Club", "*.jpg", OutUsed, BDSMRegEx)
  280. {
  281. OutAuto .= Spacer(Match1) . "- Found 'images\BDSM_Club*.jpg'`n"
  282. }
  283. else
  284. {
  285. OutMan .= Spacer(Match1) . "- no files found in 'images\BDSM_Club*.jpg' " . IdxTxt . "`n"
  286. }
  287. }
  288. else if inStr(Match1, "FUNC") ;; Unknown Function - Manual
  289. {
  290. OutMan .= Spacer(Match1) . "- Unknown Function " . IdxTxt . "`n"
  291. }
  292. else if inStr(Match1, "$") ;; Uses String variable - Manual
  293. {
  294. OutMan .= Spacer(Match1) . "- Used String Variable " . IdxTxt . "`n"
  295. }
  296. else if GetImagefromPath(Match1, OutUsed) ;; Try to find images
  297. {
  298. OutAuto .= Spacer(Match1) . "- Found image files`n"
  299. }
  300. else
  301. {
  302. OutMan .= Spacer(Match1) . "- Files not found " . IdxTxt . "`n"
  303. }
  304. }
  305. ; -- Image path is just a file name --
  306. else
  307. {
  308. IfExist %Match1%
  309. {
  310. OutUsed .= Match1 . "`n" ;; Normal file found
  311. }
  312. else
  313. {
  314. OutMan .= Spacer(Match1) . "- File not found " . IdxTxt . "`n"
  315. }
  316. }
  317. FoundPos += 8 + StrLen(Match1) ;; Increment Search Position
  318. }
  319. }
  320. ; -- VIEW images --
  321. FoundPos := 1
  322. Haystack := A_LoopField
  323. Loop, 200
  324. {
  325. ; -- Find Image File Path --
  326. FoundPos := RegExMatch(Haystack, Search2RegEx, Match, FoundPos) ;; Search for 'view' cmd path
  327. if (ErrorLevel)
  328. {
  329. MsgBox, 48, Get Image Paths, RegExMatch runtime error: %ErrorLevel%`n`nFound searching string: %Haystack%`n`nusing search: %Search2RegEx%
  330. break
  331. }
  332. if (FoundPos = 0) ;; Not Found exit loop
  333. {
  334. break
  335. }
  336. else
  337. ; if (FoundPos) ;; Found File
  338. {
  339. IdxTxt := " (L:" . LineNo . ", P:" . FoundPos . ")"
  340. Match1 := StrReplace(Match1, "/", "\") ;; Use correct Win path seperator
  341. OutAll .= Match1 . "`n"
  342. ; -- Image Path Contains Code --
  343. if inStr(Match1, "<<") ;; String contains expression
  344. {
  345. if inStr(Match1, "FUNC") ;; Unknown Function - Manual
  346. {
  347. OutMan .= Spacer(Match1) . "- Unknown Function " . IdxTxt . "`n"
  348. }
  349. else if inStr(Match1, "$") ;; Uses String variable - Manual
  350. {
  351. OutMan .= Spacer(Match1) . "- Used String Variable " . IdxTxt . "`n"
  352. }
  353. else if GetImagefromPath(Match1, OutUsed) ;; Try to find images
  354. {
  355. OutAuto .= Spacer(Match1) . "- Found image files`n"
  356. }
  357. else
  358. {
  359. OutMan .= Spacer(Match1) . "- Files not found " . IdxTxt . "`n"
  360. }
  361. }
  362. ; -- Image path is just a file name --
  363. else
  364. {
  365. IfExist %Match1%
  366. {
  367. OutUsed .= Match1 . "`n" ;; Normal file found
  368. }
  369. else
  370. {
  371. OutMan .= Spacer(Match1) . "- File not found " . IdxTxt . "`n"
  372. }
  373. }
  374. FoundPos += 5 + StrLen(Match1) ;; Increment Search Position
  375. }
  376. }
  377. }
  378. ; -- Set path to use / seperators --
  379. OutAll := StrReplace(OutAll, "\", "/")
  380. OutUsed := StrReplace(OutUsed, "\", "/")
  381. OutMiss := StrReplace(OutMiss, "\", "/")
  382. OutAuto := StrReplace(OutAuto, "\", "/")
  383. OutMan := StrReplace(OutMan, "\", "/")
  384. ; -- sort filenames and remove dupes --
  385. Sort, OutAll, U
  386. Sort, OutUsed, U
  387. Sort, OutMiss, U
  388. Sort, OutAuto, U
  389. Sort, OutMan, U
  390. ;-- save files --
  391. FileAppend, %OutAll%, %OutAllFile%
  392. FileAppend, %OutUsed%, %OutUsedFile%
  393. FileAppend, %OutMiss%, %OutMissFile%
  394. FileAppend, %OutAuto%, %OutAutoFile%
  395. FileAppend, %OutMan%, %OutManFile%
  396. Exit
  397. ; ########## Functions ##########
  398. Spacer(TxtStr = "")
  399. {
  400. Static SpaceFill := " "
  401. ;~ ps := strlen(TxtStr) + 1 ;; allow empty string = 1
  402. ;~ ss := TxtStr . SubStr(SpaceFill, ps) . "`t"
  403. return TxtStr . SubStr(SpaceFill, strlen(TxtStr)+1) . "`t"
  404. }
  405. GetImageFiles(FilePath, FileName, ByRef Output, FileNameRegEx := "", FileLoopMode := "F")
  406. { ;; Get image paths in filepath using filepattern FileName
  407. ;~ msgbox GetImageFiles()`nFilePath := %FilePath%`nFileName := %FileName%`nFileNameRegEx := %FileNameRegEx%`nFileLoopMode := %FileLoopMode%
  408. IfNotExist, %FilePath%
  409. {
  410. MsgBox, 48, Get Image Paths, Error in GetImageFiles()`n`nUnable to locate "%FilePath%" folder, Filename '%FileName%'.`n`nCurrent working dir is "%A_WorkingDir%"
  411. return false
  412. }
  413. SaveWorkDir := A_WorkingDir
  414. Setworkingdir, %FilePath%
  415. found := false
  416. ; -- Loop with or Without recursion --
  417. Loop, Files, %FileName%, %FileLoopMode% ;; Find files in FilePath using Filepattern FileName
  418. {
  419. if(FileNameRegEx) ;; Can we test file name
  420. {
  421. FndPos := RegExMatch(A_LoopFileName, FileNameRegEx) ;; File Found matches
  422. if (ErrorLevel)
  423. {
  424. MsgBox, 48, Get Image Paths, RegExMatch Error in function GetImageFiles()`n`nruntime error: %ErrorLevel%`n`nFound searching string: %A_LoopFileName%`n`nusing search: %FileNameRegEx%
  425. break
  426. }
  427. if (not FndPos) ;; Filename not matches skip
  428. {
  429. continue
  430. }
  431. }
  432. fp := FilePath . "\" . A_LoopFileFullPath
  433. Output .= fp . "`n"
  434. found := true
  435. }
  436. Setworkingdir, %SaveWorkDir%
  437. return found
  438. }
  439. GetImagefromPath(FilePath, ByRef Output)
  440. { ;; Try to get Images from path
  441. FindRegEx := "<<.*?>>"
  442. ReplaceStr := "*"
  443. fp := StrReplace(FilePath, "/", "\")
  444. fp := RegExReplace(fp, FindRegEx, ReplaceStr)
  445. splitpath, fp, FileName, Dir, Ext
  446. ;; -- Manual if wildcard in path --
  447. if inStr(Dir, "*")
  448. {
  449. ; MsgBox, 64, Get Image Path, GetImageFromPath() error: Path contains wildcard`n `nPath : '%fp%'`nDir : '%Dir%'
  450. return false
  451. }
  452. FileNameRegEx := StrReplace(FileName, "*", "\d+") ; set up test for filename wildcard to be numbers only
  453. FileNameRegEx := "i)" . StrReplace(FileNameRegEx, ".", "\.")
  454. return GetImageFiles(Dir, FileName, Output, FileNameRegEx)
  455. }