-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulk-deoldify.au3
125 lines (95 loc) · 3.31 KB
/
bulk-deoldify.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <Array.au3>
#include <File.au3>
#include <WinAPIFiles.au3>
#include <WinAPI.au3>
; these are copy-and-paste lines for testing purposes
;_ArrayDisplay($arr, "alert")
;MsgBox(0, "alert", $str)
Local $cwd = _WinAPI_GetCurrentDirectory()
Local $blackAndWhiteFolderPath = $cwd
Local $originalFolderPath = $blackAndWhiteFolderPath & "\original";
Local $coloredFolderPath = $blackAndWhiteFolderPath & "\colored";
Local $deOldifyExePath = $blackAndWhiteFolderPath & "\" & getFiles($blackAndWhiteFolderPath, "exe")[1]
Local $photos = getFiles($blackAndWhiteFolderPath, "jpg")
; create the required folders
If Not FileExists($originalFolderPath) Then
DirCreate($originalFolderPath)
EndIf
If Not FileExists($coloredFolderPath) Then
DirCreate($coloredFolderPath)
EndIf
For $i = 1 to UBound($photos) -1
deOldify($photos[$i])
Next
Func getFiles($dir, $fileExtension)
Local $files = _FileListToArrayRec($dir, "*." & $fileExtension, $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT)
If @error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path " & $dir & " is invalid.")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No " & $fileExtension & " files were found.")
Exit
EndIf
Return $files
EndFunc
Func deOldify($filename)
Run($deOldifyExePath)
; change to match any substring in the title
Opt("WinTitleMatchMode", 2)
Local $wndMain = WinWaitActive("DeOldify")
; revert back to match the title from the start which is default
;Opt("WinTitleMatchMode", 1)
Local $posMainWnd = WinGetPos($wndMain)
; click the open button
AutoItSetOption("MouseCoordMode", 1)
MouseMove ($posMainWnd[0] + 200, $posMainWnd[1] + 200)
MouseClick("left")
; in the open window, pick the file to deoldify
pickFile("[CLASS:#32770]", "[CLASS:Button; INSTANCE:1]", $blackAndWhiteFolderPath, $filename)
; click the deoldify button
MouseMove ($posMainWnd[0] + 280, $posMainWnd[1] + 355)
MouseClick("left")
; get the control that is under the cursor
$ctrl = _WinAPI_WindowFromPoint(_WinAPI_GetMousePos())
; wait for the deoldifying process to complete, that is, when the button's text gets changeed to "Done!"
While 1
$var = ControlGetText($wndMain, "", $ctrl)
Sleep(1000)
If $var = "Done!" Then
ExitLoop
EndIf
WEnd
; click the save button
MouseMove ($posMainWnd[0] + 430, $posMainWnd[1] + 200)
MouseClick("left")
; in the save window, pick where to save
pickFile("Save colorized", "[CLASS:Button; INSTANCE:2]", $coloredFolderPath)
WinClose($wndMain)
; move the original file to another folder so that it won't get picked next time
FileMove($blackAndWhiteFolderPath & "\" & $filename, $originalFolderPath & "\" & $filename)
EndFunc
Func changePathInAddressBar($wnd, $dir)
; click the address bar to make editable
Local $pos = WinGetPos(ControlGetHandle($wnd, "", "[CLASS:ToolbarWindow32; INSTANCE:4]"))
MouseMove($pos[0], $pos[1])
MouseClick("left")
Sleep(1000)
; change the path in the address bar
ControlSetText($wnd, "", "[CLASS:Edit; INSTANCE:2]", $dir)
Send("{Enter}")
EndFunc
; pick to open or save
Func pickFile($title, $btnOk, $dir, $filename = "")
Local $wnd = WinWaitActive($title)
changePathInAddressBar($wnd, $dir)
Sleep(1000)
; set the filename
If $filename Then
ControlSetText($wnd, "", "[CLASS:Edit; INSTANCE:1]", $filename)
Sleep(1000)
EndIf
; click ok
ControlClick($wnd, "", $btnOk)
Sleep(1000)
EndFunc