forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveFileFolder.nsh
More file actions
256 lines (173 loc) · 5.12 KB
/
MoveFileFolder.nsh
File metadata and controls
256 lines (173 loc) · 5.12 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
; MoveFile and MoveFolder macros
;
; Author: theblazingangel@aol.com (for the AutoPatcher project - www.autopatcher.com)
; Created: June 2007
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;==================
; MoveFile macro
;==================
!macro MoveFile sourceFile destinationFile
!define MOVEFILE_JUMP ${__LINE__}
; Check source actually exists
IfFileExists "${sourceFile}" +3 0
SetErrors
goto done_${MOVEFILE_JUMP}
; Add message to details-view/install-log
DetailPrint "Moving/renaming file: ${sourceFile} to ${destinationFile}"
; If destination does not already exists simply move file
IfFileExists "${destinationFile}" +3 0
rename "${sourceFile}" "${destinationFile}"
goto done_${MOVEFILE_JUMP}
; If overwriting without 'ifnewer' check
${If} $switch_overwrite == 1
delete "${destinationFile}"
rename "${sourceFile}" "${destinationFile}"
delete "${sourceFile}"
goto done_${MOVEFILE_JUMP}
${EndIf}
; If destination already exists
Push $R0
Push $R1
Push $R2
push $R3
GetFileTime "${sourceFile}" $R0 $R1
GetFileTime "${destinationFile}" $R2 $R3
IntCmp $R0 $R2 0 older_${MOVEFILE_JUMP} newer_${MOVEFILE_JUMP}
IntCmp $R1 $R3 older_${MOVEFILE_JUMP} older_${MOVEFILE_JUMP} newer_${MOVEFILE_JUMP}
older_${MOVEFILE_JUMP}:
delete "${sourceFile}"
goto time_check_done_${MOVEFILE_JUMP}
newer_${MOVEFILE_JUMP}:
delete "${destinationFile}"
rename "${sourceFile}" "${destinationFile}"
delete "${sourceFile}" ;incase above failed!
time_check_done_${MOVEFILE_JUMP}:
Pop $R3
Pop $R2
Pop $R1
Pop $R0
done_${MOVEFILE_JUMP}:
!undef MOVEFILE_JUMP
!macroend
;==================
; MoveFolder macro
;==================
!macro MoveFolder source destination mask
!define MOVEFOLDER_JUMP ${__LINE__}
Push $R0
Push $R1
; Move path parameters into registers so they can be altered if necessary
StrCpy $R0 "${source}"
StrCpy $R1 "${destination}"
; Sort out paths - remove final backslash if supplied
Push $0
; Source
StrCpy $0 "$R0" 1 -1
StrCmp $0 '\' 0 +2
StrCpy $R0 "$R0" -1
; Destination
StrCpy $0 "$R1" 1 -1
StrCmp $0 '\' 0 +2
StrCpy $R1 "$R1" -1
Pop $0
; Create destination dir
CreateDirectory "$R1\"
; Add message to details-view/install-log
DetailPrint "Moving files: $R0\${mask} to $R1\"
; Push registers used by ${Locate} onto stack
Push $R6
Push $R7
Push $R8
Push $R9
; Duplicate dir structure (to preserve empty folders and such)
${Locate} "$R0" "/L=D" ".MoveFolder_Locate_createDir"
; Locate files and move (via callback function)
${Locate} "$R0" "/L=F /M=${mask} /S= /G=1" ".MoveFolder_Locate_moveFile"
; Delete subfolders left over after move
Push $R2
deldir_loop_${MOVEFOLDER_JUMP}:
StrCpy $R2 0
${Locate} "$R0" "/L=DE" ".MoveFolder_Locate_deleteDir"
StrCmp $R2 0 0 deldir_loop_${MOVEFOLDER_JUMP}
Pop $R2
; Delete empty subfolders moved - say the user just wanted to move *.apm files, they now also have a load of empty dir's from dir structure duplication!
Push $R2
delnewdir_loop_${MOVEFOLDER_JUMP}:
StrCpy $R2 0
${Locate} "$R1" "/L=DE" ".MoveFolder_Locate_deleteDir"
StrCmp $R2 0 0 delnewdir_loop_${MOVEFOLDER_JUMP}
Pop $R2
; Pop registers used by ${Locate} off the stack again
Pop $R9
Pop $R8
Pop $R7
Pop $R6
; Delete source folder if empty
rmdir "$R0"
Pop $R1
Pop $R0
!undef MOVEFOLDER_JUMP
!macroend
;==================
; MoveFolder macro's ${Locate} callback functions
;==================
Function .MoveFolder_Locate_createDir
${If} $R6 == ""
Push $R2
StrLen $R2 "$R0"
StrCpy $R2 $R9 '' $R2
CreateDirectory "$R1$R2"
Pop $R2
${EndIf}
Push $R1
FunctionEnd
Function .MoveFolder_Locate_moveFile
Push $R2
; Get path to file
StrLen $R2 "$R0"
StrCpy $R2 $R9 '' $R2
StrCpy $R2 "$R1$R2"
; If destination does not already exists simply move file
IfFileExists "$R2" +3 0
rename "$R9" "$R2"
goto done
; If overwriting without 'ifnewer' check
${If} $switch_overwrite == 1
delete "$R2"
rename "$R9" "$R2"
delete "$R9"
goto done
${EndIf}
; If destination already exists
Push $0
Push $1
Push $2
push $3
GetFileTime "$R9" $0 $1
GetFileTime "$R2" $2 $3
IntCmp $0 $2 0 older newer
IntCmp $1 $3 older older newer
older:
delete "$R9"
goto time_check_done
newer:
delete "$R2"
rename "$R9" "$R2"
delete "$R9" ;incase above failed!
time_check_done:
Pop $3
Pop $2
Pop $1
Pop $0
done:
Pop $R2
Push $R1
FunctionEnd
Function .MoveFolder_Locate_deleteDir
${If} $R6 == ""
RMDir $R9
IntOp $R2 $R2 + 1
${EndIf}
Push $R1
FunctionEnd