-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-for-push.prg
424 lines (394 loc) · 10.9 KB
/
check-for-push.prg
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
* Check files to see if any binary files have changed since the last push.
* If so, run foxbin2prg on those files and push them to git.
* ask for a commit message and commit the push.
* Do this at the start of the program:
DECLARE INTEGER Beep IN WIN32API ;
INTEGER nFreq, INTEGER nDuration
LOCAL lcData, lcDigest, lnByteCount
LOCAL loCnv as c_foxbin2prg OF "FOXBIN2PRG.PRG"
SET PROCEDURE TO "foxbin2prg.exe"
loCnv = CREATEOBJECT("c_foxbin2prg")
CLEAR
? "Check folder for changed files of specific extensions and update them to github"
* use the vfpencryption.fll library to calculate file hashs.
SET LIBRARY TO (LOCFILE("vfpencryption.fll", "FLL"))
SET SAFETY OFF
SET TALK ON
SET DELETED ON
CLEAR
IF !FILE("binFileHash.dbf")
CREATE TABLE binFileHash FREE (fext c(3), fname c(120), fhash c(15), hashChkd DATETIME, GitTrack l)
USE binFileHash EXCLUSIVE
INDEX ON fname TAG fname
INDEX ON fext + fname TAG fext1
INDEX on UPPER(fname) TAG upname
COPY ALL TO txtFileHash
USE txtFileHash EXCLUSIVE
INDEX ON fname TAG fname
USE
ENDIF
IF !FILE("binExtensions.dbf")
CREATE TABLE binExtensions FREE (ext c(3), convExt c(3), fb2pext c(3), binonly l, expdata l)
USE binExtensions EXCLUSIVE
INDEX ON ext TAG ext
COPY ALL TO txtExtensions
APPEND FROM ext.txt TYPE DELIMITED
USE
lnAnsw = MESSAGEBOX("You need to set up binary and text extensions to track. Do that now?",4)
IF lnAnsw = 6
USE binExtensions
BROWSE
MESSAGEBOX("Now set up text extensions",0)
USE txtExtensions
BROWSE
USE
ENDIF
ENDIF
IF !FILE("fileWork.dbf")
CREATE TABLE filework FREE (fname c(120))
USE filework
USE
ENDIF
IF !FILE("fileChanged.dbf")
CREATE TABLE fileChanged FREE (fext c(3), fname c(120))
USE fileChanged EXCLUSIVE
INDEX ON fname TAG fname
USE
ENDIF
IF !FILE("pushlist.dbf")
CREATE TABLE pushlist FREE (fname c(120))
ENDIF
CLOSE DATABASES ALL
USE pushlist
ZAP
SELECT 0
USE fileChanged EXCLUSIVE
ZAP
SELECT 0
USE filework EXCLUSIVE
ZAP
SELECT 0
USE binExtensions
SET ORDER TO ext && ext
SELECT 0
USE binFileHash
* Make sure that file cases match reality...
! dir *.* /s/b/on > workdir.txt
SELECT binfilehash
SET ORDER TO upname && upper(fname)
SELECT pushlist
APPEND FROM workdir.txt TYPE SDF
GO TOP
SCAN
SELECT binfilehash
GO TOP
SEEK(UPPER(TRIM(pushlist.fname)))
IF FOUND()
IF !(ALLTRIM(binfilehash.fname) == ALLTRIM(pushlist.fname))
REPLACE fname WITH ALLTRIM(pushlist.fname)
ENDIF
ENDIF
SELECT pushlist
ENDSCAN
SELECT pushlist
zap
SELECT binfilehash
SET ORDER TO upname && Upper(fname)
GO TOP
lnBChanged = 0
SELECT binExtensions
GO TOP
SCAN
lcExt = binExtensions.ext
lcConv = binExtensions.convExt
lcDirCmd = "dir *." + lcExt + " /b /on /s > workdir.txt"
CLEAR
@ 2,2 SAY "Working on extension " + lcExt
@ 4,2 CLEAR
! "&lcDirCmd"
SELECT filework
ZAP
APPEND FROM workdir.txt TYPE SDF
*REPLACE ALL fname WITH UPPER(fname)
IF lcExt = "DBF"
DELETE FOR "BINEXT" $ upper(fname)
DELETE FOR "FILEWORK" $ upper(fname)
DELETE FOR "BINFILEHASH" $ upper(fname)
DELETE FOR "FILECHANGED" $ upper(fname)
DELETE FOR "PUSHLIST" $ upper(fname)
DELETE FOR "TXTFILEHASH" $ upper(fname)
DELETE FOR "TXTEXTENSIONS" $ upper(fname)
ENDIF
GO TOP
SCAN
lcFNameW = ALLTRIM(filework.fname)
@ 4,2 SAY lcFNameW + SPACE(15)
lcFileHash = STRCONV(HASHFILE(lcFNameW,5), 15)
SELECT binFileHash
GO top
llFound = SEEK(UPPER(lcFNameW))
IF !llFound
?? "New file "
APPEND BLANK
REPLACE fname WITH (lcFNameW)
REPLACE hashChkd WITH DATETIME()
REPLACE fhash WITH lcFileHash
REPLACE fext WITH lcExt
lnAnsw = MESSAGEBOX("New File " + fname + " Track in Git?",36)
IF lnAnsw = 6 && Yes
REPLACE GitTrack WITH .T.
REPLACE fhash WITH "-new-" && So, when we get to the next if, it's different and we regard it as new
ELSE
REPLACE GitTrack WITH .F.
ENDIF
ENDIF
IF TRIM(binFileHash.fhash) <> lcFileHash .AND. binFileHash.GitTrack = .T. && The file has changed and we're tracking it.
?? "File changed "
REPLACE hashChkd WITH DATETIME()
REPLACE fhash WITH lcFileHash
SELECT fileChanged
APPEND BLANK
REPLACE fname WITH lcFNameW, fext WITH lcExt
lnBChanged = lnBChanged + 1
ENDIF
?? SPACE(40)
SELECT filework
ENDSCAN
SELECT binExtensions
ENDSCAN
@ 6,2 SAY "I found " + TRANSFORM(lnBChanged) + " binary files that changed that will be pushed to GIT."
* Now, loop through the changed files and...
* ... if the file extension is one that foxbin2prg doesn't support like .apd...
* ... ... rename it to .dbf
* ... ... then run foxbin2prg on it
* ... ... then rename it back
* ... otherwise, if it is supported, run foxbin2prg on it,
* ... and either way, add the new text file to pushlist.
*
* ... If the file is a database, or if it's an apd or a pjd,
* ... ... use the file, copy it to a csv and
* ... ... add the csv to pushlist
IF lnBChanged > 0
CLOSE DATABASES ALL
USE pushlist
SELECT 0
USE binExtensions
SET ORDER TO ext && EXT
SCAN
lcExt = ext
lcConvExt = TRIM(convExt)
lcFb2pExt = TRIM(fb2pext)
llBinOnly = binonly
llExpData = expdata
@ 8,2 SAY "Checking for changed files of type " + lcExt
SELECT * FROM fileChanged WHERE fext = lcExt INTO CURSOR bin2text
IF _TALLY > 0
SELECT bin2text
SCAN
lcFName = TRIM(bin2text.fname )
* VPME binary files with extensions unknown to foxbin2prg
* have to be renamed to something else, then bin2prg'ed
* then renamed back...
IF lcConvExt > " " && unsupported extension,
lcNewName = STRTRAN(lcFName,"."+lcExt,"."+lcConvExt)
lcNewName = STRTRAN(lcFName,"."+LOWER(lcExt),"."+lcConvExt)
IF FILE(lcNewName)
DELETE FILE (lcNewName)
ENDIF
RENAME (lcFName) TO (lcNewName)
*lcConvCmd = "foxbin2prg " + lcNewName
*! "&lcConvCmd"
RENAME (lcNewName) TO (lcFName)
lcNewName = STRTRAN(lcNewName, "." + lcConvExt, "." + lcFb2pExt)
lcNFb2E = LEFT(lcExt,2) + "2"
lcOFb = STRTRAN(lcNewName, "." + lcFb2pExt, "." + lcNFb2E)
DELETE FILE (lcNFb2E) && delete the .xx2 file
loCnv.execute( lcNewName ) && create the .xx2 file
IF FILE(lcOFb)
DELETE FILE (lcOFb) && get rid of the old .nn2 file
ENDIF
RENAME (lcNewName) TO (lcOFb) && rename the .xx2 to .nn2
SELECT pushlist
APPEND BLANK
REPLACE fname WITH (lcOFb)
ELSE && OK, good, it is an known extension
* Some extensions like FLLs and DLLs can only be stored as
* binary blobs, they can't be converted to text and diffed.
* if so, we SKIP running foxbin2prg against them.
IF llBinOnly && DO NOT run foxbin2prg
SELECT pushlist
APPEND BLANK
REPLACE fname WITH lcNewName
ELSE && NOT Binary only so do a normal fb2p
* change extension from .xxx to .xx2
lcNewName = STRTRAN(lcFName, "." + lcExt, "." + lcFb2pExt)
lcNewName = STRTRAN(lcFName, "." + LOWER(lcExt), "." + lcFb2pExt)
DELETE FILE (lcNewName)
loCnv.execute( lcFName ) && Run foxbin2prg
SELECT pushlist
APPEND BLANK
REPLACE fname WITH lcNewName
ENDIF
* foxbin2prg doesn't export the data of dbf's, only the
* structure. We want the data too, so we have to put
* that somewhere. So, we make CSVs, but call them CS2
* for consistancy's sake.
IF llExpData && Export data of dbf's.
lcDataFileName = STRTRAN(lcFName, "." + lcExt, ".CS2")
SELECT 0
USE (lcFName)
COPY ALL TO (lcDataFileName) TYPE CSV
USE
SELECT pushlist
APPEND BLANK
REPLACE fname WITH lcDataFileName
ENDIF
SELECT bin2text
ENDIF
ENDSCAN
ENDIF
SELECT binExtensions
ENDSCAN
* Now, we have the binaries we want to push in pushlist as *.xx2 files.
* So, loop through those, and push each one.
@ 10,2 SAY "Adding text versions of changed binary files to git."
CLOSE DATABASES ALL
USE pushlist
SET PRINTER TO "pushlist.bat"
SET CONSOLE OFF
SET PRINTER ON
SCAN
? "git add " + TRIM(pushlist.fname)
ENDSCAN
*3? "pause"
SET PRINTER OFF
SET PRINTER TO
SET CONSOLE ON
! pushlist.bat
COPY FILE pushlist.bat TO binfiles.txt
ENDIF
? " "
? "Done with Binaries. Now, deal with the non-binarys."
CLOSE DATABASES ALL
USE txtFileHash
SET ORDER TO fname
SELECT 0
USE fileChanged EXCLUSIVE
ZAP
SELECT 0
USE filework EXCLUSIVE
ZAP
SELECT 0
USE pushlist EXCLUSIVE
ZAP
SELECT 0
lnTChanged = 0
USE txtExtensions
GO TOP
SCAN
lcExt = txtExtensions.ext
lcDirCmd = "dir *." + lcExt + " /b /on /s > workdir.txt"
@ 14,2 SAY "Working on extension " + lcExt + SPACE(5)
@ 16,2 CLEAR
! "&lcDirCmd"
SELECT filework
ZAP
APPEND FROM workdir.txt TYPE SDF
* REPLACE ALL fname WITH UPPER(fname)
DELETE FOR "WORKDIR" $ upper(fname)
DELETE FOR "PUSHLIST" $ upper(fname)
GO TOP
SCAN
lcFNameW = ALLTRIM(filework.fname)
@ 16,2 SAY lcFNameW + SPACE(5)
lcFileHash = STRCONV(HASHFILE(lcFNameW,5), 15)
SELECT txtFileHash
GO TOP
llFound = SEEK(UPPER(lcFNameW))
IF !llFound
?? "New file "
APPEND BLANK
REPLACE fname WITH UPPER(lcFNameW)
REPLACE hashChkd WITH DATETIME()
REPLACE fhash WITH lcFileHash
REPLACE fext WITH lcExt
lnAnsw = MESSAGEBOX("New File " + fname + " Track in Git?",36)
IF lnAnsw = 6 && Yes
REPLACE GitTrack WITH .T.
REPLACE fhash WITH "-new-" && So, when we get to the next if, it's different and we regard it as new
ELSE
REPLACE GitTrack WITH .F.
ENDIF
ENDIF
IF TRIM(txtFileHash.fhash) <> lcFileHash .AND. txtFileHash.GitTrack = .T. && The file has changed and we're tracking it.
?? "File changed "
REPLACE hashChkd WITH DATETIME()
REPLACE fhash WITH lcFileHash
SELECT pushlist
APPEND BLANK
REPLACE fname WITH lcFNameW
lnTChanged = lnTChanged + 1
ENDIF
?? SPACE(40)
SELECT filework
ENDSCAN
SELECT txtExtensions
ENDSCAN
IF lnTChanged > 0
* Now, we have the text files we want to push in pushlist
* So, loop through those, and push each one.
@ 20,2 SAY "Pushing " + TRANSFORM(lnTChanged) + " text files to git."
CLOSE DATABASES ALL
USE pushlist
SET PRINTER TO "pushlist.bat"
SET CONSOLE OFF
SET PRINTER ON
SCAN
? "git add " + TRIM(pushlist.fname)
ENDSCAN
*? "pause"
SET PRINTER OFF
SET PRINTER TO
SET CONSOLE ON
? " "
? " "
lcCommit = SPACE(60)
Beep(256,100)
Beep(400,50)
Beep(256,100)
DO WHILE lcCommit = SPACE(60)
@ 18,2 SAY "Short commit message? x to cancel: " GET lcCommit
READ
ENDDO
IF TRIM(UPPER(lcCommit)) == "X"
@ 18,2 SAY "Cancel requested."
RETURN
ENDIF
lcCommand = 'git commit -m "' + TRIM(lcCommit) + '"'
SET PRINTER TO "pushlist.bat" ADDITIVE
SET CONSOLE OFF
SET PRINTER ON
? lcCommand
? "git push"
? " "
SET PRINTER OFF
SET PRINTER TO
SET CONSOLE ON
! pushlist.bat
ELSE
@ 18,2 SAY "No text files changed. "
ENDIF
IF lnBChanged > 0
bfBat = FILETOSTR("binfiles.txt")
ELSE
bfBat = " No changed binary files. "
ENDIF
IF lnTChanged > 0
tfbat = FILETOSTR("pushlist.bat")
ELSE
tfbat = " No changed text files."
ENDIF
bfBat = "This is what we found and pushed." + CHR(13) + CHR(10) + bfBat + CHR(13) + CHR(10) + tfbat
STRTOFILE(bfBat,"CFPaction.txt",0)
MODIFY COMMAND CFPaction.txt
@ 22,2 SAY "Done!"