home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / archive.zip / ARCHIVE.CMD next >
OS/2 REXX Batch file  |  1999-10-03  |  23KB  |  704 lines

  1. /*
  2.  * Generator   : PPWIZARD version 99.276
  3.  *             : FREE tool for OS/2, Windows, DOS and UNIX by Dennis Bareis (db0@anz.com)
  4.  *             : http://www.labyrinth.net.au/~dbareis/ppwizard.htm
  5.  * Time        : Sunday, 3 Oct 1999 8:34:37am
  6.  * Input File  : E:\DB\PROJECTS\OS2\archive\ARCHIVE.x
  7.  * Output File : .\OUT\ARCHIVE.CMD
  8.  */
  9.  
  10. if arg(1)="!CheckSyntax!" then exit(21924)
  11.  
  12. /*
  13. *$Header:E:/DB/PVCS.IT/OS2/ARCHIVE/ARCHIVE.X_V 1.9 03 Mar 1999 11:41:46 Dennis_Bareis $
  14. */
  15. PgmVersion="99.276"
  16. PgmParameters=translate(strip(arg(1)))
  17. parse var PgmParameters Command Parameters
  18. address cmd '@echo off'
  19. EscapeChar=d2c(27)
  20. NlChar=d2c(10)
  21. Reset=EscapeChar|| '[0m'
  22. HighlightColor=EscapeChar|| '[1;33m'
  23. TitleColor=EscapeChar|| '[0;32m'
  24. ErrorColor=EscapeChar|| '[1;31m'
  25. NormalColor=EscapeChar|| '[0;32m'
  26. call DisplayCopyright
  27. call RxFuncAdd 'SysIni',           'RexxUtil', 'SysIni'
  28. call RxFuncAdd 'SysOs2Ver',        'RexxUtil', 'SysOs2Ver'
  29. call RxFuncAdd 'SysCreateObject',  'RexxUtil', 'SysCreateObject'
  30. call RxFuncAdd 'SysSetObjectData', 'RexxUtil', 'SysSetObjectData'
  31. call RxFuncAdd 'SysSearchPath',    'RexxUtil', 'SysSearchPath'
  32. call RxFuncAdd 'RxMessageBox',     'RexxUtil', 'RxMessageBox'
  33. call RxFuncAdd 'SysFileDelete',    'RexxUtil', 'SysFileDelete'
  34. call RxFuncAdd 'SysFileTree',      'RexxUtil', 'SysFileTree'
  35. /*
  36. *BASEDATE.XH Version 99.034 by Dennis Bareis
  37. *http://www.labyrinth.net.au/~dbareis/index.htm(db0@anz.com)
  38. */
  39. signal EndBASEDATEXh
  40.  
  41. BaseDate:procedure
  42. TheDate=translate(arg(1), ' ', '/-')
  43. if TheDate='' then
  44. TheDate=date('Sorted')
  45. parse var TheDate Year MM DD
  46. if length(Year)>=8 then
  47. do
  48. DD=substr(Year,7,2)
  49. MM=substr(Year,5,2)
  50. Year=left(Year,4)
  51. end
  52. DaysInMonth='31  28  31  30  31  30  31  31  30  31  30  31'
  53. if datatype(Year, 'WholeNumber')<>1 then
  54. return(-10)
  55. if datatype(MM, 'WholeNumber')<>1 then
  56. return(-20)
  57. if datatype(DD, 'WholeNumber')<>1 then
  58. return(-30)
  59. if MM<0|MM>12 then
  60. return(-21)
  61. DaysThisMonth=word(DaysInMonth,MM)
  62. if MM=2 then
  63. DaysThisMonth=DaysThisMonth+1
  64. if DD<0|DD>DaysThisMonth then
  65. return(-31)
  66. if length(strip(Year))=2 then
  67. do
  68. if Year>=80 then
  69. Year='19' ||Year
  70. else
  71. Year='20' ||Year
  72. end
  73. y=Year-0001
  74. b=y*365
  75. b=b+y%4
  76. b=b-y%100
  77. b=b+y%400
  78. m=mm-01
  79. do i=1 to m
  80. b=b+word(DaysInMonth,i)
  81. end
  82. if mm>2 then
  83. do
  84. if 0=Year//4 then
  85. do
  86. if 0=Year//100 then
  87. do
  88. if 0=Year//400 then
  89. b=b+1
  90. end
  91. else
  92. b=b+1
  93. end
  94. end
  95. d=dd-01
  96. b=b+d
  97. return(b)
  98.  
  99. EndBASEDATEXh:
  100. parse source . . RexxCmdName
  101. ArchivePgmDir=filespec('drive', RexxCmdName) || filespec('Path',RexxCmdName)
  102. LogFile=ArchivePgmDir|| "ARCHIVE.LOG"
  103. ArchiveIniFile=ArchivePgmDir|| "ARCHIVE.INI"
  104. signal on NOVALUE name RexxTrapUninitializedVariable
  105. signal on SYNTAX name RexxTrapSyntaxError
  106. signal on HALT name RexxCtrlC
  107. signal EndINSTALLXh
  108.  
  109. ProcessInstallCommand:
  110. call Normal 'Archive software is installed at "' || ArchivePgmDir || '".'
  111. CmdExe=SysSearchPath('PATH', 'CMD.EXE')
  112. if CmdExe='' then
  113. Error("Can't find OS/2 directory.")
  114. Os2Path=filespec('drive', CmdExe) || filespec('path',CmdExe)
  115. ArchiveFile=Os2Path|| 'BOOT\ARCHBASE.$$$'
  116. call Normal 'The OS/2 archive file is "' || ArchiveFile || '".'
  117. if PatchDetails='' then
  118. do
  119. ArchiveFileBu=Os2Path|| 'BOOT\ARCHBASE.ORG'
  120. if stream(ArchiveFileBu, 'c', 'query exists') = '' then
  121. do
  122. call Normal 'Backing it up to "' || ArchiveFileBu || '".'
  123. address cmd 'copy ' || ArchiveFile || ' ' || ArchiveFileBu || ' >nul'
  124. if Rc<>0 then
  125. Error("Copy failed (RC=" || RC || ')')
  126. end
  127. call OpenDesktopProperties
  128. call Highlight 'Select "ARCHIVE" tab, Ensure "Create archive at system startup" is OFF.'
  129. call Pause
  130. call Normal 'Recording current state (OFF)...'
  131. WhenOff=GetFileContents(ArchiveFile)
  132. do until WhenOff<>WhenOn
  133. call OpenDesktopProperties
  134. call Highlight 'Set the "Create archive at system startup" option to ON.'
  135. call Pause
  136. call Normal 'Recording current state (ON)...'
  137. WhenOn=GetFileContents(ArchiveFile)
  138. end
  139. if length(WhenOn)<>length(WhenOff)then
  140. Error("File sizes appear to differ (not expected)")
  141. DiffPos=compare(WhenOff,WhenOn)
  142. if DiffPos=0 then
  143. Error("Can't find difference (unexpected)")
  144. HexOffset=d2x(DiffPos-1)
  145. HexValueOff=c2x(substr(WhenOff,DiffPos,1))
  146. HexValueOn=c2x(substr(WhenOn,DiffPos,1))
  147. NewValue=HexValueOff|| ' ' || HexValueOn || ' ' || HexOffset  || ' ' ||ArchiveFile
  148. call SysIniWrite "Configuration", "PatchDetails",NewValue
  149. call SysIniWrite "Configuration", "InstalledOnOs2Version",Os2VerNow
  150. end
  151. call Normal 'Patch offset is x' || HexOffset || ' (OFF=x' || HexValueOff || ', ON=x' || HexValueOn || ').'
  152. call charout,NormalColor|| "Days between automatic archives (0=OFF) : " ||Reset
  153. NumberOfDays=strip(linein())
  154. if NumberOfDays='' then
  155. NumberOfDays=0
  156. if datatype(NumberOfDays, 'W')=0 then
  157. NumberOfDays=7
  158. call _HowManyArchives
  159. KeyFileRc=InstallHandleOs2KeyFile()
  160. if KeyFileRc<>0 then
  161. call SayAndLogErrorLine 'THIS ARCHIVE PROGRAM CAN NOT MANAGE YOUR "OS2.KEY" FILE'
  162. Title="Turn on Archiving"
  163. Location="<WP_DESKTOP>"
  164. Class="WPProgram"
  165. ObjMode="ReplaceIfExists"
  166. SetupString="EXENAME=*;"
  167. SetupString=SetupString|| 'EXENAME=CMD.EXE;'
  168. SetupString=SetupString|| 'PARAMETERS=/c ' || RexxCmdName || ' ON;'
  169. SetupString=SetupString|| "ICONFILE=" || ArchivePgmDir || 'ON.ICO;'
  170. SetupString=SetupString|| "MINIMIZED=YES;"
  171. SetupString=SetupString|| "PROGTYPE=PM;"
  172. SetupString=SetupString|| "OBJECTID=<TurnArchiveOn>;"
  173. Rc=SysCreateObject(Class,Title,Location,SetupString,ObjMode)
  174. call Normal 'Creating icon - ' ||Title
  175. if Rc=0 then
  176. Error("Could not create the icon")
  177. Title="Turn off Archiving"
  178. Location="<WP_DESKTOP>"
  179. Class="WPProgram"
  180. SetupString="EXENAME=*;"
  181. SetupString=SetupString|| 'EXENAME=CMD.EXE;'
  182. SetupString=SetupString|| 'PARAMETERS=/c ' || RexxCmdName || ' OFF;'
  183. SetupString=SetupString|| "ICONFILE="   || ArchivePgmDir || 'OFF.ICO;'
  184. SetupString=SetupString|| "MINIMIZED=YES;"
  185. SetupString=SetupString|| "PROGTYPE=PM;"
  186. SetupString=SetupString|| "OBJECTID=<TurnArchiveOff>;"
  187. Rc=SysCreateObject(Class,Title,Location,SetupString,ObjMode)
  188. call Normal 'Creating icon - ' ||Title
  189. if Rc=0 then
  190. Error("Could not create the icon")
  191. if NumberOfDays=0 then
  192. Title="Turn off Archiving"
  193. else
  194. Title="Turn off Archiving (turn on every " || NumberOfDays || ' days)'
  195. Location="<WP_START>"
  196. Class="WPProgram"
  197. SetupString="EXENAME=*;"
  198. SetupString=SetupString|| 'EXENAME=CMD.EXE;'
  199. SetupString=SetupString|| 'PARAMETERS=/c ' || RexxCmdName || ' OFF ' || NumberOfDays || ';'
  200. SetupString=SetupString|| "ICONFILE="   || ArchivePgmDir || 'OFF.ICO;'
  201. SetupString=SetupString|| "MINIMIZED=YES;"
  202. SetupString=SetupString|| "PROGTYPE=PM;"
  203. SetupString=SetupString|| "OBJECTID=<TurnArchiveOffInStartupFolder>;"
  204. Rc=SysCreateObject(Class,Title,Location,SetupString,ObjMode)
  205. call Normal 'Creating icon - ' ||Title
  206. if Rc=0 then
  207. Error("Could not create the icon")
  208. say ''
  209. call Highlight 'STARTUP FOLDER updated so that archiving is automatically'
  210. call Highlight 'turned off/on after boot.  Delete this icon icon if you wish.'
  211. say ''
  212. call Normal 'Setup Completed'
  213. call LogLine ''
  214. return(0)
  215.  
  216. InstallHandleOs2KeyFile:
  217. ArchiveFileContents=GetFileContents(ArchiveFile)
  218. PathPos=pos(Os2Path,ArchiveFileContents)
  219. if PathPos=0 then
  220. do
  221. call LogLine 'Looks like you are not using the default archive path (or any under "' || Os2Path || '")'
  222. if substr(ArchiveFileContents,8,1)=':' then
  223. PathPos=7
  224. else
  225. do
  226. call SayAndLogErrorLine 'Could not determine where archive path is...'
  227. return(1)
  228. end
  229. end
  230. parse value substr(ArchiveFileContents,PathPos)with ArchivePath '00'x
  231. Os2KeyFile=ArchivePath|| '\OS2.KEY'
  232. Os2KeyFileBu=ArchivePath|| '\OS2.ORG'
  233. call Normal '"OS2.KEY" file should be located in the "' || ArchivePath || '" directory.'
  234. address cmd 'attrib -r -s -h ' || Os2KeyFile || ' >nul 2>&1'
  235. if stream(Os2KeyFile, 'c', 'query exists') = '' then
  236. do
  237. call SayAndLogErrorLine 'The key file "' || Os2KeyFile || '" does not exist!'
  238. return(2)
  239. end
  240. call SysIniWrite "Configuration", "KeyFileNamePosn",PathPos
  241. if stream(Os2KeyFileBu, 'c', 'query exists') = '' then
  242. do
  243. call Normal 'Backing it up to "' || Os2KeyFileBu || '".'
  244. address cmd 'copy ' || Os2KeyFile || ' ' || Os2KeyFileBu || ' >nul'
  245. if Rc<>0 then
  246. Error("Copy failed (RC=" || RC || ')')
  247. end
  248. Os2KeyDetails=SysIniRead("Configuration", "KeyFilesToArchive", '')
  249. if Os2KeyDetails='' then
  250. do
  251. call Normal 'Importing details from "' || Os2KeyFile || '".'
  252. ImportLine=0
  253. CloseRc=stream(Os2KeyFile, 'c', 'close')
  254. do while lines(Os2KeyFile)<>0
  255. CurrentLine=strip(linein(Os2KeyFile))
  256. ImportLine=ImportLine+1
  257. if CurrentLine='' then
  258. iterate
  259. if left(CurrentLine,length('KEYFILE:')) <> 'KEYFILE:' then
  260. Error('Line #' || ImportLine || ' of file does not begin with "' || 'KEYFILE:' || '"!')
  261. CurrentFile=substr(CurrentLine,length('KEYFILE:')+1)
  262. call Normal '    * FOUND: ' ||CurrentFile
  263. if Os2KeyDetails='' then
  264. Os2KeyDetails=CurrentFile
  265. else
  266. Os2KeyDetails=Os2KeyDetails|| ';' ||CurrentFile
  267. end
  268. CloseRc=stream(Os2KeyFile, 'c', 'close')
  269. call SysIniWrite "Configuration", "KeyFilesToArchive",Os2KeyDetails
  270. end
  271. Os2KeyDetailsBefore=Os2KeyDetails
  272. TmpFile=ArchivePgmDir|| "KEYFILES.LST"
  273. CloseRc=stream(TmpFile, 'c', 'close')
  274. DosDelRc=SysFileDelete(TmpFile)
  275. if stream(TmpFile, 'c', 'query exists') <> '' then
  276. Error('Could not delete "' || TmpFile || '" - do you have it in use?')
  277. call lineout TmpFile, ';******************************'
  278. call lineout TmpFile, ';**** PRESS ALT+F4 TO EXIT ****'
  279. call lineout TmpFile, ';******************************'
  280. call lineout TmpFile, ''
  281. call lineout TmpFile, ';Every time OS/2 archives the desktop it also backs up'
  282. call lineout TmpFile, ';a list of "KEY" files.  You may now update this list'
  283. call lineout TmpFile, ';if you have some very important files.'
  284. call lineout TmpFile, ''
  285. call lineout TmpFile, ';You may use wildcards to specify a range of files, in'
  286. call lineout TmpFile, ';which case the actual filenames to be archived are'
  287. call lineout TmpFile, ';worked out every time archiving is turned on. As an'
  288. call lineout TmpFile, ';example you could specify "C:\OS2\MDOS\WINOS2\*.INI"'
  289. call lineout TmpFile, ''
  290. call lineout TmpFile, ';If you preceed the filenames with "+" as in "+C:\*.INI"'
  291. call lineout TmpFile, ';then all subdirectories are searched.'
  292. call lineout TmpFile, ''
  293. call lineout TmpFile, ''
  294. call lineout TmpFile, ';WARNING'
  295. call lineout TmpFile, ';~~~~~~~'
  296. call lineout TmpFile, ';The files that you specify are restored when you choose'
  297. call lineout TmpFile, ';to restore an older archive.  You MUST remember this fact'
  298. call lineout TmpFile, ';if all you wish to do is restore the workplace shell.'
  299. call lineout TmpFile, ''
  300. call lineout TmpFile, ''
  301. do while Os2KeyDetails<> ''
  302. parse var Os2KeyDetails FileMask ';' Os2KeyDetails
  303. call lineout TmpFile,FileMask
  304. end
  305. CloseRc=stream(TmpFile, 'c', 'close')
  306. call Normal 'You may now MODIFY the list of files to ARCHIVE'
  307. address cmd 'E.EXE ' ||TmpFile
  308. Os2KeyDetails=''
  309. CloseRc=stream(TmpFile, 'c', 'close')
  310. do while lines(TmpFile)<>0
  311. CurrentFile=strip(linein(TmpFile))
  312. if CurrentFile='' then
  313. iterate
  314. if left(CurrentFile,1)=';' then
  315. iterate
  316. if Os2KeyDetails='' then
  317. Os2KeyDetails=CurrentFile
  318. else
  319. Os2KeyDetails=Os2KeyDetails|| ';' ||CurrentFile
  320. end
  321. CloseRc=stream(TmpFile, 'c', 'close')
  322. DosDelRc=SysFileDelete(TmpFile)
  323. if Os2KeyDetailsBefore=Os2KeyDetails then
  324. call Normal '    * List unmodified'
  325. else
  326. do
  327. call Normal '    * List was changed'
  328. call SysIniWrite "Configuration", "KeyFilesToArchive",Os2KeyDetails
  329. end
  330. call CreateOs2KeyFile
  331. return(0)
  332.  
  333. _HowManyArchives:
  334. ArchiveFileContents=GetFileContents(ArchiveFile)
  335. ThreePos=SysIniRead("Configuration", "NumberOfArchivesPosn", '')
  336. if ThreePos='' then
  337. do
  338. call LogLine "Need to determine where OS/2 stores the archive count."
  339. Three=d2c(3)
  340. ThreePos=pos(Three,ArchiveFileContents)
  341. if ThreePos=0|pos(Three,ArchiveFileContents,ThreePos+1)<>0 then
  342. do
  343. call SayAndLogErrorLine "Can't determine archive count posn (can't change count)"
  344. return
  345. end
  346. call SysIniWrite "Configuration", "NumberOfArchivesPosn",ThreePos
  347. end
  348. call LogLine 'Warning user to use 3 archives unless they test themselves'
  349. say ''
  350. call HighLight "*******************************************************************"
  351. call HighLight "*** I have some evidence that while you can increase the number ***"
  352. call HighLight "*** of archives, when you go to restore it won't let you choose ***"
  353. call HighLight "*** the lower numbers...  I am warning you that at this stage   ***"
  354. call HighLight "*** I do not have time to work it out. I RECOMMEND you press    ***"
  355. call HighLight "*** SELECT 3 for the question below unless you have tested this ***"
  356. call HighLight "*** on a machine without important information.  If you do test ***"
  357. call HighLight '*** then please SEND RESULTS to "dbareis@labyrinth.net.at"!     ***'
  358. call HighLight "*******************************************************************"
  359. say ''
  360. CurrentCount=c2d(substr(ArchiveFileContents,ThreePos,1))
  361. do forever
  362. call charout,NormalColor|| "Number of archives to keep (ENTER=" || CurrentCount || " or 1-9) : " ||Reset
  363. NewCount=strip(linein())
  364. if NewCount='' then
  365. return
  366. if datatype(NewCount, 'W')then
  367. do
  368. if NewCount>=1&NewCount<=9 then
  369. leave
  370. end
  371. end
  372. if NewCount<>CurrentCount then
  373. PatchRc=PatchFile(ArchiveFile,d2x(ThreePos-1),d2x(NewCount))
  374. call LogLine "Now keeping " || NewCount || " archives."
  375. return
  376.  
  377. CreateOs2KeyFile:
  378. ArchiveFileContents=GetFileContents(ArchiveFile)
  379. PathPos=SysIniRead("Configuration", "KeyFileNamePosn", '')
  380. if PathPos='' then
  381. do
  382. call LogLine "Can't process 'OS2.KEY' until reinstalled."
  383. return
  384. end
  385. parse value substr(ArchiveFileContents,PathPos)with ArchivePath '00'x
  386. Os2KeyFile=ArchivePath|| '\OS2.KEY'
  387. call Normal 'Creating "' || Os2KeyFile || '"'
  388. Os2KeyDetails=SysIniRead("Configuration", "KeyFilesToArchive", '')
  389. if Os2KeyDetails='' then
  390. do
  391. call LogLine "Can't find list of KEY Files (need to reinstall)."
  392. address cmd 'start "*** ARCHIVE REINSTALL ***" /WIN /F ' || RexxCmdName || ' install'
  393. exit(GetLineNumber())
  394. end
  395. CloseRc=stream(Os2KeyFile, 'c', 'close')
  396. address cmd 'attrib -r -s -h ' || Os2KeyFile || ' >nul 2>&1'
  397. DosDelRc=SysFileDelete(Os2KeyFile)
  398. do while Os2KeyDetails<> ''
  399. parse var Os2KeyDetails FileMask ';' Os2KeyDetails
  400. if left(FileMask,1)<> '+' then
  401. DoSubDir=''
  402. else
  403. do
  404. DoSubDir='S'
  405. FileMask=substr(FileMask,2)
  406. end
  407. File.0=0
  408. call SysFileTree FileMask, 'File', 'FO' ||DoSubDir
  409. if File.0=0 then
  410. do
  411. if substr(FileMask,2,1)=':' then
  412. call Normal '    * No files match "' || FileMask || '"'
  413. if DoSubDir='' & verify(FileMask, "*?", "M")=0 then
  414. call lineout Os2KeyFile, 'KEYFILE:' ||FileMask
  415. end
  416. else
  417. do
  418. do FileIndex=1 to File.0
  419. call lineout Os2KeyFile, 'KEYFILE:' ||File.FileIndex
  420. end
  421. end
  422. end
  423. CloseRc=stream(Os2KeyFile, 'c', 'close')
  424. return
  425.  
  426. EndINSTALLXh:
  427. Os2VerNow=SysOs2Ver()
  428. PatchDetails=SysIniRead("Configuration", "PatchDetails", '')
  429. if PatchDetails<> '' then
  430. do
  431. Os2VerInstall=SysIniRead("Configuration", "InstalledOnOs2Version", '')
  432. if Os2VerInstall='' then
  433. do
  434. call SysIniWrite "Configuration", "InstalledOnOs2Version",Os2VerNow
  435. Os2VerInstall=Os2VerNow
  436. end
  437. if Os2VerInstall<>Os2VerNow then
  438. do
  439. if Command<> "INSTALL" then
  440. do
  441. call LogLine 'Archive installed on OS/2 version ' || Os2VerInstall || ', version is now ' || Os2VerNow || ', must reinstall'
  442. call SayAndLogErrorLine 'We need to reinstall ARCHIVE as the OS/2 version has changed since it was installed.'
  443. address cmd 'start "*** ARCHIVE REINSTALL ***" /WIN /F ' || RexxCmdName || ' install'
  444. exit(GetLineNumber())
  445. end
  446. end
  447. end
  448. if PatchDetails='' then
  449. do
  450. if Command<> "INSTALL" then
  451. do
  452. call Error "We can't access the configuration details stored in '" || ArchiveIniFile || "'."
  453. exit(GetLineNumber())
  454. end
  455. end
  456. parse var PatchDetails HexValueOff HexValueOn HexOffset ArchiveFile
  457. ExitRc=0
  458. select
  459. when Command="INSTALL" then
  460. ExitRc=ProcessInstallCommand()
  461. when Command="ON" then
  462. do
  463. call CreateOs2KeyFile
  464. if PatchFile(ArchiveFile,HexOffset,HexValueOn)=0 then
  465. do
  466. Msg="Archiving will take place on following boot."
  467. Icon="INFORMATION"
  468. end
  469. else
  470. do
  471. Msg="Archiving was already turned on!"
  472. Icon="EXCLAMATION"
  473. end
  474. call LogLine Msg
  475. call DisplayPmMessage Icon,Msg||GetLastArchiveTime()
  476. end
  477. when Command="OFF" then
  478. do
  479. PatchRc=PatchFile(ArchiveFile,HexOffset,HexValueOff)
  480. TurnOnPeriod=Parameters
  481. if TurnOnPeriod='' then
  482. do
  483. if PatchRc=0 then
  484. do
  485. Msg="Archiving turned off."
  486. Icon="INFORMATION"
  487. end
  488. else
  489. do
  490. Msg="Archiving was already turned off!"
  491. Icon="EXCLAMATION"
  492. end
  493. call LogLine Msg
  494. call DisplayPmMessage Icon,Msg||GetLastArchiveTime()
  495. end
  496. else
  497. do
  498. BaseDateToday=BaseDate()
  499. if PatchRc=0 then
  500. do
  501. call LogLine 'Just completed archive - archiving turned off'
  502. call SysIniWrite "LastArchive", "BaseDate",BaseDateToday
  503. call SysIniWrite "LastArchive", "FormattedTime",GetPrettyTime()
  504. end
  505. if TurnOnPeriod<>0 then
  506. do
  507. LastArchiveBaseDate=SysIniRead("LastArchive", "BaseDate", '0')
  508. DaysDiff=BaseDateToday-LastArchiveBaseDate
  509. if DaysDiff>=TurnOnPeriod|DaysDiff<0 then
  510. do
  511. call CreateOs2KeyFile
  512. call PatchFile ArchiveFile,HexOffset,HexValueOn
  513. LastArchiveTime=GetLastArchiveTime()
  514. Line2Log='Archive automatically turned on as it is every ' || TurnOnPeriod || ' days'
  515. if LastArchiveTime<> '' then
  516. Line2Log=Line2Log|| ' (last archive completed ' || LastArchiveTime || ')'
  517. call LogLine Line2Log|| '.'
  518. if TurnOnPeriod=1 then
  519. PeriodText='day'
  520. else
  521. PeriodText=TurnOnPeriod|| ' days'
  522. TheMsg='Archiving will take place on following boot.' ||NlChar||NlChar
  523. TheMsg=TheMsg|| 'You have requested that archiving occur every ' || PeriodText || '.'
  524. TheMsg=TheMsg||LastArchiveTime
  525. call DisplayPmMessage "INFORMATION",TheMsg
  526. end
  527. end
  528. end
  529. end
  530. otherwise
  531. Error('Unknown command of "' || Command || '" specified!')
  532. end
  533. exit(ExitRc)
  534.  
  535. GetLastArchiveTime:
  536. FormattedTime=SysIniRead("LastArchive", "FormattedTime", '')
  537. if FormattedTime<> '' then
  538. FormattedTime=NlChar||NlChar|| 'The last archive occurred ' || FormattedTime || '.'
  539. return(FormattedTime)
  540.  
  541. GetPrettyTime:
  542. TheTime=time('C')
  543. TheDay=date('WeekDay')
  544. TheDate=date()
  545. if arg(1)='PAD' then
  546. do
  547. TheTime=right(TheTime,7)
  548. TheDay=left(TheDay,8)
  549. TheDate=left(TheDate,11)
  550. end
  551. return(TheTime|| ' ' || TheDay || ' ' ||TheDate)
  552.  
  553. LogLine:
  554. if arg(1)='' then
  555. call lineout LogFile, ''
  556. else
  557. call lineout LogFile,GetPrettyTime('PAD') || ' : ' ||arg(1)
  558. CloseRc=stream(LogFile, 'c', 'close')
  559. return
  560.  
  561. PatchFile:
  562. Os2ArchiveFileName=arg(1)
  563. PatchLocation=x2d(arg(2))+1
  564. PatchValue=x2c(arg(3))
  565. if stream(Os2ArchiveFileName, 'c', 'query exists') = '' then
  566. Error('The file "' || Os2ArchiveFileName || '" does not exist!')
  567. address cmd 'attrib.exe -r ' || Os2ArchiveFileName || ' >nul'
  568. OriginalByte=charin(Os2ArchiveFileName,PatchLocation,1)
  569. if OriginalByte=PatchValue then
  570. do
  571. PatchRc=1
  572. CloseRc=stream(Os2ArchiveFileName, 'c', 'close')
  573. end
  574. else
  575. do
  576. PatchRc=0
  577. WriteRc=charout(Os2ArchiveFileName,PatchValue,PatchLocation)
  578. CloseRc=stream(Os2ArchiveFileName, 'c', 'close')
  579. if WriteRc<>0 then
  580. Error('Patch of archive file failed.')
  581. end
  582. address cmd 'attrib.exe +r ' || Os2ArchiveFileName || ' >nul'
  583. say 'Patching successful.'
  584. return(PatchRc)
  585.  
  586. SysIniRead:
  587. IniApp=arg(1)
  588. IniKey=arg(2)
  589. IniDefault=arg(3)
  590. IniValue=SysIni(ArchiveIniFile,IniApp,IniKey)
  591. if IniValue='ERROR:' then
  592. IniValue=IniDefault
  593. return(IniValue)
  594.  
  595. SysIniWrite:
  596. IniApp=arg(1)
  597. IniKey=arg(2)
  598. IniValue=arg(3)
  599. WriteRc=SysIni(ArchiveIniFile,IniApp,IniKey,IniValue)
  600. if WriteRc='ERROR:' then
  601. do
  602. call Error "We couldn't update the configuration details stored in '" || ArchiveIniFile || "'."
  603. exit(GetLineNumber())
  604. end
  605. return
  606.  
  607. GetFileContents:
  608. Contents=charin(arg(1),1,9999)
  609. CloseRc=stream(arg(1), 'c', 'close')
  610. if length(Contents)<512 then
  611. Error("Only read " || length(Contents) " bytes from file")
  612. return(Contents)
  613.  
  614. OpenDesktopProperties:
  615. call Normal 'Opening Desktop Properties...'
  616. call SysSetObjectData "<WP_DESKTOP>", "OPEN=SETTINGS"
  617. return
  618.  
  619. Pause:
  620. address cmd '@pause'
  621. return
  622.  
  623. SayAndLogErrorLine:
  624. say ErrorColor||arg(1)||Reset|| ''
  625. call LogLine arg(1)
  626. return
  627.  
  628. Error:
  629. ErrorRc=SIGL
  630. call SayAndLogErrorLine arg(1)
  631. call DisplayPmMessage "ERROR", "An error occurred." ||NlChar||NlChar||arg(1)
  632. exit(ErrorRc)
  633.  
  634. Normal:
  635. call LogLine arg(1)
  636. say NormalColor||arg(1)||Reset
  637. return
  638.  
  639. HighLight:
  640. call LogLine arg(1)
  641. say HighlightColor||arg(1)||Reset
  642. return
  643.  
  644. GetLineNumber:
  645. return(SIGL)
  646.  
  647. DisplayCopyright:
  648. call charout,HighlightColor
  649. say '[]-------------------------------------------------------------[]'
  650. say '| ARCHIVE.CMD: Version ' || PgmVersion || ' (C)opyright Dennis Bareis 1997    |'
  651. say '| http://www.labyrinth.net.au/~dbareis/index.htm (db0@anz.com)  |'
  652. say '[]-------------------------------------------------------------[]'
  653. say Reset
  654. return
  655.  
  656. CommonTrapHandler:
  657. FailingLine=arg(1)
  658. TrapHeading='BUG: ' ||arg(2)
  659. TextDescription=arg(3)
  660. Text=arg(4)
  661. parse source . . RexxCmdName
  662. call SayAndLogErrorLine copies('=+',39)
  663. call SayAndLogErrorLine TrapHeading
  664. call SayAndLogErrorLine copies('~',length(TrapHeading))
  665. call SayAndLogErrorLine substr(TextDescription,1,16)|| ': ' ||Text
  666. call SayAndLogErrorLine 'Failing Module  : ' ||RexxCmdName
  667. call SayAndLogErrorLine 'Failing Line #  : ' ||FailingLine
  668. call SayAndLogErrorLine 'Failing Command : ' ||strip(SourceLine(FailingLine))
  669. call SayAndLogErrorLine copies('=+',39)
  670. call DisplayPmMessage "ERROR", "Line #" || FailingLine || " failed." || NlChar || NlChar || TextDescription || ' : ' ||Text
  671. exit(FailingLine)
  672.  
  673. RexxTrapUninitializedVariable:
  674. call CommonTrapHandler SIGL, 'NoValue Abort!', 'Unknown Variable', condition('D')
  675.  
  676. RexxTrapSyntaxError:
  677. call CommonTrapHandler SIGL, 'Syntax Error!', 'Reason',errortext(Rc)
  678.  
  679. RexxCtrlC:
  680. LineCtrlC=SIGL
  681. say ''
  682. say ErrorColor||copies('=+',39)
  683. say "Come on, you pressed Ctrl+C or Break didn't you!"
  684. say copies('=+', 39) || Reset || ''
  685. exit(LineCtrlC)
  686.  
  687. DisplayPmMessage:
  688. Icon=arg(1)
  689. Text=arg(2)
  690. Title="ARCHIVE.CMD v" || PgmVersion || " ╕ Dennis Bareis 1998"
  691. if Icon='ERROR' then
  692. Button="ENTER"
  693. else
  694. Button="OK"
  695. AddText=NlChar||NlChar|| 'Please report any suggestions or '
  696. AddText=AddText|| 'bugs to "db0@anz.com". The latest version '
  697. AddText=AddText|| 'of this program and many other FREE '
  698. AddText=AddText|| 'programs are available at "http://www.labyrinth.net.au/~dbareis/index.htm".'
  699. signal ON SYNTAX NAME RxBoxCantBeUsed
  700. call RxMessageBox NlChar||Text||AddText,Title,Button,Icon
  701.  
  702. RxBoxCantBeUsed:
  703. return
  704.