home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / arc99062.zip / ARCHIVE.CMD next >
OS/2 REXX Batch file  |  1999-03-03  |  22KB  |  662 lines

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