home *** CD-ROM | disk | FTP | other *** search
/ Computer Buyer 1998 May / dpcb0598.iso / Business / Draw8 / Scripts / appled.csc < prev    next >
Text File  |  1997-05-23  |  7KB  |  232 lines

  1. REM  This script will edit the applications available from the application launcher
  2. REM  "AppLEd.csc"  for Version 7.0 made June 20, 1996
  3. REM  A copy of Corelapp.ini named Corelapp.bak is created automatically
  4. REM  Copyright 1996 Corel Corporation. All rights reserved.
  5.  
  6. #INCLUDE "ScpConst.csi"
  7. #define AppReg "SOFTWARE\corel\CORELDRAW\7.0"
  8.  
  9. ' Constants
  10. GLOBAL CONST APPS_CATEGORY$ = "[Applications]"
  11. GLOBAL CONST APPINCR%=25
  12.  
  13. ' Globals
  14. GLOBAL MaxNApp%
  15. MaxNApp%=APPINCR%
  16. GLOBAL AppName$(MaxNApp%), AppPath$(MaxNApp%), NumberOfApps%
  17.  
  18. ' Main Dialog
  19. BEGIN DIALOG OBJECT Dialog1 308, 165, "Application Launcher Editor", SUB Dialog1Sub
  20.     LISTBOX  6, 8, 143, 148, .AppList
  21.     OKBUTTON  216, 143, 40, 14, .OK1
  22.     CANCELBUTTON  260, 143, 40, 14, .Cancel1
  23.     TEXT  162, 8, 118, 8, .AppNameText, "Application Name:"
  24.     TEXTBOX  160, 17, 140, 13, .AppName
  25.     TEXT  162, 43, 127, 8, .PathText, "Application Path:"
  26.     TEXTBOX  160, 52, 140, 13, .AppPath
  27.     PUSHBUTTON  160, 96, 140, 14, .AddApp, "Add New Application"
  28.     PUSHBUTTON  160, 116, 140, 14, .RemoveApp, "Remove Application"
  29.     PUSHBUTTON  253, 69, 46, 14, .Browse, "Browse"
  30. END DIALOG
  31.  
  32. 'First, find the INI file
  33. GLOBAL ConfigDir AS STRING
  34. ConfigDir$ = REGISTRYQUERY(HKEY_LOCAL_MACHINE%,AppReg,"ConfigDir")
  35.  
  36. 'Add trailing '\' if absent
  37. IF LEFT$(ConfigDir$,1) <> "\" THEN ConfigDir$ = ConfigDir$ + "\"
  38.  
  39. 'Open the file
  40. OPEN ConfigDir$ + "Corelapp.ini" FOR INPUT AS 1
  41.  
  42. 'Read data until category header is found
  43. DIM ReadData AS STRING
  44. DO 
  45.     INPUT #1, ReadData$
  46. LOOP UNTIL EOF(1) OR ReadData$ = APPS_CATEGORY$
  47.  
  48. ' If we're not at the end, then read applications until another category is found.
  49. DIM EqualPos AS LONG
  50. IF NOT EOF(1) THEN
  51.     DO
  52.         INPUT #1, ReadData$
  53.         EqualPos = INSTR(ReadData$,"=")
  54.         IF EqualPos <> 0 THEN
  55.             NumberOfApps% = NumberOfApps% + 1
  56.             IF(NumberOfApps%>MaxNApp%) THEN
  57.               ' Increase size of App array
  58.                 MaxNApp%=MaxNApp%+APPINCR%
  59.               REDIM PRESERVE AppName$(MaxNApp%)
  60.               REDIM PRESERVE AppPath$(MaxNApp%)
  61.           ENDIF
  62.             AppName$(NumberOfApps%) = LEFT$(ReadData$,EqualPos - 1)
  63.             AppPath$(NumberOfApps%) = MID$(ReadData$,EqualPos+1) ' Skip the =
  64.         ENDIF
  65.     LOOP UNTIL EOF(1) OR LEFT(ReadData$, 1) = "["
  66. ENDIF
  67.  
  68. CLOSE
  69.  
  70. ' Edit the applications list
  71. DIM DialogReturnVal AS INTEGER
  72. DialogReturnVal% = DIALOG(Dialog1)
  73.  
  74. ' End program on cancel
  75. IF DialogReturnVal% = MSG_CANCEL% THEN END
  76.  
  77. ' Keep a backup file
  78. RENAME ConfigDir$ + "Corelapp.ini", ConfigDir$ + "Corelapp.bak"
  79.  
  80. ' Open input and output files
  81. OPEN ConfigDir$ + "Corelapp.bak" FOR INPUT AS 1
  82. OPEN ConfigDir$ + "Corelapp.ini" FOR OUTPUT AS 2
  83.  
  84. 'Read data until category header is found, copying it to the output file
  85. DO 
  86.     INPUT #1, ReadData$
  87.     PRINT #2, ReadData$
  88. LOOP UNTIL EOF(1) OR ReadData$ = APPS_CATEGORY$
  89.  
  90. ' If there was no Applications category, we must create one.
  91. IF ReadData$ <> APPS_CATEGORY$ THEN
  92.     'Skip a line
  93.     PRINT #2, ""
  94.     PRINT #2, APPS_CATEGORY$
  95. ENDIF
  96.  
  97. ' If we're not at the end, then read applications until another category is found.
  98. IF NOT EOF(1) THEN
  99.     DO
  100.         INPUT #1, ReadData$
  101.     LOOP UNTIL EOF(1) OR LEFT(ReadData$, 1) = "["
  102. ELSE
  103.     ' So as to not duplicate anything
  104.     ReadData$ = ""
  105. ENDIF
  106.  
  107. 'Now, write the new applications to the file
  108. DIM X AS INTEGER
  109. FOR X% = 1 TO NumberOfApps%
  110.     PRINT #2, AppName$(X%) + "=" + AppPath$(X%)
  111. NEXT X%
  112.  
  113. 'Finally, write the rest of the data
  114.  
  115. 'Skip a line
  116. PRINT #2, ""
  117.  
  118. 'Write the category
  119. PRINT #2, ReadData$
  120.  
  121. ' Write left over
  122. DO UNTIL EOF(1)
  123.     INPUT #1, ReadData$
  124.     PRINT #2, ReadData$
  125. LOOP
  126.  
  127. 'Close files
  128. CLOSE
  129.  
  130. 'End the program
  131. END
  132.  
  133. 'Event handler for main dialog.
  134. SUB Dialog1Sub(BYVAL ControlID%, BYVAL Event%)
  135.     DIM Selection AS INTEGER
  136.     DIM X AS INTEGER
  137.     DIM Filename AS STRING
  138.  
  139.     Selection% = Dialog1.AppList.GetSelect()
  140.     SELECT CASE Event%
  141.         CASE EVENT_INITIALIZATION
  142.             Dialog1.AppList.SetArray AppName$
  143.  
  144.         CASE EVENT_MOUSE_CLICK
  145.             SELECT CASE ControlID%
  146.                 CASE Dialog1.AppList.GetID()
  147.                     IF Selection% <> 0 THEN
  148.                         'Change the text boxes according to the selection
  149.                         Dialog1.AppName.SetText(AppName$(Selection%))
  150.                         Dialog1.AppPath.SetText(AppPath$(Selection%))
  151.                     ENDIF
  152.                 CASE Dialog1.AddApp.GetID()
  153.                     'Add a new application
  154.                     NumberOfApps% = NumberOfApps% + 1
  155.                     AppName$(NumberOfApps%) = "<New App>"
  156.                     AppPath$(NumberOfApps%) = "<New App>"
  157.                     Dialog1.AppList.AddItem AppName$(NumberOfApps%), NumberOfApps%
  158.                     Dialog1.AppList.SetSelect(NumberOfApps%)
  159.                     Dialog1.AppName.SetText(AppName$(NumberOfApps%))
  160.                     Dialog1.AppPath.SetText(AppPath$(NumberOfApps%))
  161.                     ' Necessary for control enabling
  162.                     Selection% = NumberOfApps%
  163.                 CASE Dialog1.RemoveApp.GetID()
  164.                     IF Selection% <> 0 THEN
  165.                         Selection% = Dialog1.AppList.GetSelect()
  166.                         'Cycle through the array, replacing each element with the next,
  167.                         'starting with the deleted one
  168.                         FOR X% = Selection% TO NumberOfApps% - 1                
  169.                             AppName$(X) = AppName$(X + 1)
  170.                             AppPath$(X) = AppPath$(X + 1)
  171.                         NEXT X%
  172.                         'Delete the last element
  173.                         AppName$(NumberOfApps%) = ""
  174.                         AppPath$(NumberOfApps%) = ""
  175.                         'Remove the item from the list
  176.                         Dialog1.AppList.RemoveItem(Selection%)
  177.                         'Decrement the Applications count
  178.                         NumberOfApps% = NumberOfApps% - 1
  179.                         'Reset the selection
  180.                         IF Selection% > NumberOfApps% THEN
  181.                             Selection% = NumberOfApps%
  182.                         ENDIF
  183.                         Dialog1.AppList.SetSelect(Selection%)
  184.                         Dialog1.AppName.SetText(AppName$(Selection%))
  185.                         Dialog1.AppPath.SetText(AppPath$(Selection%))
  186.                     ENDIF
  187.                 CASE Dialog1.Browse.GetID()
  188.                     IF Selection% <> 0 THEN
  189.                         Filename$ = GETFILEBOX("Program Files (*.exe)|*.exe", "Choose an application for " + AppName$(Selection%))
  190.                         IF Filename$ <> "" THEN
  191.                             AppPath$(Selection%) = FileName$
  192.                             Dialog1.AppPath.SetText(FileName$)
  193.                         ENDIF
  194.                     ENDIF
  195.             END SELECT
  196.  
  197.         CASE EVENT_CHANGE_IN_CONTENT
  198.             SELECT CASE ControlID%
  199.                 CASE Dialog1.AppName.GetID()
  200.                     IF Selection% <> 0 THEN
  201.                         ' Change the name both in the array and in the list box
  202.                         AppName$(Selection%) = Dialog1.AppName.GetText()
  203.                         Dialog1.AppList.RemoveItem(Selection%)
  204.                         Dialog1.AppList.AddItem AppName$(Selection%),Selection%
  205.                         Dialog1.AppList.SetSelect(Selection%)
  206.                     ENDIF
  207.                 CASE Dialog1.AppPath.GetID()
  208.                     IF Selection% <> 0 THEN
  209.                         'Change the name in the array.
  210.                         AppPath$(Selection%) = Dialog1.AppPath.GetText()
  211.                     ENDIF
  212.             END SELECT
  213.     END SELECT
  214.  
  215.     'Enable/disable controls
  216.     IF Selection% = 0 THEN
  217.         Dialog1.AppName.SetText("")
  218.         Dialog1.AppPath.SetText("")
  219.         Dialog1.AppName.Enable FALSE
  220.         Dialog1.AppPath.Enable FALSE
  221.         Dialog1.RemoveApp.Enable FALSE
  222.         Dialog1.Browse.Enable FALSE
  223.     ELSE
  224.         Dialog1.AppName.Enable TRUE
  225.         Dialog1.AppPath.Enable TRUE
  226.         Dialog1.RemoveApp.Enable TRUE
  227.         Dialog1.Browse.Enable TRUE
  228.     ENDIF
  229.  
  230. END SUB
  231.         
  232.