home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Corel / Ventura8 / Ventura / Scripts / LibraryList.csc < prev    next >
Encoding:
Text File  |  1998-07-08  |  14.2 KB  |  392 lines

  1. REM Lists all items in a VENTURA 8 library [CorelSCRIPT 8]
  2. REM LibraryList.csc  March, 1998
  3. REM ⌐ 1998 Corel Corporation. All rights reserved.
  4.  
  5. REM **************************************************************************************
  6. REM This script lists all the items in the specified Ventura Library
  7. REM The resulting list is displayed in a Ventura publication.
  8. REM **************************************************************************************
  9.  
  10. ' Create a temporary folder to provide a path for the include files
  11. '  -this enables the include files to be located 
  12. #addfol "..\..\Scripts"
  13. #include "ScpConst.csi"
  14. #include "VPConst.csi"
  15.  
  16. ' Embed bitmaps if script is to be compiled into exe or csb formats
  17. ' -this will eliminate the need to include these files
  18. #ADDRESBMP IntroBMP "Bitmaps\IntroBMP.bmp"
  19. #ADDRESBMP Step2BMP "Bitmaps\Step2BMP.bmp"
  20. #ADDRESBMP LastBMP "Bitmaps\LastBMP.bmp"
  21.  
  22. 'Constants for Dialog Return Values
  23. GLOBAL CONST DIALOG_RETURN_CANCEL% = 2
  24. GLOBAL CONST DIALOG_RETURN_NEXT% = 3
  25. GLOBAL CONST DIALOG_RETURN_BACK% = 4
  26. GLOBAL CONST DIALOG_RETURN_BROWSE% = 5
  27.  
  28. '/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////////////////
  29. DECLARE SUB RegQuery()
  30. DECLARE FUNCTION ShowIntro%()
  31. DECLARE FUNCTION GetLIBName%()
  32. DECLARE FUNCTION ShowFinish%()
  33. DECLARE SUB GetLibInfo() 
  34. DECLARE FUNCTION DoesFileExist(FileName$) AS BOOLEAN
  35.  
  36. '/////GLOBAL VARIABLES //////////////////////////////////////////////////////////
  37. GLOBAL VenturaRoot$        'root directory where Ventura is installed
  38. GLOBAL LibraryDir$        'directory where library files are located
  39. GLOBAL LIBName$         'name and path of library which items are to be listed
  40.  
  41. '////// LOCAL VARIABLES /////////////////////////////////////////////////////////
  42. CONST MAXSTEP% = 3        'maximum number of pages in the Wizard
  43. DIM DialogReturn%        'identifies user's selection for next step in Wizard                                        
  44. DIM NextStep%            'specifies which page appears next in the Wizard
  45.  
  46.  
  47. ' **************************************************************************************
  48. ' MAIN
  49. ' **************************************************************************************
  50. ON ERROR GOTO ErrorHandler
  51.  
  52. RegQuery                                        'get root directory where Ventura is installed
  53. LibraryDir$ = VenturaRoot$ & "\Ventura\Library"        'initialize default library directory
  54. LIBName$= VenturaRoot$ & "\Ventura\Library"            'initialize default library name
  55.  
  56. 'this section controls traversal through the dialog pages
  57. NextStep% = 1
  58. DO
  59.     SELECT CASE NextStep%
  60.         CASE 1: DialogReturn%  = ShowIntro()        'show Intro dialog
  61.         CASE 2: DialogReturn%  = GetLIBName()        'get name of library to be listed
  62.         CASE 3: DialogReturn%  = ShowFinish()        'show finish dialog
  63.     END SELECT
  64.     NextStep% = NextStep% + DialogReturn% 
  65. LOOP UNTIL NextStep% = MAXSTEP + 1
  66.  
  67. ExitScript:
  68. STOP
  69.  
  70. ErrorHandler:
  71. SELECT CASE ErrNum
  72.     CASE 800
  73.         MESSAGE "FATAL ERROR" & CHR(13) & "Script will now exit."
  74.         RESUME AT ExitScript
  75.     CASE ELSE
  76.         MESSAGE "ERROR: " & STR(ErrNum) & CHR(13) & "Script will now exit."
  77.         RESUME AT ExitScript
  78.     END SELECT
  79.  
  80.  
  81. ' *******************************************************************************
  82. ' RegQuery
  83. ' This subroutine queries the Registry to determine the root directory where 
  84. ' Ventura is installed.
  85. ' *******************************************************************************
  86. SUB RegQuery
  87. ON ERROR GOTO ErrorHandler
  88.  
  89.     'get Ventura config directory
  90.     VentDir$ = REGISTRYQUERY(HKEY_LOCAL_MACHINE,VENTURA_REGQUERY_CONST,"ConfigDir")     
  91.     
  92.     'isolate Ventura root directory from Ventura config directory
  93.     first% = 1
  94.     pos% = 1
  95.     DO WHILE first <> 0
  96.         first = INSTR(VentDir$, "\", first )
  97.         IF first <> 0 THEN
  98.             pos = first
  99.             first = first + 1
  100.         END IF
  101.     LOOP
  102.     VenturaRoot$ = LEFT(VentDir$, pos - 1)     'root directory where Ventura is installed
  103.  
  104. EXIT SUB
  105. ErrorHandler:
  106.     MESSAGE "Error reading registry:" & CHR(13) & RegString$
  107.     ErrNum = 800
  108. END SUB
  109.  
  110.  
  111. ' **************************************************************************************
  112. ' DoesFileExist
  113. ' This function determines whether the specified file exists.
  114. '
  115. ' PARAMS:FileName AS STRING - The name and path of the file in question.
  116. ' RETURNS: DoesFileExist AS BOOLEAN - TRUE if the file exists.
  117. '                                   - FALSE if the file does not exist.
  118. ' **************************************************************************************
  119. FUNCTION DoesFileExist(FileName$) AS BOOLEAN
  120. ON ERROR GOTO ErrorHandler
  121.     FileStatus$ = FINDFIRSTFOLDER(FileName$, FILEATTR_READ_ONLY OR FILEATTR_HIDDEN OR FILEATTR_SYSTEM OR FILEATTR_ARCHIVE OR FILEATTR_NORMAL_FILE OR FILEATTR_TEMPORARY)
  122.     IF FileStatus$ = "" THEN
  123.         DoesFileExist = FALSE
  124.     ELSE
  125.         DoesFileExist = TRUE
  126.     ENDIF
  127.  
  128. FunctionEnd:
  129. EXIT FUNCTION
  130.  
  131. ErrorHandler:
  132.     SELECT CASE ErrNum
  133.         CASE ELSE
  134.             DoesFileExist = FALSE
  135.     END SELECT
  136.     RESUME AT FunctionEnd
  137. END FUNCTION
  138.  
  139.  
  140. ' *******************************************************************************
  141. ' ShowIntro
  142. ' This function displays the introduction dialog.
  143. ' PARAMS: None
  144. '
  145. ' RETURNS: ShowIntro AS INTEGER - Integer indicating dialog return value.
  146. ' *******************************************************************************
  147. FUNCTION ShowIntro%
  148. BEGIN DIALOG OBJECT IntroDialog 290, 180, "Corel VENTURA Library Wizard", SUB IntroDialogEventHandler
  149.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  150.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  151.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  152.     TEXT  95, 10, 185, 20, .Text2, "This wizard lists all items in the specified Corel VENTURA library."
  153.     IMAGE  10, 10, 75, 130, .IntroImage
  154.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  155.     TEXT  95, 40, 185, 20, .Text5, "To begin listing the library items, click Next."
  156. END DIALOG
  157.  
  158.     IntroDialog.IntroImage.SetImage "#IntroBMP"
  159.     IntroDialog.IntroImage.SetStyle STYLE_IMAGE_CENTERED
  160.     IntroRet%=DIALOG(IntroDialog)
  161.     IF IntroRet% = DIALOG_RETURN_CANCEL THEN STOP            
  162.     IF IntroRet% = 3 THEN ShowIntro = 1        
  163. END FUNCTION
  164.  
  165.  
  166. ' *******************************************************************************
  167. ' IntroDialogEventHandler
  168. ' This subroutine responds to user interface with the introduction dialog.
  169. ' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is 
  170. '                            generating a dialog event.
  171. '        BYVAL Event% - Integer indicating the dialog event that has occurred.
  172. ' *******************************************************************************
  173. SUB IntroDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  174.     IF Event% = EVENT_INITIALIZATION THEN         
  175.         IntroDialog.BackButton.Enable FALSE 
  176.     ENDIF
  177.     IF Event% = EVENT_MOUSE_CLICK THEN     
  178.         SELECT CASE ControlID%
  179.             CASE IntroDialog.NextButton.GetID()
  180.                 IntroDialog.CloseDialog DIALOG_RETURN_NEXT
  181.             CASE IntroDialog.CancelButton.GetID()
  182.                 IntroDialog.CloseDialog DIALOG_RETURN_CANCEL
  183.         END SELECT
  184.     ENDIF
  185. END FUNCTION
  186.  
  187.  
  188. ' *******************************************************************************
  189. ' GetLIBName
  190. ' This function prompts the user for the name of the library.
  191. '
  192. ' RETURNS: GetLIBName AS INTEGER - Integer indicating dialog return value.
  193. ' *******************************************************************************
  194. FUNCTION GetLIBName%
  195. BEGIN DIALOG OBJECT GetLIBNameDialog 290, 180, "Corel VENTURA Library Wizard", SUB GetLIBNameDialogEventHandler
  196.     TEXTBOX  95, 29, 185, 13, .LibNameTextBox
  197.     PUSHBUTTON  234, 49, 46, 14, .BrowseButton, "&Browse..."
  198.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  199.     PUSHBUTTON  181, 160, 46, 14, .NextButton, "&Next >"
  200.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  201.     TEXT  95, 15, 175, 12, .Text2, "Which library would you like to use?"
  202.     IMAGE  10, 10, 75, 130, .GetLIBNameImage
  203.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  204. END DIALOG
  205.  
  206.     GetLIBNameDialog.SetStyle STYLE_INVISIBLE
  207.     GetLIBNameDialog.GetLIBNameImage.SetImage "#Step2BMP"
  208.     GetLIBNameDialog.GetLIBNameImage.SetStyle STYLE_IMAGE_CENTERED
  209.  
  210.     GetLIBNameRet% = Dialog(GetLIBNameDialog)
  211.     SELECT CASE GetLIBNameRet%
  212.         CASE DIALOG_RETURN_CANCEL    
  213.             STOP
  214.         CASE DIALOG_RETURN_NEXT    
  215.             GetLIBName = 1
  216.         CASE DIALOG_RETURN_BACK         
  217.             GetLIBName = -1
  218.     END SELECT
  219. END FUNCTION
  220.  
  221. ' *******************************************************************************
  222. ' GetLIBNameDialogEventHandler
  223. ' This subroutine responds to user interface with the library name dialog.
  224. ' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is 
  225. '                            generating a dialog event.
  226. '        BYVAL Event% - Integer indicating the dialog event that has occurred.
  227. ' *******************************************************************************
  228. SUB GetLIBNameDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  229. ON ERROR RESUME NEXT
  230.     IF Event% = EVENT_INITIALIZATION THEN         
  231.         GetLIBNameDialog.LibNameTextBox.SetText LIBName$
  232.         pos% = INSTR(LIBName$, ".")
  233.         IF pos% = 0 THEN 
  234.             GetLIBNameDialog.NextButton.Enable FALSE
  235.         ELSE
  236.             GetLIBNameDialog.NextButton.Enable TRUE
  237.         ENDIF    
  238.         GetLIBNameDialog.SetStyle STYLE_VISIBLE
  239.     ENDIF
  240.  
  241.     IF Event% = EVENT_CHANGE_IN_CONTENT THEN         
  242.         SELECT CASE ControlID%
  243.             CASE GetLIBNameDialog.LibNameTextBox.GetID()        
  244.                 LIBName$ = GetLIBNameDialog.LibNameTextBox.gettext()        
  245.                 pos% = INSTR(LIBName$, ".")
  246.                 IF pos% = 0 THEN 
  247.                     GetLIBNameDialog.NextButton.Enable FALSE
  248.                 ELSE
  249.                     GetLIBNameDialog.NextButton.Enable TRUE
  250.                 ENDIF    
  251.         END SELECT
  252.     ENDIF
  253.  
  254.     IF Event% = EVENT_MOUSE_CLICK THEN         
  255.         SELECT CASE ControlID%
  256.             CASE GetLIBNameDialog.NextButton.GetID()        
  257.                 IF DoesFileExist(LIBName$) = TRUE THEN     'library exists, continue
  258.                     GetLIBNameDialog.closedialog DIALOG_RETURN_NEXT
  259.                 ELSE
  260.                     MESSAGE "Cannot locate library:" & CHR(13) & LIBName$ 
  261.                 ENDIF        
  262.             CASE GetLIBNameDialog.BackButton.GetID()        
  263.                 GetLIBNameDialog.closedialog DIALOG_RETURN_BACK
  264.             CASE GetLIBNameDialog.CancelButton.GetID()        
  265.                 GetLIBNameDialog.closedialog DIALOG_RETURN_CANCEL    
  266.             CASE GetLIBNameDialog.BrowseButton.GetID()        
  267.                 SETCURRFOLDER LibraryDir$
  268.                 LIBName$ = GETFILEBOX("Ventura Library (*.vlb)|*.vlb", "Open Library")
  269.                 IF LIBName$ <> "" THEN
  270.                     GetLIBNameDialog.LibNameTextBox.SetText LIBName$
  271.                     GetLIBNameDialog.NextButton.Enable TRUE
  272.                 ELSE
  273.                     GetLIBNameDialog.LibNameTextBox.SetText LibraryDir$
  274.                     GetLIBNameDialog.NextButton.Enable FALSE
  275.                 ENDIF
  276.         END SELECT
  277.     ENDIF
  278. END SUB
  279.  
  280. ' *******************************************************************************
  281. ' ShowFinish
  282. ' This function displays the finish dialog, showing the name of the library to be
  283. ' used.
  284. ' PARAMS: None
  285. '
  286. ' RETURNS: ShowIntro AS INTEGER - Integer indicating dialog return value.
  287. ' *******************************************************************************
  288. FUNCTION ShowFinish%
  289. BEGIN DIALOG OBJECT ShowFinishDialog 290, 180, "Corel VENTURA Library Wizard", SUB ShowFinishDialogEventHandler
  290.     PUSHBUTTON  181, 160, 46, 14, .FinishButton, "&Finish"
  291.     CANCELBUTTON  234, 160, 46, 14, .CancelButton
  292.     PUSHBUTTON  135, 160, 46, 14, .BackButton, "< &Back"
  293.     IMAGE  10, 10, 75, 130, .ShowFinishImage
  294.     TEXT  95, 10, 185, 12, .Text1, "The Wizard is now ready to list the items in library:"
  295.     TEXT  95, 23, 185, 12, .Text2, LIBName$
  296.     TEXT  95, 45, 185, 20, .Text3, "Select Finish, then sit back and watch Ventura do your work for you."
  297.     GROUPBOX  10, 150, 270, 5, .LineGroupBox
  298. END DIALOG
  299.  
  300.     ShowFinishDialog.SetStyle STYLE_INVISIBLE
  301.     ShowFinishDialog.ShowFinishImage.SetImage "#LastBMP"
  302.     ShowFinishDialog.ShowFinishImage.SetStyle STYLE_IMAGE_CENTERED
  303.  
  304.     ShowFinishRet% = Dialog(ShowFinishDialog)
  305.     SELECT CASE ShowFinishRet%
  306.         CASE DIALOG_RETURN_CANCEL     
  307.             STOP
  308.         CASE DIALOG_RETURN_NEXT      
  309.             ShowFinishDialog.SetVisible FALSE
  310.             GetLibInfo
  311.             ShowFinish = 1
  312.         CASE DIALOG_RETURN_BACK 
  313.             ShowFinish = -1
  314.     END SELECT
  315. END FUNCTION
  316.  
  317.  
  318. ' *******************************************************************************
  319. ' ShowFinishDialogEventHandler
  320. ' This subroutine responds to user interface with the finish dialog.
  321. ' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is 
  322. '                            generating a dialog event.
  323. '        BYVAL Event% - Integer indicating the dialog event that has occurred.
  324. ' *******************************************************************************
  325. SUB ShowFinishDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
  326.     IF Event% = EVENT_INITIALIZATION THEN         
  327.         ShowFinishDialog.SetStyle STYLE_VISIBLE
  328.     ENDIF
  329.  
  330.     IF Event% = EVENT_MOUSE_CLICK THEN     
  331.         SELECT CASE ControlID%
  332.             CASE ShowFinishDialog.FinishButton.GetID()
  333.                 ShowFinishDialog.CloseDialog DIALOG_RETURN_NEXT
  334.             CASE ShowFinishDialog.BackButton.GetID()
  335.                 ShowFinishDialog.CloseDialog DIALOG_RETURN_BACK
  336.             CASE ShowFinishDialog.CancelButton.GetID()
  337.                 ShowFinishDialog.CloseDialog DIALOG_RETURN_CANCEL
  338.         END SELECT
  339.     ENDIF
  340. END SUB
  341.  
  342.  
  343. ' *******************************************************************************
  344. ' GetLibInfo
  345. ' This subroutine opens the specified VENTURA library, obtains a list of all 
  346. ' items contained within the library, and outputs this information to a temporary
  347. ' text file. The text file is then imported in to VENTURA, and subsequently
  348. ' removed from the Windows temp folder. The library name and total number of 
  349. ' items are displayed at the start of the pub.
  350. '
  351. ' PARAMS: None
  352. ' *******************************************************************************
  353. SUB GetLibInfo
  354.     TempLibFile$ = GETTEMPFOLDER() & "TempLib.txt"
  355.     OPEN TempLibFile$ FOR APPEND AS 1
  356.  
  357.     BEGINWAITCURSOR
  358.     WITHOBJECT OBJECT_VENTURA8
  359.         .FileLibraryOpen LIBName$ 
  360.         .FileLibraryView FALSE, TRUE        'small icons, show details
  361.         ItemsInLIB& = .FileLibraryItemCount()
  362.         
  363.         PRINT #1, "@Minor Heading = " & LibName$ & CHR(13) & CHR(10)
  364.         PRINT #1, "@Subheading = " & "Number of items: " & STR(ItemsInLIB&) & CHR(13) & CHR(10) 
  365.         
  366.         FOR i% = 1 TO ItemsInLIB&
  367.             .FileLibrarySelectItem i%
  368.             .FileLibraryItemPropertiesGet ItemName$
  369.             PRINT #1, "@Bullet = " &  STR(i%) & SPACE(2) & ItemName$ & CHR(13) & CHR(10)
  370.         NEXT i%
  371.         .FileLibraryClose TRUE        'close ALL open libs
  372.         CLOSE                    'close temporary text file
  373.  
  374.         'import temporary text file containing library information
  375.         .SetVisible TRUE
  376.         .FileNew 
  377.         .FrameFirst TRUE
  378.         .FileImportText TempLibFile$
  379.     END WITHOBJECT
  380.     KILL TempLibFile$
  381.     ENDWAITCURSOR
  382. END SUB
  383.  
  384.  
  385.  
  386.  
  387.