home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 October A
/
Pcwk10a98.iso
/
Corel
/
Ventura8
/
Ventura
/
Scripts
/
FindUnusedFiles.csc
< prev
next >
Wrap
Text File
|
1998-07-08
|
43KB
|
934 lines
REM Finds unused files in VENTURA 8 publications [CorelSCRIPT 8]
REM FindUnusedFiles.csc March, 1998
REM ⌐ 1998 Corel Corporation. All rights reserved.
REM **************************************************************************************
REM This script searches the open Ventura publication for unused picture and text files.
REM The user is prompted for the type of files to search for (picture, text, or both).
REM The user is then promted for the scope of the search (entire pub or current chapter).
REM If a publication is not open, the user is prompted to open one or exit the wizard.
REM A list of unused files is displayed (picture and text files are displayed separately).
REM The user has the option of saving this list to a file, or deleting all unused files,
REM or just leaving them alone.
REM **************************************************************************************
' Create a temporary folder to provide a path for the include files
' -this enables the include files to be located
#addfol "..\..\Scripts"
#include "ScpConst.csi"
#include "VPConst.csi"
' Embed bitmaps if script is to be compiled into exe or csb formats
' -this will eliminate the need to include these files
#ADDRESBMP IntroBMP "Bitmaps\IntroBMP.bmp"
#ADDRESBMP Step2BMP "Bitmaps\Step2BMP.bmp"
#ADDRESBMP LastBMP "Bitmaps\LastBMP.bmp"
'Constants for Dialog Return Values
GLOBAL CONST DIALOG_RETURN_CANCEL% = 2
GLOBAL CONST DIALOG_RETURN_NEXT% = 3
GLOBAL CONST DIALOG_RETURN_BACK% = 4
GLOBAL CONST DIALOG_RETURN_BROWSE% = 5
'Constants for type of files to look for
GLOBAL CONST BOTH_FILES% = 0
GLOBAL CONST PICTURE_FILES% = 1
GLOBAL CONST TEXT_FILES% = 2
'Constants for scope of the search
GLOBAL CONST SEARCH_ENTIRE_PUB% = 0
GLOBAL CONST SEARCH_CHAPTER% = 1
'/////FUNCTION & SUBROUTINE DECLARATIONS/////////////////////////////////////////////////
DECLARE SUB RegQuery()
DECLARE FUNCTION ShowIntro() AS INTEGER
DECLARE FUNCTION GetFileType() AS INTEGER
DECLARE SUB FindFiles(TypeOfFile%)
DECLARE SUB CreateListOfFiles(TypeOfFile AS BOOLEAN, NameOfFile AS STRING, CurrentChapter$)
DECLARE FUNCTION ShowUnusedFiles() AS INTEGER
DECLARE FUNCTION ShowFinish() AS INTEGER
DECLARE FUNCTION RemoveUnusedFiles() AS INTEGER
DECLARE FUNCTION SaveToFile(FileListFile$) AS BOOLEAN
'/////GLOBAL VARIABLES & CONSTANTS////////////////////////////////////////////////////////
GLOBAL CONST MAXFILES% = 100 'Maximum number of files
GLOBAL UnusedPictureFiles$(MAXFILES%, 2) 'List of unused picture files, and the chapter in which they belong
GLOBAL UnusedPictureFilesCount% 'Total number of unused picture files
GLOBAL SelectedUnusedPictureFiles$(MAXFILES%, 2) 'List of unused picture files selected for deletion, and the chapter in which they belong
GLOBAL SelectedUnusedPictureFilesCount% 'Total number of picture files selected for deletion
GLOBAL UnusedTextFiles$(MAXFILES%, 2) 'List of unused text files, and the chapter in which they belong
GLOBAL UnusedTextFilesCount% 'Total number of unused text files
GLOBAL SelectedUnusedTextFiles$(MAXFILES%, 2) 'List of unused text files selected for deletion, and the chapter in which they belong
GLOBAL SelectedUnusedTextFilesCount% 'Total number of text files selected for deletion
GLOBAL VenturaRoot$ 'Root directory of Ventura from registry
GLOBAL FileType% 'Type of tag to search for (0-BOTH; 1-Picture; 2-Text)
GLOBAL SearchType% 'Scope of the search (0-publication; 1-current chapter only)
'/////LOCAL DECLARATIONS//////////////////////////////////////////////////////////////////
CONST MAXSTEP% = 7 'maximum number of pages in the Wizard
DIM DialogReturn% 'identifies user's selection for next step in Wizard
DIM NextStep% 'specifies which page appears next in the Wizard
' **************************************************************************************
' MAIN
' **************************************************************************************
ON ERROR GOTO ErrorHandler
RegQuery 'get root directory where Ventura is installed
'this section controls traversal through the dialog pages
NextStep% = 1
DO
SELECT CASE NextStep%
CASE 1: DialogReturn% = ShowIntro() 'Show Intro dialog
CASE 2: DialogReturn% = GetFileType() 'Get type of file to look for (0-BOTH; 1-Picture; 2-Text)
IF FileType%=BOTH_FILES AND UnusedPictureFilesCount% < 1 AND UnusedTextFilesCount% < 1 THEN
FindFiles(PICTURE_FILES) 'Get list of unused picture files
FindFiles(TEXT_FILES) 'Get list of unused text files
ENDIF
IF FileType%=PICTURE_FILES AND UnusedPictureFilesCount% < 1 THEN FindFiles(PICTURE_FILES) 'Get list of unused picture files
IF FileType%=TEXT_FILES AND UnusedTextFilesCount% < 1 THEN FindFiles(TEXT_FILES) 'Get list of unused text files
CASE 3 'Display list of unused picture files
IF FileType%=PICTURE_FILES AND UnusedPictureFilesCount% > 0 THEN
DialogReturn% = ShowUnusedFiles()
ENDIF
CASE 4 'Display list of unused text files
IF FileType%=TEXT_FILES AND UnusedTextFilesCount% > 0 THEN
DialogReturn% = ShowUnusedFiles()
ENDIF
CASE 5 'Display list of unused picture and text files
IF FileType%=BOTH_FILES THEN 'Display list of unused files
IF UnusedPictureFilesCount% > 0 THEN
FileType%=PICTURE_FILES : DialogReturn% = ShowUnusedFiles()
ENDIF
IF UnusedTextFilesCount% > 0 THEN
FileType%=TEXT_FILES : DialogReturn% = ShowUnusedFiles()
ENDIF
FileType% = BOTH_FILES 'Need to reset FileType to it's correct state for next function to use
ENDIF
CASE 6: DialogReturn% = ShowFinish()
CASE 7: DialogReturn% = RemoveUnusedFiles() 'Remove unused picture files from pub
END SELECT
NextStep% = NextStep% + DialogReturn%
LOOP UNTIL NextStep% = MAXSTEP + 1
ExitScript:
STOP
ErrorHandler:
SELECT CASE ErrNum
CASE 800
MESSAGE "FATAL ERROR" & CHR(13) & "Script will now exit."
RESUME AT ExitScript
CASE ELSE
MESSAGE "ERROR: " & STR(ErrNum) & CHR(13) & "Script will now exit."
RESUME AT ExitScript
END SELECT
' *******************************************************************************
' RegQuery
' This subroutine queries the Registry to determine the root directory where
' Ventura is installed.
' *******************************************************************************
SUB RegQuery
ON ERROR GOTO ErrorHandler
'get Ventura config directory
VentDir$ = REGISTRYQUERY(HKEY_LOCAL_MACHINE,VENTURA_REGQUERY_CONST,"ConfigDir")
'isolate Ventura root directory from Ventura config directory
first% = 1
pos% = 1
DO WHILE first <> 0
first = INSTR(VentDir$, "\", first )
IF first <> 0 THEN
pos = first
first = first + 1
END IF
LOOP
VenturaRoot$ = LEFT(VentDir$, pos - 1) 'root directory where Ventura is installed
EXIT SUB
ErrorHandler:
MESSAGE "Error reading registry:" & CHR(13) & RegString$
ErrNum = 800
END SUB
' *******************************************************************************
' ShowIntro
' This function displays the introduction dialog.
'
' PARAMS: None
'
' RETURNS: ShowIntro AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION ShowIntro%
BEGIN DIALOG OBJECT IntroDialog 290, 180, "Find Unused Files Wizard", SUB IntroDialogEventHandler
PUSHBUTTON 181, 160, 46, 14, .NextButton, "&Next >"
CANCELBUTTON 234, 160, 46, 14, .CancelButton
PUSHBUTTON 135, 160, 46, 14, .BackButton, "< &Back"
TEXT 95, 10, 185, 20, .Text2, "This wizard will find all the unused picture or text files in the current publication."
TEXT 95, 40, 185, 12, .Text3, "To begin finding unused files, click Next."
IMAGE 10, 10, 75, 130, .IntroImage
GROUPBOX 10, 150, 270, 5, .LineGroupBox
END DIALOG
IntroDialog.SetStyle STYLE_INVISIBLE
IntroDialog.IntroImage.SetImage "#IntroBMP"
IntroDialog.IntroImage.SetStyle STYLE_IMAGE_CENTERED
IntroRet%=DIALOG(IntroDialog)
IF IntroRet% = DIALOG_RETURN_CANCEL THEN STOP
IF IntroRet% = DIALOG_RETURN_NEXT THEN ShowIntro% = 1
END FUNCTION
' *******************************************************************************
' IntroDialogEventHandler
' This subroutine responds to user interface with the introduction dialog.
'
' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is
' generating a dialog event.
' BYVAL Event% - Integer indicating the dialog event that has occurred.
' *******************************************************************************
SUB IntroDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
IF Event% = EVENT_INITIALIZATION THEN
IntroDialog.BackButton.Enable FALSE
IntroDialog.SetStyle STYLE_VISIBLE
ENDIF
IF Event% = EVENT_MOUSE_CLICK THEN
SELECT CASE ControlID%
CASE IntroDialog.NextButton.GetID()
IntroDialog.CloseDialog DIALOG_RETURN_NEXT
CASE IntroDialog.CancelButton.GetID()
IntroDialog.CloseDialog DIALOG_RETURN_CANCEL
END SELECT
ENDIF
END FUNCTION
' *******************************************************************************
' GetFileType
' This function displays the tag type dialog and prompts the user for the type of
' tag to look for (paragraph, character, or both).
'
' PARAMS: None
'
' RETURNS: GetFileType AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION GetFileType%
BEGIN DIALOG OBJECT FileTypeDialog 290, 180, "Find Unused Files Wizard", SUB FileTypeDialogEventHandler
OPTIONGROUP .FileTypeOptionGroup
OPTIONBUTTON 115, 40, 65, 12, .BothOptionButton, "&All files"
OPTIONBUTTON 115, 55, 65, 12, .PictureFilesOption, "&Picture files"
OPTIONBUTTON 115, 70, 65, 12, .TextFilesOption, "&Text files"
OPTIONGROUP .SearchOptionGroup
OPTIONBUTTON 115, 108, 74, 12, .EntirePubOptionButton, "&Entire publication"
OPTIONBUTTON 115, 122, 76, 12, .CurrentChapterOptionButton, "&Current chapter"
PUSHBUTTON 135, 160, 46, 14, .BackButton, "< &Back"
PUSHBUTTON 181, 160, 46, 14, .NextButton, "&Search"
CANCELBUTTON 234, 160, 46, 14, .CancelButton
TEXT 95, 10, 185, 12, .Text1, "What type of files would you like to search for?"
GROUPBOX 95, 30, 185, 58, .GroupBox1, "File Type:"
GROUPBOX 95, 95, 185, 45, .GroupBox2, "Search:"
IMAGE 10, 10, 75, 130, .FileTypeImage
GROUPBOX 10, 150, 270, 5, .LineGroupBox
END DIALOG
FileTypeDialog.SetStyle STYLE_INVISIBLE
FileTypeDialog.FileTypeImage.SetImage "#Step2BMP"
FileTypeDialog.FileTypeImage.SetStyle STYLE_IMAGE_CENTERED
FileTypeDialog.SetStyle STYLE_VISIBLE
FileTypeRet%=DIALOG(FileTypeDialog)
SELECT CASE FileTypeRet%
CASE DIALOG_RETURN_CANCEL
STOP
CASE DIALOG_RETURN_NEXT
FileTypeDialog.SetVisible FALSE
FileType% = FileTypeDialog.FileTypeOptionGroup.GetValue()
SearchType% = FileTypeDialog.SearchOptionGroup.GetValue()
REM ClearFileList
GetFileType = 1
CASE DIALOG_RETURN_BACK
GetFileType = -1
END SELECT
END FUNCTION
' *******************************************************************************
' FileTypeDialogEventHandler
' This subroutine responds to user interface with the file type dialog.
'
' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is
' generating a dialog event.
' BYVAL Event% - Integer indicating the dialog event that has occurred.
' *******************************************************************************
SUB FileTypeDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
IF Event% = EVENT_INITIALIZATION THEN
FileTypeDialog.SetStyle STYLE_VISIBLE
ENDIF
IF Event% = EVENT_MOUSE_CLICK THEN
SELECT CASE ControlID%
CASE FileTypeDialog.NextButton.GetID()
BEGINWAITCURSOR
WITHOBJECT OBJECT_VENTURA8
ENDWAITCURSOR
'Make sure there is an open pub
IF .CountWindows() = 0 THEN
PubMsg$ = "You need an open publication to run this script." & CHR(13) & "Open one now?"
MsgVal% = MESSAGEBOX(PubMsg$, "WARNING", MB_YES_NO OR MB_STOP_ICON)
IF MsgVal% = MSG_YES THEN 'Yes, open a pub
SETCURRFOLDER VenturaRoot$
PubName$ = GETFILEBOX("Publication files (*.VP*)|*.VP*", , , ,"*.vp*", VenturaRoot$ & "\Ventura\Samples" )
IF PubName$ <> "" THEN
.SetVisible TRUE
.FileOpen PubName$, , TRUE, 1, TRUE, FALSE
FileTypeDialog.closedialog DIALOG_RETURN_NEXT
ENDIF
ELSE
'STOP
ENDIF
ELSE
PubName$=.PublicationName()
FileTypeDialog.closedialog DIALOG_RETURN_NEXT
ENDIF
END WITHOBJECT
CASE FileTypeDialog.BackButton.GetID()
FileTypeDialog.closedialog DIALOG_RETURN_BACK
CASE FileTypeDialog.CancelButton.GetID()
FileTypeDialog.closedialog DIALOG_RETURN_CANCEL
END SELECT
ENDIF
END SUB
' *******************************************************************************
' ShowUnusedFiles
' This function displays the results of the unused paragraph tag search.
'
' PARAMS: None
'
' RETURNS: ShowUnusedFiles AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION ShowUnusedFiles%
BEGIN DIALOG OBJECT UnusedFilesDialog 290, 180, "Find Unused Files Wizard", SUB UnusedFilesDialogEventHandler '"Corel VENTURA Conversion Wizard - Done"
PUSHBUTTON 135, 160, 46, 14, .BackButton, "< &Back"
PUSHBUTTON 181, 160, 46, 14, .NextButton, "&Next >"
CANCELBUTTON 234, 160, 46, 14, .CancelButton
PUSHBUTTON 122, 40, 46, 14, .SelectButton, "Se&lect >>"
PUSHBUTTON 122, 55, 46, 14, .DeselectButton, "<< &Deselect"
PUSHBUTTON 122, 80, 46, 14, .SelectAllButton, "Select &All"
PUSHBUTTON 122, 95, 46, 14, .DeselectAllButton, "D&eselect All"
PUSHBUTTON 122, 120, 46, 14, .SaveButton, "&Save list..."
LISTBOX 10, 35, 100, 100, .UnusedFilesListBox
LISTBOX 10, 35, 100, 100, .ChapsListBox
LISTBOX 180, 35, 100, 100, .SelectedUnusedFilesListBox
LISTBOX 180, 35, 100, 100, .SelectedChapsListBox
TEXT 10, 5, 269, 12, .Text2, "Which picture files would you like to delete? "
TEXT 10, 20, 79, 12, .Text4, "Unused picture files:"
TEXT 90, 20, 20, 12, .UnusedFilesCount, ""
TEXT 180, 20, 75, 12, .Text5, "Files to be deleted:"
TEXT 258, 20, 20, 12, .SelectedUnusedFilesCount, ""
GROUPBOX 10, 150, 270, 5, .LineGroupBox
TEXT 11, 139, 264, 12, .StatusText, "No files selected"
END DIALOG
UnusedFilesDialog.SetStyle STYLE_INVISIBLE
UnusedFilesDialog.ChapsListBox.SetStyle STYLE_INVISIBLE
UnusedFilesDialog.SelectedChapsListBox.SetStyle STYLE_INVISIBLE
UnusedFilesDialog.StatusText.SetStyle STYLE_SUNKEN
UnusedFilesDialogRet% = DIALOG(UnusedFilesDialog)
SELECT CASE UnusedFilesDialogRet%
CASE DIALOG_RETURN_CANCEL
STOP
CASE DIALOG_RETURN_NEXT
ShowUnusedFiles = 1
CASE DIALOG_RETURN_BACK
IF FileType%=PICTURE_FILES THEN
ShowUnusedFiles = -1
ELSE
ShowUnusedFiles = -2
ENDIF
END SELECT
END FUNCTION
' *******************************************************************************
' UnusedFilesDialogEventHandler
' This subroutine responds to user interface with the unused files dialog.
'
' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is
' generating a dialog event.
' BYVAL Event% - Integer indicating the dialog event that has occurred.
' *******************************************************************************
SUB UnusedFilesDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
DIM i%
DIM SaveStatus AS BOOLEAN
STATIC SelectedUnusedFilesCount%
STATIC UnusedFilesCount%
IF Event% = EVENT_INITIALIZATION THEN
UnusedFilesDialog.UnusedFilesCount.SetStyle STYLE_RIGHT_JUSTIFY
UnusedFilesDialog.SelectedUnusedFilesCount.SetStyle STYLE_RIGHT_JUSTIFY
SELECT CASE FileType%
CASE PICTURE_FILES%
UnusedFilesCount% = UnusedPictureFilesCount%
SelectedUnusedFilesCount% = SelectedUnusedPictureFilesCount%
FOR i% = 1 TO UnusedFilesCount%
UnusedFilesDialog.UnusedFilesListBox.AddItem UnusedPictureFiles(i%, 1)
UnusedFilesDialog.ChapsListBox.AddItem UnusedPictureFiles(i%, 2)
NEXT i%
FOR i% = 1 TO SelectedUnusedFilesCount%
UnusedFilesDialog.SelectedUnusedFilesListBox.AddItem SelectedUnusedPictureFiles(i%, 1)
UnusedFilesDialog.SelectedChapsListBox.AddItem SelectedUnusedPictureFiles(i%, 2)
NEXT i%
UnusedFilesDialog.Text2.SetText "Which picture files would you like to delete?"
UnusedFilesDialog.Text4.SetText "Unused picture files:"
CASE TEXT_FILES%
UnusedFilesCount% = UnusedTextFilesCount%
SelectedUnusedFilesCount% = SelectedUnusedTextFilesCount%
FOR i% = 1 TO UnusedFilesCount%
UnusedFilesDialog.UnusedFilesListBox.AddItem UnusedTextFiles$(i%, 1)
UnusedFilesDialog.ChapsListBox.AddItem UnusedTextFiles$(i%, 2)
NEXT i%
FOR i% = 1 TO SelectedUnusedFilesCount%
UnusedFilesDialog.SelectedUnusedFilesListBox.AddItem SelectedUnusedTextFiles$(i%, 1)
UnusedFilesDialog.SelectedChapsListBox.AddItem SelectedUnusedTextFiles$(i%, 2)
NEXT i%
UnusedFilesDialog.Text2.SetText "Which text files would you like to delete?"
UnusedFilesDialog.Text4.SetText "Unused text files:"
END SELECT
IF UnusedFilesCount < 1 THEN
UnusedFilesDialog.Text2.SetText "There are no unused files."
UnusedFilesDialog.SelectButton.Enable FALSE
UnusedFilesDialog.DeselectButton.Enable FALSE
UnusedFilesDialog.SelectAllButton.Enable FALSE
UnusedFilesDialog.DeselectAllButton.Enable FALSE
UnusedFilesDialog.SaveButton.Enable FALSE
ENDIF
UnusedFilesDialog.UnusedFilesListBox.SetSelect 1
UnusedFilesDialog.UnusedFilesCount.SetText UnusedFilesDialog.UnusedFilesListBox.GetItemCount()
UnusedFilesDialog.SelectedUnusedFilesCount.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount()
UnusedFilesDialog.StatusText.SetText UnusedFilesDialog.UnusedFilesListBox.GetItem(1)
UnusedFilesDialog.SetStyle STYLE_VISIBLE
ENDIF
IF Event% = EVENT_MOUSE_CLICK THEN
SELECT CASE ControlID%
CASE UnusedFilesDialog.NextButton.GetID()
'build list of appropriate files
SELECT CASE FileType%
CASE PICTURE_FILES%
SelectedUnusedPictureFilesCount% = UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount()
REDIM SelectedUnusedPictureFiles$(SelectedUnusedPictureFilesCount, 2) 'redimension array to accomodate all selected files
FOR i% = 1 TO SelectedUnusedPictureFilesCount% 'FOR all items in selected files list
SelectedUnusedPictureFiles$(i%, 1) = UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(i%) 'add selection to FilesList
SelectedUnusedPictureFiles$(i%, 2) = UnusedFilesDialog.SelectedChapsListBox.GetItem(i%) 'add selection to FilesList
NEXT i%
UnusedPictureFilesCount% = UnusedFilesDialog.UnusedFilesListBox.GetItemCount()
REDIM UnusedPictureFiles$(UnusedPictureFilesCount, 2) 'redimension array to accomodate all selected files
FOR i% = 1 TO UnusedPictureFilesCount% 'FOR all items in selected files list
UnusedPictureFiles$(i%, 1) = UnusedFilesDialog.UnusedFilesListBox.GetItem(i%) 'add selection to FilesList
UnusedPictureFiles$(i%, 2) = UnusedFilesDialog.ChapsListBox.GetItem(i%) 'add selection to FilesList
NEXT i%
CASE TEXT_FILES%
SelectedUnusedTextFilesCount% = UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount()
REDIM SelectedUnusedTextFiles$(SelectedUnusedTextFilesCount, 2) 'redimension array to accomodate all selected files
FOR i% = 1 TO SelectedUnusedTextFilesCount% 'FOR all items in selected files list
SelectedUnusedTextFiles$(i%, 1) = UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(i%) 'add selection to FilesList
SelectedUnusedTextFiles$(i%, 2) = UnusedFilesDialog.SelectedChapsListBox.GetItem(i%) 'add selection to FilesList
NEXT i%
UnusedTextFilesCount% = UnusedFilesDialog.UnusedFilesListBox.GetItemCount()
REDIM UnusedTextFiles$(UnusedTextFilesCount, 2) 'redimension array to accomodate all selected files
FOR i% = 1 TO UnusedTextFilesCount% 'FOR all items in selected files list
UnusedTextFiles$(i%, 1) = UnusedFilesDialog.UnusedFilesListBox.GetItem(i%) 'add selection to FilesList
UnusedTextFiles$(i%, 2) = UnusedFilesDialog.ChapsListBox.GetItem(i%) 'add selection to FilesList
NEXT i%
END SELECT
UnusedFilesDialog.CloseDialog DIALOG_RETURN_NEXT
CASE UnusedFilesDialog.BackButton.GetID()
UnusedFilesDialog.CloseDialog DIALOG_RETURN_BACK
CASE UnusedFilesDialog.SelectButton.GetID()
indx% = UnusedFilesDialog.UnusedFilesListBox.GetSelect() 'get index of selection
IF indx%=0 THEN 'no tags selected
IF UnusedFilesDialog.UnusedFilesListBox.GetItemCount() = 0 THEN
MESSAGE "There are no files available for selection."
ELSE
MESSAGE "Please select a file from the available files list."
ENDIF
ELSE
UnusedFilesDialog.SelectedUnusedFilesListBox.AddItem UnusedFilesDialog.UnusedFilesListBox.GetItem(indx%) 'add selection to SelectedFilesList
UnusedFilesDialog.SelectedChapsListBox.AddItem UnusedFilesDialog.ChapsListBox.GetItem(indx%) 'add selection to SelectedFilesList
UnusedFilesDialog.UnusedFilesListBox.RemoveItem indx% 'remove selection from available files list
UnusedFilesDialog.ChapsListBox.RemoveItem indx% 'remove selection from available files list
IF indx% > UnusedFilesDialog.UnusedFilesListBox.GetItemCount() THEN
UnusedFilesDialog.UnusedFilesListBox.SetSelect indx%-1
ELSE
UnusedFilesDialog.UnusedFilesListBox.SetSelect indx%
ENDIF
UnusedFilesDialog.StatusText.SetText UnusedFilesDialog.UnusedFilesListBox.GetItem(UnusedFilesDialog.UnusedFilesListBox.GetSelect())
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect 0
ENDIF
CASE UnusedFilesDialog.DeselectButton.GetID() 'selected files list
indx% = UnusedFilesDialog.SelectedUnusedFilesListBox.GetSelect() 'get index of selection
IF indx%=0 THEN 'no files selected
IF UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() = 0 THEN
MESSAGE "There are no files available for deselection"
ELSE
MESSAGE "Please select a file from the selected files list."
ENDIF
ELSE
UnusedFilesDialog.UnusedFilesListBox.AddItem UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(indx%) 'add selection to FilesList
UnusedFilesDialog.ChapsListBox.AddItem UnusedFilesDialog.SelectedChapsListBox.GetItem(indx%) 'add selection to FilesList
UnusedFilesDialog.SelectedUnusedFilesListBox.RemoveItem indx% 'remove selection from selected files list
UnusedFilesDialog.SelectedChapsListBox.RemoveItem indx% 'remove selection from selected files list
IF indx% > UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() THEN
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect indx%-1
ELSE
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect indx%
ENDIF
UnusedFilesDialog.StatusText.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(UnusedFilesDialog.SelectedUnusedFilesListBox.GetSelect())
UnusedFilesDialog.UnusedFilesListBox.SetSelect 0
ENDIF
CASE UnusedFilesDialog.SelectAllButton.GetID()
UnusedFilesDialog.StatusText.SetText "All files selected."
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect 0
WHILE UnusedFilesDialog.UnusedFilesListBox.GetItemCount() > 0 'while there are available files
UnusedFilesDialog.SelectedUnusedFilesListBox.AddItem UnusedFilesDialog.UnusedFilesListBox.GetItem(1) 'add selection to SelectedFilesList
UnusedFilesDialog.SelectedChapsListBox.AddItem UnusedFilesDialog.ChapsListBox.GetItem(1) 'add selection to SelectedFilesList
UnusedFilesDialog.UnusedFilesListBox.RemoveItem 1 'remove selection from available files list
UnusedFilesDialog.ChapsListBox.RemoveItem 1 'remove selection from available files list
UnusedFilesDialog.UnusedFilesCount.SetText UnusedFilesDialog.UnusedFilesListBox.GetItemCount() 'number of available files
UnusedFilesDialog.SelectedUnusedFilesCount.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() 'number of selected files
WEND
CASE UnusedFilesDialog.DeselectAllButton.GetID()
UnusedFilesDialog.StatusText.SetText "No files selected."
UnusedFilesDialog.UnusedFilesListBox.SetSelect 0
WHILE UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() > 0 'while there are selected files
UnusedFilesDialog.UnusedFilesListBox.AddItem UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(1) 'add selection to FilesList
UnusedFilesDialog.ChapsListBox.AddItem UnusedFilesDialog.SelectedChapsListBox.GetItem(1) 'add selection to FilesList
UnusedFilesDialog.SelectedUnusedFilesListBox.RemoveItem 1 'remove selection from selected files list
UnusedFilesDialog.SelectedChapsListBox.RemoveItem 1 'remove selection from selected files list
UnusedFilesDialog.UnusedFilesCount.SetText UnusedFilesDialog.UnusedFilesListBox.GetItemCount() 'number of available files
UnusedFilesDialog.SelectedUnusedFilesCount.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() 'number of selected files
WEND
CASE UnusedFilesDialog.SaveButton.GetID()
SELECT CASE FileType%
CASE PICTURE_FILES
DialogTitle$ = "Save list of unused picture files to..."
DefFileName$ = "PicFiles.txt"
CASE TEXT_FILES
DialogTitle$ = "Save list of unused text files to..."
DefFileName$ = "TextFiles.txt"
END SELECT
SaveFile$ = GETFILEBOX("Text files (*.TXT)|*.TXT", "Save unused picture files to...", 1, "PicFiles.txt", "txt", VenturaRoot$)
IF SaveFile$ <> "" THEN
SaveStatus = SaveToFile(SaveFile$)
IF SaveStatus = TRUE THEN
MESSAGE "Save successful"
ELSE
MESSAGE "Unable to save to " & CHR(13) & SaveFile$
ENDIF
ENDIF
CASE UnusedFilesDialog.CancelButton.GetID()
UnusedFilesDialog.closedialog DIALOG_RETURN_CANCEL
CASE UnusedFilesDialog.UnusedFilesListBox.GetID() 'files list
UnusedFilesDialog.StatusText.SetText UnusedFilesDialog.UnusedFilesListBox.GetItem(UnusedFilesDialog.UnusedFilesListBox.GetSelect())
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect 0
CASE UnusedFilesDialog.SelectedUnusedFilesListBox.GetID() 'selected files list
UnusedFilesDialog.StatusText.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(UnusedFilesDialog.SelectedUnusedFilesListBox.GetSelect())
UnusedFilesDialog.UnusedFilesListBox.SetSelect 0
END SELECT
UnusedFilesDialog.UnusedFilesCount.SetText UnusedFilesDialog.UnusedFilesListBox.GetItemCount() 'number of available files
UnusedFilesDialog.SelectedUnusedFilesCount.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() 'number of selected files
ENDIF
IF Event% = EVENT_DBL_MOUSE_CLICK THEN
SELECT CASE ControlID%
CASE UnusedFilesDialog.UnusedFilesListBox.GetID() 'files list
indx% = UnusedFilesDialog.UnusedFilesListBox.GetSelect() 'get index of selection
UnusedFilesDialog.SelectedUnusedFilesListBox.AddItem UnusedFilesDialog.UnusedFilesListBox.GetItem(indx%) 'add selection to SelectedFilesList
UnusedFilesDialog.SelectedChapsListBox.AddItem UnusedFilesDialog.ChapsListBox.GetItem(indx%) 'add selection to SelectedFilesList
UnusedFilesDialog.UnusedFilesListBox.RemoveItem indx% 'remove selection from available files list
UnusedFilesDialog.ChapsListBox.RemoveItem indx% 'remove selection from available files list
IF indx% > UnusedFilesDialog.UnusedFilesListBox.GetItemCount() THEN
UnusedFilesDialog.UnusedFilesListBox.SetSelect indx%-1
ELSE
UnusedFilesDialog.UnusedFilesListBox.SetSelect indx%
ENDIF
CASE UnusedFilesDialog.SelectedUnusedFilesListBox.GetID() 'selected files list
indx% = UnusedFilesDialog.SelectedUnusedFilesListBox.GetSelect() 'get index of selection
UnusedFilesDialog.UnusedFilesListBox.AddItem UnusedFilesDialog.SelectedUnusedFilesListBox.GetItem(indx%) 'add selection to FilesList
UnusedFilesDialog.ChapsListBox.AddItem UnusedFilesDialog.SelectedChapsListBox.GetItem(indx%) 'add selection to FilesList
UnusedFilesDialog.SelectedUnusedFilesListBox.RemoveItem indx% 'remove selection from selected files list
UnusedFilesDialog.SelectedChapsListBox.RemoveItem indx% 'remove selection from selected files list
IF indx% > UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() THEN
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect indx%-1
ELSE
UnusedFilesDialog.SelectedUnusedFilesListBox.SetSelect indx%
ENDIF
END SELECT
UnusedFilesDialog.UnusedFilesCount.SetText UnusedFilesDialog.UnusedFilesListBox.GetItemCount() 'number of available tags
UnusedFilesDialog.SelectedUnusedFilesCount.SetText UnusedFilesDialog.SelectedUnusedFilesListBox.GetItemCount() 'number of selected tags
ENDIF
END SUB
' *******************************************************************************
' ShowFinish
' This function displays the finish dialog, showing the number of each type of
' unused files found, and how many have been selected for deletion.
'
' PARAMS: None
'
' RETURNS: ShowFinish AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION ShowFinish%
BEGIN DIALOG OBJECT ShowFinishDialog 290, 180, "Find Unused Files Wizard", SUB ShowFinishDialogEventHandler
PUSHBUTTON 135, 160, 46, 14, .BackButton, "< &Back"
PUSHBUTTON 181, 160, 46, 14, .FinishButton, "&Delete"
PUSHBUTTON 234, 160, 46, 14, .CancelButton, "&Exit"
TEXT 95, 10, 185, 12, .InfoText, InfoText$
TEXT 95, 130, 185, 12, .DeleteText, DeleteText$
TEXT 95, 30, 80, 10, .PictureFilesText, "Unused Picture Files:"
TEXT 185, 30, 90, 10, .PictureFilesText2, "n of n selected for deletion"
TEXT 95, 50, 80, 10, .TextFilesText, "Unused Text Files:"
TEXT 185, 50, 90, 10, .TextFilesText2, "n of n selected for deletion"
IMAGE 10, 10, 75, 130, .ShowFinishImage
GROUPBOX 10, 150, 270, 5, .LineGroupBox
END DIALOG
ShowFinishDialog.SetStyle STYLE_INVISIBLE
ShowFinishDialog.ShowFinishImage.SetImage "#LastBMP"
ShowFinishDialog.ShowFinishImage.SetStyle STYLE_IMAGE_CENTERED
ShowFinishRet% = Dialog(ShowFinishDialog)
SELECT CASE ShowFinishRet%
CASE DIALOG_RETURN_CANCEL
STOP
CASE DIALOG_RETURN_NEXT
ShowFinish = 1
CASE DIALOG_RETURN_BACK
ShowFinish = -1
END SELECT
END FUNCTION
' *******************************************************************************
' ShowFinishDialogEventHandler
' This subroutine responds to user interface with the finish dialog.
'
' PARAMS: BYVAL ControlID% - Integer indicating the dialog control that is
' generating a dialog event.
' BYVAL Event% - Integer indicating the dialog event that has occurred.
' *******************************************************************************
SUB ShowFinishDialogEventHandler(BYVAL ControlID%, BYVAL Event%)
IF Event% = EVENT_INITIALIZATION THEN '
TotalUnusedFilesCount = SelectedUnusedPictureFilesCount + SelectedUnusedTextFilesCount
IF TotalUnusedFilesCount = 0 THEN
InfoText$ = "No files have been selected for deletion."
DeleteText$ = ""
ShowFinishDialog.FinishButton.Enable FALSE
ELSEIF TotalUnusedFilesCount = 1 THEN
InfoText$ = TotalUnusedFilesCount & " file has been selected for deletion."
DeleteText$ = "Select Delete to permanently remove the unused file."
ELSE
InfoText$ = TotalUnusedFilesCount & " files have been selected for deletion."
DeleteText$ = "Select Delete to permanently remove the unused files."
ENDIF
ShowFinishDialog.InfoText.SetText InfoText$
ShowFinishDialog.DeleteText.SetText DeleteText$
SELECT CASE FileType%
CASE BOTH_FILES
ShowFinishDialog.PictureFilesText.SetText "Unused Picture Files:"
IF UnusedPictureFilesCount% < 1 AND SelectedUnusedPictureFilesCount% < 1 THEN
ShowFinishDialog.PictureFilesText2.SetText "No unused picture files"
ELSE
ShowFinishDialog.PictureFilesText2.SetText SelectedUnusedPictureFilesCount% & " of " & UnusedPictureFilesCount%+ SelectedUnusedPictureFilesCount% & " selected for deletion"
ENDIF
ShowFinishDialog.TextFilesText.SetText "Unused Text Files:"
IF UnusedTextFilesCount% < 1 AND SelectedUnusedTextFilesCount% < 1 THEN
ShowFinishDialog.TextFilesText2.SetText "No unused text files"
ELSE
ShowFinishDialog.TextFilesText2.SetText SelectedUnusedTextFilesCount% & " of " & UnusedTextFilesCount%+ SelectedUnusedTextFilesCount% & " selected for deletion"
ENDIF
CASE PICTURE_FILES
ShowFinishDialog.PictureFilesText.SetText "Unused Picture Files:"
IF UnusedPictureFilesCount% < 1 AND SelectedUnusedPictureFilesCount% < 1 THEN
ShowFinishDialog.PictureFilesText2.SetText "No unused picture files"
ELSE
ShowFinishDialog.PictureFilesText2.SetText SelectedUnusedPictureFilesCount% & " of " & UnusedPictureFilesCount%+ SelectedUnusedPictureFilesCount% & " selected for deletion"
ENDIF
ShowFinishDialog.TextFilesText.SetText ""
ShowFinishDialog.TextFilesText2.SetText ""
CASE TEXT_FILES
ShowFinishDialog.TextFilesText.SetText "Unused Text Files:"
IF UnusedTextFilesCount% < 1 AND SelectedUnusedTextFilesCount% < 1 THEN
ShowFinishDialog.TextFilesText2.SetText "No unused text files"
ELSE
ShowFinishDialog.TextFilesText2.SetText SelectedUnusedTextFilesCount% & " of " & UnusedTextFilesCount%+ SelectedUnusedTextFilesCount% & " selected for deletion"
ENDIF
ShowFinishDialog.PictureFilesText.SetText ""
ShowFinishDialog.PictureFilesText2.SetText ""
END SELECT
ShowFinishDialog.SetStyle STYLE_VISIBLE
ENDIF
IF Event% = EVENT_MOUSE_CLICK THEN
SELECT CASE ControlID%
CASE ShowFinishDialog.FinishButton.GetID()
ShowFinishDialog.CloseDialog DIALOG_RETURN_NEXT
CASE ShowFinishDialog.BackButton.GetID()
ShowFinishDialog.CloseDialog DIALOG_RETURN_BACK
CASE ShowFinishDialog.CancelButton.GetID()
ShowFinishDialog.CloseDialog DIALOG_RETURN_CANCEL
END SELECT
ENDIF
END SUB
' *******************************************************************************
' SaveToFile
' This function writes the list of unused files to the specified text file.
'
' PARAMS: FileListFile$ - the name of the text file in which to write the list.
'
' RETURNS: SaveToFile AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION SaveToFile(FileListFile$) AS BOOLEAN
ON ERROR GOTO ErrorHandler
CLOSE
OPEN FileListFile$ FOR APPEND AS 1
SELECT CASE FileType%
CASE PICTURE_FILES
PRINT #1, "Unused Picture Files:"
FOR i%=1 TO UnusedPictureFilesCount%
PRINT #1, UnusedPictureFiles(i%, 1)
NEXT i%
CASE TEXT_FILES
PRINT #1, "Unused Text Files:"
FOR i%=1 TO UnusedTextFilesCount%
PRINT #1, UnusedTextFiles(i%, 1)
NEXT i%
CASE BOTH_FILES
PRINT #1, "Unused Picture Files:"
FOR i%=1 TO UnusedPictureFilesCount%
PRINT #1, UnusedPictureFiles(i%, 1)
NEXT i%
PRINT #1, CHR(13)
PRINT #1, "Unused Text Files:"
FOR i%=1 TO UnusedTextFilesCount%
PRINT #1, UnusedTextFiles(i%, 1)
NEXT i%
END SELECT
CLOSE(1)
SaveToFile = TRUE
EXIT FUNCTION
ErrorHandler:
CLOSE
SaveToFile = FALSE
END FUNCTION
' *******************************************************************************
' RemoveUnusedFiles
' This function removes all selected unused files from the publication.
'
' PARAMS: None
'
' RETURNS: RemoveUnusedFiles AS INTEGER - Integer indicating dialog return value.
' *******************************************************************************
FUNCTION RemoveUnusedFiles%
WITHOBJECT OBJECT_VENTURA8
SELECT CASE FileType%
CASE PICTURE_FILES
WHILE (SelectedUnusedPictureFilesCount > 0)
.FileRemove SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 1), FALSE, TRUE, TRUE, SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 2)
SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 1) = ""
SelectedUnusedPictureFilesCount = SelectedUnusedPictureFilesCount - 1
WEND
CASE TEXT_FILES
WHILE (SelectedUnusedTextFilesCount > 0)
.FileRemove SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 1), FALSE, TRUE, FALSE, SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 2)
SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 1) = ""
SelectedUnusedTextFilesCount = SelectedUnusedTextFilesCount - 1
WEND
CASE BOTH_FILES
WHILE (SelectedUnusedPictureFilesCount > 0)
.FileRemove SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 1), FALSE, TRUE, TRUE, SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 2)
SelectedUnusedPictureFiles(SelectedUnusedPictureFilesCount, 1) = ""
SelectedUnusedPictureFilesCount = SelectedUnusedPictureFilesCount - 1
WEND
WHILE (SelectedUnusedTextFilesCount > 0)
.FileRemove SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 1), FALSE, TRUE, FALSE, SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 2)
SelectedUnusedTextFiles(SelectedUnusedTextFilesCount, 1) = ""
SelectedUnusedTextFilesCount = SelectedUnusedTextFilesCount - 1
WEND
END SELECT
END WITHOBJECT
RemoveUnusedFiles = 1
END FUNCTION
' *******************************************************************************
' FindFiles
' This subroutine locates all files of the specified type. Each file is passed
' to the CreateListOfFiles subroutine which determines whether the file is used.
'
' PARAMS: TypeOfFile AS INTEGER - the type of file being sought:
' 1-Picture files
' 2-Text files
' *******************************************************************************
SUB FindFiles(TypeOfFile%)
BEGINWAITCURSOR
WITHOBJECT OBJECT_VENTURA8
.SetVisible TRUE 'ShowVentura
SELECT CASE TypeOfFile%
CASE PICTURE_FILES 'find picture files
IF SearchType% = SEARCH_ENTIRE_PUB THEN
'FOR every chapter in publication
NumberOfChapters& = .ChapterCount()
FOR i% = 1 TO NumberOfChapters&
CurChapter$ = .ChapterGetAt(i%)
.ViewGoToPage , CurChapter$, GOTO_RELATIVE_TO_CHAPTER, GOTO_PAGE_FIRST, FALSE
PictureFiles%= .PictureFileCount()
FOR j%=1 TO PictureFiles%
PictureFileName$ = .PictureFileGetAt(j%)
CreateListOfFiles FALSE, PictureFileName$, CurChapter$
NEXT j%
NEXT i%
ELSE 'Only search current chapter
CurChapter$= .CurrentChapter()
PictureFiles%= .PictureFileCount()
FOR j%=1 TO PictureFiles%
PictureFileName$ = .PictureFileGetAt(j%)
CreateListOfFiles FALSE, PictureFileName$, CurChapter$
NEXT j%
ENDIF
CASE TEXT_FILES 'find text files
IF SearchType% = SEARCH_ENTIRE_PUB THEN
'FOR every chapter in publication
NumberOfChapters& = .ChapterCount()
FOR i% = 1 TO NumberOfChapters&
CurChapter$ = .ChapterGetAt(i%)
.ViewGoToPage , CurChapter$, GOTO_RELATIVE_TO_CHAPTER, GOTO_PAGE_FIRST, FALSE
TextFiles% = .TextFileCount()
FOR j%=1 TO TextFiles%
TextFileName$ = .TextFileGetAt(j%)
CreateListOfFiles TRUE, TextFileName$, CurChapter$
NEXT j%
NEXT i%
ELSE 'Only search current chapter
CurChapter$= .CurrentChapter()
TextFiles% = .TextFileCount()
FOR j%=1 TO TextFiles%
TextFileName$ = .TextFileGetAt(j%)
CreateListOfFiles TRUE, TextFileName$, CurChapter$
NEXT j%
ENDIF
END SELECT
END WITHOBJECT
ENDWAITCURSOR
END SUB
' *******************************************************************************
' CreateListOfFiles
' This function creates a list of all unused files of the specified type.
'
' PARAMS:TypeOfFile AS BOOLEAN - specifies the type of file to look for
' FALSE = Picture files
' TRUE = Text files
' NameOfFile AS STRING - Specifies the name of the file to find.
' CurrentChapter AS STRING - Specifies the chapter containing the file.
' *******************************************************************************
SUB CreateListOfFiles(TypeOfFile AS BOOLEAN, NameOfFile AS STRING, CurrentChapter$)
DIM Found AS BOOLEAN
Found=TRUE
WITHOBJECT OBJECT_VENTURA8
IF TypeOfFile <> FALSE THEN 'it's a text file
Found = .TextFileIsUsed(NameOfFile$)
IF Found=FALSE THEN 'file is NOT in use
UnusedTextFilesCount = UnusedTextFilesCount + 1
IF UnusedTextFilesCount% MOD MAXFILES = 0 THEN
NewCnt% = UnusedTextFilesCount% + MAXFILES
REDIM PRESERVE UnusedTextFiles$(NewCnt, 2)
REDIM PRESERVE SelectedUnusedTextFiles$(NewCnt, 2)
ENDIF
UnusedTextFiles$(UnusedTextFilesCount, 1) = NameOfFile$ : UnusedTextFiles$(UnusedTextFilesCount, 2) = CurrentChapter$
ENDIF
ELSE 'it's a picture file
Found = .PictureFileIsUsed(NameOfFile$)
IF Found=FALSE THEN 'file is NOT in use
UnusedPictureFilesCount = UnusedPictureFilesCount + 1
IF UnusedPictureFilesCount% MOD MAXFILES = 0 THEN
NewCnt% = UnusedPictureFilesCount% + MAXFILES
REDIM PRESERVE UnusedPictureFiles$(NewCnt, 2)
REDIM PRESERVE SelectedUnusedPictureFiles$(NewCnt, 2)
ENDIF
UnusedPictureFiles$(UnusedPictureFilesCount, 1) = NameOfFile$ : UnusedPictureFiles$(UnusedPictureFilesCount, 2) = CurrentChapter$
ENDIF
ENDIF
END WITHOBJECT
END SUB