Snippets
Created by
SeanB
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | Use Windows.pkg
Use cHtmlHelp.pkg
Use cApplication.pkg
Use cTextEdit.pkg
Use File_dlg.pkg
Object oHtmlHelp is a cHtmlHelp
End_Object
Object oApplication is a cApplication
Set pbPreserveEnvironment to False
Set peHelpType to htHtmlHelp
End_Object
Struct tFilelist
String sLogicalName
String sSearch
Boolean isDuplicated
Integer iPosition
End_Struct
Use Batchdd.pkg
Object oFilelistChecker is a BusinessProcess
Property String[] paDuplicateList
Function CurrentValue Integer iFile Returns tFilelist
tFilelist flValue
String sName
Get_Attribute Df_File_Logical_Name of iFile to sName
Move (lowercase(sName)) to flValue.sSearch
Move sName to flValue.sLogicalName
Move iFile to flValue.iPosition
Function_Return flValue
End_Function
Function filelist_sort tFilelist flist1 tFilelist flist2 Returns Integer
If (flist1.sSearch>flist2.sSearch) Function_Return (GT)
Else If (flist1.sSearch<flist2.sSearch) Function_Return (LT)
Else Function_Return (EQ)
End_Function
Function FillFilelistArray Returns tFilelist[]
tFilelist[] FilesList
Integer iFile
Move 0 to iFile
Repeat
Get_Attribute Df_File_Next_Used of iFile to iFile
If (iFile <> 0) Move (CurrentValue(Self,iFile)) to FilesList[SizeOfArray(FilesList)]
Until (iFile=0)
Function_Return FilesList
End_Procedure
Function ShowRepeats tFilelist[] FilesList Returns String[]
Integer iPos
Integer iMax
String sError
String[] aErrors
Move (SizeOfArray(FilesList)) to iMax
Move (iMax-1) to iMax //don't need to check last items
For iPos from 0 to (iMax-1)
If (FilesList[iPos].sSearch=FilesList[iPos+1].sSearch) Begin
Move (SFormat("Duplicate name: %1; files %2 and %3",FilesList[iPos].sLogicalName,FilesList[iPos].iPosition,FilesList[iPos+1].iPosition)) to sError
Move sError to aErrors[SizeOfArray(aErrors)]
End
Loop
Function_Return aErrors
End_Function
Procedure doProcess
tFilelist[] FilesList
Get FillFilelistArray to FilesList
Move (SortArray(FilesList,Self,get_filelist_sort)) to FilesList
Set paDuplicateList to (ShowRepeats(Self,FilesList))
End_Procedure
End_Object
Object Main is a ModalPanel
Set Size to 173 235
Set Label to "Search Filelist for duplicates"
Set Border_Style to Border_Thick
Procedure CheckForDuplicates
String sValue
String[] aDetail
Integer iPos
Integer iMax
String sFilename
Boolean isOK
Send Delete_Data to txtDetails
Get Value of frmFileList to sFilename
File_Exist sFilename isOK
If (not(isOK)) Procedure_Return
Set_Attribute DF_FILELIST_NAME to sFilename
Send AppendTextLn to txtDetails "Checking for duplicates"
Send DoProcess to oFilelistChecker
Get paDuplicateList of oFilelistChecker to aDetail
Move (SizeOfArray(aDetail)) to iMax
If (iMax = 0) Send AppendTextLn to txtDetails "No Duplicates Found"
For iPos from 0 to (iMax-1)
Send AppendTextLn to txtDetails (aDetail[iPos])
Loop
Send AppendTextLn to txtDetails "Finished"
End_Procedure
Object frmFileList is a Form
Set Size to 13 132
Set Location to 11 69
Set Label to "FileList location"
Set peAnchors to anLeftRight
End_Object
Object btnSearch is a Button
Set Size to 14 21
Set Location to 10 202
Set Label to '...'
Set peAnchors to anRight
// fires when the button is clicked
Procedure OnClick
String[] aSelectedFiles
Boolean bOpen
Get Show_Dialog of oOpenDialog1 to bOpen
If (bOpen) Begin
Get Selected_Files of oOpenDialog1 to aSelectedFiles
If ((SizeOfArray(aSelectedFiles))<>0) Set Value of frmFileList to aSelectedFiles[0]
End
End_Procedure
End_Object
Object btnGo is a Button
Set Location to 28 68
Set Label to 'Go'
// fires when the button is clicked
Procedure OnClick
Send CheckForDuplicates
End_Procedure
End_Object
Object txtDetails is a cTextEdit
Set Size to 102 219
Set Location to 49 9
Set peAnchors to anAll
End_Object
Object oOpenDialog1 is an OpenDialog
Set Filter_String to 'filelist|filelist.cfg'
Set Initial_Folder to 'C:\'
Set Filter_Index to 2
End_Object
End_Object
Start_UI Main
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.