IncrediMail conternt cataloguer and renamer

Developed or developing a new product in PureBasic? Tell the world about it.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Code: Select all

;--------------------------------------------------------------------------------------------------------------------------
; Setup the structure and list definitions that nearly every routine will access
;--------------------------------------------------------------------------------------------------------------------------

Structure NameStructure             ; Structure for the list members
  DiskFile.s                         ; The original filename on disk, including the path
  FileName.s                         ; IncrediMail disk filename. May not be the same as the original.
  FileType.s                         ; Letter, Sound, Skin, Animation, Ecard, Notifier, Smiley
  Category.s                         ; What category the file might fit into
  Collection.s                       ; Usually the Author's name, is displayed in the Style Box list
  Display.s                          ; What IncrediMail will display in the style box title for the file
  TradeMark.s                        ; Any of the authors copyright information
  TradeMarkLink.s                    ; TradeMark link. Can be web page or email address
EndStructure

Structure DictStructure             ; Structure for the user dictionary entries
  Target.s                           ; This is the string to be searched for in the source
  Replace.s                          ; This is the string to replace with in the source
EndStructure

NewList DictList.DictStructure()    ; Create a new list using the structure
NewList NameList.NameStructure()    ; Create a new list using the structure

;--------------------------------------------------------------------------------------------------------------------------
; Starting drive for the extract.exe file. Later we can use search routines or internal compression hopefully
;--------------------------------------------------------------------------------------------------------------------------

CatDir$ = "C:\iCat\"                 ; Program home and catalogue default directory for users

;--------------------------------------------------------------------------------------------------------------------------
; Get the list of files from the hard disk into a linked list  - [From Mr Skunk]
;--------------------------------------------------------------------------------------------------------------------------

Procedure GetList(SourceDirectory$, Start, Pattern$)                   ; The treewalk engine, fast!
                                                                        ; Did 5,000 files in 2 seconds
  If ExamineDirectory(Start, SourceDirectory$, "*.*")
    Repeat
      Type = NextDirectoryEntry()
      If Type = 2
        If DirectoryEntryName()  "." And DirectoryEntryName()  ".."
          a$ = SourceDirectory$ + DirectoryEntryName() + "\"
          GetList(a$, Start + 1, Pattern$)
          UseDirectory(Start)
        EndIf
      Else
        If Type = 1 And Right(UCase(DirectoryEntryName()),Len(Pattern$)) = UCase(Pattern$)
          AddElement(NameList())
          NameList()\DiskFile = SourceDirectory$ + DirectoryEntryName()  ; Loading up the list with raw disk filenames
        EndIf
      EndIf
    Until Type = 0
  EndIf

EndProcedure                                                                        ; End of this procedure

;--------------------------------------------------------------------------------------------------------------------------
; Load the user dictionary into a list in memory
;--------------------------------------------------------------------------------------------------------------------------

Procedure LoadDict(CatDir$)                                                        ; Load the user defined dictionary

  If ReadFile(0, CatDir$ + "Dictionary.txt")                                        ; Load it if it exists
  
    While Eof(0) = 0                                                                ; Keep going till the end of the file
    
        AddElement(DictList())                                                       ; Get ready to add to the bottom of the stack
        
        TempIn$ = ReadString()                                                       ; Get a line of text from the dictionary file
        
        DictList()\Target = StripTrail(Left(TempIn$, 40))                            ; Get the target string to find
        
        DictList()\Replace = StripTrail(Mid(TempIn$, 41, Len(TempIn$) - 40))         ; Get the replacement string
        
    Wend                                                                             ; Continue till end
    
  EndIf                                                                              ; End loop if file missing

CloseFile(0)                                                                          ; Close this file

EndProcedure                                                                        ; End of this procedure

;--------------------------------------------------------------------------------------------------------------------------
; Write a nice header to the output file, listing the number of files found and processed
;--------------------------------------------------------------------------------------------------------------------------

Procedure WriteHeader(ListName$)                                       ; Dump some nice headers to the output file

  ResetList(NameList())                                                 ; Reset to the first element in the list
  
  ListMembers = CountList(NameList())                                   ; Count elements for the header report
  
  Head$ = "--------------------------------------------------------------------------------------------------"
  
  CopyRight$ = "Copyright(c), 2001, FangBeast Enterprises (LOL).    "   ; Tongue in cheek header
  
  If OpenFile(0, ListName$)                                             ; Read the log file if alive
  
     FileSeek(Lof())                                                    ; Go to the end of the file
     WriteStringN(Head$)                                                ; Write the header
     WriteString(CopyRight$)                                            ; Write the copyright string
     WriteString(Str(ListMembers))                                      ; Write the number of files produced for the session
     WriteStringN(" Files processed this session")                      ; Write literal text explaining the action
     WriteStringN(Head$)                                                ; Write the header again to make it neat
     
  EndIf                                                                ; End of this write portion
  
  CloseFile(0)                                                          ; Close the file, not needed any more

EndProcedure                                                           ; End of this procedure

;--------------------------------------------------------------------------------------------------------------------------
; Clean all bad characters from the list before dumping it to ensure that it can be used for renaming later on
;--------------------------------------------------------------------------------------------------------------------------

Procedure CleanBadChars()                                                          ; Clean all illegal and high ASCII chars

  BadChars.s = "?^¢£¤¥¦§¨ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÃ