00001 // $Id: sgindgen.h 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // SGindgen.h - Index generation code 00099 00100 #ifndef INC_SGINDGEN 00101 #define INC_SGINDGEN 00102 00103 //#include "pathname.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00104 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "ccfile.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 00107 /******************************************************************************************** 00108 00109 > class IndGenFileBuffer : public CCObject 00110 00111 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00112 Created: 15/05/95 00113 Purpose: Since MSDOS seems happy returning filenames of files in a directory in a 00114 completely random fashion, we need to have some way of storing all the ones 00115 it returns us and sorting them alphabetically, so we can generate index files 00116 in a nice alphabetical order. 00117 00118 The data structure used below is basically an array of TCHAR *'s pointed to 00119 by Buffer. These TCHAR *'s are CCMalloced and given variable length C style 00120 strings by AddItem. The destructor handles the memory tidying up. 00121 00122 ********************************************************************************************/ 00123 00124 class IndGenFileBuffer : public CCObject 00125 { 00126 CC_DECLARE_DYNCREATE( IndGenFileBuffer ) 00127 00128 public: 00129 IndGenFileBuffer(); 00130 ~IndGenFileBuffer(); 00131 BOOL Init(INT32 Count); 00132 BOOL AddItem(TCHAR *String); 00133 BOOL Sort(void); 00134 TCHAR *GetItem(INT32 Count); 00135 INT32 ItemCount(void) {return Items;} 00136 00137 protected: 00138 static INT32 __cdecl SortComparator(const void *Item1, const void *Item2); 00139 00140 protected: 00141 TCHAR **Buffer; 00142 INT32 Items; 00143 INT32 Position; 00144 }; 00145 00146 00147 /******************************************************************************************** 00148 00149 > class GenerateIndexFile : public CCObject 00150 00151 Author: Richard_Millican (Xara Group Ltd) <camelotdev@xara.com> 00152 Created: 09/04/95 00153 Purpose: For generating of index files 00154 00155 ********************************************************************************************/ 00156 00157 class GenerateIndexFile : public CCObject 00158 { 00159 CC_DECLARE_DYNCREATE( GenerateIndexFile ) 00160 00161 public: 00162 00163 // Constructor 00164 GenerateIndexFile(); 00165 00166 // Destructor 00167 ~GenerateIndexFile() {} 00168 00169 // Actually generate the index 00170 BOOL Generate(PathName *IndexFile, PathName *LibDirPath, String_64 *Author, 00171 SGLibType Type, BOOL Thumbnails); 00172 00173 protected: 00174 00175 // Close the search handle 00176 BOOL CloseSearchHandle(void); 00177 00178 // Close the file handle 00179 BOOL CloseIndexFileHandle(void); 00180 00181 // Create the index file and keywords file then add headers to them 00182 BOOL CreateIndexFile(void); 00183 00184 // Count the number of files that will be added to the index file in the directory 00185 INT32 CountValidFiles(void); 00186 00187 // If the normal place for the index is read only, sir might consider a more remote location, oui ? 00188 BOOL RemoteIndexSetup(PathName *FilesPath); 00189 00190 // Check if the given index has a remote pointer, and return the location if it has 00191 BOOL CheckExistingIndexForRemoteness(PathName *IndexFile, PathName *FilesPath); 00192 00193 public: 00194 00195 // Returns true if the directory is read only 00196 static BOOL IsDirectoryReadOnly(PathName *Directory); 00197 00198 // Check to see if we've already got a remote directory for a FilesDirectory, or at 00199 // least return the location for the remote directory 00200 static BOOL CheckForRemote(PathName *FilesDirectory, String_256 *RemoteDirectory); 00201 00202 // Given a random collection of garbage as an input string, return a valid directory path on output 00203 static BOOL GiveMeAValidDirectoryName(String_256 *Input, String_256 *Output); 00204 00205 protected: 00206 00207 // Add all the header data to an index file 00208 BOOL DoIndexHeader(void); 00209 00210 // Scan the directory for files and add them to the index file 00211 BOOL AddToSubLibrary(void); 00212 00213 // Poke the count field with the correct value 00214 BOOL FixSubLibraryNumber(void); 00215 00216 protected: 00217 00218 // Add a file to the index 00219 BOOL AddFile(PathName *FileName); 00220 00221 // Return true if a file should be associated with the index 00222 static BOOL IsFileType(PathName *FileName, const SGLibType Type); 00223 00224 protected: 00225 // Get a 16bit value from the file 00226 INT16 GetShort(FILE *fp); 00227 00228 // Return the integer part of a 16.16 fixed only 00229 INT16 GetFixed(FILE *fp); 00230 00231 // Return a full 32 bit number from a file 00232 INT32 GetLONG(FILE *fp); 00233 00234 // Rip out the full TTF typeface name from a font file 00235 BOOL RipTrueTypeNameFromFile(PathName *FileName, String_256 *Name); 00236 00237 // Rip out the full ATM typeface and styles from a font file 00238 BOOL RipATMNameFromFile(PathName *FileName, String_256 *RetName, BOOL *Bold, BOOL *Italic); 00239 00240 protected: 00241 // This will check that creating the thumbnail won't cause us to go BANG ! 00242 static BOOL PreCreateThumbnail(PathName *InFile); 00243 00244 // Given an input filename and output filename, generate a thumbnail of specified dimensions 00245 BOOL CreateThumbnail(PathName *InFile, PathName *OutFile, UINT16 XSize, UINT16 YSize); 00246 00247 /* Create the thumbnails for the specified file */ 00248 BOOL CreateThumbnails(PathName *FileName, BOOL NewSystem = TRUE); 00249 00250 protected: 00251 00252 // Scan the given file and try and work out a description and keywords for it 00253 BOOL RipDescriptionFromFile(PathName *FileName, 00254 String_256 *Text, String_256 *Keywords = NULL, String_256 *Title = NULL); 00255 00256 // Try and work out a description and keywords given an EPS/ART filename (uses comments in file) 00257 BOOL RipDescriptionFromEPSFile(PathName *FileName, 00258 String_256 *Text, String_256 *Keywords = NULL, String_256 *Title = NULL); 00259 00260 // Try and work out a description and keywords given a CDR filename 00261 BOOL RipDescriptionFromCDRFile(PathName *FileName, 00262 String_256 *Text, String_256 *Keywords = NULL, String_256 *Title = NULL); 00263 00264 // Try and work out a description and keywords given a version 2 native/web filename 00265 BOOL RipDescriptionFromNativeV2File(PathName *FileName, 00266 String_256 *Text, String_256 *Keywords = NULL, String_256 *Title = NULL, 00267 BOOL *FileIsNewNative = NULL); 00268 00269 00270 // Scan an old index file looking for the description of the given filename 00271 BOOL RipDescriptionFromIndex(PathName *IndexFile, PathName *FileName, 00272 FilePos Start, INT32 DescriptionField, INT32 KeywordField, INT32 TitleField, 00273 String_256 *Text, String_256 *Keywords = NULL, String_256 *Title = NULL); 00274 00275 BOOL PrePassIndex(PathName *IndexFile, FilePos *Start, 00276 INT32 *DescriptionField, INT32 *KeywordField, INT32 *TitleField, String_256 *Description); 00277 00278 public: 00279 // General utilities for the ripping functions 00280 static BOOL ReplaceCharacters(StringBase *Source, TCHAR Search, TCHAR Replace); 00281 static INT32 CountCommas(StringBase *Source, StringBase &SearchFor); 00282 static BOOL GetToken(StringBase *Source, INT32 Count, String_256 *Result); 00283 00284 protected: 00285 // Adds the given text to the index file 00286 BOOL AddLineToIndex(String_256 *Text); 00287 00288 protected: 00289 PathName Index; 00290 PathName LibPath; 00291 SGLibType LibType; 00292 BOOL DoThumbnails; 00293 String_64 Author; 00294 00295 // Disk file for index file 00296 CCDiskFile *IndexFile; 00297 00298 // Offset into index for the 'Number of files' data 00299 FilePos IndexCountOff; 00300 00301 // Search handle for directory scan 00302 HANDLE hSearch; 00303 00304 // ID of current item and number of items in file 00305 UINT32 ID; 00306 00307 // Pre-counted number of files to add to index 00308 INT32 TotalFiles; 00309 00310 // Location of old index file (if there was one) 00311 PathName *TmpIndexFile; 00312 00313 // Sorted buffer containing all the filenames in the directory 00314 // ( Initialised by CountValidFiles() ) 00315 IndGenFileBuffer FileNameBuffer; 00316 00317 // Vars to speed up ripping old data from existing indexes 00318 FilePos OldIndexStart; 00319 INT32 OldIndexDescriptionField; 00320 INT32 OldIndexKeywordField; 00321 INT32 OldIndexTitleField; 00322 BOOL OldIndexOK; 00323 String_256 OldIndexDescription; 00324 00325 // Remote indexes 00326 BOOL IndexIsRemote; 00327 String_256 RemoteLocationOfIndex; 00328 String_256 RemoteLocationOfFiles; 00329 00330 00331 // Automatic index update functions 00332 public: 00333 static UINT32 GetDirectoryChecksum(String_256 *Directory, SGLibType Type = SGLib_Blank); 00334 static BOOL UseAutomaticUpdate; 00335 00336 public: 00337 // Preference setting saying whether thumbnail generation is required 00338 static BOOL CreateFontIndexes; 00339 00340 // Preferences to use old index files / rip doc comments out 00341 static BOOL UseOldIndexes; 00342 static BOOL UseDocComments; 00343 00344 }; 00345 00346 #endif