Library Class Reference

This is the main super gallery library group creation class... Creating one of these will create a single group in your gallery. It will contain items for each entry in the sub-lib. More...

#include <sgscan.h>

Inheritance diagram for Library:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 Library ()
 Constructor.
 ~Library ()
 Time to die...
INT32 Init (SuperGallery *ParentGal, PathName *Path, String_64 *Title, StringBase *IndexFile, SGLibType Type, BOOL Updated=FALSE, BOOL AllowedToCreateVirtualised=FALSE)
 Given a specified sublibrary index, scan it and create a supergallery display group for it, containing display items for all of the items in the index.
INT32 CreateItems (void)
 Mainly for use by the de-virtualise function... Init MUST have been called previously for this to work !
void GetLibraryTitle (StringBase *ReturnedTitle)
 To retrieve the title text for this library (this is the text that a linked SGDisplayGroup will display in the gallery list as in "Pictures of animals").
UINT32 GetModified ()
void SetModified (UINT32 nModified)
SGLibType GetType ()
BOOL GetFilename (LibraryIndex Offset, StringBase *File, BOOL FullPath=TRUE)
 Return the path/filename for the indexed library item.
BOOL GetFilename (LibraryIndex Offset, TCHAR **File)
 Return a pointer to the filename for the indexed library item.
BOOL GetTextname (LibraryIndex Offset, StringBase *Text)
 Return the textual description for the indexed library item.
BOOL GetTextname (LibraryIndex Offset, TCHAR **Text)
 Return a pointer to the textual description for the indexed library item.
UINT32 GetID (LibraryIndex Offset)
 Return the ID for the indexed library item Returns 0 if there was a problem (0 is an invalid ID).
BOOL GetTitle (LibraryIndex Offset, StringBase *Title)
 Return the 'title' for the indexed library item (if there is one).
BOOL GetTitle (LibraryIndex Offset, TCHAR **Title)
 Return a pointer to the title for the indexed library item.
BOOL GetThumbnail (LibraryIndex Offset, SGThumbSize Size, BOOL Urgent, KernelBitmap **Thumbnail)
 Return a pointer to the thumbnail for the given library index.
void KillAllThumbnails (void)
 Deletes all thumbnails from cache.
INT32 PreviewBMPWidth (SGThumbSize Size)
INT32 PreviewBMPHeight (SGThumbSize Size)
PathNameReturnIndexLocation (void)
PathNameReturnSubLibraryLocation (void)
PathNameReturnSynonymFile (void)
BOOL LocalPath2URL (String_256 *pLocalPath)
 converts a local path to a URL, using the base URL read from the library index file The URL can be used to download the file
BOOL GetSingleField (LibraryIndex Offset, UINT32 Count, StringBase *Field)
 Return a single field for a given library item Use this for extended info.
BOOL GetSingleField (LibraryIndex Offset, UINT32 Count, TCHAR **Field)
 Return a single field for a given library item Use this for extended info.
BOOL GetSingleField (LibraryIndex Offset, String_64 *FieldName, StringBase *Field)
 Return a single field for a given library item and field description Use this for extended info.
BOOL GetSingleField (LibraryIndex Offset, String_64 *FieldName, TCHAR **Field)
 Get a pointer to a single field for a given library item and field description using the extended info.
INT32 FindField (String_64 *FieldName)
 Works out the column for the given field string.
BOOL GotField (String_64 *FieldName)
 Check if a string is in the field description string...
BOOL IsWebLibrary ()
BOOL SaveIndexInDisplayedOrder (PathName *IndexFile, BOOL NewIDs)
 Save out an index file in the order the group is displayed (possibly sorted !) Notes: This is strictly a debug only function !
BOOL FreeCachedIndexes ()
 Free some memory when we close a gallery by freeing all the cached index files...
BOOL ReCacheIndexes ()
 Re-caches the indexes when opening a gallery...

Static Public Member Functions

static BOOL InitLibPrefs (void)
 Initialises the preferences in the ini file and returns the values of the entries if they're there already.
static BOOL CacheLibPrefs (void)
 Called during preference wiping to allow us to squirrel away any settings that we desire before they are wiped. This is useful if we want to retain newly installed preferences that the installer has deliberately put there! E.g the paths to the clipart etc on the CD.
static BOOL RestoreLibPrefs (void)
 Called during preference wiping to allow us to squirrel away any settings that we desire before they are wiped. This is useful if we want to retain newly installed preferences that the installer has deliberately put there! E.g the paths to the clipart etc on the CD.

Public Attributes

BOOL m_bIsWebLib
String_64Title
PathNameIndexFile
PathNameSubLibPath
PathNameSynonymFile
SuperGalleryParentGallery
SGLibGroupParentGroup
SGThumbs * Thumbnails

Static Public Attributes

static String_256 URLBase = _T("")
static ProgressProgressBar = NULL
static INT32 MaxFieldCacheEntries = 25
static BOOL BackgroundRedraw = TRUE
static BOOL CacheIndexFile = TRUE
static BOOL RemoteIndexes = TRUE
static String_256 RemoteIndexLocation = ""
static BOOL QuickIndex = TRUE

Protected Member Functions

BOOL CacheSubIndex (PathName *IndexFile)
 Creates a CCMemTextFile with the given file in, and opens it. The idea being that reading from a file in memory will be quicker than off a very slow single speed CD ROM drive.
BOOL ScanRestOfFile (TCHAR *CachedIndex, INT32 Start, INT32 Finish, BOOL AddItems=TRUE)
 Scan the rest of the file (following the START), creating items for each entry... Also change ','s to 0's, so we can retrieve field strings more quickly later on.
BOOL GetSingleFieldFromMemory (LibraryIndex Offset, UINT32 Count, StringBase *Field)
 Return a single field for a given library item using the 0 padded, cached index file in memory.
BOOL GetSingleFieldFromMemory (LibraryIndex Offset, UINT32 Count, TCHAR **Field)
 Return a pointer to a single field for a given library item using the 0 padded, cached index file in memory.
BOOL GetSingleFieldFromDisk (LibraryIndex Offset, UINT32 Count, StringBase *Field)
 Return a single field for a given library item using a diskfile for the index.
BOOL CacheInit (INT32 Entries)
 Initialises memory for a sub-index file field cache. Currently we use a single entry wide hash table with the specified number of buckets. Reading items from the cache is much quicker than from the index file itself, be it in memory or not ! (Well, that's the theory).
BOOL CacheKill (void)
 Reclaims all the memory used by the field cache.
INT32 CacheHashFunction (LibraryIndex Offset, UINT32 Count)
 Returns an index into the hash table for the given parameters. The simpler, the quicker, but probably the less efficient.
BOOL CachePut (LibraryIndex Offset, UINT32 Count, StringBase *Field)
 Adds an item into the cache for returning later on with CacheGet.
BOOL CacheGet (LibraryIndex Offset, UINT32 Count, StringBase *Field)
 Checks if an item is in the cache. If it is, return it.

Protected Attributes

SGLibType Type
INT32 ItemCount
String_256 FieldString
LibraryIndex FirstLineOffset
LibraryIndex LastLineOffset
INT32 PreviewX [3]
INT32 PreviewY [3]
UINT32 IndexDateStamp
UINT32 m_nModified
INT32 m_lOldIndex
TCHARCachedSubIndexBuf
INT32 CachedBufLength
INT32 FieldCacheEntries
SGFieldCacheFieldCache
BOOL QuickIndexEnabled
PathNameQuickIndexFile

Private Member Functions

BOOL SetUpMembers (SuperGallery *ParentGal, PathName *Path, String_64 *SLTitle, StringBase *SubI, SGLibType SLType)
 Fill in the member variables with the required paths, and things... Should only be called from Init.
BOOL SetupQuickIndexMembers (PathName *Path, BOOL CheckTheyExist)
 Given a normal index file path, set up members to a 'quick index file'. The idea is for groups of library directories to have copies of all their indexes in some common folder so that loading them in doesn't thrash the CD drive too much.
INT32 ReadHeaderInfo (CCLexFile *pSubIndex)
 Read the no of items, field text and line pSubIndex up with the first proper index line.
BOOL ScanRestOfFile (CCLexFile *pSubIndex)
 Scan the rest of the file (following the START), creating items for each entry...

Static Private Attributes

static String_256 g_ClipartLibraryPath = TEXT("")
static String_256 g_WebThemeLibraryPath = TEXT("")
static String_256 g_FontLibraryPath = TEXT("")
static String_256 g_FillsLibraryPath = TEXT("")

Friends

class LibClipartSGallery
class LibraryGallery

Detailed Description

This is the main super gallery library group creation class... Creating one of these will create a single group in your gallery. It will contain items for each entry in the sub-lib.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
See also:
LibraryFile;

Definition at line 139 of file sgscan.h.


Constructor & Destructor Documentation

Library::Library  ) 
 

Constructor.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/2/95

Definition at line 196 of file sgscan.cpp.

00197 {
00198     ParentGallery = NULL;
00199     ParentGroup = NULL;
00200 
00201     Title = NULL;
00202     IndexFile = NULL;
00203     Thumbnails = NULL;
00204     SubLibPath = NULL;
00205     SynonymFile = NULL;
00206                         
00207     ItemCount = 0;
00208     Type = SGLib_Blank;
00209 
00210     FirstLineOffset = LastLineOffset = 0;
00211 
00212     for(INT32 i=0; i<3; i++)
00213     {
00214         PreviewX[i] = 64;                       // Widths of thumbnails
00215         PreviewY[i] = 64;                       // Heights of thumbnails
00216     }
00217 
00218     // Add in a field cache for the library
00219 #ifdef FIELDCACHE
00220     FieldCache = NULL;
00221     CacheInit(MaxFieldCacheEntries);
00222 #endif
00223     
00224     // No sub index cached yet...
00225     //CachedSubIndex = NULL;
00226     CachedSubIndexBuf = NULL;
00227     CachedBufLength = 0;
00228 
00229     // Datestamp of last index cached
00230     IndexDateStamp = 0;
00231 
00232     // Quick Index stuff...
00233     QuickIndexEnabled = FALSE;
00234     QuickIndexFile = NULL;
00235 
00236     // Progress bar stuff
00237     ProgressBar = NULL;
00238     //>> webster (Adrian 02/01/97)
00239     m_nModified = 0;
00240     m_bIsWebLib = FALSE;
00241     m_lOldIndex = 0;
00242     //<< webster
00243 }

Library::~Library  ) 
 

Time to die...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95

Definition at line 258 of file sgscan.cpp.

00259 {
00260     TRACEUSER( "Richard", _T("~Library called\n"));
00261 
00262     // Ensure our parent gallery is no longer displaying us
00263     if (ParentGallery != NULL)
00264     {
00265         ParentGallery->RemoveLibraryGroup(this);
00266         ParentGallery = NULL;
00267     }
00268 
00269     if(Title != NULL)
00270     {
00271         delete Title;
00272         Title = NULL;
00273     }
00274 
00275     if(IndexFile != NULL)
00276     {
00277         delete IndexFile;
00278         IndexFile = NULL;
00279     }
00280 
00281     if(Thumbnails != NULL)
00282     {
00283         delete Thumbnails;
00284         Thumbnails = NULL;
00285     }
00286     
00287     if(SubLibPath != NULL)
00288     {
00289         delete SubLibPath;
00290         SubLibPath = NULL;
00291     }
00292 
00293     if(SynonymFile != NULL)
00294     {
00295         delete SynonymFile;
00296         SynonymFile = NULL;
00297     }
00298 
00299     // Reclaim field cache memory                       
00300 #ifdef FIELDCACHE
00301     CacheKill();
00302 #endif
00303 
00304     // Free the CachedSubIndex file buffer
00305     if(CachedSubIndexBuf != NULL)
00306     {
00307         CCFree((void *)CachedSubIndexBuf);
00308         CachedSubIndexBuf = NULL;
00309     }
00310 
00311     CachedBufLength = 0;
00312 
00313 
00314     // And reclaim all memory used by the cached subindex itself
00315 //  if(CachedSubIndex != NULL)
00316 //  {
00317 //      CachedSubIndex->DeinitLexer();  
00318 //      if(CachedSubIndex->isOpen())
00319 //          CachedSubIndex->close();
00320 //      delete CachedSubIndex;
00321 //  }
00322 
00323 
00324     if(QuickIndexFile != NULL)
00325         delete QuickIndexFile;
00326 }


Member Function Documentation

BOOL Library::CacheGet LibraryIndex  Offset,
UINT32  Count,
StringBase Field
[protected]
 

Checks if an item is in the cache. If it is, return it.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
Offset - this is the file offset of the start of the relevant line [INPUTS] Count - Field count
Field - The resulting field [OUTPUTS]
Returns:
TRUE if the item was there

Definition at line 2625 of file sgscan.cpp.

02626 {
02627 #if 0
02628     // Check the FieldCache occupancy
02629     if(FieldCache != NULL)
02630     {       
02631         INT32 Occupancy = 0;
02632         for(INT32 i=0; i<FieldCacheEntries; i++)
02633         {
02634             if(FieldCache[i].Field != NULL) Occupancy++;
02635         }
02636         TRACEUSER( "Richard", _T("Hash usage %d out of %d - %d%%\n"), Occupancy, FieldCacheEntries, (100 * Occupancy / FieldCacheEntries));
02637     }
02638 #endif
02639         
02640     // See if our entry is in the cache
02641     SGFieldCache OurEntry;
02642     if(FieldCache != NULL)
02643     {       
02644         OurEntry = FieldCache[CacheHashFunction(Offset, Count)];
02645     
02646         if(OurEntry.Offset == Offset && OurEntry.Count == Count && OurEntry.Field != NULL)
02647         {
02648             String_256 tmpstr(OurEntry.Field);
02649             *Field = tmpstr;
02650             return TRUE;
02651         }
02652     }
02653 
02654     //TRACEUSER( "Richard", _T("Field not in cache..."));
02655     
02656     return FALSE;
02657 }

INT32 Library::CacheHashFunction LibraryIndex  Offset,
UINT32  Count
[protected]
 

Returns an index into the hash table for the given parameters. The simpler, the quicker, but probably the less efficient.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
Offset - this is the file offset of the start of the relevant line [INPUTS] Count - Field count
[OUTPUTS] 
Returns:
Index into the hash table
Notes: I've had a play around with this function, and due to the random nature of the index files, can't really improve on the below all that much. Since the below is so quick, this is where it's been left.

Definition at line 2550 of file sgscan.cpp.

02551 {
02552     return ((Count + Offset) % FieldCacheEntries);
02553 }

BOOL Library::CacheInit INT32  Entries  )  [protected]
 

Initialises memory for a sub-index file field cache. Currently we use a single entry wide hash table with the specified number of buckets. Reading items from the cache is much quicker than from the index file itself, be it in memory or not ! (Well, that's the theory).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
Entries - The maximum number of entries in the field cache [INPUTS]
[OUTPUTS] 
Returns:
FALSE if it fails;

Definition at line 2459 of file sgscan.cpp.

02460 {
02461     if(Entries == 0)
02462         FieldCache = NULL;
02463     else
02464         if(FieldCache == NULL)
02465             FieldCache = (SGFieldCache *)CCMalloc(sizeof(SGFieldCache) * Entries);
02466         
02467     if(FieldCache == NULL)
02468     {
02469         FieldCacheEntries = 0;
02470         ERROR3("Library::CacheInit - Not enough memory for a field cache - reduce the Fields in the ini file");
02471         return FALSE;
02472     }
02473     else
02474     {
02475         FieldCacheEntries = Entries;
02476 
02477         SGFieldCache Dummy;
02478         Dummy.Offset = 0;
02479         Dummy.Count = 0;
02480         Dummy.Field = NULL;
02481 
02482         for(INT32 i=0; i<Entries; i++)
02483         {
02484             FieldCache[i] = Dummy;
02485         }
02486     }
02487     return TRUE;
02488 }

BOOL Library::CacheKill void   )  [protected]
 

Reclaims all the memory used by the field cache.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:
FALSE if it fails;

Definition at line 2506 of file sgscan.cpp.

02507 {
02508     TRACEUSER( "Richard", _T("Cache Kill\n"));
02509 
02510     if(FieldCache != NULL)
02511     {
02512         for(INT32 i=0; i<FieldCacheEntries; i++)
02513         {
02514             if(FieldCache[i].Field != NULL)
02515             {
02516                 CCFree(FieldCache[i].Field);
02517                 FieldCache[i].Field = NULL;
02518             }
02519         }
02520         FieldCacheEntries = 0;
02521 
02522         CCFree(FieldCache);
02523         FieldCache = NULL;
02524     }
02525 
02526     return TRUE;
02527 }

BOOL Library::CacheLibPrefs void   )  [static]
 

Called during preference wiping to allow us to squirrel away any settings that we desire before they are wiped. This is useful if we want to retain newly installed preferences that the installer has deliberately put there! E.g the paths to the clipart etc on the CD.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/97
Returns:
FALSE if it fails; TRUE if we everything went ok

Definition at line 2906 of file sgscan.cpp.

02907 {
02908     // Save away the current values stored in the preferences
02909     // Must read the values directly from the preferences as our preference variables will
02910     // not have been set up yet!
02911     Camelot.GetPrefDirect(TEXT("Libraries"), TEXT("ClipArt"),   &g_ClipartLibraryPath);
02912     Camelot.GetPrefDirect(TEXT("Libraries"), TEXT("WebTheme"),  &g_WebThemeLibraryPath);
02913     Camelot.GetPrefDirect(TEXT("Libraries"), TEXT("Font"),      &g_FontLibraryPath);
02914     Camelot.GetPrefDirect(TEXT("Libraries"), TEXT("Texture"),   &g_FillsLibraryPath);
02915 
02916     //g_ClipartLibraryPath  = LibClipartSGallery::DefaultLibraryPath;
02917     //g_FontLibraryPath     = FontsSGallery::DefaultLibraryPath;
02918     //g_FillsLibraryPath        = LibFillsSGallery::DefaultLibraryPath;
02919     
02920     return TRUE;
02921 }

BOOL Library::CachePut LibraryIndex  Offset,
UINT32  Count,
StringBase Field
[protected]
 

Adds an item into the cache for returning later on with CacheGet.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
Offset - this is the file offset of the start of the relevant line [INPUTS] Count - Field count Field - The field string to put in the cache
[OUTPUTS] 
Returns:
TRUE if we allocated the memory, etc...

Definition at line 2572 of file sgscan.cpp.

02573 {
02574     TRACEUSER( "Richard", _T("Cache Put\n"));
02575 
02576     // Put the field in the field buffer / line cache, etc...
02577     if(FieldCache != NULL)
02578     {       
02579         SGFieldCache OurEntry;
02580         OurEntry.Offset = Offset;
02581         OurEntry.Count = Count;
02582         OurEntry.Field = (TCHAR *)CCMalloc((Field->Length()+1) * sizeof(TCHAR));
02583         if(OurEntry.Field == NULL)
02584         {
02585             ERROR3("Library::GetSingleField can't allocate enough string space in field buffer");
02586             return FALSE;
02587         }
02588         else
02589         {
02590             camStrcpy(OurEntry.Field, (TCHAR *)*Field);
02591         }
02592     
02593         SGFieldCache *plc = &FieldCache[CacheHashFunction(Offset, Count)];
02594         
02595         if(plc->Field != NULL)
02596         {
02597             CCFree(plc->Field);
02598             plc->Field = NULL;
02599             //TRACEUSER( "Richard", _T("Hash Clash at %d\n"), CacheHashFunction(Offset, Count));
02600         }
02601     
02602         *plc = OurEntry;
02603 
02604         return TRUE;
02605     }
02606     return FALSE;
02607 }

BOOL Library::CacheSubIndex PathName IndexFile  )  [protected]
 

Creates a CCMemTextFile with the given file in, and opens it. The idea being that reading from a file in memory will be quicker than off a very slow single speed CD ROM drive.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/4/95
Parameters:
IndexFile - Pathname of index file which we want to cache as a memfile [INPUTS]
[OUTPUTS] 
Returns:
TRUE if the file was successfully cached and opened
Notes: There are three ways of getting at the information in the library sub index at the moment, a field cache, this index file cache and then lexing over the diskfile itself. Obviously the first two are the most desirable, but take memory up. The field cache we use is fairly good, once the items have been read. This initial reading of the items is the slow bit, so that's why we've got the option to cache the entire index file in memory as well.

See also:
Library::GetSingleField, Library::Init

Definition at line 440 of file sgscan.cpp.

00441 {
00442     BOOL OpenedOK = FALSE;
00443 
00444     // Doesn't bother with modified calls anymore, uses file size...
00445     INT32 NewFileSize = 0;
00446     
00447     if(QuickIndexEnabled)
00448         NewFileSize = SGLibOil::FileSize(QuickIndexFile);
00449     else
00450         NewFileSize = SGLibOil::FileSize(IndexFile);
00451 
00452     if(NewFileSize == 0)
00453         return FALSE;
00454 
00455     if(IndexDateStamp != 0 && IndexDateStamp != (UINT32)NewFileSize)
00456         return FALSE;
00457     IndexDateStamp = (UINT32)NewFileSize;
00458 
00459     CachedBufLength = NewFileSize;
00460     CachedSubIndexBuf = (TCHAR *)CCMalloc(CachedBufLength + 4);
00461 
00462     if(CachedSubIndexBuf != NULL)
00463     {
00464         CCDiskFile TmpDiskFile;
00465         TRY
00466         {
00467             if(QuickIndexEnabled)
00468                 OpenedOK = TmpDiskFile.open(*QuickIndexFile, ios::in);
00469             else
00470                 OpenedOK = TmpDiskFile.open(*IndexFile, ios::in);
00471 
00472             if(!OpenedOK)
00473             {
00474                 ERROR3("Couldn't open disk file for mem file");
00475                 if(CachedSubIndexBuf != NULL)
00476                     CCFree(CachedSubIndexBuf);
00477                 CachedSubIndexBuf = NULL;
00478                 CachedBufLength = 0;
00479                 return FALSE;
00480             }
00481 
00482             TmpDiskFile.read(CachedSubIndexBuf, CachedBufLength);       
00483             TmpDiskFile.close();
00484         }
00485         CATCH(CFileException, e)
00486         {   
00487             if(CachedSubIndexBuf != NULL)
00488                 CCFree(CachedSubIndexBuf);
00489             CachedSubIndexBuf = NULL;
00490             CachedBufLength = 0;
00491             if(TmpDiskFile.isOpen())
00492                 TmpDiskFile.close();
00493             return FALSE;
00494         }
00495         END_CATCH
00496     }
00497     else
00498     {
00499         CachedBufLength = 0;
00500         ERROR3("Couldn't allocate space for cached subindex file");
00501         return FALSE;
00502     }
00503     return TRUE;
00504 /* FIX */
00505 }

INT32 Library::CreateItems void   ) 
 

Mainly for use by the de-virtualise function... Init MUST have been called previously for this to work !

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/1/96
Returns:
0 if an error occurred, else a count of the items added
Notes: If you want the Quiet button code to work you need to call LibraryGallery->SetQuietStatus(FALSE); before calling this. Note that a large stream of new additions should call this just once for the first item. If you don't do this you won't get retry capability if the user's CD isn't in the drive...

Definition at line 832 of file sgscan.cpp.

00833 {
00834     // Don't do this it the group isn't v'd out
00835     if(ParentGroup != NULL && ParentGroup->IsVirtualised())
00836     {
00837         String_256 SubI;
00838         SubI = IndexFile->GetFileName();
00839         PathName pathOldIndex(IndexFile->GetPath());
00840         pathOldIndex.SetType(_T("old"));
00841         INT32 hOldIndex = _open(pathOldIndex.GetPath(), _O_RDONLY | _O_BINARY, _S_IREAD);
00842         if (hOldIndex != -1)
00843         {
00844             m_lOldIndex = _filelength(hOldIndex);
00845             _close(hOldIndex);
00846         }
00847         INT32 ItemCount = Init(ParentGallery, SubLibPath, Title, &SubI, Type);
00848         return ItemCount;
00849     }
00850 
00851     return 0;
00852 }

INT32 Library::FindField String_64 FieldName  ) 
 

Works out the column for the given field string.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/5/95
Parameters:
FieldName - Field to look for [INPUTS]
Returns:
Position of field - so for 'ID' we would return 3, etc...

Definition at line 2390 of file sgscan.cpp.

02391 {
02392     ERROR3IF(FieldName == NULL, "Library::FindField given nulls");
02393 
02394     INT32 Pos = FieldString.Sub(*FieldName);
02395     
02396     if(Pos != -1)
02397     {
02398         // Find out which field it was
02399         String_256 Left;
02400         FieldString.Left(&Left, Pos);
02401         const TCHAR BrkChar = ',';
02402 
02403         // This bit could go in basestr...      
02404         INT32 Count = 0;
02405         TCHAR *Buf = (TCHAR *)Left;
02406         INT32 Len = Left.Length();
02407         for(INT32 i = 0; i < Len; i++)
02408             if(Buf[i] == BrkChar)
02409                 Count ++;
02410 
02411         // Number of commas + 1 is our field
02412         Count ++;
02413 
02414         return Count;
02415     }
02416 
02417     return 0;
02418 }

BOOL Library::FreeCachedIndexes void   ) 
 

Free some memory when we close a gallery by freeing all the cached index files...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/6/95
Returns:
TRUE if succesful and previously cached indexes are no more...

Definition at line 342 of file sgscan.cpp.

00343 {
00344     // Reclaim field cache memory
00345 #ifdef FIELDCACHE
00346     CacheKill();
00347 #endif
00348 
00349     // Free the CachedSubIndex file buffer
00350     if(CachedSubIndexBuf != NULL)
00351     {
00352         CCFree((void *)CachedSubIndexBuf);
00353         CachedSubIndexBuf = NULL;
00354         CachedBufLength = 0;
00355         return TRUE;
00356     }
00357 
00358     return FALSE;
00359 }

BOOL Library::GetFilename LibraryIndex  Offset,
TCHAR **  File
 

Return a pointer to the filename for the indexed library item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
Offset - the index identifying the item you require [INPUTS] File - A pointer to a path name to be filled in (May NOT be NULL)
Returns:
TRUE if it succeeded
Notes: If we're using diskfiles this will return FALSE

Definition at line 1606 of file sgscan.cpp.

01607 {
01608     ERROR3IF(File == NULL, "Library::GetFilename - NULL params are illegal");
01609 
01610     // Get filename from index file
01611     return (GetSingleField(Offset, 1, File));
01612 }

BOOL Library::GetFilename LibraryIndex  Offset,
StringBase File,
BOOL  FullPath = TRUE
 

Return the path/filename for the indexed library item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - the index identifying the item you require [INPUTS] FullPath - If TRUE, return the full path of the file, otherwise just the filename
File - filled in path/file name [OUTPUTS]
Returns:
TRUE if it succeeded
Notes: File is now a stringbase for speed reasons. Constructing a full PathName was found to be quite slow, and hindered sorting quite a bit. The FullPath param is also included for this purpose.

Definition at line 1563 of file sgscan.cpp.

01564 {
01565     ERROR3IF(File == NULL, "Library::GetFilename - NULL params are illegal");
01566 
01567     if(!FullPath)
01568     {
01569         // Get filename from index file
01570         return (GetSingleField(Offset, 1, File));
01571     }
01572 
01573     String_256 Filename;
01574 
01575     // Get filename from index file
01576     if (!GetSingleField(Offset, 1, &Filename))
01577         return FALSE;
01578 
01579     // Path for normal files
01580     *File = SubLibPath->GetPath(TRUE);
01581     *File += Filename;
01582     
01583     return TRUE;
01584 }

UINT32 Library::GetID LibraryIndex  Offset  ) 
 

Return the ID for the indexed library item Returns 0 if there was a problem (0 is an invalid ID).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - The library index identifying the item you want [INPUTS]

Definition at line 1671 of file sgscan.cpp.

01672 {
01673     String_8 Tmp;
01674     if (!GetSingleField(Offset, 3, &Tmp))
01675         return(0);
01676 
01677     return((UINT32) _ttoi((TCHAR *)Tmp));
01678 }

void Library::GetLibraryTitle StringBase ReturnedTitle  ) 
 

To retrieve the title text for this library (this is the text that a linked SGDisplayGroup will display in the gallery list as in "Pictures of animals").

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/2/95
Parameters:
ReturnedTitle - will be filled in with the title (may NOT be NULL) [OUTPUTS]

Definition at line 1529 of file sgscan.cpp.

01530 {
01531     ERROR3IF(ReturnedTitle == NULL, "Library::GetLIbraryTitle - NULL Params are illegal");
01532 
01533     if (Title == NULL)
01534         *ReturnedTitle = String_16(_R(IDS_LIBRARIES_UNAMED));
01535     else
01536         *ReturnedTitle = *Title;
01537 }

UINT32 Library::GetModified  )  [inline]
 

Definition at line 199 of file sgscan.h.

00199 { return m_nModified;}

BOOL Library::GetSingleField LibraryIndex  Offset,
String_64 FieldName,
TCHAR **  Field
 

Get a pointer to a single field for a given library item and field description using the extended info.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/3/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] FieldName - Name of field we require (must be in field header)
Field - will be pointed to the field contents (if index cached). [OUTPUTS]
Returns:
FALSE if it fails;
Notes: The above code assumes that the first three fields are always: Filename, Description, ID

After that we've got things like 'Key', 'Size', 'Title' which we check the positions of using this string...

If the index isn't in memory we can't return the pointer !

Definition at line 2363 of file sgscan.cpp.

02364 {
02365     ERROR3IF(FieldName == NULL || Field == NULL, "Library::GetSingleField given nulls");
02366 
02367     if(!GotField(FieldName))
02368         return FALSE;
02369 
02370     INT32 Count = FindField(FieldName);
02371 
02372     return (Count > 0 && GetSingleField(Offset, Count, Field));
02373 }

BOOL Library::GetSingleField LibraryIndex  Offset,
String_64 FieldName,
StringBase Field
 

Return a single field for a given library item and field description Use this for extended info.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/3/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] FieldName - Name of field we require (must be in field header)
Field - will be filled in with the field contents. [OUTPUTS]
Returns:
FALSE if it fails;
Notes: The above code assumes that the first three fields are always: Filename, Description, ID

We've now got 'Title' as a fourth, but only if it's in the field description...

After that we've got things like 'Key' and 'Size' which we check the positions of using this string...

Definition at line 2321 of file sgscan.cpp.

02322 {
02323     ERROR3IF(FieldName == NULL || Field == NULL, "Library::GetSingleField given nulls");
02324 
02325     if(!GotField(FieldName))
02326     {
02327         *Field = TEXT("");
02328         return FALSE;
02329     }
02330 
02331     INT32 Count = FindField(FieldName);
02332 
02333     return (Count > 0 && GetSingleField(Offset, Count, Field));
02334 }

BOOL Library::GetSingleField LibraryIndex  Offset,
UINT32  Count,
TCHAR **  Field
 

Return a single field for a given library item Use this for extended info.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] Count - Identifies which field toi retrieve from the line of index information for this item.
Field will point to the field contents. [OUTPUTS]
Returns:
FALSE if it fails;
Notes: If using disk files we currently return false, this means you should always use the string copying one above if this returns false, etc...

Definition at line 1969 of file sgscan.cpp.

01970 {
01971     ERROR3IF(Field == NULL, "Library::GetSingleField - NULL Params are illegal");
01972 
01973     // Extract the entry from the index file
01974     BOOL GotField = FALSE;
01975 
01976     // Check if we've got a cached version of the index
01977     if(CachedSubIndexBuf != NULL)
01978     {
01979         // This will call the TCHAR ** version, not the stringbase version
01980         GotField = GetSingleFieldFromMemory(Offset, Count, Field);
01981     }
01982     
01983     return GotField;
01984 }

BOOL Library::GetSingleField LibraryIndex  Offset,
UINT32  Count,
StringBase Field
 

Return a single field for a given library item Use this for extended info.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] Count - Identifies which field toi retrieve from the line of index information for this item.
Field will be filled in with the field contents. [OUTPUTS]
Returns:
FALSE if it fails; Field will contain a blank string ("")

Definition at line 1905 of file sgscan.cpp.

01906 {
01907     ERROR3IF(Field == NULL, "Library::GetSingleField - NULL Params are illegal");
01908 
01909 #ifdef FIELDCACHE
01910     // We've got a hit in our field cache
01911     if(CacheGet(Offset, Count, Field))
01912         return TRUE;
01913 #endif
01914 
01915     // Extract the entry from the index file
01916     BOOL GotField = FALSE;
01917 
01918     // Check if we've got a cached version of the index
01919     if(CachedSubIndexBuf != NULL)
01920     {
01921         GotField = GetSingleFieldFromMemory(Offset, Count, Field);
01922     }
01923     
01924     // Memory file didn't have item, or not present... use a disk file
01925     if(!GotField)
01926     {
01927         GotField = GetSingleFieldFromDisk(Offset, Count, Field);
01928     }
01929 
01930     // If we got the field, whack it in the cache, otherwise return a blank
01931     if(!GotField)
01932         *Field = TEXT("");
01933 #ifdef FIELDCACHE
01934     else
01935     {
01936         // Clean the string up a bit
01937         LibraryFile::KillLeadingSpaces(Field);
01938         CachePut(Offset, Count, Field);
01939     }
01940 #endif
01941     
01942     return GotField;
01943 }

BOOL Library::GetSingleFieldFromDisk LibraryIndex  Offset,
UINT32  Count,
StringBase Field
[protected]
 

Return a single field for a given library item using a diskfile for the index.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/4/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] Count - Identifies which field toi retrieve from the line of index information for this item.
Field will be filled in with the field contents. [OUTPUTS]
Returns:
FALSE if it fails

Definition at line 2161 of file sgscan.cpp.

02162 {
02163     ERROR3IF(Field == NULL, "Library::GetSingleField - NULL Params are illegal");
02164 
02165     BOOL ok = TRUE;
02166     BOOL OpenedOK = TRUE;
02167     CCLexFile *SubIndex = NULL;
02168 
02169     // If we've not got a cached version of the index, use a diskfile on the index itself
02170     SubIndex = new CCDiskFile;
02171 
02172     // Open the index file, seek to our position and rip out our token
02173     if(SubIndex != NULL)
02174         OpenedOK = ((CCDiskFile *)SubIndex)->open(*IndexFile, ios::in);
02175 
02176     if(SubIndex == NULL)
02177     {
02178         ERROR3("Library::Init Disk SubIndex not created properly");
02179         return FALSE;
02180     }
02181 
02182     if(!OpenedOK)
02183     {
02184         ERROR3("Library::Init Disk SubIndex not opened properly");
02185         delete SubIndex;
02186         return FALSE;
02187     }
02188     
02189     // Subindex seeking required
02190     if (!SubIndex->InitLexer(TRUE))
02191     {
02192         ERROR3("Library::GetSingleField InitLexer failed");
02193         if(SubIndex->isOpen())
02194             SubIndex->close();
02195         delete SubIndex;
02196         return FALSE;
02197     }
02198 
02199     SubIndex->SetWhitespace("");            // Setting this to blank lets us read non-"'d strings
02200     SubIndex->SetDelimiters(",");       // ,s delimit our fields
02201     SubIndex->SetCommentMarker('#');        // #'d lines are commented out
02202     SubIndex->SetStringDelimiters("");  // No string delimiters
02203 
02204     SubIndex->seekIn(Offset);
02205     
02206     String_256 Token;
02207     LexTokenType TT = TOKEN_EOL;
02208 
02209     LibraryIndex FOffset;
02210     ok = SubIndex->GetToken();
02211     TT = SubIndex->GetTokenType();      
02212 
02213     FOffset = (LibraryIndex) SubIndex->tellIn();
02214 
02215     if(FOffset != Offset)
02216         ERROR3("Lexer didn't seek properly");
02217 
02218     while(Offset > FOffset && ok && TT != EOF)
02219     {
02220         ok = SubIndex->GetToken();
02221         FOffset = (LibraryIndex) SubIndex->tellIn();
02222         TT = SubIndex->GetTokenType();      
02223         if (TT == TOKEN_EOF) ok = FALSE;
02224     }
02225 
02226     if(!ok)
02227     {
02228         ERROR3("Library::GetSingleField Line past end of file");
02229 //      if(CachedSubIndex == NULL)
02230 //      {
02231             if(SubIndex->isOpen())
02232                 SubIndex->close();
02233             delete SubIndex;
02234 //      }
02235         return FALSE;
02236     }
02237 
02238     // Get the first token in the line (since we did a seek, the first few
02239     // tries might return garbage...)
02240     while(ok && TT != TOKEN_NORMAL)
02241     {
02242         ok = SubIndex->GetToken();
02243 
02244         if (ok)
02245         {
02246             TT = SubIndex->GetTokenType();      
02247             if (TT == TOKEN_EOF)
02248                 ok = FALSE;
02249         }
02250     }
02251 
02252     if (ok)
02253     {
02254         UINT32 i = 1;
02255 
02256         // Keep reading tokens until we hit the one we want
02257         while(Count > i && ok)
02258         {
02259             Token = SubIndex->GetTokenBuf();
02260             LibraryFile::KillLeadingSpaces(&Token);
02261 
02262             if (Token == String_8(",") )
02263                 i++;                        // Found a comma, move to next field
02264         
02265             ok = SubIndex->GetToken();      // Get next token
02266         }
02267 
02268         // Hopefully the token buffer now contains our item
02269         if (ok)                        
02270         {
02271             Token = SubIndex->GetTokenBuf();
02272             LibraryFile::KillLeadingSpaces(&Token);
02273 
02274             if (Token == String_8(",") )
02275                 *Field = TEXT("");
02276             else
02277                 *Field = Token;
02278         }
02279     }
02280 
02281     // reclaim lexer-buffer memory
02282     SubIndex->DeinitLexer();    
02283 
02284     // and close the file...
02285     if(SubIndex->isOpen())
02286         SubIndex->close();
02287 
02288     // and reclaim the diskfile memory...
02289     delete SubIndex;
02290 
02291     return ok;
02292 }

BOOL Library::GetSingleFieldFromMemory LibraryIndex  Offset,
UINT32  Count,
TCHAR **  Field
[protected]
 

Return a pointer to a single field for a given library item using the 0 padded, cached index file in memory.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] Count - Identifies which field toi retrieve from the line of index information for this item.
Field will point to the field string in memory [OUTPUTS]
Returns:
FALSE if it fails

Definition at line 2090 of file sgscan.cpp.

02091 {
02092     ERROR3IF(Field == NULL, "Library::GetSingleField - NULL Params are illegal");
02093     ERROR3IF(Offset > CachedBufLength, "Library::GetSingleField - given out of range offset");
02094     ERROR3IF(CachedSubIndexBuf == NULL, "Library::GetSingleField - called with null index buffer");
02095 
02096     // Equivalent to a memfile seek
02097     TCHAR *Start = CachedSubIndexBuf + Offset;
02098     TCHAR *Finish = CachedSubIndexBuf + CachedBufLength;
02099 
02100     if(Count == 1)
02101     {
02102         *Field = Start;
02103         return TRUE;
02104     }
02105     else
02106     {
02107         // chars to look for
02108         const TCHAR SPC = ' ';
02109 
02110         TCHAR Ch = *Start;
02111         UINT32 FieldCount = 1;
02112 
02113         // scan through fields until we hit our baby
02114         while(Count > FieldCount && Start < Finish)
02115         {
02116             if(Ch == 0) FieldCount ++;
02117             Start += sizeof(TCHAR);
02118             Ch = *Start;
02119         }
02120 
02121         if(Count == FieldCount)
02122         {
02123             // Quick, speedy kill leading spaces type thing
02124             Ch = *Start;
02125             while(Ch == SPC && Ch != 0 && Start < Finish)
02126             {
02127                 Start += sizeof(TCHAR);
02128                 Ch = *Start;
02129             }
02130 
02131             // Pass back a pointer to the string data
02132             *Field = Start;
02133             return TRUE;
02134         }
02135         else
02136             return FALSE;
02137     }   
02138 
02139     return FALSE;
02140 }

BOOL Library::GetSingleFieldFromMemory LibraryIndex  Offset,
UINT32  Count,
StringBase Field
[protected]
 

Return a single field for a given library item using the 0 padded, cached index file in memory.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/4/95
Parameters:
Offset - The index identifying the library item to get the field for [INPUTS] Count - Identifies which field toi retrieve from the line of index information for this item.
Field will be filled in with the field contents. [OUTPUTS]
Returns:
FALSE if it fails

Definition at line 2009 of file sgscan.cpp.

02010 {
02011     ERROR3IF(Field == NULL, "Library::GetSingleField - NULL Params are illegal");
02012     ERROR3IF(Offset > CachedBufLength, "Library::GetSingleField - given out of range offset");
02013     ERROR3IF(CachedSubIndexBuf == NULL, "Library::GetSingleField - called with null index buffer");
02014 
02015 #if 0
02016     // Equivalent to a memfile seek
02017     TCHAR *Start = CachedSubIndexBuf + Offset;
02018     TCHAR *Finish = CachedSubIndexBuf + CachedBufLength;
02019 
02020     if(Count == 1)
02021     {
02022         *Field = Start;
02023         return TRUE;
02024     }
02025     else
02026     {
02027         // chars to look for
02028         const TCHAR SPC = ' ';
02029 
02030         TCHAR Ch = *Start;
02031         UINT32 FieldCount = 1;
02032 
02033         // scan through fields until we hit our baby
02034         while(Count > FieldCount && Start < Finish)
02035         {
02036             if(Ch == 0)
02037                 FieldCount ++;
02038             Start += sizeof(TCHAR);
02039             Ch = *Start;
02040         }
02041 
02042         if(Count == FieldCount)
02043         {
02044             // Quick, speedy kill leading spaces type thing
02045             Ch = *Start;
02046             while(Ch == SPC && Ch != 0 && Start < Finish)
02047             {
02048                 Start += sizeof(TCHAR);
02049                 Ch = *Start;
02050             }
02051 
02052             // COPY String into field (could pass back a pointer ?)     
02053             *Field = Start;
02054             return TRUE;
02055         }
02056         else
02057             return FALSE;
02058     }   
02059 
02060     return FALSE;
02061 #endif
02062 
02063     TCHAR *Fld;
02064     BOOL ok = GetSingleFieldFromMemory(Offset, Count, &Fld);
02065     *Field = Fld;
02066 
02067     return ok;
02068 }

BOOL Library::GetTextname LibraryIndex  Offset,
TCHAR **  Text
 

Return a pointer to the textual description for the indexed library item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - the index identifying the item you require [INPUTS]
Text - A pointer to a string (May NOT be NULL) [OUTPUTS]

Definition at line 1649 of file sgscan.cpp.

01650 {
01651     ERROR3IF(Text == NULL, "Library::GetTextname - NULL params are illegal");
01652     return(GetSingleField(Offset, 2, Text));
01653 }

BOOL Library::GetTextname LibraryIndex  Offset,
StringBase Text
 

Return the textual description for the indexed library item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
Offset - the index identifying the item you require [INPUTS] Text - A pointer to a string to recieve the text name (May NOT be NULL)

Definition at line 1629 of file sgscan.cpp.

01630 {
01631     ERROR3IF(Text == NULL, "Library::GetTextname - NULL params are illegal");
01632     return(GetSingleField(Offset, 2, Text));
01633 }

BOOL Library::GetThumbnail LibraryIndex  Offset,
SGThumbSize  Size,
BOOL  Urgent,
KernelBitmap **  Thumbnail
 

Return a pointer to the thumbnail for the given library index.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>; modified by Adrian 1/12/96
Date:
22/2/95
Parameters:
Offset into index file [INPUTS] Size of thumbnail (Small, Medium, Large) Urgent - set to true if we want the thumbnail NOW ! (if false, only returns thumbnail if in cache)
Thumbnail - The value pointed to by Result will be filled in with [OUTPUTS] a pointer to a created thumbnail. This may be NULL if a thumb could not be found/created (if Urgent == FALSE, then this will be NULL if the thumb is not already cached in memory)
Returns:
TRUE if it succeeds (though this may still return a NULL thumbnail ptr) FALSE if it failed miserably

Definition at line 1778 of file sgscan.cpp.

01780 {
01781     if (Thumbnails == NULL)
01782         return FALSE;
01783 
01784     UINT32 ID = GetID(Offset);
01785     Thumbnails->SetSize(Size);
01786 
01787     // For ripping thumbnails out of art files, we need the name of the art file
01788     PathName ActualFile;
01789     PathName *pActualFile = &ActualFile;
01790     String_256 TheFile;
01791 
01792     if(!GetFilename(Offset, &TheFile, TRUE))
01793         pActualFile = NULL;
01794     else
01795         ActualFile.SetPathName(TheFile);
01796                                                                                                                  
01797     return(Thumbnails->GetThumbnail(ID, Urgent, Thumbnail, pActualFile));
01798 }

BOOL Library::GetTitle LibraryIndex  Offset,
TCHAR **  Title
 

Return a pointer to the title for the indexed library item.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
Offset - the index identifying the item you require [INPUTS]
Title - ptr to title to return [OUTPUTS]
Returns:
TRUE if it succeeded
Notes: If we're using diskfiles this will return FALSE

Definition at line 1736 of file sgscan.cpp.

01737 {
01738     ERROR3IF(Title == NULL, "Library::GetFilename - NULL params are illegal");
01739 
01740     String_64 Tmp(_R(IDS_LIBRARIES_INDEX_ITEM_TITLE));
01741     if(!GotField(&Tmp))
01742         return FALSE;
01743 
01744     // Get title from index file
01745     BOOL ok = GetSingleField(Offset, &Tmp, Title);
01746 //  BOOL ok = GetSingleField(Offset, 4, Title);
01747 
01748     // NULL titles are invalid - default to something else - probably filename
01749     if(camStrlen(*Title)  == 0)
01750         ok = FALSE;
01751 
01752     return ok;
01753 }

BOOL Library::GetTitle LibraryIndex  Offset,
StringBase Title
 

Return the 'title' for the indexed library item (if there is one).

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/5/95
Parameters:
Offset - the index identifying the item you require [INPUTS]
Title - A pointer to a path name to be filled in (May NOT be NULL) [OUTPUTS]
Returns:
TRUE if it succeeded

Definition at line 1697 of file sgscan.cpp.

01698 {
01699     ERROR3IF(Title == NULL, "Library::GetTitle - NULL params are illegal");
01700 
01701     String_64 Tmp(_R(IDS_LIBRARIES_INDEX_ITEM_TITLE));
01702     if(!GotField(&Tmp))
01703         return FALSE;
01704 
01705     // Get title from index file
01706     BOOL ok = GetSingleField(Offset, &Tmp, Title);
01707 
01708 //  BOOL ok = GetSingleField(Offset, 4, Title);
01709 
01710     // NULL titles are invalid - default to something else - probably filename
01711     if(Title->Length() == 0)
01712         ok = FALSE;
01713 
01714     return ok;
01715 }

SGLibType Library::GetType void   )  [inline]
 

Definition at line 204 of file sgscan.h.

00204 { return Type;}

BOOL Library::GotField String_64 FieldName  ) 
 

Check if a string is in the field description string...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/5/95
Parameters:
FieldName - Field to look for [INPUTS]
Returns:
TRUE if the field string has the specified field...

Definition at line 2436 of file sgscan.cpp.

02437 {
02438     return (FieldString.Sub(*FieldName) != -1);
02439 }

INT32 Library::Init SuperGallery ParentGal,
PathName Path,
String_64 SLTitle,
StringBase SubI,
SGLibType  SLType,
BOOL  Updated = FALSE,
BOOL  AllowedToCreateVirtualised = FALSE
 

Given a specified sublibrary index, scan it and create a supergallery display group for it, containing display items for all of the items in the index.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
ParentGal - The parent gallery into which the group should be added. [INPUTS] Path - The pathname of the library directory - C: SLTitle - The title text for this sublibrary SubI - The SubIndex filename - XaraClip.txt SLType - The expected type of the sublibrary Updated - True if index has just been updated AllowedToCreateVirtualised - if set to FALSE we won't create a virtualised-out group
Returns:
0 if an error occurred, -1 if the group was created in a virtualised out stage (in which case we'll need to be initialised again to create the items), else a count of the number of items in this library
If the group already exists in the gallery, it will be replaced (recreated).

Notes: If you want the Quiet button code to work you need to call LibraryGallery->SetQuietStatus(FALSE); before calling this. Note that a large stream of new additions should call this just once for the first item. If you don't do this you won't get retry capability if the user's CD isn't in the drive...

For the sake of progress bars and delayed hourglass popping up, we now call ProgressBar->Update(), if the static Library::ProgressBar is non-null...

Definition at line 546 of file sgscan.cpp.

00548 {
00549     if(ParentGal == NULL || Path == NULL || SLTitle == NULL || SubI == NULL)
00550     {
00551         ERROR3("Library::Library - NULL parameters are illegal");
00552         return 0;
00553     }
00554 
00555 //  String_256 P(Path->GetPath());
00556 //  ERROR3_PF(("LibraryInitPath = %s", (TCHAR *)P));
00557 //  ERROR3_PF(("LibraryInit SubI = %s", (TCHAR *)*SubI));
00558     if(ProgressBar != NULL) ProgressBar->Update();
00559 
00560     // Set up some of the member variables for this library object
00561     if(!SetUpMembers(ParentGal, Path, SLTitle, SubI, SLType))
00562         return 0;
00563 
00564     // Should we be creating items, etc at this point ?
00565     if(SGLibGroup::LibraryVirtualisingEnabled && ParentGroup == NULL && AllowedToCreateVirtualised)
00566     {
00567         ParentGroup = (SGLibGroup *)ParentGallery->AddLibraryGroup(this, -1);
00568         ParentGroup->SetVirtualisedState(TRUE);
00569         return -1;
00570     }
00571 
00572     // Sort the Quick Index members out. This doesn't need doing for virtualised out groups
00573     QuickIndexEnabled = SetupQuickIndexMembers(Path, TRUE);
00574 
00575     CCLexFile *SubIndex = NULL;
00576     BOOL CachedSubIndex = FALSE;
00577     BOOL OpenedOK = FALSE;
00578     BOOL Retry = FALSE;
00579 
00580     // 'Quiet' button handling when no indexes found...
00581     BOOL Quiet = FALSE;
00582     LibraryGallery *LG = NULL;
00583     if(ParentGal->IsKindOf(CC_RUNTIME_CLASS(LibraryGallery)))
00584         LG = (LibraryGallery *)ParentGal;
00585     else
00586     {
00587         ERROR3("Library::Init called with a non-library gallery gallery");
00588         return 0;
00589     }
00590 
00591     // Extra bit of code added to let the user 'retry' for their CD if we can't find it.
00592     do
00593     {
00594         Retry = FALSE;
00595 
00596         // Try to cache the index file for quicker access later on
00597         if(CacheIndexFile && !CachedSubIndex)
00598             CachedSubIndex = CacheSubIndex(IndexFile);
00599         
00600         TRY
00601         {
00602             // Use a disk file for this bit
00603             SubIndex = new CCDiskFile(1024, FALSE, TRUE);
00604             if(SubIndex != NULL)
00605             {
00606                 if(QuickIndexEnabled)
00607                     OpenedOK = ((CCDiskFile *)SubIndex)->open(*QuickIndexFile, ios::in);
00608                 else
00609                     OpenedOK = ((CCDiskFile *)SubIndex)->open(*IndexFile, ios::in);
00610             }
00611             else
00612             {
00613                 ERROR3("Library::Init SubIndex not created properly");
00614                 return(0);
00615             }
00616         }
00617 
00618         if(ProgressBar != NULL) ProgressBar->Update();
00619 
00620         CATCH(CFileException, e)
00621         {
00622             // Looks like the index file doesn't exist - or we can't get to it anyhow...
00623             // This only happens on first opening the gallery at the moment. Since this
00624             // is a pretty good candidate for not having the CD present, the below code was
00625             // added. Of course we don't know it's the CD that's not present, they could
00626             // have vaped their TEMP directory, or done something else obscenely stupid (well,
00627             // sensible really)... Who knows... Anything can and does happen...
00628             if(SubIndex != NULL)
00629             {
00630                 INT32 LastButtonPressed = 1;
00631 
00632                 Quiet = LG->GetQuietStatus();
00633             
00634                 if(!Quiet)
00635                 {
00636                     String_256 WarnMsg;
00637 
00638                     if(!SGLibGroup::LibraryVirtualisingEnabled)
00639                     {
00640                         // Old system where groups and items are all created when the gallery is opened
00641                         WarnMsg.MakeMsg(_R(IDS_LIBRARY_CANT_FIND_INDEX), (const TCHAR *)Path->GetFileName(FALSE));
00642                         Error::SetError(0, WarnMsg, 0);
00643                         LastButtonPressed = InformWarning(0, _R(IDS_CONTINUE), _R(IDS_RETRY), _R(IDS_QUIET), NULL, 2, 1);
00644                         Retry  = (LastButtonPressed == 2);
00645                         Quiet  = (LastButtonPressed == 3);
00646                     }
00647                     else
00648                     {
00649                         // New system when this will only be called when de-virtualising all groups
00650                         WarnMsg.MakeMsg(_R(IDS_LIBRARY_CANT_FIND_INDEX_SKIP), (const TCHAR *)Path->GetFileName(FALSE));
00651                         Error::SetError(0, WarnMsg, 0);
00652                         LastButtonPressed = InformWarning(0, _R(IDS_SKIP), _R(IDS_RETRY), _R(IDS_QUIET), NULL, 2, 1);
00653                         Retry  = (LastButtonPressed == 2);
00654                         Quiet  = (LastButtonPressed == 3);
00655                     }
00656 
00657                     LG->SetQuietStatus(Quiet);
00658                 }
00659                 if (SubIndex->isOpen())
00660                     SubIndex->close();
00661                 delete SubIndex;
00662                 SubIndex = NULL;
00663             }
00664             Error::ClearError();
00665             if(!Retry)
00666                 return 0;
00667         }
00668         END_CATCH
00669 
00670         // This can't happen, but just in case !
00671         if(Quiet && Retry)
00672             Retry = FALSE;
00673     } while(Retry);
00674 
00675     if(ProgressBar != NULL) ProgressBar->Update();
00676 
00677     // Subindex seeking required
00678     if (!SubIndex->InitLexer(TRUE))
00679     {
00680         ERROR3("Library::Init InitLexer failed");
00681         if(SubIndex->isOpen())
00682             SubIndex->close();
00683         delete SubIndex;
00684         return FALSE;
00685     }
00686 
00687     SubIndex->SetWhitespace("");            // Setting this to blank lets us read non-"'d strings
00688     SubIndex->SetDelimiters(",");       // ,s delimit our fields
00689     SubIndex->SetCommentMarker('#');        // #'d lines are commented out
00690     SubIndex->SetStringDelimiters("");  // No string delimiters
00691 
00692     if(OpenedOK)
00693     {
00694         // Read the header
00695         INT32 NumItems = ReadHeaderInfo(SubIndex);      
00696 
00697         if(ProgressBar != NULL) ProgressBar->Update();
00698 
00699         if (NumItems > 0)
00700         {
00701             // Remove any pre-existing groups with the same index file
00702             ((LibraryGallery *)ParentGal)->RemoveSimilarLibraryGroups(SubLibPath, (String_256 *)SubI, TRUE, FALSE, this);
00703 
00704             // Create/find the required group in the parent gallery
00705             ParentGroup = (SGLibGroup *)ParentGallery->AddLibraryGroup(this, NumItems);
00706             ParentGroup->SetVirtualisedState(FALSE);
00707 
00708             if (ParentGroup == NULL)        // Couldn't get a display group! Argh!
00709             {
00710                 // reclaim lexer-buffer memory
00711                 SubIndex->DeinitLexer();    
00712 
00713                 // and close the file...
00714                 if(SubIndex->isOpen())
00715                     SubIndex->close();
00716 
00717                 // and reclaim the diskfile memory...
00718                 delete SubIndex;
00719                 return FALSE;
00720             }
00721 
00722             if(ProgressBar != NULL) ProgressBar->Update();
00723 
00724             // And construct all the items...
00725             if(CachedSubIndexBuf == NULL)
00726                 ScanRestOfFile(SubIndex);
00727             else
00728                 ScanRestOfFile(CachedSubIndexBuf, FirstLineOffset, CachedBufLength);
00729 
00730             if(ProgressBar != NULL) ProgressBar->Update();
00731 
00732 #ifdef _DEBUG
00733             if(NumItems != ItemCount)
00734             {
00735                 String_256 Warn;
00736                 PathName Loc(IndexFile->GetLocation(FALSE));
00737                 PathName Loc2(Loc.GetLocation(FALSE));
00738                 String_256 FNameWarn(Loc2.GetFileName());
00739 
00740                 BOOL DoWarning = TRUE;
00741                 
00742 #ifdef DONT_REPORT_KNOWN_CLIPART_PROBLEMS
00743                 // Don't warn if doing Studio and only 1 off - The Infamous Rolex Bodge !
00744                 if((ItemCount == (NumItems - 1)) && FNameWarn == (String_256)"Studio")
00745                     DoWarning = FALSE;
00746 
00747                 // Corel Xara CD (rel 1) bodges
00748                 if(ItemCount == 50 && NumItems == 48 && FNameWarn == (String_256)"Xara")
00749                     DoWarning = FALSE;
00750                 if(ItemCount == 329 && NumItems == 330 && FNameWarn == (String_256)"ANIMALS")
00751                     DoWarning = FALSE;
00752                 if(ItemCount == 470 && NumItems == 474 && FNameWarn == (String_256)"PEOPLE")
00753                     DoWarning = FALSE;
00754 #endif
00755                 if(DoWarning)
00756                 {
00757                     ERROR3_PF(("Dodgy checksum for '%s' index file. Header value should read %d.", (TCHAR *)FNameWarn, ItemCount));
00758                 }
00759             }
00760 #endif
00761         }
00762     }
00763     else
00764     {
00765         // Failed to read the sub index file...
00766         ERROR3("Library::Library couldn't open sub index file");
00767     }
00768 
00769     if(ProgressBar != NULL) ProgressBar->Update();
00770 
00771     // reclaim lexer-buffer memory
00772     SubIndex->DeinitLexer();    
00773 
00774     // and close the file...
00775     if(SubIndex->isOpen())
00776         SubIndex->close();
00777 
00778     // and reclaim the diskfile memory...
00779     delete SubIndex;
00780 
00781     // Thumbnail cache class
00782     Thumbnails = NULL;
00783 
00784 //  String_256 IndexPath(IndexFile->GetPath());
00785 //  ERROR3_PF(("IndexPath = %s", (TCHAR *)IndexPath));
00786         
00787     // Path for thumbnails - this is INCORRECT !!!
00788 //  String_256 ThuF(Path->GetPath(TRUE));
00789     
00790 //  PathName IndexP(IndexFile);
00791     String_256 ThuF(IndexFile->GetLocation(FALSE));
00792     LibraryFile::TidyUpSubPath(&ThuF);
00793     SGLibOil::AppendSlashIfNotPresent(&ThuF);
00794 
00795     ThuF += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
00796     PathName ThumbPath(ThuF);
00797     if(!ThumbPath.IsValid())
00798     {
00799         ERROR3("Library::Init ThumbPath is invalid");
00800         return 0;
00801     }
00802 
00803 //  ERROR3_PF(("Path = %s, SubLibPath = %s, IndexFile = %s", Path->GetPath(), SubLibPath->GetPath(), IndexFile->GetPath()));
00804 
00805     // Allocate memory for new thumbnail cache and point to it
00806     Thumbnails = new SGThumbs(&ThumbPath, SLType, SGThumb_Small);
00807 
00808     return(ItemCount);
00809 }

BOOL Library::InitLibPrefs void   )  [static]
 

Initialises the preferences in the ini file and returns the values of the entries if they're there already.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/4/95
Parameters:
[INPUTS] 
[OUTPUTS] 
Returns:
FALSE if it fails; TRUE if we got our prefs from the ini file
Notes:

Definition at line 2796 of file sgscan.cpp.

02797 {
02798     // Only do this once
02799     static BOOL AlreadyCalled = FALSE;
02800     if(AlreadyCalled) return FALSE;
02801     AlreadyCalled = TRUE;
02802 
02803 #ifndef EXCLUDE_GALS
02804     
02805     GetApplication()->DeclareSection(TEXT("Libraries"), 12);
02806 
02807     // The locations of the libraries (as found via browse or scan)
02808     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("ClipArt"), &LibClipartSGallery::ClipartPath);
02809     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("WebTheme"), &LibClipartSGallery::WebThemePath);
02810 
02811 #ifndef STANDALONE
02812 //WEBSTER-Martin-09/01/97   - Put back by Ranbir.
02813 //#ifndef WEBSTER
02814     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Font"), &FontsSGallery::DefaultLibraryPath);
02815 //#endif //WEBSTER
02816     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Texture"), &LibFillsSGallery::DefaultLibraryPath);
02817 #endif
02818 
02819     // Remember the last display modes used
02820     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("ClipartDisplayMode"), &LibClipartSGallery::DefaultDisplayMode, 0, 2);
02821 #ifndef STANDALONE
02822 //WEBSTER-Martin-09/01/97
02823 //#ifndef WEBSTER   - Put back by Ranbir.
02824     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("FontDisplayMode"), &FontsSGallery::DefaultDisplayMode, 0, 4);
02825 //#endif //WEBSTER
02826     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("FillDisplayMode"), &LibFillsSGallery::DefaultDisplayMode, 0, 2);
02827 #endif //WEBSTER
02828 
02829 #ifdef _DEBUG
02830     // Cache the library index files in memory, so index accesses require NO disk accesses, except for thumbnails
02831     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("CacheIndexFiles"), &Library::CacheIndexFile, 0, 1);
02832 #endif
02833 
02834     // Redraw the library galleries in two passes
02835     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("BackgroundRedraw"), &Library::BackgroundRedraw, 0, 1);
02836 
02837     // Number of thumbnails to cache in memory for EACH GROUP
02838     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Thumbnails"), &SGThumbs::MaxThumbnails, 1, 100);
02839 
02840     // Number of fields to cache in the Field cache for EACH GROUP
02841     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("FieldCache"), &Library::MaxFieldCacheEntries, 1, 1000);
02842 
02843     // Rip info out of existing indexes when generating new ones
02844     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("UseOldIndexesWhenCreating"), &GenerateIndexFile::UseOldIndexes, 0, 1);
02845 
02846     // Rip info out of existing indexes when generating new ones
02847     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("UseDocCommentsWhenCreating"), &GenerateIndexFile::UseDocComments, 0, 1);
02848 
02849     // Rip info out of existing indexes when generating new ones
02850     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("AskAboutRemoving"), &LibraryGallery::AskAboutRemoving, 0, 1);
02851 
02852     // Enable 'remote' library indexes if target media is read-only...
02853     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("RemoteIndexes"), &Library::RemoteIndexes, 0, 1);
02854 
02855     // Location for 'remote' library indexes (if empty, use temp)...
02856     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("RemoteIndexLocation"), &Library::RemoteIndexLocation);
02857 
02858     // Should we make sounds if the index contains them ?
02859     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Enhancements"), &LibClipartSGallery::DoSounds);
02860 
02861     // Should we use an explorer dialog on win95 if we can ?
02862     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Explorer"), &SGLibOil::UseExplorerForAdd);
02863 
02864     // Enable 'quick indexes'
02865 #ifdef _DEBUG
02866     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("QuickIndexes"), &Library::QuickIndex, 0, 1);
02867 #endif
02868 
02869     // Should we just build the groups without items for speed ?
02870     GetApplication()->DeclarePref(TEXT("Libraries"), TEXT("Virtualising"), &SGLibGroup::LibraryVirtualisingEnabled, 0, 1);
02871 
02872 //WEBSTER-Martin-09/01/97
02873 //#ifndef WEBSTER
02874 #ifndef STANDALONE
02875     // Preferences for the fonts gallery
02876     GetApplication()->DeclareSection(TEXT("FontGallery"), 3);
02877 
02878     // Preview string used in the installed section
02879     GetApplication()->DeclarePref(TEXT("FontGallery"), TEXT("LargeInstalledDisplayString"), &FontsSGallery::LargeDisplayString);
02880 
02881     // Delete the corresponding TTF and FOT files in windows\system (or wherever) when deinstalling the font
02882     GetApplication()->DeclarePref(TEXT("FontGallery"), TEXT("DeleteFilesOnDeinstall"), &FontsSGallery::DeleteTTFandFOTfiles, 0, 1);
02883 
02884     // Enable or Disable ATM Alias in menus / galleries...
02885     GetApplication()->DeclarePref(TEXT("FontGallery"), TEXT("DisableATMAliases"), &ATMInstall::DisableATMAliases, 0, 1);
02886 #endif \\STANDALONE
02887 //#endif \\WEBSTER
02888 #endif
02889     return TRUE;
02890 }

BOOL Library::IsWebLibrary  )  [inline]
 

Definition at line 284 of file sgscan.h.

00284 {return m_bIsWebLib;} 

void Library::KillAllThumbnails void   ) 
 

Deletes all thumbnails from cache.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/2/95

Definition at line 1813 of file sgscan.cpp.

01814 {
01815     if (Thumbnails != NULL)
01816         Thumbnails->DeleteThumbnails();
01817 }                                 

BOOL Library::LocalPath2URL String_256 pLocalPath  ) 
 

converts a local path to a URL, using the base URL read from the library index file The URL can be used to download the file

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
01/12/96
Parameters:
a pointer to a String_256 containing local path to convert to a URL [INPUTS]
the expected location of the file on our web site. The input string is overwritten [OUTPUTS] with this location, but only if the function succeeds. The input string will not be modified in case of failure.
Returns:
TRUE is successful, FALSE if failed

Definition at line 1842 of file sgscan.cpp.

01843 {
01844     // The local path is made up of:
01845     // 1) a root path which is usually the exe's directory
01846     // 2) a leaf relative path which is assumed to be identical on the local drive and our web site
01847     // The URL is obtained by appending this leaf path to the root URL, and
01848     // converting all backslashes to normal ones. The returned URL is always lower case.
01849 
01850     String_256 strLocalPath(*pLocalPath);
01851     String_256 strURL(_T("http://xara.xaraonline.com/XaraX2/Resources/"));
01852     if (strURL.Length() == 0) 
01853     {
01854         ERROR3("URL base string is empty");
01855         return FALSE; // we don't have a base url, so can't convert
01856     }
01857     String_256 strWebFilesDir(GetStringField(Type, _R(IDS_CACHEDIR)));
01858     strWebFilesDir += _T("\\");
01859     strLocalPath.toLower();
01860     strWebFilesDir.toLower();
01861     strURL += camStrstr((TCHAR*) strLocalPath, (TCHAR*) strWebFilesDir + String_256(_R(IDS_CACHEPATH)).Length());
01862     strURL.toLower();
01863     // Convert backslashes to normal (UNIX) ones
01864     TCHAR* pBackSlash = NULL;
01865     while (pBackSlash = camStrchr((TCHAR*) strURL, _T('\\')))
01866             *pBackSlash = _T('/');
01867     // Check if the URL is valid
01868     WCHAR  wchURL[INTERNET_MAX_PATH_LENGTH];
01869     MultiByteToWideChar(CP_ACP, 0,  (TCHAR*) strURL, -1, wchURL, INTERNET_MAX_PATH_LENGTH);
01870     BOOL bIsValid = (IsValidURL(NULL, wchURL, 0) == S_OK) ? TRUE : FALSE;
01871     if (bIsValid)
01872     {
01873         *pLocalPath = strURL;
01874         return TRUE;
01875     }
01876     else
01877     {
01878         ERROR3("Conversion resulted in an invalid URL");
01879         return FALSE;
01880     }
01881 }

INT32 Library::PreviewBMPHeight SGThumbSize  Size  )  [inline]
 

Definition at line 243 of file sgscan.h.

00244     {
00245         if((INT32)Size < 3) return PreviewY[(INT32)Size];
00246         else return 64;
00247     }

INT32 Library::PreviewBMPWidth SGThumbSize  Size  )  [inline]
 

Definition at line 236 of file sgscan.h.

00237     {
00238         if((INT32)Size < 3) return PreviewX[(INT32)Size];
00239         else return 64;
00240     }

INT32 Library::ReadHeaderInfo CCLexFile pSubIndex  )  [private]
 

Read the no of items, field text and line pSubIndex up with the first proper index line.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
pSubIndex - the index file to read the header from [INPUTS]
Returns:
The number of items that should be found in this index file Returns 0 if there are no items, or if there was an error
Notes: On Exit, the file pointer in pSubIndex will point at the first line of the index body

Definition at line 1023 of file sgscan.cpp.

01024 {   
01025     ERROR3IF(pSubIndex == NULL, "Library::ReadHeaderInfo - NULL params are illegal");
01026 
01027     BOOL ok = TRUE;
01028     BOOL retok = TRUE;
01029     INT32 Items = 0;
01030 
01031     LexTokenType TT = TOKEN_EOL;
01032     UINT32 NonGarbageLineNumber = 0;        
01033     BOOL HitStart = FALSE;
01034     while(ok && retok && !HitStart/*NonGarbageLineNumber < 5*/)
01035     {
01036         if (!pSubIndex->GetToken()) break;
01037 
01038         // Keep reading tokens until we hit a normal one... (skips line ends and
01039         // comments for us
01040         TT = pSubIndex->GetTokenType();     
01041 
01042         while (TT != TOKEN_NORMAL && ok)
01043         {
01044             // Bodge so that lines starting #DESCRIPTION: case us to jump out...
01045             if(TT == TOKEN_COMMENT)
01046             {
01047                 // Optional header extras - Must have their name followed by a ':' then the item
01048                 if(camStrchr((TCHAR *) pSubIndex->GetTokenBuf(), _T(':')))
01049                 {
01050                     // We assume these lines aren't going to be bigger than 256 chars
01051                     String_256 TokenBufU(pSubIndex->GetTokenBuf());
01052                     TokenBufU.toUpper();
01053     
01054                     INT32 Offset = TokenBufU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_DESCRITION)));
01055 
01056                     if(Offset > -1 && Offset < 2)
01057                     {
01058                         // Need to set 'title'
01059                         if(Title)
01060                         {
01061                             String_256 TokenBuf(pSubIndex->GetTokenBuf());
01062                             TokenBuf.Right(Title, TokenBuf.Length() - (12 + Offset));               
01063                             LibraryFile::KillLeadingSpaces(Title);
01064                         }
01065                     }
01066                 }
01067             }
01068 
01069             ok = pSubIndex->GetToken();
01070             if(!ok) break;
01071             TT = pSubIndex->GetTokenType();     
01072             ok = (TT != TOKEN_EOF);
01073             if(!ok) break;
01074         }
01075         if(!ok) break;
01076 
01077         NonGarbageLineNumber++;     
01078         
01079         switch(NonGarbageLineNumber)
01080         {
01081             case 0: // Something nasty's happened
01082                 ERROR3("Library ReadHeader - Something nasty has happened");
01083                 break;
01084 
01085             case 1: // Number of files described by index
01086                 Items = _ttoi(pSubIndex->GetTokenBuf());
01087                 break;
01088 
01089             case 2: // Synonym filename
01090                 {
01091                     String_256 KPS; // %s\\XaraInfo\\%s
01092                     KPS = SubLibPath->GetPath(TRUE);
01093                     KPS += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01094                     KPS += TEXT("\\") + String_64(pSubIndex->GetTokenBuf());
01095                     SynonymFile = new PathName(KPS);
01096                     
01097                     // We can carry on from these two situations...
01098                     if(SynonymFile == NULL)
01099                     {
01100                         ERROR3("Library::ReadHeaderInfo not enough memory to create a SynonymFile path");
01101                         break;
01102                     }
01103 
01104                     if(!SynonymFile->IsValid())
01105                     {
01106                         ERROR3("Library::ReadHeaderInfo SynonymFile is invalid");
01107                         break;
01108                     }
01109                 }
01110                 break;
01111 
01112             case 3: // Thumbnail sizes
01113                 {
01114                     for(INT32 i = 0; i < 3; i++)
01115                     {
01116                         PreviewX[i] = _ttoi((TCHAR *)pSubIndex->GetTokenBuf());
01117                         
01118                         ok = pSubIndex->GetToken(); // Skip ','
01119                         if(!ok) break;
01120                         TT = pSubIndex->GetTokenType();
01121                         if(TT == TOKEN_EOL) break;
01122 
01123                         ok = pSubIndex->GetToken();
01124                         if(!ok) break;
01125                         TT = pSubIndex->GetTokenType();
01126                         if(TT == TOKEN_EOL) break;
01127 
01128                         PreviewY[i] = _ttoi((TCHAR *)pSubIndex->GetTokenBuf());
01129 
01130                         ok = pSubIndex->GetToken(); // Skip ','
01131                         if(!ok) break;
01132                         TT = pSubIndex->GetTokenType();
01133                         if(TT == TOKEN_EOL) break;
01134 
01135                         ok = pSubIndex->GetToken();
01136                         if(!ok) break;
01137                         TT = pSubIndex->GetTokenType();
01138                         if(TT == TOKEN_EOL) break;
01139 
01140                     }
01141                 }
01142                 break;
01143                     
01144             case 4: // Field titles
01145                 FieldString = pSubIndex->GetTokenBuf();
01146 
01147                 // loop through rest of line adding the info to the buffer
01148                 ok = pSubIndex->GetLineToken();
01149                 if(!ok) break;
01150 
01151                 TT = pSubIndex->GetTokenType();
01152                 if(TT == TOKEN_LINE)
01153                     FieldString += pSubIndex->GetTokenBuf();
01154                 else
01155                 {
01156                     retok = FALSE;
01157                     ERROR3("Library ReadHeader: Field line appears to be shorter than expected");
01158                 }
01159 
01160                 break;
01161 
01162 
01163 
01164             default:
01165 
01166                 // Optional header extras - Must have their name followed by a ':' then the item
01167                 if(camStrchr((TCHAR *) pSubIndex->GetTokenBuf(), _T(':')))
01168                 {
01169                     // We assume these lines aren't going to be bigger than 256 chars
01170                     String_256 TokenBufU(pSubIndex->GetTokenBuf());
01171                     TokenBufU.toUpper();
01172     
01173                     // Description for group
01174                     INT32 Offset = TokenBufU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_DESCRITION)));
01175                     if(Offset > -1 && Offset < 2)
01176                     {
01177                         // Need to set 'title'
01178                         if(Title)
01179                         {
01180                             String_256 TokenBuf(pSubIndex->GetTokenBuf());
01181                             TokenBuf.Right(Title, TokenBuf.Length() - (12 + Offset));               
01182                             LibraryFile::KillLeadingSpaces(Title);
01183                         }
01184                     }
01185 
01186                     // Remote files location
01187                     Offset = TokenBufU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_FILES)));
01188                     if(Offset == 0)
01189                     {
01190                         TRACEUSER( "Richard", _T("Remote files in use\n"));
01191 
01192                         // Need to set 'SubLibPath'
01193                         if(!SubLibPath)
01194                             SubLibPath = new PathName;
01195                             
01196                         if(SubLibPath != NULL)
01197                         {
01198                             PathName OldPath(*SubLibPath);
01199                             String_256 ThePath;
01200                             String_256 TokenBuf(pSubIndex->GetTokenBuf());
01201                             TokenBuf.Right(&ThePath, TokenBuf.Length() - (6 + Offset));
01202                             LibraryFile::KillLeadingSpaces(&ThePath);
01203 
01204                             SubLibPath->SetPathName(ThePath);
01205                             if(!SubLibPath->IsValid())
01206                             {
01207                                 *SubLibPath = OldPath;
01208                             }
01209                         }
01210                     }
01211                 }
01212 
01213                 // No further header entries, anything following the start line is a proper
01214                 // line of library text...
01215                 if(!camStrcmp((TCHAR *) pSubIndex->GetTokenBuf(), (TCHAR *)(String_16(_R(IDS_LIBRARIES_INDEX_START)))))
01216                 {
01217                     // Read until end of line
01218                     do {
01219                         ok = pSubIndex->GetToken();
01220                         if(!ok) break;
01221                         TT = pSubIndex->GetTokenType();     
01222                     } while (TT != TOKEN_EOF && TT != TOKEN_EOL && ok);
01223 
01224                     // We have reached the end of the header - exit immediately leaving
01225                     // the file pointer at the start of the file "body"
01226                     HitStart = TRUE;
01227                 }
01228                 break;
01229         }
01230 
01231         if(!ok) break;
01232 
01233         // Search for EOF or EOL after reading a line
01234         TT = pSubIndex->GetTokenType();     
01235 
01236         while (TT != TOKEN_EOF && TT != TOKEN_EOL && TT != TOKEN_LINE && TT != TOKEN_COMMENT && ok)
01237         {
01238             ok = pSubIndex->GetToken();
01239             if(!ok) break;
01240             TT = pSubIndex->GetTokenType();     
01241             ok = (TT != TOKEN_EOF);
01242             if(!ok) break;
01243         }
01244     }
01245 
01246     // Current file position is deemed the start of the first line of data
01247     FirstLineOffset = (LibraryIndex) pSubIndex->tellIn();
01248 
01249     // Hit EOF somehow... This is bad
01250     if(TT == TOKEN_EOF)
01251         return(0);
01252 
01253     if (retok)
01254         return(Items);
01255 
01256     return(0);
01257 }

BOOL Library::ReCacheIndexes void   ) 
 

Re-caches the indexes when opening a gallery...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/6/95
Returns:
TRUE if succesful and indexes have been (re-)cached... FALSE if problems

Definition at line 376 of file sgscan.cpp.

00377 {
00378     // Don't recache indexes if group is v-d out...
00379     if(ParentGroup != NULL && ParentGroup->IsVirtualised())
00380         return TRUE;
00381 
00382     // Sort out the field cache
00383 #ifdef FIELDCACHE
00384     CacheKill();
00385     CacheInit(MaxFieldCacheEntries);
00386 #endif
00387 
00388     // Recache the indexes
00389     if(CachedSubIndexBuf == NULL && CacheIndexFile && IndexFile != NULL)
00390     {
00391         // Check the index file still exists
00392         //if(!SGLibOil::FileExists(IndexFile))
00393         //  return FALSE;
00394 
00395         // See if the index file has changed...
00396         //UINT32 NewIndexStamp = SGLibOil::FileModified(IndexFile);
00397         //if(IndexDateStamp != NewIndexStamp)
00398         //  return FALSE;
00399 
00400         if(CacheSubIndex(IndexFile))
00401         {
00402             // Whizz through index, inserting 0's for commas and sorting out spaces, etc...
00403             return ScanRestOfFile(CachedSubIndexBuf, FirstLineOffset, CachedBufLength, FALSE);
00404         }
00405         else
00406         {
00407             return FALSE;
00408         }
00409     }
00410 
00411     return TRUE;
00412 }

BOOL Library::RestoreLibPrefs void   )  [static]
 

Called during preference wiping to allow us to squirrel away any settings that we desire before they are wiped. This is useful if we want to retain newly installed preferences that the installer has deliberately put there! E.g the paths to the clipart etc on the CD.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/12/97
Returns:
FALSE if it fails; TRUE if we everything went ok

Definition at line 2937 of file sgscan.cpp.

02938 {
02939     // Must save the values directly into the preferences as our preference variables will
02940     // not have been set up yet!
02941     const TCHAR * pClipPath = g_ClipartLibraryPath;
02942     const TCHAR * pWebPath = g_WebThemeLibraryPath;
02943     const TCHAR * pFontPath = g_FontLibraryPath;
02944     const TCHAR * pFillsPath = g_FillsLibraryPath;
02945     // Only put back the values if they contain something useful. Mustn't put back blank entires
02946     // otherwise the galleries will error about bad paths!
02947     if (!g_ClipartLibraryPath.IsEmpty())
02948         Camelot.SetPrefDirect(TEXT("Libraries"), TEXT("ClipArt"),   pClipPath);
02949     if (!g_WebThemeLibraryPath.IsEmpty())
02950         Camelot.SetPrefDirect(TEXT("Libraries"), TEXT("WebTheme"),  pWebPath);
02951     if (!g_FontLibraryPath.IsEmpty())
02952         Camelot.SetPrefDirect(TEXT("Libraries"), TEXT("Font"),      pFontPath);
02953     if (!g_FillsLibraryPath.IsEmpty())
02954         Camelot.SetPrefDirect(TEXT("Libraries"), TEXT("Texture"),   pFillsPath);
02955 
02956 //  LibClipartSGallery::DefaultLibraryPath  = g_ClipartLibraryPath;
02957 //  FontsSGallery::DefaultLibraryPath       = g_FontLibraryPath;
02958 //  LibFillsSGallery::DefaultLibraryPath    = g_FillsLibraryPath;
02959 
02960     return TRUE;
02961 }

PathName* Library::ReturnIndexLocation void   )  [inline]
 

Definition at line 250 of file sgscan.h.

00250 {return IndexFile;}

PathName* Library::ReturnSubLibraryLocation void   )  [inline]
 

Definition at line 253 of file sgscan.h.

00253 {return SubLibPath;}

PathName* Library::ReturnSynonymFile void   )  [inline]
 

Definition at line 256 of file sgscan.h.

00256 {return SynonymFile;}

BOOL Library::SaveIndexInDisplayedOrder PathName IndexPathName,
BOOL  NewIDs
 

Save out an index file in the order the group is displayed (possibly sorted !) Notes: This is strictly a debug only function !

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
IndexPathName - path to output index file to [INPUTS] NewIDs - regenerate the IDs in numerical order
[OUTPUTS] 
Returns:
FALSE if it fails; TRUE if we did it all ok

Definition at line 2677 of file sgscan.cpp.

02678 {
02679 #ifdef SAVEINDEX
02680     // Create index file
02681     CCDiskFile *IndexPath = new CCDiskFile(1024, TRUE, FALSE);
02682     ERROR2IF(IndexPath == NULL, FALSE, "Null index file allocated");
02683 
02684     if(!IndexPath->open(*IndexPathName, ios::out))
02685     {
02686         ERROR3("Can't create new index file");
02687         delete IndexPath;
02688         return FALSE;
02689     }
02690 
02691     // Write the header to the index file
02692     IndexPath->write(CachedSubIndexBuf, (UINT32)FirstLineOffset);
02693 
02694     // Loop through each item in the group as they're displayed and save each one out...
02695     BOOL ok = TRUE;
02696 
02697     // For the NewID stuff...
02698     INT32 Count = 0;
02699 
02700     SGDisplayNode *Item = ParentGroup;
02701 
02702     // Get the first item in the group...
02703     if(Item != NULL)
02704         Item = Item->GetChild();
02705 
02706     // Loop through all the group items
02707     while (Item != NULL)
02708     {
02709         if(Item->IsKindOf(CC_RUNTIME_CLASS(SGLibDisplayItem)))
02710         {
02711             Count++;
02712 
02713             SGLibDisplayItem *LibItem = (SGLibDisplayItem *) Item;
02714 
02715             LibraryIndex Offset = LibItem->GetDisplayedLibraryIndex();
02716             String_64 Field;
02717 
02718             TCHAR FieldStringBuffer[256];
02719             TCHAR *FieldStringDone = (TCHAR *)FieldStringBuffer;
02720             camStrcpy(FieldStringDone, (TCHAR *)FieldString);
02721 
02722             BOOL MoreFields = TRUE;
02723 
02724             // Rip out each field in turn
02725             while(MoreFields)
02726             {           
02727                 // find next comma in FieldStringDone and replace it with a 0
02728                 // If there are none then we assume that the end has come...
02729                 TCHAR *Comma = camStrchr(FieldStringDone, _T(','));
02730                 if(Comma != NULL)
02731                     *Comma = 0;
02732                 else
02733                     MoreFields = FALSE;
02734 
02735                 // kill leading spaces from FieldStringDone
02736                 while(FieldStringDone[0] == ' ')
02737                     FieldStringDone += sizeof(TCHAR);
02738 
02739                 // FieldStringDone now points to a field string... Get the data...
02740                 String_64 FieldStringToUse(FieldStringDone);
02741 
02742                 if(NewIDs && (FieldStringToUse == String_64(_R(IDS_LIBRARIES_INDEX_ITEM_ID))))
02743                     wsprintf(Field, "%d", Count);
02744                 else
02745                     ok = GetSingleField(Offset, &FieldStringToUse, &Field);
02746 
02747                 ERROR3IF(!ok, "Problems getting a field");
02748             
02749                 // Write the data into the new index file
02750                 IndexPath->write((TCHAR *)Field, (UINT32)Field.Length() * sizeof(TCHAR));
02751 
02752                 // Ternimate the data, if it's the last field, use a return...
02753                 if(Comma != NULL)
02754                 {
02755                     IndexPath->write((TCHAR *)",", sizeof(TCHAR) * 1);
02756                     FieldStringDone += ((camStrlen(FieldStringDone)+1) * sizeof(TCHAR));
02757                 }
02758                 else
02759                     IndexPath->write((TCHAR *)"\r\n", sizeof(TCHAR) * 2);       
02760             }
02761         }
02762         // If we've reached the end, this will be NULL
02763         Item = Item->GetNext();
02764     }
02765 
02766     // Close the index file and tidy up
02767     IndexPath->close();
02768     delete IndexPath;
02769 
02770     ERROR3IF(Count != ItemCount, "Wrong number of items in group -> bad !");
02771 
02772     return TRUE;
02773 #endif
02774     return FALSE;
02775 }

BOOL Library::ScanRestOfFile TCHAR CachedIndex,
INT32  Start,
INT32  Finish,
BOOL  AddItems = TRUE
[protected]
 

Scan the rest of the file (following the START), creating items for each entry... Also change ','s to 0's, so we can retrieve field strings more quickly later on.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
22/4/95
Parameters:
CachedIndex - points to the index file in memory [INPUTS] Start - Offset to start of first index line Finish - Offset to end of file in memory AddItems - Set to FALSE if you don't want the items to be added to the gallery
Returns:
TRUE if it succeeded, FALSE if not. If no items were found, it returns FALSE
AddItems added so that recaching already created tree indexes wouldn't add new items every time the gallery opens !

Definition at line 1286 of file sgscan.cpp.

01287 {
01288     if(CachedIndex == NULL)
01289     {
01290         ERROR3("Library::ScanRestOfFile - no cached index");
01291         return FALSE;
01292     }
01293 
01294     if(Start >= Finish)
01295     {
01296         ERROR3("Library::ScanRestOfFile - nothing to scan");
01297         return FALSE;
01298     }
01299 
01300     INT32 Offset = Start;
01301     INT32 NewItemOffset = 0;
01302     
01303     INT32 LineCount = 0;
01304     ItemCount = 0;
01305 
01306     TCHAR Ch = ' ';
01307     TCHAR NCh = ' ';
01308 
01309     // chars to look for
01310     const TCHAR CR = '\n';
01311     const TCHAR LF = '\r';
01312     const TCHAR REM = '#';
01313     const TCHAR SEP = ',';
01314     const TCHAR SPC = ' ';
01315 
01316 #ifdef _DEBUG
01317     // Count commas in FieldString
01318     INT32 CommaCount = 0;
01319     INT32 FieldCommaCount = 0;
01320     TCHAR *Buf = (TCHAR *)FieldString;
01321     INT32 Len = FieldString.Length();
01322     for(INT32 i = 0; i < Len; i++)
01323         if(Buf[i] == SEP)
01324             FieldCommaCount ++;
01325 #endif
01326 
01327     BOOL ok = TRUE;
01328 
01329     do {
01330         // Offset should now point to the start of a line
01331 
01332 #ifdef _DEBUG
01333         CommaCount=0;
01334 #endif
01335 
01336         Ch = CachedIndex[Offset];
01337         if((Ch == REM) || (Ch == CR) || (Ch == LF) || (Ch == SPC) || (Ch == SEP))
01338             NewItemOffset = 0;
01339         else
01340             NewItemOffset = Offset;
01341 
01342         // Scan until eol
01343         do {
01344             Ch = CachedIndex[Offset];
01345 
01346 #ifdef _DEBUG
01347             // Another separator to count
01348             if(Ch == SEP)
01349                 CommaCount ++;
01350 #endif
01351             
01352             // Zap separators into zeros
01353             if(Ch == SEP || Ch == LF || Ch == CR)
01354                 CachedIndex[Offset] = 0;
01355             
01356             Offset ++;          
01357 
01358         } while ( (Offset < Finish) && (Ch != CR) && (Ch != LF));
01359 
01360         /* FIX */
01361 #ifdef _DEBUG
01362         if(CommaCount != FieldCommaCount && CommaCount != 0)
01363         {
01364             String_256 WarnMsg;
01365             String_32 Line;
01366             
01367             // Bodge which might go wrong... Solves overflow problem...
01368             for(INT32 i=0; i<16; i++)
01369                 ((TCHAR *)Line)[i] = *(CachedIndex + NewItemOffset + (i * sizeof(TCHAR)));
01370             ((TCHAR *)Line)[i] = 0;
01371 
01372             BOOL DoCommaWarning = TRUE;
01373 
01374 #ifdef DONT_REPORT_KNOWN_CLIPART_PROBLEMS
01375             // Here are a couple of 'fixes' to stop the error3's in debug builds...
01376             if(NewItemOffset == 4205 && Start == 154 && Finish == 4271 && Offset == 4242 && CommaCount == 4 && FieldCommaCount == 5)
01377                 DoCommaWarning = FALSE; // Apple.xar fix
01378             if(NewItemOffset == 4243 && Start == 154 && Finish == 4271 && Offset == 4270 && CommaCount == 4 && FieldCommaCount == 5)
01379                 DoCommaWarning = FALSE; // Fish.xar fix
01380 #endif
01381             // Another separator to count
01382             if(DoCommaWarning)
01383             {
01384                 if(CommaCount > FieldCommaCount)    
01385                     wsprintf(WarnMsg, "Too many commas in line '%s' of '%s'", (TCHAR *)Line, (const TCHAR *)SubLibPath->GetPath());
01386                 else
01387                     wsprintf(WarnMsg, "Not enough commas in line '%s' of '%s'", (TCHAR *)Line, (const TCHAR *)SubLibPath->GetPath());
01388                 ERROR3(WarnMsg);
01389             }
01390         }
01391 #endif
01392         /* FIX */
01393 
01394         // Since we need access to the fields whilst adding the item (for sorting) we
01395         // add the item after fixing up the index line
01396         if(NewItemOffset != 0)
01397         {
01398             // Create a supergallery Display Item representing this library item, and add it
01399             // to our parent group
01400             if(AddItems)
01401             {
01402                 BOOL bIsNew = (m_lOldIndex != 0 && NewItemOffset >= m_lOldIndex) || (m_nModified == FOLDER_NEW);
01403                 ok = (ParentGallery->AddLibraryItem(ParentGroup, this, NewItemOffset, bIsNew) != NULL);
01404             }
01405 
01406             if(ok)
01407             {
01408                 ItemCount ++;
01409                 LineCount ++;
01410             }
01411         }
01412 
01413         NCh = CachedIndex[Offset];
01414 
01415         // Skip possibly double eol chars
01416         if ( ((Ch==LF) || (Ch==CR)) && ((NCh==LF) || (NCh==CR)) && (Offset < Finish) )
01417             Offset ++;  
01418 
01419     } while(Offset < Finish);
01420 
01421     return (ItemCount > 0);
01422 }

BOOL Library::ScanRestOfFile CCLexFile pSubIndex  )  [private]
 

Scan the rest of the file (following the START), creating items for each entry...

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/2/95
Parameters:
pSubIndex - points to a CCLexFile to be scanned. The file pointer on [INPUTS] entry is expected to be at the start of the index-file body.
Returns:
TRUE if it succeeded, FALSE if not. If no items were found, it returns FALSE

Definition at line 1443 of file sgscan.cpp.

01444 {
01445     ERROR3IF(pSubIndex == NULL, "Library::ScanRestOfFile - NULL params are illegal");
01446 
01447     BOOL ok = TRUE;
01448     BOOL retok = TRUE;
01449 
01450     LexTokenType TT;
01451     UINT32 LineCount = 0;
01452     ItemCount = 0;
01453     LibraryIndex LineOffset = 0;
01454 
01455     // Current file position is deemed the start of the first line of data
01456     FirstLineOffset = (LibraryIndex) pSubIndex->tellIn();
01457 
01458     while(ok && retok)
01459     {
01460         // Remember line offset for the *start* of the line
01461         LineOffset = (LibraryIndex) pSubIndex->tellIn();
01462 
01463         if(!pSubIndex->GetToken()) break;
01464 
01465         // Keep reading tokens until we hit a normal one... (skips line ends and
01466         // comments for us - we could do this by skipping lines at a time, but there
01467         // are problems with comments...
01468         TT = pSubIndex->GetTokenType();     
01469         while (TT != TOKEN_NORMAL && ok)
01470         {
01471             // Remember line offset for the *start* of the line
01472             LineOffset = (LibraryIndex) pSubIndex->tellIn();
01473 
01474             ok = pSubIndex->GetToken();
01475             if(!ok) break;
01476             TT = pSubIndex->GetTokenType();     
01477             ok = (TT != TOKEN_EOF);
01478             if(!ok) break;
01479         }
01480         if(!ok) break;
01481 
01482         // Create a supergallery Display Item representing this library item, and add it
01483         // to our parent group
01484 
01485         ok = (ParentGallery->AddLibraryItem(ParentGroup, this, LineOffset) != NULL);
01486 
01487         if(ok) ItemCount ++;
01488         else break;
01489 
01490         // Search for EOF or EOL after reading a line
01491         TT = pSubIndex->GetTokenType();     
01492 
01493         while (TT != TOKEN_EOF && TT != TOKEN_EOL && TT != TOKEN_LINE && ok)
01494         {
01495             // Remember line offset for the *start* of the line
01496             LineOffset = (LibraryIndex) pSubIndex->tellIn();
01497 
01498             ok = pSubIndex->GetToken();
01499             if(!ok) break;
01500             TT = pSubIndex->GetTokenType();     
01501             ok = (TT != TOKEN_EOF);
01502             if(!ok) break;
01503         }
01504     }
01505 
01506     // Current file position is deemed the start of the first line of data
01507     LastLineOffset = (LibraryIndex) pSubIndex->tellIn();
01508 
01509     return (ItemCount > 0);
01510 }

void Library::SetModified UINT32  nModified  )  [inline]
 

Definition at line 201 of file sgscan.h.

00201 { m_nModified = nModified;};

BOOL Library::SetUpMembers SuperGallery ParentGal,
PathName Path,
String_64 SLTitle,
StringBase SubI,
SGLibType  SLType
[private]
 

Fill in the member variables with the required paths, and things... Should only be called from Init.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/5/95
Parameters:
ParentGal - The parent gallery into which the group should be added. [INPUTS] Path - The pathname of the library directory - C: SLTitle - The title text for this sublibrary SubI - The SubIndex filename - XaraClip.txt SLType - The expected type of the sublibrary
Returns:
TRUE if things went OK...

Definition at line 875 of file sgscan.cpp.

00877 {
00878     ERROR3IF(ParentGal == NULL || Path == NULL || SLTitle == NULL || SubI == NULL, "Library::SetUpMembers - NULL parameters are illegal");
00879 
00880 //  String_256 P(Path->GetPath());
00881 //  ERROR3_PF(("Path = %s", (TCHAR *)P));
00882 
00883     ParentGallery = ParentGal;
00884 
00885     // Number of (active) items in sub-lib
00886     ItemCount = 0;
00887 
00888     // Field string found at the head of the sub-index 
00889     FieldString = "";
00890 
00891     // Type of Sub-Library
00892     Type = SLType;
00893 
00894     // Title text as given in main index file (used for the group name)
00895     // "A group containing pictures of animals" for example
00896     if(Title == NULL)
00897     {
00898         Title = new String_64(*SLTitle);
00899         if (Title == NULL)
00900             return FALSE;
00901     }
00902 
00903     // Add index path to index filename
00904     String_256 General(Path->GetPath(TRUE));
00905     General += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
00906     General += TEXT("\\");
00907     General += *SubI;
00908 
00909     // IndexFile now contains the full path to the index filename
00910     // "C:\testlib\animals\xarainfo\xaraclip.txt" for example
00911     if(IndexFile == NULL)
00912     {
00913         IndexFile = new PathName(General);
00914         if (IndexFile == NULL)
00915             return FALSE;
00916     }
00917 
00918     if(!IndexFile->IsValid())
00919     {
00920         ERROR3("Library::SetUpMembers indexfile is invalid");
00921         return FALSE;
00922     }
00923 
00924     // Full path of library directory -> C:\testlib\animals
00925     if(SubLibPath == NULL)
00926     {
00927         SubLibPath = new PathName(*Path);
00928         if(SubLibPath == NULL)
00929             return FALSE;
00930     }
00931 
00932     if(!SubLibPath->IsValid())
00933     {
00934         ERROR3("Library::SetUpMembers SubLibPath is invalid");
00935         return FALSE;
00936     }
00937 
00938     // For checking the Offsets...
00939     FirstLineOffset = 0;
00940     LastLineOffset = 0;
00941 
00942     return TRUE;
00943 }

BOOL Library::SetupQuickIndexMembers PathName Path,
BOOL  CheckTheyExist
[private]
 

Given a normal index file path, set up members to a 'quick index file'. The idea is for groups of library directories to have copies of all their indexes in some common folder so that loading them in doesn't thrash the CD drive too much.

Author:
Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/1/96
Parameters:
Path - Path for normal index [INPUTS] CheckTheyExist - Checks with the filesystem for the file's existance
Returns:
TRUE if paths set up and files found Note: We will ALWAYS return FALSE if CheckTheyExist is FALSE

Definition at line 967 of file sgscan.cpp.

00968 {
00969     QuickIndexEnabled = FALSE;
00970 
00971     // Quick indexes are just a slight bodge for speeding up the gallery opening times with
00972     // CD's... Basically instead of hunting all over the place for indexes, we stick all the
00973     // indexes down the XaraInfo directory (with the main index.txt), and open these instead
00974     // of the normal ones... If these don't exist, then obviously we can't use them...
00975     if(Library::QuickIndex)
00976     {
00977         // Work out Quick path
00978         PathName QuickPath(Path->GetPath());
00979         String_256 QuickPathLoc(QuickPath.GetLocation(FALSE));
00980         QuickPathLoc += TEXT("\\") + String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME)) + TEXT("\\");
00981         QuickPathLoc += Path->GetFileName(FALSE);
00982         QuickPathLoc += TEXT(".txt");
00983         QuickPath.SetPathName(QuickPathLoc);
00984         
00985         if(CheckTheyExist && SGLibOil::FileExists(&QuickPath))
00986         {
00987             if(QuickIndexFile == NULL)
00988             {
00989                 QuickIndexFile = new PathName(QuickPathLoc);
00990                         
00991                 if(QuickIndexFile != NULL)
00992                     QuickIndexEnabled = TRUE;
00993             }
00994         }
00995 
00996         Error::ClearError();
00997     }
00998 
00999     return QuickIndexEnabled;
01000 }


Friends And Related Function Documentation

friend class LibClipartSGallery [friend]
 

Definition at line 141 of file sgscan.h.

friend class LibraryGallery [friend]
 

Definition at line 142 of file sgscan.h.


Member Data Documentation

BOOL Library::BackgroundRedraw = TRUE [static]
 

Definition at line 392 of file sgscan.h.

INT32 Library::CachedBufLength [protected]
 

Definition at line 364 of file sgscan.h.

TCHAR* Library::CachedSubIndexBuf [protected]
 

Definition at line 361 of file sgscan.h.

BOOL Library::CacheIndexFile = TRUE [static]
 

Definition at line 395 of file sgscan.h.

SGFieldCache* Library::FieldCache [protected]
 

Definition at line 380 of file sgscan.h.

INT32 Library::FieldCacheEntries [protected]
 

Definition at line 379 of file sgscan.h.

String_256 Library::FieldString [protected]
 

Definition at line 302 of file sgscan.h.

LibraryIndex Library::FirstLineOffset [protected]
 

Definition at line 305 of file sgscan.h.

String_256 Library::g_ClipartLibraryPath = TEXT("") [static, private]
 

Definition at line 171 of file sgscan.h.

String_256 Library::g_FillsLibraryPath = TEXT("") [static, private]
 

Definition at line 174 of file sgscan.h.

String_256 Library::g_FontLibraryPath = TEXT("") [static, private]
 

Definition at line 173 of file sgscan.h.

String_256 Library::g_WebThemeLibraryPath = TEXT("") [static, private]
 

Definition at line 172 of file sgscan.h.

UINT32 Library::IndexDateStamp [protected]
 

Definition at line 311 of file sgscan.h.

PathName* Library::IndexFile
 

Definition at line 323 of file sgscan.h.

INT32 Library::ItemCount [protected]
 

Definition at line 300 of file sgscan.h.

LibraryIndex Library::LastLineOffset [protected]
 

Definition at line 306 of file sgscan.h.

BOOL Library::m_bIsWebLib
 

Definition at line 294 of file sgscan.h.

INT32 Library::m_lOldIndex [protected]
 

Definition at line 315 of file sgscan.h.

UINT32 Library::m_nModified [protected]
 

Definition at line 314 of file sgscan.h.

INT32 Library::MaxFieldCacheEntries = 25 [static]
 

Definition at line 389 of file sgscan.h.

SuperGallery* Library::ParentGallery
 

Definition at line 328 of file sgscan.h.

SGLibGroup* Library::ParentGroup
 

Definition at line 329 of file sgscan.h.

INT32 Library::PreviewX[3] [protected]
 

Definition at line 308 of file sgscan.h.

INT32 Library::PreviewY[3] [protected]
 

Definition at line 309 of file sgscan.h.

Progress * Library::ProgressBar = NULL [static]
 

Definition at line 369 of file sgscan.h.

BOOL Library::QuickIndex = TRUE [static]
 

Definition at line 404 of file sgscan.h.

BOOL Library::QuickIndexEnabled [protected]
 

Definition at line 384 of file sgscan.h.

PathName* Library::QuickIndexFile [protected]
 

Definition at line 385 of file sgscan.h.

BOOL Library::RemoteIndexes = TRUE [static]
 

Definition at line 398 of file sgscan.h.

String_256 Library::RemoteIndexLocation = "" [static]
 

Definition at line 401 of file sgscan.h.

PathName* Library::SubLibPath
 

Definition at line 324 of file sgscan.h.

PathName* Library::SynonymFile
 

Definition at line 325 of file sgscan.h.

SGThumbs* Library::Thumbnails
 

Definition at line 332 of file sgscan.h.

String_64* Library::Title
 

Definition at line 321 of file sgscan.h.

SGLibType Library::Type [protected]
 

Definition at line 298 of file sgscan.h.

String_256 Library::URLBase = _T("") [static]
 

Definition at line 292 of file sgscan.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:55:52 2007 for Camelot by  doxygen 1.4.4