#include <sgscanf.h>
Inheritance diagram for LibraryFile:
Public Member Functions | |
LibraryFile () | |
Constructor. | |
~LibraryFile () | |
Destructor. | |
INT32 | Init (SuperGallery *ParentGal, PathName *Path, SGLibType Type, BOOL Updated=FALSE, BOOL DoScroll=TRUE) |
The main entry point for the galleries... Locates and runs through each entry in the main index file, if the entry matches the given type, we go and create a group for the sub-lib, and add all the items in the sub-lib to it... Returns number of groups created (0 indicates a possible problem). | |
BOOL | AddSpecificIndex (SuperGallery *ParentGal, PathName *Path, SGLibType Type, StringBase *Description=NULL, UINT32 bModified=0, BOOL bIsWebLib=FALSE) |
Adds a specific index to the gallery. | |
List * | GetLibraryList (void) |
Returns a pointer to the LibraryFile's list of available libraries. You should treat this list as READ ONLY. | |
PathName * | GetLibraryPathName (void) |
To determine the pathname with which this library was initialised. | |
SGLibType | GetLibraryType (void) |
To determine the librry type of this library file and its Libraries. | |
BOOL | CheckForSubIndexes (SuperGallery *ParentGal, PathName *Path, SGLibType Type, BOOL Updated=FALSE) |
Checks for default sublibrary indexes. If there are non, and we have the technology, give the user the option to create one, and then use that. | |
void | DoScrollRedraw (void) |
Scrolls to newly added groups... | |
Static Public Member Functions | |
static BOOL | KillLeadingSpaces (StringBase *Str) |
Strip any leading AND NOW TRAILING spaces from the given string. | |
static BOOL | GenerateDefaultIndex (PathName *IndexFile, PathName *LibDirPath, String_64 *Author, SGLibType Type, BOOL Thumbnails) |
Generates a dummy index file for a directory of say .art files. | |
static BOOL | GetSubIndexDetails (LibraryGallery *LG, String_256 *DefaultIndex, String_256 *IndexDesc, BOOL *CanGenerate) |
Return various library specific details. | |
static BOOL | TidyUpSubPath (String_256 *Str) |
Removes trailing backslashes and trailing xarainfo's from the string. This means we can browse to a xarainfo directory then jump back a place to get the correct library subpath, etc... | |
static INT32 | CountLines (PathName *IndexFilePath) |
Count number of valid lines in a file. | |
Public Attributes | |
List | Libraries |
SuperGallery * | ParentGallery |
LibraryGallery * | ParentLibraryGallery |
Static Public Attributes | |
static Library * | FirstLibraryAdded = NULL |
static Library * | LastLibraryAdded = NULL |
Protected Member Functions | |
void | InitScrollRedrawSystem (void) |
Resets the static vars... Notes:. | |
void | AddNewFolderToScrollRedrawSystem (Library *NewFolder) |
Adds a new library to the Scroll / redraw system Notes:. | |
Protected Attributes | |
PathName | MyPath |
SGLibType | MyType |
Definition at line 124 of file sgscanf.h.
|
Constructor.
Definition at line 149 of file sgscanf.cpp. 00150 { 00151 ParentGallery = NULL; 00152 ParentLibraryGallery = NULL; 00153 MyType = SGLib_Blank; 00154 InitScrollRedrawSystem(); 00155 }
|
|
Destructor.
Definition at line 170 of file sgscanf.cpp. 00171 { 00172 // Delete any live libraries. They will inform the gallery as they die 00173 if (!Libraries.IsEmpty()) 00174 Libraries.DeleteAll(); 00175 00176 TRACEUSER( "Richard", _T("~LibraryFile called\n")); 00177 }
|
|
Adds a new library to the Scroll / redraw system Notes:.
Definition at line 1191 of file sgscanf.cpp. 01192 { 01193 // Keep track of libraries added for redraw purposes... 01194 if(FirstLibraryAdded == NULL) 01195 FirstLibraryAdded = NewFolder; 01196 LastLibraryAdded = NewFolder; 01197 }
|
|
Adds a specific index to the gallery.
This function can be used in preference to Init Definition at line 831 of file sgscanf.cpp. 00833 { 00834 if(ParentGal == NULL || Path == NULL || !Libraries.IsEmpty() || !Path->IsValid()) 00835 { 00836 ERROR3("LibraryFile::AddSpecificIndex - Problems on entry"); 00837 return FALSE; 00838 } 00839 00840 // Check the path for the library exists 00841 // if(!SGLibOil::FileExists(Path)) 00842 // return FALSE; 00843 00844 // Remember the pathname and type 00845 MyPath = *Path; 00846 MyType = Type; 00847 ParentGallery = ParentGal; 00848 00849 // Create the sub lib 00850 Library *NewSubLib = new Library; 00851 00852 if (NewSubLib != NULL) 00853 { 00854 // Path = "C:\testlib\animals\xarainfo\animals.txt" 00855 // Path of files themselves... FilesPath = "C:\testlib\animals" 00856 NewSubLib->m_bIsWebLib = bIsWebLib; 00857 PathName TmpPath(Path->GetLocation(FALSE)); 00858 NewSubLib->SetModified(bModified); 00859 00860 // If it's a root directory we need the slash... 00861 PathName FilesPath; 00862 String_256 TmpRootCheck(TmpPath.GetLocation(TRUE)); 00863 if(SGLibOil::IsRootDirectory(&TmpRootCheck)) 00864 FilesPath.SetPathName(TmpPath.GetLocation(TRUE)); 00865 else 00866 FilesPath.SetPathName(TmpPath.GetLocation(FALSE)); 00867 00868 // Default title for the new group 00869 String_256 Desc256; 00870 String_64 Desc64; 00871 if(Description == NULL) 00872 Desc256 = Path->GetTruncatedPath(60); 00873 else 00874 Desc256 = *Description; 00875 Desc256.Left(&Desc64, 64); 00876 00877 // The filename of the index 00878 String_64 IndexFilename(Path->GetFileName(TRUE)); 00879 00880 // Add this new index to the library file and scan it in... 00881 if(NewSubLib->Init(ParentGal, &FilesPath, &Desc64, &IndexFilename, Type, FALSE, (Description != NULL))) 00882 { 00883 Libraries.AddTail(NewSubLib); 00884 00885 // Keep track of libraries added for redraw purposes... 00886 AddNewFolderToScrollRedrawSystem(NewSubLib); 00887 00888 return TRUE; 00889 } 00890 else 00891 { 00892 // if there was a problem, don't go round leaving memory everywhere... 00893 delete NewSubLib; 00894 NewSubLib = NULL; 00895 } 00896 } 00897 00898 // Nothing added 00899 return FALSE; 00900 }
|
|
Checks for default sublibrary indexes. If there are non, and we have the technology, give the user the option to create one, and then use that.
Definition at line 636 of file sgscanf.cpp. 00637 { 00638 // The directory given had no XaraInfo\index.txt file, maybe it's a sublib, check 00639 // For defaults... 00640 00641 String_256 DefaultIndex; 00642 String_256 IndexDesc; 00643 BOOL CanGenerate; 00644 BOOL ok = TRUE; 00645 00646 // Need to reset the Quiet status before a stream of Library::Init calls 00647 ParentLibraryGallery->SetQuietStatus(FALSE); 00648 00649 if(GetSubIndexDetails(ParentLibraryGallery, &DefaultIndex, &IndexDesc, &CanGenerate)) 00650 { 00651 String_256 SubP(Path->GetPath(TRUE)); // "%s\\XaraInfo\\%s" 00652 SubP += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME)); 00653 SubP += TEXT("\\") + DefaultIndex; 00654 PathName SubPath(SubP); 00655 if(!SubPath.IsValid()) 00656 { 00657 ERROR3("LibraryFile::CheckForSubIndexes invalid subpath"); 00658 return FALSE; 00659 } 00660 00661 BOOL Generate = FALSE; 00662 BOOL Found = FALSE; 00663 00664 // Is there a default sub index ? 00665 Found = SGLibOil::FileExists(&SubPath); 00666 00667 if(!Found && CanGenerate) 00668 { 00669 if(Library::RemoteIndexes && GenerateIndexFile::IsDirectoryReadOnly(Path)) 00670 { 00671 // Check whether there's a 'temporary' index for this directory, and 00672 // possibly use that instead of the read only directory... 00673 00674 String_256 RemoteLocationOfIndex; 00675 BOOL Existing = GenerateIndexFile::CheckForRemote(Path, &RemoteLocationOfIndex); 00676 00677 if(Existing) 00678 { 00679 String_256 SubP(RemoteLocationOfIndex); // %s\\XaraInfo\\%s 00680 SGLibOil::AppendSlashIfNotPresent(&SubP); 00681 SubP += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME)); 00682 SubP += TEXT("\\") + DefaultIndex; 00683 PathName TmpSubPath(SubP); 00684 00685 Found = SGLibOil::FileExists(&TmpSubPath); 00686 00687 // OK, so there's a remote index sitting pretty in the user's temporary 00688 // location... Use that and don't bother generating a new one... 00689 if(Found) 00690 { 00691 SubPath.SetPathName(SubP); 00692 Path->SetPathName(RemoteLocationOfIndex); 00693 } 00694 } 00695 } 00696 00697 if(!Found) 00698 { 00699 // tell the user that there is no index file, and ask if they want one generating 00700 String_256 WarnMsg; 00701 String_256 TmpPath(SubPath.GetLocation(FALSE)); 00702 LibraryFile::TidyUpSubPath(&TmpPath); 00703 WarnMsg.MakeMsg(_R(IDS_LIBRARY_NO_INDEX_FILE_GEN), (TCHAR *)IndexDesc, (TCHAR *)TmpPath); 00704 Error::SetError(0, WarnMsg, 0); 00705 //INT32 ButtonPressed = InformMessage(0, _R(IDS_NOTHUMBNAILS), _R(IDS_THUMBNAILS), _R(IDS_CANCEL)/*, _R(IDS_HELP)*/); 00706 INT32 ButtonPressed = InformMessage(0, _R(IDS_CREATE), _R(IDS_CANCEL)); 00707 Error::ClearError(); 00708 00709 if(ButtonPressed < 2) 00710 { 00711 // Generate an index... 00712 String_64 Author(PRODUCT_NAME); 00713 Generate = GenerateDefaultIndex(&SubPath, Path, &Author, Type, TRUE); 00714 ok = TRUE; 00715 } 00716 else 00717 { 00718 // Cancel or help clicked 00719 ok = FALSE; 00720 } 00721 } 00722 } 00723 00724 if(!Found && !CanGenerate) 00725 { 00726 // tell the user that there is no index file, and give them a cancel... 00727 String_256 WarnMsg; 00728 String_256 TmpPath(SubPath.GetLocation(FALSE)); 00729 LibraryFile::TidyUpSubPath(&TmpPath); 00730 WarnMsg.MakeMsg(_R(IDS_LIBRARY_NO_INDEX_FILE), (TCHAR *)IndexDesc, (TCHAR *)TmpPath); 00731 Error::SetError(0, WarnMsg, 0); 00732 INT32 ButtonPressed = InformWarning(0, _R(IDS_CANCEL), NULL); 00733 Error::ClearError(); 00734 ok = FALSE; 00735 } 00736 00737 // Check again... 00738 Found = SGLibOil::FileExists(&SubPath); 00739 00740 if((Found && ok) || (!Found && Generate && ok)) 00741 { 00742 String_256 Description256 = Path->GetPath(); 00743 AbbreviateName(Description256, 60, TRUE); 00744 00745 String_64 Description(Description256); 00746 BOOL DoAgain = TRUE; 00747 while (DoAgain) 00748 { 00749 DoAgain = FALSE; 00750 00751 // Create the sub lib 00752 Library *NewSubLib = new Library; 00753 00754 if (NewSubLib != NULL) 00755 { 00756 String_64 DefIndex64(DefaultIndex); 00757 String_256 PathToAdd256 = SubPath.GetLocation(FALSE); 00758 TidyUpSubPath(&PathToAdd256); 00759 PathName PathToAdd(PathToAdd256); 00760 Error::ClearError(); 00761 00762 // Create the actual group itself 00763 if(NewSubLib->Init(ParentGal, &PathToAdd, &Description, &DefIndex64, Type, Updated)) 00764 { 00765 Libraries.AddTail(NewSubLib); 00766 00767 ok = TRUE; 00768 00769 // Keep track of libraries added for redraw purposes... 00770 AddNewFolderToScrollRedrawSystem(NewSubLib); 00771 } 00772 else 00773 { 00774 delete NewSubLib; 00775 NewSubLib = NULL; 00776 00777 String_256 WarnMsg; 00778 String_256 SmallPath; 00779 PathToAdd256.Left(&SmallPath, 150); 00780 00781 // "The index for '%s' seems to be invalid and requires updating." 00782 WarnMsg.MakeMsg(_R(IDS_LIBRARY_DODGY_INDEX), (TCHAR *)SmallPath); 00783 Error::SetError(0, WarnMsg, 0); 00784 INT32 Button = InformWarning(0, _R(IDS_GENERATE), _R(IDS_CANCEL)); 00785 Error::ClearError(); 00786 00787 String_256 IPathToAdd256(PathToAdd256); 00788 SGLibOil::AppendSlashIfNotPresent(&IPathToAdd256); 00789 IPathToAdd256 += TEXT("indexfle.txt"); // This is just to check we can write ok... 00790 PathName IPathToAdd(IPathToAdd256); 00791 00792 if(Button == 1) 00793 DoAgain = SGLibOil::GenerateClicked(ParentLibraryGallery, &IPathToAdd); 00794 00795 if(!DoAgain) 00796 ok = FALSE; 00797 00798 Error::ClearError(); 00799 } 00800 } 00801 } 00802 } 00803 } 00804 return ok; 00805 }
|
|
Count number of valid lines in a file.
Definition at line 984 of file sgscanf.cpp. 00985 { 00986 INT32 Count = 0; 00987 00988 CCDiskFile TmpDiskFile; 00989 if (!TmpDiskFile.InitLexer(FALSE)) 00990 { 00991 ERROR3("Library::CountLines - Problems with InitLexer"); 00992 return 0; 00993 } 00994 00995 if (TmpDiskFile.open(*IndexFilePath, ios::in)) 00996 { 00997 BOOL Finished = FALSE;; 00998 LexTokenType TokType = TOKEN_LINE; 00999 while(TmpDiskFile.GetLineToken() && TokType != TOKEN_EOF) 01000 { 01001 TokType = TmpDiskFile.GetTokenType(); 01002 if(TokType == TOKEN_LINE) 01003 Count ++; 01004 } 01005 } 01006 01007 // reclaim lexer-buffer memory 01008 TmpDiskFile.DeinitLexer(); 01009 01010 if(TmpDiskFile.isOpen()) 01011 TmpDiskFile.close(); 01012 01013 return Count; 01014 }
|
|
Scrolls to newly added groups...
Definition at line 1210 of file sgscanf.cpp. 01211 { 01212 // Scroll / redraw the newly added groups... 01213 if(FirstLibraryAdded != NULL && LastLibraryAdded != NULL) 01214 { 01215 SGLibGroup *FirstGroup = FirstLibraryAdded->ParentGroup; 01216 SGLibGroup *SecondGroup = LastLibraryAdded->ParentGroup; 01217 01218 if(FirstGroup != NULL && SecondGroup != NULL) 01219 { 01220 // Redraw whatever we need to and reformat the gallery ready for poking... 01221 ParentGallery->ReformatAndRedrawIfNecessary(); 01222 01223 // Calculate where the new folders are... 01224 DocRect ScrollToRect; 01225 FirstGroup->GetFormatRect(&ScrollToRect); 01226 if(SecondGroup != FirstGroup) 01227 { 01228 DocRect TempRect; 01229 FirstGroup->GetFormatRect(&TempRect); 01230 ScrollToRect = ScrollToRect.Union(TempRect); 01231 } 01232 01233 // Actually do the scroll... 01234 ParentGallery->ScrollToShow(&ScrollToRect, TRUE); 01235 } 01236 } 01237 }
|
|
Generates a dummy index file for a directory of say .art files.
Definition at line 1132 of file sgscanf.cpp. 01134 { 01135 if(IndexFile == NULL || LibDirPath == NULL) 01136 { 01137 ERROR3("LibraryFile::GenerateDefaultIndex null params are bad"); 01138 return FALSE; 01139 } 01140 01141 GenerateIndexFile TmpGen; 01142 BOOL ok = TmpGen.Generate(IndexFile, LibDirPath, Author, Type, Thumbnails); 01143 01144 return ok; 01145 }
|
|
Returns a pointer to the LibraryFile's list of available libraries. You should treat this list as READ ONLY.
Definition at line 212 of file sgscanf.h. 00213 { 00214 return(&Libraries); 00215 }
|
|
To determine the pathname with which this library was initialised.
Definition at line 1078 of file sgscanf.cpp. 01079 { 01080 // Did the client forget to call Init() before calling this method? 01081 ERROR3IF(MyType == SGLib_Blank, "This LibraryFile has not been properly initialised!"); 01082 01083 return(&MyPath); 01084 }
|
|
To determine the librry type of this library file and its Libraries.
Definition at line 1103 of file sgscanf.cpp. 01104 { 01105 // Did the client forget to call Init() before calling this method? 01106 ERROR3IF(MyType == SGLib_Blank, "This LibraryFile has not been properly initialised!"); 01107 01108 return(MyType); 01109 }
|
|
Return various library specific details.
Definition at line 587 of file sgscanf.cpp. 00589 { 00590 if(DefaultIndex == NULL || IndexDesc == NULL || CanGenerate == NULL || LG == NULL) 00591 { 00592 ERROR3("LibraryFile::GetSubIndexDetails given null params"); 00593 return FALSE; 00594 } 00595 00596 if(LG == NULL) 00597 { 00598 ERROR3("LibraryFile::GetSubIndexDetails called when there was a NULL ParentLibraryGallery"); 00599 *CanGenerate = FALSE; 00600 } 00601 else 00602 { 00603 // Get pathname of default sublib index and find out whether we can generate indexes, etc 00604 *CanGenerate = LG->CanCreateIndexes(); 00605 return(LG->GetDefaults(DefaultIndex, IndexDesc, NULL)); 00606 } 00607 00608 return FALSE; 00609 }
|
|
The main entry point for the galleries... Locates and runs through each entry in the main index file, if the entry matches the given type, we go and create a group for the sub-lib, and add all the items in the sub-lib to it... Returns number of groups created (0 indicates a possible problem).
This function needs splitting and tidying up sometime...
Definition at line 215 of file sgscanf.cpp. 00216 { 00217 #ifndef EXCLUDE_GALS 00218 if(ParentGal == NULL || APath == NULL || !Libraries.IsEmpty()) 00219 { 00220 ERROR3("LibraryFile::Init - NULL parameters are illegal OR Init called > 1 times"); 00221 if(!Libraries.IsEmpty()) 00222 return(Libraries.GetCount()); 00223 else 00224 return 0; 00225 } 00226 00227 BOOL ok = TRUE; 00228 00229 // Tidy up Path a bit 00230 String_256 OurPath(APath->GetPath()); 00231 LibraryFile::TidyUpSubPath(&OurPath); 00232 00233 // Now point Path to the new pathname 00234 PathName ModifiedPath(OurPath); 00235 PathName *Path = &ModifiedPath; 00236 00237 if(!ModifiedPath.IsValid()) 00238 { 00239 ERROR3("LibraryFile::Init -> Modified library path is invalid"); 00240 return 0; 00241 } 00242 00243 // Remember the pathname and type 00244 MyPath = *Path; 00245 MyType = Type; 00246 00247 ParentGallery = ParentGal; 00248 if(ParentGallery->IsKindOf(CC_RUNTIME_CLASS(LibraryGallery))) 00249 ParentLibraryGallery = (LibraryGallery *)ParentGal; 00250 else 00251 { 00252 ERROR3("LibraryFile::Init passed a non-library gallery - yikes..."); 00253 return 0; 00254 } 00255 00256 // Need to reset the Quiet status before a stream of Library::Init calls 00257 ParentLibraryGallery->SetQuietStatus(FALSE); 00258 00259 BOOL Retry = TRUE; 00260 while(Retry) 00261 { 00262 Retry = FALSE; 00263 00264 // Would be nice to have a way of adding a file to a path in PathName... Is there one ? 00265 if(!SGLibOil::FileExists(Path)) 00266 { 00267 // We're opening the font gallery, but can't find the font library path - don't warn 00268 if(Type == SGLib_Font) 00269 return 0; 00270 00271 // tell the user that the directory doesn't exist 00272 String_256 WarnMsg; 00273 String_256 DefaultIndex; 00274 String_256 IndexDesc; 00275 BOOL CanGenerate; 00276 00277 ok = LibraryFile::GetSubIndexDetails(ParentLibraryGallery, &DefaultIndex, &IndexDesc, &CanGenerate); 00278 00279 String_256 TmpPath(Path->GetLocation(FALSE)); 00280 LibraryFile::TidyUpSubPath(&TmpPath); 00281 00282 // Taken out by Graham 30/10/97: If the gallery had no directory specified, 00283 //we used to throw a warning which said "do you want to specify another folder?" 00284 //We don't do this any more, because the default is to open all galleries empty and 00285 //then download stuff from the Xara web site 00286 #if 0 00287 WarnMsg.MakeMsg(_R(IDS_BROWSE_OR_SCAN), (TCHAR *)IndexDesc, (TCHAR *)TmpPath); 00288 Error::SetError(0, WarnMsg, 0); 00289 INT32 ButtonPressed = InformWarning(0, _R(IDS_BROWSE), _R(IDS_RETRY), _R(IDS_CANCEL)/*, _R(IDS_HELP)*/); 00290 #else // WEBSTER 00291 INT32 ButtonPressed = 3; 00292 #endif // WEBSTER 00293 TRACEUSER( "Richard", _T("ButtonPressed: %d\n"), ButtonPressed); 00294 Error::ClearError(); 00295 switch(ButtonPressed) 00296 { 00297 case 1: 00298 { 00299 // Open the Browse dialog (or the Add.. dialog as it seems to be called now) 00300 PathName ThePath(*Path); 00301 00302 // This returns FALSE if Cancel was hit, or an error occurred. 00303 if(!SGLibOil::GetLibPath(ParentLibraryGallery, &ThePath, CanGenerate, Type)) 00304 { 00305 ERROR3("GetLibPath returned FALSE in LF::Init"); 00306 return 0; 00307 } 00308 else 00309 { 00310 ModifiedPath = ThePath; 00311 if(!ModifiedPath.IsValid()) 00312 { 00313 ERROR3("LibraryFile::Init -> scanned library path is invalid"); 00314 return 0; 00315 } 00316 00317 // Remember the pathname 00318 MyPath = ThePath; 00319 00320 switch(Type) 00321 { 00322 case SGLib_ClipArt: 00323 case SGLib_Bitmap: 00324 LibClipartSGallery::DefaultLibraryPath = MyPath.GetPath(); 00325 LibClipartSGallery::ClipartPath = LibClipartSGallery::DefaultLibraryPath; 00326 break; 00327 00328 case SGLib_ClipArt_WebThemes: 00329 LibClipartSGallery::DefaultLibraryPath = MyPath.GetPath(); 00330 LibClipartSGallery::WebThemePath = LibClipartSGallery::DefaultLibraryPath; 00331 break; 00332 00333 #ifndef STANDALONE 00334 case SGLib_Texture: 00335 case SGLib_Fractal: 00336 LibFillsSGallery::DefaultLibraryPath = MyPath.GetPath(); 00337 break; 00338 00339 case SGLib_Font: 00340 // WEBSTER-Martin-09/01/97 - Put back by Ranbir. 00341 //#ifndef WEBSTER 00342 FontsSGallery::DefaultLibraryPath = MyPath.GetPath(); 00343 break; // Not in webster so we get the error below 00344 //#endif // WEBSTER 00345 #endif 00346 default: 00347 ERROR2(FALSE,"Library::ScanForLocation Type not present!"); 00348 break; 00349 } 00350 } 00351 break; 00352 } 00353 00354 case 2: 00355 Retry = TRUE; 00356 #if 0 00357 { 00358 // Scan 00359 String_256 Result; 00360 if(!Library::ScanForLocation(Type, &Result)) 00361 { 00362 ERROR3("No libraries found..."); 00363 return 0; 00364 } 00365 00366 if(!ModifiedPath.SetPathName(Result)) 00367 { 00368 ERROR3("LibraryFile::Init -> scanned library path is invalid"); 00369 return 0; 00370 } 00371 00372 // Remember the pathname and type 00373 MyPath = *Path; 00374 } 00375 #endif 00376 break; 00377 00378 case 3: 00379 // Cancel 00380 return 0; 00381 } 00382 } 00383 } 00384 00385 // Wipe libraries added to gallery for scroll / redraw purposes... 00386 InitScrollRedrawSystem(); 00387 00388 // Check the actual path exists 00389 if(SGLibOil::FileExists(Path)) 00390 { 00391 // Would be nice to have a way of adding a file to a path in PathName... Is there one ? 00392 String_256 IndexFile((const TCHAR *)Path->GetPath(TRUE)); // "%s\\XaraInfo\\index.txt" 00393 IndexFile += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME)); 00394 IndexFile += TEXT("\\") + String_16(_R(IDS_LIBRARIES_INDEX_FILENAME)); 00395 00396 PathName IndexFilePath(IndexFile); 00397 if(!IndexFilePath.IsValid()) 00398 { 00399 ERROR3("LibraryFile::Init indexfilepath is invalid"); 00400 return 0; 00401 } 00402 00403 CCDiskFile MainIndex; 00404 if (!MainIndex.InitLexer(FALSE)) 00405 { 00406 // SetError! 00407 ERROR3("LibraryFile::LibraryFile InitLexer failed"); 00408 return(0); 00409 } 00410 00411 if(SGLibOil::FileExists(&IndexFilePath)) 00412 { 00413 // Count lines in index file 00414 INT32 Count = CountLines(&IndexFilePath); 00415 00416 TRACEUSER( "Richard", _T("%d lines in index file\n"), Count); 00417 00418 // Used for the percentage display 00419 INT32 CurrentGroupNumber = 0; 00420 00421 // Just in case there's a slow job already going on... 00422 SmashSlowJob(); 00423 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING)); 00424 BeginSlowJob(Count, FALSE, &SlowJob); 00425 00426 // Now use the index file to create each group in turn 00427 if (MainIndex.open(IndexFilePath, ios::in)) 00428 { 00429 MainIndex.SetWhitespace(""); // Setting this to blank lets us read non-"'d strings 00430 MainIndex.SetDelimiters(","); // ,s delimit our fields 00431 MainIndex.SetCommentMarker('#'); // #'d lines are commented out 00432 MainIndex.SetStringDelimiters(""); // No string delimiters 00433 00434 String_64 Directory; 00435 String_64 Description; 00436 String_64 SubIndex; 00437 String_64 Kind; 00438 LexTokenType TT; 00439 00440 BOOL EscapePressed = FALSE; 00441 00442 while(ok && !EscapePressed) 00443 { 00444 if(!MainIndex.GetToken()) break; // Get SubLib directory name 00445 00446 // Keep reading tokens until we hit a normal one... (skips line ends and 00447 // comments for us 00448 TT = MainIndex.GetTokenType(); 00449 while (TT != TOKEN_NORMAL && ok) 00450 { 00451 ok = MainIndex.GetToken(); 00452 if(!ok) break; 00453 TT = MainIndex.GetTokenType(); 00454 ok = (TT != TOKEN_EOF); 00455 if(!ok) break; 00456 } 00457 if(!ok) break; 00458 00459 Directory = MainIndex.GetTokenBuf(); 00460 KillLeadingSpaces(&Directory); 00461 00462 if(!MainIndex.GetToken()) break; // Get ',' 00463 if(!MainIndex.GetToken()) break; // Get Description 00464 String_256 Description256; 00465 Description256 = MainIndex.GetTokenBuf(); 00466 KillLeadingSpaces(&Description256); 00467 Description256.Left(&Description, 60); 00468 00469 if(!MainIndex.GetToken()) break; // Get ',' 00470 if(!MainIndex.GetToken()) break; // Get Sub Library Index name 00471 SubIndex = MainIndex.GetTokenBuf(); 00472 KillLeadingSpaces(&SubIndex); 00473 00474 if(!MainIndex.GetToken()) break; // Get ',' 00475 if(!MainIndex.GetToken()) break; // Get type of files in sublib 00476 Kind = MainIndex.GetTokenBuf(); 00477 KillLeadingSpaces(&Kind); 00478 00479 BOOL Match = FALSE; 00480 Match = ParentLibraryGallery->CheckForIndexMatch(&Kind); 00481 00482 if(Match) 00483 { 00484 // Show status of additions 00485 EscapePressed = !ContinueSlowJob(CurrentGroupNumber++); 00486 00487 // Sort pathname of sublib directory out 00488 String_256 SubP(Path->GetPath(TRUE)); 00489 SubP += Directory; 00490 PathName SubPath(SubP); 00491 if(!SubPath.IsValid()) 00492 { 00493 ERROR3("LibraryFile::Init - invalid subpath"); 00494 if(MainIndex.isOpen()) 00495 MainIndex.close(); 00496 EndSlowJob(); 00497 return 0; 00498 } 00499 00500 // Go ahead and add the new group 00501 if(ok) 00502 { 00503 // Create the sub lib 00504 Library *NewSubLib = new Library; 00505 00506 if (NewSubLib != NULL) 00507 { 00508 // Create the new group in the gallery (note the TRUE for create a virtualised one if 00509 // we can to save time / memory) 00510 if(NewSubLib->Init(ParentGal, &SubPath, &Description, &SubIndex, Type, Updated, TRUE)) 00511 { 00512 Libraries.AddTail(NewSubLib); 00513 00514 // Keep track of libraries added for redraw purposes... 00515 AddNewFolderToScrollRedrawSystem(NewSubLib); 00516 } 00517 else 00518 { 00519 // This check is new, should be ok... 00520 delete NewSubLib; 00521 NewSubLib = NULL; 00522 ERROR3("Library::Init failed in LibraryFile::Init"); 00523 ok = FALSE; 00524 } 00525 } 00526 } 00527 } 00528 } 00529 00530 } else { 00531 // Failed to open the index file... 00532 00533 // SetError?! 00534 ERROR3("LibraryFile::LibraryFile couldn't open index file"); 00535 ok = FALSE; 00536 } 00537 00538 EndSlowJob(); 00539 00540 } else { 00541 // The directory given had no XaraInfo\index.txt file, maybe it's a sublib, check 00542 // For defaults... 00543 ok = CheckForSubIndexes(ParentGal, Path, Type, Updated); 00544 } 00545 00546 // reclaim lexer-buffer memory 00547 MainIndex.DeinitLexer(); 00548 00549 // And close the file 00550 if(MainIndex.isOpen()) 00551 MainIndex.close(); 00552 00553 // Scroll / redraw the newly added groups... 00554 if(DoScroll) 00555 DoScrollRedraw(); 00556 } 00557 else 00558 { 00559 TRACEUSER( "Richard", _T("Path doesn't exist\n")); 00560 } 00561 00562 // And return the number of items created 00563 return(Libraries.GetCount()); 00564 #endif 00565 return 0; 00566 }
|
|
Resets the static vars... Notes:.
Definition at line 1169 of file sgscanf.cpp. 01170 { 01171 FirstLibraryAdded = NULL; 01172 LastLibraryAdded = NULL; 01173 }
|
|
Strip any leading AND NOW TRAILING spaces from the given string.
Definition at line 1033 of file sgscanf.cpp. 01034 { 01035 ERROR3IF(Str == NULL, "LibraryFile::KillLeadingSpaces - NULL params are illegal"); 01036 01037 if( ((TCHAR *)(*Str))[0] != ' ' && ((TCHAR *)(*Str))[Str->Length()-1] != ' ') 01038 return TRUE; 01039 01040 INT32 Length = Str->Length(); 01041 INT32 FirstNonSpaceChar = 0; 01042 while (((TCHAR *)(*Str))[FirstNonSpaceChar] == ' ' && FirstNonSpaceChar < Length) 01043 FirstNonSpaceChar++; 01044 01045 if(FirstNonSpaceChar >= Length) 01046 *Str = ""; 01047 else 01048 { 01049 // Strip off trailing spaces... 01050 INT32 LastNonSpaceChar = Length; 01051 while (((TCHAR *)(*Str))[LastNonSpaceChar-1] == ' ' && LastNonSpaceChar > 0) 01052 LastNonSpaceChar--; 01053 01054 String_256 Str256; 01055 Str->Mid(&Str256, FirstNonSpaceChar, LastNonSpaceChar - FirstNonSpaceChar); 01056 *Str = Str256; 01057 } 01058 01059 return TRUE; 01060 }
|
|
Removes trailing backslashes and trailing xarainfo's from the string. This means we can browse to a xarainfo directory then jump back a place to get the correct library subpath, etc...
Definition at line 925 of file sgscanf.cpp. 00926 { 00927 if(Str == NULL) 00928 { 00929 ERROR3("LibraryFile::TidyUpSubPath given a null string"); 00930 return FALSE; 00931 } 00932 00933 String_256 OurPath(*Str); 00934 00935 // Remove a trailing '\' if there is one 00936 if(((TCHAR *)OurPath)[OurPath.Length() - 1] == '\\') 00937 { 00938 Str->Left(&OurPath, Str->Length() - 1); 00939 } 00940 00941 if(OurPath.Length() > 10) 00942 { 00943 // Remove a 'XaraInfo' if there is one on the end 00944 String_256 OurPathTmp(OurPath); 00945 String_16 RighthandSection; 00946 OurPathTmp.Right(&RighthandSection, 9); 00947 RighthandSection.toUpper(); 00948 00949 // \\XARAINFO 00950 String_16 XaraInfo("\\" + String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME_CAPS))); 00951 if(camStrcmp((TCHAR *)RighthandSection, (TCHAR *)XaraInfo) == 0) 00952 { 00953 // Use the un-uppered string to return 00954 OurPathTmp.Left(&OurPath, OurPath.Length() - 9); 00955 } 00956 } 00957 00958 // Check if root directory, if so, add in a trailing '\' (fixes root directory problems) 00959 if(SGLibOil::IsRootDirectory(&OurPath)) 00960 { 00961 //ERROR3("Drive name given - appending a slash"); 00962 OurPath += TEXT("\\"); 00963 } 00964 00965 *Str = OurPath; 00966 return TRUE; 00967 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|