00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104 #include "sgscanf.h"
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 #include "progress.h"
00115
00116 #include "sglib.h"
00117
00118 #include "sgfonts.h"
00119 #include "sglcart.h"
00120 #include "sglfills.h"
00121 #include "sgindgen.h"
00122 #include "sgliboil.h"
00123 #include "sglbase.h"
00124 #include "product.h"
00125
00126
00127 #include "mfccopy.h"
00128
00129 DECLARE_SOURCE("$Revision: 1282 $");
00130
00131 CC_IMPLEMENT_DYNCREATE(LibraryFile, ListItem)
00132
00133 #define new CAM_DEBUG_NEW
00134
00135 Library *LibraryFile::FirstLibraryAdded = NULL;
00136 Library *LibraryFile::LastLibraryAdded = NULL;
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 LibraryFile::LibraryFile()
00150 {
00151 ParentGallery = NULL;
00152 ParentLibraryGallery = NULL;
00153 MyType = SGLib_Blank;
00154 InitScrollRedrawSystem();
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 LibraryFile::~LibraryFile()
00171 {
00172
00173 if (!Libraries.IsEmpty())
00174 Libraries.DeleteAll();
00175
00176 TRACEUSER( "Richard", _T("~LibraryFile called\n"));
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 INT32 LibraryFile::Init(SuperGallery *ParentGal, PathName *APath, SGLibType Type, BOOL Updated, BOOL DoScroll)
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
00230 String_256 OurPath(APath->GetPath());
00231 LibraryFile::TidyUpSubPath(&OurPath);
00232
00233
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
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
00257 ParentLibraryGallery->SetQuietStatus(FALSE);
00258
00259 BOOL Retry = TRUE;
00260 while(Retry)
00261 {
00262 Retry = FALSE;
00263
00264
00265 if(!SGLibOil::FileExists(Path))
00266 {
00267
00268 if(Type == SGLib_Font)
00269 return 0;
00270
00271
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
00283
00284
00285
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));
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
00300 PathName ThePath(*Path);
00301
00302
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
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
00341
00342 FontsSGallery::DefaultLibraryPath = MyPath.GetPath();
00343 break;
00344
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
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
00373 MyPath = *Path;
00374 }
00375 #endif
00376 break;
00377
00378 case 3:
00379
00380 return 0;
00381 }
00382 }
00383 }
00384
00385
00386 InitScrollRedrawSystem();
00387
00388
00389 if(SGLibOil::FileExists(Path))
00390 {
00391
00392 String_256 IndexFile((const TCHAR *)Path->GetPath(TRUE));
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
00407 ERROR3("LibraryFile::LibraryFile InitLexer failed");
00408 return(0);
00409 }
00410
00411 if(SGLibOil::FileExists(&IndexFilePath))
00412 {
00413
00414 INT32 Count = CountLines(&IndexFilePath);
00415
00416 TRACEUSER( "Richard", _T("%d lines in index file\n"), Count);
00417
00418
00419 INT32 CurrentGroupNumber = 0;
00420
00421
00422 SmashSlowJob();
00423 String_64 SlowJob(_R(IDS_LIBRARY_SCANNING));
00424 BeginSlowJob(Count, FALSE, &SlowJob);
00425
00426
00427 if (MainIndex.open(IndexFilePath, ios::in))
00428 {
00429 MainIndex.SetWhitespace("");
00430 MainIndex.SetDelimiters(",");
00431 MainIndex.SetCommentMarker('#');
00432 MainIndex.SetStringDelimiters("");
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;
00445
00446
00447
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;
00463 if(!MainIndex.GetToken()) break;
00464 String_256 Description256;
00465 Description256 = MainIndex.GetTokenBuf();
00466 KillLeadingSpaces(&Description256);
00467 Description256.Left(&Description, 60);
00468
00469 if(!MainIndex.GetToken()) break;
00470 if(!MainIndex.GetToken()) break;
00471 SubIndex = MainIndex.GetTokenBuf();
00472 KillLeadingSpaces(&SubIndex);
00473
00474 if(!MainIndex.GetToken()) break;
00475 if(!MainIndex.GetToken()) break;
00476 Kind = MainIndex.GetTokenBuf();
00477 KillLeadingSpaces(&Kind);
00478
00479 BOOL Match = FALSE;
00480 Match = ParentLibraryGallery->CheckForIndexMatch(&Kind);
00481
00482 if(Match)
00483 {
00484
00485 EscapePressed = !ContinueSlowJob(CurrentGroupNumber++);
00486
00487
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
00501 if(ok)
00502 {
00503
00504 Library *NewSubLib = new Library;
00505
00506 if (NewSubLib != NULL)
00507 {
00508
00509
00510 if(NewSubLib->Init(ParentGal, &SubPath, &Description, &SubIndex, Type, Updated, TRUE))
00511 {
00512 Libraries.AddTail(NewSubLib);
00513
00514
00515 AddNewFolderToScrollRedrawSystem(NewSubLib);
00516 }
00517 else
00518 {
00519
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
00532
00533
00534 ERROR3("LibraryFile::LibraryFile couldn't open index file");
00535 ok = FALSE;
00536 }
00537
00538 EndSlowJob();
00539
00540 } else {
00541
00542
00543 ok = CheckForSubIndexes(ParentGal, Path, Type, Updated);
00544 }
00545
00546
00547 MainIndex.DeinitLexer();
00548
00549
00550 if(MainIndex.isOpen())
00551 MainIndex.close();
00552
00553
00554 if(DoScroll)
00555 DoScrollRedraw();
00556 }
00557 else
00558 {
00559 TRACEUSER( "Richard", _T("Path doesn't exist\n"));
00560 }
00561
00562
00563 return(Libraries.GetCount());
00564 #endif
00565 return 0;
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 BOOL LibraryFile::GetSubIndexDetails(LibraryGallery *LG, String_256 *DefaultIndex,
00588 String_256 *IndexDesc, BOOL *CanGenerate)
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
00604 *CanGenerate = LG->CanCreateIndexes();
00605 return(LG->GetDefaults(DefaultIndex, IndexDesc, NULL));
00606 }
00607
00608 return FALSE;
00609 }
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 BOOL LibraryFile::CheckForSubIndexes(SuperGallery *ParentGal, PathName *Path, SGLibType Type, BOOL Updated)
00637 {
00638
00639
00640
00641 String_256 DefaultIndex;
00642 String_256 IndexDesc;
00643 BOOL CanGenerate;
00644 BOOL ok = TRUE;
00645
00646
00647 ParentLibraryGallery->SetQuietStatus(FALSE);
00648
00649 if(GetSubIndexDetails(ParentLibraryGallery, &DefaultIndex, &IndexDesc, &CanGenerate))
00650 {
00651 String_256 SubP(Path->GetPath(TRUE));
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
00665 Found = SGLibOil::FileExists(&SubPath);
00666
00667 if(!Found && CanGenerate)
00668 {
00669 if(Library::RemoteIndexes && GenerateIndexFile::IsDirectoryReadOnly(Path))
00670 {
00671
00672
00673
00674 String_256 RemoteLocationOfIndex;
00675 BOOL Existing = GenerateIndexFile::CheckForRemote(Path, &RemoteLocationOfIndex);
00676
00677 if(Existing)
00678 {
00679 String_256 SubP(RemoteLocationOfIndex);
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
00688
00689 if(Found)
00690 {
00691 SubPath.SetPathName(SubP);
00692 Path->SetPathName(RemoteLocationOfIndex);
00693 }
00694 }
00695 }
00696
00697 if(!Found)
00698 {
00699
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
00706 INT32 ButtonPressed = InformMessage(0, _R(IDS_CREATE), _R(IDS_CANCEL));
00707 Error::ClearError();
00708
00709 if(ButtonPressed < 2)
00710 {
00711
00712 String_64 Author(PRODUCT_NAME);
00713 Generate = GenerateDefaultIndex(&SubPath, Path, &Author, Type, TRUE);
00714 ok = TRUE;
00715 }
00716 else
00717 {
00718
00719 ok = FALSE;
00720 }
00721 }
00722 }
00723
00724 if(!Found && !CanGenerate)
00725 {
00726
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
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
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
00763 if(NewSubLib->Init(ParentGal, &PathToAdd, &Description, &DefIndex64, Type, Updated))
00764 {
00765 Libraries.AddTail(NewSubLib);
00766
00767 ok = TRUE;
00768
00769
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
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");
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 }
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831 BOOL LibraryFile::AddSpecificIndex(SuperGallery *ParentGal, PathName *Path, SGLibType Type,
00832 StringBase *Description, UINT32 bModified, BOOL bIsWebLib)
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
00841
00842
00843
00844
00845 MyPath = *Path;
00846 MyType = Type;
00847 ParentGallery = ParentGal;
00848
00849
00850 Library *NewSubLib = new Library;
00851
00852 if (NewSubLib != NULL)
00853 {
00854
00855
00856 NewSubLib->m_bIsWebLib = bIsWebLib;
00857 PathName TmpPath(Path->GetLocation(FALSE));
00858 NewSubLib->SetModified(bModified);
00859
00860
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
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
00878 String_64 IndexFilename(Path->GetFileName(TRUE));
00879
00880
00881 if(NewSubLib->Init(ParentGal, &FilesPath, &Desc64, &IndexFilename, Type, FALSE, (Description != NULL)))
00882 {
00883 Libraries.AddTail(NewSubLib);
00884
00885
00886 AddNewFolderToScrollRedrawSystem(NewSubLib);
00887
00888 return TRUE;
00889 }
00890 else
00891 {
00892
00893 delete NewSubLib;
00894 NewSubLib = NULL;
00895 }
00896 }
00897
00898
00899 return FALSE;
00900 }
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925 BOOL LibraryFile::TidyUpSubPath(String_256 *Str)
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
00936 if(((TCHAR *)OurPath)[OurPath.Length() - 1] == '\\')
00937 {
00938 Str->Left(&OurPath, Str->Length() - 1);
00939 }
00940
00941 if(OurPath.Length() > 10)
00942 {
00943
00944 String_256 OurPathTmp(OurPath);
00945 String_16 RighthandSection;
00946 OurPathTmp.Right(&RighthandSection, 9);
00947 RighthandSection.toUpper();
00948
00949
00950 String_16 XaraInfo("\\" + String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME_CAPS)));
00951 if(camStrcmp((TCHAR *)RighthandSection, (TCHAR *)XaraInfo) == 0)
00952 {
00953
00954 OurPathTmp.Left(&OurPath, OurPath.Length() - 9);
00955 }
00956 }
00957
00958
00959 if(SGLibOil::IsRootDirectory(&OurPath))
00960 {
00961
00962 OurPath += TEXT("\\");
00963 }
00964
00965 *Str = OurPath;
00966 return TRUE;
00967 }
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 INT32 LibraryFile::CountLines(PathName *IndexFilePath)
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
01008 TmpDiskFile.DeinitLexer();
01009
01010 if(TmpDiskFile.isOpen())
01011 TmpDiskFile.close();
01012
01013 return Count;
01014 }
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033 BOOL LibraryFile::KillLeadingSpaces(StringBase *Str)
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
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 }
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078 PathName *LibraryFile::GetLibraryPathName(void)
01079 {
01080
01081 ERROR3IF(MyType == SGLib_Blank, "This LibraryFile has not been properly initialised!");
01082
01083 return(&MyPath);
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103 SGLibType LibraryFile::GetLibraryType(void)
01104 {
01105
01106 ERROR3IF(MyType == SGLib_Blank, "This LibraryFile has not been properly initialised!");
01107
01108 return(MyType);
01109 }
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132 BOOL LibraryFile::GenerateDefaultIndex(PathName *IndexFile, PathName *LibDirPath, String_64 *Author,
01133 SGLibType Type, BOOL Thumbnails)
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 }
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169 void LibraryFile::InitScrollRedrawSystem(void)
01170 {
01171 FirstLibraryAdded = NULL;
01172 LastLibraryAdded = NULL;
01173 }
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191 void LibraryFile::AddNewFolderToScrollRedrawSystem(Library *NewFolder)
01192 {
01193
01194 if(FirstLibraryAdded == NULL)
01195 FirstLibraryAdded = NewFolder;
01196 LastLibraryAdded = NewFolder;
01197 }
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 void LibraryFile::DoScrollRedraw(void)
01211 {
01212
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
01221 ParentGallery->ReformatAndRedrawIfNecessary();
01222
01223
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
01234 ParentGallery->ScrollToShow(&ScrollToRect, TRUE);
01235 }
01236 }
01237 }