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 "sgindgen.h"
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 extern BOOL MakeShortPath(LPTSTR lpszPath, size_t cchMaxLen);
00137
00138 DECLARE_SOURCE("$Revision: 1361 $");
00139
00140 CC_IMPLEMENT_DYNCREATE(GenerateIndexFile, CCObject)
00141 CC_IMPLEMENT_DYNCREATE(IndGenFileBuffer, CCObject)
00142
00143 PORTNOTE("other", "Removed most of sgindgen.cpp" )
00144 #ifndef EXCLUDE_FROM_XARALX
00145
00146 #define new CAM_DEBUG_NEW
00147
00148
00149
00150
00151 #ifdef _DEBUG
00152 #ifdef _BATCHING
00153 BOOL GenerateIndexFile::CreateFontIndexes = TRUE;
00154 #else
00155 BOOL GenerateIndexFile::CreateFontIndexes = FALSE;
00156 #endif
00157 #else
00158 BOOL GenerateIndexFile::CreateFontIndexes = FALSE;
00159 #endif
00160
00161
00162 BOOL GenerateIndexFile::UseOldIndexes = TRUE;
00163 BOOL GenerateIndexFile::UseDocComments = TRUE;
00164
00165
00166 BOOL GenerateIndexFile::UseAutomaticUpdate = FALSE;
00167
00168
00169
00170
00171
00172 static BOOL QuietThumbnail = FALSE;
00173
00174
00175 static BOOL StopIndGen = FALSE;
00176
00177 static FilePos LastFoundItemInIndex = 0;
00178
00179
00180
00181
00182 #endif
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 GenerateIndexFile::GenerateIndexFile()
00201 {
00202 LibType = SGLib_Blank;
00203 DoThumbnails = FALSE;
00204 Author = _T("");
00205 IndexFile = NULL;
00206 IndexCountOff = 0;
00207 hSearch = NULL;
00208 ID = 0;
00209 TotalFiles = 0;
00210 TmpIndexFile = NULL;
00211 OldIndexStart = 0;
00212 OldIndexDescriptionField = OldIndexKeywordField = OldIndexTitleField = 0;
00213 OldIndexOK = FALSE;
00214 OldIndexDescription = "";
00215
00216 }
00217
00218 #if 0
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 BOOL GenerateIndexFile::CloseSearchHandle(void)
00237 {
00238
00239 if(hSearch != NULL) {
00240 if (!FindClose(hSearch)) {
00241 ERROR3("Couldn't close search handle.");
00242 return FALSE;
00243 }
00244 else
00245 {
00246 hSearch = NULL;
00247 }
00248 }
00249 return TRUE;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 BOOL GenerateIndexFile::CloseIndexFileHandle(void)
00269 {
00270 if(IndexFile != NULL)
00271 {
00272 IndexFile->close();
00273 delete IndexFile;
00274 IndexFile = NULL;
00275 }
00276 return TRUE;
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 BOOL GenerateIndexFile::IsDirectoryReadOnly(PathName *Directory)
00297 {
00298 ERROR3IF(Directory == NULL, "GenerateIndexFile::IsDirectoryReadOnly given a NULL dir");
00299
00300 String_256 ROPathStr(Directory->GetPath(TRUE));
00301 ROPathStr += TEXT("XaraInf");
00302 PathName ROPath(ROPathStr);
00303 Error::ClearError();
00304
00305 CCDiskFile ROFile(1024, FALSE, TRUE);
00306 BOOL ReadOnly = TRUE;
00307 BOOL CreatedFile = FALSE;
00308
00309
00310 TRY
00311 {
00312 CreatedFile = ROFile.open(ROPath, ios::out);
00313 }
00314
00315 CATCH(CFileException, e)
00316 {
00317
00318 ReadOnly = TRUE;
00319 Error::ClearError();
00320 }
00321 END_CATCH
00322
00323
00324 if (ROFile.isOpen())
00325 ROFile.close();
00326
00327 if(CreatedFile)
00328 {
00329 SGLibOil::FileDelete(&ROPath);
00330 return FALSE;
00331 }
00332
00333 return TRUE;
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 BOOL GenerateIndexFile::CheckForRemote(PathName *FilesDirectory, String_256 *RemoteDirectory)
00354 {
00355 ERROR3IF(FilesDirectory == NULL || RemoteDirectory == NULL, "GenerateIndexFile::CheckForRemote given NULL args");
00356
00357 *RemoteDirectory = Library::RemoteIndexLocation;
00358 BOOL UseTmp = FALSE;
00359
00360 if(RemoteDirectory->Length()==0)
00361 UseTmp = TRUE;
00362 else
00363 {
00364 PathName RemLocPath(*RemoteDirectory);
00365 if(!RemLocPath.IsValid() || !SGLibOil::FileExists(&RemLocPath) || IsDirectoryReadOnly(&RemLocPath))
00366 UseTmp = TRUE;
00367 }
00368
00369 if(UseTmp)
00370 {
00371 TCHAR *OSTMP = _tgetenv("TEMP");
00372 if(OSTMP == NULL)
00373 {
00374
00375
00376
00377
00378
00379 *RemoteDirectory = TEXT("");
00380 return FALSE;
00381
00382 }
00383
00384 camStrcpy((TCHAR *)*RemoteDirectory, OSTMP);
00385 }
00386
00387 String_256 TmpDir(FilesDirectory->GetFileName(FALSE));
00388 String_256 FPath(FilesDirectory->GetPath());
00389
00390 if(SGLibOil::IsRootDirectory(&FPath))
00391 {
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 if(!GiveMeAValidDirectoryName(&FPath, &TmpDir))
00433 return FALSE;
00434 }
00435
00436
00437 if(TmpDir.Length() == 0)
00438 return FALSE;
00439
00440 SGLibOil::AppendSlashIfNotPresent(RemoteDirectory);
00441 *RemoteDirectory += TmpDir;
00442
00443 PathName RemLocPath(*RemoteDirectory);
00444 if(RemLocPath.IsValid() && SGLibOil::FileExists(&RemLocPath) && !IsDirectoryReadOnly(&RemLocPath))
00445 return TRUE;
00446 else
00447 return FALSE;
00448 }
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 BOOL GenerateIndexFile::GiveMeAValidDirectoryName(String_256 *Input, String_256 *Output)
00468 {
00469 ERROR3IF(Input == NULL || Output == NULL, "GenerateIndexFile::GiveMeAValidDirectoryName given NULL params");
00470
00471 if(Input == NULL || Output == NULL)
00472 return FALSE;
00473
00474 INT32 Length = Input->Length();
00475 Output->Empty();
00476 INT32 StartIndex = 0;
00477
00478 if(Input->Sub(String_8("\\\\")) == 0 && Input->CountChar('\\') > 2)
00479 {
00480 String_256 Tmp;
00481 Input->Right(&Tmp, Length - 2);
00482
00483
00484 StartIndex = Tmp.Sub(String_8("\\")) + 2;
00485
00486 if((Length - StartIndex) < 2)
00487 StartIndex = 0;
00488 }
00489
00490 for(INT32 i = StartIndex; i <= Length; i++)
00491 {
00492 if(Output->Length() < 8)
00493 {
00494 if(iswalnum((*Input)[i]))
00495 *Output += TEXT((*Input)[i]);
00496 }
00497 }
00498
00499 if(Output->Length() > 0)
00500 return TRUE;
00501
00502 return FALSE;
00503 }
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 BOOL GenerateIndexFile::RemoteIndexSetup(PathName *FilesPath)
00523 {
00524 ERROR3IF(FilesPath == NULL, "GenerateIndexFile::RemoteIndexSetup passed a null path");
00525
00526 IndexIsRemote = FALSE;
00527 RemoteLocationOfIndex = "";
00528 RemoteLocationOfFiles = "";
00529
00530 if(!Library::RemoteIndexes)
00531 return FALSE;
00532
00533 BOOL Existing = CheckForRemote(FilesPath, &RemoteLocationOfIndex);
00534
00535 if(RemoteLocationOfIndex.Length() == 0)
00536 return FALSE;
00537
00538
00539 if(!SGLibOil::FileExists(&Index))
00540 {
00541
00542 String_256 Msg;
00543 String_256 SmallLocation;
00544 RemoteLocationOfIndex.Left(&SmallLocation, 100);
00545 Msg.MakeMsg(_R(IDS_LIBRARY_CREATE_REMOTE), (TCHAR *)SmallLocation);
00546 Error::SetError(0, Msg, 0);
00547 INT32 ButtonPressed = InformWarning(0, _R(IDS_CREATE), _R(IDS_CANCEL));
00548 Error::ClearError();
00549
00550 if(ButtonPressed != 1)
00551 return FALSE;
00552 }
00553
00554
00555 PathName TmpPath(RemoteLocationOfIndex);
00556
00557 if(!SGLibOil::FileExists(&TmpPath))
00558 {
00559
00560 if (!CreateDirectory((TCHAR *)RemoteLocationOfIndex, NULL))
00561 {
00562 DWORD err = GetLastError();
00563 ERROR3("Can't create Tmp Index directory");
00564 return FALSE;
00565 }
00566 }
00567
00568 IndexIsRemote = TRUE;
00569 SGLibOil::AppendSlashIfNotPresent(&RemoteLocationOfIndex);
00570
00571
00572 RemoteLocationOfIndex += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
00573 RemoteLocationOfFiles = FilesPath->GetPath(FALSE);
00574
00575 return TRUE;
00576 }
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 BOOL GenerateIndexFile::CreateIndexFile(void)
00596 {
00597 if(!GenerateIndexFile::CreateFontIndexes && LibType == SGLib_Font)
00598 return FALSE;
00599
00600 String_256 XIPathStr;
00601
00602
00603 if(IsDirectoryReadOnly(&LibPath))
00604 {
00605
00606 Error::ClearError();
00607
00608 if(RemoteIndexSetup(&LibPath))
00609 {
00610 XIPathStr = RemoteLocationOfIndex;
00611 IndexIsRemote = TRUE;
00612
00613 String_256 NewIndex(RemoteLocationOfIndex);
00614 SGLibOil::AppendSlashIfNotPresent(&NewIndex);
00615
00616
00617 NewIndex += Index.GetFileName(TRUE);
00618
00619 Index = NewIndex;
00620 }
00621 else
00622 {
00623
00624
00625 InformWarning(_R(IDS_READONLY_MEDIA), _R(IDS_OK));
00626 XIPathStr = LibPath.GetPath(TRUE);
00627 XIPathStr += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
00628 IndexIsRemote = FALSE;
00629 }
00630 }
00631 else
00632 {
00633 XIPathStr = LibPath.GetPath(TRUE);
00634 XIPathStr += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
00635 IndexIsRemote = FALSE;
00636 }
00637
00638
00639
00640
00641 PathName XIPath(XIPathStr);
00642
00643 if(!SGLibOil::FileExists(&XIPath))
00644 {
00645
00646 if (!CreateDirectory((TCHAR *)XIPathStr, NULL))
00647 {
00648 DWORD err = GetLastError();
00649 ERROR3("Can't create XaraInfo directory");
00650 return FALSE;
00651 }
00652 }
00653
00654
00655
00656 OldIndexOK = FALSE;
00657
00658
00659 if(SGLibOil::FileExists(&Index) && GenerateIndexFile::UseOldIndexes)
00660 {
00661 TmpIndexFile = new PathName(Index);
00662 if(TmpIndexFile != NULL)
00663 {
00664 TmpIndexFile->SetType("BAK");
00665 SGLibOil::FileCopy(&Index, TmpIndexFile);
00666
00667 OldIndexOK = PrePassIndex(TmpIndexFile, &OldIndexStart, &OldIndexDescriptionField,
00668 &OldIndexKeywordField, &OldIndexTitleField, &OldIndexDescription);
00669 }
00670 }
00671
00672 IndexFile = new CCDiskFile(1024, TRUE, FALSE);
00673 if(IndexFile == NULL)
00674 {
00675 ERROR3("Null index file allocated");
00676 return FALSE;
00677 }
00678
00679 if(!IndexFile->open(Index, ios::out))
00680 {
00681 TRACEUSER( "Richard", _T("Can't open index file"));
00682 delete IndexFile;
00683 IndexFile = NULL;
00684 return FALSE;
00685 }
00686
00687 return TRUE;
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706 BOOL GenerateIndexFile::DoIndexHeader(void)
00707 {
00708 String_256 Line(_R(IDS_LIBRARIES_INDEX_FILE_FOR));
00709 Line += LibPath.GetFileName();
00710 Line += TEXT("\r\n");
00711 AddLineToIndex(&Line);
00712
00713
00714
00715
00716 IndexCountOff = IndexFile->tell();
00717
00718 ID = 0;
00719 wsprintf(Line, "%05d", TotalFiles);
00720 Line += TEXT("\r\n");
00721 AddLineToIndex(&Line);
00722
00723
00724 Line = _R(IDS_LIBRARIES_SYNONYM_FILENAME);
00725 Line += TEXT("\r\n");
00726 AddLineToIndex(&Line);
00727
00728
00729
00730
00731
00732 if(LibType == SGLib_Font)
00733 Line = TEXT("28,16, 160,12, 180,26\r\n");
00734 else
00735 Line = TEXT("45,45, 130,64, 130,130\r\n");
00736
00737
00738
00739 AddLineToIndex(&Line);
00740
00741
00742 Line = String_16(_R(IDS_LIBRARIES_INDEX_ITEM_FILENAME));
00743 Line += TEXT(", ");
00744 Line += String_16(_R(IDS_LIBRARIES_INDEX_ITEM_DESC));
00745 Line += TEXT(", ");
00746 Line += String_16(_R(IDS_LIBRARIES_INDEX_ITEM_ID));
00747 Line += TEXT(", ");
00748 Line += String_16(_R(IDS_LIBRARIES_INDEX_ITEM_TITLE));
00749 Line += TEXT(", ");
00750 Line += String_16(_R(IDS_LIBRARIES_INDEX_ITEM_KEY));
00751 Line += TEXT(", ");
00752 Line += String_16(_R(IDS_LIBRARIES_INDEX_ITEM_SIZE));
00753 Line += TEXT("\r\n");
00754 AddLineToIndex(&Line);
00755
00756 String_256 Description;
00757 if(OldIndexDescription.Length() == 0 || !GenerateIndexFile::UseOldIndexes)
00758 {
00759 String_256 TmpPath(LibPath.GetPath());
00760 LibraryFile::TidyUpSubPath(&TmpPath);
00761 TmpPath.Left(&Description, 60);
00762 }
00763 else
00764 Description = OldIndexDescription;
00765
00766 Line = TEXT("#");
00767 Line += String_16(_R(IDS_LIBRARIES_INDEX_DESCRITION));
00768 Line += TEXT(" ") + Description;
00769 Line += TEXT("\r\n");
00770 AddLineToIndex(&Line);
00771
00772 if(IndexIsRemote)
00773 {
00774 Line = _R(IDS_LIBRARIES_INDEX_FILES);
00775 Line += TEXT(" ") + RemoteLocationOfFiles;
00776 Line += TEXT("\r\n");
00777 AddLineToIndex(&Line);
00778 }
00779
00780 Line = _R(IDS_LIBRARIES_INDEX_START);
00781 Line += TEXT("\r\n");
00782 AddLineToIndex(&Line);
00783
00784 return TRUE;
00785 }
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 BOOL GenerateIndexFile::AddToSubLibrary(void)
00805 {
00806 BOOL Problems = FALSE;
00807 INT32 Count = FileNameBuffer.ItemCount();
00808 INT32 i = 0;
00809
00810 while(i < Count)
00811 {
00812 TCHAR *Item = FileNameBuffer.GetItem(i);
00813 i++;
00814
00815 if(Item != NULL)
00816 {
00817 PathName FileToAdd(Item);
00818
00819 if(!AddFile(&FileToAdd))
00820 {
00821 ERROR3("Problems adding file to index or keyword file - or ESC pressed");
00822 Problems = TRUE;
00823 i = Count;
00824 }
00825 }
00826 }
00827
00828 return !Problems;
00829 }
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 INT32 GenerateIndexFile::CountValidFiles(void)
00848 {
00849
00850 String_64 Status(_R(IDS_LIBRARY_CREATION_SCANNING));
00851 BeginSlowJob(-1, FALSE, &Status);
00852
00853 INT32 Count = 0;
00854 BOOL Counting = TRUE;
00855 BOOL Creating = FALSE;
00856 INT32 Pass = 0;
00857 BOOL ok = TRUE;
00858
00859 String_256 FileSearch((const TCHAR *)LibPath.GetPath(TRUE));
00860 FileSearch += TEXT("*.*");
00861
00862 WIN32_FIND_DATA FileData;
00863 BOOL fFinished;
00864
00865
00866
00867
00868 do
00869 {
00870 Pass ++;
00871 Counting = (Pass == 1);
00872 Creating = (Pass == 2);
00873
00874 fFinished = FALSE;
00875 hSearch = 0;
00876
00877
00878 hSearch = FindFirstFile(FileSearch, &FileData);
00879 if (hSearch == INVALID_HANDLE_VALUE)
00880 {
00881 ERROR3("No valid files found in this directory");
00882 fFinished = TRUE;
00883 }
00884
00885 while (!fFinished)
00886 {
00887
00888 String_256 FileToAddStr((const TCHAR *)LibPath.GetPath(TRUE));
00889 FileToAddStr += (TCHAR *)FileData.cFileName;
00890
00891
00892 DWORD FileAttributes = GetFileAttributes(FileToAddStr);
00893
00894 if( ((FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
00895 (FileAttributes & FILE_ATTRIBUTE_HIDDEN) ||
00896 (FileAttributes & FILE_ATTRIBUTE_SYSTEM)) == 0)
00897 {
00898 PathName FileToAdd(FileToAddStr);
00899
00900
00901 if(IsFileType(&FileToAdd, LibType))
00902 {
00903
00904 if(Counting)
00905 Count ++;
00906
00907
00908 if(Creating)
00909 FileNameBuffer.AddItem((TCHAR *)FileToAddStr);
00910 }
00911 }
00912
00913
00914 if (!FindNextFile(hSearch, &FileData))
00915 fFinished = TRUE;
00916 }
00917
00918
00919 if(!CloseSearchHandle())
00920 ERROR3("Couldn't close search handle.");
00921
00922 if(Count != 0 && Counting)
00923 {
00924 ok = FileNameBuffer.Init(Count);
00925 }
00926
00927 if(Count != 0 && Creating)
00928 {
00929 ok = FileNameBuffer.Sort();
00930 }
00931
00932
00933 } while(Count != 0 && Pass < 2 && ok);
00934
00935 EndSlowJob();
00936 return Count;
00937 }
00938
00939 #endif
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964 IndGenFileBuffer::IndGenFileBuffer()
00965 {
00966 Buffer = NULL;
00967 Items = 0;
00968 Position = 0;
00969 }
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987 IndGenFileBuffer::~IndGenFileBuffer()
00988 {
00989 if(Buffer != NULL)
00990 {
00991 for(INT32 i = 0; i<Items; i++)
00992 {
00993 if(Buffer[i] != NULL)
00994 CCFree(Buffer[i]);
00995 }
00996
00997 CCFree(Buffer);
00998 Buffer = NULL;
00999 }
01000 }
01001
01002 #if 0
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020 BOOL IndGenFileBuffer::Init(INT32 Count)
01021 {
01022 ERROR3IF(Buffer != NULL, "IndGenFileBuffer::Init called twice for same object");
01023
01024 Items = Count;
01025 Buffer = (TCHAR **)CCMalloc(sizeof(TCHAR *) * Count);
01026
01027 if(Buffer == NULL)
01028 {
01029 ERROR3("IndGenFileBuffer::Init failed to allocate buffer memory");
01030 Items = 0;
01031 return FALSE;
01032 }
01033
01034 for(INT32 i = 0; i<Items; i++)
01035 {
01036 Buffer[i] = NULL;
01037 }
01038
01039 return TRUE;
01040 }
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058 BOOL IndGenFileBuffer::AddItem(TCHAR *String)
01059 {
01060 ERROR3IF(Items == 0, "IndGenFileBuffer::AddItem called without initialising first");
01061
01062 if(Position >= Items)
01063 {
01064 ERROR3("IndGenFileBuffer::AddItem called too many times");
01065 return FALSE;
01066 }
01067
01068 BOOL ok = FALSE;
01069
01070 Buffer[Position] = (TCHAR *)CCMalloc((camStrlen(String) + 1) * sizeof(TCHAR));
01071 if(Buffer[Position] != NULL)
01072 {
01073 camStrcpy(Buffer[Position], String);
01074 ok = TRUE;
01075 }
01076
01077 Position++;
01078
01079 return ok;
01080 }
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098 BOOL IndGenFileBuffer::Sort(void)
01099 {
01100 qsort(Buffer, Items, sizeof(TCHAR *), IndGenFileBuffer::SortComparator);
01101
01102 return FALSE;
01103 }
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122 INT32 __cdecl IndGenFileBuffer::SortComparator(const void *Item1, const void *Item2)
01123 {
01124 if(Item1 == NULL || Item2 == NULL)
01125 {
01126 ERROR3("IndGenFileBuffer::SortComparator given null params");
01127 return 0;
01128 }
01129
01130 TCHAR *String1 = *((TCHAR **)Item1);
01131 TCHAR *String2 = *((TCHAR **)Item2);
01132
01133
01134 INT32 Value = CompareString(LOCALE_USER_DEFAULT,
01135 (NORM_IGNORECASE | NORM_IGNOREKANATYPE | NORM_IGNOREWIDTH),
01136 String1, -1, String2, -1);
01137 Value -= 2;
01138
01139 return(Value);
01140 }
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158 TCHAR *IndGenFileBuffer::GetItem(INT32 Count)
01159 {
01160 ERROR3IF(Count > Position, "IndGenFileBuffer::GetItem given an index which hasn't been added yet");
01161
01162 return Buffer[Count];
01163 }
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181 BOOL GenerateIndexFile::FixSubLibraryNumber(void)
01182 {
01183 if(IndexFile && IndexCountOff)
01184 {
01185 IndexFile->seek(IndexCountOff);
01186 String_256 Line;
01187 wsprintf(Line, "%05d", ID);
01188 AddLineToIndex(&Line);
01189 }
01190 else
01191 return FALSE;
01192
01193 return TRUE;
01194 }
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213 BOOL GenerateIndexFile::AddFile(PathName *FileName)
01214 {
01215
01216 if(!ContinueSlowJob(ID))
01217 return FALSE;
01218 ID++;
01219
01220 TRACEUSER( "Richard", _T("Adding %s - ID %d to Index file\n"), (const TCHAR *)FileName->GetPath(), ID);
01221
01222
01223 INT32 Size = (DWORD)SGLibOil::FileSize(FileName);
01224
01225
01226 String_256 FName(FileName->GetFileName(TRUE));
01227 FName.toLower();
01228
01229
01230 TCHAR First = camToupper(((TCHAR *)FName)[0]);
01231 ((TCHAR *)FName)[0] = First;
01232
01233
01234 String_256 Description;
01235
01236 #ifdef FILENAME_AS_DEFAULT_DESCRIPTION
01237 Description = FileName->GetFileName(FALSE);
01238 Description.toLower();
01239
01240
01241 First = camToupper(((TCHAR *)Description)[0]);
01242 ((TCHAR *)Description)[0] = First;
01243 #endif
01244
01245
01246 String_256 Keywords("");
01247
01248
01249 String_256 Title("");
01250
01251 BOOL FoundProperDescription = FALSE;
01252
01253
01254 if(LibType == SGLib_Font) {
01255
01256 String_8 Ending(".");
01257 Ending += FileName->GetType();
01258 Ending.toLower();
01259 Ending += ";";
01260
01261 if(Ending.Sub((String_8)".ttf;") != -1)
01262 {
01263 String_256 MenuName;
01264 if(RipTrueTypeNameFromFile(FileName, &MenuName))
01265 {
01266 Description = MenuName;
01267 FoundProperDescription = TRUE;
01268 }
01269 }
01270
01271 if(Ending.Sub((String_8)".pfb;") != -1)
01272 {
01273 String_256 MenuName;
01274 BOOL Bold = FALSE;
01275 BOOL Italic = FALSE;
01276 if(RipATMNameFromFile(FileName, &MenuName, &Bold, &Italic))
01277 {
01278
01279 if(Bold || Italic) MenuName += ";";
01280 if(Bold) MenuName += String_16(_R(IDS_FONTS_CAPITAL_BOLD));
01281 if(Italic) MenuName += String_16(_R(IDS_FONTS_CAPITAL_ITALIC));
01282
01283 Description = MenuName;
01284 FoundProperDescription = TRUE;
01285 }
01286 }
01287 }
01288
01289
01290
01291
01292 if((LibType == SGLib_ClipArt || LibType == SGLib_ClipArt_WebThemes) && !FoundProperDescription && GenerateIndexFile::UseDocComments)
01293 {
01294 String_256 OldDesc(Description);
01295 String_256 OldKeywords(Keywords);
01296 String_256 OldTitle(Title);
01297 if(RipDescriptionFromFile(FileName, &OldDesc, &OldKeywords, &OldTitle))
01298 {
01299 Description = OldDesc;
01300 Keywords = OldKeywords;
01301 Title = OldTitle;
01302 FoundProperDescription = TRUE;
01303 }
01304 }
01305
01306
01307
01308 if(TmpIndexFile != NULL)
01309 {
01310
01311
01312 String_256 OldDesc(Description);
01313 String_256 OldKeywords(Keywords);
01314 String_256 OldTitle(Title);
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327 String_256 FN;
01328 FN = FileName->GetFileName();
01329
01330 if(RipDescriptionFromIndex(TmpIndexFile, FileName, OldIndexStart,
01331 OldIndexDescriptionField, OldIndexKeywordField, OldIndexTitleField,
01332 &OldDesc, &OldKeywords, &OldTitle))
01333 {
01334 Description = OldDesc;
01335 Keywords = OldKeywords;
01336 Title = OldTitle;
01337 FoundProperDescription = TRUE;
01338
01339 if(Description == Title)
01340 Description = (String_256)"";
01341
01342 }
01343 else
01344 {
01345 #ifdef _BATCHING
01346
01347
01348 String_8 Ending(FileName->GetType());
01349 Ending.toLower();
01350 if(Ending.Sub((String_8)"xar") != -1)
01351 {
01352 PathName NewFileName(*FileName);
01353 NewFileName.SetType("ART");
01354
01355 if(RipDescriptionFromIndex(TmpIndexFile, &NewFileName, OldIndexStart,
01356 OldIndexDescriptionField, OldIndexKeywordField, OldIndexTitleField,
01357 &OldDesc, &OldKeywords, &OldTitle))
01358 {
01359 Description = OldDesc;
01360 Keywords = OldKeywords;
01361 Title = OldTitle;
01362 FoundProperDescription = TRUE;
01363
01364 if(Description == Title)
01365 Description = (String_256)"";
01366 }
01367 }
01368 #endif
01369
01370 }
01371
01372
01373
01374
01375
01376
01377
01378 }
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422 if(Description.Length() != 0)
01423 ReplaceCharacters(&Description, ',', ';');
01424
01425 if(Title.Length() != 0)
01426 ReplaceCharacters(&Title, ',', ';');
01427
01428 if(Keywords.Length() != 0)
01429 ReplaceCharacters(&Keywords, ',', ';');
01430
01431 String_256 Line;
01432 wsprintf(Line, "%s, %s, %d, %s, %s, %d\r\n", (TCHAR *)FName, (TCHAR *)Description,
01433 ID, (TCHAR *)Title, (TCHAR *)Keywords, Size);
01434 AddLineToIndex(&Line);
01435
01436 if( DoThumbnails )
01437 CreateThumbnails(FileName, TRUE);
01438
01439 if(StopIndGen)
01440 return FALSE;
01441
01442 return TRUE;
01443 }
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 BOOL GenerateIndexFile::IsFileType(PathName *FileName, const SGLibType Type)
01463 {
01464
01465 String_8 Ending(".");
01466 Ending += FileName->GetType();
01467 Ending.toLower();
01468 Ending += ";";
01469
01470
01471
01472 switch(Type) {
01473 case SGLib_Font:
01474
01475 if(Ending.Sub((String_8)".ttf;") != -1) return TRUE;
01476
01477
01478 if(Ending.Sub((String_8)".pfb;") != -1)
01479 {
01480 PathName TmpFile(*FileName);
01481 TmpFile.SetType((String_8)"pfm");
01482 BOOL PFM = SGLibOil::FileExists(&TmpFile);
01483 TmpFile.SetType((String_8)"afm");
01484 BOOL AFM = SGLibOil::FileExists(&TmpFile);
01485 if(PFM && AFM)
01486 return TRUE;
01487 }
01488 break;
01489
01490 case SGLib_ClipArt:
01491 case SGLib_ClipArt_WebThemes:
01492 {
01493
01494 if( (Ending.Sub((String_8)".art;") != -1)
01495 || (Ending.Sub((String_8)".xar;") != -1)
01496 || (Ending.Sub((String_8)".cxn;") != -1)
01497 || (Ending.Sub((String_8)".cxw;") != -1)
01498 || (Ending.Sub((String_8)".web;") != -1) )
01499 return TRUE;
01500
01501
01502 Filter *pFilter = Filter::GetFirst();
01503
01504 while (pFilter != NULL)
01505 {
01506 FilterFlags Flags = pFilter->GetFlags();
01507
01508 if ( Flags.CanImport && Flags.ShowFilter )
01509 {
01510
01511
01512
01513
01514 String_256 FilterString(pFilter->pOILFilter->ConstructFilterString());
01515 FilterString.toLower();
01516 FilterString += ";";
01517
01518 if(FilterString.Sub(Ending) != -1)
01519 return TRUE;
01520 }
01521
01522
01523 pFilter = Filter::GetNext(pFilter);
01524 }
01525
01526
01527
01528
01529
01530
01531
01532
01533 }
01534 break;
01535
01536 case SGLib_Texture:
01537 case SGLib_Bitmap:
01538 {
01539 Filter *pFilter = Filter::GetFirst();
01540 while (pFilter != NULL)
01541 {
01542 FilterFlags Flags = pFilter->GetFlags();
01543
01544 if ( Flags.CanImport && Flags.ShowFilter && pFilter->IS_KIND_OF(BitmapFilter))
01545 {
01546
01547
01548
01549
01550 String_256 FilterString(pFilter->pOILFilter->ConstructFilterString());
01551 FilterString.toLower();
01552 FilterString += ";";
01553
01554 if(FilterString.Sub(Ending) != -1)
01555 return TRUE;
01556 }
01557
01558
01559 pFilter = Filter::GetNext(pFilter);
01560 }
01561 }
01562 break;
01563
01564 case SGLib_Blank:
01565 return TRUE;
01566
01567 case SGLib_Fractal:
01568 case SGLib_Colour:
01569 default:
01570 break;
01571 }
01572
01573 return FALSE;
01574 }
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592 INT8 GenerateIndexFile::GetShort(FILE *fp)
01593 {
01594 INT8 ret;
01595 ret = (_gettc(fp) << 8);
01596 ret += _gettc(fp);
01597 return ret;
01598 }
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615
01616 INT8 GenerateIndexFile::GetFixed(FILE *fp)
01617 {
01618 INT8 ret;
01619 ret = (_gettc(fp) << 8);
01620 ret += _gettc(fp);
01621 _gettc(fp);
01622 _gettc(fp);
01623 return ret;
01624 }
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642 INT32 GenerateIndexFile::GetLONG(FILE *fp)
01643 {
01644 INT32 ret;
01645 ret = (_gettc(fp) << 24);
01646 ret |= (_gettc(fp) << 16);
01647 ret |= (_gettc(fp) << 8);
01648 ret |= (_gettc(fp));
01649 return ret;
01650 }
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678 BOOL GenerateIndexFile::RipTrueTypeNameFromFile(PathName *FileName, String_256 *RetName)
01679 {
01680 #ifdef _DEBUG
01681
01682 if(FileName == NULL || RetName == NULL)
01683 {
01684 ERROR3("GenerateIndexFile::RipTrueTypeNameFromFile given null params - bad !");
01685 return FALSE;
01686 }
01687
01688 BOOL ok=TRUE;
01689 BOOL found = FALSE;
01690
01691 FILE *file = NULL;
01692
01693 file = _tfopen((const TCHAR *)FileName->GetPath(), "rb");
01694 if(file) {
01695
01696
01697
01698 INT8 version = GetFixed(file);
01699 UINT8 NumTables = GetShort(file);
01700
01701 GetShort(file);
01702 GetShort(file);
01703 GetShort(file);
01704
01705
01706
01707 TCHAR tag[8] = "";
01708 static INT32 checksum = 0;
01709 static INT32 Noffset = 0;
01710 static INT32 length = 0;
01711
01712 static INT32 NameOffset = 0;
01713
01714 INT32 i;
01715
01716 for(i=1; i<=NumTables; i++) {
01717
01718
01719
01720 tag[0] = _gettc(file);
01721 tag[1] = _gettc(file);
01722 tag[2] = _gettc(file);
01723 tag[3] = _gettc(file);
01724 tag[4] = 0;
01725
01726 checksum = GetLONG(file);
01727 Noffset = GetLONG(file);
01728 length = GetLONG(file);
01729
01730 if(feof(file)) {
01731 DWORD Z = GetLastError();
01732 ERROR3("eof returned in ttf file");
01733 }
01734
01735
01736 if(!(camStrcmp(tag,"name"))) {
01737 NameOffset = Noffset;
01738 }
01739
01740 }
01741
01742
01743
01744
01745 if(NameOffset != 0) {
01746
01747 if(fseek(file, NameOffset, SEEK_SET)) {
01748 ERROR3("Can't find TTF name table");
01749 fclose(file);
01750 return FALSE;
01751 }
01752
01753 UINT8 FormatSelect = GetShort(file);
01754 UINT8 NumRecords = GetShort(file);
01755 UINT8 StringStore = GetShort(file);
01756
01757 UINT8 PlatformID;
01758 UINT8 PlatformSpecID;
01759 UINT8 LangID;
01760 UINT8 NameID;
01761 UINT8 StrLen;
01762 UINT8 StrOff;
01763
01764 UINT8 family_strlen = 0;
01765 UINT8 family_stroff = 0;
01766
01767 for(i=1; i<=NumRecords; i++) {
01768
01769 PlatformID = GetShort(file);
01770 PlatformSpecID = GetShort(file);
01771 LangID = GetShort(file);
01772 NameID = GetShort(file);
01773 StrLen = GetShort(file);
01774 StrOff = GetShort(file);
01775
01776
01777 if(NameID == 4 && PlatformID == 1) {
01778
01779
01780
01781 family_strlen = StrLen;
01782 family_stroff = StrOff;
01783
01784 fpos_t pos;
01785
01786 fgetpos(file, &pos);
01787 if(fseek(file, family_stroff + StringStore + NameOffset, SEEK_SET)) {
01788
01789 ERROR3("String in name table past end of file in TTF file.");
01790
01791 } else {
01792
01793 if(family_strlen >= 255) family_strlen = 255-1;
01794
01795 TCHAR Name[255];
01796
01797
01798 _fgetts(Name, family_strlen+1, file);
01799 found = TRUE;
01800
01801 camStrcpy((TCHAR *)*RetName, Name);
01802
01803 TRACEUSER( "Richard", _T("Font name = %s\n"), Name);
01804 TRACEUSER( "Richard", _T("PlatID %d, SpecID %d, LangID %d\n"), PlatformID, PlatformSpecID, LangID);
01805 }
01806 fsetpos(file, &pos);
01807 }
01808 }
01809
01810 if(!found)
01811 ERROR3("Can't find TTF family name");
01812
01813 }
01814
01815
01816
01817 fclose(file);
01818 }
01819
01820 return found;
01821
01822 #endif
01823
01824 return TRUE;
01825 }
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849 BOOL GenerateIndexFile::RipATMNameFromFile(PathName *FileName, String_256 *RetName, BOOL *Bold, BOOL *Italic)
01850 {
01851 #ifdef _DEBUG
01852
01853 ERROR3IF(FileName == NULL || RetName == NULL || Bold == NULL || Italic == NULL, "Null params given to ATM ripper");
01854
01855
01856
01857
01858
01859 BOOL ok = TRUE;
01860
01861 *RetName = TEXT("");
01862 *Bold = FALSE;
01863 *Italic = FALSE;
01864
01865 PathName PFMPath(*FileName);
01866 PFMPath.SetType((String_8)"PFM");
01867
01868 if(!SGLibOil::FileExists(&PFMPath))
01869 {
01870 ERROR3("Can't find PFM file");
01871 return FALSE;
01872 }
01873
01874 CCDiskFile PFMFile(1024, FALSE, TRUE);
01875
01876 TRY
01877 {
01878
01879 ok = PFMFile.open(PFMPath, ios::in | ios::nocreate | ios::binary);
01880 }
01881
01882 CATCH(CFileException, e)
01883 {
01884 Error::ClearError();
01885 return FALSE;
01886 }
01887 END_CATCH
01888
01889 FilePos Position = 100;
01890 BOOL FoundPostScript = FALSE;
01891 PFMFile.seekIn(Position);
01892
01893 TRY
01894 {
01895
01896 while(!PFMFile.eof() && !FoundPostScript)
01897 {
01898
01899 DWORD Buffer[256];
01900 memset(Buffer, 0, 256 * 4);
01901 PFMFile.seekIn(Position);
01902
01903 if(!FoundPostScript)
01904 {
01905 PFMFile.read((void *)Buffer, 11);
01906
01907 if(!camStrcmp(((TCHAR *)Buffer) , "PostScript"))
01908 {
01909
01910 FoundPostScript = TRUE;
01911
01912 TCHAR Typeface[256];
01913 INT32 Count = 0;
01914
01915 do {
01916 PFMFile.read((void *)Buffer, 1);
01917 Typeface[Count] = ((TCHAR *)Buffer)[0];
01918 } while(Typeface[Count++] != 0 && !PFMFile.eof());
01919
01920 TCHAR Styles[256];
01921 Count = 0;
01922
01923 do {
01924 PFMFile.read((void *)Buffer, 1);
01925 Styles[Count] = ((TCHAR *)Buffer)[0];
01926 } while(Styles[Count++] != 0 && !PFMFile.eof());
01927
01928 String_256 StyleStr;
01929 StyleStr = (TCHAR *)Styles;
01930
01931
01932
01933
01934 if(StyleStr.Sub((String_8)"-Medium") != -1)
01935 {
01936 String_256 TypeString(Typeface);
01937 if(TypeString.Sub((String_8)"Lt") != -1)
01938 *Bold = TRUE;
01939 }
01940
01941 if( StyleStr.Sub((String_8)"-Bold") != -1
01942 || StyleStr.Sub((String_8)"-Semi") != -1
01943 || StyleStr.Sub((String_8)"-Black") != -1
01944 || StyleStr.Sub((String_8)"-Demi") != -1
01945 || StyleStr.Sub((String_8)"-Heavy") != -1)
01946 *Bold = TRUE;
01947
01948
01949 if( StyleStr.Sub((String_8)"Ital") != -1
01950 || StyleStr.Sub((String_8)"BoldIt") != -1
01951 || StyleStr.Sub((String_8)"DemiIt") != -1
01952 || StyleStr.Sub((String_8)"SemiIt") != -1
01953 || StyleStr.Sub((String_8)"HeavyIt") != -1
01954 || StyleStr.Sub((String_8)"BlackIt") != -1)
01955 *Italic = TRUE;
01956
01957 StyleStr = (TCHAR *)Typeface;
01958 *RetName = StyleStr;
01959
01960
01961 }
01962 }
01963
01964 Position ++;
01965 }
01966 }
01967
01968
01969 CATCH(CFileException, e)
01970 {
01971
01972 ok = FALSE;
01973
01974
01975 Error::ClearError();
01976 }
01977 END_CATCH
01978
01979
01980 TRY
01981 {
01982 if (PFMFile.isOpen())
01983 PFMFile.close();
01984 }
01985 CATCH(CFileException, e)
01986 {
01987
01988 Error::ClearError();
01989 }
01990 END_CATCH
01991
01992
01993 #endif
01994
01995 return TRUE;
01996 }
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015 BOOL GenerateIndexFile::PreCreateThumbnail(PathName *InFile)
02016 {
02017 if(InFile == NULL)
02018 return FALSE;
02019
02020 String_8 Ending(InFile->GetType());
02021 Ending.toLower();
02022
02023
02024 if(Ending.Sub((String_8)"bmp") != -1)
02025 {
02026 BOOL NiceHappyBpp = FALSE;
02027
02028 FILE *pFile = fopen((const TCHAR *)InFile->GetPath(), "rb");
02029 if(pFile)
02030 {
02031 INT32 b = fgetc(pFile);
02032 INT32 m = fgetc(pFile);
02033
02034
02035 if(b == 'B' && m == 'M')
02036 {
02037 DWORD BppOffset = sizeof(BITMAPFILEHEADER) + 4 + 4 + 4 + 2;
02038
02039 if(!fseek(pFile, BppOffset, SEEK_SET))
02040 {
02041 INT32 bpp = fgetc(pFile);
02042 bpp += (fgetc(pFile) << 8);
02043
02044
02045 if(bpp == 1 || bpp == 4 || bpp == 8 || bpp == 24)
02046 NiceHappyBpp = TRUE;
02047 }
02048 }
02049 fclose(pFile);
02050 }
02051 return NiceHappyBpp;
02052 }
02053
02054 return TRUE;
02055 }
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080 BOOL GenerateIndexFile::CreateThumbnail(PathName *InFile, PathName *OutFile, UINT8 XSize, UINT8 YSize)
02081 {
02082
02083 if(LibType == SGLib_Font)
02084 return FALSE;
02085
02086
02087 if(XSize == 0 || YSize == 0)
02088 return FALSE;
02089
02090
02091 if(!PreCreateThumbnail(InFile))
02092 return FALSE;
02093
02094
02095
02096
02097 CCDiskFile TempDiskFile(1024, FALSE, TRUE);
02098
02099
02100 BOOL ok = TempDiskFile.open(*InFile, ios::in | ios::binary);
02101
02102
02103 GenericFilter *pGenericFilter = Filter::GetGenericFilter();
02104 if (ok) ok = (pGenericFilter != NULL);
02105 if (ok)
02106 {
02107
02108
02109
02110 UINT32 FileSize = TempDiskFile.Size();
02111
02112
02113 Filter *pImportFilter = pGenericFilter->GetBestFilter(&TempDiskFile);
02114
02115 if (pImportFilter == NULL)
02116 return FALSE;
02117
02118
02119 Filter *pFilter = Filter::GetFirst();
02120 while (pFilter != NULL)
02121 {
02122 if (IS_A(pFilter,ThumbnailFilterPNG))
02123
02124 break;
02125
02126
02127 pFilter = Filter::GetNext(pFilter);
02128 }
02129
02130 if (pFilter == NULL)
02131 return FALSE;
02132
02133
02134 ThumbnailFilterPNG *pPNGFilter = (ThumbnailFilterPNG *)pFilter;
02135
02136 INT32 PixelSize = 72000 / 96;
02137
02138
02139 INT32 OldPreviewSize = PreviewFilter::PreviewBitmapSize;
02140
02141
02142 PreviewFilter::PreviewBitmapSize = (XSize > YSize ? XSize : YSize) * PixelSize;
02143
02144
02145 Document *pOldCurrent = Document::GetCurrent();
02146 Document *pOldSelected = Document::GetSelected();
02147
02148
02149 Document *pDoc = new Document(TRUE);
02150 if (pDoc == NULL)
02151 ok = FALSE;
02152 else
02153 {
02154 pDoc->Init(0);
02155
02156
02157 SelOperation *pOp = new SelOperation;
02158 if (pOp == NULL)
02159 ok = FALSE;
02160 else
02161 {
02162
02163 Document::SetSelectedViewAndSpread(pDoc, NULL, pDoc->FindFirstSpread());
02164
02165 if (pImportFilter->IS_KIND_OF(BaseBitmapFilter))
02166 {
02167 KernelBitmap *pKernelBitmap = NULL;
02168
02169
02170 ok = pImportFilter->ImportBitmap(&TempDiskFile, &pKernelBitmap);
02171
02172
02173 if (TempDiskFile.isOpen())
02174 TempDiskFile.close();
02175
02176
02177 BitmapExportDocument *pBmpDoc = new BitmapExportDocument();
02178 if (pBmpDoc != NULL)
02179 {
02180
02181 DocRect RectToExport;
02182 RectToExport.lo.x = 0;
02183 RectToExport.lo.y = 0;
02184 RectToExport.hi.x = XSize * PixelSize;
02185 RectToExport.hi.y = YSize * PixelSize;
02186
02187
02188 pBmpDoc->Init(pKernelBitmap, RectToExport);
02189
02190 if (ok) ok = pPNGFilter->DoExport(pOp, &TempDiskFile, OutFile, pBmpDoc, TRUE);
02191
02192
02193 delete pBmpDoc;
02194 }
02195 else
02196 ok = FALSE;
02197
02198
02199
02200
02201 }
02202 else
02203 {
02204
02205
02206
02207 View *pOldView = View::GetCurrent();
02208
02209
02210 DocView *pView = new DocView(pDoc);
02211 if (pView && pView->Init())
02212 {
02213
02214 pView->SetCurrent();
02215
02216
02217 ok = pImportFilter->DoImport(pOp,&TempDiskFile,pDoc);
02218
02219 delete pView;
02220 }
02221
02222
02223 if (pOldView != NULL)
02224 pOldView->SetCurrent();
02225 else
02226 View::SetNoCurrent();
02227
02228
02229 if (TempDiskFile.isOpen())
02230 TempDiskFile.close();
02231
02232
02233 if (ok) ok = pPNGFilter->DoExport(pOp, &TempDiskFile, OutFile, pDoc, TRUE);
02234 }
02235
02236
02237 delete pOp;
02238 }
02239
02240
02241 if (pOldCurrent != NULL)
02242 pOldCurrent->SetCurrent();
02243 else
02244 Document::SetNoCurrent();
02245
02246
02247 if (pOldSelected != NULL)
02248 Document::SetSelectedViewAndSpread(pOldSelected);
02249 else
02250 Document::SetNoSelectedViewAndSpread();
02251
02252
02253 delete pDoc;
02254 pDoc = NULL;
02255 }
02256
02257
02258 PreviewFilter::PreviewBitmapSize = OldPreviewSize;
02259 }
02260
02261
02262 if (TempDiskFile.isOpen())
02263 TempDiskFile.close();
02264
02265
02266
02267
02268
02269 #if FALSE
02270
02271
02272 static WarnAboutAccusoft = TRUE;
02273 if (AccusoftFilters::GetVersionNumber() <= 0)
02274 {
02275 #ifdef _DEBUG
02276 if(WarnAboutAccusoft)
02277 {
02278
02279
02280 String_256 Msg("Accusoft DLL not found, can't generate thumbnails");
02281 Error::SetError(0, Msg, 0);
02282 INT32 ButtonPressed = InformWarning(0, _R(IDS_SKIP), _R(IDS_SILENT));
02283 Error::ClearError();
02284
02285 if(ButtonPressed == 2)
02286 WarnAboutAccusoft = FALSE;
02287 }
02288 #endif
02289 return FALSE;
02290 }
02291
02292 TRACEUSER( "Richard", _T("About to do %s (%d)"), (const TCHAR *)InFile->GetPath(), SGLibOil::FileSize(InFile));
02293
02294 BOOL ok = FALSE;
02295
02296
02297 void *Fish = CCMalloc(sizeof(BITMAPINFOHEADER) + 256 * 4);
02298 BITMAPINFOHEADER *header = (BITMAPINFOHEADER *)Fish;
02299
02300 char FileWithPath[256];
02301 camStrcpy(FileWithPath, (const TCHAR *)InFile->GetPath());
02302
02303 INT32 z = AccusoftFilters::pfnIMGLOW_get_fileinfo(FileWithPath, header);
02304 if(z<0)
02305 {
02306 #ifdef _DEBUG
02307
02308 if(!QuietThumbnail)
02309 {
02310 String_256 Msg;
02311 wsprintf(Msg, "GenIdxFl::CreateThumbnail GetFileInfo - '%s' (0x%x '", (const TCHAR *)InFile->GetPath(), z);
02312 String_256 bodge(_R(IDE_ACCUSOFT_ERROR) - z);
02313 Msg += bodge;
02314 Msg += TEXT("')");
02315 ERROR3(Msg);
02316 }
02317 #endif
02318 CCFree(Fish);
02319 }
02320 else
02321 {
02322
02323 INT32 BmpX = 0;
02324 INT32 BmpY = 0;
02325
02326 BmpX = header->biWidth;
02327 BmpY = header->biHeight;
02328
02329 CCFree(Fish);
02330
02331 double XScale = (double)BmpX / (double)XSize;
02332 double YScale = (double)BmpY / (double)YSize;
02333
02334 double Scale = (double)1;
02335 if(XScale > YScale)
02336 Scale = XScale;
02337 else
02338 Scale = YScale;
02339 if(Scale <= (double)0)
02340 Scale = (double)0.1;
02341
02342 XScale = (double)BmpX / (double)Scale;
02343 YScale = (double)BmpY / (double)Scale;
02344
02345 INT32 Xscale = (INT32)XScale;
02346 INT32 Yscale = (INT32)YScale;
02347
02348
02349 INT32 x = AccusoftFilters::pfnIMGLOW_set_decompsize(Xscale, Yscale);
02350 if(x<0)
02351 {
02352 #ifdef _DEBUG
02353 String_256 Msg;
02354 _stprintf(Msg, "GenIdxFl::CreateThumbnail SetDecompSize - '%s' (0x%x '", (const TCHAR *)InFile->GetPath(), x);
02355 String_256 bodge(_R(IDE_ACCUSOFT_ERROR) - x);
02356 Msg += bodge;
02357 Msg += TEXT("')");
02358 ERROR3(Msg);
02359 #endif
02360 }
02361 else
02362 {
02363
02364 INT32 imghandle = AccusoftFilters::pfnIMG_decompress_bitmap(FileWithPath);
02365 if(imghandle<0)
02366 {
02367 #ifdef _DEBUG
02368 String_256 Msg;
02369 _stprintf(Msg, "GenIdxFl::CreateThumbnail DecompBitmap - '%s' (0x%x '", (const TCHAR *)InFile->GetPath(), imghandle);
02370 String_256 bodge(_R(IDE_ACCUSOFT_ERROR) - imghandle);
02371 Msg += bodge;
02372 Msg += TEXT("')");
02373 ERROR3(Msg);
02374 #endif
02375 } else {
02376
02377 TCHAR OutFileAndPath[256];
02378 camStrcpy(OutFileAndPath, (const TCHAR *)OutFile->GetPath());
02379
02380
02381 INT32 Problem = AccusoftFilters::pfnIMG_save_bitmap(imghandle, OutFileAndPath, BMP_UNCOMPRESSED);
02382
02383 if(Problem == 0)
02384 {
02385
02386 ok = TRUE;
02387 }
02388 else
02389 {
02390 #ifdef _DEBUG
02391 String_256 Msg;
02392 _stprintf(Msg, "GenIdxFl::CreateThumbnail SaveBitmap - '%s' (0x%x '", (const TCHAR *)InFile->GetPath(), Problem);
02393 String_256 bodge(_R(IDE_ACCUSOFT_ERROR) - Problem);
02394 Msg += bodge;
02395 Msg += TEXT("')");
02396 ERROR3(Msg);
02397 #endif
02398 }
02399 }
02400 }
02401 }
02402
02403
02404 #endif // FALSE
02405
02406
02407 if(!ok)
02408 {
02409 if(!QuietThumbnail)
02410 {
02411
02412 String_256 Msg;
02413 Msg.MakeMsg(_R(IDS_LIBRARY_THUMBNAIL_PROBLEMS), (const TCHAR *)InFile->GetFileName(TRUE));
02414 Error::SetError(0, Msg, 0);
02415 INT32 ButtonPressed = InformWarning(0, _R(IDS_OK), _R(IDS_SILENT), _R(IDS_STOP), NULL);
02416 Error::ClearError();
02417
02418 if(ButtonPressed == 2)
02419 QuietThumbnail = TRUE;
02420
02421 if(ButtonPressed == 3)
02422 StopIndGen = TRUE;
02423 }
02424
02425
02426 SGLibOil::FileDelete(OutFile);
02427 }
02428
02429
02430
02431
02432 return ok;
02433
02434
02435 }
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462 BOOL GenerateIndexFile::CreateThumbnails(PathName *FileName, BOOL NewSystem)
02463 {
02464 if(FileName == NULL)
02465 {
02466 ERROR3("GenerateIndexFile::CreateThumbnails given a null filename - bad");
02467 return FALSE;
02468 }
02469
02470 if(LibType == SGLib_Font || LibType == SGLib_Colour)
02471 {
02472
02473 return FALSE;
02474 }
02475
02476
02477 String_8 Ending;
02478 Ending = FileName->GetType();
02479 Ending.toLower();
02480
02481
02482
02483 if(Ending == (String_8)"cxn")
02484 return TRUE;
02485
02486 if(Ending == (String_8)"cxw")
02487 return TRUE;
02488 if((Ending == (String_8)"web") || (Ending == (String_8)"xar"))
02489 {
02490
02491 CCDiskFile File(1024, FALSE, TRUE);
02492
02493 BOOL ok;
02494
02495
02496 TRY
02497 {
02498 ok = File.open(*FileName, ios::in | ios::binary | ios::nocreate);
02499 }
02500 CATCH( CFileException, e)
02501 {
02502 ok = FALSE;
02503 Error::ClearError();
02504 }
02505 END_CATCH
02506
02507
02508 BOOL IsNewFormat = FALSE;
02509 UINT32 FilterId = FILTERID_NONE;
02510
02511
02512
02513 if (ok)
02514 {
02515
02516
02517 if (BaseCamelotFilter::SkipToPreviewBitmap(&File, &IsNewFormat, &FilterId))
02518 {
02519 if (FilterId != FILTERID_NONE)
02520 return TRUE;
02521 }
02522
02523
02524
02525 else
02526 {
02527 GenericFilter* pGenericFilter = Filter::GetGenericFilter();
02528 if (pGenericFilter != NULL)
02529 {
02530 File.seek(0);
02531 Filter* pOldXarFilter = pGenericFilter->GetBestFilter(&File);
02532 if (pOldXarFilter != NULL &&
02533 pOldXarFilter->FilterID == FILTERID_NATIVE_EPS)
02534 return TRUE;
02535 }
02536 }
02537 }
02538 }
02539 if(Ending == (String_8)"art")
02540 return TRUE;
02541 if(Ending == (String_8)"cdr")
02542 return TRUE;
02543 if(Ending == (String_8)"cdt")
02544 return TRUE;
02545 if(Ending == (String_8)"cdx")
02546 return TRUE;
02547 if(Ending == (String_8)"cmx")
02548 return TRUE;
02549 if(Ending == (String_8)"eps")
02550 return TRUE;
02551
02552
02553 if(Ending == (String_8)"wmf")
02554 return TRUE;
02555 if(Ending == (String_8)"pcd")
02556 return TRUE;
02557
02558
02559 BOOL okl = TRUE, okm = TRUE, oks = TRUE;
02560 PathName InFile(*FileName);
02561 PathName OutFile;
02562
02563
02564 TCHAR LibraryTypeCharacter = 'A';
02565 UINT8 XsizeL = 128, YsizeL = 128;
02566 UINT8 XsizeM = 128, YsizeM = 64;
02567 UINT8 XsizeS = 45, YsizeS = 45;
02568
02569 String_256 OutFileStr;
02570
02571 if(NewSystem)
02572 {
02573 if(IndexIsRemote)
02574 {
02575
02576 OutFileStr = RemoteLocationOfIndex;
02577 SGLibOil::AppendSlashIfNotPresent(&OutFileStr);
02578
02579
02580 }
02581 else
02582 {
02583
02584 OutFileStr = LibPath.GetPath(TRUE);
02585 OutFileStr += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
02586 OutFileStr += TEXT("\\");
02587 }
02588
02589 OutFileStr += FileName->GetFileName(FALSE);
02590
02591
02592 OutFileStr += TEXT(".png");
02593
02594
02595
02596 OutFile.SetPathName(OutFileStr);
02597 if((SGLibOil::FileExists(&OutFile)) && (SGLibOil::FileSize(&OutFile) >= 0) )
02598 {
02599
02600 UINT32 InModified = SGLibOil::FileModified(&InFile);
02601 UINT32 OutModified = SGLibOil::FileModified(&OutFile);
02602
02603
02604
02605 if(InModified <= OutModified)
02606 return TRUE;
02607 }
02608
02609
02610 return (CreateThumbnail(&InFile, &OutFile, XsizeL, YsizeL));
02611 }
02612 else
02613 {
02614 switch(LibType)
02615 {
02616
02617 case SGLib_Texture:
02618 LibraryTypeCharacter = 'T';
02619 break;
02620
02621
02622 case SGLib_ClipArt:
02623 case SGLib_ClipArt_WebThemes:
02624 case SGLib_Bitmap:
02625 LibraryTypeCharacter = 'A';
02626 break;
02627
02628
02629 case SGLib_Font:
02630 LibraryTypeCharacter = 'F';
02631 XsizeL = 180;
02632 YsizeL = 26;
02633 XsizeM = 160;
02634 YsizeM = 12;
02635 XsizeS = 28;
02636 YsizeS = 32;
02637 break;
02638 }
02639
02640 String_256 Dir(LibPath.GetPath(TRUE));
02641 Dir += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
02642 Dir += TEXT("\\");
02643
02644
02645 _stprintf(OutFileStr, "%s%C%05dL.bmp", (TCHAR *)Dir, LibraryTypeCharacter, ID);
02646 OutFile.SetPathName(OutFileStr);
02647 okl = CreateThumbnail(&InFile, &OutFile, XsizeL, YsizeL);
02648
02649 _stprintf(OutFileStr, "%s%C%05dM.bmp", (TCHAR *)Dir, LibraryTypeCharacter, ID);
02650 OutFile.SetPathName(OutFileStr);
02651 okm = CreateThumbnail(&InFile, &OutFile, XsizeM, YsizeM);
02652
02653 _stprintf(OutFileStr, "%s%C%05dS.bmp", (TCHAR *)Dir, LibraryTypeCharacter, ID);
02654 OutFile.SetPathName(OutFileStr);
02655 oks = CreateThumbnail(&InFile, &OutFile, XsizeS, YsizeS);
02656
02657 return (okl && okm && oks);
02658 }
02659 return FALSE;
02660 }
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682 BOOL GenerateIndexFile::RipDescriptionFromFile(PathName *FileName, String_256 *Text, String_256 *Keywords, String_256 *Title)
02683 {
02684 ERROR3IF(FileName == NULL, "GenerateIndexFile::RipDescriptionFromIndex given null filename");
02685 ERROR3IF(Text == NULL, "GenerateIndexFile::RipDescriptionFromIndex given null text");
02686
02687 String_256 Type(FileName->GetType());
02688 Type.toLower();
02689
02690
02691 #ifdef _BATCHING
02692 if( (Type.Sub((String_8)"xar") != -1) || (Type.Sub((String_8)"art") != -1) )
02693 {
02694 PathName TmpPath(*FileName);
02695 TmpPath.SetType("CDR");
02696 if(SGLibOil::FileExists(&TmpPath))
02697 {
02698 return RipDescriptionFromCDRFile(&TmpPath, Text, Keywords, Title);
02699 }
02700 }
02701 #endif
02702
02703
02704
02705 if( (Type.Sub((String_8)"cxn") != -1) || (Type.Sub((String_8)"cxw") != -1) || (Type.Sub((String_8)"web") != -1) )
02706 {
02707 return RipDescriptionFromNativeV2File(FileName, Text, Keywords, Title);
02708 }
02709
02710
02711 if( (Type.Sub((String_8)"xar") != -1) || (Type.Sub((String_8)"art") != -1) || (Type.Sub((String_8)"eps") != -1) )
02712 {
02713
02714
02715
02716 BOOL IsNewNativeFile = FALSE;
02717 BOOL ok = RipDescriptionFromNativeV2File(FileName, Text, Keywords, Title, &IsNewNativeFile);
02718
02719 if (IsNewNativeFile)
02720 return ok;
02721
02722
02723
02724 return RipDescriptionFromEPSFile(FileName, Text, Keywords, Title);
02725 }
02726
02727 #ifdef _BATCHING
02728 if( (Type.Sub((String_8)"cdr") != -1) )
02729 {
02730 return RipDescriptionFromCDRFile(FileName, Text, Keywords, Title);
02731 }
02732 #endif
02733
02734 return FALSE;
02735 }
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764 BOOL GenerateIndexFile::RipDescriptionFromCDRFile(PathName *FileName, String_256 *Text, String_256 *Keywords, String_256 *Title)
02765 {
02766 #ifdef _BATCHING
02767
02768
02769
02770 BOOL ok = TRUE;
02771
02772 PathName CDRPath(*FileName);
02773
02774 if(!SGLibOil::FileExists(&CDRPath))
02775 {
02776 ERROR3("Can't find CDR file");
02777 return FALSE;
02778 }
02779
02780 CCDiskFile CDRFile(1024, FALSE, TRUE);
02781
02782 TRY
02783 {
02784
02785 ok = CDRFile.open(CDRPath, ios::in | ios::nocreate | ios::binary);
02786 }
02787
02788 CATCH(CFileException, e)
02789 {
02790 Error::ClearError();
02791 return FALSE;
02792 }
02793 END_CATCH
02794
02795 FilePos Position = 0x400;
02796 BOOL FoundInfoIKey = FALSE;
02797 CDRFile.seekIn(Position);
02798
02799 TRY
02800 {
02801
02802 while(!CDRFile.eof() && !FoundInfoIKey)
02803 {
02804 DWORD Buffer[256];
02805 memset(Buffer, 0, 256 * 4);
02806 CDRFile.seekIn(Position);
02807
02808 if(!FoundInfoIKey)
02809 {
02810 CDRFile.read((void *)Buffer, 8);
02811
02812
02813 if(!camStrcmp(((TCHAR *)Buffer) , "INFOIKEY"))
02814 {
02815 FoundInfoIKey = TRUE;
02816
02817
02818 INT32 Count = 3;
02819 while(Count > 0 && !CDRFile.eof())
02820 {
02821 CDRFile.read((void *)Buffer, 1);
02822 if(((TCHAR *)Buffer)[0] == 0)
02823 Count --;
02824 };
02825
02826 TCHAR Keys[256];
02827 Count = -1;
02828
02829 do {
02830
02831 CDRFile.read((void *)((char *)Keys + (++Count)), 1);
02832
02833
02834
02835 } while(Keys[Count] != 0 && !CDRFile.eof() && Count < 255);
02836
02837 *Keywords = (String_256)Keys;
02838
02839
02840
02841
02842 if(Keywords->Sub((String_8)" ") != -1)
02843 {
02844 String_256 Tmp(*Keywords);
02845 Tmp.Left(Keywords, Tmp.Sub((String_8)" "));
02846 }
02847
02848
02849 String_256 Tmp(*Keywords);
02850 String_256 Tmp2;
02851 INT32 Offset = Tmp.Sub((String_8)";");
02852 while(Offset != -1 && Tmp.Length()>0)
02853 {
02854 Tmp2 = Tmp;
02855 Tmp2.Right(&Tmp, ((Tmp2.Length() - Offset) - 1));
02856 Offset = Tmp.Sub((String_8)";");
02857 }
02858 *Title = Tmp;
02859
02860 ReplaceCharacters(Title, ',', ' ');
02861
02862 ReplaceCharacters(Keywords, ';', '|');
02863 ReplaceCharacters(Keywords, ',', '|');
02864 ReplaceCharacters(Keywords, ' ', '|');
02865
02866 CDRFile.close();
02867 return TRUE;
02868 }
02869 }
02870 Position ++;
02871 }
02872 }
02873
02874
02875 CATCH(CFileException, e)
02876 {
02877
02878 ok = FALSE;
02879
02880
02881 Error::ClearError();
02882 }
02883 END_CATCH
02884
02885
02886 TRY
02887 {
02888 if (CDRFile.isOpen())
02889 CDRFile.close();
02890 }
02891 CATCH(CFileException, e)
02892 {
02893
02894 Error::ClearError();
02895 }
02896 END_CATCH
02897
02898
02899 #endif
02900
02901 return FALSE;
02902 }
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929 BOOL GenerateIndexFile::RipDescriptionFromEPSFile(PathName *FileName, String_256 *Text, String_256 *Keywords, String_256 *Title)
02930 {
02931 CCDiskFile *EPSDiskFile = new CCDiskFile(1024, TRUE, FALSE);
02932 if (EPSDiskFile == NULL)
02933 {
02934 ERROR3("Problems allocating CCDiskFile");
02935 return FALSE;
02936 }
02937
02938 if (!EPSDiskFile->InitLexer(TRUE))
02939 {
02940 ERROR3("Problems with InitLexer");
02941 delete EPSDiskFile;
02942 return FALSE;
02943 }
02944
02945 if (!EPSDiskFile->open(*FileName, ios::in))
02946 {
02947 ERROR3("Can't open ART/EPS file");
02948 EPSDiskFile->DeinitLexer();
02949 delete EPSDiskFile;
02950 return FALSE;
02951 }
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969 String_256 TokenBuffer("");
02970 LexTokenType TokType = TOKEN_LINE;
02971
02972 BOOL FoundDocumentInfo = FALSE;
02973 BOOL FoundDescription = FALSE;
02974 BOOL FileHasNoComments = FALSE;
02975 BOOL UpHat = FALSE;
02976
02977
02978
02979 char Buf[4];
02980
02981
02982 memset(Buf, 0, 4);
02983
02984
02985 EPSDiskFile->read(Buf, 4);
02986
02987 UINT32* pUINT32 = (UINT32*)Buf;
02988
02989 if ((Buf[0]=='\xC5') && (Buf[1]=='\xD0') && (Buf[2]=='\xD3') && (Buf[3]=='\xC6'))
02990 {
02991
02992 FilePos StartOfEPS = 0;
02993 EPSDiskFile->read(&StartOfEPS, 4);
02994 TRACEUSER( "Richard", _T("EPS Starts at %ld\n"), StartOfEPS);
02995
02996
02997 EPSDiskFile->seekIn(StartOfEPS, ios::beg);
02998 }
02999 else if (pUINT32[0] == CXF_IDWORD1)
03000 {
03001
03002 TRACEUSER( "Neville", _T(".xar file in new format\n"));
03003 return FALSE;
03004 }
03005 else
03006 {
03007
03008 EPSDiskFile->seekIn(0, ios::beg);
03009
03010
03011
03012
03013
03014
03015
03016 TRACE( _T(".xar file without binary TIFF header! Dangerous! Assume no indexing data\n"));
03017
03018 }
03019
03020 BOOL TimeToFinish = FALSE;
03021
03022
03023
03024
03025
03026
03027 while(!TimeToFinish && !FileHasNoComments && EPSDiskFile->GetLineToken() && TokType != TOKEN_EOF)
03028 {
03029 TokType = EPSDiskFile->GetTokenType();
03030 if(TokType == TOKEN_LINE)
03031 {
03032 TokenBuffer = EPSDiskFile->GetTokenBuf();
03033
03034 if(FoundDocumentInfo)
03035 {
03036
03037 if(TokenBuffer.Sub((String_8)"%%+") == -1)
03038 {
03039 FileHasNoComments = !FoundDescription;
03040 TimeToFinish = TRUE;
03041 }
03042
03043
03044 if(TokenBuffer.Sub((String_8)"%%+c ") == 0)
03045 {
03046
03047
03048 String_256 TheDesc( ((TCHAR *)TokenBuffer) + 5 );
03049 String_256 TheDescU(TheDesc);
03050 TheDescU.toUpper();
03051
03052
03053
03054
03055
03056 if(TheDesc.Length() > 64)
03057 {
03058 TokenBuffer.Mid(&TheDesc, 5, 64);
03059 }
03060 else
03061 {
03062
03063 if(TheDesc.Sub((String_8)"^") != -1)
03064 {
03065 TokenBuffer.Mid(&TheDesc, 5, TheDesc.Sub((String_8)"^"));
03066 UpHat = TRUE;
03067 }
03068 }
03069
03070 if(Keywords && TheDescU.Sub(String_16(_R(IDS_LIBRARIES_RIP_XAR_KEYWORDS))) == 0)
03071 {
03072
03073
03074 INT32 exclude = 4;
03075
03076
03077 while ( (((TCHAR *)TheDesc)[exclude] == ' ') && (exclude < TheDesc.Length()))
03078 exclude ++;
03079
03080 TheDesc.Right(Keywords, TheDesc.Length() - exclude);
03081
03082 ReplaceCharacters(Keywords, ',', '|');
03083 }
03084 else
03085 {
03086 if(Title && TheDescU.Sub(String_16(_R(IDS_LIBRARIES_RIP_XAR_TITLE))) == 0)
03087 {
03088
03089 INT32 exclude = 6;
03090
03091
03092 while ( (((TCHAR *)TheDesc)[exclude] == ' ') && (exclude < TheDesc.Length()))
03093 exclude ++;
03094
03095 TheDesc.Right(Title, TheDesc.Length() - exclude);
03096
03097 ReplaceCharacters(Title, ',', '|');
03098 }
03099 else
03100 {
03101
03102 if(!FoundDescription)
03103 {
03104 ReplaceCharacters(&TheDesc, ',', '|');
03105 *Text = TheDesc;
03106 }
03107 }
03108 }
03109
03110 FoundDescription = TRUE;
03111 }
03112 }
03113 else
03114 {
03115
03116 String_256 TokenBufferU(TokenBuffer);
03117 TokenBufferU.toUpper();
03118
03119
03120 if(TokenBufferU.Sub((String_16)"%%DOCUMENTINFO") == 0)
03121 {
03122 FoundDocumentInfo = TRUE;
03123 }
03124
03125
03126 if( (TokenBufferU.Sub((String_16)"%%AWCOLOURTABLE") == 0)
03127 || (TokenBufferU.Sub((String_16)"%%COMPRESSION") == 0)
03128 || (TokenBuffer.Sub((String_8)"%") != 0) )
03129 {
03130 FileHasNoComments = TRUE;
03131 TimeToFinish = TRUE;
03132 }
03133 }
03134 }
03135 }
03136
03137
03138 EPSDiskFile->DeinitLexer();
03139
03140 if(EPSDiskFile->isOpen())
03141 EPSDiskFile->close();
03142
03143 delete EPSDiskFile;
03144
03145 return FoundDescription;
03146 }
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160
03161
03162
03163
03164
03165
03166
03167
03168
03169
03170
03171 BOOL GenerateIndexFile::RipDescriptionFromNativeV2File(PathName *FileName,
03172 String_256 *Text, String_256 *Keywords, String_256 *Title,
03173 BOOL *FileIsNewNative)
03174 {
03175 CCDiskFile *NativeDiskFile = new CCDiskFile(1024, TRUE, FALSE);
03176 if (NativeDiskFile == NULL)
03177 {
03178 ERROR3("Problems allocating CCDiskFile");
03179 return FALSE;
03180 }
03181
03182 if (!NativeDiskFile->open(*FileName, ios::in))
03183 {
03184 ERROR3("Can't open CXN/CXW file");
03185 delete NativeDiskFile;
03186 return FALSE;
03187 }
03188
03189 BOOL FoundDescription = FALSE;
03190
03191
03192
03193
03194
03195
03196 String_256 DocumentComment;
03197 BOOL IsNewNativeFile = FALSE;
03198 BOOL ok = BaseCamelotFilter::SkipToIndexInformation(NativeDiskFile, &DocumentComment, &IsNewNativeFile);
03199
03200 if (FileIsNewNative)
03201 *FileIsNewNative = IsNewNativeFile;
03202 if (!ok)
03203 {
03204 if(NativeDiskFile->isOpen())
03205 NativeDiskFile->close();
03206
03207 delete NativeDiskFile;
03208 return FALSE;
03209 }
03210
03211
03212
03213 if (!DocumentComment.IsEmpty())
03214 {
03215
03216
03217
03218
03219
03220 const TCHAR LineEnd = TEXT('\n');
03221 INT32 pos = 0;
03222 INT32 LastPos = 0;
03223 String_256 TheDesc;
03224 String_256 TheDescU;
03225 BOOL TimeToEnd = FALSE;
03226 while (pos >= 0 && !TimeToEnd)
03227 {
03228
03229 pos = DocumentComment.FindNextChar(LineEnd, pos);
03230
03231
03232
03233 if (pos == -1)
03234 {
03235
03236 pos = DocumentComment.Length() + 1;
03237
03238 TimeToEnd = TRUE;
03239 }
03240
03241
03242 if ((pos >= 0) && (pos - LastPos <= 1))
03243 {
03244
03245 pos += 1;
03246
03247 LastPos = pos;
03248 }
03249 else if ((pos >= 0) && (pos - LastPos > 1))
03250 {
03251
03252
03253 DocumentComment.Mid(&TheDesc, LastPos , pos - LastPos - 1);
03254
03255 pos += 1;
03256
03257 LastPos = pos;
03258
03259
03260 TheDescU = TheDesc;
03261 TheDescU.toUpper();
03262
03263 if(Keywords && TheDescU.Sub(String_16(_R(IDS_LIBRARIES_RIP_XAR_KEYWORDS))) == 0)
03264 {
03265
03266
03267 INT32 exclude = 4;
03268
03269
03270 while ( (((TCHAR *)TheDesc)[exclude] == ' ') && (exclude < TheDesc.Length()))
03271 exclude ++;
03272
03273 TheDesc.Right(Keywords, TheDesc.Length() - exclude);
03274
03275 ReplaceCharacters(Keywords, ',', '|');
03276 }
03277 else
03278 {
03279
03280 if(Title && TheDescU.Sub(String_16(_R(IDS_LIBRARIES_RIP_XAR_TITLE))) == 0)
03281 {
03282
03283 INT32 exclude = 6;
03284
03285
03286 while ( (((TCHAR *)TheDesc)[exclude] == ' ') && (exclude < TheDesc.Length()))
03287 exclude ++;
03288
03289 TheDesc.Right(Title, TheDesc.Length() - exclude);
03290
03291 ReplaceCharacters(Title, ',', '|');
03292 }
03293 else
03294 {
03295
03296 if(!FoundDescription)
03297 {
03298 ReplaceCharacters(&TheDesc, ',', '|');
03299 *Text = TheDesc;
03300 }
03301 }
03302 }
03303
03304
03305 FoundDescription = TRUE;
03306 }
03307 }
03308 }
03309
03310 if(NativeDiskFile->isOpen())
03311 NativeDiskFile->close();
03312
03313 delete NativeDiskFile;
03314
03315 return FoundDescription;
03316 }
03317
03318 #endif
03319
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335
03336
03337 BOOL GenerateIndexFile::ReplaceCharacters(StringBase *Source, TCHAR Search, TCHAR Replace)
03338 {
03339 ERROR3IF(Source == NULL, "GenerateIndexFile::ReplaceCharacters - source == null");
03340
03341 INT32 Len = Source->Length();
03342 if (Len == 0)
03343 return FALSE;
03344
03345 #ifdef _DEBUG
03346 INT32 Count = 0;
03347 #endif
03348
03349 TCHAR *Buf = (TCHAR *)*Source;
03350 for(INT32 i = 0; i < Len; i++)
03351 {
03352 if(*Buf == Search)
03353 {
03354 *Buf = Replace;
03355 #ifdef _DEBUG
03356 Count ++;
03357 #endif
03358 }
03359 Buf ++;
03360 }
03361
03362 #ifdef _DEBUG
03363 TRACEUSER("Richard", _T("%d %c chars found in %s and replaced with %c\n"), Count, Search, (TCHAR *)*Source, Replace);
03364 #endif
03365 return TRUE;
03366 }
03367
03368 #if 0
03369
03370
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389
03390 INT32 GenerateIndexFile::CountCommas(StringBase *Source, StringBase &SearchFor)
03391 {
03392 ERROR3IF(Source == NULL, "GenerateIndexFile::CountCommas - source == null");
03393
03394 INT32 Len = Source->Length();
03395 if(Len == 0)
03396 return 0;
03397
03398 INT32 Count = 0;
03399 INT32 Pos = Source->Sub(SearchFor);
03400
03401 if(Pos != -1)
03402 {
03403
03404 String_256 Left;
03405 Source->Left(&Left, Pos);
03406 Len = Left.Length();
03407
03408
03409 TCHAR *Buf = (TCHAR *)Left;
03410 for(INT32 i = 0; i < Len; i++)
03411 if(*(Buf++) == ',')
03412 Count ++;
03413 }
03414 return Count;
03415 }
03416
03417
03418
03419
03420
03421
03422
03423
03424
03425
03426
03427
03428
03429
03430
03431
03432
03433
03434
03435 BOOL GenerateIndexFile::GetToken(StringBase *Source, INT32 Count, String_256 *Result)
03436 {
03437 ERROR3IF(Source == NULL, "GenerateIndexFile::GetToken - source == null");
03438
03439 TCHAR *Comma = NULL;
03440
03441 if(Count == 0)
03442 {
03443 Comma = ((TCHAR *)*Source);
03444 }
03445 else
03446 {
03447 Comma = camStrchr((TCHAR *)*Source, _T(','));
03448
03449 if(Count > 2)
03450 {
03451 for(INT32 i = Count - 1; i > 0; i--)
03452 {
03453 Comma = camStrchr(Comma + 1, _T(','));
03454
03455
03456 if(Comma == NULL)
03457 return FALSE;
03458 }
03459 }
03460 }
03461
03462 INT32 first = (Comma - (TCHAR *)*Source) + 1;
03463 INT32 second = 0;
03464 if(camStrchr(Comma + 1, _T(',')))
03465 second = (camStrchr(Comma + 1, _T(',')) - (TCHAR *)*Source);
03466 else
03467 second = camStrlen((TCHAR *)*Source);
03468
03469
03470 while ( (((TCHAR *)*Source)[first] == ' ') && (first < Source->Length()))
03471 first ++;
03472
03473
03474 if(second > 0)
03475 while ( (((TCHAR *)*Source)[second-1] == ' ') && (second > first))
03476 second --;
03477
03478
03479 if(first != 0 && second != 0 && first < second)
03480 {
03481 Source->Mid(Result, first, second - first);
03482 return TRUE;
03483 }
03484
03485
03486 return FALSE;
03487 }
03488
03489
03490
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511 BOOL GenerateIndexFile::PrePassIndex(PathName *IndexFile, FilePos *Start,
03512 INT32 *DescriptionField, INT32 *KeywordField, INT32 *TitleField, String_256 *Description)
03513 {
03514 ERROR3IF(IndexFile == NULL, "GenerateIndexFile::PrePassIndex given null index");
03515
03516 CCDiskFile *TmpDiskFile = new CCDiskFile(1024, TRUE, FALSE);
03517 if (TmpDiskFile == NULL)
03518 {
03519 ERROR3("Null index file allocated");
03520 return FALSE;
03521 }
03522
03523 if (!TmpDiskFile->InitLexer(TRUE))
03524 {
03525 ERROR3("Problems with InitLexer");
03526 delete TmpDiskFile;
03527 TmpDiskFile = NULL;
03528 return FALSE;
03529 }
03530
03531 if (!TmpDiskFile->open(*IndexFile, ios::in))
03532 {
03533 ERROR3("Can't open index file for pre pass");
03534 TmpDiskFile->DeinitLexer();
03535 delete TmpDiskFile;
03536 TmpDiskFile = NULL;
03537 return FALSE;
03538 }
03539
03540 LexTokenType TokType = TOKEN_LINE;
03541 BOOL FoundFieldTitles = FALSE;
03542 BOOL FoundStart = FALSE;
03543
03544
03545 while(TmpDiskFile->GetLineToken() && TokType != TOKEN_EOF && !FoundStart)
03546 {
03547 TokType = TmpDiskFile->GetTokenType();
03548 if(TokType == TOKEN_LINE || TokType == TOKEN_COMMENT)
03549 {
03550 String_256 TokenBufferU(TmpDiskFile->GetTokenBuf());
03551 TokenBufferU.toUpper();
03552
03553 String_16 FilenameStr(_R(IDS_LIBRARIES_INDEX_ITEM_FILENAME));
03554 String_16 DescStr(_R(IDS_LIBRARIES_INDEX_ITEM_DESC));
03555 FilenameStr.toUpper();
03556 DescStr.toUpper();
03557
03558
03559 if(TokType == TOKEN_LINE && !FoundFieldTitles && TokenBufferU.Sub(FilenameStr) == 0 && TokenBufferU.Sub(DescStr) > 0)
03560 {
03561 if(DescriptionField)
03562 {
03563 String_16 Str(_R(IDS_LIBRARIES_INDEX_ITEM_DESC));
03564 Str.toUpper();
03565 *DescriptionField = CountCommas(&TokenBufferU, Str);
03566 }
03567
03568 if(KeywordField)
03569 {
03570 String_16 Str(_R(IDS_LIBRARIES_INDEX_ITEM_KEY));
03571 Str.toUpper();
03572 *KeywordField = CountCommas(&TokenBufferU, Str);
03573 }
03574
03575 if(TitleField)
03576 {
03577 String_16 Str(_R(IDS_LIBRARIES_INDEX_ITEM_TITLE));
03578 Str.toUpper();
03579 *TitleField = CountCommas(&TokenBufferU, Str);
03580 }
03581
03582 FoundFieldTitles = TRUE;
03583 }
03584 else if(TokType == TOKEN_LINE && TokenBufferU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_START))) == 0)
03585 {
03586
03587 if(Start)
03588 *Start = TmpDiskFile->tellIn();
03589
03590 FoundStart = TRUE;
03591 }
03592 else
03593 {
03594
03595
03596 INT32 Offset = TokenBufferU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_DESCRITION)));
03597
03598 if(Description && Offset > -1 && Offset < 2)
03599 {
03600 String_256 TokenBuffer(TmpDiskFile->GetTokenBuf());
03601 TokenBuffer.Right(Description, TokenBuffer.Length() - (12 + Offset));
03602 LibraryFile::KillLeadingSpaces(Description);
03603 }
03604 }
03605 }
03606 }
03607
03608
03609 TmpDiskFile->DeinitLexer();
03610
03611 if(TmpDiskFile->isOpen())
03612 TmpDiskFile->close();
03613
03614 delete TmpDiskFile;
03615
03616 return (FoundFieldTitles && FoundStart);
03617 }
03618
03619
03620
03621
03622
03623
03624
03625
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646 BOOL GenerateIndexFile::RipDescriptionFromIndex(PathName *IndexFile, PathName *FileName,
03647 FilePos Start, INT32 DescriptionField, INT32 KeywordField, INT32 TitleField,
03648 String_256 *Text, String_256 *Keywords, String_256 *Title)
03649 {
03650 ERROR3IF(IndexFile == NULL, "GenerateIndexFile::RipDescriptionFromIndex given null index");
03651 ERROR3IF(FileName == NULL, "GenerateIndexFile::RipDescriptionFromIndex given null filename");
03652 ERROR3IF(Text == NULL, "GenerateIndexFile::RipDescriptionFromIndex given null text");
03653
03654 if(IndexFile == NULL || FileName == NULL || Text == NULL)
03655 return FALSE;
03656
03657
03658 if(KeywordField < 2 || TitleField < 2 || (DescriptionField == TitleField))
03659 return FALSE;
03660
03661 CCDiskFile *TmpDiskFile = new CCDiskFile(1024, TRUE, FALSE);
03662 if (TmpDiskFile == NULL)
03663 {
03664 ERROR3("Null index file allocated");
03665 return FALSE;
03666 }
03667
03668 if (!TmpDiskFile->InitLexer(TRUE))
03669 {
03670 ERROR3("Problems with InitLexer");
03671 delete TmpDiskFile;
03672 return FALSE;
03673 }
03674
03675 if (!TmpDiskFile->open(*IndexFile, ios::in))
03676 {
03677 ERROR3("Can't open backup index file");
03678 TmpDiskFile->DeinitLexer();
03679 delete TmpDiskFile;
03680 return FALSE;
03681 }
03682
03683
03684 TmpDiskFile->seekIn(Start);
03685
03686 String_256 TokenBuffer;
03687 LexTokenType TokType = TOKEN_LINE;
03688 BOOL FoundDescription = FALSE;
03689 String_256 TheFile(FileName->GetFileName());
03690
03691 String_256 ShortPath(FileName->GetPath());
03692 TheFile.toUpper();
03693
03694
03695
03696
03697 #ifdef _DEBUG
03698 ERROR3IF(!MakeShortPath((TCHAR *)ShortPath, _MAX_PATH), "MakeShortPath failed in SGIndGen");
03699 #else
03700 MakeShortPath((TCHAR *)ShortPath, _MAX_PATH);
03701 #endif
03702
03703
03704 PathName SrtPath(ShortPath);
03705 ShortPath = SrtPath.GetFileName(TRUE);
03706
03707
03708 while(TmpDiskFile->GetLineToken() && TokType != TOKEN_EOF && !FoundDescription)
03709 {
03710 TokType = TmpDiskFile->GetTokenType();
03711 if(TokType == TOKEN_LINE)
03712 {
03713 TokenBuffer = TmpDiskFile->GetTokenBuf();
03714 String_256 TokenBufferU(TokenBuffer);
03715 TokenBufferU.toUpper();
03716
03717
03718
03719
03720 if(TokenBufferU.Sub(TheFile) == 0 || TokenBufferU.Sub(ShortPath) == 0)
03721 {
03722 TRACEUSER( "Richard", _T("Matched %s\n"), (TCHAR *)TheFile);
03723
03724
03725
03726
03727 if(GetToken(&TokenBuffer, DescriptionField, Text))
03728 {
03729 FoundDescription = TRUE;
03730 TRACEUSER( "Richard", _T("Description - '%s'\n"), (TCHAR *)*Text);
03731 }
03732
03733 if(Title && TitleField != 0)
03734 {
03735
03736
03737
03738 if(GetToken(&TokenBuffer, TitleField, Title))
03739 {
03740 FoundDescription = TRUE;
03741 TRACEUSER( "Richard", _T("Title - '%s'\n"), (TCHAR *)*Title);
03742 }
03743 }
03744
03745 if(Keywords && KeywordField != 0)
03746 {
03747
03748
03749
03750
03751 if(GetToken(&TokenBuffer, KeywordField, Keywords))
03752 {
03753 FoundDescription = TRUE;
03754 TRACEUSER( "Richard", _T("Keywords - '%s'\n"), (TCHAR *)*Keywords);
03755 }
03756 }
03757 }
03758 }
03759 }
03760
03761
03762
03763
03764
03765
03766
03767
03768 TmpDiskFile->DeinitLexer();
03769
03770 if(TmpDiskFile->isOpen())
03771 TmpDiskFile->close();
03772
03773 delete TmpDiskFile;
03774
03775
03776
03777 if(Title->Length() == 0 && FoundDescription)
03778 {
03779 String_256 Type(FileName->GetType());
03780 Type.toLower();
03781 if( (Type.Sub((String_8)"art") == 0) || (Type.Sub((String_8)"xar") == 0))
03782 {
03783 *Title = FileName->GetFileName(FALSE);
03784
03785
03786 Title->toLower();
03787
03788
03789 TCHAR First = camToupper(((TCHAR *)*Title)[0]);
03790 ((TCHAR *)*Title)[0] = First;
03791 }
03792 }
03793
03794 return FoundDescription;
03795 }
03796
03797
03798
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810
03811
03812
03813
03814 BOOL GenerateIndexFile::AddLineToIndex(String_256 *Text)
03815 {
03816 if(IndexFile == NULL)
03817 {
03818 ERROR3("GenerateIndexFile::AddLineToIndex called with NULL index file");
03819 return FALSE;
03820 }
03821
03822 if(Text == NULL)
03823 {
03824 ERROR3("GenerateIndexFile::AddLineToIndex called with NULL text ptr");
03825 return FALSE;
03826 }
03827
03828 IndexFile->write(*Text, (UINT32)Text->Length());
03829
03830 return TRUE;
03831 }
03832
03833
03834
03835
03836
03837
03838
03839
03840
03841
03842
03843
03844
03845
03846
03847
03848
03849
03850 BOOL GenerateIndexFile::CheckExistingIndexForRemoteness(PathName *IndexFile, PathName *FilesPath)
03851 {
03852 ERROR3IF(IndexFile == NULL || FilesPath == NULL, "GenerateIndexFile::CheckExistingIndexForRemoteness given null params");
03853 if(IndexFile == NULL || FilesPath == NULL)
03854 return FALSE;
03855
03856 if(!SGLibOil::FileExists(IndexFile))
03857 return FALSE;
03858
03859 CCDiskFile *TmpDiskFile = new CCDiskFile(1024, FALSE, TRUE);
03860 if (TmpDiskFile == NULL)
03861 {
03862 ERROR3("Null index file allocated");
03863 return FALSE;
03864 }
03865
03866 if (!TmpDiskFile->InitLexer(TRUE))
03867 {
03868 ERROR3("Problems with InitLexer");
03869 delete TmpDiskFile;
03870 TmpDiskFile = NULL;
03871 return FALSE;
03872 }
03873
03874 TRY
03875 {
03876 if (!TmpDiskFile->open(*IndexFile, ios::in))
03877 {
03878 ERROR3("Can't open index file for pre pass");
03879 TmpDiskFile->DeinitLexer();
03880 delete TmpDiskFile;
03881 TmpDiskFile = NULL;
03882 return FALSE;
03883 }
03884 }
03885
03886 CATCH(CFileException, e)
03887 {
03888
03889 Error::ClearError();
03890 return FALSE;
03891 }
03892 END_CATCH
03893
03894 LexTokenType TokType = TOKEN_LINE;
03895 String_256 RemotePath;
03896 BOOL FoundRemotePath = FALSE;
03897 BOOL FinishLooping = FALSE;
03898
03899
03900 while(TmpDiskFile->GetLineToken() && TokType != TOKEN_EOF && !FinishLooping)
03901 {
03902 TokType = TmpDiskFile->GetTokenType();
03903 if(TokType == TOKEN_LINE || TokType == TOKEN_COMMENT)
03904 {
03905 String_256 TokenBufferU(TmpDiskFile->GetTokenBuf());
03906 TokenBufferU.toUpper();
03907
03908 if(TokType == TOKEN_LINE && TokenBufferU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_START))) == 0)
03909 FinishLooping = TRUE;
03910 else
03911 {
03912
03913 INT32 Offset = TokenBufferU.Sub(String_16(_R(IDS_LIBRARIES_INDEX_FILES)));
03914 if(Offset == 0)
03915 {
03916 String_256 TokenBuffer(TmpDiskFile->GetTokenBuf());
03917 TokenBuffer.Right(&RemotePath, TokenBuffer.Length() - (6 + Offset));
03918 LibraryFile::KillLeadingSpaces(&RemotePath);
03919 FinishLooping = TRUE;
03920 FoundRemotePath = TRUE;
03921 FilesPath->SetPathName(RemotePath);
03922 }
03923 }
03924 }
03925 }
03926
03927
03928 TmpDiskFile->DeinitLexer();
03929
03930 if(TmpDiskFile->isOpen())
03931 TmpDiskFile->close();
03932
03933 delete TmpDiskFile;
03934
03935 return (FoundRemotePath);
03936 }
03937
03938
03939
03940
03941
03942
03943
03944
03945
03946
03947
03948
03949
03950
03951
03952
03953
03954
03955
03956
03957
03958
03959
03960 BOOL GenerateIndexFile::Generate(PathName *IFile, PathName *LibDirPath, String_64 *Auth,
03961 SGLibType Type, BOOL Thumbnails)
03962 {
03963
03964
03965
03966
03967 if(IFile == NULL || LibDirPath == NULL)
03968 {
03969 ERROR3("GenerateIndexFile::Generate null params are bad");
03970 return FALSE;
03971 }
03972
03973 if(SGLibOil::FileExists(IFile) && IsDirectoryReadOnly(LibDirPath))
03974 {
03975 ERROR3("Chosen directory is read only and already has an index... (We shouldn't really get here...)");
03976 return FALSE;
03977 }
03978
03979
03980 IndexIsRemote = CheckExistingIndexForRemoteness(IFile, LibDirPath);
03981
03982 Index = *IFile;
03983 LibPath = *LibDirPath;
03984 LibType = Type;
03985 DoThumbnails = Thumbnails;
03986
03987 #ifdef _DEBUG
03988 String_256 ChecksumDir(LibPath.GetPath());
03989 UINT32 Checksum = GetDirectoryChecksum(&ChecksumDir, Type);
03990
03991 #endif
03992
03993 if(Auth != NULL)
03994 Author = *Auth;
03995 else
03996 Author = "";
03997
03998
03999 IndexFile = NULL;
04000
04001
04002 IndexCountOff = 0;
04003
04004
04005 hSearch = NULL;
04006
04007
04008 ID = 0;
04009
04010
04011
04012 TmpIndexFile = NULL;
04013
04014
04015 IndexIsRemote = FALSE;
04016 RemoteLocationOfIndex = "";
04017 RemoteLocationOfFiles = "";
04018
04019 BOOL ok = FALSE;
04020
04021
04022 QuietThumbnail = FALSE;
04023
04024
04025 StopIndGen = FALSE;
04026
04027
04028 TotalFiles = CountValidFiles();
04029
04030 if(TotalFiles == 0)
04031 {
04032
04033 INT32 ButtonPressed = InformWarning(_R(IDS_LIBRARY_NO_FILES), _R(IDS_OK), NULL);
04034 Error::ClearError();
04035 ok = FALSE;
04036 }
04037 else
04038 {
04039
04040 String_64 *Status = new String_64(_R(IDS_LIBRARY_GENERATING_INDEX));
04041 BeginSlowJob(TotalFiles, FALSE, Status);
04042
04043
04044 if(CreateIndexFile())
04045 {
04046
04047 if(DoIndexHeader())
04048 {
04049
04050 ok = AddToSubLibrary();
04051
04052
04053 if(!FixSubLibraryNumber())
04054 ok = FALSE;
04055 }
04056 }
04057
04058
04059 CloseSearchHandle();
04060
04061
04062 CloseIndexFileHandle();
04063
04064
04065 if(TmpIndexFile != NULL)
04066 {
04067 SGLibOil::FileDelete(TmpIndexFile);
04068 delete TmpIndexFile;
04069 TmpIndexFile = NULL;
04070 }
04071
04072 if(Status != NULL)
04073 {
04074 delete Status;
04075 Status = NULL;
04076 }
04077
04078 EndSlowJob();
04079 }
04080
04081 if(!ok)
04082 {
04083 TRACEUSER( "Richard", _T("All finished and hunky-dorey...\n"));
04084 }
04085
04086
04087 if(IndexIsRemote)
04088 *IFile = Index;
04089
04090
04091 Error::ClearError();
04092
04093 return ok;
04094 }
04095
04096
04097
04098
04099
04100
04101
04102
04103
04104
04105
04106
04107
04108
04109
04110
04111
04112
04113
04114
04115 UINT32 GenerateIndexFile::GetDirectoryChecksum(String_256 *Directory, SGLibType Type)
04116 {
04117 UINT32 Checksum = 0;
04118
04119 if(GenerateIndexFile::UseAutomaticUpdate)
04120 {
04121
04122 String_64 Status(_R(IDS_LIBRARIES_CALCULATING_CHECKSUM));
04123 BeginSlowJob(-1, FALSE, &Status);
04124
04125 WIN32_FIND_DATA FileData;
04126 BOOL fFinished = FALSE;
04127 HANDLE hSearch = 0;
04128
04129 String_256 FileSearch(*Directory);
04130 SGLibOil::AppendSlashIfNotPresent(&FileSearch);
04131
04132
04133 FileSearch += TEXT("*.*");
04134
04135
04136 hSearch = FindFirstFile(FileSearch, &FileData);
04137 if (hSearch == INVALID_HANDLE_VALUE)
04138 {
04139 ERROR3("No valid files found in this directory");
04140 fFinished = TRUE;
04141 }
04142
04143
04144 while (!fFinished)
04145 {
04146
04147 String_256 FileToAddStr(*Directory);
04148 SGLibOil::AppendSlashIfNotPresent(&FileToAddStr);
04149
04150
04151 FileToAddStr += (TCHAR *)FileData.cFileName;
04152
04153
04154 DWORD FileAttributes = GetFileAttributes(FileToAddStr);
04155
04156 if( ((FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
04157 (FileAttributes & FILE_ATTRIBUTE_HIDDEN) ||
04158 (FileAttributes & FILE_ATTRIBUTE_SYSTEM)) == 0)
04159 {
04160 PathName FileToAdd(FileToAddStr);
04161
04162
04163 if(IsFileType(&FileToAdd, Type))
04164 {
04165 UINT32 Modified = SGLibOil::FileModified(&FileToAdd);
04166 INT32 Size = SGLibOil::FileSize(&FileToAdd);
04167
04168 Checksum ++;
04169 Checksum += Modified;
04170 Checksum += Size;
04171 }
04172 }
04173
04174
04175 if (!FindNextFile(hSearch, &FileData))
04176 fFinished = TRUE;
04177 }
04178
04179
04180 if(hSearch != NULL)
04181 if (!FindClose(hSearch))
04182 ERROR3("Couldn't close search handle.");
04183 hSearch = NULL;
04184
04185 EndSlowJob();
04186 }
04187
04188 return Checksum;
04189 }
04190
04191 #endif