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 #include "camtypes.h"
00101 #include "sgliboil.h"
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #include "ccdc.h"
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 #include "dlgmgr.h"
00128
00129 #include "oilbitmap.h"
00130
00131
00132 #include "progress.h"
00133 #include "helpuser.h"
00134
00135
00136
00137
00138
00139 #include "camelot.h"
00140 #include "camdoc.h"
00141 #include "unicdman.h"
00142
00143
00144 #include "cxftags.h"
00145 #include "cxfile.h"
00146
00147
00148
00149
00150 #include "pathnmex.h"
00151
00152
00153
00154
00155
00156 #include "nodebmp.h"
00157 #include "product.h"
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 #if defined(__WXMSW__)
00169 #include <shfolder.h>
00170 #endif
00171
00172 extern void FixFPControlRegister(void);
00173
00174
00175 PORTNOTE("dialog","Removed OpClipartImport")
00176 #ifndef EXCLUDE_FROM_XARALX
00177 CC_IMPLEMENT_DYNCREATE(OpClipartImport, SelOperation)
00178 #endif
00179 PORTNOTE("dialog","Removed OpBitmapImport")
00180 #ifndef EXCLUDE_FROM_XARALX
00181 CC_IMPLEMENT_DYNCREATE(OpBitmapImport, Operation)
00182 #endif
00183 CC_IMPLEMENT_DYNCREATE(SGLibOil, CCObject)
00184
00185
00186
00187 #define new CAM_DEBUG_NEW
00188
00189 extern BOOL getDrive(const TCHAR**, TCHAR* drive);
00190 extern BOOL getNetDrive(const TCHAR**, TCHAR* drive, BOOL *BadCharacter);
00191
00192 TCHAR *SGLibOil::TmpSndName = NULL;
00193
00194
00195
00196
00197
00198 #define SCANFORXARAMOUNT
00199
00200 #if defined(__WXMSW__)
00201 const TCHAR chPathSep = _T('\\');
00202 #else
00203 const TCHAR chPathSep = _T('/');
00204 #endif
00205
00206 PORTNOTE("dialog","Removed OpClipartImport impl.")
00207 #ifndef EXCLUDE_FROM_XARALX
00208
00209
00210
00211 ClipartImportParam::ClipartImportParam()
00212 {
00213 File = NULL;
00214 Import = FALSE;
00215 Result = FALSE;
00216 DropInfo = NULL;
00217 }
00218
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 OpClipartImport::OpClipartImport() : SelOperation()
00236 {
00237 OpFlags.HasOwnTimeIndicator = TRUE;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 OpClipartImport::~OpClipartImport()
00256 {
00257 }
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 BOOL OpClipartImport::Init()
00272 {
00273 OpBitmapImport::Init();
00274 OpAsynchBitmapImport::Init();
00275
00276 return RegisterOpDescriptor(
00277 0,
00278 _R(IDS_OPCLIPARTIMPORT),
00279 CC_RUNTIME_CLASS(OpClipartImport),
00280 OPTOKEN_OPCLIPARTIMPORT,
00281 OpClipartImport::GetState,
00282 0,
00283 0,
00284 0,
00285 0
00286
00287 );
00288 }
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 OpState OpClipartImport::GetState(String_256* pString, OpDescriptor* pOpDesc)
00302 {
00303
00304 OpState OpSt;
00305
00306 return(OpSt);
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 void OpClipartImport::Do(OpDescriptor *NotUsed)
00325 {
00326 ERROR3("OpClipartImport does not provide a Do() function - Use DoWithParam");
00327 End();
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 void OpClipartImport::DoWithParam(OpDescriptor* pOp, OpParam* pClipartImportParam)
00348 {
00349 ClipartImportParam *pInfo = (ClipartImportParam *) pClipartImportParam;
00350
00351 if(pInfo == NULL)
00352 {
00353 ERROR3("OpClipartImport called with NULL info pointer");
00354 FailAndExecute();
00355 End();
00356 return;
00357 }
00358 else
00359 {
00360 if(pInfo->File == NULL)
00361 {
00362 ERROR3("OpClipartImport called with NULL file pointer");
00363 FailAndExecute();
00364 End();
00365 return;
00366 }
00367 }
00368
00369 PathName Path = *(pInfo->File);
00370
00371 if(!Path.IsValid())
00372 {
00373 ERROR3("Filename is invalid");
00374
00375 FailAndExecute();
00376 End();
00377 return;
00378 }
00379
00380 if(!pInfo->Import)
00381 {
00382
00383 CCamApp *pApp = AfxGetApp();
00384 BaseFileDialog::SelectedFilter = 0;
00385
00386 String_256 OpenPath((const TCHAR *)Path.GetPath());
00387
00388
00389
00390 CCamDoc* pDoc = (CCamDoc*) pApp->OpenDocumentFile((TCHAR *)OpenPath);
00391
00392
00393
00394 if(pDoc != NULL) pOurDoc = Document::GetSelected();
00395
00396 Document* pCurDoc = pDoc->GetKernelDoc();
00397
00398
00399
00400
00401 }
00402 else
00403 {
00404
00405 if(Document::GetSelected() == NULL)
00406 {
00407 ERROR3("No selected document");
00408
00409 FailAndExecute();
00410 End();
00411 return;
00412 }
00413
00414
00415 UINT32 SelFilter = FILTERID_GENERIC;
00416 BOOL LayersImport = FALSE;
00417
00418
00419 Filter *pFilter = Filter::GetFirst();
00420
00421 if(pFilter == NULL)
00422 return;
00423
00424 while (pFilter != NULL)
00425 {
00426 if ((pFilter->GetFlags().CanImport) && (pFilter->FilterID == SelFilter))
00427
00428 break;
00429
00430
00431 pFilter = Filter::GetNext(pFilter);
00432 }
00433
00434 if (pFilter == NULL)
00435 {
00436 InformError(_R(IDT_CANT_FIND_FILTER));
00437 FailAndExecute();
00438 End();
00439 return;
00440 }
00441 else
00442 {
00443
00444
00445
00446 if (!pFilter->IS_KIND_OF(FilterFamily))
00447 {
00448 UINT32 Size = 1024;
00449 INT32 FileSize;
00450 ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);
00451
00452
00453 if (FilterBuf == NULL)
00454 {
00455
00456 InformError();
00457 FailAndExecute();
00458 End();
00459 return;
00460 }
00461
00462
00463
00464
00465
00466
00467 pFilter->PreHowCompatible();
00468
00469
00470
00471
00472 if (pFilter->HowCompatible(Path, FilterBuf, Size, FileSize) < 9)
00473 {
00474
00475 ErrorInfo Question;
00476 Question.ErrorMsg = _R(IDT_IMPQUERY_NOTSURE);
00477 Question.Button[0] = _R(IDB_IMPQUERY_IMPORT);
00478 Question.Button[1] = _R(IDB_IMPQUERY_DONTIMPORT);
00479
00480 if (AskQuestion(&Question) != _R(IDB_IMPQUERY_IMPORT))
00481 {
00482
00483 TRACEUSER( "Richard", wxT("Filter compatibility was less than 10\n") );
00484
00485
00486 CCFree(FilterBuf);
00487 FailAndExecute();
00488 InformMessage(_R(IDT_IMP_USERABORT));
00489 End();
00490 return;
00491 }
00492 }
00493
00494
00495 CCFree(FilterBuf);
00496 }
00497
00498
00499 if (DoStartSelOp(FALSE))
00500
00501
00502 {
00503
00504 CCDiskFile DiskFile(1024, FALSE, TRUE);
00505
00506
00507
00508 Document* pCurDoc;
00509 ImportPosition Pos;
00510
00511 if (pInfo->DropInfo)
00512 {
00513
00514
00515 pCurDoc = pInfo->DropInfo->pDoc;
00516
00517 Pos.Position = pInfo->DropInfo->DropPos;
00518 Pos.pSpread = pInfo->DropInfo->pSpread;
00519 }
00520 else
00521 {
00522 pCurDoc = Document::GetSelected();
00523 }
00524
00525 if(pCurDoc == NULL)
00526 {
00527 ERROR3("OpClipartImport::DoWithParam retrieved NULL selected doc");
00528 return;
00529 }
00530
00531 TRY
00532 {
00533 if (!DiskFile.open(Path, ios::in | ios::binary))
00534 {
00535
00536 TRACEUSER( "Richard", wxT("Failed to open file in ClipartImport Do") );
00537 InformError(_R(IDT_IMPORT_NOTFOUND));
00538 FailAndExecute();
00539 End();
00540 return;
00541 }
00542
00543
00544 ImportPosition* ImportPos;
00545 if (pInfo->DropInfo)
00546 ImportPos = &Pos;
00547 else
00548 {
00549
00550
00551
00552 DocView* pDocView=DocView::GetCurrent();
00553
00554
00555 Pos=pDocView->GetCentreImportPosition();
00556
00557 ImportPos=&Pos;
00558 }
00559
00560
00561
00562 if (!pFilter->DoImport(this, &DiskFile, pCurDoc, FALSE, ImportPos))
00563 {
00564
00565 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00566 InformError();
00567 else
00568 Error::ClearError();
00569 FailAndExecute();
00570 End();
00571
00572
00573 if (DiskFile.isOpen())
00574 DiskFile.close();
00575
00576 return;
00577 }
00578
00579
00580 if (DiskFile.isOpen())
00581 DiskFile.close();
00582
00583 }
00584
00585
00586 CATCH(CFileException, e)
00587 {
00588
00589 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00590 InformError();
00591 else
00592 Error::ClearError();
00593
00594
00595 TRY
00596 {
00597 if (DiskFile.isOpen())
00598 DiskFile.close();
00599 }
00600 CATCH(CFileException, e)
00601 {
00602
00603 }
00604 END_CATCH
00605
00606
00607 FailAndExecute();
00608 End();
00609 return;
00610 }
00611 END_CATCH
00612 }
00613 }
00614 }
00615
00616
00617 GetMainFrame()->SetActiveWindow();
00618
00619 End();
00620 }
00621
00622
00623
00624
00625
00626
00627
00628
00629 BitmapImportParam::BitmapImportParam()
00630 {
00631 File = NULL;
00632 Result = FALSE;
00633
00634 pTargetDoc = 0;
00635 TagObjectToFill = 0;
00636 TagObjectValid = false;
00637 pObject = 0;
00638 pObjectValid = false;
00639 }
00640
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657 OpBitmapImport::OpBitmapImport() : Operation()
00658 {
00659 OpFlags.HasOwnTimeIndicator = TRUE;
00660 }
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 OpBitmapImport::~OpBitmapImport()
00678 {
00679 }
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693 BOOL OpBitmapImport::Init()
00694 {
00695 return RegisterOpDescriptor(
00696 0,
00697 _R(IDS_OPCLIPARTIMPORT),
00698 CC_RUNTIME_CLASS(OpBitmapImport),
00699 OPTOKEN_OPBITMAPIMPORT,
00700 OpBitmapImport::GetState,
00701 0,
00702 0,
00703 0,
00704 0
00705
00706 );
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720 OpState OpBitmapImport::GetState(String_256* pString, OpDescriptor* pOpDesc)
00721 {
00722
00723 OpState OpSt;
00724
00725 return(OpSt);
00726 }
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743 void OpBitmapImport::Do(OpDescriptor *NotUsed)
00744 {
00745 ERROR3("OpBitmapImport does not provide a Do() function - Use DoWithParam");
00746 End();
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 void OpBitmapImport::DoWithParam(OpDescriptor* pOp, OpParam* pBitmapImportParam)
00766 {
00767 BitmapImportParam *pInfo = (BitmapImportParam *) pBitmapImportParam;
00768 KernelBitmap* pBitmap = 0;
00769
00770 if(pInfo == NULL)
00771 {
00772 ERROR3("OpBitmapImport called with NULL info pointer");
00773 FailAndExecute();
00774 End();
00775 return;
00776 }
00777 else
00778 {
00779 if(pInfo->File == NULL)
00780 {
00781 ERROR3("OpBitmapImport called with NULL file pointer");
00782 FailAndExecute();
00783 End();
00784 return;
00785 }
00786 }
00787
00788 PathName Path = *(pInfo->File);
00789
00790 if(!Path.IsValid())
00791 {
00792 ERROR3("Filename is invalid");
00793
00794 FailAndExecute();
00795 End();
00796 return;
00797 }
00798
00799
00800 UINT32 SelFilter = FILTERID_GENERIC;
00801 BOOL LayersImport = FALSE;
00802
00803
00804 Filter *pFilter = Filter::GetFirst();
00805
00806 if(pFilter == NULL)
00807 return;
00808
00809 while (pFilter != NULL)
00810 {
00811 if ((pFilter->GetFlags().CanImport) && (pFilter->FilterID == SelFilter))
00812
00813 break;
00814
00815
00816 pFilter = Filter::GetNext(pFilter);
00817 }
00818
00819 if (pFilter == NULL)
00820 {
00821 InformError(_R(IDT_CANT_FIND_FILTER));
00822 FailAndExecute();
00823 End();
00824 return;
00825 }
00826 else
00827 {
00828
00829
00830
00831 if (!pFilter->IS_KIND_OF(FilterFamily))
00832 {
00833 UINT32 Size = 1024;
00834 INT32 FileSize;
00835 ADDR FilterBuf = pFilter->LoadInitialSegment(Path, &Size, &FileSize);
00836
00837
00838 if (FilterBuf == NULL)
00839 {
00840
00841 InformError();
00842 FailAndExecute();
00843 End();
00844 return;
00845 }
00846
00847
00848
00849
00850
00851
00852 pFilter->PreHowCompatible();
00853
00854
00855
00856
00857 if (pFilter->HowCompatible(Path, FilterBuf, Size, FileSize) < 9)
00858 {
00859
00860 ErrorInfo Question;
00861 Question.ErrorMsg = _R(IDT_IMPQUERY_NOTSURE);
00862 Question.Button[0] = _R(IDB_IMPQUERY_IMPORT);
00863 Question.Button[1] = _R(IDB_IMPQUERY_DONTIMPORT);
00864
00865 if (AskQuestion(&Question) != _R(IDB_IMPQUERY_IMPORT))
00866 {
00867
00868 TRACEUSER( "Richard", wxT("Filter compatibility was less than 10\n") );
00869
00870
00871 CCFree(FilterBuf);
00872 FailAndExecute();
00873 InformMessage(_R(IDT_IMP_USERABORT));
00874 End();
00875 return;
00876 }
00877 }
00878
00879
00880 CCFree(FilterBuf);
00881 }
00882
00883
00884 CCDiskFile DiskFile(1024, FALSE, TRUE);
00885
00886 TRY
00887 {
00888 if (!DiskFile.open(Path, ios::in | ios::binary))
00889 {
00890
00891 TRACEUSER( "Richard", wxT("Failed to open file in BitmapImport Do") );
00892 InformError(_R(IDT_IMPORT_NOTFOUND));
00893 FailAndExecute();
00894 End();
00895 return;
00896 }
00897
00898
00899 if (!pFilter->ImportBitmap(&DiskFile, &pBitmap))
00900 {
00901
00902 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00903 InformError();
00904 else
00905 Error::ClearError();
00906 FailAndExecute();
00907 End();
00908
00909 return;
00910 }
00911
00912
00913 if (DiskFile.isOpen())
00914 DiskFile.close();
00915 }
00916
00917
00918 CATCH(CFileException, e)
00919 {
00920
00921 if (Error::GetErrorNumber() != _R(IDN_USER_CANCELLED))
00922 InformError();
00923 else
00924 Error::ClearError();
00925
00926
00927 TRY
00928 {
00929 if (DiskFile.isOpen())
00930 DiskFile.close();
00931 }
00932 CATCH(CFileException, e)
00933 {
00934
00935 }
00936 END_CATCH
00937
00938
00939 FailAndExecute();
00940 End();
00941 return;
00942 }
00943 END_CATCH
00944 }
00945
00946
00947 ApplyFill(pInfo, pBitmap);
00948
00949
00950 if (pBitmap && pBitmap->GetParentBitmapList() == NULL)
00951 {
00952
00953 delete pBitmap;
00954 }
00955
00956
00957 GetMainFrame()->SetActiveWindow();
00958
00959
00960 End();
00961 }
00962
00963 bool OpBitmapImport::ApplyFill(BitmapImportParam *pInfo, KernelBitmap* pBitmap)
00964 {
00965
00966 if (Document::GetCurrent() != pInfo->pTargetDoc || pInfo->pTargetDoc == 0)
00967 {
00968
00969
00970
00971
00972 ERROR3("Cannot apply fill when active document has changed");
00973 return false;
00974 }
00975
00976
00977 if (!Document::SpreadBelongsToDoc(pInfo->pTargetDoc, pInfo->pSpread))
00978 {
00979 ERROR3("Trying to import a bitmap fill into a non-existent spread");
00980 return false;
00981 }
00982
00983
00984 switch(pInfo->FillType)
00985 {
00986
00987 case ApplyToObject:
00988 {
00989 NodeRenderableInk* pObjectToUse;
00990 if (pInfo->TagObjectValid)
00991 {
00992 Node *pTreeRoot = pInfo->pTargetDoc->GetFirstNode()->FindFirstDepthFirst();
00993 if (pTreeRoot) pTreeRoot = pTreeRoot->FindNext();
00994 Node *pNode = pTreeRoot->FindFirstDepthFirst();
00995 while ((pNode != NULL) && (pNode->GetTag() != pInfo->TagObjectToFill))
00996 pNode = pNode->FindNextDepthFirst(pTreeRoot);
00997
00998 if (pNode == 0)
00999 return false;
01000
01001 if (pNode->IsAnObject())
01002 pObjectToUse = static_cast<NodeRenderableInk *>(pNode);
01003 else
01004 {
01005 ERROR3("It has the tag we saved but its type has changed. This is odd");
01006 return false;
01007 }
01008 }
01009
01010 AttrBitmapColourFill* Attrib = new AttrBitmapColourFill;
01011 if (Attrib == 0)
01012 return false;
01013
01014 Attrib->AttachBitmap(pBitmap);
01015
01016 if (pInfo->TagObjectValid)
01017 AttributeManager::ApplyAttribToNode(pObjectToUse, Attrib);
01018 else if (pInfo->pObjectValid)
01019 AttributeManager::ApplyAttribToNode(pInfo->pObject, Attrib);
01020 else
01021 AttributeManager::AttributeSelected(0, Attrib);
01022
01023 return true;
01024 }
01025
01026 case ApplyToObjectAsTransp:
01027 {
01028 NodeRenderableInk* pObjectToUse;
01029
01030 if (pInfo->TagObjectValid)
01031 {
01032 Node *pTreeRoot = pInfo->pTargetDoc->GetFirstNode()->FindFirstDepthFirst();
01033 if (pTreeRoot) pTreeRoot = pTreeRoot->FindNext();
01034 Node *pNode = pTreeRoot->FindFirstDepthFirst();
01035 while ((pNode != NULL) && (pNode->GetTag() != pInfo->TagObjectToFill))
01036 pNode = pNode->FindNextDepthFirst(pTreeRoot);
01037
01038 if (pNode == 0)
01039 return false;
01040
01041 if (pNode->IsAnObject())
01042 pObjectToUse = static_cast<NodeRenderableInk *>(pNode);
01043 else
01044 {
01045 ERROR3("It has the tag we saved but its type has changed. This is odd");
01046 return false;
01047 }
01048 }
01049
01050 pBitmap = NodeBitmap::CheckGreyscaleBitmap(pBitmap, _R(IDS_BMPGAL_MAKEGREY), _R(IDS_BMPGAL_DOGREY));
01051
01052 AttributeManager::HaveAskedAboutContoneColours = FALSE;
01053 AttributeManager::UserCancelledContoneColours = FALSE;
01054
01055 if (pBitmap == 0)
01056 return false;
01057
01058
01059 NodeAttribute *Attrib = new AttrBitmapTranspFill;
01060 if (Attrib == 0)
01061 return false;
01062
01063 (static_cast<AttrBitmapTranspFill *>(Attrib))->AttachBitmap(pBitmap);
01064
01065 if (pInfo->TagObjectValid)
01066 AttributeManager::ApplyAttribToNode(pObjectToUse, Attrib);
01067 else if (pInfo->pObjectValid)
01068 AttributeManager::ApplyAttribToNode(pInfo->pObject, Attrib);
01069 else
01070 AttributeManager::AttributeSelected(0, Attrib);
01071
01072 return true;
01073 }
01074 case SetBackground:
01075 {
01076 OpBackgroundParam Param;
01077 Param.pBitmap = pBitmap;
01078 Param.pDoc = pInfo->pTargetDoc;
01079 Param.pSpread = pInfo->pSpread;
01080
01081
01082 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_BACKGROUND);
01083
01084
01085 pOpDesc->Invoke(&Param);
01086 return true;
01087 }
01088 case AddToPage:
01089 {
01090 PageDropInfo DropInfo;
01091
01092 DropInfo.pDoc = pInfo->pTargetDoc;
01093 DropInfo.pSpread = pInfo->pSpread;
01094 DropInfo.DropPos = pInfo->DropPos;
01095
01096
01097 OpDescriptor* OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(OpCreateNodeBitmap));
01098
01099
01100 OpDesc->Invoke(&OpParam((INT32)pBitmap,(INT32)&DropInfo));
01101 return true;
01102 }
01103 default:
01104 {
01105 ERROR3("Unknown fill type");
01106 return false;
01107 }
01108 }
01109 }
01110
01111 #endif // wxCamelot port
01112
01113
01114
01115
01116
01117
01118
01119 BOOL SGLibOil::TidyUp(void)
01120 {
01121 if(TmpSndName != NULL)
01122 {
01123 PathName TheFile(TmpSndName);
01124 FileDelete(&TheFile);
01125 TmpSndName = NULL;
01126 }
01127 return TRUE;
01128 }
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146 BOOL SGLibOil::FileCopy(PathName *Source, PathName *Destination)
01147 {
01148 PORTNOTETRACE("dialog","SGLibOil::FileCopy - do nothing");
01149 #ifndef EXCLUDE_FROM_XARALX
01150 if(Source == NULL || Destination == NULL)
01151 {
01152 ERROR3("SGLibOil::FileCopy Source or Destination files should not be null");
01153 return FALSE;
01154 }
01155
01156 if(!Destination->IsValid() || !Source->IsValid())
01157 {
01158 ERROR3("SGLibOil::FileCopy given invalid path");
01159 return FALSE;
01160 }
01161
01162 if(FileExists(Destination))
01163 {
01164 ERROR3("SGLibOil::FileCopy destination file already exists");
01165 return FALSE;
01166 }
01167
01168 if(!FileExists(Source))
01169 {
01170 ERROR3("SGLibOil::FileCopy source file doesn't exist");
01171 return FALSE;
01172 }
01173
01174
01175
01176
01177
01178
01179
01180 INT32 Size = SGLibOil::FileSize(Source);
01181 void *Buffer = CCMalloc(Size + 4);
01182
01183 if(Buffer != NULL)
01184 {
01185 CCDiskFile File(1024, FALSE, TRUE);
01186
01187
01188 try
01189 {
01190
01191 File.open( Source->GetPath(), ios::in | ios::binary );
01192 File.read( Buffer, Size );
01193 if(File.isOpen())
01194 File.close();
01195
01196
01197 File.open(Destination->GetPath(), ios::out | ios::binary);
01198 File.write(Buffer, Size);
01199 if(File.isOpen())
01200 File.close();
01201
01202 CCFree(Buffer);
01203
01204
01205 return TRUE;
01206 }
01207 catch( CFileException )
01208 {
01209
01210
01211 Error::ClearError();
01212 }
01213
01214 CCFree(Buffer);
01215 }
01216
01217
01218
01219
01220
01221 FILE *FPin = NULL;
01222 FILE *FPout = NULL;
01223
01224 #if defined(__WXMSW__)
01225 FPin = _tfopen((const TCHAR *)Source->GetPath(), "rb");
01226 FPout = _tfopen((const TCHAR *)Destination->GetPath(), "wb");
01227 #else
01228 PSTR pszSrc, pszDst;
01229 {
01230 size_t cchTmp = camWcstombs( NULL, Source->GetPath(), 0 ) + 1;
01231 pszSrc = PSTR( alloca( cchTmp ) );
01232 camWcstombs( pszSrc, Source->GetPath(), cchTmp );
01233 }
01234 {
01235 size_t cchTmp = camWcstombs( NULL, Destination->GetPath(), 0 ) + 1;
01236 pszDst = PSTR( alloca( cchTmp ) );
01237 camWcstombs( pszDst, Destination->GetPath(), cchTmp );
01238 }
01239
01240 FPin = fopen( pszSrc, "rb" );
01241 FPout = fopen( pszDst, "wb" );
01242 #endif
01243
01244 if(FPin != NULL || FPout != NULL)
01245 {
01246 TCHAR C;
01247 while(!feof(FPin))
01248 {
01249 C = _fgettc(FPin);
01250 if(!feof(FPin)) _fputtc(C, FPout);
01251 }
01252 fclose(FPin);
01253 fclose(FPout);
01254 return TRUE;
01255 }
01256
01257 if(FPin != NULL) fclose(FPin);
01258 if(FPout != NULL) fclose(FPout);
01259 #endif
01260 return FALSE;
01261 }
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276 BOOL SGLibOil::FileExists(PathName *FileName)
01277 {
01278 return wxFile::Exists( PCTSTR(FileName->GetPath()) );
01279
01280 #if 0
01281 CCDiskFile File;
01282 BOOL OldTEState = File.SetThrowExceptions(FALSE);
01283 BOOL OldREState = File.SetReportErrors(FALSE);
01284 BOOL Found = FALSE;
01285
01286
01287 Found = File.open(FileName->GetPath(), ios::in | ios::binary | ios::nocreate);
01288 if(Found) File.close();
01289
01290 File.SetThrowExceptions(OldTEState);
01291 File.SetReportErrors(OldREState);
01292 Error::ClearError();
01293
01294 return Found;
01295 #endif
01296 }
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 BOOL SGLibOil::DirExists( const PathName& FileName )
01312 {
01313 return wxDir::Exists( PCTSTR(FileName.GetPath()) );
01314
01315 #if 0
01316 CCDiskFile File;
01317 BOOL OldTEState = File.SetThrowExceptions(FALSE);
01318 BOOL OldREState = File.SetReportErrors(FALSE);
01319 BOOL Found = FALSE;
01320
01321
01322 Found = File.open(FileName->GetPath(), ios::in | ios::binary | ios::nocreate);
01323 if(Found) File.close();
01324
01325 File.SetThrowExceptions(OldTEState);
01326 File.SetReportErrors(OldREState);
01327 Error::ClearError();
01328
01329 return Found;
01330 #endif
01331 }
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346 INT32 SGLibOil::FileSize(PathName *FileName)
01347 {
01348 PORTNOTETRACE("dialog","SGLibOil::FileSize - do nothing");
01349 #ifndef EXCLUDE_FROM_XARALX
01350 ERROR3IF(FileName == NULL, "SGLibOil::FileSize Filename should not be null");
01351 ERROR3IF(!FileName->IsValid(), "SGLibOil::FileSize given invalid path");
01352
01353 INT32 FileSize = 0;
01354
01355
01356
01357 FILE *FP = NULL;
01358 FP = _tfopen((const TCHAR *)FileName->GetPath(), "rb");
01359 if(FP != NULL)
01360 {
01361 fseek(FP,0,SEEK_END);
01362 FileSize = ftell(FP);
01363 fclose(FP);
01364 }
01365
01366 return FileSize;
01367 #else
01368 return 1;
01369 #endif
01370 }
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385 BOOL SGLibOil::FileDelete(PathName *FileName)
01386 {
01387 PORTNOTETRACE("dialog","SGLibOil::FileDelete - do nothing");
01388 #ifndef EXCLUDE_FROM_XARALX
01389 ERROR3IF(FileName == NULL || !FileName->IsValid(), "SGLibOil::FileDelete given a dodgy FileName");
01390
01391
01392 if( _taccess( (const TCHAR *)FileName->GetPath(), ios::in ) == 0 )
01393 {
01394
01395 if(_tremove((const TCHAR *)FileName->GetPath()) == 0)
01396 return TRUE;
01397 }
01398 #endif
01399 return FALSE;
01400 }
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414 UINT32 SGLibOil::FileModified(PathName *FileName)
01415 {
01416 PORTNOTETRACE("dialog","SGLibOil::FileModified - do nothing");
01417 #ifndef EXCLUDE_FROM_XARALX
01418 ERROR3IF(FileName == NULL, "SGLibOil::FileModified given a NULL FileName");
01419 ERROR3IF(!FileName->IsValid(), "SGLibOil::FileModified given invalid path");
01420
01421 struct _tstat buf;
01422
01423 INT32 Result = _tstat((const TCHAR *)FileName->GetPath(), &buf);
01424
01425 if(Result != 0)
01426 return 0;
01427
01428
01429
01430 if(buf.st_mtime == -1)
01431 return 0;
01432
01433 return (UINT32)buf.st_mtime;
01434 #else
01435 return 1;
01436 #endif
01437 }
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466 BOOL SGLibOil::LocateCDROMDrive(LibraryGallery *LG, SGLibType LibType, String_256 *DriveName,
01467 BOOL *OnXaraNet, String_256 *XaraMount, BOOL AdjustPressed)
01468 {
01469 #if !defined(__WXMSW__)
01470 TRACE( _T("Warning - SGLibOil::FileModified called") );
01471 return FALSE;
01472 #else
01473 if(!LG || !DriveName || !OnXaraNet || !XaraMount)
01474 {
01475 ERROR3("SGLibOil::LocateCDROMDrive given null input stuff");
01476 return FALSE;
01477 }
01478
01479 BOOL FoundCD = FALSE;
01480 BOOL FoundXara = FALSE;
01481 BOOL FoundProgramMount = FALSE;
01482
01483 *OnXaraNet = FALSE;
01484
01485 DWORD dwTemp;
01486 const DWORD DriveStringBufferSize = 20480;
01487 TCHAR DriveStringBuffer[DriveStringBufferSize];
01488 TCHAR *lpszDriveStringBuffer = (TCHAR *)DriveStringBuffer;
01489 TCHAR RootPathName[] = { '?', ':', chPathSep, 0 };
01490
01491 String_64 SlowJob(_R(IDS_LIBRARIES_FINDING_CD));
01492 BeginSlowJob(('z' - 'a'), FALSE, &SlowJob);
01493
01494 DWORD dwDriveMask=GetLogicalDrives();
01495 DWORD dwRC=GetLogicalDriveStrings(DriveStringBufferSize, lpszDriveStringBuffer);
01496
01497
01498 ERROR3IF(dwDriveMask == 0, "SGLibOil::LocateCDROMDrive - DriveMask == 0 - this means you haven't got any drives at all on your system !!!");
01499
01500 if(dwRC == 0)
01501 {
01502 memset(DriveStringBuffer, 0, DriveStringBufferSize);
01503 INT32 i = 0;
01504 for(*RootPathName='a'; *RootPathName<='z'; (*RootPathName)++)
01505 {
01506 DriveStringBuffer[i] = *RootPathName;
01507 DriveStringBuffer[i + 1] = ':';
01508 DriveStringBuffer[i + 2] = chPathSep;
01509 DriveStringBuffer[i + 3] = 0;
01510 i += 4;
01511 }
01512
01513 dwRC = i;
01514 dwDriveMask = 0xffffffff;
01515 }
01516
01517 if(dwRC != 0 && dwDriveMask != 0)
01518 {
01519
01520 for(*RootPathName='a'; *RootPathName<='z'; (*RootPathName)++)
01521 {
01522 if(!ContinueSlowJob(*RootPathName - 'a'))
01523 {
01524 *RootPathName = 'z';
01525 }
01526 else
01527 {
01528 dwTemp=dwDriveMask & 1;
01529 dwDriveMask >>= 1;
01530 if (dwTemp)
01531 {
01532
01533 dwRC=GetDriveType(RootPathName);
01534
01535 switch (dwRC)
01536 {
01537 case DRIVE_REMOTE:
01538 #ifdef SCANFORXARAMOUNT
01539 {
01540 TRACEUSER( "Richard", wxT("The drive type for %s is remote\n"), lpszDriveStringBuffer);
01541
01542
01543 String_256 FileSystemName;
01544 String_256 VolumeName;
01545 DWORD SerialNumber = 0;
01546 BOOL bRC;
01547
01548 bRC=GetVolumeInformation(RootPathName,
01549 (TCHAR *)VolumeName,
01550 255,
01551 &SerialNumber,
01552 NULL,
01553 NULL,
01554 (TCHAR *)FileSystemName,
01555 255);
01556
01557 if(bRC)
01558 {
01559 TRACEUSER( "Richard", wxT("%d - %s - %s\n"), SerialNumber, (TCHAR *)VolumeName, (TCHAR *)FileSystemName);
01560
01561 BOOL FoundAPossibleMount = FALSE;
01562
01563
01564 if( (SerialNumber == (DWORD)0x589c1e6f)
01565 && (VolumeName == (String_256)"")
01566 && (FileSystemName == (String_256)"NTFS") )
01567 {
01568 FoundProgramMount = TRUE;
01569 }
01570
01571 if(!AdjustPressed)
01572 {
01573
01574 if( (SerialNumber == 0x6863b85e)
01575 && (VolumeName == (String_256)"CORELXARA")
01576 && (FileSystemName == (String_256)"CDFS") )
01577 {
01578 FoundAPossibleMount = TRUE;
01579 }
01580 }
01581
01582
01583 if(AdjustPressed)
01584 {
01585 if( (SerialNumber == 0xec29b7f6)
01586 && (VolumeName == (String_256)"")
01587 && (FileSystemName == (String_256)"NTFS") )
01588 {
01589 FoundAPossibleMount = TRUE;
01590 }
01591 }
01592
01593 if(FoundAPossibleMount)
01594 {
01595
01596 String_256 CDPath(lpszDriveStringBuffer);
01597 String_256 CheckPath(lpszDriveStringBuffer);
01598
01599 if(AdjustPressed)
01600 {
01601 switch(LibType)
01602 {
01603 case SGLib_ClipArt:
01604 case SGLib_ClipArt_WebThemes:
01605 CheckPath += TEXT("Graphics\\XaraSt~1");
01606 break;
01607 case SGLib_Font:
01608 CheckPath += TEXT("Fonts");
01609 break;
01610 case SGLib_Texture:
01611 CheckPath += TEXT("Graphics\\Fills");
01612 break;
01613 default:
01614 CheckPath += TEXT("Fills\\Fabric");
01615 break;
01616 }
01617 }
01618 else
01619 CheckPath += TEXT("Fills\\Fabric");
01620
01621 if(_taccess((TCHAR *)CheckPath, ios::in ) == 0)
01622 {
01623 String_256 Drive(CDPath);
01624 SGLibOil::AppendSlashIfNotPresent(&Drive);
01625 *XaraMount = Drive;
01626 *OnXaraNet = TRUE;
01627 FoundXara = TRUE;
01628 }
01629 }
01630 }
01631 else
01632 {
01633 DWORD Problem = GetLastError();
01634 TRACEUSER( "Richard", wxT("GetVolumeInformation returned %d error"), Problem);
01635 }
01636 }
01637 #endif
01638 break;
01639
01640 case DRIVE_CDROM:
01641
01642
01643 if(!FoundCD)
01644 {
01645 String_256 CDPath(lpszDriveStringBuffer);
01646 String_256 LibDirName;
01647 PORTNOTE("dialog","Removed LibraryGallery usage")
01648 #ifndef EXCLUDE_FROM_XARALX
01649 LG->GetLibraryDirectoryName(&LibDirName);
01650 #endif
01651 CDPath += LibDirName;
01652
01653 if( 0 == _taccess( (TCHAR *)CDPath, ios::in ) )
01654 {
01655 FoundCD = TRUE;
01656 *DriveName = lpszDriveStringBuffer;
01657 }
01658
01659
01660
01661 if(!FoundCD && LibType == SGLib_Texture)
01662 {
01663 CDPath = (String_256)lpszDriveStringBuffer;
01664 CDPath += TEXT("Clipart\\Clipart\\");
01665 CDPath += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01666 CDPath += TEXT("\\");
01667 CDPath += String_16(_R(IDS_LIBRARIES_FILLS_DIRNAME));
01668 if(_taccess((TCHAR *)CDPath, ios::in ) == 0)
01669 {
01670 FoundCD = TRUE;
01671 *DriveName = lpszDriveStringBuffer;
01672 *DriveName += TEXT("Clipart\\Clipart\\");
01673 *DriveName += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
01674 *DriveName += TEXT("\\");
01675 }
01676 }
01677 }
01678 break;
01679
01680 case DRIVE_REMOVABLE:
01681 TRACEUSER( "Richard", wxT("The drive type for %s is removable\n"), lpszDriveStringBuffer);
01682 break;
01683
01684 case DRIVE_FIXED:
01685 TRACEUSER( "Richard", wxT("The drive type for %s is fixed\n"), lpszDriveStringBuffer);
01686
01687
01688 break;
01689
01690 case DRIVE_RAMDISK:
01691 TRACEUSER( "Richard", wxT("The drive type for %s is ramdisk\n"), lpszDriveStringBuffer);
01692 break;
01693
01694 default:
01695 break;
01696 }
01697
01698
01699 lpszDriveStringBuffer = lpszDriveStringBuffer + camStrlen(lpszDriveStringBuffer) + 1;
01700 }
01701 }
01702 }
01703 }
01704
01705 EndSlowJob();
01706
01707 #ifdef _DEBUG
01708 if(!FoundCD && !FoundXara && FoundProgramMount)
01709 {
01710 String_256 XaraMsg;
01711 XaraMsg = "You're connected to the Xara Net, but not the CamelotCD mount, so can't 'find' the library. ";
01712 ERROR3(XaraMsg);
01713 }
01714 #endif
01715
01716 return (FoundCD || FoundXara);
01717 #endif
01718 }
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743 UINT32 CALLBACK SGLibOil::FileHook( wxWindow *pDlg, UINT32 Msg, UINT32 wParam, INT32 lParam )
01744 {
01745 PORTNOTETRACE("dialog","SGLibOil::FileHook - do nothing - window CB");
01746 #ifndef EXCLUDE_FROM_XARALX
01747 switch(Msg)
01748 {
01749 case WM_INITDIALOG:
01750 {
01751 #ifdef STANDALONE
01752
01753 HWND hGadget = GetDlgItem((HWND)hDlg, (INT32)_R(IDC_LIBPATH_HELP_BUTTON));
01754 ShowWindow(hGadget, SW_HIDE);
01755 #endif
01756
01757
01758 if (UnicodeManager::IsDBCSOS())
01759 FontFactory::ApplyFontToWindow(hDlg, STOCKFONT_DIALOG);
01760 }
01761 return TRUE;
01762
01763 case WM_COMMAND:
01764
01765 switch(wParam)
01766 {
01767 case _R(IDC_LIBPATH_HELP_BUTTON):
01768
01769
01770
01771 _HelpUser(TEXT("SGalleryAddFolderDlg"));
01772 return TRUE;
01773
01774 case IDOK:
01775
01776 PostMessage(GetParent(hDlg), WM_COMMAND, IDOK, (INT32)FALSE);
01777 return FALSE;
01778
01779 case _R(IDC_LIBPATH_GENERATE):
01780
01781
01782
01783
01784 SGLibOil::GenerateButtonClicked = TRUE;
01785 PostMessage(hDlg, WM_COMMAND, IDOK, (INT32)FALSE);
01786 return FALSE;
01787
01788 case _R(IDC_LIBPATH_SEARCH):
01789
01790 {
01791 if(!SGLibOil::ParentLibraryGallery->ScanForLocation(SGLibOil::LibType,
01792 &SGLibOil::SearchDirectory))
01793 {
01794
01795 INT32 ButtonPressed = InformWarning(_R(IDS_LIBRARY_BROWSING_CANT_FIND_LIBRARY), _R(IDS_OK));
01796 Error::ClearError();
01797 return FALSE;
01798 }
01799
01800 DirPath Path(SGLibOil::SearchDirectory);
01801 if(!Path.IsValid())
01802 {
01803 ERROR3("Scanned to path is invalid");
01804
01805 return FALSE;
01806 }
01807
01808
01809 SGLibOil::SearchButtonClicked = TRUE;
01810
01811 PostMessage(hDlg, WM_COMMAND, IDOK, (INT32)FALSE);
01812 return FALSE;
01813 }
01814
01815 default:
01816 break;
01817 }
01818 break;
01819
01820 default:
01821 return FALSE;
01822 }
01823 #endif
01824 return FALSE;
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 #if _MFC_VER >= 0x400
01850 UINT32 CALLBACK SGLibOil::ExplorerFileHook(HWND hDlg, UINT32 Msg, UINT32 wParam, INT32 lParam)
01851 {
01852
01853 static char szstr2[256];
01854
01855 switch(Msg)
01856 {
01857 case WM_INITDIALOG:
01858 {
01859 #ifdef STANDALONE
01860
01861 HWND hGadget = GetDlgItem((HWND)hDlg, (INT32)_R(IDC_LIBPATH_HELP_BUTTON));
01862 ShowWindow(hGadget, SW_HIDE);
01863 #endif
01864 CommDlg_OpenSave_HideControl(GetParent(hDlg), edt1);
01865 CommDlg_OpenSave_HideControl(GetParent(hDlg), stc3);
01866 CommDlg_OpenSave_HideControl(GetParent(hDlg), cmb1);
01867 CommDlg_OpenSave_HideControl(GetParent(hDlg), stc2);
01868 CommDlg_OpenSave_HideControl(GetParent(hDlg), chx1);
01869
01870 CommDlg_OpenSave_HideControl(GetParent(hDlg), IDOK);
01871 CommDlg_OpenSave_HideControl(GetParent(hDlg), IDCANCEL);
01872
01873
01874
01875
01876
01877
01878 CommDlg_OpenSave_HideControl(hDlg, _R(IDC_LIBPATH_ISLIBRARY));
01879 HWND hGadget2 = GetDlgItem((HWND)hDlg, (INT32)_R(IDC_LIBPATH_ISLIBRARY));
01880 ::MoveWindow(hGadget2, 212, 113+200, 200, 12, TRUE);
01881
01882
01883 if (UnicodeManager::IsDBCSOS())
01884 FontFactory::ApplyFontToWindow(hDlg, STOCKFONT_DIALOG);
01885
01886 return TRUE;
01887 }
01888
01889 case WM_NOTIFY:
01890 return ExplorerFileHookNotify(hDlg, (LPOFNOTIFY)lParam);
01891
01892 case WM_COMMAND:
01893
01894 switch(wParam)
01895 {
01896 case _R(IDC_LIBPATH_HELP_BUTTON):
01897
01898
01899
01900
01901 _HelpUser(TEXT("SGalleryAddFolderDlg"));
01902 break;
01903
01904 case IDOK:
01905 {
01906
01907 String_256 TmpPath;
01908 INT32 Length = 0;
01909 Length = CommDlg_OpenSave_GetFolderPath((HWND)GetParent(hDlg), (TCHAR *)TmpPath, 255);
01910 if(Length > 0)
01911 {
01912 SGLibOil::BrowsePath = TmpPath;
01913 ((TCHAR *)SGLibOil::BrowsePath)[Length] = (TCHAR)'\0x00';
01914 }
01915
01916 PostMessage((HWND)GetParent(hDlg), WM_COMMAND, IDCANCEL, (INT32)FALSE);
01917 break;
01918 }
01919
01920 case IDCANCEL:
01921
01922 SGLibOil::BrowsePath = "";
01923 PostMessage((HWND)GetParent(hDlg), WM_COMMAND, IDCANCEL, (INT32)FALSE);
01924 break;
01925
01926 case _R(IDC_LIBPATH_GENERATE):
01927 {
01928
01929 SGLibOil::GenerateButtonClicked = TRUE;
01930 String_256 TmpPath;
01931
01932 INT32 Length = 0;
01933 Length = CommDlg_OpenSave_GetFolderPath((HWND)GetParent(hDlg), (TCHAR *)TmpPath, 255);
01934 if(Length > 0)
01935 {
01936 SGLibOil::BrowsePath = TmpPath;
01937 ((TCHAR *)SGLibOil::BrowsePath)[Length] = (TCHAR)'\0x00';
01938 }
01939
01940 PostMessage((HWND)GetParent(hDlg), WM_COMMAND, IDCANCEL, (INT32)FALSE);
01941 break;
01942 }
01943
01944 case _R(IDC_LIBPATH_SEARCH):
01945 {
01946
01947
01948 if(!SGLibOil::ParentLibraryGallery->ScanForLocation(SGLibOil::LibType,
01949 &SGLibOil::SearchDirectory))
01950 {
01951 INT32 ButtonPressed = InformWarning(_R(IDS_LIBRARY_BROWSING_CANT_FIND_LIBRARY), _R(IDS_OK));
01952 Error::ClearError();
01953 return FALSE;
01954 }
01955
01956 DirPath Path(SGLibOil::SearchDirectory);
01957 if(!Path.IsValid())
01958 {
01959 ERROR3("Scanned to path is invalid");
01960
01961 return FALSE;
01962 }
01963
01964
01965 SGLibOil::SearchButtonClicked = TRUE;
01966
01967 PostMessage((HWND)GetParent(hDlg), WM_COMMAND, IDCANCEL, (INT32)FALSE);
01968 return FALSE;
01969 }
01970
01971 default:
01972 break;
01973 }
01974 break;
01975
01976 case WM_HELP:
01977 ERROR3("Context sensitive help clicked...");
01978 break;
01979
01980 default:
01981 return FALSE;
01982 }
01983
01984 return FALSE;
01985 }
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006 BOOL SGLibOil::ExplorerFileHookNotify(HWND hDlg, LPOFNOTIFY pofn)
02007 {
02008 switch(pofn->hdr.code)
02009 {
02010
02011 case CDN_SELCHANGE:
02012 break;
02013
02014 case CDN_FOLDERCHANGE:
02015 case CDN_INITDONE:
02016 {
02017 String_256 TmpPath;
02018 INT32 Length = 0;
02019 Length = CommDlg_OpenSave_GetFolderPath((HWND)GetParent(hDlg), (TCHAR *)TmpPath, 255);
02020 if(Length > 0)
02021 {
02022 SGLibOil::BrowsePath = TmpPath;
02023
02024 for(INT32 i=(Length-1); i<=255; i++)
02025 ((TCHAR *)SGLibOil::BrowsePath)[i] = (TCHAR)0;
02026
02027
02028
02029
02030
02031
02032
02033
02034 SetDlgItemText(hDlg, _R(IDC_LIBPATH_PATHNAME), (TCHAR *)BrowsePath);
02035
02036 if(SGLibOil::CheckForIndex(&SGLibOil::BrowsePath, SGLibOil::ParentLibraryGallery))
02037 SetDlgItemText(hDlg, _R(IDC_LIBPATH_ISLIBRARY), (TCHAR *)String_256(_R(IDS_LIBPATH_INDEX_EXISTS)));
02038 else
02039 SetDlgItemText(hDlg, _R(IDC_LIBPATH_ISLIBRARY), (TCHAR *)String_256(_R(IDS_LIBPATH_INDEX_DOESNT_EXIST)));
02040 }
02041 break;
02042 }
02043
02044
02045
02046 case CDN_HELP:
02047 break;
02048
02049
02050
02051 case CDN_FILEOK:
02052 break;
02053
02054
02055 case CDN_SHAREVIOLATION:
02056 ERROR3("SGLibOil::ExplorerFileHookNotify got a share violation");
02057 break;
02058
02059
02060 case CDN_TYPECHANGE:
02061 break;
02062
02063
02064 default:
02065 break;
02066 }
02067
02068 return TRUE;
02069 }
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091
02092 BOOL SGLibOil::CheckForIndex(String_256 *Path, LibraryGallery *ParentGallery)
02093 {
02094 ERROR3IF(Path == NULL || ParentGallery == NULL, "SGLibOil::CheckForIndex given NULLs");
02095
02096 String_256 OurPath(*Path);
02097 if(LibraryFile::TidyUpSubPath(&OurPath))
02098 {
02099
02100 SGLibOil::AppendSlashIfNotPresent(&OurPath);
02101
02102 OurPath += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
02103
02104 PathName Index;
02105 String_256 IndexPath;
02106
02107
02108 String_256 DefIndex;
02109 ParentGallery->GetDefaults(&DefIndex, NULL, NULL);
02110
02111 IndexPath = OurPath;
02112 SGLibOil::AppendSlashIfNotPresent(&OurPath);
02113 IndexPath += DefIndex;
02114
02115 Index.SetPathName(IndexPath);
02116 Error::ClearError();
02117 if(FileExists(&Index))
02118 return TRUE;
02119
02120
02121 IndexPath = OurPath;
02122 SGLibOil::AppendSlashIfNotPresent(&IndexPath);
02123 IndexPath += String_256(_R(IDS_LIBRARIES_INDEX_FILENAME));
02124
02125 Index.SetPathName(IndexPath);
02126 Error::ClearError();
02127 if(FileExists(&Index))
02128 return TRUE;
02129 }
02130
02131 Error::ClearError();
02132 return FALSE;
02133 }
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156 BOOL SGLibOil::GenerateClicked(LibraryGallery *LG, PathName *GenDirectory)
02157 {
02158 if(GenDirectory == NULL || LG == NULL)
02159 {
02160 ERROR3("GenerateClicked given a null params");
02161 return FALSE;
02162 }
02163
02164 if(!GenDirectory->IsValid())
02165 {
02166 ERROR3("GenerateClicked given an invalid path");
02167 return FALSE;
02168 }
02169
02170 String_256 OurDirectory = GenDirectory->GetLocation();
02171
02172
02173 if(OurDirectory.Sub((String_8)"...") != -1)
02174 {
02175 ERROR3("Sorry, pathname has been truncated, can't generate index");
02176 return FALSE;
02177 }
02178 else
02179 {
02180 if(OurDirectory.Length() > 1)
02181 {
02182
02183 LibraryFile::TidyUpSubPath(&OurDirectory);
02184
02185 DirPath SubLibraryPath(OurDirectory);
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195 if(SubLibraryPath.IsValid())
02196 {
02197
02198 String_256 IndexName;
02199 String_256 IndexDesc;
02200 BOOL CanGenerate = LG->CanCreateIndexes();
02201
02202 if(LG->GetDefaults(&IndexName, &IndexDesc, NULL))
02203 {
02204 if(CanGenerate)
02205 {
02206 String_256 FullIndexPathStr(OurDirectory);
02207 SGLibOil::AppendSlashIfNotPresent(&FullIndexPathStr);
02208 FullIndexPathStr += String_16(_R(IDS_LIBRARIES_XARAINFO_DIRNAME));
02209 FullIndexPathStr += TEXT("\\") + IndexName;
02210 PathName FullIndexPath(FullIndexPathStr);
02211 if(FullIndexPath.IsValid())
02212 {
02213 INT32 ButtonPressed = 0;
02214 BOOL DoThumbnails = TRUE;
02215
02216 #if 0
02217 if(SGLibOil::FileExists(&FullIndexPath))
02218 {
02219
02220 ButtonPressed = InformWarning(_R(IDS_LIBRARY_OVERWRITE_INDEX_FILE), _R(IDS_GENERATE), _R(IDS_CANCEL));
02221 Error::ClearError();
02222 if(ButtonPressed == 2)
02223 return FALSE;
02224 }
02225 #endif
02226
02227 #if 0
02228
02229 ButtonPressed = InformWarning(_R(IDS_WITH_THUMBNAILS_OR_NOT), _R(IDS_THUMBNAILS), _R(IDS_NOTHUMBNAILS), _R(IDS_CANCEL));
02230 Error::ClearError();
02231 if(ButtonPressed > 2)
02232 return FALSE;
02233 DoThumbnails = (ButtonPressed == 1);
02234 #endif
02235
02236 if(SGLibOil::FileExists(&FullIndexPath) && GenerateIndexFile::IsDirectoryReadOnly(&SubLibraryPath))
02237 {
02238
02239 InformMessage(_R(IDS_LIBRARY_UPDATE_RO_WITH_INDEX), _R(IDS_CANCEL));
02240 Error::ClearError();
02241 return FALSE;
02242 }
02243
02244
02245 ButtonPressed = InformWarning(_R(IDS_LIBRARY_CHECK_INDEX_CREATE), _R(IDS_CREATE), _R(IDS_CANCEL));
02246 Error::ClearError();
02247 if(ButtonPressed > 1)
02248 return FALSE;
02249 DoThumbnails = TRUE;
02250
02251
02252 String_64 Author("");
02253
02254 BOOL ok = LibraryFile::GenerateDefaultIndex(&FullIndexPath, &SubLibraryPath, &Author, LibType, DoThumbnails);
02255 if(FullIndexPathStr != FullIndexPath.GetPath())
02256 {
02257
02258 *GenDirectory = FullIndexPath.GetLocation(FALSE);
02259 SGLibOil::BrowsePath = GenDirectory->GetPath();
02260 }
02261 return ok;
02262 }
02263 }
02264 else
02265 {
02266 ERROR3("You can't generate an index file for this type of library");
02267 }
02268 }
02269 }
02270 else
02271 {
02272 ERROR3("Invalid pathname...");
02273 }
02274 }
02275 }
02276 return FALSE;
02277 }
02278
02279
02280
02281
02282
02283 SGLibType SGLibOil::LibType = SGLib_Blank;
02284 LibraryGallery *SGLibOil::ParentLibraryGallery = NULL;
02285
02286
02287 String_256 SGLibOil::BrowsePath = "";
02288
02289
02290 BOOL SGLibOil::GenerateButtonClicked = FALSE;
02291
02292
02293 BOOL SGLibOil::SearchButtonClicked = FALSE;
02294
02295
02296 String_256 SGLibOil::SearchDirectory = "";
02297
02298
02299 BOOL SGLibOil::UseExplorerForAdd = FALSE;
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323 BOOL SGLibOil::GetLibPath(LibraryGallery *LG, PathName *ThePath, BOOL CanGenerate, SGLibType Type,
02324 BOOL *Updated)
02325 {
02326 if(ThePath == NULL || LG == NULL)
02327 {
02328 ERROR3("SGLibOil::GetLibPath given null params");
02329 return FALSE;
02330 }
02331
02332
02333 BOOL Explorer = FALSE;
02334 #if _MFC_VER >= 0x400
02335
02336
02337 if(CCamApp::IsNewWindowsUI())
02338 Explorer = TRUE;
02339 #endif
02340
02341 if(Updated) *Updated = FALSE;
02342
02343 SGLibOil::LibType = Type;
02344 SGLibOil::ParentLibraryGallery = LG;
02345
02346 TCHAR Filter[] = "Library directories|TheIndex|||";
02347
02348 DWORD CFileFlags = OFN_HIDEREADONLY | OFN_NOTESTFILECREATE |
02349 OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
02350 #if _MFC_VER >= 0x400
02351 if(Explorer)
02352 CFileFlags |= OFN_EXPLORER;
02353 #endif
02354
02355 CFileDialog BrowseFileDialog(TRUE,
02356 NULL,
02357 (const TCHAR *)ThePath->GetPath(),
02358 CFileFlags,
02359 (TCHAR *)Filter,
02360 NULL);
02361
02362 String_256 InitialPath(ThePath->GetPath(TRUE));
02363
02364
02365 SGLibOil::BrowsePath = "";
02366
02367 String_256 ExplorerBrowsePath;
02368
02369 BrowseFileDialog.m_ofn.lStructSize = sizeof(OPENFILENAME);
02370 BrowseFileDialog.m_ofn.hwndOwner = NULL;
02371 BrowseFileDialog.m_ofn.hInstance = AfxGetResourceHandle();
02372 if(Explorer)
02373 BrowseFileDialog.m_ofn.lpstrFile = (TCHAR *)ExplorerBrowsePath;
02374 else
02375 BrowseFileDialog.m_ofn.lpstrFile = (TCHAR *)SGLibOil::BrowsePath;
02376
02377 BrowseFileDialog.m_ofn.nMaxFile = 255;
02378 BrowseFileDialog.m_ofn.lpstrInitialDir = (TCHAR *)InitialPath;
02379 BrowseFileDialog.m_ofn.Flags = CFileFlags;
02380
02381 String_64 DlgTitle(_R(IDS_LIBPATHDLG));
02382 BrowseFileDialog.m_ofn.lpstrTitle = (TCHAR *)DlgTitle;
02383
02384
02385 #if _MFC_VER >= 0x400
02386 if(Explorer)
02387 {
02388 BrowseFileDialog.m_ofn.lpfnHook = (LPOFNHOOKPROC)SGLibOil::ExplorerFileHook;
02389 if(CanGenerate)
02390 BrowseFileDialog.m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_LIBPATHGENDLG95));
02391 else
02392 BrowseFileDialog.m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_LIBPATHDLG95));
02393 }
02394 else
02395 #endif
02396 {
02397 BrowseFileDialog.m_ofn.lpfnHook = (LPOFNHOOKPROC)SGLibOil::FileHook;
02398 if(CanGenerate)
02399 BrowseFileDialog.m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_LIBPATHGENDLG));
02400 else
02401 BrowseFileDialog.m_ofn.lpTemplateName = MAKEINTRESOURCE(_R(IDD_LIBPATHDLG));
02402 }
02403
02404 GenerateButtonClicked = FALSE;
02405 SearchButtonClicked = FALSE;
02406
02407
02408 BOOL Again = TRUE;
02409 while(Again)
02410 {
02411
02412 ControlHelper::InformModalDialogOpened();
02413
02414 INT32 Result = BrowseFileDialog.DoModal();
02415
02416
02417
02418 if(Explorer)
02419 {
02420
02421 if(SGLibOil::BrowsePath.Length() > 0)
02422 {
02423
02424 SGLibOil::AppendSlashIfNotPresent(&SGLibOil::BrowsePath);
02425
02426 SGLibOil::BrowsePath += TEXT("fish.wib");
02427 }
02428 }
02429
02430
02431
02432
02433 ControlHelper::InformModalDialogClosed();
02434
02435
02436
02437
02438 PORTNOTE("dialog","Removed FixFPControlRegister usage - is it needed anymore?")
02439 #ifndef EXCLUDE_FROM_XARALX
02440 FixFPControlRegister();
02441 #endif
02442
02443
02444 Again = FALSE;
02445
02446
02447
02448 if(SearchButtonClicked)
02449 {
02450
02451
02452 SearchButtonClicked = FALSE;
02453
02454
02455 Again = TRUE;
02456
02457
02458 BrowseFileDialog.m_ofn.lpstrInitialDir = SGLibOil::SearchDirectory;
02459 }
02460
02461
02462
02463
02464 if(GenerateButtonClicked)
02465 {
02466
02467
02468 GenerateButtonClicked = FALSE;
02469 PathName GenPath(SGLibOil::BrowsePath);
02470
02471 if(GenPath.IsValid())
02472 {
02473
02474 if(!GenerateClicked(LG, &GenPath))
02475 {
02476
02477 Again = TRUE;
02478
02479
02480 BrowseFileDialog.m_ofn.lpstrInitialDir = SGLibOil::BrowsePath;
02481 }
02482 else
02483 {
02484 if(Updated) *Updated = TRUE;
02485 }
02486 }
02487 else
02488 {
02489 Error::ClearError();
02490 Again = TRUE;
02491 }
02492 }
02493
02494 if(Again)
02495 {
02496
02497 SGLibOil::BrowsePath = "";
02498
02499 if(!(Explorer && SearchButtonClicked))
02500 BrowseFileDialog.m_ofn.lpstrFile = (TCHAR *)SGLibOil::BrowsePath;
02501 }
02502 }
02503
02504 if(SGLibOil::BrowsePath == (String_256)"")
02505 {
02506 Error::ClearError();
02507 return FALSE;
02508 }
02509 else
02510 {
02511 PathName Ret(SGLibOil::BrowsePath);
02512 if(Ret.IsValid())
02513 {
02514
02515
02516 String_256 Location = Ret.GetLocation(FALSE);
02517 if(IsRootDirectory(&Location))
02518 Location = Ret.GetLocation(TRUE);
02519
02520 PathName PathForReturn(Location);
02521 *ThePath = PathForReturn;
02522 }
02523 else
02524 {
02525 ERROR3("SGLibOil::GetLibPath !Ret.IsValid()");
02526 Error::ClearError();
02527 return FALSE;
02528 }
02529 }
02530
02531 Error::ClearError();
02532
02533
02534
02535
02536
02537 return TRUE;
02538 }
02539
02540 #endif
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558 BOOL SGLibOil::MakeSound(PathName *WaveFile)
02559 {
02560 #if defined(__WXMSW__)
02561
02562 String_256 File(WaveFile->GetPath());
02563 BOOL ok = PlaySound((TCHAR *)File, NULL, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02564 if(!ok)
02565 ok = sndPlaySound((TCHAR *)File, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02566
02567 return ok;
02568 #else
02569 TRACE( wxT("Warning - SGLibOil::MakeSound called\n") );
02570 return TRUE;
02571 #endif
02572 }
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590 BOOL SGLibOil::PlayRandomSample(String_256 *SampleString, String_256 *SubPath)
02591 {
02592 #if defined(__WXMSW__)
02593 String_256 SoundToUse(*SampleString);
02594
02595 if(SoundToUse.Length() > 2)
02596 {
02597
02598 INT32 Fields = SampleString->CountChar('|');
02599
02600 if(Fields > 0)
02601 {
02602 INT32 Count = (rand()%(Fields+1))+1;
02603 String_256 TmpSoundToUse(SoundToUse);
02604
02605 if(Count > 0)
02606 {
02607 TCHAR *Start = (TCHAR *)*SampleString;
02608 TCHAR *Finish = Start + SampleString->Length();
02609
02610
02611 const TCHAR BAR = '|';
02612
02613 TCHAR Ch = *Start;
02614 INT32 FieldCount = 1;
02615
02616
02617 while(Count > FieldCount && Start < Finish)
02618 {
02619 if(Ch == 0) break;
02620 if(Ch == BAR) FieldCount ++;
02621 Start += sizeof(TCHAR);
02622 Ch = *Start;
02623 }
02624
02625
02626 if(Count == FieldCount)
02627 TmpSoundToUse = Start;
02628 }
02629
02630
02631 if(TmpSoundToUse.Sub(String_8(_T("|"))) != -1)
02632 TmpSoundToUse.Left(&SoundToUse, TmpSoundToUse.Sub(String_8(_T("|"))));
02633 else
02634 SoundToUse = TmpSoundToUse;
02635 }
02636
02637
02638 if(SoundToUse.Sub(String_8(_T("\\"))) == -1)
02639 {
02640 String_256 File = *SubPath;
02641 SGLibOil::AppendSlashIfNotPresent(&File);
02642 File += SoundToUse;
02643 SoundToUse = File;
02644 }
02645
02646 PathName SoundPath(SoundToUse);
02647 return SGLibOil::MakeSound(&SoundPath);
02648 }
02649 return FALSE;
02650 #else
02651 TRACE( wxT("Warning - SGLibOil::PlayRandomSample called\n") );
02652 return TRUE;
02653 #endif
02654 }
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672 BOOL SGLibOil::IsRootDirectory(String_256 *Path)
02673 {
02674 TRACE( wxT("Warning - SGLibOil::PlayRandomSample called\n") );
02675 #if defined(__WXMSW__)
02676 ERROR3IF(Path == NULL, "SGLibOil::IsRootDirectory given a NULL string");
02677 if(Path == NULL)
02678 return FALSE;
02679
02680
02681
02682 String_256 TmpPath(*Path);
02683 if(TmpPath[TmpPath.Length()-1] == _T('\\'))
02684 Path->Left(&TmpPath, Path->Length()-1);
02685
02686
02687 if( TmpPath.Length() == 2 && TmpPath[1] == _T(':') )
02688 return TRUE;
02689
02690
02691
02692
02693 if( ( TmpPath.Sub( String_8( wxT("\\\\") ), 0, wxT('*') ) == 0 && TmpPath.CountChar( wxT('\\') ) <= 3 ) )
02694 {
02695
02696 return TRUE;
02697 }
02698
02699
02700 return FALSE;
02701 #else
02702 return FALSE;
02703 #endif
02704 }
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724 BOOL SGLibOil::LoadSoundDefinition(CXaraFileRecordHandler *pXFileRecHandler, CXaraFile * pCXFile,
02725 INT32 Tag, UINT32 Size, UINT32 RecordNumber)
02726 {
02727 TRACE( wxT("Warning - SGLibOil::LoadSoundDefinition called\n") );
02728 #if defined(__WXMSW__)
02729 if(TmpSndName != NULL)
02730 {
02731 PathName TheFile(TmpSndName);
02732 FileDelete(&TheFile);
02733 TmpSndName = NULL;
02734 }
02735
02736
02737 if(( TmpSndName = _ttmpnam( NULL ) ) != NULL )
02738 {
02739 UINT32 Size = pCXFile->GetCurrentRecordSize();
02740 CCFile *pRecordFile = pCXFile->GetCCFile();
02741
02742 void *Buffer = CCMalloc(Size + 4);
02743
02744 BOOL ok = FALSE;
02745
02746 if(Buffer != NULL)
02747 {
02748 CCDiskFile File(1024, FALSE, TRUE);
02749
02750
02751 try
02752 {
02753
02754 pRecordFile->read(Buffer, Size);
02755
02756
02757 PathName OutputPath(TmpSndName);
02758 File.open(OutputPath, ios::out | ios::binary);
02759 File.write(Buffer, Size);
02760 if(File.isOpen())
02761 File.close();
02762
02763
02764 ok = TRUE;
02765 }
02766 catch( CFileException )
02767 {
02768
02769
02770 Error::ClearError();
02771 }
02772
02773 CCFree(Buffer);
02774 }
02775
02776 if(ok)
02777 {
02778 ok = PlaySound((TCHAR *)TmpSndName, NULL, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02779 if(!ok)
02780 ok = sndPlaySound((TCHAR *)TmpSndName, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT | SND_FILENAME);
02781 }
02782
02783
02784 }
02785
02786 return TRUE;
02787 #else
02788 return FALSE;
02789 #endif
02790 }
02791
02792
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806 BOOL SGLibOil::ExportWav(BaseCamelotFilter *pFilter)
02807 {
02808 #if 0
02809 BOOL ok = TRUE;
02810 INT32 RecordNumber = pFilter->StartStreamedRecord(TAG_DEFINESOUND_WAV, CXF_UNKNOWN_SIZE);
02811
02812
02813 if (RecordNumber <= 0)
02814 return RecordNumber;
02815
02816 PathName Source("C:\\sample.wav");
02817 INT32 Size = SGLibOil::FileSize(&Source);
02818 void *Buffer = CCMalloc(Size + 4);
02819
02820 if(Buffer != NULL)
02821 {
02822 CCDiskFile File(1024, FALSE, TRUE);
02823
02824
02825 TRY
02826 {
02827
02828 File.open(Source.GetPath(), ios::in | ios::binary | ios::nocreate);
02829 File.read(Buffer, Size);
02830 if(File.isOpen())
02831 File.close();
02832
02833
02834
02835 for(INT32 i=0; i<Size; i++)
02836 pFilter->Write(((BYTE *)Buffer)[i]);
02837 }
02838
02839 CATCH( CFileException, e)
02840 {
02841
02842
02843 Error::ClearError();
02844 }
02845 END_CATCH
02846
02847 CCFree(Buffer);
02848 }
02849
02850
02851
02852 if (ok) ok = pFilter->EndStreamedRecord();
02853
02854 return ok;
02855 #else
02856 return FALSE;
02857 #endif
02858 }
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874 void SGLibOil::AppendSlashIfNotPresent(String_256 *Str)
02875 {
02876 ERROR3IF(Str == NULL, "SGLibOil::AppendSlashIfNotPresent given a NULL string");
02877 if(Str == NULL)
02878 return;
02879
02880 if(Str->Length() > 0)
02881 if( ((TCHAR *)*Str)[Str->Length()-1] != '/' )
02882 *Str += TEXT("/");
02883 }
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899
02900
02901
02902 DWORD SGLibOil::GetDriveSerialNumber(String_256 *PathStr)
02903 {
02904 TRACE( wxT("Warning - SGLibOil::GetDriveSerialNumber called\n") );
02905 #if defined(__WXMSW__)
02906 if(PathStr == NULL)
02907 return 0;
02908
02909 TCHAR Drive[MAX_PATH];
02910 BOOL driveFound = FALSE;
02911
02912
02913 String_256 Path = *PathStr;
02914 const TCHAR *fn;
02915 fn = Path;
02916 BOOL BadCharacter = FALSE;
02917
02918
02919
02920
02921
02922
02923 if (String::IsAlpha(*fn))
02924 driveFound = getDrive(&fn, Drive);
02925 else
02926 driveFound = getNetDrive(&fn, Drive, &BadCharacter);
02927
02928 if(driveFound && !BadCharacter)
02929 {
02930 String_256 FileSystemName;
02931 String_256 VolumeName;
02932 DWORD SerialNumber = 0;
02933 BOOL bRC = FALSE;
02934
02935 bRC=GetVolumeInformation(Drive,
02936 (TCHAR *)VolumeName,
02937 255,
02938 &SerialNumber,
02939 NULL,
02940 NULL,
02941 (TCHAR *)FileSystemName,
02942 255);
02943
02944 if(bRC)
02945 return SerialNumber;
02946 }
02947
02948 return 0;
02949 #else
02950 return 0x00BAD000;
02951 #endif
02952 }
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977 namespace InetUtils {
02978
02979 TCHAR* GetStringField( UINT32 nIndex, UINT32 nCompositeStringID )
02980 {
02981 PORTNOTETRACE("dialog","GetStringField - do nothing");
02982 #ifndef EXCLUDE_FROM_XARALX
02983 TCHAR rgtchBuff[1024];
02984 BOOL bLoad = ::LoadString(AfxGetResourceHandle(), nCompositeStringID, rgtchBuff, sizeof(rgtchBuff));
02985 ERROR3IF(!bLoad, "Failed to load string from resource");
02986 TCHAR* szField = _tcstok(rgtchBuff, _T("|"));
02987 for (UINT32 i = 0; i < nIndex && szField; i++)
02988 szField = _tcstok(NULL, _T("|"));
02989 return szField;
02990 #else
02991 return NULL;
02992 #endif
02993 }
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016
03017 String_256 MakeURL(const String_256& rRelativePath, const String_256& rRootURL)
03018 {
03019 String_256 strURL = rRootURL;
03020 INT32 nCharCount = rRelativePath.Length();
03021 if (camStrstr( (const TCHAR *)strURL, _T("file://") ) )
03022 strURL += rRelativePath;
03023 else for (INT32 i = 0; i < nCharCount; i++)
03024 {
03025
03026
03027 if (rRelativePath[i] == _T('\\'))
03028 strURL += _T('/');
03029 else
03030 strURL += camTolower( rRelativePath[i] );
03031 }
03032 return strURL;
03033 }
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046
03047
03048
03049 String_256 MakeLocalPath(const String_256& rRelPath)
03050 {
03051 String_256 strAppDataPath;
03052 GetAppDataPath(&strAppDataPath);
03053 if (strAppDataPath.IsEmpty())
03054 return strAppDataPath;
03055 PathNameEx appDataPath(strAppDataPath);
03056 String_256 strLocalPath = appDataPath.GetLocation(TRUE);
03057 strLocalPath += String_256(_R(IDS_CACHEPATH));
03058 strLocalPath += rRelPath;
03059 return strLocalPath;
03060 }
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071 BOOL GetTempInetDir(String_256* pTempDir)
03072 {
03073 #if defined(__WXMSW__)
03074 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE | CSIDL_FLAG_CREATE,
03075 NULL, 0, static_cast<TCHAR *>(*pTempDir))))
03076 return FALSE;
03077 #else
03078 #pragma error( "No equiverlent for SHGetFolderPath" )
03079 #endif
03080
03081 *pTempDir += wxT("\\");
03082
03083 return TRUE;
03084 }
03085
03086
03087
03088
03089
03090
03091
03092
03093
03094
03095 BOOL GetAppDataPath(String_256* pPath)
03096 {
03097 #if defined(__WXMSW__)
03098 if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE,
03099 NULL, 0, static_cast<TCHAR *>(*pPath))))
03100 return FALSE;
03101 #else
03102 #pragma error( "No equiverlent for SHGetFolderPath" )
03103 #endif
03104
03105 *pPath += wxT("\\");
03106 *pPath += String_256(PRODUCT_MANUFACTURER);
03107 *pPath += wxT("\\");
03108 *pPath += String_256(PROGRAM_NAME);
03109 *pPath += wxT("\\");
03110
03111 return TRUE;
03112 }
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123 BOOL GetAppCachePath(String_256* pPath)
03124 {
03125 if (!GetAppDataPath(pPath))
03126 return FALSE;
03127
03128 *pPath += String_256(_R(IDS_CACHEPATH));
03129
03130 return TRUE;
03131 }
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153 BOOL DeleteDirectoryTree(const String_256& rPath)
03154 {
03155 PathNameEx dirPath(rPath);
03156 return dirPath.Remove();
03157 }}
03158
03159
03160
03161