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 #include "camtypes.h"
00100
00101 #include "helpdownload.h"
00102
00103 #include "impexpop.h"
00104
00105 #include "xmlutils.h"
00106 #include "fileutil.h"
00107 #include "resdll.h"
00108
00109 #include "helpdownloadwebdialog.h"
00110 #include "helpuser.h"
00111 #include "registry.h"
00112 #include "product.h"
00113 #include "afxdisp.h"
00114 #include "menuops.h"
00115 #include "progress.h"
00116
00117 #import "webfileupdater.dll"
00118 using namespace WEBFILEUPDATERLib;
00119
00120
00121 DECLARE_SOURCE("$Revision: 836 $");
00122
00123 CC_IMPLEMENT_DYNCREATE(HelpDownloadOp, DownloadOp)
00124 CC_IMPLEMENT_DYNCREATE(HelpDownloadDlg, Operation)
00125
00126 typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
00127
00128 #define new CAM_DEBUG_NEW
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #ifdef PROD_XS
00142 String_256 HelpDownloadOp::IndexBaseURL = "http:
00143 #else
00144 String_256 HelpDownloadOp::IndexBaseURL = "http:
00145 #endif
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 BOOL HelpDownloadOp::HighBandwidth = FALSE;
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 String_256 HelpDownloadOp::DeferredCopySrc = "";
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 String_256 HelpDownloadOp::DeferredCopyDest = "";
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 String_32 HelpDownloadOp::IndexLeafName = "index.xml";
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 INT32 HelpDownloadOp::CurrentIndexRelease = 0;
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 HelpDownloadParam::HelpDownloadParam()
00224 {
00225 PathName pathTemp = FileUtil::GetTemporaryPathName();
00226 file = pathTemp.GetPath();
00227 m_pIndexDoc = NULL;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 HelpDownloadParam::~HelpDownloadParam()
00244 {
00245
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265 BOOL HelpDownloadOp::CheckForNewFiles(BOOL bForeground)
00266 {
00267 if (!bForeground)
00268 {
00269
00270
00271 CheckIndexFile();
00272 }
00273
00274
00275
00276
00277 if (bForeground)
00278 Progress::Start(FALSE, _R(IDS_UPDATING_HANDS), -1);
00279
00280 CString strClientFolder = GetSupportFilepath();
00281 strClientFolder.TrimRight('\\');
00282 BOOL bOK = OpUpdate::UpdateFiles(bForeground, strClientFolder, (CString)IndexBaseURL, (CString)IndexLeafName, _T("UpdateHelpAndSupport"));
00283
00284 if (bForeground)
00285 Progress::Stop();
00286
00287 if (bOK && bForeground)
00288 {
00289
00290
00291 CurrentIndexRelease = 0;
00292 BOOL bDidSomething = CheckIndexFile();
00293 if (!bDidSomething)
00294 {
00295
00296
00297 CHelpDownloadWebDialog dlgReportNothing(_T("HelpAndSupportOK.web"));
00298 dlgReportNothing.DoModal();
00299 }
00300 }
00301
00302 return FALSE;
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 BOOL HelpDownloadOp::CheckIndexFile()
00321 {
00322 IXMLDOMDocumentPtr pDoc = CXMLUtils::NewDocument();
00323 HRESULT hr;
00324 BOOL bDidSomething = FALSE;
00325
00326
00327 ::CreateDirectory(GetSupportFilepath(), NULL);
00328
00329 VARIANT_BOOL varResult;
00330
00331 CString strIndexFilename = GetSupportFilepath(GetIndexFileForLocale(_T("")));
00332 hr = pDoc->load(_variant_t(strIndexFilename), &varResult);
00333 if (FAILED(hr) || varResult==VARIANT_FALSE)
00334 {
00335
00336 strIndexFilename = GetSupportFilepath(GetIndexFileForLocale(_T("ENG")));
00337 hr = pDoc->load(_variant_t(strIndexFilename), &varResult);
00338 }
00339
00340
00341 if (SUCCEEDED(hr) && varResult==VARIANT_TRUE)
00342 {
00343
00344
00345 BOOL bFinishedWithIndex = ProcessDownloadIndex(pDoc, FALSE, &bDidSomething);
00346
00347
00348
00349
00350
00351
00352 }
00353
00354 return bDidSomething;
00355 }
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 CString HelpDownloadOp::GetSupportFilepath(const CString& strLeafName, const CString& strSupportFolder)
00372 {
00373 CString strPath;
00374 LPTSTR pathbuffer = strPath.GetBuffer(_MAX_PATH);
00375
00376 TCHAR achzExePath[_MAX_PATH];
00377 if (::GetModuleFileName(AfxGetInstanceHandle(), achzExePath, _MAX_PATH) == 0)
00378 {
00379 TRACEUSER( "Phil", _T("GetModuleFileName failed in GetSupportFilepath\n"));
00380 return _T("");
00381 }
00382
00383 TCHAR achzDrive[_MAX_DRIVE];
00384 TCHAR achzDirectory[_MAX_DIR];
00385 TCHAR achzFileName[_MAX_FNAME];
00386 TCHAR achzExtn[_MAX_EXT];
00387 TCHAR achzLeafPath[_MAX_DIR];
00388 TCHAR achzLeafFile[_MAX_FNAME];
00389 TCHAR achzLeafExtension[_MAX_EXT];
00390 _tsplitpath(achzExePath, achzDrive, achzDirectory, achzFileName, achzExtn);
00391 _tsplitpath(strLeafName, NULL, achzLeafPath, achzLeafFile, achzLeafExtension);
00392
00393 camStrcat(achzDirectory, strSupportFolder);
00394 camStrcat(achzDirectory, achzLeafPath);
00395
00396 _tmakepath(pathbuffer, achzDrive, achzDirectory, achzLeafFile, achzLeafExtension);
00397
00398 strPath.ReleaseBuffer();
00399
00400 return strPath;
00401 }
00402
00403
00404 CString HelpDownloadOp::GetIndexFileForLocale(const CString& strLocale)
00405 {
00406 if (strLocale.IsEmpty())
00407 return CResDll::GetCurrentLocale() + _T("\\") + IndexLeafName;
00408 else
00409 return strLocale + _T("\\") + IndexLeafName;
00410 }
00411
00412
00413 CString HelpDownloadOp::GetFileForLocale(const CString& strLocale, const CString& strFile)
00414 {
00415 if (strLocale.IsEmpty())
00416 return CResDll::GetCurrentLocale() + _T("\\") + strFile;
00417 else
00418 return strLocale + _T("\\") + strFile;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 BOOL HelpDownloadOp::Init()
00436 {
00437 Camelot.DeclareSection("Update", 12);
00438 Camelot.DeclarePref("Update", "HighBandwidth", &HighBandwidth);
00439 Camelot.DeclarePref("Update", "DeferredCopySrc", &DeferredCopySrc);
00440 Camelot.DeclarePref("Update", "DeferredCopyDest", &DeferredCopyDest);
00441 Camelot.DeclarePref("Update", "HelpAndSupportIndexLeafName", &IndexLeafName);
00442 Camelot.DeclarePref("Update", "HelpAndSupportCurrentIndexRelease", &CurrentIndexRelease);
00443
00444 HelpDownloadDlg::Init();
00445
00446 return RegisterOpDescriptor(
00447 0,
00448 _R(IDS_HELPDOWNLOADOP),
00449 CC_RUNTIME_CLASS(HelpDownloadOp),
00450 OPTOKEN_HELPDOWNLOADOP,
00451 HelpDownloadOp::GetState,
00452 0,
00453 0,
00454 0,
00455 0
00456 );
00457 }
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473 OpState HelpDownloadOp::GetState(String_256*, OpDescriptor*)
00474 {
00475 OpState OpSt;
00476 return(OpSt);
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495 BOOL HelpDownloadOp::OnDocChangingMsg(Document* pChangingDoc, DocChangingMsg::DocState State)
00496 {
00497 return TRUE;
00498 }
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 void HelpDownloadOp::OnDownloadSuccess()
00516 {
00517
00518 HelpDownloadParam* pGenericParam = (HelpDownloadParam*) pParam;
00519
00520 String_256 GenericFile = (pGenericParam->file).GetFileName();
00521 if (IsUserName("Phil"))
00522 TRACE1("HelpDownloadOp::OnDownloadSuccess(), file = %s\n", (TCHAR*)GenericFile);
00523
00524 PathName pathTemp = pGenericParam->file;
00525 String_256 URL = pGenericParam->strURL;
00526 PathName pathDestination = pGenericParam->m_pathDestination;
00527
00528
00529
00530
00531
00532
00533 if (pGenericParam->m_strResourceType==String_16("Help"))
00534 {
00535
00536
00537
00538
00539
00540 BOOL bOK = ::CopyFile(pathTemp.GetPath(), pathDestination.GetPath(), FALSE);
00541 if (bOK)
00542 {
00543 ::DeleteFile(pathTemp.GetPath());
00544 }
00545 else
00546 {
00547
00548 DeferFileCopy(pathTemp.GetPath(), pathDestination.GetPath());
00549 }
00550 }
00551 else
00552 {
00553
00554
00555
00556
00557
00558 BOOL bOK = ::CopyFile(pathTemp.GetPath(), pathDestination.GetPath(), FALSE);
00559 if (bOK)
00560 {
00561 ::DeleteFile(pathTemp.GetPath());
00562 }
00563 else
00564 {
00565
00566 DeferFileCopy(pathTemp.GetPath(), pathDestination.GetPath());
00567 }
00568 }
00569
00570
00571
00572 IXMLDOMNodePtr pOptionNode = pGenericParam->m_pOptionNode;
00573 if (pOptionNode)
00574 {
00575 CXMLUtils::ReplaceElement(pOptionNode, "Downloaded", TRUE);
00576 }
00577
00578 BOOL bFinishedWithIndex = ProcessDownloadIndex(pGenericParam->m_pIndexDoc, TRUE);
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 void HelpDownloadOp::OnDownloadFail()
00597 {
00598
00599 HelpDownloadParam* pGenParam = (HelpDownloadParam*) pParam;
00600
00601 if (pGenParam==NULL)
00602 {
00603 ERROR2RAW("OpBitmapDownload::OnDownloadFail - no download parameters");
00604 return;
00605 }
00606
00607
00608 String_256 strMessage;
00609 PathName path(pGenParam->m_pathDestination);
00610 String_256 strLeafname = path.GetFileName();
00611 strMessage.MakeMsg(_R(IDS_HANDS_DOWNLOADFAILED), &strLeafname);
00612 Error::SetError(0, strMessage, 0);
00613 InformError();
00614
00615 }
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 void HelpDownloadOp::OnDownloadAbort()
00632 {
00633
00634
00635 HelpDownloadParam* pGenericParam = (HelpDownloadParam*) pParam;
00636
00637 String_256 GenericFile = pGenericParam->strURL;
00638 if (IsUserName("Phil"))
00639 TRACE1("HelpDownloadOp::OnDownloadAbort(), file = %s\n", (TCHAR*)GenericFile);
00640
00641
00642
00643
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 BOOL HelpDownloadOp::ProcessDownloadIndex(IXMLDOMDocumentPtr pDoc, BOOL bSilent, BOOL* pbDidSomething)
00661 {
00662
00663
00664
00665
00666 HRESULT hr;
00667
00668 if (pbDidSomething)
00669 *pbDidSomething = FALSE;
00670
00671
00672 DWORD Flags = 0;
00673 if (!InternetGetConnectedState(&Flags, 0))
00674
00675 return FALSE;
00676
00677
00678 IXMLDOMNodePtr pRoot = NULL;
00679 hr = pDoc->selectSingleNode(_bstr_t("/HelpAndSupportFiles"), &pRoot);
00680 if (SUCCEEDED(hr) && pRoot!=NULL)
00681 {
00682 INT32 ThisRelease = CXMLUtils::GetAttributeLong(pRoot, "ReleaseNumber");
00683 if (CurrentIndexRelease>=ThisRelease)
00684 return FALSE;
00685 }
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697 IXMLDOMNodePtr pOptionNode = NULL;
00698 CString strResourceType;
00699 CString strLocale;
00700 pOptionNode = FindFirstOption(pDoc, &strResourceType, &strLocale);
00701 if (pOptionNode)
00702 {
00703
00704
00705 if (pbDidSomething)
00706 *pbDidSomething = TRUE;
00707
00708 if (!bSilent)
00709 {
00710 INT32 ret = IDOK;
00711 CHelpDownloadWebDialog webdlg(_T("NewHelpAndSupportFile.web"));
00712 webdlg.m_bFastConnection = HighBandwidth;
00713 ret = webdlg.DoModal();
00714 if (ret!=IDOK)
00715 {
00716 if (ret==_R(IDB_IGNORE))
00717 {
00718
00719
00720
00721
00722
00723
00724 CurrentIndexRelease = CXMLUtils::GetAttributeLong(pRoot, "ReleaseNumber");
00725 pOptionNode = NULL;
00726 return TRUE;
00727 }
00728 else
00729 {
00730
00731
00732 return FALSE;
00733 }
00734 }
00735 else
00736 {
00737 BOOL bChanged = (HighBandwidth!=webdlg.m_bFastConnection);
00738
00739
00740 HighBandwidth = webdlg.m_bFastConnection;
00741
00742 if (bChanged)
00743 {
00744
00745
00746 pOptionNode = FindFirstOption(pDoc, &strResourceType, &strLocale);
00747 }
00748 }
00749 }
00750
00751 if (pOptionNode)
00752 {
00753
00754 CString strURL = CXMLUtils::GetNodeString(pOptionNode, _T("si:URL"));
00755 CString strFilename = CXMLUtils::GetNodeString(pOptionNode, _T("si:Name"));
00756 COleDateTime filedate;
00757 BOOL bdateOK = filedate.ParseDateTime(CXMLUtils::GetNodeString(pOptionNode, _T("si:DateTime")), 0, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_UK), SORT_DEFAULT));
00758
00759 UINT32 filesize = CXMLUtils::GetNodeLong(pOptionNode, _T("si:Size"));
00760 CString strDescription = CXMLUtils::GetNodeString(pOptionNode, _T("si:Description"));
00761
00762 ERROR2IF(strResourceType.IsEmpty(), FALSE, "About to download but Resource type is unknown.");
00763 ERROR2IF(strLocale.IsEmpty(), FALSE, "About to download but Resource locale is unknown.");
00764 CString strPathname = GetFullResourcePath(strResourceType, strFilename, strLocale);
00765
00766
00767
00768
00769
00770
00771 HelpDownloadParam* pParam = new HelpDownloadParam;
00772 if (pParam==NULL)
00773 return FALSE;
00774
00775
00776
00777
00778 while ((!EnoughDiskSpace((CString)pParam->file.GetPath(), filesize) || !EnoughDiskSpace(strPathname, filesize*2)))
00779 {
00780 INT32 ret = InformWarning(_R(IDS_NOTENOUGHSPACETODOWNLOAD), _R(IDS_TRYAGAIN), _R(IDS_CANCEL));
00781 if (ret==2)
00782 return FALSE;
00783 }
00784
00785
00786
00787
00788
00789 pParam->bHasProgressDlg = TRUE;
00790 pParam->m_pathDestination = String_256(strPathname);
00791 pParam->strURL = String_256(strURL);
00792 if (!strDescription.IsEmpty())
00793 pParam->strDescription = String_256(strDescription);
00794 pParam->type = TYPE_SUPPORT;
00795 pParam->m_strResourceType = String_16(strResourceType);
00796 pParam->priority = AsynchDownload::PRIORITY_NORMAL;
00797 pParam->m_date = filedate;
00798 pParam->m_pIndexDoc = pDoc;
00799 pParam->m_pOptionNode = pOptionNode;
00800
00801 OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_HELPDOWNLOADOP);
00802 if (pOpDesc)
00803 {
00804 pOpDesc->Invoke(pParam, FALSE);
00805 }
00806
00807 return FALSE;
00808 }
00809 }
00810
00811
00812
00813 CurrentIndexRelease = CXMLUtils::GetAttributeLong(pRoot, "ReleaseNumber");
00814 return TRUE;
00815 }
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833 IXMLDOMNodePtr HelpDownloadOp::FindFirstOption(IXMLDOMDocumentPtr pDoc,
00834 CString* pstrResourceType,
00835 CString* pstrLocale)
00836 {
00837 HRESULT hr;
00838 IXMLDOMNodePtr pOptionNode = NULL;
00839 IXMLDOMNodeListPtr pList = NULL;
00840 IXMLDOMNodePtr pResourceNode = NULL;
00841 CString strType = "";
00842
00843
00844 hr = pDoc->selectNodes(_bstr_t("//si:Resource"), &pList);
00845 if (SUCCEEDED(hr) && pList!=NULL)
00846 {
00847 hr = pList->nextNode(&pResourceNode);
00848 while (pResourceNode)
00849 {
00850 pOptionNode = NULL;
00851 CString strResourceType = CXMLUtils::GetAttributeString(pResourceNode, _T("type"));
00852 if (pstrResourceType)
00853 *pstrResourceType = strResourceType;
00854
00855
00856 CString strOptionSelector;
00857 CString strLocale = CResDll::GetCurrentLocale();
00858 if (pstrLocale)
00859 *pstrLocale = strLocale;
00860 INT32 i=2;
00861 while (pOptionNode==NULL && i--)
00862 {
00863 if (i==0)
00864 {
00865
00866 strLocale = _T("ENG");
00867 if (pstrLocale)
00868 *pstrLocale = strLocale;
00869 }
00870
00871
00872 strOptionSelector = _T("si:Option[");
00873 if (HighBandwidth)
00874 {
00875 strType = _T("large");
00876 strOptionSelector += _T("@size=\"large\" ");
00877 }
00878 else
00879 {
00880 strType = _T("small");
00881 strOptionSelector += _T("@size=\"small\" ");
00882 }
00883 strOptionSelector += _T("and @locale=\"") + strLocale + "\" ";
00884 strOptionSelector += _T("]");
00885 hr = pResourceNode->selectSingleNode(_bstr_t(strOptionSelector), &pOptionNode);
00886
00887
00888
00889 if ((FAILED(hr) || pOptionNode==NULL) && HighBandwidth)
00890 {
00891 strOptionSelector = _T("si:Option[");
00892 strOptionSelector += _T("@size=\"small\" ");
00893 strOptionSelector += _T("and @locale=\"") + strLocale + "\" ";
00894 strOptionSelector += _T("]");
00895 strType = _T("");
00896 hr = pResourceNode->selectSingleNode(_bstr_t(strOptionSelector), &pOptionNode);
00897 }
00898 }
00899
00900 if (pOptionNode==NULL)
00901 pOptionNode = pResourceNode;
00902
00903 if (pOptionNode)
00904 {
00905
00906 CString strURL = CXMLUtils::GetNodeString(pOptionNode, _T("si:URL"));
00907 CString strFilename = CXMLUtils::GetNodeString(pOptionNode, _T("si:Name"));
00908 COleDateTime filedate;
00909 BOOL bdateOK = filedate.ParseDateTime(CXMLUtils::GetNodeString(pOptionNode, _T("si:DateTime")), 0, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_UK), SORT_DEFAULT));
00910
00911 UINT32 filesize = CXMLUtils::GetNodeLong(pOptionNode, _T("si:Size"));
00912 CString strDescription = CXMLUtils::GetNodeString(pOptionNode, _T("si:Description"));
00913
00914 CString strPathname = GetFullResourcePath(strResourceType, strFilename, strLocale);
00915
00916
00917
00918
00919 IXMLDOMDocumentPtr pCDIndexDoc = CXMLUtils::NewDocument();
00920 VARIANT_BOOL varResult;
00921
00922 CString strCDIndexFilename = GetSupportFilepath(GetFileForLocale(strLocale, _T("cdindex.xml")));
00923 hr = pCDIndexDoc->load(_variant_t(strCDIndexFilename), &varResult);
00924 if (FAILED(hr) || varResult==VARIANT_FALSE)
00925 pCDIndexDoc = NULL;
00926
00927
00928
00929 if (!strFilename.IsEmpty()
00930 && strPathname!=DeferredCopyDest
00931 && !MatchFileAttributes(strPathname, filedate, filesize)
00932 && !FileOnCD(pCDIndexDoc, strFilename, filedate, filesize, strLocale, strType)
00933 && LegalFileType(strFilename)
00934 && LegalPathname(strPathname)
00935 )
00936 {
00937
00938 if (HasBeenDownloaded(pOptionNode))
00939 {
00940
00941 String_256 strMessage;
00942 String_256 strName = CXMLUtils::GetNodeString(pOptionNode, _T("si:Name"));
00943 strMessage.MakeMsg(_R(IDS_WARN_REPEATDOWNLOAD), &strName);
00944 Error::SetError(0, strMessage, 0);
00945 INT32 ret = InformWarning(0, _R(IDS_CONTINUEUPDATE), _R(IDS_STOPUPDATE));
00946 if (ret==2)
00947 return NULL;
00948
00949
00950 }
00951 else
00952
00953 return pOptionNode;
00954 }
00955 }
00956 hr = pList->nextNode(&pResourceNode);
00957 }
00958 }
00959
00960 return NULL;
00961 }
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979 CString HelpDownloadOp::GetFullResourcePath(const CString& strResourceType,
00980 const CString& strFilename,
00981 const CString& strLocale)
00982 {
00983 CString strPath;
00984
00985 if (strResourceType.CompareNoCase(_T("Movie"))==0)
00986 {
00987
00988 strPath = GetSupportFilepath(GetFileForLocale(strLocale, strFilename));
00989 }
00990 else if (strResourceType.CompareNoCase(_T("Help"))==0)
00991 {
00992
00993 strPath = GetSupportFilepath(GetFileForLocale(strLocale, strFilename));
00994 }
00995 else
00996 ERROR3("Unknown Support Resource Type");
00997
00998 return strPath;
00999 }
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015 BOOL HelpDownloadOp::MatchFileAttributes(const CString& strFilePath, const COleDateTime& datetime, UINT32 size)
01016 {
01017 try
01018 {
01019 HANDLE hFile;
01020 WIN32_FIND_DATA FindFileInfo;
01021 hFile = ::FindFirstFile(strFilePath, &FindFileInfo);
01022 unsigned __int64 i64filesize = 0;
01023 if (hFile!=INVALID_HANDLE_VALUE)
01024 {
01025 i64filesize = ((__int64)FindFileInfo.nFileSizeHigh*((__int64)MAXDWORD+1))+FindFileInfo.nFileSizeLow;
01026 ::FindClose(hFile);
01027 }
01028
01029
01030
01031 COleDateTime filetime(FindFileInfo.ftLastWriteTime);
01032
01033 if (datetime.GetStatus()!=COleDateTime::valid || filetime.GetStatus()!=COleDateTime::valid)
01034 {
01035 TRACE( _T("MatchFileAttributes one or other COleDateTime is invalid!\n"));
01036 return i64filesize==size;
01037 }
01038
01039 TRACEUSER( "Phil", _T("MFA: File = %s\n"), strFilePath);
01040 TRACEUSER( "Phil", _T("MFA: UK xml time = %s\n"), datetime.Format(LOCALE_NOUSEROVERRIDE, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_UK), SORT_DEFAULT)));
01041 TRACEUSER( "Phil", _T("MFA: UK file time = %s\n"), filetime.Format(LOCALE_NOUSEROVERRIDE, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_UK), SORT_DEFAULT)));
01042 TRACEUSER( "Phil", _T("MFA: xml size = %d\n"), size);
01043 TRACEUSER( "Phil", _T("MFA: file size = %d\n"), i64filesize);
01044 return (filetime>=datetime && i64filesize==size);
01045 }
01046 catch (...)
01047 {
01048 return FALSE;
01049 }
01050 }
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066 BOOL HelpDownloadOp::FileOnCD(IXMLDOMDocumentPtr pDoc,
01067 const CString& strName,
01068 const COleDateTime& datetime,
01069 UINT32 size,
01070 const CString& strLocale,
01071 const CString& strType)
01072 {
01073 if (pDoc==NULL)
01074 return FALSE;
01075
01076
01077 IXMLDOMNodePtr pNode = NULL;
01078 IXMLDOMNodeListPtr pOptionsList = NULL;
01079 CString strOptionSelector;
01080
01081
01082 strOptionSelector = _T("//si:Resource/si:Option[");
01083 if (strType==_T("large"))
01084 strOptionSelector += _T("(@size=\"large\" or @size=\"cd\") ");
01085 else
01086 strOptionSelector += _T("(@size=\"small\" or @size=\"large\" or @size=\"cd\") ");
01087
01088
01089
01090
01091 strOptionSelector += _T("and @locale=\"") + strLocale + "\" ";
01092 strOptionSelector += _T("and si:Name=\"") + strName + "\" ";
01093 strOptionSelector += _T("]");
01094 HRESULT hr = pDoc->selectNodes(_bstr_t(strOptionSelector), &pOptionsList);
01095 if (SUCCEEDED(hr) && pOptionsList!=NULL)
01096 {
01097 hr = pOptionsList->nextNode(&pNode);
01098 while (pNode)
01099 {
01100 CString strCDName = CXMLUtils::GetNodeString(pNode, _T("si:Name"));
01101 COleDateTime dtCDdate;
01102 BOOL bdateOK = dtCDdate.ParseDateTime(CXMLUtils::GetNodeString(pNode, _T("si:DateTime")), 0, MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_UK), SORT_DEFAULT));
01103 UINT32 ulCDSize = CXMLUtils::GetNodeLong(pNode, _T("si:Size"));
01104
01105
01106
01107 if (dtCDdate.GetStatus()!=COleDateTime::valid || datetime.GetStatus()!=COleDateTime::valid)
01108 {
01109 if (strCDName==strName
01110
01111 )
01112 {
01113
01114 return TRUE;
01115 }
01116 }
01117 else
01118 {
01119 if (strCDName==strName
01120 && dtCDdate==datetime
01121
01122 )
01123 {
01124
01125 return TRUE;
01126 }
01127 }
01128
01129 hr = pOptionsList->nextNode(&pNode);
01130 }
01131 }
01132
01133
01134 return FALSE;
01135 }
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151 BOOL HelpDownloadOp::LegalFileType(const CString& strFilename)
01152 {
01153 TCHAR achzExtn[_MAX_EXT];
01154
01155 _tsplitpath(strFilename, NULL, NULL, NULL, achzExtn);
01156
01157 return (camStrstr(_T(".htm .txt .xml .chm .mpg .avi .jpg .png .gif .web .xar .wix .wmv"), achzExtn)!=NULL);
01158 }
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174 BOOL HelpDownloadOp::LegalPathname(const CString& strPathname)
01175 {
01176 return (camStrstr(strPathname, _T(".."))==NULL);
01177 }
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 BOOL HelpDownloadOp::HasBeenDownloaded(IXMLDOMNodePtr pNode)
01194 {
01195 return (pNode!=NULL && CXMLUtils::GetNodeBOOL(pNode, "Downloaded"));
01196 }
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210 void HelpDownloadOp::DeferFileCopy(const String_256& pTempFile, const String_256& pDestFile)
01211 {
01212
01213
01214
01215
01216
01217 if (DeferredCopySrc.IsEmpty())
01218 {
01219 DeferredCopySrc = pTempFile;
01220 DeferredCopyDest = pDestFile;
01221 }
01222
01223
01224
01225 }
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239 void HelpDownloadOp::DoDeferredFileCopy()
01240 {
01241
01242
01243 HKEY hKey = OpenRegKey(hAppStateRegKey, TEXT("Options\\Update"));
01244 if (hKey)
01245 {
01246 GetRegString(hKey, TEXT("DeferredCopySrc"), &DeferredCopySrc);
01247 GetRegString(hKey, TEXT("DeferredCopyDest"), &DeferredCopyDest);
01248
01249 if (!DeferredCopySrc.IsEmpty() && !DeferredCopyDest.IsEmpty())
01250 {
01251 BOOL bOK = ::CopyFile((LPCTSTR)DeferredCopySrc, (LPCTSTR)DeferredCopyDest, FALSE);
01252 }
01253
01254 if (!DeferredCopySrc.IsEmpty())
01255 ::DeleteFile((LPCTSTR)DeferredCopySrc);
01256
01257 DeferredCopySrc = "";
01258 DeferredCopyDest = "";
01259
01260 SetRegString(hKey, TEXT("DeferredCopySrc"), &DeferredCopySrc);
01261 SetRegString(hKey, TEXT("DeferredCopyDest"), &DeferredCopyDest);
01262
01263 CloseRegKey(hKey);
01264 }
01265 }
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280 BOOL HelpDownloadOp::EnoughDiskSpace(const CString& strPath, const UINT32 sizeRequired)
01281 {
01282 TCHAR szDrive[_MAX_DRIVE + 1];
01283 _tsplitpath(strPath, szDrive, NULL, NULL, NULL);
01284 camStrcat(szDrive, _T("\\"));
01285
01286
01287 BOOL fResult = FALSE;
01288 P_GDFSE pGetDiskFreeSpaceEx = NULL;
01289 pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle ("kernel32.dll"), "GetDiskFreeSpaceExA");
01290
01291 unsigned __int64 i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
01292 DWORD dwSectorsPerCluster, dwBytesPerSector, dwNumberOfFreeClusters, dwTotalNumberOfClusters;
01293
01294 if (pGetDiskFreeSpaceEx)
01295 {
01296 fResult = pGetDiskFreeSpaceEx(szDrive, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes);
01297
01298
01299 if (fResult)
01300 return ((__int64)sizeRequired < i64FreeBytesToCaller);
01301 }
01302 else
01303 {
01304 fResult = GetDiskFreeSpace (szDrive, &dwSectorsPerCluster, &dwBytesPerSector, &dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
01305 if (fResult)
01306 {
01307
01308 i64FreeBytes = (__int64)dwNumberOfFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
01309
01310
01311 return ((__int64)sizeRequired < i64FreeBytes);
01312 }
01313 }
01314
01315
01316 if (!fResult) { ERROR3("Can't GetDiskFreeSpace()!"); }
01317 return FALSE;
01318 }
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335 BOOL HelpDownloadDlg::Init()
01336 {
01337 return RegisterOpDescriptor(
01338 0,
01339 _R(IDS_HELPDOWNLOADDLG),
01340 CC_RUNTIME_CLASS(HelpDownloadDlg),
01341 OPTOKEN_HELPDOWNLOADDLG,
01342 HelpDownloadDlg::GetState,
01343 0,
01344 0,
01345 0,
01346 0
01347 );
01348
01349 }
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365 OpState HelpDownloadDlg::GetState(String_256*, OpDescriptor*)
01366 {
01367 OpState OpSt;
01368 return(OpSt);
01369 }
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383 void HelpDownloadDlg::Do(OpDescriptor* od)
01384 {
01385 HelpDownloadOp::CheckForNewFiles(TRUE);
01386 }
01387
01388
01389