Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2250 lines
64 KiB

  1. // OcarptMain.cpp : Implementation of COcarptMain
  2. //#define UNICODE
  3. //#define _UNICODE
  4. #include "stdafx.h"
  5. #include "Ocarpt.h"
  6. #include "OcarptMain.h"
  7. #include <direct.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <commdlg.h>
  11. #include <Wincrypt.h>
  12. #include <io.h>
  13. #include "Compress.h"
  14. #define MAX_RETRIES 5
  15. #define MAX_RETRY_COUNT 10
  16. #include <strsafe.h>
  17. TCHAR * COcarptMain::_approvedDomains[] = { _T("ocatest"),
  18. _T("oca.microsoft.com"),
  19. _T("oca.microsoft.de"),
  20. _T("oca.microsoft.fr"),
  21. _T("ocadeviis"),
  22. _T("redbgitwb10"),
  23. _T("redbgitwb11"),
  24. _T("ocajapan.rte.microsoft.com")};
  25. TCHAR g_LastResponseURL[MAX_PATH];
  26. TCHAR g_LastUploadedFile[MAX_PATH];
  27. EnumUploadStatus g_UploadStatus;
  28. ULONG g_UploadFailureCode;
  29. typedef struct _UPLOAD_CONTEXT {
  30. WCHAR SourceFile[MAX_PATH];
  31. WCHAR DestFile[MAX_PATH];
  32. WCHAR Language[50];
  33. WCHAR OptionCode[20];
  34. BOOL ConvertToMini;
  35. COcarptMain *Caller;
  36. POCA_UPLOADFILE pUploadFile;
  37. } UPLOAD_CONTEXT, *PUPLOAD_CONTEXT;
  38. /***********************************************************************************
  39. *
  40. * Main proc to do file upload to server. This is started in a new thread.
  41. *
  42. ***********************************************************************************/
  43. DWORD WINAPI
  44. UploadThreadStart(
  45. LPVOID pCtxt
  46. )
  47. {
  48. PUPLOAD_CONTEXT pParams = (PUPLOAD_CONTEXT) pCtxt;
  49. ULONG ReturnCode = 100;
  50. HINTERNET hInet = NULL;
  51. DWORD dwUrlLength = 0;
  52. WCHAR wszServerName[MAX_PATH];
  53. BOOL bRet;
  54. DWORD dwLastError;
  55. HANDLE hSourceFile = INVALID_HANDLE_VALUE;
  56. wchar_t ConvSourceFile[MAX_PATH];
  57. BOOL Converted = FALSE;
  58. wchar_t RemoteFileName[MAX_PATH];
  59. BOOL bIsCab = FALSE;
  60. DWORD ErrorCode = 0;
  61. BOOL UploadSuccess = FALSE;
  62. DWORD NumRetries = 0;
  63. DWORD dwFileSize;
  64. HANDLE hFile = NULL;
  65. HINTERNET hRequest = NULL;
  66. HINTERNET hSession = NULL;
  67. HINTERNET hConnect = NULL;
  68. DWORD ResLength = 255;
  69. DWORD index = 0;
  70. static const wchar_t *pszAccept[] = {L"*.*", 0};
  71. DWORD ResponseCode = 0;
  72. // New Strings for temporary directory fix.
  73. wchar_t TempPath[MAX_PATH];
  74. wchar_t TempCabName[MAX_PATH];
  75. wchar_t TempDumpName[MAX_PATH];
  76. wchar_t ResponseURL[255];
  77. GUID guidNewGuid;
  78. wchar_t *szGuidRaw = NULL;
  79. BOOL bConvertToMini = pParams->ConvertToMini;
  80. HRESULT hResult = S_OK;
  81. BOOL bSecure = TRUE;
  82. // ::MessageBoxW(NULL,L"UploadCalled",NULL,MB_OK);
  83. if ( (!pParams->SourceFile) || (!pParams->DestFile) ||
  84. (!pParams->Language) || (!pParams->OptionCode) ||
  85. (!pParams->Caller) )
  86. {
  87. // ::MessageBoxW(NULL,L"Failed Param Check",NULL,MB_OK);
  88. return S_OK;
  89. }
  90. if (!pParams->Caller->CreateTempDir(TempPath))
  91. {
  92. goto ExitUploadThread;
  93. }
  94. //Get a guid
  95. hResult = CoCreateGuid(&guidNewGuid);
  96. if (FAILED(hResult))
  97. {
  98. //-------------What do we send here....
  99. ErrorCode = GetLastError();
  100. ReturnCode = ErrorCode;
  101. goto ExitUploadThread;
  102. }
  103. else
  104. {
  105. if (UuidToStringW(&guidNewGuid, &szGuidRaw) != RPC_S_OK)
  106. {
  107. ErrorCode = GetLastError();
  108. ReturnCode = ErrorCode;
  109. goto ExitUploadThread;
  110. }
  111. }
  112. // build the tempfile name
  113. if (StringCbPrintfW(TempDumpName,sizeof TempDumpName, L"%s\\%sOCARPT.dmp",
  114. TempPath,
  115. szGuidRaw + 19) != S_OK)
  116. {
  117. goto ExitUploadThread;
  118. }
  119. // build the cabfile name
  120. if (StringCbPrintfW(TempCabName,sizeof TempCabName, L"%s\\%sOCARPT.Cab",
  121. TempPath, szGuidRaw + 19) != S_OK)
  122. {
  123. goto ExitUploadThread;
  124. }
  125. // Determine if we need to convert the selected file.
  126. pParams->Caller->GetFileHandle(pParams->SourceFile, &hSourceFile);
  127. if (hSourceFile == INVALID_HANDLE_VALUE)
  128. {
  129. goto ExitUploadThread;
  130. }
  131. dwFileSize=GetFileSize(hSourceFile,NULL);
  132. CloseHandle(hSourceFile);
  133. g_UploadStatus = UploadCopyingFile;
  134. if (bConvertToMini)
  135. {
  136. // We need to convert this file.
  137. BSTR Destination, Source;
  138. Source = pParams->SourceFile;
  139. if (!pParams->Caller->ConvertFullDumpInternal(&Source,&Destination) )
  140. {
  141. ReturnCode = 3;
  142. goto ExitUploadThread;
  143. }
  144. else
  145. {
  146. Converted = TRUE;
  147. if (CopyFileW(Destination,TempDumpName,FALSE))
  148. {
  149. SetFileAttributesW(TempDumpName,FILE_ATTRIBUTE_NORMAL);
  150. if (StringCbCopyW(ConvSourceFile,sizeof ConvSourceFile,TempDumpName) != S_OK)
  151. {
  152. ErrorCode = GetLastError();
  153. ReturnCode = ErrorCode;
  154. goto ExitUploadThread;
  155. }
  156. SysFreeString(Destination);
  157. }
  158. }
  159. }
  160. else
  161. {
  162. // ****** copy the file to cab to the temp path
  163. if (dwFileSize < 1000000 &&
  164. CopyFileW(pParams->SourceFile, TempDumpName,FALSE))
  165. {
  166. SetFileAttributesW(TempDumpName,FILE_ATTRIBUTE_NORMAL);
  167. // Place the location of the file into the string we use
  168. // for the file upload process.
  169. if (StringCbCopyW(ConvSourceFile,sizeof ConvSourceFile,TempDumpName)!= S_OK)
  170. {
  171. ErrorCode = GetLastError();
  172. ReturnCode = ErrorCode;
  173. goto ExitUploadThread;
  174. }
  175. } else
  176. {
  177. // We are unable to copy the file, use the file from original location
  178. if (StringCbCopyW(ConvSourceFile,sizeof ConvSourceFile, pParams->SourceFile)!= S_OK)
  179. {
  180. ErrorCode = GetLastError();
  181. ReturnCode = ErrorCode;
  182. goto ExitUploadThread;
  183. }
  184. }
  185. }
  186. if (dwFileSize > 10000000)
  187. {
  188. // ::MessageBoxW(NULL,L"File is too big ",NULL,MB_OK);
  189. // goto ExitUploadThread;
  190. }
  191. LPWSTR wszExt = wcsstr(ConvSourceFile, L".cab");
  192. if (wszExt == NULL || wcscmp(wszExt, L".cab"))
  193. {
  194. g_UploadStatus = UploadCompressingFile;
  195. if (Compress(TempCabName,ConvSourceFile,NULL))
  196. {
  197. if (StringCbCopyW(ConvSourceFile,sizeof ConvSourceFile, TempCabName) != S_OK)
  198. {
  199. ErrorCode = GetLastError();
  200. ReturnCode = ErrorCode;
  201. goto ExitUploadThread;
  202. }
  203. } else
  204. {
  205. // we failed to compress file
  206. ErrorCode = GetLastError();
  207. ReturnCode = ErrorCode;
  208. goto ExitUploadThread;
  209. }
  210. } else
  211. {
  212. if (!CopyFileW(ConvSourceFile, TempCabName,FALSE))
  213. {
  214. ReturnCode = ErrorCode = GetLastError();
  215. goto ExitUploadThread;
  216. }
  217. if (StringCbCopyW(ConvSourceFile,sizeof ConvSourceFile, TempCabName) != S_OK)
  218. {
  219. ReturnCode = ErrorCode = GetLastError();
  220. goto ExitUploadThread;
  221. }
  222. }
  223. // Now build the output file name.
  224. wchar_t * TempString;
  225. TempString = PathFindFileNameW(ConvSourceFile);
  226. if (StringCbPrintfW(RemoteFileName,sizeof RemoteFileName, L"/OCA/M_%s", TempString) != S_OK)
  227. {
  228. ErrorCode = GetLastError();
  229. ReturnCode = ErrorCode;
  230. goto ExitUploadThread;
  231. }
  232. if (szGuidRaw)
  233. {
  234. RpcStringFreeW(&szGuidRaw);
  235. }
  236. pParams->Caller->GetFileHandle(ConvSourceFile,&hFile);
  237. if (hFile == INVALID_HANDLE_VALUE)
  238. {
  239. ErrorCode = GetLastError();
  240. goto ExitUploadThread;
  241. } else
  242. {
  243. dwFileSize = GetFileSize (hFile, NULL);
  244. CloseHandle(hFile);
  245. hFile = INVALID_HANDLE_VALUE;
  246. }
  247. g_UploadStatus = UploadConnecting;
  248. if ((ErrorCode = pParams->pUploadFile->InitializeSession(pParams->OptionCode, (LPWSTR) ConvSourceFile)) != S_OK)
  249. {
  250. ReturnCode = ErrorCode;
  251. goto ExitUploadThread;
  252. }
  253. char TEMPString[MAX_PATH];
  254. wcstombs(TEMPString, wszServerName,MAX_PATH);
  255. while ((NumRetries < MAX_RETRIES) && (!UploadSuccess))
  256. {
  257. ErrorCode = 0;
  258. if ((ErrorCode = pParams->pUploadFile->SendFile(RemoteFileName,
  259. bSecure)) != S_OK)
  260. {
  261. goto EndRetry;
  262. }
  263. if (ErrorCode == E_ABORT)
  264. {
  265. goto ExitUploadThread;
  266. }
  267. if (ErrorCode == ERROR_SUCCESS)
  268. {
  269. UploadSuccess = TRUE;
  270. }
  271. EndRetry:
  272. if (!UploadSuccess)
  273. {
  274. ++NumRetries;
  275. bSecure = FALSE;
  276. }
  277. }
  278. if (UploadSuccess)
  279. {
  280. // So far so good... Now lets call the isapi.
  281. StringCbCopyW(wszServerName,sizeof(wszServerName),
  282. pParams->pUploadFile->GetServerName());
  283. pParams->pUploadFile->UnInitialize();
  284. ResponseURL[0] = 0;
  285. StringCbCopyW(ResponseURL, sizeof(ResponseURL), L"Getting Server Response");
  286. pParams->pUploadFile->SetUploadResult(UploadGettingResponse,
  287. ResponseURL);
  288. if (
  289. pParams->Caller->GetResponseURL(
  290. (wchar_t *)wszServerName,
  291. PathFindFileNameW(RemoteFileName),
  292. (dwFileSize > 70000), ResponseURL) == 0)
  293. {
  294. pParams->pUploadFile->SetUploadResult(UploadSucceded,
  295. ResponseURL);
  296. StringCbCopyW(g_LastResponseURL, sizeof(g_LastResponseURL), ResponseURL);
  297. // Cleanup and return
  298. // Clean up
  299. if (hFile!= INVALID_HANDLE_VALUE)
  300. CloseHandle (hFile);
  301. pParams->pUploadFile->UnInitialize();
  302. // Try to delete the cab. If for some reason we can't that ok.
  303. pParams->Caller->DeleteTempDir(TempPath, TempDumpName, TempCabName);
  304. g_UploadStatus = UploadSucceded;
  305. return S_OK;
  306. }
  307. else
  308. {
  309. // what here
  310. pParams->pUploadFile->SetUploadResult(UploadSucceded,
  311. L"Unable to get valid response from server");
  312. }
  313. }
  314. else
  315. {
  316. ReturnCode = ErrorCode;
  317. }
  318. ExitUploadThread:
  319. // Clean up
  320. if (hFile!= INVALID_HANDLE_VALUE)
  321. CloseHandle (hFile);
  322. pParams->pUploadFile->UnInitialize();
  323. pParams->Caller->DeleteTempDir(TempPath, TempDumpName, TempCabName);
  324. g_UploadStatus = UploadFailure;
  325. g_UploadFailureCode = ErrorCode;
  326. return S_OK;
  327. }
  328. /////////////////////////////////////////////////////////////////////////////
  329. // COcarptMain
  330. // UTILITY FUNCTIONS
  331. BOOL COcarptMain::ValidMiniDump(LPCTSTR FileName)
  332. {
  333. BOOL ReturnValue = false;
  334. HANDLE hFile = INVALID_HANDLE_VALUE;
  335. DWORD dwBytesRead = 0;
  336. char buff[10];
  337. DWORD dwSize = 0;
  338. hFile = CreateFile(FileName,
  339. GENERIC_READ,
  340. FILE_SHARE_READ,
  341. NULL,
  342. OPEN_EXISTING,
  343. FILE_ATTRIBUTE_NORMAL,
  344. NULL);
  345. if (hFile != INVALID_HANDLE_VALUE)
  346. {
  347. dwSize = GetFileSize(hFile, NULL);
  348. if( (dwSize >= 65536) && (dwSize < 1000000) )
  349. {
  350. ZeroMemory(buff, sizeof buff);
  351. if (ReadFile(hFile, buff, 10, &dwBytesRead, NULL))
  352. {
  353. if(strncmp(buff,"PAGEDUMP ",8)==0)
  354. ReturnValue = true;
  355. }
  356. }
  357. CloseHandle(hFile);
  358. }
  359. return ReturnValue;
  360. }
  361. BOOL COcarptMain::ValidMiniDump(BSTR FileName)
  362. {
  363. BOOL ReturnValue = false;
  364. HANDLE hFile = INVALID_HANDLE_VALUE;
  365. DWORD dwBytesRead = 0;
  366. char buff[10];
  367. DWORD dwSize;
  368. GetFileHandle(FileName,&hFile);
  369. if (hFile != INVALID_HANDLE_VALUE)
  370. {
  371. dwSize = GetFileSize(hFile, NULL);
  372. if( ( dwSize >= 65536) && (dwSize < 1000000) )
  373. {
  374. ZeroMemory (buff, sizeof buff);
  375. if (ReadFile(hFile, buff, 10, &dwBytesRead, NULL))
  376. {
  377. if(strncmp(buff,"PAGEDUMP ",8)==0)
  378. ReturnValue = true;
  379. }
  380. }
  381. CloseHandle(hFile);
  382. }
  383. return ReturnValue;
  384. }
  385. /*****************************************************
  386. Function: CreateTempDirectory
  387. Arguments: [out] wchar_t *TempPath
  388. Return Values:
  389. True = Temp directory was created
  390. False = An error occured building the temp directory.
  391. */
  392. BOOL COcarptMain::CreateTempDir(wchar_t *TempDirectory)
  393. {
  394. // int DriveNum;
  395. wchar_t lpWindowsDir[MAX_PATH];
  396. BOOL Status = FALSE;
  397. wchar_t TempFile[MAX_PATH * 2];
  398. BOOL Done=FALSE;
  399. int Retries = 0;
  400. wchar_t *src;
  401. wchar_t *dest;
  402. if (!GetWindowsDirectoryW(lpWindowsDir, MAX_PATH))
  403. {
  404. // ?
  405. return Status;
  406. }
  407. // now strip out the drive letter
  408. src = lpWindowsDir;
  409. dest = TempDirectory;
  410. while (*src != _T('\\'))
  411. {
  412. *dest = *src;
  413. ++ src;
  414. ++ dest;
  415. }
  416. *dest = _T('\\');
  417. ++dest;
  418. *dest = _T('\0');
  419. // tack on the directory name we wish to create
  420. // in this case ocatemp.
  421. if (StringCbCatW(TempDirectory,MAX_PATH *2, L"OcaTemp\0") != S_OK)
  422. {
  423. goto ERRORS;
  424. }
  425. // Check to see if this directory exists.
  426. if (PathIsDirectoryW(TempDirectory) )
  427. {
  428. // Yes. Then use the existing path
  429. if (StringCbCopyW(TempFile,sizeof TempFile,TempDirectory) != S_OK)
  430. {
  431. goto ERRORS;
  432. }
  433. if (StringCbCatW(TempFile,sizeof TempFile,L"\\Mini.dmp") != S_OK)
  434. {
  435. goto ERRORS;
  436. }
  437. // First check to see if the file already exists
  438. if (PathFileExistsW(TempFile))
  439. {
  440. Done = FALSE;
  441. Retries = 0;
  442. // The file exists attempt to delete it.
  443. while (!Done)
  444. {
  445. if (DeleteFileW(TempFile))
  446. {
  447. Done = TRUE;
  448. }
  449. else
  450. {
  451. ++ Retries;
  452. Sleep(1000);
  453. }
  454. if (Retries > 5)
  455. {
  456. Done = TRUE;
  457. }
  458. }
  459. if (PathFileExistsW(TempFile))
  460. {
  461. return Status;
  462. }
  463. }
  464. if (StringCbCopyW(TempFile,sizeof TempFile,TempDirectory) != S_OK)
  465. {
  466. Status = FALSE;
  467. goto ERRORS;
  468. }
  469. if (StringCbCatW(TempFile,sizeof TempFile,L"\\Mini.cab") != S_OK)
  470. {
  471. Status = FALSE;
  472. goto ERRORS;
  473. }
  474. // Now check to see if the cab already exists
  475. if (PathFileExistsW(TempFile))
  476. {
  477. Done =FALSE;
  478. Retries = 0;
  479. // The file exists attempt to delete it.
  480. while (!Done)
  481. {
  482. if (DeleteFileW(TempFile))
  483. {
  484. Done = TRUE;
  485. }
  486. else
  487. {
  488. ++ Retries;
  489. Sleep(1000);
  490. }
  491. if (Retries > 5)
  492. {
  493. Done = TRUE;
  494. }
  495. }
  496. if (PathFileExistsW(TempFile))
  497. {
  498. return Status;
  499. }
  500. }
  501. Status = TRUE;
  502. }
  503. else
  504. {
  505. // No create it.
  506. if (! CreateDirectoryW(TempDirectory,NULL) )
  507. {
  508. return Status;
  509. }
  510. Status = TRUE;
  511. }
  512. ERRORS:
  513. // return the path to the calling function.
  514. return Status;
  515. }
  516. /*****************************************************
  517. Function: DeleteTempDir
  518. Arguments: [in] wchar_t *TempPath -- directory to delete
  519. [in] wchar_t *FileName -- Dump file to delete
  520. [in] wchar_t *CabName -- CabFile to delete
  521. Return Values:
  522. True = Cleanup Succeeded
  523. False = An error occured deleteing a file or directory
  524. */
  525. BOOL COcarptMain::DeleteTempDir(wchar_t *TempDirectory,wchar_t *FileName,wchar_t *CabName)
  526. {
  527. if (PathFileExistsW(FileName))
  528. {
  529. if (!DeleteFileW(FileName))
  530. {
  531. return FALSE;
  532. }
  533. }
  534. if (PathFileExistsW(CabName))
  535. {
  536. if (!DeleteFileW(CabName))
  537. {
  538. return FALSE;
  539. }
  540. }
  541. if (PathIsDirectoryW(TempDirectory))
  542. {
  543. if (!RemoveDirectoryW(TempDirectory))
  544. {
  545. return FALSE;
  546. }
  547. }
  548. return TRUE;
  549. }
  550. void COcarptMain::GetFileHandle(wchar_t *FileName, HANDLE *hFile)
  551. {
  552. *hFile = CreateFileW(FileName,
  553. GENERIC_READ,
  554. FILE_SHARE_READ,
  555. NULL,
  556. OPEN_EXISTING,
  557. FILE_ATTRIBUTE_NORMAL,
  558. NULL);
  559. }
  560. BOOL COcarptMain::FindMiniDumps( BSTR *FileLists)
  561. {
  562. CComBSTR FileList;
  563. TCHAR strTMP[255];
  564. LONG lResult;
  565. BOOL blnResult;
  566. FILETIME FileTime;
  567. FILETIME LocalFileTime;
  568. //Get an instance of the ATL Registry wrapper class
  569. CRegKey objRegistry;
  570. TCHAR szPath[_MAX_PATH];
  571. TCHAR szValue[_MAX_PATH];
  572. DWORD dwLen = _MAX_PATH;
  573. // There is no sense attempting to locate the mini dump path since Win9x and NT4 don't generate them.
  574. DWORD dwVersion = GetVersion();
  575. DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  576. BOOL bWin9x = FALSE;
  577. BOOL bNT4 = FALSE;
  578. BOOL NoFiles = FALSE;
  579. SYSTEMTIME Systime;
  580. BOOL FoundFirst = FALSE;
  581. BOOL Status = TRUE;
  582. if (dwVersion < 0x80000000)
  583. {
  584. if (dwWindowsMajorVersion == 4)
  585. bNT4 = TRUE;
  586. }
  587. if (bNT4)
  588. {
  589. // clear the string
  590. *FileLists = FileList.Detach();
  591. return FALSE;
  592. }
  593. //Open The CrashControl section in the registry
  594. lResult = objRegistry.Open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\CrashControl"));
  595. if (lResult == ERROR_SUCCESS)
  596. {
  597. //Get the Minidump path
  598. lResult = objRegistry.QueryValue(szValue, _T("MinidumpDir"), &dwLen);
  599. if (lResult == ERROR_SUCCESS){
  600. if(szValue[0] == _T('%')){
  601. /* If the first character is '%' then this is an
  602. environment variable which must be translated */
  603. //Find The Position of the Last '%'
  604. int i = 0;
  605. for(i = 1;i < (int)_tcslen(szValue); i++)
  606. {
  607. if(szValue[i] == _T('%'))
  608. {
  609. break;
  610. }
  611. }
  612. //Extract the environment variable for the path
  613. TCHAR szEnvStr[MAX_PATH];
  614. ZeroMemory( szEnvStr, sizeof szEnvStr);
  615. _tcsncpy(szEnvStr,szValue, (i+ 1));
  616. // ::MessageBox(NULL, szEnvStr, "szEnvStr",MB_OK);
  617. //Extract the remainder of the path
  618. TCHAR szPathRemainder[MAX_PATH];
  619. ZeroMemory(szPathRemainder, sizeof szPathRemainder);
  620. _tcsncpy(szPathRemainder,szValue +(i + 1), (_tcslen(szValue)-(i+ 1)));
  621. //Join the path and filename together
  622. ZeroMemory(szPath,sizeof szPath);
  623. blnResult = ExpandEnvironmentStrings(szEnvStr,szPath,dwLen);
  624. if (StringCbCat(szPath,sizeof szPath,szPathRemainder) != S_OK)
  625. {
  626. *FileLists = FileList.Detach();
  627. objRegistry.Close();
  628. return FALSE;
  629. }
  630. }
  631. else{
  632. if (StringCbCopy(szPath,sizeof szPath,szValue) != S_OK)
  633. {
  634. *FileLists = FileList.Detach();
  635. objRegistry.Close();
  636. return FALSE;
  637. }
  638. }
  639. }
  640. else // Query Value Failed
  641. {
  642. *FileLists = FileList.Detach();
  643. objRegistry.Close();
  644. return FALSE;
  645. }
  646. objRegistry.Close();
  647. }
  648. else //Reg Open Failed
  649. {
  650. *FileLists = FileList.Detach();
  651. return FALSE;
  652. }
  653. /* Next search the minidump directory and build a string with javaScript code
  654. This javascript code will have an eval applied to it so the browser can
  655. use the Array named _FileList. The date in file list needs to be mm/dd/yyyy
  656. so the time_t from the finddata_t struct is converted to a tm struct by
  657. calling localtime on it. The tm struct is then passed to a private function
  658. to extract and concatenate the mm dd and yyyy.*/
  659. //::MessageBox(NULL, szPath, "Looking for Minidumps",MB_OK);
  660. if (PathIsDirectory(szPath))
  661. {
  662. BOOL Done = FALSE;
  663. HANDLE hFindFile = INVALID_HANDLE_VALUE;
  664. WIN32_FIND_DATA FindData;
  665. TCHAR SearchPath[MAX_PATH];
  666. TCHAR FilePath[MAX_PATH];
  667. if (_tcslen(szPath) > 1)
  668. {
  669. if (szPath[_tcslen(szPath)-1] != _T('\\'))
  670. if (StringCbCat(szPath,sizeof szPath,_T("\\")) == S_OK)
  671. {
  672. if (StringCbCopy (SearchPath,sizeof SearchPath, szPath) == S_OK)
  673. {
  674. if(StringCbCat(SearchPath,sizeof SearchPath, _T("*.dmp")) == S_OK)
  675. {
  676. Status = TRUE;
  677. }
  678. else
  679. Status = FALSE;
  680. }
  681. else
  682. Status = FALSE;
  683. }
  684. else
  685. Status = FALSE;
  686. }
  687. if (Status)
  688. {
  689. // ::MessageBox(NULL, SearchPath, "Search Path",MB_OK);
  690. hFindFile = FindFirstFile(SearchPath, &FindData);
  691. /* Find first .dmp file in current directory */
  692. if( hFindFile == INVALID_HANDLE_VALUE )
  693. {
  694. *FileLists = FileList.Detach();
  695. return FALSE;
  696. }
  697. else
  698. {
  699. if (StringCbCopy(FilePath,sizeof FilePath, szPath) == S_OK)
  700. {
  701. if (StringCbCat(FilePath, sizeof FilePath, FindData.cFileName) == S_OK)
  702. {
  703. if ( !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  704. {
  705. //::MessageBox(NULL, FilePath, "Validating file",MB_OK);
  706. if(ValidMiniDump(FilePath))
  707. {
  708. FileList = _T("2:");
  709. FileList += FilePath;
  710. FileList += _T(",");
  711. //GetFileTime(FindData.cFileName, &FileTime,NULL,NULL);
  712. FileTime = FindData.ftLastWriteTime;
  713. FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
  714. FileTimeToSystemTime(&LocalFileTime, &Systime);
  715. GetDateFormat (LOCALE_USER_DEFAULT,
  716. DATE_SHORTDATE,
  717. &Systime,
  718. NULL,
  719. strTMP,
  720. 255);
  721. // FormatMiniDate(&Systime, strTMP);
  722. FileList += strTMP;
  723. FileList += _T(";");
  724. FoundFirst = TRUE;
  725. }
  726. }
  727. while(FindNextFile(hFindFile,&FindData))
  728. {
  729. if ( !(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  730. {
  731. if (StringCbCopy(FilePath,sizeof FilePath, szPath) == S_OK)
  732. {
  733. if (StringCbCat(FilePath,sizeof FilePath, FindData.cFileName)== S_OK)
  734. {
  735. if(ValidMiniDump(FilePath))
  736. {
  737. if (!FoundFirst)
  738. {
  739. FileList = _T("2:");
  740. FoundFirst = TRUE;
  741. }
  742. FileList += FilePath;
  743. FileList += _T(",");
  744. FileTime = FindData.ftLastWriteTime;
  745. FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
  746. FileTimeToSystemTime(&LocalFileTime, &Systime);
  747. GetDateFormat (LOCALE_USER_DEFAULT,
  748. DATE_SHORTDATE,
  749. &Systime,
  750. NULL,
  751. strTMP,
  752. 255);
  753. FileList += strTMP;
  754. FileList += _T(";");
  755. } // end validate dump
  756. } // end string cat
  757. } //end string copy
  758. }// end file attributes
  759. } // end while
  760. }
  761. }
  762. FindClose( hFindFile );
  763. } // end valid file handle
  764. }// end if status
  765. } // end path is directory
  766. else
  767. {
  768. // ::MessageBox(NULL, szPath, "Path not found",MB_OK);
  769. *FileLists = FileList.Detach();
  770. return FALSE;
  771. }
  772. if (!FoundFirst)
  773. {
  774. *FileLists = FileList.Detach();
  775. return FALSE;
  776. }
  777. *FileLists = FileList.Detach();
  778. return TRUE;
  779. }
  780. BOOL COcarptMain::FindFullDumps( BSTR *FileLists)
  781. {
  782. CComBSTR FileList;
  783. LONG lResult;
  784. BOOL blnResult;
  785. //Get an instance of the ATL Registry wrapper class
  786. CRegKey objRegistry;
  787. TCHAR szFileName[MAX_PATH];
  788. ZeroMemory(szFileName,sizeof szFileName);
  789. DWORD dwVersion = GetVersion();
  790. DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  791. BOOL bWin9x = FALSE;
  792. BOOL bNT4 = FALSE;
  793. if (dwVersion < 0x80000000)
  794. {
  795. bWin9x = FALSE;
  796. if (dwWindowsMajorVersion == 4)
  797. bNT4 = TRUE;
  798. }
  799. else
  800. {
  801. bWin9x = TRUE;
  802. bNT4 = FALSE;
  803. }
  804. if (bWin9x || bNT4)
  805. {
  806. FileList = _T("");
  807. return FALSE;
  808. }
  809. //Open The CrashControl section in the registry
  810. lResult = objRegistry.Open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\CrashControl"));
  811. if (lResult == ERROR_SUCCESS)
  812. {
  813. TCHAR szValue[_MAX_PATH];
  814. DWORD dwLen = _MAX_PATH;
  815. //Get the name of the full dump file
  816. lResult = objRegistry.QueryValue(szValue, _T("DumpFile"), &dwLen);
  817. if (lResult == ERROR_SUCCESS){
  818. /* If the first character is '%' then this is an
  819. environment variable which must be translated */
  820. if(szValue[0] == _T('%')){
  821. //Find The Position of the Last '%'
  822. for(int i = 1;i < sizeof(szValue); i++){
  823. if(szValue[i] == '%'){break;}
  824. }
  825. //Extract the environment variable for the path
  826. TCHAR szEnvStr[MAX_PATH];
  827. ZeroMemory(szEnvStr, sizeof szEnvStr);
  828. _tcsncpy(szEnvStr,szValue, (i+ 1));
  829. //Extract the remainder of the path
  830. TCHAR szFileNameRemainder[MAX_PATH];
  831. ZeroMemory(szFileNameRemainder, sizeof szFileNameRemainder);
  832. _tcsncpy(szFileNameRemainder,szValue +(i + 1), (_tcslen(szValue)-(i+ 1)));
  833. //Translate the environment variable
  834. blnResult = ExpandEnvironmentStrings(szEnvStr,szFileName,dwLen);
  835. //Join the path and filename together
  836. if (StringCbCat(szFileName,sizeof szFileName,szFileNameRemainder) != S_OK)
  837. {
  838. FileList = _T("");
  839. objRegistry.Close();
  840. *FileLists = FileList.Detach();
  841. return FALSE;
  842. }
  843. }
  844. else{
  845. if (StringCbCopy(szFileName,sizeof szFileName,szValue) != S_OK)
  846. {
  847. FileList = _T("");
  848. objRegistry.Close();
  849. *FileLists = FileList.Detach();
  850. return FALSE;
  851. }
  852. }
  853. FILETIME ftCreate, ftLastAccess, ftLastWrite;
  854. // SYSTEMTIME st;
  855. HANDLE fileHandle;
  856. fileHandle = CreateFile(szFileName,
  857. GENERIC_READ,
  858. FILE_SHARE_READ,
  859. NULL,
  860. OPEN_EXISTING,
  861. FILE_ATTRIBUTE_NORMAL,
  862. NULL);
  863. if (fileHandle == INVALID_HANDLE_VALUE)
  864. {
  865. FileList = _T("");
  866. objRegistry.Close();
  867. *FileLists = FileList.Detach();
  868. return FALSE;
  869. }
  870. blnResult = GetFileTime(fileHandle, &ftCreate, &ftLastAccess, &ftLastWrite);
  871. FileList = _T("3:");
  872. //Convert File time to a mm/dd/yyyy format
  873. FILETIME LocalFileTime;
  874. SYSTEMTIME SysTime;
  875. wchar_t LocaleTime[255];
  876. FileTimeToLocalFileTime(&ftCreate, &LocalFileTime);
  877. FileTimeToSystemTime(&LocalFileTime, &SysTime);
  878. GetDateFormatW (LOCALE_USER_DEFAULT,
  879. DATE_SHORTDATE,
  880. &SysTime,
  881. NULL,
  882. LocaleTime,
  883. 255);
  884. FileList += szFileName;
  885. FileList += _T(",");
  886. FileList += LocaleTime;
  887. FileList += _T(";");
  888. CloseHandle(fileHandle);
  889. }
  890. else //QueryValue failed
  891. {
  892. FileList = _T("");
  893. objRegistry.Close();
  894. *FileLists = FileList.Detach();
  895. return FALSE;
  896. }
  897. objRegistry.Close();
  898. }
  899. else //Key Open Failed
  900. {
  901. FileList = _T("");
  902. objRegistry.Close();
  903. *FileLists = FileList.Detach();
  904. return FALSE;
  905. }
  906. *FileLists = FileList.Detach();
  907. return TRUE;
  908. }
  909. void COcarptMain::FormatDate(tm *pTimeStruct, CComBSTR &strDate)
  910. {
  911. strDate = L"";
  912. char BUFFER[5];
  913. if(pTimeStruct->tm_mon+1 < 10){
  914. _itoa((pTimeStruct->tm_mon +1),BUFFER,10);
  915. strDate += L"0";
  916. strDate += BUFFER;
  917. }
  918. else{
  919. _itoa((pTimeStruct->tm_mon +1),BUFFER,10);
  920. strDate += BUFFER;
  921. }
  922. strDate += L"/";
  923. if(pTimeStruct->tm_mday < 10){
  924. _itoa((pTimeStruct->tm_mday),BUFFER,10);
  925. strDate += L"0";
  926. strDate += BUFFER;
  927. }
  928. else{
  929. _itoa((pTimeStruct->tm_mday),BUFFER,10);
  930. strDate += BUFFER;
  931. }
  932. strDate += L"/";
  933. _itoa((pTimeStruct->tm_year +1900),BUFFER,10);
  934. strDate += BUFFER;
  935. }
  936. /*****************************************************8
  937. Function:
  938. Arguments:
  939. Return Values:
  940. */
  941. void COcarptMain::FormatDate(SYSTEMTIME *pTimeStruct, CComBSTR &strDate)
  942. {
  943. strDate = L"";
  944. char BUFFER[5];
  945. //We want local time not GMT.
  946. SYSTEMTIME *pLocalTime = pTimeStruct;
  947. FILETIME FileTime, LocalFileTime;
  948. SystemTimeToFileTime(pTimeStruct, &FileTime);
  949. FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
  950. FileTimeToSystemTime(&LocalFileTime, pLocalTime);
  951. if(pTimeStruct->wMonth < 10){
  952. _itoa((pLocalTime->wMonth),BUFFER,10);
  953. strDate += L"0";
  954. strDate += BUFFER;
  955. }
  956. else{
  957. _itoa((pLocalTime->wMonth),BUFFER,10);
  958. strDate += BUFFER;
  959. }
  960. strDate += L"/";
  961. if(pTimeStruct->wDay < 10){
  962. _itoa((pLocalTime->wDay),BUFFER,10);
  963. strDate += L"0";
  964. strDate += BUFFER;
  965. }
  966. else{
  967. _itoa((pLocalTime->wDay),BUFFER,10);
  968. strDate += BUFFER;
  969. }
  970. strDate += L"/";
  971. _itoa((pLocalTime->wYear),BUFFER,10);
  972. strDate += BUFFER;
  973. }
  974. /*****************************************************
  975. Function:
  976. Arguments:
  977. Return Values:
  978. */
  979. void COcarptMain::FormatMiniDate(SYSTEMTIME *pTimeStruct, CComBSTR &strDate)
  980. {
  981. TCHAR Temp[255];
  982. //We want local time not GMT.
  983. SYSTEMTIME *pLocalTime = pTimeStruct;
  984. FILETIME FileTime, LocalFileTime;
  985. SystemTimeToFileTime(pTimeStruct, &FileTime);
  986. FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
  987. FileTimeToSystemTime(&LocalFileTime, pLocalTime);
  988. GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, pLocalTime,NULL,Temp,255);
  989. strDate +=Temp;
  990. }
  991. /*****************************************************8
  992. Function:
  993. Arguments:
  994. Return Values:
  995. */
  996. BOOL COcarptMain::ConvertFullDumpInternal (BSTR *Source, BSTR *Destination)
  997. { int ReturnCode = 0;
  998. PROCESS_INFORMATION ProcessInfo;
  999. STARTUPINFOW StartupInfoW;
  1000. HANDLE hMiniFile;
  1001. wchar_t TempPathW[MAX_PATH];
  1002. wchar_t Stringbuff[50];
  1003. DWORD dwBytesRead = 0;
  1004. HANDLE hFile;
  1005. WORD * BuildNum;
  1006. CComBSTR Dest = L"";
  1007. DWORD BuildNumber = 0;
  1008. DWORD RetryCount = 0;
  1009. wchar_t Windir[MAX_PATH];
  1010. ZeroMemory(TempPathW,sizeof TempPathW);
  1011. ZeroMemory(Windir, MAX_PATH *2);
  1012. GetTempPathW(MAX_PATH, TempPathW);
  1013. HANDLE hDir;
  1014. // Validate the Temp Path
  1015. if ( (hDir = CreateFileW(TempPathW,
  1016. GENERIC_READ,
  1017. FILE_SHARE_READ,
  1018. NULL,
  1019. OPEN_EXISTING,
  1020. FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS,
  1021. NULL)) == INVALID_HANDLE_VALUE)
  1022. {
  1023. if (StringCbCopyW(TempPathW,sizeof TempPathW, L"\0") != S_OK)
  1024. {
  1025. return FALSE;
  1026. }
  1027. if (!GetWindowsDirectoryW(TempPathW,MAX_PATH))
  1028. {
  1029. //CloseHandle(hDir);
  1030. return FALSE;
  1031. }
  1032. }
  1033. PathAppendW(TempPathW, L"mini000000-00.dmp");
  1034. GetFileHandle(TempPathW,&hMiniFile);
  1035. if (hMiniFile == INVALID_HANDLE_VALUE)
  1036. {
  1037. RetryCount = 0;
  1038. while ( (GetLastError() == ERROR_SHARING_VIOLATION) && (RetryCount < MAX_RETRY_COUNT))
  1039. {
  1040. ++ RetryCount;
  1041. Sleep(1000); // Sleep for 1 second
  1042. GetFileHandle(TempPathW,&hMiniFile);
  1043. }
  1044. }
  1045. if ((GetLastError() == ERROR_SHARING_VIOLATION) && (RetryCount >= MAX_RETRY_COUNT))
  1046. {
  1047. if (hDir != INVALID_HANDLE_VALUE)
  1048. {
  1049. CloseHandle(hDir);
  1050. }
  1051. return FALSE; // Well nothing we can do here return conversion failure.
  1052. }
  1053. if ( (hMiniFile != INVALID_HANDLE_VALUE) ) // Yes it does So we need to delete it.
  1054. {
  1055. CloseHandle(hMiniFile);
  1056. DeleteFileW(TempPathW);
  1057. }
  1058. CComBSTR strCommand = L"";
  1059. /* // open the full dump file and get the build number.
  1060. // We don't need this any more
  1061. hFile = CreateFileW(*Source,
  1062. GENERIC_READ,
  1063. FILE_SHARE_READ,
  1064. NULL,OPEN_EXISTING,
  1065. FILE_ATTRIBUTE_NORMAL,
  1066. NULL );
  1067. if (hFile == INVALID_HANDLE_VALUE)
  1068. {
  1069. if (hDir != INVALID_HANDLE_VALUE)
  1070. {
  1071. CloseHandle(hDir);
  1072. return FALSE;
  1073. }
  1074. }
  1075. // Get the build number.
  1076. if (ReadFile(hFile,Stringbuff,24,&dwBytesRead,NULL))
  1077. {
  1078. CloseHandle(hFile);
  1079. BuildNum = (WORD*) (Stringbuff + 12);
  1080. BuildNumber = _wtol ( BuildNum);
  1081. }
  1082. else
  1083. {
  1084. if (hFile != INVALID_HANDLE_VALUE)
  1085. {
  1086. CloseHandle (hFile);
  1087. }
  1088. if (hDir != INVALID_HANDLE_VALUE)
  1089. CloseHandle (hDir);
  1090. return FALSE;
  1091. }
  1092. */
  1093. // Get the Windows Directory
  1094. if (!GetWindowsDirectoryW(Windir, MAX_PATH))
  1095. {
  1096. // we can't continue
  1097. if (hDir != INVALID_HANDLE_VALUE)
  1098. CloseHandle (hDir);
  1099. return FALSE;
  1100. }
  1101. strCommand += Windir;
  1102. strCommand += L"\\Downloaded Program Files\\";
  1103. strCommand += L"dumpconv.exe -i \"";
  1104. strCommand += *Source;
  1105. strCommand += L"\" -o ";
  1106. strCommand += L"\"" ;
  1107. strCommand += TempPathW;
  1108. strCommand += "\"";
  1109. ZeroMemory(&StartupInfoW,sizeof(STARTUPINFOW));
  1110. StartupInfoW.cb = sizeof (STARTUPINFOW);
  1111. ReturnCode = CreateProcessW(NULL,
  1112. strCommand,
  1113. NULL,
  1114. NULL,
  1115. FALSE,
  1116. CREATE_NO_WINDOW,
  1117. NULL,
  1118. NULL,
  1119. &StartupInfoW,
  1120. &ProcessInfo);
  1121. if (ReturnCode)
  1122. {
  1123. CloseHandle(ProcessInfo.hThread);
  1124. CloseHandle(ProcessInfo.hProcess);
  1125. HANDLE hFile2 = INVALID_HANDLE_VALUE;
  1126. Sleep(2000);
  1127. for(short i = 0; i < 30; i++)
  1128. {
  1129. hFile2 = CreateFileW(TempPathW,
  1130. GENERIC_READ,
  1131. 0,
  1132. NULL,
  1133. OPEN_EXISTING,
  1134. FILE_ATTRIBUTE_NORMAL,
  1135. NULL);
  1136. if (hFile2 != INVALID_HANDLE_VALUE)
  1137. {
  1138. Dest += TempPathW;
  1139. CloseHandle(hFile2);
  1140. if (hDir != INVALID_HANDLE_VALUE)
  1141. CloseHandle(hDir);
  1142. *Destination = Dest.Detach();
  1143. return TRUE;
  1144. }
  1145. Sleep(1000);
  1146. }
  1147. }
  1148. if (hDir != INVALID_HANDLE_VALUE)
  1149. CloseHandle(hDir);
  1150. return FALSE;
  1151. }
  1152. DWORD COcarptMain::GetResponseURL(wchar_t *HostName, wchar_t *RemoteFileName, BOOL fFullDump, wchar_t *ResponseURL)
  1153. {
  1154. wchar_t IsapiUrl[255];
  1155. wchar_t ConnectString [255];
  1156. HINTERNET hInet = NULL;
  1157. HINTERNET hRedirUrl = NULL;
  1158. wchar_t* pUploadUrl = NULL;
  1159. DWORD dwUrlLength = 0;
  1160. URL_COMPONENTSW urlComponents;
  1161. BOOL bRet;
  1162. DWORD dwLastError;
  1163. HANDLE hSourceFile = INVALID_HANDLE_VALUE;
  1164. wchar_t ConvSourceFile[MAX_PATH];
  1165. BOOL Converted = FALSE;
  1166. BOOL bIsCab = FALSE;
  1167. DWORD ErrorCode = 0;
  1168. BOOL UploadSuccess = FALSE;
  1169. DWORD NumRetries = 0;
  1170. DWORD dwBytesRead;
  1171. DWORD dwBytesWritten;
  1172. BYTE *pBuffer;
  1173. HANDLE hFile;
  1174. DWORD ResLength = 255;
  1175. DWORD index = 0;
  1176. static const wchar_t *pszAccept[] = {L"*.*", 0};
  1177. DWORD ResponseCode = 0;
  1178. wchar_t *temp;
  1179. wchar_t NewState;
  1180. WCHAR wszProxyServer[100], wszByPass[100];
  1181. //wsprintfW (IsapiUrl, L"https://%s/isapi/oca_extension.dll?id=%s&Type=5",HostName, RemoteFileName);
  1182. if (StringCbPrintfW(IsapiUrl,sizeof IsapiUrl,
  1183. L"/isapi/oca_extension.dll?id=%s&Type=%ld",
  1184. RemoteFileName,
  1185. (fFullDump ? 7 : 5)) != S_OK)
  1186. {
  1187. return 1;
  1188. }
  1189. // ::MessageBoxW(NULL,L"Getting the isapi response",IsapiUrl,MB_OK);
  1190. // Get the URL returned from the MS Corporate IIS redir.dll isapi URL redirector
  1191. dwUrlLength = 512;
  1192. pUploadUrl = (wchar_t*)malloc(dwUrlLength);
  1193. if(!pUploadUrl)
  1194. {
  1195. //ReturnCode->intVal = GetLastError();
  1196. ErrorCode = GetLastError();
  1197. goto exitGetResonseURL;
  1198. }
  1199. ZeroMemory(pUploadUrl, dwUrlLength);
  1200. ErrorCode = m_pUploadFile->GetUrlPageData(IsapiUrl, pUploadUrl, dwUrlLength);
  1201. if(ErrorCode != ERROR_SUCCESS)
  1202. {
  1203. dwLastError = GetLastError();
  1204. // If last error was due to insufficient buffer size, create a new one the correct size.
  1205. if(dwLastError == ERROR_INSUFFICIENT_BUFFER)
  1206. {
  1207. if (pUploadUrl)
  1208. {
  1209. free(pUploadUrl);
  1210. pUploadUrl = NULL;
  1211. }
  1212. pUploadUrl = (wchar_t*)malloc(dwUrlLength);
  1213. if(!pUploadUrl)
  1214. {
  1215. ErrorCode = GetLastError();
  1216. goto exitGetResonseURL;
  1217. }
  1218. }
  1219. else
  1220. {
  1221. goto exitGetResonseURL;
  1222. }
  1223. }
  1224. // Parse the returned url and swap the type value for the state value.
  1225. if (StringCbCopyW(ResponseURL,MAX_PATH * 2, pUploadUrl) != S_OK)
  1226. {
  1227. ErrorCode = GetLastError();
  1228. goto exitGetResonseURL;
  1229. }
  1230. temp = ResponseURL;
  1231. temp += (wcslen(ResponseURL)-1);
  1232. //::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1233. while (*temp != L'=')
  1234. -- temp;
  1235. // ok Temp + 1 is our new state value.
  1236. NewState = *(temp+1);
  1237. //::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1238. //::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1239. // Now back up till the next =
  1240. -- temp; // Skip the current =
  1241. while (*temp != L'=')
  1242. -- temp;
  1243. //::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1244. if ( (*(temp - 1) == L'D') || (*(temp -1) == L'd')) // We have an ID field and have to go back further.
  1245. {
  1246. // first terminate the string after the Guid.
  1247. while (*temp != '&')
  1248. ++temp;
  1249. *temp = L'\0';
  1250. // ::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1251. // now go back 2 = signs.
  1252. while (*temp != L'=')
  1253. -- temp;
  1254. --temp;
  1255. // ::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1256. while (*temp != L'=')
  1257. -- temp;
  1258. *(temp+1) = NewState;
  1259. // ::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1260. }
  1261. else
  1262. {
  1263. //::MessageBoxW(NULL,temp,L"New State Value else case (no id field)",MB_OK);
  1264. *(temp+1) = NewState;
  1265. *(temp+2) = L'\0'; // Null terminate the string after the state. (we don't wan't the type value
  1266. }
  1267. // ::MessageBoxW(NULL,temp,L"New State Value",MB_OK);
  1268. // ::MessageBoxW(NULL,L"Returning URL to web page.",ResponseURL,MB_OK);
  1269. ErrorCode = 0;
  1270. exitGetResonseURL:
  1271. if (pUploadUrl)
  1272. free(pUploadUrl);
  1273. return ErrorCode;;
  1274. }
  1275. //INTERFACES
  1276. STDMETHODIMP
  1277. COcarptMain::Upload(
  1278. BSTR *SourceFile,
  1279. BSTR *DestFile,
  1280. BSTR *Language,
  1281. BSTR *OptionCode,
  1282. int ConvertToMini,
  1283. VARIANT *ReturnCode)
  1284. {
  1285. HRESULT hResult = S_OK;
  1286. HANDLE hThread;
  1287. DWORD dwThreadId;
  1288. static UPLOAD_CONTEXT UploadCtxt = {0};
  1289. ReturnCode->vt = VT_INT;
  1290. ReturnCode->intVal = 0;
  1291. // ::MessageBoxW(NULL,L"UploadCalled",NULL,MB_OK);
  1292. if ( (!SourceFile) || (!DestFile) || (!Language) || (!OptionCode))
  1293. {
  1294. // ::MessageBoxW(NULL,L"Failed Param Check",NULL,MB_OK);
  1295. ReturnCode->intVal = 100;
  1296. }
  1297. if (!InApprovedDomain())
  1298. {
  1299. // ::MessageBoxW(NULL,L"Failed Domain Check",NULL,MB_OK);
  1300. return E_FAIL;
  1301. }
  1302. if (m_pUploadFile == NULL)
  1303. {
  1304. OcaUpldCreate(&m_pUploadFile);
  1305. }
  1306. if (m_pUploadFile == NULL)
  1307. {
  1308. ReturnCode->intVal = 100;
  1309. return E_FAIL;
  1310. }
  1311. if (m_pUploadFile->IsUploadInProgress())
  1312. {
  1313. ReturnCode->intVal = 100;
  1314. return S_OK;
  1315. }
  1316. g_UploadStatus = UploadStarted;
  1317. StringCbCopyW(UploadCtxt.DestFile, sizeof(UploadCtxt.DestFile), *DestFile);
  1318. StringCbCopyW(UploadCtxt.Language, sizeof(UploadCtxt.Language), *Language);
  1319. StringCbCopyW(UploadCtxt.OptionCode, sizeof(UploadCtxt.OptionCode), *OptionCode);
  1320. StringCbCopyW(UploadCtxt.SourceFile, sizeof(UploadCtxt.SourceFile), *SourceFile);
  1321. UploadCtxt.pUploadFile = m_pUploadFile;
  1322. UploadCtxt.Caller = this;
  1323. UploadCtxt.ConvertToMini = ConvertToMini;
  1324. hThread = CreateThread(NULL, 0, &UploadThreadStart, (PVOID) &UploadCtxt,
  1325. 0, &dwThreadId);
  1326. // hThread = NULL;
  1327. // UploadThreadStart((LPVOID) &UploadCtxt);
  1328. if (hThread)
  1329. {
  1330. WaitForSingleObject(hThread, 400);
  1331. CloseHandle(hThread);
  1332. } else
  1333. {
  1334. ReturnCode->intVal = 100;
  1335. g_UploadStatus = UploadFailure;
  1336. }
  1337. return S_OK;
  1338. }
  1339. STDMETHODIMP COcarptMain::Search(VARIANT *pvFileList)
  1340. {
  1341. CComBSTR FileList;
  1342. FileList="";
  1343. if (!InApprovedDomain())
  1344. {
  1345. return E_FAIL;
  1346. }
  1347. if (!FindMiniDumps(&FileList))
  1348. {
  1349. //::MessageBoxW(NULL, L"No MiniDumps Found", L"No mini's",MB_OK);
  1350. FindFullDumps(&FileList);
  1351. }
  1352. pvFileList->vt = VT_BSTR;
  1353. pvFileList->bstrVal = FileList.Detach();
  1354. return S_OK;
  1355. }
  1356. STDMETHODIMP COcarptMain::Browse(BSTR *pbstrTitle, BSTR *Lang, VARIANT *Path)
  1357. {
  1358. HWND hParent = NULL;
  1359. // char *WindowTitle;
  1360. CComBSTR WindowText = *pbstrTitle;
  1361. WindowText += " - Microsoft Internet Explorer";
  1362. // determine the language and Load the resource strings.
  1363. wchar_t String1[200];
  1364. wchar_t String2[200];
  1365. static wchar_t szFilterW[400];
  1366. if (!InApprovedDomain())
  1367. {
  1368. return E_FAIL;
  1369. }
  1370. LoadStringW(::_Module.GetModuleInstance(), IDS_STRING_ENU_DMPFILE, String1, 200);
  1371. LoadStringW(::_Module.GetModuleInstance(), IDS_STRING_ENU_ALLFILES, String2, 200);
  1372. // Build the buffer;
  1373. wchar_t Pattern1[] = L"*.dmp";
  1374. wchar_t Pattern2[] = L"*.*";
  1375. wchar_t * src;
  1376. wchar_t *dest;
  1377. src = String1;
  1378. dest = szFilterW;
  1379. while (*src != L'\0')
  1380. {
  1381. *dest = *src;
  1382. src ++;
  1383. dest ++;
  1384. }
  1385. src = Pattern1;
  1386. *dest = L'\0';
  1387. ++dest;
  1388. while (*src != L'\0')
  1389. {
  1390. *dest = *src;
  1391. src ++;
  1392. dest ++;
  1393. }
  1394. *dest = L'\0';
  1395. ++dest;
  1396. src = String2;
  1397. while (*src != L'\0')
  1398. {
  1399. *dest = *src;
  1400. src ++;
  1401. dest ++;
  1402. }
  1403. src = Pattern2;
  1404. *dest = L'\0';
  1405. ++dest;
  1406. while (*src != L'\0')
  1407. {
  1408. *dest = *src;
  1409. src ++;
  1410. dest ++;
  1411. }
  1412. *dest = L'\0';
  1413. ++dest;
  1414. *dest = L'\0';
  1415. BOOL Return = FALSE;
  1416. char szFileName[MAX_PATH] = "\0";
  1417. char szDefaultPath[MAX_PATH] = "\0";
  1418. wchar_t szFileNameW [MAX_PATH] = L"\0";
  1419. wchar_t szDefaultPathW[MAX_PATH] = L"\0";
  1420. BOOL bNT4 = FALSE;
  1421. DWORD dwVersion = GetVersion();
  1422. DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  1423. if (dwVersion < 0x80000000)
  1424. {
  1425. if (dwWindowsMajorVersion == 4)
  1426. bNT4 = TRUE;
  1427. }
  1428. CComBSTR RetrievedName = L"";
  1429. hParent = FindWindowExW(NULL,NULL,L"IEFrame",WindowText);
  1430. OPENFILENAMEW ofnw;
  1431. if (!GetWindowsDirectoryW(szDefaultPathW,MAX_PATH))
  1432. {
  1433. Path->vt = VT_BSTR;
  1434. Path->bstrVal = L"";
  1435. return S_OK;
  1436. }
  1437. if (bNT4)
  1438. {
  1439. ofnw.lStructSize = sizeof(OPENFILENAME);
  1440. }
  1441. else
  1442. {
  1443. ofnw.lStructSize = sizeof (OPENFILENAMEW);
  1444. }
  1445. ofnw.lpstrFilter = szFilterW;
  1446. ofnw.lpstrInitialDir = szDefaultPathW;
  1447. ofnw.lpstrFile = szFileNameW;
  1448. ofnw.hInstance = NULL;
  1449. ofnw.hwndOwner = hParent;
  1450. ofnw.lCustData = NULL;
  1451. ofnw.Flags = 0;
  1452. // | OFN_ALLOWMULTISELECT | OFN_EXPLORER ; // - enable to allow multiple selection
  1453. ofnw.lpstrDefExt = L"dmp";
  1454. ofnw.lpstrCustomFilter = NULL;
  1455. ofnw.nMaxFile = MAX_PATH;
  1456. ofnw.lpstrFileTitle = NULL;
  1457. ofnw.lpstrTitle = NULL;
  1458. ofnw.nFileOffset = 0;
  1459. ofnw.nFileExtension = 0;
  1460. ofnw.lpfnHook = NULL;
  1461. ofnw.lpTemplateName = NULL;
  1462. if (!GetOpenFileNameW(&ofnw) )
  1463. {
  1464. Path->vt = VT_BSTR;
  1465. Path->bstrVal = RetrievedName.Detach();
  1466. return S_OK;
  1467. }
  1468. else
  1469. {
  1470. RetrievedName = ofnw.lpstrFile;
  1471. #if _WANT_MULTIPLE_DUMPS_SELECTED_
  1472. LPWSTR szDir, szNextFile;
  1473. szDir = ofnw.lpstrFile;
  1474. szNextFile = wcslen(szDir) + szDir;
  1475. ++szNextFile;
  1476. if (*szNextFile)
  1477. {
  1478. RetrievedName.Append(L"\\");
  1479. RetrievedName.Append(szNextFile);
  1480. szNextFile = wcslen(szNextFile) + szNextFile;
  1481. ++szNextFile;
  1482. }
  1483. while (*szNextFile)
  1484. {
  1485. RetrievedName.Append(L";");
  1486. RetrievedName.Append(szDir);
  1487. RetrievedName.Append(L"\\");
  1488. RetrievedName.Append(szNextFile);
  1489. szNextFile = wcslen(szNextFile) + szNextFile;
  1490. ++szNextFile;
  1491. }
  1492. #endif
  1493. Path->vt = VT_BSTR;
  1494. Path->bstrVal = RetrievedName.Detach();
  1495. }
  1496. return S_OK;;
  1497. }
  1498. STDMETHODIMP COcarptMain::ValidateDump( BSTR *FileName, VARIANT *Result)
  1499. {
  1500. BOOL ReturnValue = false;
  1501. HANDLE hFile;
  1502. wchar_t TempFileName[MAX_PATH];
  1503. if (!InApprovedDomain())
  1504. {
  1505. return E_FAIL;
  1506. }
  1507. //wcscpy(TempFileName,*FileName);
  1508. if (StringCbPrintfW(TempFileName,sizeof TempFileName, L"\"%s\"",*FileName) != S_OK)
  1509. {
  1510. return E_FAIL;
  1511. }
  1512. GetFileHandle(TempFileName, &hFile);
  1513. if (hFile == INVALID_HANDLE_VALUE)
  1514. {
  1515. Result->vt = VT_INT;
  1516. Result->intVal = 1;
  1517. return S_OK;
  1518. }
  1519. DWORD dwSize;
  1520. dwSize = GetFileSize(hFile, NULL);
  1521. DWORD dwBytesRead;
  1522. BYTE buff[40];
  1523. WORD *BuildNum;
  1524. if ( dwSize < 65536 )
  1525. {
  1526. CloseHandle(hFile);
  1527. Result->vt = VT_INT;
  1528. Result->intVal = 1;
  1529. return S_OK;
  1530. }
  1531. if( (dwSize >= 65536) && (dwSize <= 500000) )
  1532. {
  1533. ZeroMemory(buff,sizeof buff);
  1534. if (ReadFile(hFile, buff, 24, &dwBytesRead, NULL))
  1535. {
  1536. if (strncmp ((const char *)buff,"PAGEDU64 ",8)== 0)
  1537. {
  1538. Result->vt = VT_INT;
  1539. Result->intVal = 0;
  1540. }
  1541. else
  1542. {
  1543. if(strncmp((const char *)buff,"PAGEDUMP ",8)==0)
  1544. {
  1545. Result->vt = VT_INT;
  1546. Result->intVal = 0;
  1547. }
  1548. else
  1549. {
  1550. Result->vt = VT_INT;
  1551. Result->intVal = 1;
  1552. }
  1553. }
  1554. CloseHandle(hFile);
  1555. }
  1556. else
  1557. {
  1558. CloseHandle(hFile);
  1559. Result->vt = VT_INT;
  1560. Result->intVal = 1;
  1561. }
  1562. }
  1563. else
  1564. {
  1565. ZeroMemory(buff,sizeof buff);
  1566. if (ReadFile(hFile, buff, 24, &dwBytesRead, NULL))
  1567. {
  1568. CloseHandle(hFile);
  1569. if (strncmp ((const char *)buff,"PAGEDU64 ",8)== 0)
  1570. {
  1571. Result->vt = VT_INT;
  1572. Result->intVal = 0;
  1573. }
  1574. else
  1575. {
  1576. if(strncmp((const char *)buff,"PAGEDUMP ",8)!=0)
  1577. {
  1578. Result->vt = VT_INT;
  1579. Result->intVal = 1;
  1580. }
  1581. else
  1582. {
  1583. BSTR Destination;
  1584. if(ConvertFullDumpInternal(FileName, &Destination))
  1585. {
  1586. // Validate the converted dump
  1587. HANDLE hMiniDump;
  1588. BYTE Stringbuff[256];
  1589. //WORD * BuildNum;
  1590. ZeroMemory(Stringbuff,30);
  1591. if (ValidMiniDump(Destination))
  1592. {
  1593. // add code here to get the OS Build
  1594. GetFileHandle(Destination, &hMiniDump);
  1595. if (hMiniDump != INVALID_HANDLE_VALUE)
  1596. {
  1597. if (ReadFile(hMiniDump,Stringbuff,24,&dwBytesRead,NULL))
  1598. {
  1599. // BuildNum = (WORD*) (Stringbuff + 12);
  1600. Result->vt = VT_INT;
  1601. Result->intVal = 0;
  1602. }
  1603. else
  1604. { // file read failed
  1605. Result->vt = VT_INT;
  1606. Result->intVal = 1;
  1607. }
  1608. CloseHandle(hMiniDump);
  1609. }
  1610. else
  1611. {
  1612. Result->vt = VT_INT;
  1613. Result->intVal = 2;
  1614. }
  1615. }
  1616. else
  1617. {
  1618. Result->vt = VT_INT;
  1619. Result->intVal = 2;
  1620. }
  1621. SysFreeString(Destination);
  1622. }
  1623. else
  1624. {
  1625. Result->vt = VT_INT;
  1626. Result->intVal = 2;
  1627. }
  1628. }
  1629. } // end else
  1630. }// end if
  1631. else
  1632. {
  1633. CloseHandle(hFile);
  1634. Result->vt = VT_INT;
  1635. Result->intVal = 1;
  1636. }
  1637. } // end else
  1638. return S_OK;
  1639. }
  1640. STDMETHODIMP COcarptMain::RetrieveFileContents(BSTR *FileName, VARIANT *pvContents)
  1641. {
  1642. CComBSTR Error = L"";
  1643. CComBSTR HexString = L"";
  1644. DWORD dwBytesRead;
  1645. wchar_t LineBuffer [255]; // Buffer for hex portion of string
  1646. wchar_t AsciiBuffer [255]; // Buffer for Ascii portion of string
  1647. BYTE* nonhexbuffer = NULL; // Raw file buffer.
  1648. BYTE * src = NULL; // Pointer into Raw File Buffer
  1649. wchar_t * dest = NULL; // Pointer into Hex string
  1650. wchar_t * dest2 = NULL; // Pointer into Ascii string
  1651. dest = LineBuffer;
  1652. dest2 = AsciiBuffer;
  1653. wchar_t *Temp2; // Used to copy Ascii string into hex string
  1654. wchar_t HexDigit[4]; // Used to convert the character read to hex
  1655. BYTE Temp ; // Pointer into the buffer read from the file
  1656. char Temp3; // Used to convert the character read to a Unicode Character
  1657. DWORD TotalCount = 0; // Number of bytes processed from the file buffer
  1658. DWORD BytesPerLine = 16; // Number of hex bytes displayed per line
  1659. DWORD ByteCount = 0; // Number of hex bytes processed
  1660. HANDLE hFile;
  1661. BSTR Destination;
  1662. wchar_t PathName[MAX_PATH];
  1663. if (!InApprovedDomain())
  1664. {
  1665. return E_FAIL;
  1666. }
  1667. ZeroMemory(PathName,MAX_PATH);
  1668. // Convert from a bstr to a wchar_t
  1669. if (StringCbPrintfW(PathName,sizeof PathName,L"\"%s\"",*FileName) != S_OK)
  1670. {
  1671. goto ERRORS;
  1672. }
  1673. GetFileHandle(PathName, &hFile);
  1674. //::MessageBoxW(NULL,PathName, L"Loading File",MB_OK);
  1675. if (hFile == INVALID_HANDLE_VALUE)
  1676. {
  1677. //::MessageBoxW(NULL,PathName,L"Failed to get the File handle",NULL);
  1678. pvContents->vt = VT_BSTR;
  1679. pvContents->bstrVal = Error.Detach();
  1680. return S_OK;
  1681. }
  1682. DWORD FileSize = GetFileSize(hFile,NULL); // Size of file in bytes
  1683. if (FileSize > 1000000)
  1684. {
  1685. // Ok We have to convert it
  1686. CloseHandle(hFile);
  1687. if( !ConvertFullDumpInternal(FileName, &Destination))
  1688. {
  1689. pvContents->vt = VT_BSTR;
  1690. pvContents->bstrVal = Error.Detach();
  1691. return S_OK;
  1692. }
  1693. GetFileHandle(Destination, &hFile);
  1694. if (hFile == INVALID_HANDLE_VALUE)
  1695. {
  1696. pvContents->vt = VT_BSTR;
  1697. pvContents->bstrVal = Error.Detach();
  1698. return S_OK;
  1699. }
  1700. FileSize = GetFileSize(hFile,NULL);
  1701. if ( FileSize > 80000)
  1702. {
  1703. pvContents->vt = VT_BSTR;
  1704. pvContents->bstrVal = Error.Detach();
  1705. return S_OK;
  1706. }
  1707. }
  1708. if ( (nonhexbuffer = (BYTE*) malloc (FileSize)) == NULL)
  1709. {
  1710. CloseHandle(hFile);
  1711. pvContents->vt = VT_BSTR;
  1712. pvContents->bstrVal = Error.Detach();
  1713. return S_OK;
  1714. }
  1715. ZeroMemory(nonhexbuffer,sizeof nonhexbuffer);
  1716. if (ReadFile(hFile, nonhexbuffer, FileSize, &dwBytesRead, NULL))
  1717. {
  1718. if (dwBytesRead < 10) // make sure we got something
  1719. {
  1720. if (nonhexbuffer)
  1721. free(nonhexbuffer);
  1722. CloseHandle (hFile);
  1723. pvContents->vt = VT_BSTR;
  1724. pvContents->bstrVal = Error.Detach();
  1725. return S_OK;
  1726. }
  1727. }
  1728. else
  1729. {
  1730. if (nonhexbuffer)
  1731. free(nonhexbuffer);
  1732. CloseHandle (hFile);
  1733. pvContents->vt = VT_BSTR;
  1734. pvContents->bstrVal = Error.Detach();
  1735. return S_OK;
  1736. }
  1737. // clear the buffers
  1738. ZeroMemory(LineBuffer,255);
  1739. ZeroMemory(AsciiBuffer,255);
  1740. src = nonhexbuffer;
  1741. while (TotalCount <= dwBytesRead)
  1742. {
  1743. while (ByteCount < BytesPerLine)
  1744. {
  1745. Temp = *src;
  1746. if (StringCbCopyW ( HexDigit,sizeof HexDigit, L"\0") != S_OK)
  1747. {
  1748. goto ERRORS;
  1749. }
  1750. _itow(Temp,HexDigit,16);
  1751. if (Temp < 16 )
  1752. {
  1753. *dest = L'0';
  1754. ++dest;
  1755. *dest = HexDigit[0];
  1756. ++dest;
  1757. }
  1758. else
  1759. {
  1760. *dest = HexDigit[0];
  1761. ++dest;
  1762. *dest = HexDigit[1];
  1763. ++dest;
  1764. }
  1765. if ( (Temp< 32) || (Temp >126))
  1766. *dest2 = L'.';
  1767. else
  1768. {
  1769. Temp3 = (char) Temp;
  1770. mbtowc (dest2, &Temp3,1);
  1771. }
  1772. if (ByteCount == 7 )
  1773. {
  1774. *dest = L' ';
  1775. ++dest;
  1776. }
  1777. ++dest2;
  1778. ++TotalCount;
  1779. ++ ByteCount;
  1780. ++ src;
  1781. }
  1782. ByteCount = 0;
  1783. // Add 5 spaces to the hex string
  1784. for (int i = 0; i < 5; i++)
  1785. {
  1786. *dest = L' ';
  1787. ++dest;
  1788. }
  1789. // Combine the strings
  1790. Temp2 = AsciiBuffer;
  1791. while( Temp2 != dest2)
  1792. {
  1793. *dest = *Temp2;
  1794. ++dest;
  1795. ++Temp2;
  1796. }
  1797. // add CR-LF combination
  1798. *dest = L'\r';
  1799. ++dest;
  1800. *dest = L'\n';
  1801. ++dest;
  1802. // Null terminate the string
  1803. *dest = L'\0';
  1804. *dest = L'\0';
  1805. // Add the complete strings to the Bstr to be returned.
  1806. HexString += LineBuffer;
  1807. // Clear buffers
  1808. if (StringCbCopyW(AsciiBuffer,sizeof AsciiBuffer,L"\0") != S_OK)
  1809. {
  1810. // Major problem here jump to errors
  1811. goto ERRORS;
  1812. }
  1813. if (StringCbCopyW(LineBuffer,sizeof LineBuffer,L"\0") != S_OK)
  1814. {
  1815. // same as above
  1816. goto ERRORS;
  1817. }
  1818. // Reset the pointers
  1819. dest = LineBuffer;
  1820. dest2 = AsciiBuffer;
  1821. }
  1822. ERRORS:
  1823. if (nonhexbuffer)
  1824. free (nonhexbuffer);
  1825. pvContents->vt = VT_BSTR;
  1826. pvContents->bstrVal = HexString.Detach();
  1827. return S_OK;
  1828. }
  1829. STDMETHODIMP COcarptMain::GetUploadStatus(VARIANT *PercentDone)
  1830. {
  1831. ULONG Done = -1;
  1832. Sleep(200);
  1833. switch (g_UploadStatus)
  1834. {
  1835. case UploadNotStarted:
  1836. Done = 0;
  1837. break;
  1838. case UploadStarted:
  1839. Done = 1;
  1840. break;
  1841. case UploadCompressingFile:
  1842. Done = g_CompressedPercentage;
  1843. break;
  1844. case UploadGettingResponse:
  1845. Done = 0;
  1846. break;
  1847. case UploadCopyingFile:
  1848. case UploadConnecting:
  1849. case UploadTransferInProgress:
  1850. Done = 1;
  1851. if (m_pUploadFile != NULL)
  1852. {
  1853. Done = m_pUploadFile->GetPercentComplete();
  1854. }
  1855. break;
  1856. case UploadSucceded:
  1857. Done = 200;
  1858. break;
  1859. case UploadFailure:
  1860. Done = 300;
  1861. break;
  1862. default:
  1863. Done = 100;
  1864. }
  1865. PercentDone->vt = VT_INT;
  1866. PercentDone->intVal = Done;
  1867. return S_OK;
  1868. }
  1869. STDMETHODIMP COcarptMain::GetUploadResult(VARIANT *UploadResult)
  1870. {
  1871. WCHAR wszUploadRes[MAX_PATH];
  1872. CComBSTR Result = L"";
  1873. switch (g_UploadStatus)
  1874. {
  1875. case UploadCompressingFile:
  1876. Result = _T("Compressing ...");
  1877. break;
  1878. case UploadCopyingFile:
  1879. Result = _T("Preparing files to report ...");
  1880. break;
  1881. case UploadConnecting:
  1882. case UploadTransferInProgress:
  1883. if (m_pUploadFile &&
  1884. m_pUploadFile->GetUploadResult(wszUploadRes, sizeof(wszUploadRes)))
  1885. {
  1886. Result = wszUploadRes;
  1887. } else
  1888. {
  1889. Result = _T("Transfering to server ...");
  1890. }
  1891. break;
  1892. case UploadGettingResponse:
  1893. Result = _T("Getting Response from server");
  1894. break;
  1895. case UploadSucceded:
  1896. m_pUploadFile->GetUploadResult(wszUploadRes, sizeof(wszUploadRes));
  1897. Result = wszUploadRes;
  1898. break;
  1899. default:
  1900. StringCbPrintf(wszUploadRes, sizeof(wszUploadRes),
  1901. _T("Cannot get upload result - error %lx"),
  1902. g_UploadFailureCode);
  1903. Result = wszUploadRes;
  1904. break;
  1905. }
  1906. UploadResult->vt = VT_BSTR;
  1907. UploadResult->bstrVal = Result.Detach();
  1908. return S_OK;
  1909. }
  1910. STDMETHODIMP COcarptMain::CancelUpload(VARIANT *ReturnCode)
  1911. {
  1912. ULONG res=0;
  1913. if (g_UploadStatus == UploadCompressingFile)
  1914. {
  1915. g_CancelCompression = TRUE;
  1916. }
  1917. if (m_pUploadFile != NULL &&
  1918. m_pUploadFile->IsUploadInProgress())
  1919. {
  1920. res = m_pUploadFile->Cancel();
  1921. }
  1922. ReturnCode->vt = VT_INT;
  1923. ReturnCode->intVal = res;
  1924. return S_OK;
  1925. }