Source code of Windows XP (NT5)
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.

1699 lines
52 KiB

  1. ///////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  4. //
  5. // HIGHLITE.CPP : implementation file
  6. //
  7. // by DougO
  8. //
  9. #include "header.h"
  10. #include "hhctrl.h"
  11. #include "strtable.h"
  12. #include "resource.h"
  13. #include "hha_strtable.h"
  14. #include "toc.h"
  15. #include "wwheel.h"
  16. #include "web.h"
  17. #include <shellapi.h>
  18. #include <wininet.h>
  19. #include "urlmon.h"
  20. // #include "stdlib.h"
  21. #include "direct.h"
  22. // #include "io.h"
  23. #include "cdlg.h"
  24. #include "sample.h"
  25. // Used to lock toplevel windows before displaying a dialog.
  26. #include "lockout.h"
  27. #include "urlmon.h"
  28. #include "sampinit.h"
  29. static long GetFreeDiskSpaceInKB(LPSTR pFile);
  30. HRESULT DownloadURL(char *pszURL, char *pszDest);
  31. ///////////////////////////////////////////////////////////
  32. //
  33. // Functions
  34. //
  35. ///////////////////////////////////////////////////////////
  36. //
  37. // ProcessSample
  38. //
  39. BOOL ProcessSample(PCSTR szSFLFilePath,PCSTR szSampleBaseUrl,PCSTR szDialogTitle, CHtmlHelpControl* pCtl, BOOL bCompressed)
  40. {
  41. CSampleDialog SD;
  42. HWND hwnd;
  43. SD.m_bCompressed = bCompressed;
  44. SD.m_pHtmlHelpCtl = pCtl;
  45. strcpy(SD.m_szDialogTitle,szDialogTitle);
  46. strcpy(SD.m_szSmplPath,szSampleBaseUrl);
  47. SetCursor(LoadCursor(NULL,IDC_WAIT));
  48. if(!SD.ParseDatFile((char *)szSFLFilePath))
  49. {
  50. SetCursor(LoadCursor(NULL,IDC_ARROW));
  51. return FALSE;
  52. }
  53. if ( pCtl->m_hwnd )
  54. hwnd = pCtl->m_hwnd;
  55. else
  56. hwnd = GetActiveWindow();
  57. // Disable all of the toplevel application windows, before we bring up the dialog.
  58. CLockOut LockOut ;
  59. LockOut.LockOut(hwnd) ;
  60. if(g_bWinNT5)
  61. {
  62. DialogBoxParamW(_Module.GetResourceInstance(), MAKEINTRESOURCEW(IDD_SAMPLE_DLG), hwnd,
  63. (DLGPROC) SampleDlgProc,(LPARAM)(&SD));
  64. }
  65. else
  66. {
  67. DialogBoxParam(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_SAMPLE_DLG), hwnd,
  68. (DLGPROC) SampleDlgProc,(LPARAM)(&SD));
  69. }
  70. #ifdef _DEBUG
  71. DWORD dw=GetLastError();
  72. dw = dw;
  73. #endif
  74. return TRUE;
  75. }
  76. void GetSamplesDir( LPSTR lpszPath )
  77. {
  78. char szPathname[_MAX_PATH];
  79. char szPath[_MAX_PATH];
  80. char szDrive[_MAX_DRIVE];
  81. GetModuleFileName( 0, szPathname, _MAX_PATH );
  82. _splitpath( szPathname, szDrive, szPath, 0, 0 );
  83. strcpy(lpszPath,szDrive);
  84. strcat(lpszPath,"\\Samples\\");
  85. OemToAnsi(lpszPath,lpszPath);
  86. AnsiLower(lpszPath);
  87. }
  88. CSampleDialog::CSampleDialog()
  89. {
  90. TEXTMETRIC tm;
  91. HDC hDC;
  92. HBITMAP hBM,hBM2;
  93. m_pFirstSample = NULL;
  94. m_bCopyAllSamples = FALSE;
  95. m_szDefSamplePath[0] = 0;
  96. m_szURL[0] = 0;
  97. m_szSmplPath[0] = 0;
  98. m_bCompressed = TRUE;
  99. m_szBaseDir[0] = 0;
  100. m_szOemPath[0] = 0;
  101. m_hJapaneseFont = 0;
  102. m_bSetDefPath = FALSE;
  103. hDC = GetDC(NULL);
  104. GetTextMetrics(hDC,&tm);
  105. m_TextCharWidth = tm.tmMaxCharWidth;
  106. ReleaseDC(NULL,hDC);
  107. InitCommonControls();
  108. m_hImageList = ImageList_Create(16,16,ILC_COLOR4 | ILC_MASK,6,0);
  109. if (m_hImageList)
  110. {
  111. hBM = LoadBitmap(_Module.GetResourceInstance() ,MAKEINTRESOURCE(DISKTREE));
  112. hBM2 = LoadBitmap(_Module.GetResourceInstance() ,MAKEINTRESOURCE(DISKTREEM));
  113. ImageList_Add(m_hImageList,hBM,hBM2);
  114. DeleteObject(hBM);
  115. DeleteObject(hBM2);
  116. }
  117. if (PRIMARYLANGID(GetSystemDefaultLangID()) == LANG_JAPANESE)
  118. {
  119. HDC hDC;
  120. hDC = GetDC(NULL);
  121. if (hDC)
  122. {
  123. LOGFONT lf;
  124. lf.lfHeight = MulDiv(-9,GetDeviceCaps(hDC,LOGPIXELSY),72);
  125. lf.lfWidth = 0;
  126. lf.lfEscapement = 0;
  127. lf.lfOrientation = 0;
  128. lf.lfWeight = FW_NORMAL;
  129. lf.lfItalic = FALSE;
  130. lf.lfUnderline = FALSE;
  131. lf.lfStrikeOut = FALSE;
  132. lf.lfCharSet = SHIFTJIS_CHARSET;
  133. lf.lfOutPrecision = OUT_STRING_PRECIS;
  134. lf.lfClipPrecision = CLIP_STROKE_PRECIS;
  135. lf.lfQuality = DRAFT_QUALITY;
  136. lf.lfPitchAndFamily = FF_MODERN | VARIABLE_PITCH;
  137. strncpy(lf.lfFaceName, "�l�r �o�S�V�b�N", LF_FACESIZE-1);
  138. m_hJapaneseFont= CreateFontIndirect(&lf);
  139. }
  140. }
  141. }
  142. CSampleDialog::~CSampleDialog()
  143. {
  144. SAMPLE_DATA *ps,*qs;
  145. if (m_pFirstSample)
  146. {
  147. for (ps = m_pFirstSample,qs = 0;ps ; )
  148. {
  149. if (ps->pszFileName)
  150. lcFree(ps->pszFileName);
  151. qs = ps;
  152. ps = ps->pNext;
  153. lcFree(qs);
  154. }
  155. m_pFirstSample = NULL;
  156. }
  157. if (m_hImageList)
  158. {
  159. ImageList_Destroy(m_hImageList);
  160. m_hImageList = NULL;
  161. }
  162. }
  163. VOID CSampleDialog::AddSample(SAMPLE_DATA *p)
  164. {
  165. static SAMPLE_DATA *pLast = NULL;
  166. if (!m_pFirstSample)
  167. m_pFirstSample = p;
  168. else
  169. pLast->pNext = p;
  170. pLast = p;
  171. return;
  172. }
  173. VOID CSampleDialog::SetAllFonts(HWND hWnd)
  174. {
  175. HWND hwndT;
  176. for (hwndT = GetWindow(hWnd,GW_CHILD);
  177. hwndT;
  178. hwndT = GetWindow(hwndT,GW_HWNDNEXT))
  179. SendMessage(hwndT, WM_SETFONT, (WPARAM)_Resource.GetUIFont(), 0L);
  180. }
  181. BOOL CSampleDialog::ParseDatFile(char *pszSFLFile)
  182. {
  183. SAMPLE_DATA * pNew;
  184. char szDefaultDir[MAX_PATH], szSampleDir[MAX_PATH];
  185. LPSTR pszFileKeys, pszTemp;
  186. BOOL bRet = FALSE;
  187. if(!m_bCompressed)
  188. {
  189. if(!GetPrivateProfileString("options","SampleDir","",szSampleDir,sizeof(szSampleDir),pszSFLFile))
  190. {
  191. return FALSE;
  192. }
  193. else
  194. {
  195. if(szSampleDir[0])
  196. CatPath(m_szSmplPath,szSampleDir);
  197. else
  198. return FALSE;
  199. }
  200. }
  201. if(!GetPrivateProfileString("options","DefaultPath","",szDefaultDir,sizeof(szDefaultDir),pszSFLFile))
  202. {
  203. // no DefaultDirectory set, use a default
  204. //
  205. strcpy(m_szDefSamplePath,"sample");
  206. }
  207. else
  208. {
  209. char *pBuffer = szDefaultDir;
  210. // removing leading white space
  211. //
  212. while(*pBuffer && isspace(*(unsigned char*)pBuffer))
  213. pBuffer = CharNext(pBuffer);
  214. // copy the path
  215. //
  216. strcpy(m_szDefSamplePath,pBuffer);
  217. pBuffer = szDefaultDir;
  218. // remove trailing white space
  219. //
  220. while(*pBuffer && !isspace(*(unsigned char*)pBuffer))
  221. pBuffer = CharNext(pBuffer);
  222. *pBuffer = 0;
  223. }
  224. // Get the list of sample files. Compute an appropiate buffer size based upon the size of the .SFL file.
  225. //
  226. WIN32_FIND_DATA file;
  227. if ( FindFirstFile(pszSFLFile, &file) == INVALID_HANDLE_VALUE )
  228. return FALSE;
  229. pszFileKeys = (LPSTR)lcMalloc(file.nFileSizeLow);
  230. if(!GetPrivateProfileString("files", NULL,"", pszFileKeys, file.nFileSizeLow, pszSFLFile))
  231. goto cleanup;
  232. pszTemp = pszFileKeys;
  233. //
  234. // parse each file entry
  235. //
  236. while(*pszTemp)
  237. {
  238. char szFlag[10];
  239. pNew = (SAMPLE_DATA*) lcMalloc(sizeof(SAMPLE_DATA));
  240. if (!pNew)
  241. {
  242. goto cleanup;
  243. }
  244. memset(pNew,0,sizeof(SAMPLE_DATA));
  245. szFlag[0] = 0;
  246. if(!GetPrivateProfileString("files",pszTemp,"",szFlag,sizeof(szFlag),pszSFLFile))
  247. pNew->iFlags = 0;
  248. else
  249. {
  250. char *pBuffer = szFlag;
  251. while(*pBuffer && isspace(*(unsigned char*)pBuffer))
  252. pBuffer= CharNext(pBuffer);
  253. if(*pBuffer == '1')
  254. pNew->iFlags = 1;
  255. else if(*pBuffer == '2')
  256. pNew->iFlags = 2;
  257. else
  258. pNew->iFlags = 0;
  259. }
  260. pNew->pszFileName = lcStrDup(pszTemp);
  261. AddSample(pNew);
  262. while(*pszTemp++)
  263. ;
  264. }
  265. bRet = TRUE;
  266. cleanup:
  267. lcFree(pszFileKeys);
  268. return bRet;
  269. }
  270. UINT GetOneSel(HWND hWnd, BOOL fAny)
  271. {
  272. UINT i,c,s;
  273. s = (UINT) LB_ERR;
  274. c = (UINT) SendMessage(hWnd,LB_GETCOUNT,0,0L);
  275. if (c == (UINT)LB_ERR)
  276. return((UINT)LB_ERR);
  277. for (i = 0; i< c; i++)
  278. {
  279. if (SendMessage(hWnd,LB_GETSEL,i,0L))
  280. {
  281. if (fAny)
  282. return(i);
  283. if (s == (UINT)LB_ERR)
  284. s = i;
  285. else
  286. return(UINT)LB_ERR;
  287. }
  288. }
  289. return(s);
  290. }
  291. void ECSelect(HWND hWnd, WORD id, INT type)
  292. {
  293. WPARAM wParam;
  294. LPARAM lParam;
  295. if (id)
  296. hWnd = GetDlgItem(hWnd,id);
  297. if (type)
  298. lParam = 0x7FFFFFFF;
  299. else
  300. lParam = 0;
  301. if (type == 2)
  302. wParam = 0x7FFFFFFF;
  303. else
  304. wParam = 0;
  305. SendMessage(hWnd,EM_SETSEL,wParam,lParam);
  306. }
  307. void BackSlashToSlash(char *sz)
  308. {
  309. char *p;
  310. for (p = sz; *p ; p = CharNext(p)) //bugbug DBCS?
  311. {
  312. if (*p == '\\')
  313. *p = '/';
  314. }
  315. }
  316. INT_PTR SampleCopyProcStub(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  317. {
  318. CSampleDialog *pSD;
  319. pSD = (CSampleDialog *) GetWindowLongPtr(hWnd,GWLP_USERDATA);
  320. if (pSD)
  321. return (INT_PTR)(pSD->SampleCopyProc(hWnd,uiMsg,wParam,lParam));
  322. switch (uiMsg)
  323. {
  324. case WM_INITDIALOG:
  325. SetWindowLongPtr(hWnd,GWLP_USERDATA,lParam);
  326. pSD = (CSampleDialog *)lParam;
  327. return (INT_PTR)(pSD->SampleCopyProc(hWnd,uiMsg,wParam,lParam));
  328. default:
  329. return (INT_PTR)(FALSE);
  330. }
  331. return (INT_PTR)(TRUE);
  332. }
  333. void CSampleDialog::FillDrives(HWND hWnd)
  334. {
  335. INT i,k;
  336. DWORD dw;
  337. char szDrive[10];
  338. char szTempDrive[] = "A:\\";
  339. char szVolumeLabel[128];
  340. UINT errmode = SetErrorMode(SEM_FAILCRITICALERRORS);
  341. SendMessage(hWnd,CB_SETEXTENDEDUI,TRUE,0);
  342. for (i = 0;i < 26 ;i++ )
  343. {
  344. m_szDrive[0] = i + 'A';
  345. m_szDrive[1] = ':';
  346. m_szDrive[2] = 0;
  347. szTempDrive[0] = i+'A';
  348. switch(GetDriveType(szTempDrive))
  349. {
  350. case DRIVE_CDROM:
  351. case DRIVE_RAMDISK:
  352. case DRIVE_FIXED:
  353. m_drivetypes[i] = 3;
  354. m_szDrive[0] = 'A' + i;
  355. strcat(m_szDrive,"\\*.*");
  356. szVolumeLabel[0] = 0;
  357. GetVolumeInformation(szTempDrive,szVolumeLabel,128,NULL,NULL,
  358. NULL,NULL,0);
  359. if (!szTempDrive[0])
  360. m_szDrive[2] = 0;
  361. else
  362. {
  363. m_szDrive[2] = ' ';
  364. m_szDrive[3] = '[';
  365. strcpy(m_szDrive + 4, szVolumeLabel);
  366. strcat(m_szDrive,"]");
  367. }
  368. break;
  369. case DRIVE_REMOVABLE:
  370. m_drivetypes[i] = 4;
  371. break;
  372. case DRIVE_REMOTE:
  373. strcpy(szDrive,m_szDrive);
  374. m_drivetypes[i] = 5;
  375. k = 64;
  376. m_szDrive[2] = ' ';
  377. m_szDrive[3] = 0;
  378. dw = sizeof(szVolumeLabel);
  379. WNetGetConnection(szDrive,szVolumeLabel,&dw);
  380. strcat(m_szDrive,szVolumeLabel);
  381. k = (INT)dw;
  382. break;
  383. default:
  384. m_drivetypes[i] = 0;
  385. break;
  386. }
  387. OemToAnsi(m_szDrive,m_szDrive);
  388. AnsiLower(m_szDrive);
  389. if (m_drivetypes[i])
  390. k = (INT)SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)(LPSTR)m_szDrive);
  391. if (i + 'a' == m_szDir[0])
  392. SendMessage(hWnd,CB_SETCURSEL,k,0L);
  393. }
  394. SetErrorMode(errmode);
  395. }
  396. BOOL SampleDlgProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  397. {
  398. HWND hWndLB = GetDlgItem(hWnd,IDC_SAMPLE_LB);
  399. BOOL bCopyAll = FALSE;
  400. CSampleDialog * pSD;
  401. pSD = (CSampleDialog*) GetWindowLongPtr(hWnd,GWLP_USERDATA);
  402. if (pSD)
  403. return (pSD->SampleDlgProc(hWnd,uiMsg,wParam,lParam));
  404. switch (uiMsg)
  405. {
  406. case WM_INITDIALOG:
  407. SetWindowLongPtr(hWnd,GWLP_USERDATA,lParam);
  408. pSD = (CSampleDialog*) lParam;
  409. return(pSD->SampleDlgProc(hWnd,uiMsg,wParam,lParam));
  410. default:
  411. return(FALSE);
  412. }
  413. return(TRUE);
  414. }
  415. void CSampleDialog::FillDirs(HWND hWnd, HWND hWndStatic)
  416. {
  417. LPSTR lp, lpDir, p;
  418. char szDirName[MAX_PATHLEN * 2],szDirT[MAX_PATHLEN * 2],szAnsi[MAX_PATHLEN * 2];
  419. char szTmp[MAX_PATHLEN * 2], *pOem;
  420. WORD iDir;
  421. int i,t;
  422. BOOL fResetOemPtr;
  423. WIN32_FIND_DATA lpFD;
  424. HANDLE hSearch;
  425. int length = 0,length2 = 0,index;
  426. HDC hDC = NULL;
  427. SIZE size;
  428. RECT rc;
  429. hDC = GetDC(hWnd);
  430. GetWindowRect(hWnd,&rc);
  431. SendMessage(hWnd,WM_SETREDRAW,FALSE,0L);
  432. index = (int)SendMessage(hWnd,LB_GETCOUNT,0,0L);
  433. for (i = 0; i< index;i++)
  434. {
  435. p = (char*)SendMessage(hWnd,LB_GETITEMDATA,i,0L);
  436. if (p)
  437. lcFree(p);
  438. }
  439. SendMessage(hWnd,LB_RESETCONTENT,0,0L);
  440. OemToAnsi(m_szDir,szAnsi);
  441. SetWindowText(hWndStatic,szAnsi);
  442. strcpy(m_szOemPath,m_szDir);
  443. ASSERT(strlen(m_szOemPath) < sizeof(m_szOemPath));
  444. ASSERT(strlen(m_szDir) < sizeof(m_szDir));
  445. BOOL bAnsi = AreFileApisANSI();
  446. SetFileApisToOEM();
  447. lp = m_szOemPath + strlen(m_szOemPath);
  448. p = CharPrev(m_szOemPath,lp);
  449. if (*p != '\\')
  450. {
  451. *lp = '\\';
  452. lp = CharNext(lp);
  453. *lp = 0;
  454. }
  455. strcat(m_szOemPath,"*.*");
  456. for (hSearch = FindFirstFile(m_szOemPath,&lpFD), t = 1 ;
  457. hSearch != INVALID_HANDLE_VALUE && t;
  458. t = FindNextFile(hSearch,&lpFD))
  459. {
  460. if (!(lpFD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  461. continue;
  462. if (lpFD.cFileName[0] == '.')
  463. continue;
  464. strcpy(szTmp,lpFD.cFileName);
  465. OemToAnsi(lpFD.cFileName,lpFD.cFileName);
  466. AnsiLower(lpFD.cFileName);
  467. for (t = 0;
  468. SendMessage(hWnd,LB_GETTEXT,t,(DWORD_PTR)(LPSTR)szDirT) != LB_ERR;
  469. t++)
  470. {
  471. if (_strcmpi(lpFD.cFileName,szDirT) < 0)
  472. break;
  473. }
  474. SendMessage(hWnd,LB_INSERTSTRING,t,(DWORD_PTR)(LPSTR)lpFD.cFileName);
  475. p = (char*)lcMalloc(strlen(szTmp) + 1);
  476. if (!p)
  477. {
  478. }
  479. memset(p,0,strlen(szTmp) + 1);
  480. memcpy(p,szTmp,strlen(szTmp));
  481. SendMessage(hWnd,LB_SETITEMDATA,t,(LPARAM) p);
  482. GetTextExtentPoint32(hDC,lpFD.cFileName,(int)strlen(lpFD.cFileName),&size);
  483. if (size.cx > length)
  484. length = size.cx;
  485. }
  486. *lp = 0;
  487. //
  488. // Note last component is *.*... we don't want it anyway
  489. //
  490. // Parse up the current string into dir components and add to
  491. // list box.
  492. fResetOemPtr = FALSE;
  493. OemToAnsi(m_szOemPath,szAnsi);
  494. for (iDir = 0, lp = szAnsi, lpDir = szDirName, pOem = m_szOemPath ;
  495. *lp;)
  496. {
  497. if (fResetOemPtr == TRUE)
  498. {
  499. pOem += strlen(szDirName);
  500. if (*pOem == '\\')
  501. pOem = CharNext(pOem);
  502. fResetOemPtr = FALSE;
  503. }
  504. if (*lp == '\\')
  505. {
  506. if (!iDir)
  507. *lpDir++ = '\\';
  508. if (lpDir != szDirName)
  509. {
  510. *lpDir = 0;
  511. SendMessage(hWnd,LB_INSERTSTRING,iDir,(DWORD_PTR)(LPSTR)szDirName);
  512. p = (char*)lcMalloc(strlen(szDirName) + 1);
  513. if (!p)
  514. {
  515. }
  516. memset(p,0,strlen(szDirName) + 1);
  517. memcpy(p,pOem,strlen(szDirName));
  518. SendMessage(hWnd,LB_SETITEMDATA,iDir,(LPARAM) p);
  519. GetTextExtentPoint32(hDC,szDirName,(int)strlen(szDirName),&size);
  520. if (size.cx + (iDir * (m_TextCharWidth/2)) + 1 + 16> length2)
  521. {
  522. length2 = size.cx + (iDir * (m_TextCharWidth/2)) + 1 + 16;
  523. }
  524. lpDir = szDirName;
  525. iDir++;
  526. fResetOemPtr = TRUE;
  527. lp++;
  528. }
  529. }
  530. else
  531. {
  532. if (IsDBCSLeadByte(*lp))
  533. *lpDir++ = *lp++;
  534. *lpDir++ = *lp++;
  535. }
  536. }
  537. // Determine if we're going to need an HScrollbar. Figure out the length
  538. // of the string with the indenting and the folder icon (16 pels)
  539. length += iDir*(m_TextCharWidth/2) + 1 + 16;
  540. if (length2 > length)
  541. length = length2;
  542. SendMessage(hWnd,LB_SETHORIZONTALEXTENT,length,0L);
  543. if (rc.right - rc.left <= length)
  544. {
  545. ShowScrollBar(hWnd,SB_HORZ,TRUE);
  546. }
  547. else
  548. ShowScrollBar(hWnd,SB_HORZ,FALSE);
  549. m_iDir = iDir - 1;
  550. SendMessage(hWnd,LB_SETCURSEL,m_iDir,0L);
  551. SendMessage(hWnd,WM_SETREDRAW,TRUE,0L);
  552. InvalidateRect(hWnd,NULL,TRUE);
  553. ReleaseDC(hWnd,hDC);
  554. if(bAnsi)
  555. SetFileApisToANSI();
  556. }
  557. void CSampleDialog::SelectDrive(HWND hWnd)
  558. {
  559. int i;
  560. char szDrive[80];
  561. i = (int)SendMessage(hWnd,CB_GETCURSEL,0,0L);
  562. if (i == LB_ERR)
  563. return;
  564. SendMessage(hWnd,CB_GETLBTEXT,i,(DWORD_PTR)(LPSTR)szDrive);
  565. AnsiLower(szDrive);
  566. i = szDrive[0] - 'a' + 1;
  567. _getdcwd(i,m_szDir,sizeof(m_szDir));
  568. OemToAnsi(m_szDir,m_szDir);
  569. AnsiLower(m_szDir);
  570. }
  571. void CSampleDialog::SelectDirectory(HWND hWnd)
  572. {
  573. WORD i, iSub;
  574. WORD c;
  575. LPSTR lp;
  576. TCHAR *p;
  577. iSub = 0;
  578. c = (WORD)SendMessage(hWnd,LB_GETCURSEL,0,0L);
  579. if (c > m_iDir)
  580. {
  581. iSub = c;
  582. c = (WORD)m_iDir;
  583. }
  584. for (lp = m_szDir,i = 0; i <= c ;i++ )
  585. {
  586. if ( i > 1)
  587. {
  588. *lp++ = '\\';
  589. }
  590. p = (char*) SendMessage(hWnd,LB_GETITEMDATA,i,0L);
  591. if (!p)
  592. SendMessage(hWnd,LB_GETTEXT,i,(DWORD_PTR)lp);
  593. else
  594. strcpy(lp,p);
  595. lp += strlen(lp);
  596. }
  597. if (iSub)
  598. {
  599. if (i > 1)
  600. *lp++ = '\\';
  601. p = (char*) SendMessage(hWnd,LB_GETITEMDATA,iSub,0L);
  602. strcpy(lp,p);
  603. }
  604. }
  605. BOOL CSampleDialog::SampleDlgProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  606. {
  607. HWND hWndLB = GetDlgItem(hWnd,IDC_SAMPLE_LB);
  608. SAMPLE_DATA *p;
  609. int i,cItems,iCurSel;
  610. UINT_PTR s;
  611. char szTmp[MAX_PATH],szMsg[256],szURL[256];
  612. WCHAR wszTmp[MAX_PATH],wszMsg[256];
  613. BOOL bCopyAll = FALSE;
  614. char *pStart,*pTemp;
  615. HRESULT hr;
  616. SIZE size;
  617. HDC hDC;
  618. INT width = 0;
  619. BOOL fHorz = FALSE;
  620. RECT rc;
  621. switch (uiMsg)
  622. {
  623. case WM_INITDIALOG:
  624. //
  625. // Get the right fonts selected into the right controls on the dialog...
  626. //
  627. SetAllFonts(hWnd); // First the UI font...
  628. SendDlgItemMessage(hWnd, IDC_SAMPLE_LB, WM_SETFONT, (WPARAM)m_pHtmlHelpCtl->GetContentFont(), FALSE); // Now, Content font...
  629. //
  630. // set the dialog caption text
  631. //
  632. // SetWindowText(hWnd,m_szDialogTitle);
  633. GetWindowRect(hWndLB,&rc);
  634. hDC = GetDC(hWndLB);
  635. SendDlgItemMessage(hWnd,IDC_SAMPLE_LB,LB_RESETCONTENT,0,(LPARAM)0);
  636. for (p = m_pFirstSample;p;p = p->pNext)
  637. {
  638. i = (int)SendDlgItemMessage(hWnd,IDC_SAMPLE_LB,LB_ADDSTRING,0,(LPARAM)p->pszFileName);
  639. SendDlgItemMessage(hWnd,IDC_SAMPLE_LB,LB_SETITEMDATA,i,(LPARAM)p);
  640. GetTextExtentPoint32(hDC,p->pszFileName,(int)strlen(p->pszFileName),&size);
  641. if (size.cx > width)
  642. width = size.cx;
  643. }
  644. if (rc.right - rc.left <= width)
  645. SendMessage(hWndLB,LB_SETHORIZONTALEXTENT,width,0L);
  646. else
  647. ShowScrollBar(hWndLB,SB_HORZ,FALSE);
  648. ReleaseDC(hWndLB,hDC);
  649. hDC = NULL;
  650. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_VIEW),FALSE);
  651. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_COPY),FALSE);
  652. SetCursor(LoadCursor(NULL,IDC_ARROW));
  653. break;
  654. case WM_CLOSE:
  655. PostMessage(hWnd, WM_COMMAND,IDCANCEL,0L);
  656. break;
  657. case WM_COMMAND:
  658. switch(LOWORD(wParam))
  659. {
  660. case IDCANCEL:
  661. case IDOK:
  662. EndDialog(hWnd,0);
  663. break;
  664. case IDC_SAMPLE_LB:
  665. if (HIWORD(wParam) == LBN_SELCHANGE)
  666. {
  667. if ( ((iCurSel = GetOneSel(hWndLB,FALSE)) == LB_ERR))
  668. {
  669. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_VIEW),FALSE);
  670. }
  671. else
  672. {
  673. SendMessage(hWndLB,LB_GETTEXT,iCurSel,(LPARAM)(LPSTR)szTmp);
  674. p = (SAMPLE_DATA*) SendMessage(hWndLB,LB_GETITEMDATA,
  675. iCurSel,(LPARAM)0);
  676. if (p->iFlags & SAMP_VIEWABLE)
  677. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_VIEW),TRUE);
  678. else
  679. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_VIEW),FALSE);
  680. }
  681. if (GetOneSel(hWndLB,TRUE) == LB_ERR)
  682. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_COPY),FALSE);
  683. else
  684. EnableWindow(GetDlgItem(hWnd,IDC_SAMPLE_COPY),TRUE);
  685. break;
  686. }
  687. else if (HIWORD(wParam) != LBN_DBLCLK)
  688. break;
  689. // fall through intended
  690. case IDC_SAMPLE_VIEW:
  691. if ( ((iCurSel = GetOneSel(hWndLB,FALSE)) != LB_ERR) )
  692. SendMessage(hWndLB,LB_GETTEXT,iCurSel,(LPARAM)(LPSTR)szTmp);
  693. GetTempPath(sizeof(szTmp),szTmp);
  694. // copy it first.
  695. i = (int)SendMessage(hWndLB,LB_GETCURSEL,0,0);
  696. if (i == LB_ERR)
  697. {
  698. if(g_bWinNT5)
  699. {
  700. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszTmp,sizeof(wszTmp));
  701. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,wszMsg,sizeof(wszMsg));
  702. MessageBoxW(hWnd,wszMsg,wszTmp,MB_OK);
  703. }
  704. else
  705. {
  706. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szTmp,sizeof(szTmp));
  707. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,szMsg,sizeof(szMsg));
  708. MessageBox(hWnd,szMsg,szTmp,MB_OK);
  709. }
  710. break;
  711. }
  712. p = (SAMPLE_DATA*) SendMessage(hWndLB,LB_GETITEMDATA,i,
  713. (LPARAM)0);
  714. // wsprintf(szURL,"%s%s",m_szSmplPath,p->pszFileName);
  715. strcpy(szURL,m_szSmplPath);
  716. CatPath(szURL,p->pszFileName);
  717. if (m_bCompressed)
  718. BackSlashToSlash(szURL);
  719. pStart = p->pszFileName;
  720. pTemp = p->pszFileName;
  721. while(*pTemp)
  722. {
  723. if(*pTemp == '\\')
  724. pStart = pTemp+1;
  725. pTemp = CharNext(pTemp);
  726. }
  727. CatPath(szTmp,pStart);
  728. // BUGBUG - insert code here to view uncompressed samples
  729. if (m_bCompressed)
  730. hr = DownloadURL(szURL,szTmp);
  731. else
  732. CopyFile(szURL,szTmp,FALSE);
  733. if (FAILED(hr))
  734. {
  735. if(g_bWinNT5)
  736. {
  737. DeleteFile(szTmp);
  738. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszTmp,sizeof(wszTmp));
  739. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,wszMsg,sizeof(wszMsg));
  740. MessageBoxW(hWnd,wszMsg,wszTmp,MB_OK|MB_ICONEXCLAMATION);
  741. }
  742. else
  743. {
  744. DeleteFile(szTmp);
  745. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szTmp,sizeof(szTmp));
  746. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,szMsg,sizeof(szMsg));
  747. MessageBox(hWnd,szMsg,szTmp,MB_OK|MB_ICONEXCLAMATION);
  748. }
  749. break;
  750. }
  751. // View the file
  752. //
  753. char szBuffer[MAX_PATH];
  754. wsprintf(szBuffer, "notepad %s", szTmp);
  755. WinExec(szBuffer,SW_SHOW);
  756. if (FAILED(hr))
  757. {
  758. if(g_bWinNT5)
  759. {
  760. DeleteFile(szTmp);
  761. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszTmp,sizeof(wszTmp));
  762. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_VIEW_ERRORS,wszMsg,sizeof(wszMsg));
  763. MessageBoxW(hWnd,wszMsg,wszTmp,MB_OK|MB_ICONEXCLAMATION);
  764. }
  765. else
  766. {
  767. DeleteFile(szTmp);
  768. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szTmp,sizeof(szTmp));
  769. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_VIEW_ERRORS,szMsg,sizeof(szMsg));
  770. MessageBox(hWnd,szMsg,szTmp,MB_OK|MB_ICONEXCLAMATION);
  771. }
  772. }
  773. break;
  774. case IDC_SAMPLE_COPYALL:
  775. m_bCopyAllSamples = TRUE;
  776. // fall through intended
  777. case IDC_SAMPLE_COPY:
  778. cItems = (int)SendMessage(hWndLB,LB_GETCOUNT,0,0);
  779. for (i = 0; i < cItems ;i++ )
  780. {
  781. p = (SAMPLE_DATA *) SendDlgItemMessage(hWnd,IDC_SAMPLE_LB,
  782. LB_GETITEMDATA,i,(LPARAM)0);
  783. s = (int)SendMessage(hWndLB, LB_GETSEL,i,0);
  784. if (s != 0 && s != LB_ERR)
  785. p->bCopy = TRUE;
  786. else
  787. p->bCopy = FALSE;
  788. }
  789. // Disable all of the toplevel application windows, before we bring up the dialog.
  790. CLockOut LockOut ;
  791. LockOut.LockOut(hWnd) ;
  792. // Display dialog.
  793. if(g_bWinNT5)
  794. {
  795. s = DialogBoxParamW(_Module.GetResourceInstance(), MAKEINTRESOURCEW(IDD_SAMPLE_COPY_DLG),
  796. hWnd,(DLGPROC)SampleCopyProcStub,(LPARAM)this);
  797. }
  798. else
  799. {
  800. s = DialogBoxParam(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_SAMPLE_COPY_DLG),
  801. hWnd,(DLGPROC)SampleCopyProcStub,(LPARAM)this);
  802. }
  803. // Enable all of the windows which we disabled.
  804. LockOut.Unlock() ;
  805. if (s == SAMPLE_COPY_ERRORS)
  806. {
  807. if(g_bWinNT5)
  808. {
  809. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszTmp,sizeof(wszTmp));
  810. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,wszMsg,sizeof(wszMsg));
  811. MessageBoxW(hWnd,wszMsg,wszTmp,MB_OK);
  812. }
  813. else
  814. {
  815. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szTmp,sizeof(szTmp));
  816. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_ERRORS,szMsg,sizeof(szMsg));
  817. MessageBox(hWnd,szMsg,szTmp,MB_OK);
  818. }
  819. }
  820. else if (s == SAMPLE_COPY_SUCCESS)
  821. {
  822. if(g_bWinNT5)
  823. {
  824. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszTmp,sizeof(wszTmp));
  825. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_COMPLETE,wszMsg,sizeof(wszMsg));
  826. MessageBoxW(hWnd,wszMsg,wszTmp,MB_OK);
  827. }
  828. else
  829. {
  830. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szTmp,sizeof(szTmp));
  831. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_COPY_COMPLETE,szMsg,sizeof(szMsg));
  832. MessageBox(hWnd,szMsg,szTmp,MB_OK);
  833. }
  834. }
  835. break;
  836. }
  837. break;
  838. default:
  839. return(FALSE);
  840. }
  841. return(TRUE);
  842. }
  843. BOOL CSampleDialog::SampleCopyProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  844. {
  845. HWND hWndParent;
  846. INT i,f;
  847. SAMPLE_DATA *pData;
  848. char szTmp[MAX_PATHLEN],*lp;
  849. char szURL[MAX_PATHLEN];
  850. char szDest[MAX_PATHLEN * 2];
  851. WCHAR wszDest[MAX_PATHLEN * 2];
  852. char szSrc[MAX_PATHLEN];
  853. char szMsg[MAX_PATHLEN * 2],szMsg2[MAX_PATHLEN * 2],szAnsiPath[MAX_PATHLEN * 2];
  854. WCHAR wszMsg[MAX_PATHLEN * 2];
  855. WCHAR wszMsg2[MAX_PATHLEN * 2];
  856. WCHAR wszCaption[32];
  857. char szCaption[32];
  858. unsigned short wszPath[MAX_PATHLEN * 2];
  859. char *q;
  860. HANDLE hFile = INVALID_HANDLE_VALUE;
  861. HRESULT hr;
  862. BOOL bCopyErrors = FALSE;
  863. HCURSOR hOldCursor = NULL;
  864. static BOOL init = 0;
  865. switch (uiMsg)
  866. {
  867. case WM_DRAWITEM:
  868. wParam = ((LPDRAWITEMSTRUCT)lParam)->CtlID;
  869. if (wParam == IDD_DIRLIST)
  870. DirectoryDrawItem((LPDRAWITEMSTRUCT)lParam);
  871. else if (wParam == IDD_DRIVELIST)
  872. DriveDrawItem((LPDRAWITEMSTRUCT)lParam);
  873. break;
  874. case WM_INITDIALOG:
  875. // For some reason, retail builds on NT 4 get 2 INITDIALOG msgs, so
  876. // we'll make sure we only do this once (same is true for SampleDlgProc)
  877. if (init)
  878. break;
  879. SetAllFonts(hWnd);
  880. SendDlgItemMessage(hWnd, IDD_FILELIST, WM_SETFONT, (WPARAM)m_pHtmlHelpCtl->GetContentFont(), FALSE);
  881. hWndParent = GetWindow(hWnd,GW_OWNER);
  882. if (m_bCompressed)
  883. {
  884. if(g_bWinNT5)
  885. {
  886. LoadStringW(_Module.GetResourceInstance() ,IDS_WHY_COPY,wszMsg,sizeof(wszMsg));
  887. SetDlgItemTextW(hWnd,IDD_HELP_TEXT,wszMsg);
  888. }
  889. else
  890. {
  891. LoadString(_Module.GetResourceInstance() ,IDS_WHY_COPY,szMsg,sizeof(szMsg));
  892. SetDlgItemText(hWnd,IDD_HELP_TEXT,szMsg);
  893. }
  894. }
  895. // GetInstall dir and cat it with default sample dest
  896. SetWindowText(GetDlgItem(hWnd,IDD_DIRNAME),m_szDefSamplePath);
  897. for (i = 0; ;i++)
  898. {
  899. if (!m_bCopyAllSamples)
  900. {
  901. f = (INT)SendDlgItemMessage(hWndParent,IDC_SAMPLE_LB,LB_GETSEL,i,0L);
  902. if (f == LB_ERR)
  903. break;
  904. if (!f)
  905. continue;
  906. }
  907. if ( SendDlgItemMessage(hWndParent,IDC_SAMPLE_LB,LB_GETTEXT,i,(LPARAM)szTmp) == LB_ERR)
  908. break;
  909. if (i)
  910. {
  911. ECSelect(hWnd,IDD_FILELIST,2);
  912. SendDlgItemMessage(hWnd,IDD_FILELIST,EM_REPLACESEL,0,(DWORD_PTR)((LPSTR) " "));
  913. }
  914. ECSelect(hWnd,IDD_FILELIST,2);
  915. SendDlgItemMessage(hWnd,IDD_FILELIST,EM_REPLACESEL,0,(DWORD_PTR) ((LPSTR)szTmp));
  916. }
  917. // Get the last known sample dest
  918. if (!m_szBaseDir[0])
  919. {
  920. // set the base dir here - I think this includes the drive letter
  921. //
  922. GetSamplesDir(m_szBaseDir);
  923. }
  924. CharToOem(m_szBaseDir,m_szDir);
  925. if(!m_bSetDefPath)
  926. {
  927. CatPath(m_szDir,m_szDefSamplePath);
  928. m_bSetDefPath = TRUE;
  929. }
  930. SendMessage(GetDlgItem(hWnd,IDD_DIRLIST),LB_SETHORIZONTALEXTENT,0,0L);
  931. FillDrives(GetDlgItem(hWnd,IDD_DRIVELIST));
  932. FillDirs(GetDlgItem(hWnd,IDD_DIRLIST),GetDlgItem(hWnd,IDD_DIRNAME));
  933. init = TRUE;
  934. break;
  935. case WM_CLOSE:
  936. init = FALSE;
  937. PostMessage(hWnd, WM_COMMAND,IDCANCEL,0L);
  938. break;
  939. case WM_COMMAND:
  940. switch (LOWORD(wParam))
  941. {
  942. case IDCANCEL:
  943. m_bCopyAllSamples = FALSE;
  944. EndDialog(hWnd,0);
  945. init = FALSE;
  946. break;
  947. case IDD_DRIVELIST:
  948. if (HIWORD(wParam) != CBN_SELCHANGE)
  949. break;
  950. ChangeDrive:
  951. SelectDrive(GetDlgItem(hWnd,IDD_DRIVELIST));
  952. FillDirs(GetDlgItem(hWnd,IDD_DIRLIST),GetDlgItem(hWnd,
  953. IDD_DIRNAME));
  954. break;
  955. case IDD_DIRLIST:
  956. if (HIWORD(wParam) != LBN_DBLCLK)
  957. break;
  958. ChangeDir:
  959. SelectDirectory(GetDlgItem(hWnd,IDD_DIRLIST));
  960. FillDirs(GetDlgItem(hWnd,IDD_DIRLIST),GetDlgItem(hWnd,
  961. IDD_DIRNAME));
  962. break;
  963. case IDD_NETWORK:
  964. if (WNetConnectionDialog(hWnd,RESOURCETYPE_DISK) == NO_ERROR)
  965. {
  966. SendDlgItemMessage(hWnd,IDD_DRIVELIST,CB_RESETCONTENT,0,0L);
  967. FillDrives(GetDlgItem(hWnd,IDD_DRIVELIST));
  968. }
  969. break;
  970. case IDOK:
  971. init = FALSE;
  972. BOOL bYesToAll = FALSE;
  973. BOOL bCancel = FALSE;
  974. if (GetFocus() == GetDlgItem(hWnd,IDD_DRIVELIST))
  975. goto ChangeDrive;
  976. else if (GetFocus() == GetDlgItem(hWnd,IDD_DIRLIST))
  977. goto ChangeDir;
  978. EnableWindow(GetDlgItem(hWnd,IDOK),FALSE);
  979. GetWindowText(GetDlgItem(hWnd,IDD_DIRNAME),szAnsiPath,sizeof(szAnsiPath));
  980. // Now, check to see if the edit box text is the same as the tree control
  981. // path. If so, use the OEM path we're storing, if not, use the path in
  982. // the edit control. Note, that will be an ansi path
  983. OemToAnsi(m_szOemPath,szTmp);
  984. if (!_strnicmp(szAnsiPath,szTmp,(int)strlen(szAnsiPath)))
  985. {
  986. strcpy(szDest,szTmp);
  987. strcpy(m_szBaseDir,szTmp);
  988. }
  989. else
  990. {
  991. strcpy(m_szDir, szAnsiPath);
  992. strcpy(m_szBaseDir,m_szDir);
  993. }
  994. lp = m_szBaseDir + strlen(m_szBaseDir);
  995. lp = CharPrev(m_szBaseDir,lp);
  996. if (*lp == '\\')
  997. *lp = 0;
  998. ASSERT(strlen(m_szBaseDir) < sizeof(m_szBaseDir));
  999. // Create the base dir if it doesn't exist
  1000. if (IsDirectory(m_szBaseDir) == FALSE)
  1001. {
  1002. if(g_bWinNT5)
  1003. {
  1004. LoadStringW(_Module.GetResourceInstance() ,IDS_CONFIRM_MKDIR,wszMsg,sizeof(wszMsg));
  1005. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszCaption,sizeof(wszCaption));
  1006. WCHAR wszAnsiPath[MAX_PATH];
  1007. MultiByteToWideChar(CP_ACP, 0, szAnsiPath, -1, (PWSTR) wszAnsiPath, sizeof(wszAnsiPath)/2);
  1008. wsprintfW(wszMsg2,wszMsg,wszAnsiPath);
  1009. if (MessageBoxW(hWnd,wszMsg2,wszCaption,MB_OKCANCEL) == IDCANCEL)
  1010. {
  1011. EnableWindow(GetDlgItem(hWnd,IDOK),TRUE);
  1012. return(FALSE);
  1013. }
  1014. }
  1015. else
  1016. {
  1017. LoadString(_Module.GetResourceInstance() ,IDS_CONFIRM_MKDIR,szMsg,sizeof(szMsg));
  1018. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szCaption,sizeof(szCaption));
  1019. wsprintf(szMsg2,szMsg,szAnsiPath);
  1020. if (MessageBox(hWnd,szMsg2,szCaption,MB_OKCANCEL) == IDCANCEL)
  1021. {
  1022. EnableWindow(GetDlgItem(hWnd,IDOK),TRUE);
  1023. return(FALSE);
  1024. }
  1025. }
  1026. }
  1027. hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
  1028. for (pData = m_pFirstSample;pData;pData = pData->pNext)
  1029. {
  1030. if (m_bCopyAllSamples || pData->bCopy)
  1031. {
  1032. // Get a base source location
  1033. strcpy(szSrc,m_szSmplPath);
  1034. CatPath(szSrc,pData->pszFileName);
  1035. strcpy(szURL,szSrc);
  1036. strcpy(szDest,m_szBaseDir);
  1037. CatPath(szDest,pData->pszFileName);
  1038. ASSERT(strlen(szDest) < sizeof(szDest));
  1039. // Create the path to the file
  1040. strcpy(szTmp,szDest);
  1041. q = szTmp + strlen(szTmp) ;
  1042. while (*q != '/' && q > szTmp && *q != '\\')
  1043. q = CharPrev(szTmp,q);
  1044. *q = 0;
  1045. if (CreatePath(szTmp))
  1046. {
  1047. // Directory creation barf.
  1048. bCopyErrors = TRUE;
  1049. m_szBaseDir[0] = 0;
  1050. break;
  1051. }
  1052. if (m_bCompressed)
  1053. BackSlashToSlash(szURL);
  1054. copyagain:
  1055. // check for existing file
  1056. //
  1057. hFile = ::CreateFile(szDest,GENERIC_READ,NULL,NULL,OPEN_EXISTING,
  1058. FILE_ATTRIBUTE_NORMAL,NULL);
  1059. ::CloseHandle(hFile);
  1060. if (hFile != INVALID_HANDLE_VALUE && !bYesToAll)
  1061. {
  1062. // char szString[80],szTemp[MAX_PATH+80],szCaption[50];
  1063. // LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_OVERWRITE,szString,sizeof(szString));
  1064. // LoadString(_Module.GetResourceInstance() ,IDS_FILE_COPY,szCaption,sizeof(szCaption));
  1065. // wsprintf(szTemp,szString,pData->pszFileName);
  1066. COverwriteDlg overwrite(hWnd, pData->pszFileName);
  1067. int Ret = overwrite.DoModal();
  1068. if(Ret == IDNO)
  1069. continue;
  1070. if(Ret == 0)
  1071. {
  1072. bCancel = TRUE;
  1073. goto ack;
  1074. }
  1075. if(Ret == IDRETRY)
  1076. bYesToAll = TRUE;
  1077. }
  1078. if (m_bCompressed)
  1079. hr = DownloadURL(szURL,szDest);
  1080. else
  1081. {
  1082. CopyFile(szURL,szDest,FALSE);
  1083. }
  1084. // URLDownloadToFile is braindead in that it doesn't
  1085. // necessarily return a proper error code, so we gotta
  1086. // check each file to see if it really copied. BOUGS!
  1087. hFile = ::CreateFile(szDest,GENERIC_READ,NULL,NULL,OPEN_EXISTING,
  1088. FILE_ATTRIBUTE_NORMAL,NULL);
  1089. DWORD dwFileSize = 0;
  1090. BOOL bZeroSizeFile = FALSE;
  1091. char szDestDrive[]="C:";
  1092. szDestDrive[0] = szDest[0];
  1093. if(hFile)
  1094. dwFileSize = GetFileSize(hFile,NULL);
  1095. CloseHandle(hFile);
  1096. if(!m_bCompressed)
  1097. {
  1098. HANDLE hFile2 = ::CreateFile(szURL,GENERIC_READ,NULL,NULL,OPEN_EXISTING,
  1099. FILE_ATTRIBUTE_NORMAL,NULL);
  1100. if(hFile2)
  1101. {
  1102. if(!GetFileSize(hFile2,NULL))
  1103. bZeroSizeFile = TRUE;
  1104. CloseHandle(hFile2);
  1105. }
  1106. }
  1107. // take off the read only attributes
  1108. DWORD dwAtr = GetFileAttributes(szDest);
  1109. if (dwAtr != 0xFFFFFFFF)
  1110. {
  1111. dwAtr = dwAtr & (~FILE_ATTRIBUTE_READONLY);
  1112. SetFileAttributes(szDest, dwAtr);
  1113. }
  1114. if (hFile != INVALID_HANDLE_VALUE && !dwFileSize && !bZeroSizeFile)
  1115. {
  1116. LONG lFreeSpace = GetFreeDiskSpaceInKB(szDest);
  1117. if(lFreeSpace < 1024)
  1118. {
  1119. if(g_bWinNT5)
  1120. {
  1121. DeleteFile(szDest);
  1122. WCHAR wszFmt[64];
  1123. LoadStringW(_Module.GetResourceInstance() ,IDS_NO_SPACE,wszFmt,sizeof(wszFmt));
  1124. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszCaption,sizeof(wszCaption));
  1125. WCHAR wszDestDrive[10];
  1126. MultiByteToWideChar(CP_ACP, 0, szDestDrive, -1, (PWSTR) wszDestDrive, 10);
  1127. wsprintfW(wszMsg,wszFmt,wszDestDrive);
  1128. if (MessageBoxW(NULL,wszMsg,wszCaption,MB_YESNO) == IDYES)
  1129. {
  1130. goto copyagain;
  1131. }
  1132. bCopyErrors = TRUE;
  1133. goto ack;
  1134. }
  1135. else
  1136. {
  1137. DeleteFile(szDest);
  1138. char szFmt[64];
  1139. LoadString(_Module.GetResourceInstance() ,IDS_NO_SPACE,szFmt,sizeof(szFmt));
  1140. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szCaption,sizeof(szCaption));
  1141. wsprintf(szMsg,szFmt,szDestDrive);
  1142. if (MessageBox(NULL,szMsg,szCaption,MB_YESNO) == IDYES)
  1143. {
  1144. goto copyagain;
  1145. }
  1146. bCopyErrors = TRUE;
  1147. goto ack;
  1148. }
  1149. }
  1150. }
  1151. else
  1152. {
  1153. if (hFile == INVALID_HANDLE_VALUE)
  1154. {
  1155. DWORD dwErr = GetLastError();
  1156. if (dwErr== ERROR_SHARING_VIOLATION)
  1157. {
  1158. if(g_bWinNT5)
  1159. {
  1160. WCHAR wszFmt[64];
  1161. LoadStringW(_Module.GetResourceInstance() ,IDS_SHARE_VIOLATION,wszFmt,sizeof(wszFmt));
  1162. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszCaption,sizeof(wszCaption));
  1163. wsprintfW(wszMsg,wszFmt,wszDest);
  1164. if (MessageBoxW(NULL,wszMsg,wszCaption,MB_YESNO) == IDYES)
  1165. {
  1166. goto copyagain;
  1167. }
  1168. bCopyErrors = TRUE;
  1169. }
  1170. else
  1171. {
  1172. char szFmt[64];
  1173. LoadString(_Module.GetResourceInstance() ,IDS_SHARE_VIOLATION,szFmt,sizeof(szFmt));
  1174. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szCaption,sizeof(szCaption));
  1175. wsprintf(szMsg,szFmt,szDest);
  1176. if (MessageBox(NULL,szMsg,szCaption,MB_YESNO) == IDYES)
  1177. {
  1178. goto copyagain;
  1179. }
  1180. bCopyErrors = TRUE;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. if(g_bWinNT5)
  1186. {
  1187. bCopyErrors = TRUE;
  1188. WCHAR wszFmt[64];
  1189. LoadStringW(_Module.GetResourceInstance() ,IDS_ERROR_COPYING,wszFmt,sizeof(wszFmt));
  1190. LoadStringW(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,wszCaption,sizeof(wszCaption));
  1191. wsprintfW(wszMsg,wszFmt,wszDest);
  1192. if (MessageBoxW(NULL,wszMsg,wszCaption,MB_YESNO) == IDNO)
  1193. {
  1194. goto ack;
  1195. }
  1196. }
  1197. else
  1198. {
  1199. bCopyErrors = TRUE;
  1200. char szFmt[64];
  1201. LoadString(_Module.GetResourceInstance() ,IDS_ERROR_COPYING,szFmt,sizeof(szFmt));
  1202. LoadString(_Module.GetResourceInstance() ,IDS_SAMPLE_CAPTION,szCaption,sizeof(szCaption));
  1203. wsprintf(szMsg,szFmt,szDest);
  1204. if (MessageBox(NULL,szMsg,szCaption,MB_YESNO) == IDNO)
  1205. {
  1206. goto ack;
  1207. }
  1208. }
  1209. }
  1210. }
  1211. }
  1212. hFile = INVALID_HANDLE_VALUE;
  1213. }
  1214. }
  1215. ack:
  1216. SetCursor(hOldCursor);
  1217. m_bCopyAllSamples = FALSE;
  1218. // if m_szDefSamplePath is \foo\bar and m_szBaseDir is
  1219. // d:\tmp\foo\bar, we only wanna save d:\tmp
  1220. char *p = m_szBaseDir + strlen (m_szBaseDir) -
  1221. strlen(m_szDefSamplePath);
  1222. if (!strcmp(p,m_szDefSamplePath) && *(p-1) == '\\')
  1223. *p = 0;
  1224. if (bCopyErrors)
  1225. EndDialog(hWnd,SAMPLE_COPY_ERRORS);
  1226. else
  1227. {
  1228. MultiByteToWideChar(CP_ACP,0,m_szBaseDir,-1,wszPath,sizeof(wszPath));
  1229. if(bCancel)
  1230. EndDialog(hWnd,SAMPLE_COPY_CANCEL);
  1231. else
  1232. EndDialog(hWnd,SAMPLE_COPY_SUCCESS);
  1233. }
  1234. break;
  1235. }
  1236. break;
  1237. default:
  1238. return(FALSE);
  1239. }
  1240. return(TRUE);
  1241. }
  1242. void CSampleDialog::DirectoryDrawItem(LPDRAWITEMSTRUCT lpdi)
  1243. {
  1244. INT indent;
  1245. INT bitmap;
  1246. INT sel;
  1247. char szDir[MAX_PATHLEN];
  1248. INT cx,cy;
  1249. if (lpdi->itemID > m_iDir)
  1250. {
  1251. indent = m_iDir + 1;
  1252. bitmap = 0;
  1253. }
  1254. else
  1255. {
  1256. indent = lpdi->itemID;
  1257. if (lpdi->itemID == m_iDir)
  1258. bitmap = 1;
  1259. else
  1260. bitmap = 2;
  1261. }
  1262. indent++;
  1263. if (lpdi->itemAction == ODA_FOCUS)
  1264. goto drawfocus;
  1265. if (lpdi->itemState & ODS_SELECTED)
  1266. {
  1267. SetBkColor(lpdi->hDC,GetSysColor(COLOR_HIGHLIGHT));
  1268. SetTextColor(lpdi->hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
  1269. sel = 1;
  1270. }
  1271. else
  1272. {
  1273. SetBkColor(lpdi->hDC,GetSysColor(COLOR_WINDOW));
  1274. SetTextColor(lpdi->hDC,GetSysColor(COLOR_WINDOWTEXT));
  1275. sel = 0;
  1276. }
  1277. ImageList_GetIconSize(m_hImageList,&cx,&cy);
  1278. SendMessage(lpdi->hwndItem,LB_GETTEXT,lpdi->itemID,(DWORD_PTR)(LPSTR)szDir);
  1279. ExtTextOut(lpdi->hDC,
  1280. lpdi->rcItem.left + indent * (m_TextCharWidth/2) + 1 + cy,
  1281. lpdi->rcItem.top + 1, ETO_OPAQUE,&lpdi->rcItem,
  1282. szDir,(int)strlen(szDir),NULL);
  1283. ImageList_Draw(m_hImageList,bitmap,lpdi->hDC,
  1284. lpdi->rcItem.left + ((2*indent)-1) * (m_TextCharWidth/2)/2,
  1285. lpdi->rcItem.top,ILD_TRANSPARENT);
  1286. if (lpdi->itemState & ODS_FOCUS)
  1287. {
  1288. drawfocus:
  1289. DrawFocusRect(lpdi->hDC,&lpdi->rcItem);
  1290. }
  1291. }
  1292. void CSampleDialog::DriveDrawItem(LPDRAWITEMSTRUCT lpdi)
  1293. {
  1294. int drive;
  1295. char szDrive[100];
  1296. int sel;
  1297. INT cx,cy;
  1298. if (lpdi->itemAction & ODA_FOCUS)
  1299. goto focus;
  1300. if (lpdi->itemID == -1)
  1301. return;
  1302. SendMessage(lpdi->hwndItem,CB_GETLBTEXT,lpdi->itemID,(DWORD_PTR)(LPSTR)szDrive);
  1303. drive = (szDrive[0] - 'A') & 31;
  1304. if (lpdi->itemState & ODS_SELECTED)
  1305. {
  1306. SetBkColor(lpdi->hDC,GetSysColor(COLOR_HIGHLIGHT));
  1307. SetTextColor(lpdi->hDC,GetSysColor(COLOR_HIGHLIGHTTEXT));
  1308. sel = 1;
  1309. }
  1310. else
  1311. {
  1312. SetBkColor(lpdi->hDC,GetSysColor(COLOR_WINDOW));
  1313. SetTextColor(lpdi->hDC,GetSysColor(COLOR_WINDOWTEXT));
  1314. sel = 0;
  1315. }
  1316. ImageList_GetIconSize(m_hImageList,&cx,&cy);
  1317. ExtTextOut(lpdi->hDC,
  1318. lpdi->rcItem.left + m_TextCharWidth + cx,
  1319. lpdi->rcItem.top + 1, ETO_OPAQUE,&lpdi->rcItem,
  1320. szDrive,(int)strlen(szDrive),NULL);
  1321. ImageList_Draw(m_hImageList,m_drivetypes[drive],lpdi->hDC,
  1322. lpdi->rcItem.left + m_TextCharWidth /2,
  1323. lpdi->rcItem.top,ILD_TRANSPARENT);
  1324. if (lpdi->itemState & ODS_FOCUS)
  1325. {
  1326. focus:
  1327. DrawFocusRect(lpdi->hDC,&lpdi->rcItem);
  1328. }
  1329. }
  1330. BOOL CSampleDialog::CheckCD(TCHAR *lpFileName)
  1331. {
  1332. return(TRUE);
  1333. }
  1334. BOOL COverwriteDlg::OnBeginOrEnd()
  1335. {
  1336. if (m_fInitializing)
  1337. {
  1338. char szTmp[512],szTmp2[600];
  1339. WCHAR wszTmp[512],wszTmp2[600];
  1340. if(g_bWinNT5)
  1341. {
  1342. LoadStringW(_Module.GetResourceInstance() , IDS_SAMPLE_OVERWRITE, wszTmp, 512);
  1343. WCHAR wszFileName[MAX_PATH];
  1344. MultiByteToWideChar(CP_ACP, 0, pszFileName, -1, (PWSTR) wszFileName, MAX_PATH);
  1345. wsprintfW(wszTmp2,wszTmp,wszFileName);
  1346. ::SendMessageW(::GetDlgItem(m_hWnd,IDC_OVERWRITE_YN), WM_SETFONT, (WPARAM) _Resource.GetUIFont(), FALSE);
  1347. SetWindowTextW(GetDlgItem(IDC_OVERWRITE_YN), wszTmp2);
  1348. }
  1349. else
  1350. {
  1351. LoadString(_Module.GetResourceInstance() , IDS_SAMPLE_OVERWRITE, szTmp, 512);
  1352. wsprintf(szTmp2,szTmp,pszFileName);
  1353. ::SendMessage(::GetDlgItem(m_hWnd,IDC_OVERWRITE_YN), WM_SETFONT, (WPARAM) _Resource.GetUIFont(), FALSE);
  1354. SetWindowText(IDC_OVERWRITE_YN, szTmp2);
  1355. }
  1356. }
  1357. return TRUE;
  1358. }
  1359. // GetFreeDiskSpace: Function to Measure Available Disk Space
  1360. //
  1361. static long GetFreeDiskSpaceInKB(LPSTR pFile)
  1362. {
  1363. DWORD dwFreeClusters, dwBytesPerSector, dwSectorsPerCluster, dwClusters;
  1364. char RootName[MAX_PATH];
  1365. LPSTR ptmp; //required arg
  1366. ULARGE_INTEGER ulA, ulB, ulFreeBytes;
  1367. // need to find path for root directory on drive containing
  1368. // this file.
  1369. GetFullPathName(pFile, sizeof(RootName), RootName, &ptmp);
  1370. // truncate this to the name of the root directory (god how tedious)
  1371. if (RootName[0] == '\\' && RootName[1] == '\\') {
  1372. // path begins with \\server\share\path so skip the first
  1373. // three backslashes
  1374. ptmp = &RootName[2];
  1375. while (*ptmp && (*ptmp != '\\')) {
  1376. ptmp++;
  1377. }
  1378. if (*ptmp) {
  1379. // advance past the third backslash
  1380. ptmp++;
  1381. }
  1382. } else {
  1383. // path must be drv:\path
  1384. ptmp = RootName;
  1385. }
  1386. // find next backslash and put a null after it
  1387. while (*ptmp && (*ptmp != '\\')) {
  1388. ptmp++;
  1389. }
  1390. // found a backslash ?
  1391. if (*ptmp) {
  1392. // skip it and insert null
  1393. ptmp++;
  1394. *ptmp = '\0';
  1395. }
  1396. // the only real way of finding out free disk space is calling
  1397. // GetDiskFreeSpaceExA, but it doesn't exist on Win95
  1398. HINSTANCE h = LoadLibraryA("kernel32.dll");
  1399. if (h) {
  1400. typedef BOOL (WINAPI *MyFunc)(LPCSTR RootName, PULARGE_INTEGER pulA, PULARGE_INTEGER pulB, PULARGE_INTEGER pulFreeBytes);
  1401. MyFunc pfnGetDiskFreeSpaceEx = (MyFunc)GetProcAddress(h, "GetDiskFreeSpaceExA");
  1402. FreeLibrary(h);
  1403. if (pfnGetDiskFreeSpaceEx) {
  1404. if (!pfnGetDiskFreeSpaceEx(RootName, &ulA, &ulB, &ulFreeBytes))
  1405. return -1;
  1406. return (long)(ulFreeBytes.QuadPart / 1024);
  1407. }
  1408. }
  1409. if (!GetDiskFreeSpace(RootName, &dwSectorsPerCluster, &dwBytesPerSector, &dwFreeClusters, &dwClusters))
  1410. return (-1);
  1411. return(MulDiv(dwSectorsPerCluster * dwBytesPerSector, dwFreeClusters,1024));
  1412. }
  1413. HRESULT DownloadURL(char *pszURL, char *pszDest)
  1414. {
  1415. char pszCachedFile[MAX_PATH];
  1416. char Buffer[1024];
  1417. pszCachedFile[0] = 0;
  1418. IStream* pStream;
  1419. // open the stream
  1420. //
  1421. IBindCtx *pbc = NULL;
  1422. CreateBindCtx(0, &pbc);
  1423. IMoniker* pMoniker = NULL;
  1424. OLECHAR wFSName[_MAX_PATH];
  1425. mbstowcs(wFSName, pszURL, strlen(pszURL) + 1);
  1426. IParseDisplayName* pDisplay = NULL;
  1427. HRESULT hr = CoCreateInstance(CLSID_PARSE_URL, NULL, CLSCTX_INPROC_SERVER,
  1428. IID_IParseDisplayName, (void **) &pDisplay);
  1429. if (FAILED(hr))
  1430. return hr;
  1431. ULONG lEaten;
  1432. hr = pDisplay->ParseDisplayName(pbc, wFSName, &lEaten, &pMoniker);
  1433. if (FAILED(hr))
  1434. return hr;
  1435. hr = pMoniker->BindToStorage(pbc, NULL, IID_IStream, (void**) &pStream);
  1436. if (FAILED(hr))
  1437. return hr;
  1438. pMoniker->Release();
  1439. pDisplay->Release();
  1440. pbc->Release();
  1441. ULONG dwBytesRead = 0;
  1442. HANDLE hOutputFile;
  1443. if ((hOutputFile = CreateFile(pszDest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL )) == INVALID_HANDLE_VALUE)
  1444. return E_FAIL;
  1445. do
  1446. {
  1447. DWORD dwBytesWritten = 0;
  1448. Buffer[0] = 0;
  1449. // read from the stream
  1450. //
  1451. hr = pStream->Read( Buffer, sizeof(Buffer), &dwBytesRead);
  1452. if (FAILED(hr))
  1453. return hr;
  1454. // dump the text to the screen for now.
  1455. //
  1456. if(!(FAILED(hr) && dwBytesRead))
  1457. {
  1458. if(!WriteFile(hOutputFile, Buffer, dwBytesRead, &dwBytesWritten, NULL))
  1459. return E_FAIL;
  1460. if(dwBytesRead != dwBytesWritten)
  1461. return E_FAIL;
  1462. }
  1463. } while( SUCCEEDED(hr) && dwBytesRead == sizeof(Buffer));
  1464. CloseHandle(hOutputFile);
  1465. pStream->Release();
  1466. return S_OK;
  1467. }