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.

1713 lines
56 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* WFDLGS2.C - */
  4. /* */
  5. /* More Windows File System Dialog procedures */
  6. /* */
  7. /****************************************************************************/
  8. #include "winfile.h"
  9. #include "lfn.h"
  10. #include "wfcopy.h"
  11. #include "winnet.h"
  12. #include "wnetcaps.h" // WNetGetCaps()
  13. #include "commdlg.h"
  14. CHAR szShellOpenCommand[] = "\\shell\\open\\command";
  15. VOID CheckAttribsDlgButton(HWND hDlg, INT id, DWORD dwAttribs, DWORD dwAttribs3State, DWORD dwAttribsOn);
  16. // Return pointers to various bits of a path.
  17. // ie where the dir name starts, where the filename starts and where the
  18. // params are.
  19. VOID
  20. GetPathInfo(
  21. LPSTR szTemp,
  22. LPSTR *ppDir,
  23. LPSTR *ppFile,
  24. LPSTR *ppPar
  25. )
  26. {
  27. /* strip leading spaces
  28. */
  29. for (*ppDir = szTemp; **ppDir == ' '; (*ppDir)++)
  30. ;
  31. /* locate the parameters
  32. */
  33. for (*ppPar = *ppDir; **ppPar && **ppPar != ' '; (*ppPar)++)
  34. ;
  35. /* locate the start of the filename and the extension.
  36. */
  37. for (*ppFile = *ppPar; *ppFile > *ppDir; --(*ppFile)) {
  38. if (((*ppFile)[-1] == ':') || ((*ppFile)[-1] == '\\'))
  39. break;
  40. }
  41. }
  42. VOID
  43. ValidateExtension(
  44. HWND hDlg
  45. )
  46. {
  47. CHAR szTemp[10];
  48. INT count;
  49. count = GetDlgItemText(hDlg, IDD_EXTENSION, szTemp, sizeof(szTemp));
  50. EnableWindow(GetDlgItem(hDlg, IDD_SEARCHALL), count);
  51. EnableWindow(GetDlgItem(hDlg, IDOK), count);
  52. SendMessage(hDlg, DM_SETDEFID, count ? IDOK : IDCANCEL, 0L);
  53. }
  54. // since LoadString() only reads up to a null we have to mark
  55. // special characters where we want nulls then convert them
  56. // after loading.
  57. VOID
  58. FixupNulls(
  59. LPSTR p
  60. )
  61. {
  62. LPSTR pT;
  63. while (*p) {
  64. if (*p == '#') {
  65. pT = p;
  66. p = AnsiNext(p);
  67. *pT = TEXT('\0');
  68. } else
  69. p = AnsiNext(p);
  70. }
  71. }
  72. // Find the key associated with the given value.
  73. BOOL
  74. ValidFileTypeValue(
  75. LPSTR szVal,
  76. LPSTR szKey,
  77. WORD cbMaxKey
  78. )
  79. {
  80. HKEY hk = NULL;
  81. WORD wTmp;
  82. LONG lTmp;
  83. BOOL retval = FALSE;
  84. CHAR szValTmp[128];
  85. if (RegOpenKey(HKEY_CLASSES_ROOT,szNULL,&hk) != ERROR_SUCCESS)
  86. return(FALSE);
  87. for (wTmp = 0;
  88. RegEnumKey(hk, wTmp, szKey, cbMaxKey) == ERROR_SUCCESS;
  89. wTmp++) {
  90. // Skip things that aren't file type things.
  91. if (szKey[0] == '.')
  92. continue;
  93. lTmp = 128;
  94. if (RegQueryValue(hk, szKey, szValTmp, &lTmp) != ERROR_SUCCESS) {
  95. continue;
  96. }
  97. if (!szValTmp[0])
  98. continue;
  99. if (!lstrcmp(szValTmp, szVal)) {
  100. #ifdef VERBDEBUG
  101. OutputDebugString("wf.vftv: Found a match\n\r");
  102. #endif
  103. // Found a match.
  104. retval = TRUE;
  105. goto ProcExit;
  106. }
  107. }
  108. szKey[0] = TEXT('\0');
  109. ProcExit:
  110. RegCloseKey(hk);
  111. return retval;
  112. }
  113. // Sets the selection of a listbox to that matching the given string.
  114. VOID
  115. SetLBSelection(
  116. HWND hDlg,
  117. INT nDlgItem,
  118. LPSTR sz
  119. )
  120. {
  121. INT iMatch;
  122. iMatch = (INT) SendDlgItemMessage(hDlg, nDlgItem, LB_SELECTSTRING, -1, (LPARAM) sz);
  123. if (iMatch == LB_ERR) {
  124. #ifdef VERBDEBUG
  125. OutputDebugString("wf.sdft: Selection missing from list box.\n\r");
  126. #endif
  127. return;
  128. }
  129. return;
  130. }
  131. // Given an extension (with or without a dot) set the list box or the
  132. // programname fields properly.
  133. VOID
  134. UpdateSelectionOrName(
  135. HWND hDlg
  136. )
  137. {
  138. CHAR szExt[128];
  139. CHAR szTemp[128];
  140. LONG cbTemp;
  141. LPSTR p;
  142. // Get the current extension (after the dot).
  143. GetDlgItemText(hDlg, IDD_EXTENSION, szTemp, sizeof(szTemp));
  144. // Make sure it has a dot.
  145. if (szTemp[0] != '.') {
  146. // Add one.
  147. szExt[0] = '.';
  148. lstrcpy(szExt+1, szTemp);
  149. } else {
  150. // It's already got one.
  151. lstrcpy(szExt, szTemp);
  152. }
  153. cbTemp = sizeof(szTemp);
  154. if (RegQueryValue(HKEY_CLASSES_ROOT,szExt,
  155. szMessage,&cbTemp) == ERROR_SUCCESS) {
  156. if (*szMessage) {
  157. // it's associated with a class
  158. #ifdef VERBDEBUG
  159. OutputDebugString("wf.uson: ");
  160. OutputDebugString(szTemp);
  161. OutputDebugString(" associated with class (");
  162. OutputDebugString(szMessage);
  163. OutputDebugString(")\n\r");
  164. #endif
  165. szTemp[0] = TEXT('\0');
  166. cbTemp = sizeof(szTemp);
  167. RegQueryValue(HKEY_CLASSES_ROOT,szMessage,szTemp,&cbTemp);
  168. #ifdef VERBDEBUG
  169. OutputDebugString("wf.uson: Associated with value (");
  170. OutputDebugString(szTemp);
  171. OutputDebugString(")\n\r");
  172. #endif
  173. // Set the list box selection to the right type.
  174. SetLBSelection(hDlg, IDD_CLASSLIST, szTemp);
  175. // Put the type name in the program name field.
  176. SetDlgItemText(hDlg, IDD_PROGRAMNAME, szTemp);
  177. } else {
  178. // it's not associated with a class, see if it has a
  179. // shell open command and treat it as a command association
  180. lstrcat(szExt,szShellOpenCommand);
  181. cbTemp = sizeof(szTemp);
  182. if (RegQueryValue(HKEY_CLASSES_ROOT, szExt, szTemp, &cbTemp) == ERROR_SUCCESS
  183. && szTemp[0]) {
  184. #ifdef VERBDEBUG
  185. OutputDebugString("wf.uson: It has a shell open command.\n\r");
  186. #endif
  187. goto ProgramAssoc;
  188. } else {
  189. // Put "none" in the field.
  190. #ifdef VERBDEBUG
  191. OutputDebugString("wf.uson: Class set to nothing.\n\r");
  192. #endif
  193. LoadString(hAppInstance, IDS_ASSOCNONE, szTemp, sizeof(szTemp));
  194. SetDlgItemText(hDlg,IDD_PROGRAMNAME, szTemp);
  195. SetLBSelection(hDlg, IDD_CLASSLIST, szTemp);
  196. goto NoAssoc;
  197. }
  198. }
  199. } else if (GetProfileString(szExtensions, szExt+1, szNULL, szTemp, sizeof(szTemp))) {
  200. ProgramAssoc:
  201. /* Remove the "^." bulloney. */
  202. p = szTemp;
  203. while ((*p) && (*p != '^') && (*p != '%'))
  204. p = AnsiNext(p);
  205. *p = TEXT('\0');
  206. p--;
  207. if (*p == ' ')
  208. *p = 0;
  209. SetDlgItemText(hDlg, IDD_PROGRAMNAME, szTemp);
  210. // Set clear the selection.
  211. SendDlgItemMessage(hDlg, IDD_CLASSLIST, LB_SETCURSEL, -1, 0L);
  212. } else {
  213. // Nothing.
  214. #ifdef VERBDEBUG
  215. OutputDebugString("wf.uson: No association.\n\r");
  216. #endif
  217. LoadString(hAppInstance, IDS_ASSOCNONE, szTemp, sizeof(szTemp));
  218. SetDlgItemText(hDlg,IDD_PROGRAMNAME, szTemp);
  219. SetLBSelection(hDlg, IDD_CLASSLIST, szTemp);
  220. }
  221. NoAssoc:
  222. SendDlgItemMessage(hDlg, IDD_PROGRAMNAME, EM_LIMITTEXT, sizeof(szTemp) - 1, 0L);
  223. }
  224. // Given a class key returns the shell\open\command string in szValue
  225. // and the number of chars copied in cbMaxValue. cbMaxValue should
  226. // be initialised to the max siz eof szValue.
  227. VOID
  228. GetAssociatedExe(
  229. LPSTR szKey,
  230. LPSTR szValue,
  231. LONG *plcbValue
  232. )
  233. {
  234. CHAR szTemp[128];
  235. LONG i;
  236. lstrcpy(szTemp, szKey);
  237. lstrcat(szTemp, szShellOpenCommand);
  238. #ifdef VERBDEBUG
  239. OutputDebugString("wf.gae: Key Query ");
  240. OutputDebugString(szTemp);
  241. OutputDebugString("\n\r");
  242. #endif
  243. RegQueryValue(HKEY_CLASSES_ROOT, szTemp, szValue, plcbValue);
  244. // Strip any params.
  245. for (i=0; szValue[i] != TEXT('\0'); i++) {
  246. if (szValue[i] == ' ') {
  247. szValue[i] = TEXT('\0');
  248. break;
  249. }
  250. }}
  251. /*--------------------------------------------------------------------------*/
  252. /* */
  253. /* AssociateDlgProc() - */
  254. /* */
  255. /*--------------------------------------------------------------------------*/
  256. INT_PTR
  257. APIENTRY
  258. AssociateDlgProc(
  259. register HWND hDlg,
  260. UINT wMsg,
  261. WPARAM wParam,
  262. LPARAM lParam
  263. )
  264. {
  265. CHAR szTemp[128];
  266. CHAR szTemp2[128];
  267. HKEY hk = NULL;
  268. switch (wMsg) {
  269. case WM_INITDIALOG:
  270. {
  271. LPSTR p;
  272. register LPSTR pSave;
  273. INT iItem;
  274. CHAR szTemp3[128];
  275. CHAR szTemp4[128];
  276. LONG lcbTemp;
  277. SendDlgItemMessage(hDlg,IDD_CLASSLIST,LB_RESETCONTENT,0,0L);
  278. if (RegOpenKey(HKEY_CLASSES_ROOT,szNULL,&hk) == ERROR_SUCCESS) {
  279. for (wParam = 0;
  280. RegEnumKey(hk, (DWORD)wParam, szTemp, sizeof(szTemp)) == ERROR_SUCCESS;
  281. wParam++) {
  282. // Skip things that aren't file type things.
  283. if (szTemp[0] == '.')
  284. continue;
  285. lParam = 128;
  286. if (RegQueryValue(hk, szTemp, szTemp2, (PLONG)&lParam) != ERROR_SUCCESS) {
  287. continue;
  288. }
  289. // Skip things that aren't relevant ot the shell.
  290. lParam = 128;
  291. lstrcpy(szTemp3, szTemp);
  292. lstrcat(szTemp3, "\\shell");
  293. if (RegQueryValue(hk, szTemp3, szTemp4, (PLONG)&lParam) != ERROR_SUCCESS) {
  294. continue;
  295. }
  296. if (!szTemp2[0])
  297. continue;
  298. // Add on program info
  299. lcbTemp = sizeof(szTemp3);
  300. szTemp3[0] = TEXT('\0');
  301. GetAssociatedExe(szTemp, szTemp3, &lcbTemp);
  302. if (szTemp3[0] != TEXT('\0')) {
  303. lstrcat(szTemp2, " (");
  304. lstrcat(szTemp2, szTemp3);
  305. lstrcat(szTemp2, ")");
  306. }
  307. iItem = (INT)SendDlgItemMessage(hDlg,IDD_CLASSLIST, LB_ADDSTRING,0,(LPARAM)szTemp2);
  308. SendDlgItemMessage(hDlg,IDD_CLASSLIST,LB_SETITEMDATA,iItem,
  309. (DWORD)AddAtom(szTemp));
  310. }
  311. RegCloseKey(hk);
  312. }
  313. // Add the (None) entry at the begining.
  314. LoadString(hAppInstance, IDS_ASSOCNONE, szTemp, sizeof(szTemp));
  315. SendDlgItemMessage(hDlg,IDD_CLASSLIST, LB_INSERTSTRING,0,(LPARAM)szTemp);
  316. lstrcpy(szTitle,".");
  317. /* Make 'p' point to the file's extension. */
  318. pSave = GetSelection(TRUE);
  319. if (pSave) {
  320. p = GetExtension(pSave);
  321. if (!IsProgramFile(pSave)) {
  322. lstrcat(szTitle,p);
  323. }
  324. LocalFree((HANDLE)pSave);
  325. }
  326. SendDlgItemMessage(hDlg, IDD_EXTENSION, EM_LIMITTEXT, 4, 0L);
  327. SetDlgItemText(hDlg, IDD_EXTENSION, szTitle+1);
  328. SendDlgItemMessage(hDlg, IDD_EXTENSION, EM_SETMODIFY, 0, 0L);
  329. /* this is empty if there is no class association
  330. */
  331. szMessage[0]=0;
  332. szTemp2[0]=0;
  333. UpdateSelectionOrName(hDlg);
  334. ValidateExtension(hDlg);
  335. break;
  336. }
  337. case WM_COMMAND:
  338. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  339. HWND hwndT, hwndNext;
  340. case IDD_HELP:
  341. goto DoHelp;
  342. case IDD_EXTENSION:
  343. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE) {
  344. ValidateExtension(hDlg);
  345. UpdateSelectionOrName(hDlg);
  346. }
  347. break;
  348. case IDD_SEARCHALL:
  349. {
  350. OPENFILENAME ofn;
  351. DWORD dwSave = dwContext;
  352. dwContext = IDH_ASSOC_BROWSE;
  353. LoadString(hAppInstance, IDS_PROGRAMS, szTemp2, sizeof(szTemp2));
  354. FixupNulls(szTemp2);
  355. LoadString(hAppInstance, IDS_ASSOCIATE, szTitle, sizeof(szTitle));
  356. szTemp[0] = TEXT('\0');
  357. ofn.lStructSize = sizeof(ofn);
  358. ofn.hwndOwner = hDlg;
  359. ofn.hInstance = NULL;
  360. ofn.lpstrFilter = szTemp2;
  361. ofn.lpstrCustomFilter = NULL;
  362. ofn.nFilterIndex = 1;
  363. ofn.lpstrFile = szTemp;
  364. ofn.lpstrFileTitle = NULL;
  365. ofn.nMaxFile = sizeof(szTemp);
  366. ofn.lpstrInitialDir = NULL;
  367. ofn.lpstrTitle = szTitle;
  368. ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY;
  369. ofn.lpfnHook = NULL;
  370. ofn.lpstrDefExt = NULL;
  371. if (GetOpenFileName(&ofn)) {
  372. SetDlgItemText(hDlg, IDD_PROGRAMNAME, szTemp);
  373. }
  374. dwContext = dwSave;
  375. }
  376. DosResetDTAAddress(); // undo any bad things COMMDLG did
  377. break;
  378. case IDD_CLASSLIST:
  379. // Handle a selection change.
  380. if (GET_WM_COMMAND_CMD(wParam, lParam) == LBN_SELCHANGE) {
  381. INT iSel;
  382. LONG lTemp2;
  383. ATOM aClass;
  384. // Get selection number.
  385. if (SendDlgItemMessage(hDlg,IDD_CLASSLIST,LB_GETCURSEL,0,0L) == 0) {
  386. // User selected "none".
  387. LoadString(hAppInstance, IDS_ASSOCNONE, szTemp, sizeof(szTemp));
  388. // Copy into PROGRAMNAME field.
  389. SetDlgItemText(hDlg, IDD_PROGRAMNAME, (LPSTR) szTemp);
  390. } else {
  391. // User selected a file type.
  392. // Get the atom from the list box.
  393. iSel = (WORD) SendDlgItemMessage(hDlg, IDD_CLASSLIST,
  394. LB_GETCURSEL,0,0L);
  395. aClass = (ATOM) SendDlgItemMessage(hDlg, IDD_CLASSLIST,
  396. LB_GETITEMDATA, iSel, 0L);
  397. // Use the atom to get the file type key.
  398. GetAtomName(aClass, szTemp, sizeof(szTemp));
  399. // Use the file type key to get the file type value.
  400. lTemp2 = sizeof(szTemp2);
  401. RegQueryValue(HKEY_CLASSES_ROOT, szTemp, szTemp2,
  402. &lTemp2);
  403. // Splat the file type value into PROGRAMNAME field.
  404. SetDlgItemText(hDlg, IDD_PROGRAMNAME, szTemp2);
  405. }
  406. break;
  407. }
  408. case IDD_PROGRAMNAME:
  409. break;
  410. case IDOK:
  411. {
  412. GetDlgItemText(hDlg, IDD_EXTENSION, szTemp, 5);
  413. if (szTemp[0] != '.') {
  414. lstrcpy(szTitle,".");
  415. lstrcat(szTitle, szTemp);
  416. } else
  417. lstrcpy(szTitle, szTemp);
  418. if (IsProgramFile(szTitle)) {
  419. LoadString(hAppInstance, IDS_NOEXEASSOC, szTemp, sizeof(szTemp));
  420. wsprintf(szMessage, szTemp, (LPSTR)szTitle);
  421. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  422. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  423. SetDlgItemText(hDlg, IDD_EXTENSION, szNULL);
  424. break;
  425. }
  426. // Read IDD_PROGRAMNAME bit.
  427. GetDlgItemText(hDlg, IDD_PROGRAMNAME, szTemp, sizeof(szTemp));
  428. LoadString(hAppInstance, IDS_ASSOCNONE, szTemp2, sizeof(szTemp2));
  429. // Is it "(None)" ?
  430. if (!lstrcmp(szTemp, szTemp2)) {
  431. DeleteAssoc:
  432. // Yep, They selected none.
  433. RegDeleteKey(HKEY_CLASSES_ROOT,szTitle);
  434. WriteProfileString(szExtensions, szTitle+1, NULL);
  435. } else if (ValidFileTypeValue(szTemp, szTemp2, sizeof(szTemp2))) {
  436. LPSTR p1, p2;
  437. // The file type key is in szTemp2 (eg wrifile).
  438. // The extension key (eg .wri) is in szTitle.
  439. // The file type value (eg Write Document) is in
  440. // szTemp.
  441. #ifdef VERBDEBUG
  442. OutputDebugString("wf.adp: Valid file type selected.\n\r");
  443. OutputDebugString("wf.adp: Extension ");
  444. OutputDebugString(szTitle);
  445. OutputDebugString("\n\r");
  446. OutputDebugString("wf.adp: File type key ");
  447. OutputDebugString(szTemp2);
  448. OutputDebugString("\n\r");
  449. OutputDebugString("wf.adp: File type value ");
  450. OutputDebugString(szTemp);
  451. OutputDebugString("\n\r");
  452. #endif
  453. /* set the class
  454. */
  455. RegSetValue(HKEY_CLASSES_ROOT, szTitle, REG_SZ, szTemp2, 0L);
  456. /* get the class's SHELL\OPEN\COMMAND
  457. */
  458. lstrcpy(szTemp, szTemp2);
  459. lstrcat(szTemp, szShellOpenCommand);
  460. lParam = 128;
  461. szTemp2[0] = 0;
  462. RegQueryValue(HKEY_CLASSES_ROOT, szTemp, szTemp2, (PLONG)&lParam);
  463. /* insert ^.ext in for %1 in win.ini!
  464. */
  465. for (p1 = szTemp, p2 = szTemp2; *p2; p2 = AnsiNext(p2)) {
  466. if (*p2 == '%') {
  467. p2++;
  468. if (!*p2)
  469. break;
  470. if (*p2 == '1') {
  471. *p1++ = '^';
  472. lstrcpy(p1,szTitle);
  473. p1 += lstrlen(p1);
  474. } else {
  475. *p1++ = *p2;
  476. }
  477. } else {
  478. *p1++=*p2;
  479. }
  480. }
  481. *p1 = 0; // null terminate
  482. /* and use it for the extensions section
  483. */
  484. WriteProfileString(szExtensions,szTitle+1, szTemp);
  485. } else {
  486. // It must be a program name.
  487. /* if no command line, treat as none
  488. */
  489. if (!szTemp[0])
  490. goto DeleteAssoc;
  491. // make sure it has an extension
  492. if (*GetExtension(szTemp) == 0)
  493. lstrcat(szTemp, ".exe");
  494. if (!IsProgramFile(szTemp)) {
  495. LoadString(hAppInstance, IDS_ASSOCNOTEXE, szTemp2, sizeof(szTemp2));
  496. wsprintf(szMessage, szTemp2, (LPSTR)szTemp);
  497. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  498. MessageBox(hDlg, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  499. SetDlgItemText(hDlg, IDD_PROGRAMNAME, szNULL);
  500. break;
  501. }
  502. /* unassociate the class from the extension
  503. */
  504. RegSetValue(HKEY_CLASSES_ROOT, szTitle, REG_SZ, szNULL, 0L);
  505. /* update the [extensions] section
  506. */
  507. lstrcpy(szTemp2, szTemp);
  508. lstrcat(szTemp2, " ^.");
  509. lstrcat(szTemp2, szTitle+1);
  510. WriteProfileString(szExtensions, szTitle+1, szTemp2);
  511. /* update the reg database
  512. */
  513. lstrcat(szTemp," %1");
  514. lstrcat(szTitle, szShellOpenCommand);
  515. RegSetValue(HKEY_CLASSES_ROOT, szTitle, REG_SZ, szTemp, 0L);
  516. }
  517. // rebuild the list of document extensions
  518. LocalFree((HANDLE)szDocuments);
  519. BuildDocumentString();
  520. /* Update all of the Directory Windows in order to see
  521. * the effect of the new extensions.
  522. */
  523. hwndT = GetWindow(hwndMDIClient, GW_CHILD);
  524. while (hwndT) {
  525. hwndNext = GetWindow(hwndT, GW_HWNDNEXT);
  526. if (!GetWindow(hwndT, GW_OWNER))
  527. SendMessage(hwndT, WM_FILESYSCHANGE, FSC_REFRESH, 0L);
  528. hwndT = hwndNext;
  529. }
  530. }
  531. /*** FALL THRU ***/
  532. case IDCANCEL:
  533. {
  534. INT iItem;
  535. INT cItems;
  536. ATOM aClass;
  537. cItems = (INT)SendDlgItemMessage(hDlg,IDD_CLASSLIST,
  538. LB_GETCOUNT,0,0L);
  539. /* clean out them atoms except for "(none)".
  540. */
  541. for (iItem = 1; iItem < cItems; iItem++) {
  542. aClass = (ATOM)SendDlgItemMessage(hDlg,IDD_CLASSLIST,
  543. LB_GETITEMDATA,iItem,0L);
  544. if (aClass == LB_ERR)
  545. break;
  546. DeleteAtom(aClass);
  547. }
  548. EndDialog(hDlg, TRUE);
  549. break;
  550. }
  551. default:
  552. return(FALSE);
  553. }
  554. break;
  555. default:
  556. if (wMsg == wHelpMessage || wMsg == wBrowseMessage) {
  557. DoHelp:
  558. WFHelp(hDlg);
  559. return TRUE;
  560. } else
  561. return FALSE;
  562. }
  563. return(TRUE);
  564. }
  565. //
  566. // Strips off the path portion and replaces the first part of an 8-dot-3
  567. // filename with an asterisk.
  568. //
  569. VOID
  570. StarFilename(
  571. LPSTR pszPath
  572. )
  573. {
  574. LPSTR p;
  575. /* Remove any leading path information. */
  576. StripPath(pszPath);
  577. for (p = pszPath; *p && *p != '.'; p = (LPSTR)AnsiNext(p));
  578. if (*p == '.') {
  579. lstrcpy(pszPath+1, p);
  580. pszPath[0] = '*';
  581. } else
  582. lstrcpy(pszPath, szStarDotStar);
  583. }
  584. /*--------------------------------------------------------------------------*/
  585. /* */
  586. /* SearchDlgProc() - */
  587. /* */
  588. /*--------------------------------------------------------------------------*/
  589. INT_PTR
  590. APIENTRY
  591. SearchDlgProc(
  592. register HWND hDlg,
  593. UINT wMsg,
  594. WPARAM wParam,
  595. LPARAM lParam
  596. )
  597. {
  598. LPSTR p;
  599. MDICREATESTRUCT MDICS;
  600. CHAR szStart[MAXFILENAMELEN];
  601. UNREFERENCED_PARAMETER(lParam);
  602. switch (wMsg) {
  603. case WM_INITDIALOG:
  604. SendDlgItemMessage(hDlg, IDD_DIR, EM_LIMITTEXT, sizeof(szSearch)-(1+MAXFILENAMELEN), 0L);
  605. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szStart)-1, 0L);
  606. GetSelectedDirectory(0, szSearch);
  607. SetDlgItemText(hDlg, IDD_DIR, szSearch);
  608. p = GetSelection(TRUE);
  609. if (p) {
  610. GetNextFile(p, szStart, sizeof(szStart));
  611. StarFilename(szStart);
  612. SetDlgItemText(hDlg, IDD_NAME, szStart);
  613. LocalFree((HANDLE)p);
  614. }
  615. CheckDlgButton(hDlg, IDD_SEARCHALL, bSearchSubs);
  616. break;
  617. case WM_COMMAND:
  618. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  619. case IDD_HELP:
  620. goto DoHelp;
  621. case IDCANCEL:
  622. EndDialog(hDlg, FALSE);
  623. break;
  624. case IDOK:
  625. GetDlgItemText(hDlg, IDD_DIR, szSearch, sizeof(szSearch));
  626. QualifyPath(szSearch);
  627. GetDlgItemText(hDlg, IDD_NAME, szStart, sizeof(szStart));
  628. AppendToPath(szSearch, szStart);
  629. bSearchSubs = IsDlgButtonChecked(hDlg, IDD_SEARCHALL);
  630. EndDialog(hDlg, TRUE);
  631. /* Is the search window already up? */
  632. if (hwndSearch) {
  633. if (SendMessage(hwndSearch, FS_CHANGEDISPLAY, CD_PATH, (LPARAM)szSearch)) {
  634. SendMessage(hwndMDIClient, WM_MDIACTIVATE, GET_WM_MDIACTIVATE_MPS(0, 0, hwndSearch));
  635. if (IsIconic(hwndSearch))
  636. ShowWindow(hwndSearch, SW_SHOWNORMAL);
  637. }
  638. } else {
  639. LoadString(hAppInstance, IDS_SEARCHTITLE, szMessage, 32);
  640. lstrcat(szMessage, szSearch);
  641. /* Have the MDIClient create the MDI directory window. */
  642. MDICS.szClass = szSearchClass;
  643. MDICS.hOwner = hAppInstance;
  644. MDICS.szTitle = szMessage;
  645. MDICS.style = 0;
  646. MDICS.x = CW_USEDEFAULT;
  647. MDICS.y = 0;
  648. MDICS.cx = CW_USEDEFAULT;
  649. MDICS.cy = 0;
  650. // it would be nice to pass szSearch through here
  651. // as well...
  652. {
  653. HWND hwnd;
  654. hwnd = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE,
  655. 0, 0L);
  656. MDICS.lParam = 0;
  657. if (hwnd &&
  658. (GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZE))
  659. MDICS.lParam |= WS_MAXIMIZE;
  660. }
  661. SendMessage(hwndMDIClient, WM_MDICREATE, 0, (LPARAM)&MDICS);
  662. if (hwndSearch && MDICS.lParam)
  663. SendMessage(hwndMDIClient, WM_MDIMAXIMIZE, (WPARAM)hwndSearch, 0L);
  664. }
  665. break;
  666. default:
  667. return(FALSE);
  668. }
  669. break;
  670. default:
  671. if (wMsg == wHelpMessage) {
  672. DoHelp:
  673. WFHelp(hDlg);
  674. return TRUE;
  675. } else
  676. return FALSE;
  677. }
  678. return TRUE;
  679. }
  680. #define RUN_LENGTH 120
  681. /*--------------------------------------------------------------------------*/
  682. /* */
  683. /* RunDlgProc() - */
  684. /* */
  685. /*--------------------------------------------------------------------------*/
  686. INT_PTR
  687. APIENTRY
  688. RunDlgProc(
  689. HWND hDlg,
  690. UINT wMsg,
  691. WPARAM wParam,
  692. LPARAM lParam
  693. )
  694. {
  695. LPSTR p,pDir,pFile,pPar;
  696. register WORD ret;
  697. LPSTR pDir2;
  698. CHAR szTemp[MAXPATHLEN];
  699. CHAR szTemp2[MAXPATHLEN];
  700. CHAR sz3[RUN_LENGTH];
  701. UNREFERENCED_PARAMETER(lParam);
  702. switch (wMsg) {
  703. case WM_INITDIALOG:
  704. SetDlgDirectory(hDlg, NULL);
  705. SetWindowDirectory(); // and really set the DOS current directory
  706. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szTemp)-1, 0L);
  707. p = GetSelection(TRUE);
  708. if (p) {
  709. SetDlgItemText(hDlg, IDD_NAME, p);
  710. LocalFree((HANDLE)p);
  711. }
  712. break;
  713. case WM_COMMAND:
  714. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  715. case IDD_HELP:
  716. goto DoHelp;
  717. case IDCANCEL:
  718. EndDialog(hDlg, FALSE);
  719. break;
  720. #if 0
  721. case IDD_BROWSE:
  722. {
  723. OPENFILENAME ofn;
  724. DWORD dwSave = dwContext;
  725. dwContext = IDH_RUN_BROWSE;
  726. LoadString(hAppInstance, IDS_PROGRAMS, szTemp2, sizeof(szTemp2));
  727. FixupNulls(szTemp2);
  728. LoadString(hAppInstance, IDS_RUN, szTitle, sizeof(szTitle));
  729. GetSelectedDirectory(0, szDir);
  730. szTemp[0] = 0;
  731. ofn.lStructSize = sizeof(ofn);
  732. ofn.hwndOwner = hDlg;
  733. ofn.hInstance = NULL;
  734. ofn.lpstrFilter = szTemp2;
  735. ofn.lpstrCustomFilter = NULL;
  736. ofn.nFilterIndex = 1;
  737. ofn.nMaxCustFilter = NULL;
  738. ofn.lpstrFile = szTemp;
  739. ofn.nMaxFile = sizeof(szTemp);
  740. ofn.lpstrInitialDir = szDir;
  741. ofn.lpstrTitle = szTitle;
  742. ofn.lpstrFileTitle = NULL;
  743. ofn.nMaxFile = sizeof(szTemp);
  744. ofn.Flags = OFN_SHOWHELP|OFN_HIDEREADONLY;
  745. ofn.lpfnHook = NULL;
  746. ofn.lpstrDefExt = "EXE";
  747. if (GetOpenFileName(&ofn)) {
  748. SetDlgItemText(hDlg, IDD_NAME, szTemp);
  749. PostMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE);
  750. }
  751. DosResetDTAAddress(); // undo any bad things COMMDLG did
  752. dwContext = dwSave;
  753. break;
  754. }
  755. #endif
  756. case IDOK:
  757. {
  758. BOOL bLoadIt;
  759. GetDlgItemText(hDlg, IDD_NAME, szTemp, sizeof(szTemp));
  760. GetPathInfo(szTemp, &pDir, &pFile, &pPar);
  761. // copy away parameters
  762. lstrcpy(sz3,pPar);
  763. *pPar = 0; // strip the params from the program
  764. // REVIEW HACK Hard code UNC style paths.
  765. if (*pDir == '\\' && *(pDir+1) == '\\') {
  766. // This is a UNC style filename so NULLify directory.
  767. pDir2 = NULL;
  768. } else {
  769. GetSelectedDirectory(0, szTemp2);
  770. pDir2 = szTemp2;
  771. }
  772. bLoadIt = IsDlgButtonChecked(hDlg, IDD_LOAD);
  773. FixAnsiPathForDos(szTemp);
  774. if (pDir2)
  775. FixAnsiPathForDos(pDir2);
  776. ret = ExecProgram(szTemp, sz3, pDir2, bLoadIt);
  777. if (ret)
  778. MyMessageBox(hDlg, IDS_EXECERRTITLE, ret, MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  779. else
  780. EndDialog(hDlg, TRUE);
  781. break;
  782. }
  783. default:
  784. return(FALSE);
  785. }
  786. break;
  787. default:
  788. if (wMsg == wHelpMessage || wMsg == wBrowseMessage) {
  789. DoHelp:
  790. WFHelp(hDlg);
  791. return TRUE;
  792. } else
  793. return FALSE;
  794. }
  795. return TRUE;
  796. }
  797. VOID
  798. CopyToClipboard(
  799. LPSTR pszFrom
  800. )
  801. {
  802. CHAR szPath[MAXPATHLEN];
  803. UINT wFormat;
  804. HANDLE hMem;
  805. GetNextFile(pszFrom, szPath, sizeof(szPath));
  806. QualifyPath(szPath);
  807. FixAnsiPathForDos(szPath);
  808. wFormat = RegisterClipboardFormat("FileName");
  809. if (!wFormat)
  810. return;
  811. hMem = GlobalAlloc(GPTR|GMEM_DDESHARE, lstrlen(szPath)+1);
  812. if (!hMem)
  813. return;
  814. lstrcpy(GlobalLock(hMem), szPath);
  815. GlobalUnlock(hMem);
  816. if (OpenClipboard(hwndFrame)) {
  817. EmptyClipboard();
  818. SetClipboardData(wFormat, hMem);
  819. #if 0
  820. // write, excel and winword will not past the package
  821. // if we put text in the clipboard.
  822. hMem = GlobalAlloc(GPTR | GMEM_DDESHARE, lstrlen(szPath)+1);
  823. if (hMem) {
  824. lstrcpy(GlobalLock(hMem), szPath);
  825. GlobalUnlock(hMem);
  826. SetClipboardData(CF_OEMTEXT, hMem);
  827. }
  828. #endif
  829. CloseClipboard();
  830. }
  831. }
  832. VOID
  833. EnableCopy(
  834. HWND hDlg,
  835. BOOL bCopy
  836. )
  837. {
  838. HWND hwnd;
  839. // turn these on
  840. hwnd = GetDlgItem(hDlg, IDD_COPYTOCLIP);
  841. if (hwnd) {
  842. EnableWindow(hwnd, bCopy);
  843. ShowWindow(hwnd, bCopy ? SW_SHOWNA : SW_HIDE);
  844. }
  845. hwnd = GetDlgItem(hDlg, IDD_COPYTOFILE);
  846. if (hwnd) {
  847. EnableWindow(hwnd, bCopy);
  848. ShowWindow(hwnd, bCopy ? SW_SHOWNA : SW_HIDE);
  849. }
  850. // turn these off
  851. hwnd = GetDlgItem(hDlg, IDD_STATUS);
  852. if (hwnd) {
  853. EnableWindow(hwnd, !bCopy);
  854. ShowWindow(hwnd, !bCopy ? SW_SHOWNA : SW_HIDE);
  855. }
  856. hwnd = GetDlgItem(hDlg, IDD_NAME);
  857. if (hwnd) {
  858. EnableWindow(hwnd, !bCopy);
  859. ShowWindow(hwnd, !bCopy ? SW_SHOWNA : SW_HIDE);
  860. }
  861. }
  862. VOID
  863. MessWithRenameDirPath(
  864. PSTR pszPath
  865. )
  866. {
  867. CHAR szPath[MAXPATHLEN];
  868. // absolute path? don't tamper with it!
  869. if (!lstrcmp(pszPath + 1, ":\\") ||
  870. (lstrlen(pszPath) > (sizeof(szPath) - 4)))
  871. return;
  872. // prepend "..\" to this non absolute path
  873. lstrcpy(szPath, "..\\");
  874. lstrcat(szPath, pszPath);
  875. lstrcpy(pszPath, szPath);
  876. }
  877. /*--------------------------------------------------------------------------*/
  878. /* */
  879. /* SuperDlgProc() - */
  880. /* */
  881. /*--------------------------------------------------------------------------*/
  882. /* This proc handles the Print, Move, Copy, Delete, and Rename functions.
  883. * The calling routine (AppCommandProc()) sets 'wSuperDlgMode' before
  884. * calling DialogBox() to indicate which function is being used.
  885. */
  886. INT_PTR
  887. APIENTRY
  888. SuperDlgProc(
  889. register HWND hDlg,
  890. UINT wMsg,
  891. WPARAM wParam,
  892. LPARAM lParam
  893. )
  894. {
  895. WORD len;
  896. LPSTR pszFrom;
  897. CHAR szTo[MAXPATHLEN];
  898. static BOOL bTreeHasFocus;
  899. UNREFERENCED_PARAMETER(lParam);
  900. switch (wMsg) {
  901. case WM_INITDIALOG:
  902. {
  903. LPSTR p;
  904. HWND hwndActive;
  905. SetDlgDirectory(hDlg, NULL);
  906. EnableCopy(hDlg, wSuperDlgMode == IDM_COPY);
  907. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  908. bTreeHasFocus = (GetTreeFocus(hwndActive) == HasTreeWindow(hwndActive));
  909. p = GetSelection(FALSE);
  910. switch (wSuperDlgMode) {
  911. case IDM_COPY:
  912. LoadString(hAppInstance, IDS_COPY, szTitle, sizeof(szTitle));
  913. SetWindowText(hDlg, szTitle);
  914. if (bTreeHasFocus) { // selection came from the tree
  915. AddBackslash(p);
  916. lstrcat(p, szStarDotStar);
  917. }
  918. break;
  919. case IDM_RENAME:
  920. LoadString(hAppInstance, IDS_RENAME, szTitle, sizeof(szTitle));
  921. SetWindowText(hDlg, szTitle);
  922. // when renaming the current directory we cd up a level
  923. // (not really) and apply the appropriate hacks
  924. if (bTreeHasFocus) {
  925. lstrcpy(szTo, p);
  926. StripFilespec(szTo);
  927. SetDlgDirectory(hDlg, szTo); // make the user think this!
  928. StripPath(p); // name part of dir
  929. }
  930. break;
  931. }
  932. SetDlgItemText(hDlg, IDD_FROM, p);
  933. LocalFree((HANDLE)p);
  934. if ((wSuperDlgMode == IDM_PRINT) || (wSuperDlgMode == IDM_DELETE))
  935. wParam = IDD_FROM;
  936. else
  937. wParam = IDD_TO;
  938. SendDlgItemMessage(hDlg, (int)wParam, EM_LIMITTEXT, sizeof(szTo) - 1, 0L);
  939. break;
  940. }
  941. case WM_COMMAND:
  942. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  943. WORD id = GET_WM_COMMAND_ID(wParam, lParam);
  944. case IDD_HELP:
  945. goto DoHelp;
  946. case IDD_COPYTOFILE:
  947. case IDD_COPYTOCLIP:
  948. CheckButtons:
  949. CheckRadioButton(hDlg, IDD_COPYTOCLIP, IDD_COPYTOFILE, id);
  950. break;
  951. case IDD_TO:
  952. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_SETFOCUS) {
  953. id = IDD_COPYTOFILE;
  954. goto CheckButtons;
  955. }
  956. break;
  957. case IDCANCEL:
  958. /* This is for when this dialog is being used to print. */
  959. bUserAbort = TRUE;
  960. SuperDlgExit:
  961. EndDialog(hDlg, FALSE);
  962. break;
  963. case IDOK:
  964. len = (WORD)(SendDlgItemMessage(hDlg, IDD_FROM, EM_LINELENGTH, -1, 0L) + 1);
  965. // make sure the pszFrom buffer is big enough to
  966. // add the "..\" stuff in MessWithRenameDirPath()
  967. len += 4;
  968. pszFrom = (LPSTR)LocalAlloc(LPTR, len);
  969. if (!pszFrom)
  970. goto SuperDlgExit;
  971. GetDlgItemText(hDlg, IDD_FROM, pszFrom, len);
  972. GetDlgItemText(hDlg, IDD_TO, szTo, sizeof(szTo));
  973. if (wSuperDlgMode == IDM_COPY && IsDlgButtonChecked(hDlg, IDD_COPYTOCLIP)) {
  974. CopyToClipboard(pszFrom);
  975. goto SuperDlgExit;
  976. }
  977. if (!szTo[0]) {
  978. switch (wSuperDlgMode) {
  979. case IDM_RENAME:
  980. case IDM_MOVE:
  981. goto SuperDlgExit;
  982. case IDM_COPY:
  983. szTo[0] = '.';
  984. szTo[1] = '\0';
  985. break;
  986. }
  987. }
  988. EnableCopy(hDlg, FALSE);
  989. hdlgProgress = hDlg;
  990. if (wSuperDlgMode == IDM_PRINT)
  991. WFPrint(pszFrom);
  992. else {
  993. if (wSuperDlgMode == IDM_RENAME && bTreeHasFocus) {
  994. MessWithRenameDirPath(pszFrom);
  995. MessWithRenameDirPath(szTo);
  996. }
  997. /* HACK: Compute the FUNC_ values from WFCOPY.H */
  998. WFMoveCopyDriver(pszFrom, szTo, (WORD)(wSuperDlgMode-IDM_MOVE+1));
  999. }
  1000. LocalFree((HANDLE)pszFrom);
  1001. lFreeSpace = -1L; // force status info refresh
  1002. EndDialog(hDlg, TRUE);
  1003. break;
  1004. default:
  1005. return(FALSE);
  1006. }
  1007. break;
  1008. default:
  1009. if (wMsg == wHelpMessage) {
  1010. DoHelp:
  1011. WFHelp(hDlg);
  1012. return TRUE;
  1013. } else
  1014. return FALSE;
  1015. }
  1016. return TRUE;
  1017. }
  1018. VOID
  1019. CheckAttribsDlgButton(
  1020. HWND hDlg,
  1021. INT id,
  1022. DWORD dwAttribs,
  1023. DWORD dwAttribs3State,
  1024. DWORD dwAttribsOn
  1025. )
  1026. {
  1027. INT i;
  1028. if (dwAttribs3State & dwAttribs)
  1029. i = 2;
  1030. else if (dwAttribsOn & dwAttribs)
  1031. i = 1;
  1032. else
  1033. i = 0;
  1034. CheckDlgButton(hDlg, id, i);
  1035. }
  1036. INT
  1037. InitPropertiesDialog(
  1038. HWND hDlg
  1039. )
  1040. {
  1041. HWND hwndLB, hwndActive, hwndTree;
  1042. DWORD_PTR dwTemp;
  1043. HANDLE hMem;
  1044. LPMYDTA lpmydta;
  1045. DWORD dwAttribsOn, dwAttribs3State, dwAttribsLast;
  1046. HWND hwndDir, hwnd;
  1047. CHAR szName[MAXPATHLEN];
  1048. CHAR szPath[MAXPATHLEN];
  1049. CHAR szTemp[MAXPATHLEN + 20];
  1050. CHAR szBuf[80];
  1051. WCHAR szNum[30];
  1052. INT i, iMac, iCount, dyButton;
  1053. DWORD dwSize;
  1054. RECT rc, rcT;
  1055. DWORD dwAttrib;
  1056. FILETIME Time;
  1057. DWORD Length;
  1058. LFNDTA lfndta;
  1059. PSTR p;
  1060. HFONT hFont;
  1061. INT nType = 0;
  1062. // this is needed for relative findfirst calls below
  1063. SetWindowDirectory();
  1064. hwndActive = (HWND)SendMessage(hwndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  1065. hwndDir = HasDirWindow(hwndActive);
  1066. hwndTree = HasTreeWindow(hwndActive);
  1067. iCount = 0;
  1068. dwAttribsOn = 0; // all bits to check
  1069. dwAttribs3State = 0; // all bits to 3 state
  1070. dwAttribsLast = 0xFFFF; // previous bits
  1071. dwSize = 0L;
  1072. if (hwndTree && hwndTree == GetTreeFocus(hwndActive)) {
  1073. SendMessage(hwndActive, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  1074. StripBackslash(szPath);
  1075. FixAnsiPathForDos(szPath);
  1076. if (!WFFindFirst(&lfndta, szPath, ATTR_ALL | ATTR_DIR)) {
  1077. LoadString(hAppInstance, IDS_REASONS+DE_PATHNOTFOUND, szMessage, sizeof(szMessage));
  1078. MessageBox(hwndFrame, szMessage, szPath, MB_OK | MB_ICONSTOP);
  1079. EndDialog(hDlg, FALSE);
  1080. return 0;
  1081. }
  1082. WFFindClose(&lfndta);
  1083. OemToAnsi(szPath, szPath);
  1084. dwAttribsOn = lfndta.fd.dwFileAttributes;
  1085. Time = lfndta.fd.ftLastWriteTime;
  1086. Length = lfndta.fd.nFileSizeLow; // BUG < 64 bits!
  1087. goto FULL_PATH_KINDA_THING;
  1088. }
  1089. if (hwndDir) {
  1090. hwndLB = GetDlgItem(hwndDir, IDCW_LISTBOX);
  1091. hMem = (HANDLE)GetWindowLongPtr(hwndDir, GWLP_HDTA);
  1092. } else {
  1093. hwndLB = GetDlgItem(hwndActive, IDCW_LISTBOX);
  1094. hMem = (HANDLE)GetWindowLongPtr(hwndActive, GWLP_HDTASEARCH);
  1095. }
  1096. iMac = (WORD)SendMessage(hwndLB, LB_GETCOUNT, 0, 0L);
  1097. for (i = 0; i < iMac; i++) {
  1098. if ((BOOL)SendMessage(hwndLB, LB_GETSEL, i, 0L)) {
  1099. // get info from either dir or search window
  1100. if (hwndDir) {
  1101. SendMessage(hwndLB, LB_GETTEXT, i, (LPARAM)&lpmydta);
  1102. dwAttrib = lpmydta->my_dwAttrs;
  1103. /* Check that this is not the .. entry */
  1104. if (dwAttrib & ATTR_DIR && dwAttrib & ATTR_PARENT)
  1105. continue;
  1106. Time = lpmydta->my_ftLastWriteTime;
  1107. Length = lpmydta->my_nFileSizeLow;
  1108. lstrcpy(szName, lpmydta->my_cFileName);
  1109. } else {
  1110. SendMessage(hwndLB, LB_GETTEXT, i, (LPARAM)szPath);
  1111. dwTemp = SendMessage(hwndLB, LB_GETITEMDATA, i, 0L);
  1112. dwAttrib = ((LPDTASEARCH)lpmydta)[dwTemp].sch_dwAttrs;
  1113. Time = ((LPDTASEARCH)lpmydta)[dwTemp].sch_ftLastWriteTime;
  1114. Length = ((LPDTASEARCH)lpmydta)[dwTemp].sch_nFileSizeLow;
  1115. }
  1116. dwAttribsOn |= dwAttrib;
  1117. if (dwAttribsLast == 0xFFFF)
  1118. // save the previous bits for future compares
  1119. dwAttribsLast = dwAttrib;
  1120. else
  1121. // remember all bits that don't compare to last bits
  1122. dwAttribs3State |= (dwAttrib ^ dwAttribsLast);
  1123. dwSize += Length;
  1124. iCount++;
  1125. }
  1126. }
  1127. GetDlgItemText(hDlg, IDD_TEXT, szTemp, sizeof(szTemp));
  1128. wsprintf(szBuf, szTemp, iCount, AddCommasW(dwSize, szNum));
  1129. SetDlgItemText(hDlg, IDD_TEXT, szBuf);
  1130. if (iCount == 1) {
  1131. if (hwndDir) {
  1132. SendMessage(hwndDir, FS_GETDIRECTORY, sizeof(szPath), (LPARAM)szPath);
  1133. } else {
  1134. FULL_PATH_KINDA_THING:
  1135. lstrcpy(szName, szPath);
  1136. StripPath(szName);
  1137. StripFilespec(szPath);
  1138. }
  1139. StripBackslash(szPath);
  1140. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  1141. wsprintf(szTemp, szTitle, (LPSTR)szName);
  1142. SetWindowText(hDlg, szTemp);
  1143. SetDlgItemText(hDlg, IDD_NAME, szName);
  1144. SetDlgItemText(hDlg, IDD_DIR, szPath);
  1145. wsprintf(szTemp, szSBytes, (LPSTR)AddCommasW(Length, szNum));
  1146. SetDlgItemText(hDlg, IDD_SIZE, szTemp);
  1147. PutDate(&Time, szTemp);
  1148. lstrcat(szTemp, " ");
  1149. PutTime(&Time, szTemp + lstrlen(szTemp));
  1150. SetDlgItemText(hDlg, IDD_DATE, szTemp);
  1151. } else
  1152. dwContext = IDH_GROUP_ATTRIBS;
  1153. // add the network specific property buttons
  1154. if (WNetGetCaps(WNNC_DIALOG) & WNNC_DLG_PROPERTYDIALOG) {
  1155. GetWindowRect(GetDlgItem(hDlg,IDOK), &rcT);
  1156. GetWindowRect(GetDlgItem(hDlg,IDCANCEL), &rc);
  1157. dyButton = rc.top - rcT.top;
  1158. GetWindowRect(GetDlgItem(hDlg,IDD_HELP), &rc);
  1159. ScreenToClient(hDlg,(LPPOINT)&rc.left);
  1160. ScreenToClient(hDlg,(LPPOINT)&rc.right);
  1161. p = GetSelection(3);
  1162. if (p) {
  1163. for (i = 0; i < 6; i++) {
  1164. if (iCount > 1)
  1165. nType = WNPS_MULT;
  1166. else if (dwAttribsOn & ATTR_DIR)
  1167. nType = WNPS_DIR;
  1168. else
  1169. nType = WNPS_FILE;
  1170. if (WNetGetPropertyText((WORD)i, (WORD)nType, p, szTemp, 30, WNTYPE_FILE) != WN_SUCCESS)
  1171. break;
  1172. if (!szTemp[0])
  1173. break;
  1174. OffsetRect(&rc,0,dyButton);
  1175. hwnd = CreateWindowEx(0, "button", szTemp,
  1176. WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_PUSHBUTTON,
  1177. rc.left, rc.top,
  1178. rc.right - rc.left, rc.bottom-rc.top,
  1179. hDlg, (HMENU)IntToPtr(i + IDD_NETWORKFIRST), hAppInstance, NULL);
  1180. if (hwnd) {
  1181. hFont = (HFONT)SendDlgItemMessage(hDlg, IDOK, WM_GETFONT, 0, 0L);
  1182. SendMessage(hwnd, WM_SETFONT, (WPARAM)hFont, 0L);
  1183. }
  1184. }
  1185. LocalFree((HANDLE)p);
  1186. ClientToScreen(hDlg,(LPPOINT)&rc.left);
  1187. ClientToScreen(hDlg,(LPPOINT)&rc.right);
  1188. GetWindowRect(hDlg,&rcT);
  1189. rc.bottom += dyButton;
  1190. if (rcT.bottom <= rc.bottom) {
  1191. SetWindowPos(hDlg,NULL,0,0,rcT.right-rcT.left,
  1192. rc.bottom - rcT.top, SWP_NOMOVE|SWP_NOZORDER);
  1193. }
  1194. }
  1195. }
  1196. // change those that don't need to be 3state to regular
  1197. if (ATTR_READONLY & dwAttribs3State)
  1198. SetWindowLong(GetDlgItem(hDlg, IDD_READONLY), GWL_STYLE, WS_VISIBLE | WS_GROUP | WS_TABSTOP | BS_AUTO3STATE | WS_CHILD);
  1199. if (ATTR_HIDDEN & dwAttribs3State)
  1200. SetWindowLong(GetDlgItem(hDlg, IDD_HIDDEN), GWL_STYLE, WS_VISIBLE | BS_AUTO3STATE | WS_CHILD);
  1201. if (ATTR_ARCHIVE & dwAttribs3State)
  1202. SetWindowLong(GetDlgItem(hDlg, IDD_ARCHIVE), GWL_STYLE, WS_VISIBLE | BS_AUTO3STATE | WS_CHILD);
  1203. if (ATTR_SYSTEM & dwAttribs3State)
  1204. SetWindowLong(GetDlgItem(hDlg, IDD_SYSTEM), GWL_STYLE, WS_VISIBLE | BS_AUTO3STATE | WS_CHILD);
  1205. CheckAttribsDlgButton(hDlg, IDD_READONLY, ATTR_READONLY, dwAttribs3State, dwAttribsOn);
  1206. CheckAttribsDlgButton(hDlg, IDD_HIDDEN, ATTR_HIDDEN, dwAttribs3State, dwAttribsOn);
  1207. CheckAttribsDlgButton(hDlg, IDD_ARCHIVE, ATTR_ARCHIVE, dwAttribs3State, dwAttribsOn);
  1208. CheckAttribsDlgButton(hDlg, IDD_SYSTEM, ATTR_SYSTEM, dwAttribs3State, dwAttribsOn);
  1209. return nType;
  1210. }
  1211. /*--------------------------------------------------------------------------*/
  1212. /* */
  1213. /* AttribsDlgProc() - */
  1214. /* */
  1215. // assumes the active MDI child has a directory window
  1216. /*--------------------------------------------------------------------------*/
  1217. INT_PTR
  1218. APIENTRY
  1219. AttribsDlgProc(
  1220. register HWND hDlg,
  1221. UINT wMsg,
  1222. WPARAM wParam,
  1223. LPARAM lParam
  1224. )
  1225. {
  1226. LPSTR p, pSel;
  1227. BOOL bRet;
  1228. HCURSOR hCursor;
  1229. DWORD dwAttribsNew, dwAttribs, dwChangeMask;
  1230. UINT state;
  1231. CHAR szName[MAXPATHLEN];
  1232. static INT nType;
  1233. UNREFERENCED_PARAMETER(lParam);
  1234. switch (wMsg) {
  1235. case WM_INITDIALOG:
  1236. nType = InitPropertiesDialog(hDlg);
  1237. break;
  1238. case WM_COMMAND:
  1239. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1240. case IDD_HELP:
  1241. goto DoHelp;
  1242. case IDD_NETWORKFIRST+0:
  1243. case IDD_NETWORKFIRST+1:
  1244. case IDD_NETWORKFIRST+2:
  1245. case IDD_NETWORKFIRST+3:
  1246. case IDD_NETWORKFIRST+4:
  1247. case IDD_NETWORKFIRST+5:
  1248. p = GetSelection(3);
  1249. if (p) {
  1250. WNetPropertyDialog(hDlg, (WORD)(GET_WM_COMMAND_ID(wParam, lParam)-IDD_NETWORKFIRST), (WORD)nType, p, WNTYPE_FILE);
  1251. LocalFree((HANDLE)p);
  1252. }
  1253. break;
  1254. case IDCANCEL:
  1255. EndDialog(hDlg, FALSE);
  1256. break;
  1257. case IDOK:
  1258. bRet = TRUE;
  1259. dwChangeMask = ATTR_READWRITE;
  1260. dwAttribsNew = ATTR_READWRITE;
  1261. if ((state = IsDlgButtonChecked(hDlg, IDD_READONLY)) < 2) {
  1262. dwChangeMask |= ATTR_READONLY;
  1263. if (state == 1)
  1264. dwAttribsNew |= ATTR_READONLY;
  1265. }
  1266. if ((state = IsDlgButtonChecked(hDlg, IDD_HIDDEN)) < 2) {
  1267. dwChangeMask |= ATTR_HIDDEN;
  1268. if (state == 1)
  1269. dwAttribsNew |= ATTR_HIDDEN;
  1270. }
  1271. if ((state = IsDlgButtonChecked(hDlg, IDD_ARCHIVE)) < 2) {
  1272. dwChangeMask |= ATTR_ARCHIVE;
  1273. if (state == 1)
  1274. dwAttribsNew |= ATTR_ARCHIVE;
  1275. }
  1276. if ((state = IsDlgButtonChecked(hDlg, IDD_SYSTEM)) < 2) {
  1277. dwChangeMask |= ATTR_SYSTEM;
  1278. if (state == 1)
  1279. dwAttribsNew |= ATTR_SYSTEM;
  1280. }
  1281. EndDialog(hDlg, bRet);
  1282. pSel = GetSelection(FALSE);
  1283. if (!pSel)
  1284. break;
  1285. hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  1286. ShowCursor(TRUE);
  1287. DisableFSC();
  1288. p = pSel;
  1289. while (p = GetNextFile(p, szName, sizeof(szName))) {
  1290. QualifyPath(szName);
  1291. FixAnsiPathForDos(szName);
  1292. dwAttribs = GetFileAttributes(szName);
  1293. if (dwAttribs & 0x8000) // BUG hardcoded!
  1294. goto AttributeError;
  1295. else
  1296. dwAttribs &= ~ATTR_DIR;
  1297. dwAttribs = (dwChangeMask & dwAttribsNew) | (~dwChangeMask & dwAttribs);
  1298. if (WFSetAttr(szName, dwAttribs)) {
  1299. AttributeError:
  1300. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  1301. LoadString(hAppInstance, IDS_ATTRIBERR, szMessage, sizeof(szMessage));
  1302. MessageBox(hwndFrame, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  1303. bRet = FALSE;
  1304. break;
  1305. }
  1306. // clear all the FSC messages from the message queue
  1307. wfYield();
  1308. }
  1309. EnableFSC();
  1310. ShowCursor(FALSE);
  1311. SetCursor(hCursor);
  1312. LocalFree((HANDLE)pSel);
  1313. break;
  1314. default:
  1315. return FALSE;
  1316. }
  1317. break;
  1318. default:
  1319. if (wMsg == wHelpMessage) {
  1320. DoHelp:
  1321. WFHelp(hDlg);
  1322. return TRUE;
  1323. } else
  1324. return FALSE;
  1325. }
  1326. return TRUE;
  1327. }
  1328. /*--------------------------------------------------------------------------*/
  1329. /* */
  1330. /* MakeDirDlgProc() - */
  1331. /* */
  1332. /*--------------------------------------------------------------------------*/
  1333. INT_PTR
  1334. APIENTRY
  1335. MakeDirDlgProc(
  1336. HWND hDlg,
  1337. UINT wMsg,
  1338. WPARAM wParam,
  1339. LPARAM lParam
  1340. )
  1341. {
  1342. CHAR szPath[MAXPATHLEN];
  1343. INT ret;
  1344. UNREFERENCED_PARAMETER(lParam);
  1345. switch (wMsg) {
  1346. case WM_INITDIALOG:
  1347. SetDlgDirectory(hDlg, NULL);
  1348. SendDlgItemMessage(hDlg, IDD_NAME, EM_LIMITTEXT, sizeof(szPath)-1, 0L);
  1349. break;
  1350. case WM_COMMAND:
  1351. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1352. case IDD_HELP:
  1353. goto DoHelp;
  1354. case IDCANCEL:
  1355. EndDialog(hDlg, FALSE);
  1356. break;
  1357. case IDOK:
  1358. GetDlgItemText(hDlg, IDD_NAME, szPath, sizeof(szPath));
  1359. EndDialog(hDlg, TRUE);
  1360. // parse out any quoted strings
  1361. GetNextFile(szPath, szPath, sizeof(szPath));
  1362. QualifyPath(szPath);
  1363. hdlgProgress = hDlg;
  1364. if (NetCheck(szPath,WNDN_MKDIR) == WN_SUCCESS) {
  1365. FixAnsiPathForDos(szPath);
  1366. ret = WF_CreateDirectory(hDlg, szPath);
  1367. if (ret && ret!=DE_OPCANCELLED) {
  1368. if (WFIsDir(szPath))
  1369. ret = IDS_MAKEDIREXISTS;
  1370. else
  1371. ret += IDS_REASONS;
  1372. GetWindowText(hDlg, szTitle, sizeof(szTitle));
  1373. LoadString(hAppInstance, ret, szMessage, sizeof(szMessage));
  1374. MessageBox(hwndFrame, szMessage, szTitle, MB_OK | MB_ICONSTOP);
  1375. }
  1376. }
  1377. break;
  1378. default:
  1379. return FALSE;
  1380. }
  1381. break;
  1382. default:
  1383. if (wMsg == wHelpMessage) {
  1384. DoHelp:
  1385. WFHelp(hDlg);
  1386. return TRUE;
  1387. } else
  1388. return FALSE;
  1389. }
  1390. return TRUE;
  1391. }