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

819 lines
20 KiB

  1. /*
  2. * File: open_msc.c - stuff for calling Common Open Dialog
  3. *
  4. * Copyright 1991 by Hilgraeve Inc. -- Monroe, MI
  5. * All rights reserved
  6. *
  7. * $Revision: 23 $
  8. * $Date: 7/08/02 6:44p $
  9. */
  10. #include <windows.h>
  11. #pragma hdrstop
  12. // #define DEBUGSTR 1
  13. #include <commdlg.h>
  14. #include <memory.h>
  15. #include <stdlib.h>
  16. #include <shlobj.h>
  17. #include "stdtyp.h"
  18. #include <term\res.h>
  19. #include "mc.h"
  20. #include "tdll.h"
  21. #include "globals.h"
  22. #include "file_msc.h"
  23. #include "load_res.h"
  24. #include "htchar.h"
  25. #include <tdll\assert.h>
  26. #include "misc.h"
  27. #include "registry.h"
  28. #include "open_msc.h"
  29. static OPENFILENAME ofn;
  30. static BROWSEINFO bi;
  31. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  32. * FUNCTION:
  33. *
  34. * DESCRIPTION:
  35. *
  36. * ARGUEMENTS:
  37. *
  38. * RETURNS:
  39. */
  40. // This function prototype changed from BOOL FAR PASCAL. -- REV 3-6-98.
  41. UINT_PTR APIENTRY gnrcFindDirHookProc(HWND hdlg,
  42. UINT msg,
  43. WPARAM wPar,
  44. LPARAM lPar)
  45. {
  46. TCHAR acMsg[64];
  47. WORD windowID;
  48. windowID = LOWORD(wPar);
  49. switch (msg)
  50. {
  51. case WM_INITDIALOG:
  52. break;
  53. case WM_DESTROY:
  54. break;
  55. case WM_COMMAND:
  56. switch (windowID)
  57. {
  58. case IDOK:
  59. LoadString(glblQueryDllHinst(),
  60. 40809,
  61. acMsg,
  62. sizeof(acMsg) / sizeof(TCHAR));
  63. SetDlgItemText(hdlg, edt1, acMsg);
  64. // EndDialog(hdlg, 1);
  65. break;
  66. case lst2:
  67. if (HIWORD(lPar) == LBN_DBLCLK)
  68. {
  69. SetFocus(GetDlgItem(hdlg, IDOK));
  70. PostMessage(hdlg,
  71. WM_COMMAND,
  72. IDOK,
  73. MAKELONG((INT_PTR)GetDlgItem(hdlg, IDOK),0));
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. return FALSE;
  84. }
  85. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  86. * FUNCTION:
  87. *
  88. * DESCRIPTION:
  89. *
  90. * ARGUEMENTS:
  91. *
  92. * RETURNS:
  93. */
  94. #if FALSE
  95. BOOL FAR PASCAL gnrcFindFileHookProc(HWND hdlg,
  96. UINT msg,
  97. WPARAM wPar,
  98. LPARAM lPar)
  99. {
  100. WORD windowID;
  101. windowID = LOWORD(wPar);
  102. switch (msg)
  103. {
  104. case WM_INITDIALOG:
  105. ofn.lCustData = 0;
  106. break;
  107. case WM_DESTROY:
  108. break;
  109. default:
  110. break;
  111. }
  112. return FALSE;
  113. }
  114. #endif
  115. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  116. * FUNCTION:
  117. * gnrcFindFileDialog
  118. *
  119. * DESCRIPTION:
  120. * This function makes the FindFile common dialog a little bit easier to
  121. * call.
  122. *
  123. * ARGUEMENTS:
  124. * hwnd -- the window handle to use as the parent
  125. * pszTitle -- text to display as the title
  126. * pszDirectory -- path to use as default directory
  127. * pszMasks -- file name masks
  128. *
  129. * RETURNS:
  130. * A pointer to a string that contains the file name. This string is malloced
  131. * and must be freed by the caller, or..
  132. * NULL which indicates the user canceled the operation.
  133. */
  134. LPTSTR gnrcFindFileDialogInternal(HWND hwnd,
  135. LPCTSTR pszTitle,
  136. LPCTSTR pszDirectory,
  137. LPCTSTR pszMasks,
  138. int nFindFlag,
  139. LPCTSTR pszInitName)
  140. {
  141. int index;
  142. LPTSTR pszRet = NULL;
  143. LPTSTR pszStr;
  144. LPCTSTR pszWrk;
  145. TCHAR acMask[128];
  146. TCHAR acTitle[64];
  147. TCHAR szExt[4];
  148. TCHAR szFile[FNAME_LEN + 1];
  149. TCHAR szDir[FNAME_LEN + 1];
  150. int iRet;
  151. int iSize;
  152. int iExtSize;
  153. //DWORD dwMaxComponentLength;
  154. //DWORD dwFileSystemFlags;
  155. memset((LPTSTR)&ofn, 0, sizeof(ofn));
  156. TCHAR_Fill(szFile, TEXT('\0'), sizeof(szFile)/sizeof(TCHAR));
  157. TCHAR_Fill(szExt, TEXT('\0'), sizeof(szExt)/sizeof(TCHAR));
  158. TCHAR_Fill(acMask, TEXT('\0'), sizeof(acMask)/sizeof(TCHAR));
  159. TCHAR_Fill(acTitle, TEXT('\0'), sizeof(acTitle)/sizeof(TCHAR));
  160. //
  161. // So we can use the same binaries on Win9.x/WinNT/Win2K, we need
  162. // to make sure the size of this structure is correct for those
  163. // platforms. If WINVER and _WIN32_WINNT >= 0x0500, the size is
  164. // OPENFILENAME_SIZE_VERSION_400 otherwise the size is OPENFILENAME.
  165. // See OPENFILENAME documentation for more info. REV: 05/24/2001
  166. //
  167. #if(WINVER >= 0x0500 && _WIN32_WINNT >= 0x0500)
  168. if (!IsNT() || (IsNT() && GetWindowsMajorVersion() < 5))
  169. {
  170. ofn.lStructSize = sizeof(OPENFILENAME_SIZE_VERSION_400);
  171. }
  172. else
  173. {
  174. ofn.lStructSize = sizeof(OPENFILENAME);
  175. }
  176. #else
  177. ofn.lStructSize = sizeof(OPENFILENAME);
  178. #endif
  179. ofn.hwndOwner = hwnd;
  180. ofn.hInstance = (HANDLE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
  181. if ((pszMasks == NULL) || (StrCharGetStrLength(pszMasks) == 0))
  182. {
  183. resLoadFileMask(glblQueryDllHinst(),
  184. IDS_CMM_ALL_FILES1,
  185. 1,
  186. acMask,
  187. sizeof(acMask) / sizeof(TCHAR));
  188. ofn.lpstrFilter = acMask;
  189. }
  190. else
  191. {
  192. ofn.lpstrFilter = pszMasks;
  193. pszWrk = pszMasks;
  194. pszWrk = StrCharFindFirst(pszWrk, TEXT('.'));
  195. if (*pszWrk == '.')
  196. {
  197. pszWrk = StrCharNext(pszWrk);
  198. pszStr = (LPTSTR)pszWrk;
  199. index = 0;
  200. /* This works because we know how the mask are going to be formed */
  201. while ((index < 3) && (*pszWrk != ')'))
  202. {
  203. index += 1;
  204. pszWrk = StrCharNext(pszWrk);
  205. }
  206. if (pszWrk >= pszStr)
  207. MemCopy(szExt, pszStr, pszWrk - pszStr);
  208. }
  209. pszWrk = NULL;
  210. }
  211. iSize = StrCharGetByteCount(pszInitName);
  212. //MPT:10SEP98 if there is no name, just set the dest string to nothing
  213. if( iSize <= FNAME_LEN && pszInitName && iSize > 0)
  214. {
  215. MemCopy(szFile, pszInitName, iSize);
  216. }
  217. else
  218. {
  219. szFile[0] = TEXT('\0');
  220. }
  221. ofn.lpstrDefExt = (LPTSTR)szExt;
  222. ofn.lpstrCustomFilter = NULL;
  223. ofn.nMaxCustFilter = 0;
  224. ofn.nFilterIndex = 0;
  225. ofn.lpstrFile = (LPTSTR)szFile;
  226. ofn.nMaxFile = FNAME_LEN;
  227. if ((pszDirectory == NULL) || (StrCharGetStrLength(pszDirectory) == 0))
  228. {
  229. #ifdef NT_EDITION
  230. // mpt:07-30-97
  231. if (IsNT())
  232. #endif
  233. GetUserDirectory(szDir, FNAME_LEN + 1);
  234. #ifdef NT_EDITION
  235. else
  236. {
  237. TCHAR acDirTmp[FNAME_LEN];
  238. GetModuleFileName(glblQueryHinst(), acDirTmp, FNAME_LEN);
  239. mscStripName(acDirTmp);
  240. }
  241. #endif
  242. }
  243. else
  244. {
  245. StrCharCopyN(szDir, pszDirectory, FNAME_LEN + 1);
  246. }
  247. pszStr = StrCharLast(szDir);
  248. if (*pszStr == TEXT('\\'))
  249. *pszStr = TEXT('\0');
  250. ofn.lpstrInitialDir = szDir;
  251. ofn.lpstrFileTitle = NULL;
  252. ofn.nMaxFileTitle = 0;
  253. if ((pszTitle == NULL) || (StrCharGetByteCount(pszTitle) == 0))
  254. {
  255. // ofn.lpstrTitle = "Select File";
  256. LoadString(glblQueryDllHinst(),
  257. IDS_CPF_SELECT_FILE,
  258. acTitle,
  259. sizeof(acTitle) / sizeof(TCHAR));
  260. ofn.lpstrTitle = acTitle;
  261. }
  262. else
  263. {
  264. ofn.lpstrTitle = pszTitle;
  265. }
  266. ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_EXPLORER;
  267. if (nFindFlag)
  268. {
  269. ofn.Flags |= OFN_FILEMUSTEXIST;
  270. iRet = GetOpenFileName(&ofn);
  271. }
  272. else
  273. {
  274. ofn.Flags |= OFN_OVERWRITEPROMPT;
  275. #if 0
  276. // This was added so the common dialog for "Save As" applies
  277. // the same restrictions as the New Connect dialog when it
  278. // comes to saving session file names.
  279. //
  280. GetVolumeInformation(NULL, NULL, 0, NULL, &dwMaxComponentLength,
  281. &dwFileSystemFlags, NULL, 0);
  282. if(dwMaxComponentLength == 255)
  283. {
  284. ofn.nMaxFile = dwMaxComponentLength - 1;
  285. }
  286. else
  287. {
  288. ofn.nMaxFile = 8;
  289. }
  290. #endif
  291. iRet = GetSaveFileName(&ofn);
  292. }
  293. if (iRet != 0)
  294. {
  295. iExtSize = StrCharGetStrLength(ofn.lpstrDefExt);
  296. iSize = min(StrCharGetStrLength(ofn.lpstrFile), (int)ofn.nMaxFile);
  297. if (iSize > 0)
  298. {
  299. pszRet = malloc(ofn.nMaxFile * sizeof(TCHAR));
  300. if (pszRet != NULL)
  301. {
  302. TCHAR_Fill(pszRet, TEXT('\0'), ofn.nMaxFile);
  303. // Due to a bug in GetSaveFileName(), it is possible
  304. // the file will not contain the default extension if
  305. // the filename is too long for the default extension
  306. // to be appended. We need to make sure we have the
  307. // proper file extension type. REV: 10/18/2000
  308. //
  309. if(iSize != (ofn.nFileExtension + iExtSize) &&
  310. nFindFlag == FALSE)
  311. {
  312. StrCharCopyN(pszRet, ofn.lpstrFile, iSize - iExtSize - 1);
  313. StrCharCat(pszRet, TEXT("."));
  314. StrCharCat(pszRet, ofn.lpstrDefExt);
  315. }
  316. else
  317. {
  318. StrCharCopyN(pszRet, ofn.lpstrFile, ofn.nMaxFile);
  319. }
  320. // make sure this is a NULL terminated string.
  321. //
  322. pszRet[ofn.nMaxFile - 1] = TEXT( '\0');
  323. }
  324. return pszRet;
  325. }
  326. else
  327. {
  328. return(NULL);
  329. }
  330. }
  331. else
  332. {
  333. DWORD dwError = CommDlgExtendedError();
  334. return(NULL);
  335. }
  336. return(NULL);
  337. }
  338. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  339. * FUNCTION:
  340. *
  341. * DESCRIPTION:
  342. *
  343. * ARGUMENTS:
  344. *
  345. * RETURNS:
  346. *
  347. */
  348. LPTSTR gnrcFindFileDialog(HWND hwnd,
  349. LPCTSTR pszTitle,
  350. LPCTSTR pszDirectory,
  351. LPCTSTR pszMasks)
  352. {
  353. return gnrcFindFileDialogInternal(hwnd,
  354. pszTitle,
  355. pszDirectory,
  356. pszMasks,
  357. TRUE,
  358. NULL);
  359. }
  360. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  361. * FUNCTION:
  362. *
  363. * DESCRIPTION:
  364. *
  365. * ARGUMENTS:
  366. *
  367. * RETURNS:
  368. *
  369. */
  370. LPTSTR gnrcSaveFileDialog(HWND hwnd,
  371. LPCTSTR pszTitle,
  372. LPCTSTR pszDirectory,
  373. LPCTSTR pszMasks,
  374. LPCTSTR pszInitName)
  375. {
  376. return gnrcFindFileDialogInternal(hwnd,
  377. pszTitle,
  378. pszDirectory,
  379. pszMasks,
  380. FALSE,
  381. pszInitName);
  382. }
  383. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  384. * FUNCTION:
  385. * gnrcFindDirectoryDialog
  386. *
  387. * DESCRIPTION:
  388. *
  389. * ARGUEMENTS:
  390. *
  391. * RETURNS:
  392. */
  393. LPTSTR gnrcFindDirectoryDialog(HWND hwnd, HSESSION hSession, LPTSTR pszDir)
  394. {
  395. #ifndef INCL_USE_NEWFOLDERDLG
  396. BOOL bRet;
  397. #else
  398. #if TODO
  399. LPMALLOC pMalloc = NULL;
  400. #endif // TODO
  401. HRESULT hResult = S_OK;
  402. #endif
  403. LPTSTR pszStr;
  404. TCHAR acTitle[64];
  405. TCHAR acList[64];
  406. TCHAR szDir[FNAME_LEN];
  407. TCHAR szFile[FNAME_LEN];
  408. int pszStrLen;
  409. LoadString(glblQueryDllHinst(),
  410. IDS_CMM_SEL_DIR,
  411. acTitle,
  412. sizeof(acTitle) / sizeof(TCHAR));
  413. resLoadFileMask(glblQueryDllHinst(),
  414. IDS_CMM_ALL_FILES1,
  415. 1,
  416. acList,
  417. sizeof(acList) / sizeof(TCHAR));
  418. TCHAR_Fill(szFile, TEXT('\0'), sizeof(szFile) / sizeof(TCHAR));
  419. memset((LPTSTR)&ofn, 0, sizeof(ofn));
  420. if ((pszDir == NULL) || (StrCharGetStrLength(pszDir) == 0))
  421. {
  422. //changed to use working folder rather than current - mpt 8-18-99
  423. if ( !GetWorkingDirectory(szDir, FNAME_LEN) )
  424. {
  425. GetCurrentDirectory(FNAME_LEN, szDir);
  426. }
  427. }
  428. else
  429. {
  430. StrCharCopyN(szDir, pszDir, FNAME_LEN);
  431. }
  432. pszStr = StrCharLast(szDir);
  433. if (*pszStr == TEXT('\\'))
  434. *pszStr = TEXT('\0');
  435. #ifndef INCL_USE_NEWFOLDERDLG
  436. ofn.lCustData = 0L;
  437. //
  438. // So we can use the same binaries on Win9.x/WinNT/Win2K, we need
  439. // to make sure the size of this structure is correct for those
  440. // platforms. If WINVER and _WIN32_WINNT >= 0x0500, the size is
  441. // OPENFILENAME_SIZE_VERSION_400 otherwise the size is OPENFILENAME.
  442. // See OPENFILENAME documentation for more info. REV: 05/24/2001
  443. //
  444. #if(WINVER >= 0x0500 && _WIN32_WINNT >= 0x0500)
  445. if (!IsNT() || (IsNT() && GetWindowsMajorVersion() < 5))
  446. {
  447. ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
  448. }
  449. else
  450. {
  451. ofn.lStructSize = sizeof(OPENFILENAME);
  452. }
  453. #else // (WINVER >= 0x0500 && _WIN32_WINNT >= 0x0500)
  454. ofn.lStructSize = sizeof(OPENFILENAME);
  455. #endif //( WINVER >= 0x0500 && _WIN32_WINNT >= 0x0500)
  456. ofn.hwndOwner = hwnd;
  457. ofn.hInstance = (HANDLE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
  458. ofn.lpstrTitle = acTitle;
  459. ofn.lpstrFilter = acList;
  460. ofn.lpstrCustomFilter = NULL;
  461. ofn.nMaxCustFilter = 0;
  462. ofn.nFilterIndex = 0;
  463. ofn.lpstrFile = szFile;
  464. ofn.nMaxFile = sizeof(szFile);
  465. ofn.nFileOffset = 0;
  466. ofn.nFileExtension = 0;
  467. ofn.lpstrFileTitle = acTitle;
  468. ofn.nMaxFileTitle = sizeof(acTitle);
  469. ofn.lpstrDefExt = NULL;
  470. // If OFN_ENABLEHOOK and/or OFN_ENABLETEMPLATE flags are set the call to
  471. // GetOpenFileName() will crash the application, then only a single drive
  472. // will appear in the "Drives:" dropdown list. This is a bug in the 1691
  473. // build of Windows 98. -- REV 3-6-98.
  474. //
  475. ofn.Flags = OFN_ENABLEHOOK | OFN_ENABLETEMPLATE |
  476. OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  477. ofn.lpfnHook = gnrcFindDirHookProc;
  478. ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FINDDIRECTORY);
  479. ofn.lpstrInitialDir = szDir;
  480. bRet = GetOpenFileName(&ofn);
  481. if (StrCharGetStrLength(szFile) == 0)
  482. {
  483. return NULL;
  484. }
  485. pszStr = StrCharFindLast(szFile, TEXT('\\'));
  486. if (*pszStr == TEXT('\\'))
  487. {
  488. pszStr = StrCharNext(pszStr);
  489. *pszStr = TEXT('\0');
  490. }
  491. #else //INCL_USE_NEWFOLDERDLG
  492. //TODO:MPT Finish up the new browse for folder mechanism
  493. // - free pidl's when done
  494. //
  495. // CoInitialize and get the Shell allocator's IMalloc interface.
  496. //
  497. hResult = CoInitialize( NULL );
  498. if ( hResult != S_OK && hResult != S_FALSE )
  499. {
  500. szFile[0] = TEXT('\0');
  501. }
  502. else
  503. {
  504. #if TODO
  505. if ( SHGetMalloc( &pMalloc ) != NOERROR || !pMalloc )
  506. {
  507. szFile[0] = TEXT('\0');
  508. }
  509. else if ( pMalloc )
  510. {
  511. #endif // TODO
  512. LPITEMIDLIST pidlSelected = NULL;
  513. //pidlSelected = (LPITEMIDLIST) CoTaskMemAlloc( sizeof(ITEMIDLIST) );
  514. bi.pidlRoot = NULL;
  515. bi.hwndOwner = hwnd;
  516. bi.pszDisplayName = szDir;
  517. bi.lpszTitle = acTitle;
  518. bi.ulFlags = BIF_RETURNONLYFSDIRS;
  519. //
  520. // Add the new dialog style flag to get all the new shell's
  521. // functionality (make resizable, etc.).
  522. //
  523. bi.ulFlags |= BIF_USENEWUI;
  524. bi.lpfn = NULL; //gnrcBrowseFolderHookProc;
  525. bi.lParam = 0;
  526. pidlSelected = SHBrowseForFolder( &bi );
  527. if ( pidlSelected )
  528. {
  529. SHGetPathFromIDList( pidlSelected, szFile );
  530. //
  531. // Free the memory and by the Shell allocator for this PIDL.
  532. //
  533. //pMalloc->Free( pidlSelected );
  534. pidlSelected = NULL;
  535. }
  536. #if TODO
  537. //
  538. // Release the Shell allocator's IMalloc interface.
  539. //
  540. //pMalloc->Release();
  541. pMalloc = NULL;
  542. }
  543. #endif // TODO
  544. CoUninitialize();
  545. }
  546. if (StrCharGetStrLength(szFile) == 0)
  547. {
  548. return NULL;
  549. }
  550. #endif //INCL_USE_NEWFOLDERDLG
  551. fileFinalizeDIR(hSession, szFile, szFile);
  552. pszStrLen = StrCharGetByteCount(szFile) + 1;
  553. pszStr = malloc(pszStrLen);
  554. StrCharCopyN(pszStr, szFile, pszStrLen);
  555. return pszStr;
  556. }
  557. #ifdef INCL_USE_NEWFOLDERDLG
  558. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  559. * FUNCTION:
  560. * gnrcBrowseFolderHookProc
  561. *
  562. * DESCRIPTION:
  563. *
  564. * ARGUEMENTS:
  565. *
  566. * RETURNS:
  567. */
  568. UINT_PTR CALLBACK gnrcBrowseFolderHookProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
  569. {
  570. return 0;
  571. }
  572. #endif
  573. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  574. * FUNCTION:
  575. * GetUserDirectory
  576. *
  577. * DESCRIPTION:
  578. * Returns the default HyperTerminal directory for the current user
  579. *
  580. * ARGUMENTS:
  581. * pszUserDir -- where to write the default directory
  582. * dwSize -- size, in characters, of the above buffer
  583. *
  584. * RETURNS:
  585. * If the function succeeds, the return value is the number of characters
  586. * stored into the buffer pointed to by pszDir, not including the
  587. * terminating null character.
  588. *
  589. * If the specified environment variable name was not found in the
  590. * environment block for the current process, the return value is zero.
  591. *
  592. * If the buffer pointed to by lpBuffer is not large enough, the return
  593. * value is the buffer size, in characters, required to hold the value
  594. * string and its terminating null character.
  595. *
  596. * Author: JMH, 6-12-96
  597. */
  598. DWORD GetUserDirectory(LPTSTR pszUserDir, DWORD dwSize)
  599. {
  600. DWORD dwRet = MAX_PATH;
  601. TCHAR szProfileDir[MAX_PATH];
  602. TCHAR szProfileDir1[MAX_PATH];
  603. TCHAR szProfileRoot[MAX_PATH];
  604. szProfileRoot[0] = TEXT('\0');
  605. if ( htRegQueryValue(HKEY_CURRENT_USER,
  606. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"),
  607. TEXT("Programs"),
  608. szProfileRoot,
  609. &dwRet) != 0 )
  610. {
  611. assert(0);
  612. return 0;
  613. }
  614. dwRet = MAX_PATH;
  615. szProfileDir[0] = TEXT('\0');
  616. if ( htRegQueryValue(HKEY_CURRENT_USER,
  617. TEXT("SOFTWARE\\Hilgraeve Inc\\HyperTerminal PE\\3.0"),
  618. TEXT("SessionsPath"),
  619. szProfileDir,
  620. &dwRet) != 0 )
  621. {
  622. LPTSTR pszStr = NULL;
  623. dwRet = MAX_PATH;
  624. szProfileDir[0] = TEXT('\0');
  625. if ( htRegQueryValue(HKEY_CURRENT_USER,
  626. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GrpConv\\MapGroups"),
  627. TEXT("Communications"),
  628. szProfileDir,
  629. &dwRet) != 0 )
  630. {
  631. //mpt:12-16-98 If HyperTerminal was never installed by the operating system, this
  632. // key is not present so we need to fake one.
  633. LoadString(glblQueryDllHinst(), IDS_GNRL_PROFILE_DIR, szProfileDir, sizeof(szProfileDir)/sizeof(TCHAR) );
  634. }
  635. szProfileDir1[0] = TEXT('\0');
  636. LoadString(glblQueryDllHinst(), IDS_GNRL_APPNAME, szProfileDir1, sizeof(szProfileDir)/sizeof(TCHAR) );
  637. pszStr = StrCharLast(szProfileDir);
  638. if (*szProfileDir && *pszStr != TEXT('\\'))
  639. {
  640. StrCharCat(szProfileDir, TEXT("\\"));
  641. }
  642. StrCharCat(szProfileDir, szProfileDir1);
  643. dwRet = StrCharGetStrLength(szProfileRoot) + StrCharGetStrLength(szProfileDir);
  644. assert(!(dwRet + sizeof(TCHAR) > dwSize));
  645. StrCharCopyN(pszUserDir, szProfileRoot, dwSize);
  646. if ((DWORD)(StrCharGetStrLength(pszUserDir) + 1) < dwSize)
  647. {
  648. StrCharCat(pszUserDir, TEXT("\\"));
  649. }
  650. if (dwRet + sizeof(TCHAR) < dwSize)
  651. {
  652. StrCharCat(pszUserDir, szProfileDir);
  653. }
  654. }
  655. else
  656. {
  657. dwRet = StrCharGetStrLength(szProfileDir);
  658. assert(dwRet + sizeof(TCHAR) > dwSize);
  659. StrCharCopyN(pszUserDir, szProfileDir, dwSize);
  660. }
  661. return dwRet;
  662. }
  663. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  664. * FUNCTION:
  665. * CreateUserDirectory (NT_EDITION only)
  666. *
  667. * DESCRIPTION:
  668. * For NT, if HT is installed after the os update, no directory
  669. * will exist for HT in the user profile. This function creates the
  670. * directory if necessary, since the rest of the program assumes
  671. * it exists.
  672. *
  673. * ARGUMENTS:
  674. * None.
  675. *
  676. * RETURNS:
  677. * Nothing.
  678. *
  679. * Author: JMH, 6-13-96
  680. */
  681. void CreateUserDirectory(void)
  682. {
  683. TCHAR szUserDir[MAX_PATH];
  684. GetUserDirectory(szUserDir, MAX_PATH);
  685. mscCreatePath(szUserDir);
  686. }
  687. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  688. * FUNCTION:
  689. * GetWorkingDirectory
  690. *
  691. * DESCRIPTION: Determines if we are running under Windows NT
  692. *
  693. * ARGUMENTS:
  694. * None.
  695. *
  696. * RETURNS:
  697. * 0 if user directory not specified
  698. *
  699. * Author: MPT 8-18-99
  700. */
  701. DWORD GetWorkingDirectory(LPTSTR pszUserDir, DWORD dwSize)
  702. {
  703. DWORD dwRet = MAX_PATH;
  704. DWORD lReturn = 1;
  705. pszUserDir[0] = TEXT('\0');
  706. #if defined(NT_EDITION)
  707. lReturn = 0;
  708. #else
  709. if ( htRegQueryValue(HKEY_CURRENT_USER,
  710. TEXT("SOFTWARE\\Hilgraeve Inc\\HyperTerminal PE\\3.0"),
  711. TEXT("WorkingPath"),
  712. pszUserDir,
  713. &dwRet) != 0 )
  714. {
  715. lReturn = 0;
  716. }
  717. #endif
  718. return lReturn;
  719. }