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.

804 lines
19 KiB

  1. #include "pch.hxx"
  2. #include "impapi.h"
  3. #include "comconv.h"
  4. #include <newimp.h>
  5. #include <..\Eudora\eudrimp.h>
  6. #include <ImpAth16.h>
  7. #include <mapi.h>
  8. #include <mapix.h>
  9. #include <import.h>
  10. #include <dllmain.h>
  11. #include <imnapi.h>
  12. #include <commdlg.h>
  13. #include <strconst.h>
  14. ASSERTDATA
  15. typedef struct tagSELATH16INFO
  16. {
  17. char szFile[MAX_PATH];
  18. char szUser[MAX_PATH];
  19. } SELATH16INFO;
  20. INT_PTR CALLBACK ProvideIniPathProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  21. HRESULT GetIniFilePath(SELATH16INFO *pSelAth, HWND hwnd);
  22. static const char g_Athena16Mail[] = "c:\\Athena16\\Mail\\Mail.ini";
  23. static const char c_szUsers[] = "Users";
  24. static const char c_szPathFileFmt[] = "%s\\%s";
  25. static const char c_szAsterisk[] = "*";
  26. static const char c_szDot[] = ".";
  27. static const char c_szDotDot[] = "..";
  28. static const char c_szFoldersDir[] = "\\Folders";
  29. static const char c_szMsgListFile[] = "\\msg_list";
  30. CAthena16Import::CAthena16Import()
  31. {
  32. DllAddRef();
  33. m_cRef = 1;
  34. m_plist = NULL;
  35. *m_szUser = 0;
  36. }
  37. CAthena16Import::~CAthena16Import()
  38. {
  39. if (m_plist != NULL)
  40. EudoraFreeFolderList(m_plist);
  41. DllRelease();
  42. }
  43. ULONG CAthena16Import::AddRef()
  44. {
  45. m_cRef++;
  46. return(m_cRef);
  47. }
  48. ULONG CAthena16Import::Release()
  49. {
  50. ULONG cRef;
  51. cRef = --m_cRef;
  52. if (cRef == 0)
  53. delete this;
  54. return(cRef);
  55. }
  56. HRESULT CAthena16Import::QueryInterface(REFIID riid, LPVOID *ppv)
  57. {
  58. HRESULT hr = S_OK;
  59. if (ppv == NULL)
  60. return(E_INVALIDARG);
  61. *ppv = NULL;
  62. if (IID_IMailImport == riid)
  63. *ppv = (IMailImport *)this;
  64. else if (IID_IUnknown == riid)
  65. *ppv = (IUnknown *)this;
  66. else
  67. hr = E_NOINTERFACE;
  68. if (*ppv != NULL)
  69. ((LPUNKNOWN)*ppv)->AddRef();
  70. return(hr);
  71. }
  72. HRESULT CAthena16Import::InitializeImport(HWND hwnd)
  73. {
  74. // Only if the default path to the mail.ini file is
  75. // incorrect prompt the user!!!
  76. HRESULT hr = S_FALSE;
  77. int iRet;
  78. SELATH16INFO sa;
  79. ZeroMemory(&sa, sizeof(sa));
  80. hr = GetIniFilePath(&sa, hwnd);
  81. StrCpyN(m_szIniFile, sa.szFile, ARRAYSIZE(m_szIniFile));
  82. if (GetNumUsers(sa.szFile, sa.szUser, ARRAYSIZE(sa.szUser)) > 1)
  83. {
  84. iRet = (int) DialogBoxParam(g_hInstImp, MAKEINTRESOURCE(iddSelectAth16User), hwnd, SelectAth16UserDlgProc, (LPARAM)&sa);
  85. if (iRet == IDCANCEL)
  86. hr = S_FALSE;
  87. else if (iRet == IDOK)
  88. StrCpyN(m_szUser, sa.szUser, ARRAYSIZE(m_szUser));
  89. else
  90. hr = E_FAIL;
  91. }
  92. else
  93. {
  94. StrCpyN(m_szUser, sa.szUser, ARRAYSIZE(m_szUser));
  95. }
  96. return(hr);
  97. }
  98. INT_PTR CALLBACK SelectAth16UserDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  99. {
  100. HWND hwndT;
  101. WORD id;
  102. DWORD cb;
  103. char sz[MAX_PATH];
  104. SELATH16INFO *psa;
  105. int index;
  106. TCHAR szSections[1000];
  107. TCHAR szUserName[256];
  108. int nCount = 0;
  109. int nOldStop = 0;
  110. int nLength = 0;
  111. switch (msg)
  112. {
  113. case WM_INITDIALOG:
  114. Assert(lParam != NULL);
  115. psa = (SELATH16INFO *)lParam;
  116. SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)psa);
  117. hwndT = GetDlgItem(hwnd, IDC_USERLIST);
  118. // fill list
  119. cb = sizeof(sz);
  120. if(GetPrivateProfileString(c_szUsers, NULL, c_szEmpty, szSections, 1000, psa->szFile) != NULL)
  121. {
  122. StrCpyN(szUserName, (const char*)&szSections[nCount], ARRAYSIZE(szUserName)); // Copies the string up to the first NULL
  123. nLength = lstrlen(szUserName);
  124. do
  125. {
  126. SendMessage(hwndT, LB_ADDSTRING, 0, (LPARAM)szUserName);
  127. nCount += (nLength + 1);
  128. StrCpyN(szUserName, (const char*)&szSections[nCount], ARRAYSIZE(szUserName)); // Copies the string up to the first NULL
  129. nLength = lstrlen(szUserName);
  130. }while(nLength);
  131. }
  132. SendMessage(hwndT, LB_SETCURSEL, 0, 0);
  133. return(TRUE);
  134. case WM_COMMAND:
  135. id = LOWORD(wParam);
  136. switch (id)
  137. {
  138. case IDOK:
  139. psa = (SELATH16INFO *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  140. Assert(psa != NULL);
  141. hwndT = GetDlgItem(hwnd, IDC_USERLIST);
  142. index = (int) SendMessage(hwndT, LB_GETCURSEL, 0, 0);
  143. Assert(index >= 0);
  144. SendMessage(hwndT, LB_GETTEXT, (WPARAM)index, (LPARAM)psa->szUser);
  145. // fall through
  146. case IDCANCEL:
  147. EndDialog(hwnd, id);
  148. return(TRUE);
  149. }
  150. break;
  151. }
  152. return(FALSE);
  153. }
  154. HRESULT CAthena16Import::GetDirectory(char *szDir, UINT cch)
  155. {
  156. HRESULT hr = S_FALSE;
  157. Assert(szDir != NULL);
  158. if (*m_szUser != 0)
  159. hr = GetUserDir(szDir, cch);
  160. if (FAILED(hr))
  161. *szDir = 0;
  162. return(S_OK);
  163. }
  164. HRESULT CAthena16Import::GetUserDir(char *szDir, UINT cch)
  165. {
  166. HRESULT hr;
  167. Assert(lstrlen(m_szUser));
  168. if(GetPrivateProfileString(c_szUsers, m_szUser, c_szEmpty, szDir, cch, m_szIniFile) != NULL)
  169. {
  170. StrCatBuff(szDir, c_szFoldersDir,cch);
  171. hr = S_OK;
  172. }
  173. else
  174. hr = S_FALSE;
  175. return hr;
  176. }
  177. HRESULT CAthena16Import::SetDirectory(char *szDir)
  178. {
  179. HRESULT hr;
  180. Assert(szDir != NULL);
  181. // CAN WE DO SOMETHING TO VALIDATE THIS MAIL DIRECTORY!!!
  182. if (m_plist != NULL)
  183. {
  184. EudoraFreeFolderList(m_plist);
  185. m_plist = NULL;
  186. }
  187. hr=GetAthSubFolderList(szDir, &m_plist, NULL);
  188. return(hr);
  189. }
  190. HRESULT CAthena16Import::EnumerateFolders(DWORD_PTR dwCookie, IEnumFOLDERS **ppEnum)
  191. {
  192. CAthena16FOLDERS *pEnum;
  193. EUDORANODE *pnode;
  194. Assert(ppEnum != NULL);
  195. *ppEnum = NULL;
  196. if (dwCookie == COOKIE_ROOT)
  197. pnode = m_plist;
  198. else
  199. pnode = ((EUDORANODE *)dwCookie)->pchild;
  200. if (pnode == NULL)
  201. return(S_FALSE);
  202. pEnum = new CAthena16FOLDERS(pnode);
  203. if (pEnum == NULL)
  204. return(E_OUTOFMEMORY);
  205. *ppEnum = pEnum;
  206. return(S_OK);
  207. }
  208. STDMETHODIMP CAthena16Import::ImportFolder(DWORD_PTR dwCookie, IFolderImport *pImport)
  209. {
  210. HRESULT hr=S_OK;
  211. EUDORANODE* pNode = NULL;
  212. pNode = (EUDORANODE*)dwCookie;
  213. hr=ProcessMessages(pNode->szFile, ARRAYSIZE(pNode->szFile), pImport);
  214. return hr;
  215. }
  216. CAthena16FOLDERS::CAthena16FOLDERS(EUDORANODE *plist)
  217. {
  218. Assert(plist != NULL);
  219. m_cRef = 1;
  220. m_plist = plist;
  221. m_pnext = plist;
  222. }
  223. CAthena16FOLDERS::~CAthena16FOLDERS()
  224. {
  225. }
  226. ULONG CAthena16FOLDERS::AddRef()
  227. {
  228. m_cRef++;
  229. return(m_cRef);
  230. }
  231. ULONG CAthena16FOLDERS::Release()
  232. {
  233. ULONG cRef;
  234. cRef = --m_cRef;
  235. if (cRef == 0)
  236. delete this;
  237. return(cRef);
  238. }
  239. HRESULT CAthena16FOLDERS::QueryInterface(REFIID riid, LPVOID *ppv)
  240. {
  241. HRESULT hr = S_OK;
  242. if (ppv == NULL)
  243. return(E_INVALIDARG);
  244. *ppv = NULL;
  245. if (IID_IEnumFOLDERS == riid)
  246. *ppv = (IEnumFOLDERS *)this;
  247. else if (IID_IUnknown == riid)
  248. *ppv = (IUnknown *)this;
  249. else
  250. hr = E_NOINTERFACE;
  251. if (*ppv != NULL)
  252. ((LPUNKNOWN)*ppv)->AddRef();
  253. return(hr);
  254. }
  255. HRESULT CAthena16FOLDERS::Next(IMPORTFOLDER *pfldr)
  256. {
  257. Assert(pfldr != NULL);
  258. if (m_pnext == NULL)
  259. return(S_FALSE);
  260. ZeroMemory(pfldr, sizeof(IMPORTFOLDER));
  261. pfldr->dwCookie = (DWORD_PTR)m_pnext;
  262. StrCpyN(pfldr->szName, m_pnext->szName, ARRAYSIZE(pfldr->szName));
  263. pfldr->type = m_pnext->type;
  264. pfldr->fSubFolders = (m_pnext->pchild != NULL);
  265. m_pnext = m_pnext->pnext;
  266. return(S_OK);
  267. }
  268. HRESULT CAthena16FOLDERS::Reset()
  269. {
  270. m_pnext = m_plist;
  271. return(S_OK);
  272. }
  273. HRESULT GetAthSubFolderList(LPTSTR szInstallPath, EUDORANODE **ppList, EUDORANODE *pParent)
  274. {
  275. HRESULT hr= S_OK;
  276. EUDORANODE *pNode=NULL,
  277. *pNew=NULL,
  278. *pLast=NULL;
  279. EUDORANODE *pPrevious=NULL;
  280. EUDORANODE *ptemp=NULL;
  281. BOOL Flag=TRUE;
  282. BOOL child=TRUE;
  283. TCHAR szInstallPathNew[MAX_PATH];
  284. TCHAR szInstallPathCur[MAX_PATH];
  285. WIN32_FIND_DATA fFindData;
  286. HANDLE hnd=NULL;
  287. wnsprintf(szInstallPathCur, ARRAYSIZE(szInstallPathCur), c_szPathFileFmt, szInstallPath, c_szAsterisk);
  288. hnd = FindFirstFile(szInstallPathCur, &fFindData);
  289. if (hnd == INVALID_HANDLE_VALUE)
  290. return(E_FAIL);
  291. do {
  292. if((fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  293. {
  294. if(!lstrcmpi(fFindData.cFileName, c_szDot) || !lstrcmpi(fFindData.cFileName, c_szDotDot))
  295. continue;// Do not process the system dirs!
  296. if (!MemAlloc((void **)&pNew, sizeof(EUDORANODE)))
  297. goto err;
  298. ZeroMemory(pNew, sizeof(EUDORANODE));
  299. StrCpyN(pNew->szName, fFindData.cFileName, ARRAYSIZE(pNew->szName));
  300. wnsprintf(szInstallPathNew, ARRAYSIZE(szInstallPathNew), c_szPathFileFmt, szInstallPath, fFindData.cFileName);
  301. StrCpyN(pNew->szFile, szInstallPathNew, ARRAYSIZE(pNew->szFile));
  302. pNew->pparent= pParent;
  303. pNew->depth = (pParent != NULL) ? pParent->depth + 1 : 0;
  304. if(pNode == NULL)
  305. pNode = pNew;
  306. pLast = pNew;
  307. if(Flag)
  308. pPrevious=pNew;
  309. else
  310. {
  311. if(pPrevious)
  312. {
  313. pPrevious->pnext=pNew;
  314. pPrevious=pNew;
  315. }
  316. }
  317. if(child)
  318. {
  319. if(pParent)
  320. pParent->pchild=pNew;
  321. child=FALSE;
  322. }
  323. GetAthSubFolderList(szInstallPathNew, &pNew->pchild,pNew);
  324. Flag = FALSE;
  325. }
  326. }while(FindNextFile(hnd, &fFindData));
  327. *ppList = pNode;
  328. err:
  329. if(hnd)
  330. FindClose(hnd);
  331. hnd=NULL;
  332. return hr;
  333. }
  334. HRESULT ProcessMessages(LPSTR szFileName, DWORD cchFileName, IFolderImport *pImport)
  335. {
  336. HANDLE hFile=NULL;
  337. long uCount=0;
  338. long i=0;
  339. HRESULT hr=S_OK;
  340. TCHAR szpath[MAX_PATH];
  341. ULONG cError=0;
  342. StrCpyN(szpath, szFileName, cchFileName);
  343. StrCatBuff(szFileName,c_szMsgListFile, cchFileName);
  344. hFile = CreateFile(szFileName,
  345. GENERIC_READ,
  346. 0,
  347. NULL,
  348. OPEN_EXISTING,
  349. FILE_ATTRIBUTE_NORMAL,
  350. NULL);
  351. if (INVALID_HANDLE_VALUE == hFile)
  352. return(hrNoMessages);
  353. uCount = GetMessageCount(hFile);
  354. if (uCount > 0)
  355. {
  356. pImport->SetMessageCount(uCount);
  357. for (i = 0; i < uCount; i++)
  358. {
  359. hr = ProcessMsgList(hFile, szpath, pImport);
  360. if (hr == hrMemory || hr == hrUserCancel)
  361. break;
  362. if (hr != S_OK)
  363. cError++;
  364. }
  365. }
  366. CloseHandle(hFile);
  367. if ((cError) && SUCCEEDED(hr))
  368. hr = hrCorruptMessage;
  369. return(hr);
  370. }
  371. /******************************************************************************
  372. * FUNCTION NAME:GetMessageCount
  373. *
  374. * PURPOSE:To Get a count of number of messages inside a folder.
  375. *
  376. * PARAMETERS:
  377. *
  378. * IN: Handle of the msg_list(index) file.
  379. *
  380. * OUT:
  381. *
  382. * RETURNS: LONG value which contains number of messages in a folder.
  383. ******************************************************************************/
  384. long GetMessageCount(HANDLE hFile)
  385. {
  386. MsgHeader msg;
  387. ULONG ulRead;
  388. if(!ReadFile(hFile, &msg.ver, 1,&ulRead,NULL))
  389. return(0);
  390. if(!ReadFile(hFile, &msg.TotalMessages, 4,&ulRead,NULL))
  391. return(0);
  392. if(!ReadFile(hFile, &msg.ulTotalUnread, 4,&ulRead,NULL))
  393. return(0);
  394. return(msg.TotalMessages);
  395. }
  396. /******************************************************************************
  397. * FUNCTION NAME:ProcessMsgList
  398. *
  399. * PURPOSE:To Get the Athena16 Folders List
  400. *
  401. * PARAMETERS:
  402. *
  403. * IN: Handle of the msg_list(index) file, Handle and Current folder path.
  404. *
  405. * OUT:
  406. *
  407. * RETURNS: HRESULT
  408. ******************************************************************************/
  409. HRESULT ProcessMsgList(HANDLE hFile, LPSTR szPath, IFolderImport* pImport)
  410. {
  411. DWORD msgheader = 0;
  412. ULONG ulRead;
  413. LPSTR szmsgbuffer;
  414. HRESULT hResult = S_FALSE;
  415. if (!ReadFile(hFile, &msgheader, 2, &ulRead, NULL))
  416. return(0);
  417. if (!MemAlloc((void **)&szmsgbuffer, msgheader + 1))
  418. return(E_OUTOFMEMORY);
  419. if (!ReadFile(hFile, (LPVOID)szmsgbuffer, msgheader, &ulRead, NULL))
  420. {
  421. hResult = hrReadFile;
  422. }
  423. else
  424. {
  425. szmsgbuffer[msgheader] = 0;
  426. hResult = ParseMsgBuffer(szmsgbuffer, szPath, pImport);
  427. }
  428. MemFree(szmsgbuffer);
  429. return(hResult);
  430. }
  431. /******************************************************************************
  432. * FUNCTION NAME:ParseMsgBuffer
  433. *
  434. * PURPOSE:To Get the Athena16 Folders List
  435. *
  436. * PARAMETERS:
  437. *
  438. * IN: Handle,current folder path,buffer which contains the msg_list file.
  439. *
  440. * OUT:
  441. *
  442. * RETURNS: HRESULT
  443. ******************************************************************************/
  444. HRESULT ParseMsgBuffer(LPSTR szmsgbuffer, LPSTR szPath, IFolderImport *pImport)
  445. {
  446. char szfilename[MAX_PATH];
  447. char temp[MAX_PATH];
  448. HRESULT hResult = S_OK;
  449. DWORD dwFlags = 0;
  450. GetMsgFileName(szmsgbuffer, szfilename, ARRAYSIZE(szfilename));
  451. if (szmsgbuffer[9] == 'N')
  452. dwFlags = MSG_STATE_UNREAD;
  453. wnsprintf(temp, ARRAYSIZE(temp), c_szPathFileFmt, szPath, szfilename);
  454. hResult = ProcessSingleMessage(temp, dwFlags, pImport);
  455. return(hResult);
  456. }
  457. HRESULT ProcessSingleMessage(LPTSTR szFilePath, DWORD dwFlags, IFolderImport* pImport)
  458. {
  459. LPSTREAM lpstm = NULL;
  460. ULONG ulFileSize, cbMsg;
  461. ULONG ulRead;
  462. HANDLE mapMsg, hMsg;
  463. BYTE *pByteBuffer = NULL;
  464. HRESULT hResult = S_FALSE;
  465. hMsg = CreateFile(szFilePath, GENERIC_READ, FILE_SHARE_READ, NULL,
  466. OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  467. if (hMsg == INVALID_HANDLE_VALUE)
  468. return(S_FALSE);
  469. cbMsg = GetFileSize(hMsg, NULL);
  470. if (cbMsg > 0)
  471. {
  472. mapMsg = CreateFileMapping(hMsg, NULL, PAGE_READONLY, 0, 0, NULL);
  473. if (mapMsg != NULL)
  474. {
  475. pByteBuffer = (BYTE *)MapViewOfFile(mapMsg, FILE_MAP_READ, 0, 0, 0);
  476. if (pByteBuffer != NULL)
  477. {
  478. hResult = HrByteToStream(&lpstm, (LPBYTE)pByteBuffer, cbMsg);
  479. if (SUCCEEDED(hResult))
  480. {
  481. Assert(lpstm != NULL);
  482. hResult = pImport->ImportMessage(MSG_TYPE_MAIL, dwFlags, lpstm, NULL, 0);
  483. lpstm->Release();
  484. }
  485. UnmapViewOfFile(pByteBuffer);
  486. }
  487. CloseHandle(mapMsg);
  488. }
  489. }
  490. CloseHandle(hMsg);
  491. return(hResult);
  492. }
  493. /******************************************************************************
  494. * FUNCTION NAME:GetMsgFileName
  495. *
  496. * PURPOSE:Get the file name of each message from msg_list file.
  497. *
  498. * PARAMETERS:
  499. *
  500. * IN: buffer which contains msg_list file
  501. *
  502. * OUT: File name of a message file.
  503. *
  504. * RETURNS: HRESULT
  505. ******************************************************************************/
  506. HRESULT GetMsgFileName(LPCSTR szmsgbuffer, char *szfilename, DWORD cchFileName)
  507. {
  508. ULONG i, ul;
  509. StrCpyN(szfilename, szmsgbuffer, cchFileName);
  510. szfilename[10] = 0;
  511. ul = lstrlen(szfilename);
  512. Assert(ul == 10);
  513. Assert(szfilename[8] == 0x01);
  514. szfilename[9] = szfilename[9] & 0x7f; // turn off the highbit which is used to indicate attachment
  515. if (szfilename[9] == ' ')
  516. szfilename[8] = 0;
  517. else
  518. szfilename[8] = '.';
  519. return(S_OK);
  520. }
  521. int GetNumUsers(char *szFile, char *szUser, DWORD cchUser)
  522. {
  523. TCHAR szSections[1000];
  524. int nCount = 0;
  525. int nLoop = 0;
  526. if (GetPrivateProfileString(c_szUsers, NULL, c_szEmpty, szSections, ARRAYSIZE(szSections), szFile) > 0)
  527. {
  528. StrCpyN(szUser, szSections, cchUser);
  529. while (nLoop < ARRAYSIZE(szSections))
  530. {
  531. if(szSections[nLoop] == 0)
  532. {
  533. if(szSections[nLoop+1] == 0)
  534. {
  535. nCount++;
  536. return nCount;
  537. }
  538. else
  539. nCount++;
  540. }
  541. nLoop++;
  542. }
  543. }
  544. return nCount;
  545. }
  546. HRESULT GetIniFilePath(SELATH16INFO *pSelAth, HWND hwnd)
  547. {
  548. int nRet = 0;
  549. HRESULT hr;
  550. WIN32_FIND_DATA pWinFind;
  551. if(FindFirstFile(g_Athena16Mail, &pWinFind) == INVALID_HANDLE_VALUE)
  552. {
  553. nRet = (int) DialogBoxParam(g_hInstImp, MAKEINTRESOURCE(iddProvideMailPath), hwnd, ProvideIniPathProc, (LPARAM)pSelAth);
  554. if (nRet == IDCANCEL)
  555. hr = S_FALSE;
  556. else if (nRet == IDOK)
  557. hr = S_OK;
  558. else
  559. hr = E_FAIL;
  560. }
  561. else
  562. {
  563. StrCpyN(pSelAth->szFile, g_Athena16Mail, ARRAYSIZE(pSelAth->szFile));
  564. hr = S_OK;
  565. }
  566. return hr;
  567. }
  568. INT_PTR CALLBACK ProvideIniPathProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  569. {
  570. HWND hwndT;
  571. WORD id;
  572. SELATH16INFO *psa;
  573. int nCount = 0;
  574. WIN32_FIND_DATA pWinFind;
  575. OPENFILENAME ofn;
  576. TCHAR szFilter[CCHMAX_STRINGRES];
  577. TCHAR szFile[MAX_PATH];
  578. int nLen, i = 0;
  579. switch (uMsg)
  580. {
  581. case WM_INITDIALOG:
  582. Assert(lParam != NULL);
  583. psa = (SELATH16INFO *)lParam;
  584. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psa);
  585. return(TRUE);
  586. case WM_COMMAND:
  587. id = LOWORD(wParam);
  588. switch (id)
  589. {
  590. case IDOK:
  591. psa = (SELATH16INFO *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  592. Assert(psa != NULL);
  593. hwndT = GetDlgItem(hwndDlg, IDC_EDT1);
  594. nCount = (int) SendMessage(hwndT, WM_GETTEXT, MAX_PATH, (LPARAM)psa->szFile);
  595. if(nCount)
  596. {
  597. //Make sure that the file is valid
  598. if(FindFirstFile(psa->szFile, &pWinFind) != INVALID_HANDLE_VALUE)
  599. {
  600. EndDialog(hwndDlg, id);
  601. return TRUE;
  602. }
  603. }
  604. //No file was selected. Do not end the dialog. Put up a messagebox asking the user to slect a valid file.
  605. ImpMessageBox(hwndDlg, MAKEINTRESOURCE(idsImportTitle), MAKEINTRESOURCE(idsErrorMailIni), NULL, MB_OK | MB_ICONSTOP);
  606. return TRUE;
  607. // fall through
  608. case IDCANCEL:
  609. EndDialog(hwndDlg, id);
  610. return(TRUE);
  611. case IDC_BUTT1:
  612. *szFile = 0;
  613. // replace the '|' characters in the filter string with nulls.
  614. nCount = 0;
  615. nLen = LoadString(g_hInstImp, idsFilterMailIni, szFilter, ARRAYSIZE(szFilter));
  616. while (i < nLen)
  617. {
  618. if (szFilter[i] == '|')
  619. {
  620. szFilter[i] = '\0';
  621. nCount++;
  622. }
  623. i++;
  624. }
  625. ZeroMemory (&ofn, sizeof(ofn));
  626. ofn.lStructSize = sizeof(ofn);
  627. ofn.hwndOwner = hwndDlg;
  628. ofn.lpstrFilter = szFilter;
  629. ofn.nFilterIndex = 1;
  630. ofn.lpstrFile = szFile;
  631. ofn.nMaxFile = sizeof(szFile);
  632. ofn.Flags = OFN_NOCHANGEDIR | OFN_NOREADONLYRETURN | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  633. if(GetOpenFileName(&ofn))
  634. {
  635. hwndT = GetDlgItem(hwndDlg, IDC_EDT1);
  636. SendMessage(hwndT, WM_SETTEXT, MAX_PATH, (LPARAM)szFile);
  637. }
  638. return TRUE;
  639. }
  640. break;
  641. }
  642. return(FALSE);
  643. }