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.

1509 lines
36 KiB

  1. /*++
  2. Copyright (c) 1993-1995 Microsoft Corporation
  3. Module Name:
  4. nwconv.c
  5. Abstract:
  6. Author:
  7. Arthur Hanson (arth) 16-Jun-1994
  8. Revision History:
  9. --*/
  10. #include "globals.h"
  11. #include "nwconv.h"
  12. #include "convapi.h"
  13. #include "userdlg.h"
  14. #include "filedlg.h"
  15. #include "transfer.h"
  16. #include "columnlb.h"
  17. #include "ntnetapi.h"
  18. #include "nwnetapi.h"
  19. HINSTANCE hInst; // current instance
  20. TCHAR szAppName[] = TEXT("NWConv"); // The name of this application
  21. TCHAR ProgPath[MAX_PATH + 1];
  22. TCHAR NT_PROVIDER[60];
  23. TCHAR NW_PROVIDER[60];
  24. TCHAR NW_SERVICE_NAME[80];
  25. #define DEF_CONFIG_FILE TEXT("NWConv.DAT")
  26. // version as x.yz expressed as xyz (no decimal point).
  27. #define CONFIG_VER 026
  28. #define CHECK_CONST 0xA5A56572
  29. SOURCE_SERVER_BUFFER *lpSourceServer;
  30. DEST_SERVER_BUFFER *lpDestServer;
  31. BOOL TrialConversion = TRUE;
  32. BOOL IsNetWareBrowse;
  33. BOOL FirstTime = TRUE;
  34. HICON MyIcon;
  35. UINT NumServerPairs = 0;
  36. HWND hDlgMain;
  37. HHOOK hhkMsgFilter = NULL;
  38. UINT wHelpMessage;
  39. UINT uMenuID;
  40. HMENU hMenu;
  41. UINT uMenuFlags;
  42. #ifdef DEBUG
  43. int DebugFlag = 0;
  44. #endif
  45. CONVERT_LIST *ConvertListStart = NULL;
  46. CONVERT_LIST *ConvertListEnd = NULL;
  47. CONVERT_LIST *CurrentConvertList = NULL;
  48. int TotalConvertCount = 0;
  49. SOURCE_SERVER_BUFFER *SServListStart = NULL;
  50. SOURCE_SERVER_BUFFER *SServListEnd = NULL;
  51. SOURCE_SERVER_BUFFER *SServListCurrent = NULL;
  52. DEST_SERVER_BUFFER *DServListStart = NULL;
  53. DEST_SERVER_BUFFER *DServListEnd = NULL;
  54. DEST_SERVER_BUFFER *DServListCurrent = NULL;
  55. DOMAIN_BUFFER *DomainListStart = NULL;
  56. DOMAIN_BUFFER *DomainListEnd = NULL;
  57. BOOL SuccessfulConversion = FALSE;
  58. BOOL ViewLogs = FALSE;
  59. BOOL InConversion = FALSE;
  60. /*+-------------------------------------------------------------------------+
  61. | Function Prototypes. |
  62. +-------------------------------------------------------------------------+*/
  63. LRESULT CALLBACK DlgUsers(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  64. LRESULT CALLBACK DlgMoveIt(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  65. VOID AboutBox_Do(HWND hDlg);
  66. VOID ToggleControls(HWND hDlg, BOOL Toggle);
  67. /////////////////////////////////////////////////////////////////////////
  68. VOID NTServInfoDlg_SwitchControls(
  69. HWND hDlg,
  70. BOOL Toggle
  71. )
  72. /*++
  73. Routine Description:
  74. Arguments:
  75. Return Value:
  76. --*/
  77. {
  78. HWND hCtrl;
  79. // The NW Controls
  80. hCtrl = GetDlgItem(hDlg, IDC_T_VOLUMES);
  81. ShowWindow(hCtrl, Toggle);
  82. EnableWindow(hCtrl, Toggle);
  83. hCtrl = GetDlgItem(hDlg, IDC_LIST3);
  84. ShowWindow(hCtrl, Toggle);
  85. EnableWindow(hCtrl, Toggle);
  86. // The NT Controls
  87. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  88. ShowWindow(hCtrl, !Toggle);
  89. EnableWindow(hCtrl, !Toggle);
  90. hCtrl = GetDlgItem(hDlg, IDC_LIST2);
  91. ShowWindow(hCtrl, !Toggle);
  92. EnableWindow(hCtrl, !Toggle);
  93. hCtrl = GetDlgItem(hDlg, IDC_T_DRIVES);
  94. ShowWindow(hCtrl, !Toggle);
  95. EnableWindow(hCtrl, !Toggle);
  96. hCtrl = GetDlgItem(hDlg, IDC_T_SHARES);
  97. ShowWindow(hCtrl, !Toggle);
  98. EnableWindow(hCtrl, !Toggle);
  99. } // NTServInfoDlg_SwitchControls
  100. /////////////////////////////////////////////////////////////////////////
  101. VOID
  102. NTServInfoDlg_EnableNT(
  103. HWND hDlg
  104. )
  105. /*++
  106. Routine Description:
  107. Arguments:
  108. Return Value:
  109. --*/
  110. {
  111. TCHAR VerStr[TMP_STR_LEN_256];
  112. SetDlgItemText(hDlg, IDC_TYPE, Lids(IDS_S_15));
  113. wsprintf(VerStr, TEXT("%lu.%lu"), CurrentConvertList->FileServ->VerMaj, CurrentConvertList->FileServ->VerMin);
  114. SetDlgItemText(hDlg, IDC_VERSION, VerStr);
  115. NTServInfoDlg_SwitchControls(hDlg, FALSE);
  116. } // NTServInfoDlg_EnableNT
  117. /////////////////////////////////////////////////////////////////////////
  118. VOID
  119. NTServInfoDlg_EnableNW(
  120. HWND hDlg
  121. )
  122. /*++
  123. Routine Description:
  124. Arguments:
  125. Return Value:
  126. --*/
  127. {
  128. TCHAR VerStr[TMP_STR_LEN_256];
  129. SetDlgItemText(hDlg, IDC_TYPE, Lids(IDS_S_16));
  130. wsprintf(VerStr, TEXT("%u.%u"), CurrentConvertList->SourceServ->VerMaj, CurrentConvertList->SourceServ->VerMin);
  131. SetDlgItemText(hDlg, IDC_VERSION, VerStr);
  132. NTServInfoDlg_SwitchControls(hDlg, TRUE);
  133. } // NTServInfoDlg_EnableNW
  134. /////////////////////////////////////////////////////////////////////////
  135. LRESULT CALLBACK
  136. NTServInfoDlg(
  137. HWND hDlg,
  138. UINT message,
  139. WPARAM wParam,
  140. LPARAM lParam
  141. )
  142. /*++
  143. Routine Description:
  144. Arguments:
  145. Return Value:
  146. --*/
  147. {
  148. static TCHAR AddLine[TMP_STR_LEN_256];
  149. HWND hCtrl;
  150. UINT_PTR dwData, dwIndex;
  151. int wmId, wmEvent;
  152. ULONG i;
  153. DRIVE_LIST *DriveList;
  154. SHARE_LIST *ShareList;
  155. switch (message) {
  156. case WM_INITDIALOG:
  157. // Center the dialog over the application window
  158. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  159. // Add the servers to the combo-box and select the source server
  160. hCtrl = GetDlgItem(hDlg, IDC_COMBO1);
  161. dwIndex = SendMessage(hCtrl, CB_ADDSTRING, (WPARAM) 0, (LPARAM) CurrentConvertList->FileServ->Name);
  162. SendMessage(hCtrl, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) CurrentConvertList->FileServ);
  163. dwIndex = SendMessage(hCtrl, CB_ADDSTRING, (WPARAM) 0, (LPARAM) CurrentConvertList->SourceServ->Name);
  164. SendMessage(hCtrl, CB_SETITEMDATA, (WPARAM) dwIndex, (LPARAM) CurrentConvertList->SourceServ);
  165. SendMessage(hCtrl, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) CurrentConvertList->SourceServ->Name);
  166. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0L);
  167. return (TRUE);
  168. case WM_COMMAND:
  169. wmId = LOWORD(wParam);
  170. wmEvent = HIWORD(wParam);
  171. switch (wmId) {
  172. case IDOK:
  173. EndDialog(hDlg, 0);
  174. return (TRUE);
  175. break;
  176. case ID_INIT:
  177. // Fill in the Drive and share lists for NT system
  178. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  179. DriveList = CurrentConvertList->FileServ->DriveList;
  180. if (DriveList != NULL) {
  181. for (i = 0; i < DriveList->Count; i++) {
  182. wsprintf(AddLine, TEXT("%s: [%4s] %s"), DriveList->DList[i].Drive, DriveList->DList[i].DriveType, DriveList->DList[i].Name);
  183. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  184. wsprintf(AddLine, Lids(IDS_S_17), lToStr(DriveList->DList[i].FreeSpace));
  185. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  186. }
  187. }
  188. hCtrl = GetDlgItem(hDlg, IDC_LIST2);
  189. ShareList = CurrentConvertList->FileServ->ShareList;
  190. if (ShareList != NULL)
  191. for (i = 0; i < ShareList->Count; i++) {
  192. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) ShareList->SList[i].Name);
  193. wsprintf(AddLine, Lids(IDS_S_18), ShareList->SList[i].Path);
  194. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  195. }
  196. hCtrl = GetDlgItem(hDlg, IDC_LIST3);
  197. ShareList = CurrentConvertList->SourceServ->ShareList;
  198. if (ShareList != NULL)
  199. for (i = 0; i < ShareList->Count; i++) {
  200. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) ShareList->SList[i].Name);
  201. wsprintf(AddLine, Lids(IDS_S_19), lToStr(ShareList->SList[i].Size));
  202. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  203. }
  204. PostMessage(hDlg, WM_COMMAND, ID_UPDATECOMBO, 0L);
  205. break;
  206. case ID_UPDATECOMBO:
  207. hCtrl = GetDlgItem(hDlg, IDC_COMBO1);
  208. dwIndex = SendMessage(hCtrl, CB_GETCURSEL, 0, 0L);
  209. if (dwIndex != CB_ERR) {
  210. dwData = SendMessage(hCtrl, CB_GETITEMDATA, dwIndex, 0L);
  211. if (dwData == (UINT_PTR) CurrentConvertList->FileServ)
  212. NTServInfoDlg_EnableNT(hDlg);
  213. if (dwData == (UINT_PTR) CurrentConvertList->SourceServ)
  214. NTServInfoDlg_EnableNW(hDlg);
  215. }
  216. break;
  217. case IDC_COMBO1:
  218. if (wmEvent == CBN_SELCHANGE)
  219. PostMessage(hDlg, WM_COMMAND, ID_UPDATECOMBO, 0L);
  220. break;
  221. }
  222. break;
  223. }
  224. return (FALSE); // Didn't process the message
  225. lParam;
  226. } // NTServInfoDlg
  227. /////////////////////////////////////////////////////////////////////////
  228. VOID
  229. NTServInfoDlg_Do(
  230. HWND hDlg
  231. )
  232. /*++
  233. Routine Description:
  234. Arguments:
  235. Return Value:
  236. --*/
  237. {
  238. DLGPROC lpfnDlg;
  239. lpfnDlg = MakeProcInstance((DLGPROC)NTServInfoDlg, hInst);
  240. DialogBox(hInst, TEXT("NTServInfo"), hDlg, lpfnDlg) ;
  241. FreeProcInstance(lpfnDlg);
  242. } // NTServInfoDlg_Do
  243. /////////////////////////////////////////////////////////////////////////
  244. VOID
  245. MainListbox_Add(
  246. HWND hDlg,
  247. DWORD_PTR Data,
  248. LPTSTR SourceServ,
  249. LPTSTR DestServ
  250. )
  251. /*++
  252. Routine Description:
  253. Arguments:
  254. Return Value:
  255. --*/
  256. {
  257. TCHAR AddLine[256];
  258. CONVERT_LIST *ptr;
  259. CONVERT_LIST *nptr = NULL;
  260. DWORD_PTR dwData, ret;
  261. DWORD wItemNum = 0;
  262. HWND hCtrl;
  263. BOOL match = FALSE;
  264. ULONG_PTR nPairs;
  265. // We want to insert this after any any other conversion to this source
  266. // machine - unfortuantly it is cumbersome to do this.
  267. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  268. // start count at one less as it will always be one ahead of us
  269. nPairs = SendMessage(hCtrl, LB_GETCOUNT, 0, 0L);
  270. // Try to find a matching destination server for this in the listbox
  271. ptr = (CONVERT_LIST *) Data;
  272. while((wItemNum < nPairs) && !match) {
  273. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  274. if (dwData != LB_ERR) {
  275. nptr = (CONVERT_LIST *) dwData;
  276. if (!lstrcmpi(ptr->FileServ->Name, nptr->FileServ->Name))
  277. match = TRUE;
  278. }
  279. if (!match)
  280. wItemNum++;
  281. }
  282. if (match) {
  283. // have a match - so go to the end of the matching servers...
  284. while((wItemNum < nPairs) && match) {
  285. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  286. if (dwData != LB_ERR) {
  287. nptr = (CONVERT_LIST *) dwData;
  288. if (lstrcmpi(ptr->FileServ->Name, nptr->FileServ->Name))
  289. match = FALSE;
  290. }
  291. if (match)
  292. wItemNum++;
  293. }
  294. } else {
  295. if (ptr->FileServ->InDomain && ptr->FileServ->Domain) {
  296. wItemNum = 0;
  297. // No matching servers, so try to find matching domain
  298. while((wItemNum < nPairs) && !match) {
  299. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  300. if (dwData != LB_ERR) {
  301. nptr = (CONVERT_LIST *) dwData;
  302. if (nptr->FileServ->InDomain && nptr->FileServ->Domain)
  303. if (!lstrcmpi(ptr->FileServ->Domain->Name, nptr->FileServ->Domain->Name))
  304. match = TRUE;
  305. }
  306. if (!match)
  307. wItemNum++;
  308. }
  309. if (match) {
  310. // have a match - so go to the end of the matching domain...
  311. while((wItemNum < nPairs) && match) {
  312. dwData = ColumnLB_GetItemData(hCtrl, wItemNum);
  313. if (dwData != LB_ERR) {
  314. nptr = (CONVERT_LIST *) dwData;
  315. if (nptr->FileServ->InDomain && nptr->FileServ->Domain) {
  316. if (lstrcmpi(ptr->FileServ->Domain->Name, nptr->FileServ->Domain->Name))
  317. match = FALSE;
  318. } else
  319. match = FALSE;
  320. }
  321. if (match)
  322. wItemNum++;
  323. }
  324. }
  325. } // if domain
  326. }
  327. wsprintf(AddLine, TEXT("%s\t%s\t"), SourceServ, DestServ);
  328. wItemNum = ColumnLB_InsertString(hCtrl, wItemNum, AddLine);
  329. ret = ColumnLB_SetItemData(hCtrl, wItemNum, Data);
  330. ColumnLB_SetCurSel(hCtrl, wItemNum);
  331. } // MainListbox_Add
  332. /////////////////////////////////////////////////////////////////////////
  333. VOID
  334. ConfigurationReset(
  335. HWND hDlg
  336. )
  337. /*++
  338. Routine Description:
  339. Arguments:
  340. Return Value:
  341. --*/
  342. {
  343. // Remove the listbox entries
  344. ColumnLB_ResetContent(GetDlgItem(hDlg, IDC_LIST1));
  345. ToggleControls(hDlg, FALSE);
  346. SetFocus(GetDlgItem(hDlg, IDC_ADD));
  347. ConvertListDeleteAll();
  348. UserOptionsDefaultsReset();
  349. FileOptionsDefaultsReset();
  350. LogOptionsInit();
  351. } // ConfigurationReset
  352. /////////////////////////////////////////////////////////////////////////
  353. VOID
  354. ConfigurationSave(
  355. LPTSTR FileName
  356. )
  357. /*++
  358. Routine Description:
  359. Arguments:
  360. Return Value:
  361. --*/
  362. {
  363. DWORD wrote;
  364. HANDLE hFile;
  365. CHAR FileNameA[MAX_PATH + 1];
  366. DWORD Check, Ver;
  367. WideCharToMultiByte(CP_ACP, 0, FileName, -1, FileNameA, sizeof(FileNameA), NULL, NULL);
  368. // Create it no matter what
  369. hFile = CreateFileA( FileNameA, GENERIC_WRITE, 0,
  370. NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
  371. if (hFile != INVALID_HANDLE_VALUE) {
  372. // Save out our check value and the version info
  373. Check = CHECK_CONST;
  374. WriteFile(hFile, &Check, sizeof(Check), &wrote, NULL);
  375. Ver = CONFIG_VER;
  376. WriteFile(hFile, &Ver, sizeof(Ver), &wrote, NULL);
  377. // Save global log file options
  378. LogOptionsSave(hFile);
  379. // Save out convert Lists
  380. ConvertListSaveAll(hFile);
  381. }
  382. if (hFile != INVALID_HANDLE_VALUE)
  383. CloseHandle(hFile);
  384. return;
  385. } // ConfigurationSave
  386. /////////////////////////////////////////////////////////////////////////
  387. VOID
  388. ConfigurationLoad(
  389. HWND hDlg,
  390. LPTSTR FileName
  391. )
  392. /*++
  393. Routine Description:
  394. Arguments:
  395. Return Value:
  396. --*/
  397. {
  398. static TCHAR AddLine[256];
  399. DWORD wrote;
  400. HANDLE hFile;
  401. CHAR FileNameA[MAX_PATH + 1];
  402. DWORD Check, Ver;
  403. WideCharToMultiByte(CP_ACP, 0, FileName, -1, FileNameA, sizeof(FileNameA), NULL, NULL);
  404. // Open, but fail if already exists.
  405. hFile = CreateFileA( FileNameA, GENERIC_READ, 0,
  406. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  407. if (hFile != INVALID_HANDLE_VALUE) {
  408. ConfigurationReset(hDlg);
  409. ReadFile(hFile, &Check, sizeof(Check), &wrote, NULL);
  410. if (Check != CHECK_CONST) {
  411. CloseHandle(hFile);
  412. ErrorBox(Lids(IDS_E_10));
  413. return;
  414. }
  415. ReadFile(hFile, &Ver, sizeof(Ver), &wrote, NULL);
  416. if (Ver != CONFIG_VER) {
  417. CloseHandle(hFile);
  418. ErrorBox(Lids(IDS_E_11));
  419. return;
  420. }
  421. LogOptionsLoad(hFile);
  422. // Load in convert list and all associated info...
  423. ConvertListLoadAll(hFile);
  424. // Everything from the file is loaded in - but now the painful part
  425. // begins. We need to take the following steps:
  426. //
  427. // 1. Walk all lists and refix pointers from their index
  428. // 2. Re-Validate servers, shares, domains, etc. to make sure they
  429. // haven't changed underneath us since we saved out the file.
  430. // 3. Re-create info that wasn't saved out (like drive lists).
  431. // 1. Walk and refix lists
  432. ConvertListFixup(hDlg);
  433. // Now add them to the listbox
  434. CurrentConvertList = ConvertListStart;
  435. while (CurrentConvertList) {
  436. MainListbox_Add(hDlg, (DWORD_PTR) CurrentConvertList, CurrentConvertList->SourceServ->Name, CurrentConvertList->FileServ->Name);
  437. CurrentConvertList = CurrentConvertList->next;
  438. }
  439. // Re-enable all the toggles
  440. if (NumServerPairs)
  441. PostMessage(hDlg, WM_COMMAND, (WPARAM) IDM_ADDSEL, 0);
  442. }
  443. if (hFile != INVALID_HANDLE_VALUE)
  444. CloseHandle(hFile);
  445. return;
  446. } // ConfigurationLoad
  447. /////////////////////////////////////////////////////////////////////////
  448. VOID
  449. CanonServerName(
  450. LPTSTR ServerName
  451. )
  452. /*++
  453. Routine Description:
  454. Arguments:
  455. Return Value:
  456. --*/
  457. {
  458. LPTSTR TmpStr = ServerName;
  459. while (*TmpStr == TEXT('\\'))
  460. TmpStr++;
  461. lstrcpy(ServerName, TmpStr);
  462. } // CanonServerName
  463. /////////////////////////////////////////////////////////////////////////
  464. int
  465. MessageFilter(
  466. INT nCode,
  467. WPARAM wParam,
  468. LPMSG lpMsg
  469. )
  470. /*++
  471. Routine Description:
  472. Arguments:
  473. Return Value:
  474. --*/
  475. {
  476. if (nCode < 0)
  477. goto DefHook;
  478. if (nCode == MSGF_MENU) {
  479. if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1) {
  480. // Window of menu we want help for is in loword of lParam.
  481. PostMessage(hDlgMain, wHelpMessage, MSGF_MENU, (LPARAM)lpMsg->hwnd);
  482. return 1;
  483. }
  484. }
  485. else
  486. if (nCode == MSGF_DIALOGBOX) {
  487. if (lpMsg->message == WM_KEYDOWN && lpMsg->wParam == VK_F1) {
  488. // Dialog box we want help for is in loword of lParam
  489. PostMessage(hDlgMain, wHelpMessage, MSGF_DIALOGBOX, (LPARAM)lpMsg->hwnd);
  490. return 1;
  491. }
  492. } else
  493. DefHook:
  494. return (INT)DefHookProc(nCode, wParam, (DWORD_PTR)lpMsg, &hhkMsgFilter);
  495. return 0;
  496. } // MessageFilter
  497. /////////////////////////////////////////////////////////////////////////
  498. int APIENTRY
  499. WinMain(
  500. HINSTANCE hInstance,
  501. HINSTANCE hPrevInstance,
  502. LPSTR lpCmdLine,
  503. int nCmdShow
  504. )
  505. /*++
  506. Routine Description:
  507. Arguments:
  508. Return Value:
  509. --*/
  510. {
  511. LPTSTR ptr;
  512. DLGPROC lpproc;
  513. HACCEL haccel;
  514. MSG msg;
  515. hInst = hInstance;
  516. if (!hPrevInstance) {
  517. BookTab_Initialize(hInst);
  518. ColumnLBClass_Register(hInst);
  519. }
  520. MultiByteToWideChar(CP_ACP, 0, _pgmptr, -1, ProgPath, sizeof(ProgPath) );
  521. // go to the end and rewind to remove program name
  522. ptr = ProgPath;
  523. while (*ptr)
  524. ptr++;
  525. while (*ptr != TEXT('\\'))
  526. ptr--;
  527. ptr++;
  528. *ptr = TEXT('\0');
  529. MemInit();
  530. MyIcon = LoadIcon(hInst, szAppName);
  531. lpproc = MakeProcInstance((DLGPROC) DlgMoveIt, hInst);
  532. hDlgMain = CreateDialog(hInst, szAppName, NULL, lpproc);
  533. wHelpMessage = RegisterWindowMessage(TEXT("ShellHelp"));
  534. haccel = LoadAccelerators(hInst, TEXT("MainAcc"));
  535. hhkMsgFilter = SetWindowsHook(WH_MSGFILTER, (HOOKPROC)MessageFilter);
  536. while (GetMessage(&msg, NULL, 0, 0)) {
  537. if (!TranslateAccelerator(hDlgMain, haccel, &msg))
  538. if ((hDlgMain == 0) || !IsDialogMessage(hDlgMain, &msg)) {
  539. TranslateMessage(&msg);
  540. DispatchMessage(&msg);
  541. }
  542. }
  543. FreeProcInstance(lpproc);
  544. ColumnLBClass_Unregister(hInst);
  545. DestroyIcon(MyIcon);
  546. StringTableDestroy();
  547. return (int) msg.wParam;
  548. } // WinMain
  549. /////////////////////////////////////////////////////////////////////////
  550. VOID
  551. ToggleControls(
  552. HWND hDlg,
  553. BOOL Toggle
  554. )
  555. /*++
  556. Routine Description:
  557. Arguments:
  558. Return Value:
  559. --*/
  560. {
  561. HWND hCtrl;
  562. hCtrl = GetDlgItem(hDlg, IDOK);
  563. EnableWindow(hCtrl, Toggle);
  564. hCtrl = GetDlgItem(hDlg, IDC_TRIAL);
  565. EnableWindow(hCtrl, Toggle);
  566. hCtrl = GetDlgItem(hDlg, IDC_DELETE);
  567. EnableWindow(hCtrl, Toggle);
  568. hCtrl = GetDlgItem(hDlg, IDC_USERINF);
  569. EnableWindow(hCtrl, Toggle);
  570. hCtrl = GetDlgItem(hDlg, IDC_FILEINF);
  571. EnableWindow(hCtrl, Toggle);
  572. } // ToggleControls
  573. /////////////////////////////////////////////////////////////////////////
  574. DWORD
  575. ConfigFileGet(
  576. HWND hwnd
  577. )
  578. /*++
  579. Routine Description:
  580. Arguments:
  581. Return Value:
  582. --*/
  583. {
  584. OPENFILENAME ofn;
  585. TCHAR szDirName[MAX_PATH+1];
  586. TCHAR szFile[256], szFileTitle[256];
  587. UINT i, cbString;
  588. TCHAR chReplace;
  589. TCHAR szFilter[256];
  590. LPTSTR szExt = TEXT("CNF");
  591. lstrcpy(szDirName, ProgPath);
  592. lstrcpy(szFile, TEXT(""));
  593. if ((cbString = LoadString(hInst, IDS_MAINFILTERSTRING, szFilter, sizeof(szFilter))) == 0) {
  594. // Error occured
  595. return 1L;
  596. }
  597. chReplace = szFilter[cbString - 1]; // Retrieve wild character
  598. for (i = 0; szFilter[i] != TEXT('\0'); i++) {
  599. if (szFilter[i] == chReplace)
  600. szFilter[i] = TEXT('\0');
  601. }
  602. // Set all structure members to zero
  603. memset(&ofn, 0, sizeof(OPENFILENAME));
  604. ofn.lStructSize = sizeof(OPENFILENAME);
  605. ofn.hwndOwner = hwnd;
  606. ofn.lpstrFilter = szFilter;
  607. ofn.nFilterIndex = 1;
  608. ofn.lpstrFile = szFile;
  609. ofn.nMaxFile = sizeof(szFile);
  610. ofn.lpstrFileTitle = szFileTitle;
  611. ofn.nMaxFileTitle = sizeof(szFileTitle);
  612. ofn.lpstrInitialDir = szDirName;
  613. ofn.lpstrDefExt = szExt;
  614. ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;
  615. if (GetOpenFileName(&ofn)) {
  616. // Load the configuration
  617. ConfigurationLoad(hwnd, ofn.lpstrFile);
  618. return 0L;
  619. } else {
  620. // Couldn't open the dang file
  621. return 1L;
  622. }
  623. } // ConfigFileGet
  624. /////////////////////////////////////////////////////////////////////////
  625. DWORD
  626. ConfigFileSave(
  627. HWND hwnd
  628. )
  629. /*++
  630. Routine Description:
  631. Arguments:
  632. Return Value:
  633. --*/
  634. {
  635. OPENFILENAME ofn;
  636. TCHAR szDirName[MAX_PATH + 1];
  637. TCHAR szFile[MAX_PATH + 1], szFileTitle[MAX_PATH + 1];
  638. UINT i, cbString;
  639. TCHAR chReplace;
  640. TCHAR szFilter[256];
  641. LPTSTR szExt;
  642. szExt = Lids(IDS_S_20);
  643. lstrcpy(szDirName, ProgPath);
  644. lstrcpy(szFile, TEXT(""));
  645. if ((cbString = LoadString(hInst, IDS_MAINFILTERSTRING, szFilter, sizeof(szFilter))) == 0) {
  646. // Error occured
  647. return 1L;
  648. }
  649. chReplace = szFilter[cbString - 1]; // Retrieve wild character
  650. for (i = 0; szFilter[i] != TEXT('\0'); i++) {
  651. if (szFilter[i] == chReplace)
  652. szFilter[i] = TEXT('\0');
  653. }
  654. // Set all structure members to zero
  655. memset(&ofn, 0, sizeof(OPENFILENAME));
  656. ofn.lStructSize = sizeof(OPENFILENAME);
  657. ofn.hwndOwner = hwnd;
  658. ofn.lpstrFilter = szFilter;
  659. ofn.nFilterIndex = 1;
  660. ofn.lpstrFile = szFile;
  661. ofn.nMaxFile = sizeof(szFile);
  662. ofn.lpstrFileTitle = szFileTitle;
  663. ofn.nMaxFileTitle = sizeof(szFileTitle);
  664. ofn.lpstrInitialDir = szDirName;
  665. ofn.lpstrDefExt = szExt;
  666. ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  667. if (GetSaveFileName(&ofn)) {
  668. // Save Configuration
  669. ConfigurationSave( ofn.lpstrFile);
  670. return 0L;
  671. } else {
  672. // Couldn't save it
  673. return 1L;
  674. }
  675. } // ConfigFileSave
  676. /////////////////////////////////////////////////////////////////////////
  677. BOOL
  678. ProvidersInit()
  679. /*++
  680. Routine Description:
  681. Arguments:
  682. Return Value:
  683. --*/
  684. {
  685. HKEY hKey;
  686. DWORD dwType, dwSize;
  687. LONG Status;
  688. BOOL ret = FALSE;
  689. dwSize = sizeof(NW_PROVIDER);
  690. if ((Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Lids(IDS_S_23), 0, KEY_READ, &hKey)) == ERROR_SUCCESS)
  691. if ((Status = RegQueryValueEx(hKey, Lids(IDS_S_21), NULL, &dwType, (LPBYTE) NW_PROVIDER, &dwSize)) == ERROR_SUCCESS)
  692. ret = TRUE;
  693. RegCloseKey(hKey);
  694. if (ret) {
  695. ret = FALSE;
  696. hKey = 0;
  697. dwSize = sizeof(NT_PROVIDER);
  698. if ((Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Lids(IDS_S_25), 0, KEY_READ, &hKey)) == ERROR_SUCCESS)
  699. if ((Status = RegQueryValueEx(hKey, Lids(IDS_S_21), NULL, &dwType, (LPBYTE) NT_PROVIDER, &dwSize)) == ERROR_SUCCESS)
  700. ret = TRUE;
  701. RegCloseKey(hKey);
  702. }
  703. if (ret) {
  704. ret = FALSE;
  705. hKey = 0;
  706. dwSize = sizeof(NW_SERVICE_NAME);
  707. if ((Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, Lids(IDS_S_24), 0, KEY_READ, &hKey)) == ERROR_SUCCESS)
  708. if ((Status = RegQueryValueEx(hKey, Lids(IDS_S_22), NULL, &dwType, (LPBYTE) Lids(IDS_S_24), &dwSize)) == ERROR_SUCCESS)
  709. ret = TRUE;
  710. RegCloseKey(hKey);
  711. }
  712. return ret;
  713. } // ProvidersInit
  714. /////////////////////////////////////////////////////////////////////////
  715. BOOL
  716. CheckServiceInstall()
  717. /*++
  718. Routine Description:
  719. Arguments:
  720. Return Value:
  721. --*/
  722. {
  723. SC_HANDLE hSC;
  724. DWORD dwBytesNeeded, dwNumEntries, dwhResume;
  725. ENUM_SERVICE_STATUS *lpStatus = NULL;
  726. BOOL ret = FALSE;
  727. if (!ProvidersInit())
  728. return FALSE;
  729. // initialize variables for enumeration...
  730. dwBytesNeeded = dwNumEntries = dwhResume = 0;
  731. // acquire handle to svc controller to query for netware client...
  732. if (hSC = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE)) {
  733. UINT i;
  734. LPTSTR lpServiceName = Lids(IDS_S_26); // NWCWorkstation
  735. // ask for buffer size...
  736. ret = EnumServicesStatus(
  737. hSC,
  738. SERVICE_WIN32,
  739. SERVICE_ACTIVE,
  740. NULL,
  741. 0,
  742. &dwBytesNeeded,
  743. &dwNumEntries,
  744. &dwhResume
  745. );
  746. // intentionally called function with no buffer to size...
  747. if ((ret == FALSE) && (GetLastError() == ERROR_MORE_DATA)) {
  748. // allocate buffer with size passed back...
  749. if (lpStatus = AllocMemory(dwBytesNeeded)) {
  750. // ask for svc entries...
  751. if (EnumServicesStatus(
  752. hSC,
  753. SERVICE_WIN32,
  754. SERVICE_ACTIVE,
  755. lpStatus,
  756. dwBytesNeeded,
  757. &dwBytesNeeded,
  758. &dwNumEntries,
  759. &dwhResume)) {
  760. // search service names for match...
  761. for (i = 0; ((i < dwNumEntries) && (ret == FALSE)); i++) {
  762. if (!lstrcmpi(lpStatus[i].lpServiceName, lpServiceName)) {
  763. ret = TRUE; // found it...
  764. }
  765. }
  766. }
  767. FreeMemory(lpStatus);
  768. }
  769. }
  770. CloseServiceHandle(hSC);
  771. }
  772. return ret;
  773. } // CheckServiceInstall
  774. /////////////////////////////////////////////////////////////////////////
  775. LRESULT CALLBACK
  776. DlgMoveIt(
  777. HWND hDlg,
  778. UINT message,
  779. WPARAM wParam,
  780. LPARAM lParam
  781. )
  782. /*++
  783. Routine Description:
  784. Arguments:
  785. Return Value:
  786. --*/
  787. {
  788. static TCHAR AddLine[256];
  789. int wmId, wmEvent;
  790. HWND hCtrl;
  791. PAINTSTRUCT ps;
  792. HDC hDC;
  793. RECT rc;
  794. DWORD Index;
  795. DWORD_PTR dwData;
  796. int TabStop;
  797. switch (message) {
  798. case WM_INITDIALOG:
  799. ConvertListStart = ConvertListEnd = NULL;
  800. UserOptionsDefaultsReset();
  801. FileOptionsDefaultsReset();
  802. LogOptionsInit();
  803. // Disable controls until server pair is choosen...
  804. ToggleControls(hDlg, FALSE);
  805. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  806. GetClientRect(hCtrl, &rc);
  807. // Size is half width of listbox - vertical scrollbar
  808. TabStop = (((rc.right - rc.left) - GetSystemMetrics(SM_CXVSCROLL)) / 2);
  809. ColumnLB_SetNumberCols(hCtrl, 2);
  810. ColumnLB_SetColTitle(hCtrl, 0, Lids(IDS_D_11));
  811. ColumnLB_SetColTitle(hCtrl, 1, Lids(IDS_D_12));
  812. ColumnLB_SetColWidth(hCtrl, 0, TabStop);
  813. // Calculate 2nd this way instead of just TabStop to get rid of roundoff
  814. ColumnLB_SetColWidth(hCtrl, 1, (rc.right - rc.left) - TabStop);
  815. // This is needed as otherwise only the Add box will display - weird...
  816. ShowWindow(hDlg, SW_SHOWNORMAL);
  817. // Check if NWCS is installed
  818. PostMessage(hDlg, WM_COMMAND, ID_INIT, 0L);
  819. break;
  820. case WM_ERASEBKGND:
  821. // Process so icon background isn't painted grey - main dlg
  822. // can't be DS_MODALFRAME either, or else a frame is painted around
  823. // the icon.
  824. if (IsIconic(hDlg))
  825. return TRUE;
  826. break;
  827. case WM_DESTROY:
  828. NTConnListDeleteAll();
  829. PostQuitMessage(0);
  830. break;
  831. case WM_PAINT:
  832. hDC = BeginPaint(hDlg, &ps);
  833. if (IsIconic(hDlg)) {
  834. GetClientRect(hDlg, &rc);
  835. DrawIcon(hDC, rc.left, rc.top, MyIcon);
  836. }
  837. EndPaint(hDlg, &ps);
  838. break;
  839. case WM_COMMAND:
  840. wmId = LOWORD(wParam);
  841. wmEvent = HIWORD(wParam);
  842. // If we are currently doing a conversion then get out
  843. if (InConversion)
  844. break;
  845. switch (wmId) {
  846. case IDOK:
  847. InConversion = TRUE;
  848. DoConversion(hDlg, FALSE);
  849. InConversion = FALSE;
  850. if (ConversionSuccessful()) {
  851. ConfigurationReset(hDlg);
  852. DeleteFile(DEF_CONFIG_FILE);
  853. }
  854. break;
  855. case ID_INIT:
  856. CursorHourGlass();
  857. if (!CheckServiceInstall()) {
  858. CursorNormal();
  859. WarningError(Lids(IDS_E_12));
  860. PostMessage(hDlg, WM_DESTROY, 0, 0);
  861. } else {
  862. ConfigurationLoad(hDlg, DEF_CONFIG_FILE);
  863. CursorNormal();
  864. if (!NumServerPairs) {
  865. // Put up the add dialog box
  866. if (FirstTime) {
  867. FirstTime = FALSE;
  868. PostMessage(hDlg, WM_COMMAND, IDC_ADD, 0);
  869. }
  870. }
  871. }
  872. break;
  873. case IDC_TRIAL:
  874. InConversion = TRUE;
  875. DoConversion(hDlg, TRUE);
  876. InConversion = FALSE;
  877. break;
  878. case IDCANCEL:
  879. case IDC_EXIT:
  880. CursorHourGlass();
  881. if (NumServerPairs)
  882. ConfigurationSave(DEF_CONFIG_FILE);
  883. else {
  884. DeleteFile(DEF_CONFIG_FILE);
  885. }
  886. ConfigurationReset(hDlg);
  887. CursorNormal();
  888. PostMessage(hDlg, WM_DESTROY, 0, 0);
  889. break;
  890. case ID_FILE_OPEN:
  891. ConfigFileGet(hDlg);
  892. break;
  893. case ID_FILE_SAVE:
  894. ConfigFileSave(hDlg);
  895. break;
  896. case ID_FILE_DEFAULT:
  897. if (MessageBox(hDlg, Lids(IDS_RESTOREDEFAULTS), Lids(IDS_TXTWARNING), MB_OKCANCEL | MB_ICONEXCLAMATION) == IDOK) {
  898. // Remove the listbox entries
  899. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  900. ColumnLB_ResetContent(hCtrl);
  901. ToggleControls(hDlg, FALSE);
  902. ConvertListDeleteAll();
  903. UserOptionsDefaultsReset();
  904. FileOptionsDefaultsReset();
  905. ViewLogs = FALSE;
  906. }
  907. break;
  908. case ID_LOGGING:
  909. DoLoggingDlg(hDlg);
  910. return TRUE;
  911. break;
  912. case IDC_USERINF:
  913. // Figure out which server pair is selected and pass server pair to user config dialog
  914. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  915. Index = ColumnLB_GetCurSel(hCtrl);
  916. dwData = ColumnLB_GetItemData(hCtrl, Index);
  917. CurrentConvertList = (CONVERT_LIST *) dwData;
  918. UserOptions_Do(hDlg, CurrentConvertList->ConvertOptions, CurrentConvertList->SourceServ, CurrentConvertList->FileServ);
  919. return TRUE;
  920. case IDC_FILEINF:
  921. // Figure out which server pair is selected and pass server pair to file config dialog
  922. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  923. Index = ColumnLB_GetCurSel(hCtrl);
  924. dwData = ColumnLB_GetItemData(hCtrl, Index);
  925. CurrentConvertList = (CONVERT_LIST *) dwData;
  926. FileOptions_Do(hDlg, CurrentConvertList->FileOptions, CurrentConvertList->SourceServ, CurrentConvertList->FileServ);
  927. break;
  928. case IDHELP:
  929. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_MAIN);
  930. break;
  931. case ID_HELP_CONT:
  932. WinHelp(hDlg, HELP_FILE, HELP_CONTENTS, 0L);
  933. break;
  934. case ID_HELP_INDEX:
  935. WinHelp(hDlg, HELP_FILE, HELP_PARTIALKEY, 0L);
  936. break;
  937. case ID_HELP_USING:
  938. WinHelp(hDlg, HELP_FILE, HELP_HELPONHELP, 0L);
  939. break;
  940. case IDC_ADD:
  941. if (!DialogServerBrowse(hInst, hDlg, &lpSourceServer, &lpDestServer)) {
  942. dwData = (DWORD_PTR) ConvertListAdd(lpSourceServer, lpDestServer);
  943. MainListbox_Add(hDlg, dwData, lpSourceServer->Name, lpDestServer->Name);
  944. PostMessage(hDlg, WM_COMMAND, (WPARAM) IDM_ADDSEL, 0);
  945. }
  946. return TRUE;
  947. case IDC_DELETE:
  948. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  949. Index = ColumnLB_GetCurSel(hCtrl);
  950. if (Index != LB_ERR) {
  951. dwData = ColumnLB_GetItemData(hCtrl, Index);
  952. ConvertListDelete((CONVERT_LIST *) dwData);
  953. ColumnLB_DeleteString(hCtrl, Index);
  954. }
  955. if (!NumServerPairs) {
  956. hCtrl = GetDlgItem(hDlg, IDC_ADD);
  957. SetFocus(hCtrl);
  958. ToggleControls(hDlg, FALSE);
  959. UserOptionsDefaultsReset();
  960. FileOptionsDefaultsReset();
  961. } else {
  962. Index = ColumnLB_GetCurSel(hCtrl);
  963. if (Index == LB_ERR)
  964. ColumnLB_SetCurSel(hCtrl, 0);
  965. }
  966. break;
  967. case IDM_ADDSEL:
  968. ToggleControls(hDlg, TRUE);
  969. break;
  970. case IDC_LIST1:
  971. if (wmEvent == LBN_SELCHANGE) {
  972. if (NumServerPairs)
  973. ToggleControls(hDlg, TRUE);
  974. } else
  975. if (wmEvent == LBN_DBLCLK) {
  976. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  977. Index = ColumnLB_GetCurSel(hCtrl);
  978. if (Index != LB_ERR) {
  979. dwData = ColumnLB_GetItemData(hCtrl, Index);
  980. if (dwData != 0) {
  981. CurrentConvertList = (CONVERT_LIST *) dwData;
  982. NTServInfoDlg_Do(hDlg);
  983. }
  984. }
  985. }
  986. break;
  987. case ID_APP_ABOUT:
  988. AboutBox_Do(hDlg);
  989. return TRUE;
  990. }
  991. break;
  992. case WM_MENUSELECT:
  993. // when a menu is selected we must remember which one it was so that
  994. // when F1 is pressed we know what help to bring up.
  995. if (GET_WM_MENUSELECT_HMENU(wParam, lParam)) {
  996. // Save the menu the user selected
  997. uMenuID = GET_WM_MENUSELECT_CMD(wParam, lParam);
  998. uMenuFlags = GET_WM_MENUSELECT_FLAGS(wParam, lParam);
  999. hMenu = GET_WM_MENUSELECT_HMENU(wParam, lParam);
  1000. }
  1001. break;
  1002. default:
  1003. if (message == wHelpMessage) {
  1004. if (GET_WM_COMMAND_ID(wParam, lParam) == MSGF_MENU) {
  1005. // Get outta menu mode if help for a menu item
  1006. if (uMenuID && hMenu) {
  1007. // save and restore menu vars so they aren't overwritten by
  1008. // the message we are sending
  1009. UINT m = uMenuID;
  1010. HMENU hM = hMenu;
  1011. UINT mf = uMenuFlags;
  1012. SendMessage(hDlg, WM_CANCELMODE, 0, 0L);
  1013. uMenuID = m;
  1014. hMenu = hM;
  1015. uMenuFlags = mf;
  1016. }
  1017. if (!(uMenuFlags & MF_POPUP)) {
  1018. switch(uMenuID) {
  1019. case ID_FILE_OPEN:
  1020. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDM_HELP_RCONFIG);
  1021. break;
  1022. case ID_FILE_SAVE:
  1023. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDM_HELP_SCONFIG);
  1024. break;
  1025. case ID_FILE_DEFAULT:
  1026. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDM_HELP_RDCONFIG);
  1027. break;
  1028. case IDC_EXIT:
  1029. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDM_HELP_EXIT);
  1030. break;
  1031. }
  1032. #ifdef fooo
  1033. // According to winhelp: GetSystemMenu, uMenuID >= 0x7000
  1034. // means system menu items!
  1035. //
  1036. // This should not be nec since MF_SYSMENU is set!
  1037. if (uMenuFlags & MF_SYSMENU || uMenuID >= 0xf000)
  1038. dwContext = bMDIFrameSysMenu ? IDH_SYSMENU : IDH_SYSMENUCHILD;
  1039. WFHelp(hwnd);
  1040. #endif
  1041. }
  1042. }
  1043. #ifdef fooo
  1044. else if (GET_WM_COMMAND_ID(wParam, lParam) == MSGF_DIALOGBOX) {
  1045. // context range for message boxes
  1046. if (dwContext >= IDH_MBFIRST && dwContext <= IDH_MBLAST)
  1047. WFHelp(hwnd);
  1048. else
  1049. // let dialog box deal with it
  1050. PostMessage(GetRealParent((HWND)lParam), wHelpMessage, 0, 0L);
  1051. }
  1052. #endif
  1053. }
  1054. break;
  1055. }
  1056. return (FALSE); // Didn't process the message
  1057. } // DlgMoveIt