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.

951 lines
29 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. COPYFLOP.C
  5. Abstract:
  6. Floppy disk creation setup dialog
  7. Author:
  8. Bob Watson (a-robw)
  9. Revision History:
  10. 17 Feb 94 Written
  11. --*/
  12. //
  13. // Windows Include Files
  14. //
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <malloc.h>
  18. #include <tchar.h> // unicode macros
  19. //
  20. // app include files
  21. //
  22. #include "otnboot.h"
  23. #include "otnbtdlg.h"
  24. //
  25. // static data for this module
  26. //
  27. //
  28. // mszDirNameList is the local list of directories that corresponds to the
  29. // items displayed in the Client List. This buffer is loaded by the
  30. // LoadClientList routine and the entry index of the directory is the
  31. // Item Data for the list box name entry.
  32. //
  33. static TCHAR mszDirNameList[SMALL_BUFFER_SIZE];
  34. //
  35. // These string arrays are used to cross reference the drive selected
  36. // to the "drive name" for IOCTL functions or the Dir name for file
  37. // operations.
  38. //
  39. static LPCTSTR szDriveNames[2] = {TEXT("\\\\.\\A:"), TEXT("\\\\.\\B:")};
  40. static LPCTSTR szDriveDirs[2] = {TEXT("A:"), TEXT("B:")};
  41. #ifdef TERMSRV
  42. extern TCHAR szCommandLineVal[MAX_PATH];
  43. extern BOOL bUseCleanDisks;
  44. #endif // TERMSRV
  45. static
  46. MEDIA_TYPE
  47. GetDriveTypeFromList (
  48. IN HWND hwndDlg
  49. )
  50. /*++
  51. Routine Description:
  52. Gets the selected drive from the drive list box and looks up the drive
  53. type using the IOCTL function. The drive type enum value is
  54. returned.
  55. NOTE: This function may cause a system error box if there is no media
  56. in the drive or there is a device/drive error.
  57. Arguments:
  58. IN HWND hwndDlg
  59. handle to the dialog box window
  60. Return Value:
  61. value of type MEDIA_TYPE that corresponds to the drive type of the
  62. drive selected in the drive list box.
  63. --*/
  64. {
  65. int nSelIndex;
  66. HANDLE hFloppy;
  67. DWORD dwRetSize;
  68. DISK_GEOMETRY dgFloppy;
  69. // get selected drive
  70. nSelIndex = (int)SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST,
  71. LB_GETCURSEL, 0, 0);
  72. // open device to get type
  73. hFloppy = CreateFile (
  74. szDriveNames[nSelIndex],
  75. 0,
  76. (FILE_SHARE_READ | FILE_SHARE_WRITE),
  77. NULL,
  78. OPEN_EXISTING,
  79. FILE_ATTRIBUTE_NORMAL,
  80. NULL);
  81. if (hFloppy != INVALID_HANDLE_VALUE) {
  82. // get drive information
  83. if (!DeviceIoControl (hFloppy,
  84. IOCTL_DISK_GET_DRIVE_GEOMETRY,
  85. NULL, 0,
  86. &dgFloppy,
  87. sizeof(DISK_GEOMETRY),
  88. &dwRetSize,
  89. NULL) ){
  90. // unable to get data so set to unknown
  91. dgFloppy.MediaType = Unknown;
  92. } // else return data from returned structure
  93. CloseHandle (hFloppy);
  94. } else {
  95. // unable to access floppy, so return unknown
  96. dgFloppy.MediaType = Unknown;
  97. }
  98. return dgFloppy.MediaType;
  99. }
  100. static
  101. VOID
  102. FillDriveList (
  103. IN HWND hwndDlg
  104. )
  105. /*++
  106. Routine Description:
  107. Loads the text strings into the drive selection list box.
  108. NOTE: The order of these entries is significant in that it is
  109. used to index into the static device and drive name arrays.
  110. Arguments:
  111. IN HWND hwndDlg
  112. handle to dialog box window
  113. Return Value:
  114. NONE
  115. --*/
  116. {
  117. #ifdef JAPAN
  118. // fixed kkntbug #11940
  119. // Network client administrator can not make install disks on PC with C drive as FD
  120. PDISK_GEOMETRY pDiskGeometry;
  121. HANDLE hDrive;
  122. LPTSTR szDrive;
  123. TCHAR cDriveName;
  124. BYTE nCounter;
  125. BOOL bFloppy;
  126. BOOL bRet;
  127. DWORD dwArryCount;
  128. DWORD dwLastError;
  129. DWORD dwMediaType;
  130. DWORD dwLogicalDrive;
  131. DWORD dwReturnedByteCount;
  132. #endif
  133. // clear list box
  134. SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST, LB_RESETCONTENT, 0, 0);
  135. #ifdef JAPAN
  136. // fixed kkntbug #11940
  137. // Network client administrator can not make install disks on PC with C drive as FD
  138. szDrive = GlobalAlloc (GPTR, MAX_PATH_BYTES);
  139. if (szDrive != NULL) {
  140. dwLogicalDrive = GetLogicalDrives();
  141. for (cDriveName = *cszAColon, nCounter = 0;
  142. cDriveName <= *cszLastDrive;
  143. cDriveName++, nCounter++) {
  144. if ((dwLogicalDrive>>nCounter)&NCDU_LOGICAL_DRIVE_MASK) {
  145. bFloppy = FALSE;
  146. wsprintf (szDrive, TEXT("%s%s%s%c%s"),
  147. cszDoubleBackslash, cszDot, cszBackslash, cDriveName, cszColon);
  148. hDrive = CreateFile (szDrive,
  149. 0,
  150. (FILE_SHARE_READ | FILE_SHARE_WRITE),
  151. NULL,
  152. OPEN_EXISTING,
  153. FILE_ATTRIBUTE_NORMAL,
  154. NULL);
  155. if (hDrive != INVALID_HANDLE_VALUE) {
  156. dwArryCount = 1;
  157. pDiskGeometry = NULL;
  158. do {
  159. if (!pDiskGeometry)
  160. pDiskGeometry = (PDISK_GEOMETRY)
  161. GlobalLock (GlobalAlloc (GHND,
  162. sizeof(DISK_GEOMETRY)*dwArryCount));
  163. else
  164. pDiskGeometry = (PDISK_GEOMETRY)
  165. GlobalLock (GlobalReAlloc (GlobalHandle (pDiskGeometry),
  166. sizeof(DISK_GEOMETRY)*dwArryCount,
  167. GHND));
  168. if (!pDiskGeometry) break;
  169. bRet = DeviceIoControl (hDrive,
  170. IOCTL_DISK_GET_MEDIA_TYPES,
  171. NULL,
  172. 0,
  173. pDiskGeometry,
  174. sizeof(DISK_GEOMETRY)*dwArryCount,
  175. &dwReturnedByteCount,
  176. NULL);
  177. dwLastError = GetLastError();
  178. GlobalUnlock(GlobalHandle(pDiskGeometry));
  179. dwArryCount++;
  180. } while ( ! bRet && ( dwLastError == ERROR_INSUFFICIENT_BUFFER ||
  181. dwLastError == ERROR_MORE_DATA ) );
  182. if (pDiskGeometry) {
  183. pDiskGeometry = (PDISK_GEOMETRY)GlobalLock(GlobalHandle(pDiskGeometry));
  184. for (dwMediaType = 0; dwMediaType < (dwArryCount-1); dwMediaType++) {
  185. if (((pDiskGeometry+dwMediaType)->MediaType != Unknown) &&
  186. ((pDiskGeometry+dwMediaType)->MediaType != RemovableMedia) &&
  187. ((pDiskGeometry+dwMediaType)->MediaType != FixedMedia))
  188. bFloppy = TRUE;
  189. }
  190. GlobalUnlock(GlobalHandle(pDiskGeometry));
  191. GlobalFree(GlobalHandle(pDiskGeometry));
  192. }
  193. if (bFloppy) {
  194. wsprintf (szDrive, TEXT("%c%s"), cDriveName, cszColon);
  195. SendDlgItemMessage (hwndDlg,
  196. NCDU_DRIVE_LIST,
  197. LB_ADDSTRING,
  198. 0,
  199. (LPARAM)szDrive);
  200. }
  201. CloseHandle (hDrive);
  202. }
  203. }
  204. }
  205. FREE_IF_ALLOC (szDrive);
  206. } else {
  207. #else
  208. SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST, LB_ADDSTRING, 0, (LPARAM)cszAColon);
  209. SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST, LB_ADDSTRING, 0, (LPARAM)cszBColon);
  210. #endif
  211. #ifdef JAPAN
  212. // fixed kkntbug #11940
  213. // Network client administrator can not make install disks on PC with C drive as FD
  214. }
  215. #endif
  216. SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST, LB_SETCURSEL, 0, 0);
  217. }
  218. static
  219. DWORD
  220. NumberOfDisks (
  221. IN HWND hwndDlg
  222. )
  223. /*++
  224. Routine Description:
  225. Counts the number of "disk" directories in the currently selected client
  226. installation disk dir. The method used to count disks relies on the
  227. assumption that each disk's files are in a directory and the
  228. directories are mamed Disk1, Disk2, etc. The count is performed by
  229. looking for each disk directory in sequence and stopping when a
  230. dir is not found. i.e. if disk5 is not found, then 4 disks are
  231. assumed.
  232. Arguments:
  233. Handle to dialog box window
  234. Return Value:
  235. count of directorys ("disks") found
  236. --*/
  237. {
  238. LPTSTR szFromPath;
  239. LPTSTR szDirStart;
  240. BOOL bCounting;
  241. UINT nClientIndex;
  242. DWORD nDiskNumber = 0;
  243. szFromPath = GlobalAlloc (GPTR, MAX_PATH_BYTES);
  244. if (szFromPath != NULL) {
  245. // get root dir of dist tree
  246. lstrcpy (szFromPath, pAppInfo->szDistPath);
  247. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  248. // append client sw subdir
  249. nClientIndex = (UINT)SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  250. LB_GETCURSEL, 0, 0);
  251. lstrcat (szFromPath, GetEntryInMultiSz (mszDirNameList, nClientIndex+1));
  252. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  253. lstrcat (szFromPath, cszDisksSubDir);
  254. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  255. szDirStart = &szFromPath[lstrlen(szFromPath)];
  256. // count directories
  257. bCounting = TRUE;
  258. nDiskNumber = 0;
  259. while (bCounting) {
  260. nDiskNumber++;
  261. _stprintf (szDirStart, fmtDiskNumber,
  262. nDiskNumber);
  263. bCounting = IsPathADir (szFromPath);
  264. }
  265. // account for last directory that wasn't found
  266. nDiskNumber -= 1;
  267. FREE_IF_ALLOC (szFromPath);
  268. }
  269. return nDiskNumber; // for now
  270. }
  271. static
  272. BOOL
  273. UpdateDiskCount (
  274. IN HWND hwndDlg
  275. )
  276. /*++
  277. Routine Description:
  278. updates the disk count text displayed in the dialog box.
  279. Arguments:
  280. IN HWND hwndDlg
  281. handle to dialog box window
  282. Return Value:
  283. TRUE if display updated successfully
  284. FALSE if not.
  285. --*/
  286. {
  287. LPTSTR szBuffer;
  288. DWORD dwNumDisks;
  289. szBuffer = GlobalAlloc (GPTR, MAX_PATH_BYTES);
  290. if (szBuffer != NULL) {
  291. dwNumDisks = NumberOfDisks (hwndDlg);
  292. if (dwNumDisks == 1) {
  293. _stprintf (szBuffer, GetStringResource (FMT_1_DISK_REQUIRED));
  294. } else {
  295. _stprintf (szBuffer, GetStringResource (FMT_N_DISKS_REQUIRED),
  296. dwNumDisks);
  297. }
  298. SetDlgItemText (hwndDlg, NCDU_NUM_DISKS_REQUIRED, szBuffer);
  299. FREE_IF_ALLOC (szBuffer);
  300. return TRUE;
  301. } else {
  302. return FALSE;
  303. }
  304. }
  305. static
  306. BOOL
  307. CopyFlopDlg_WM_INITDIALOG (
  308. IN HWND hwndDlg,
  309. IN WPARAM wParam,
  310. IN LPARAM lParam
  311. )
  312. /*++
  313. Routine Description:
  314. Dialog box initialization routine. Loads list boxes in dialog
  315. Arguments:
  316. IN HWND hwndDlg
  317. Handle to dialog box window
  318. IN WPARAM wParam
  319. Not used
  320. IN LPARAM lParam
  321. Not used
  322. Return Value:
  323. FALSE, always.
  324. --*/
  325. {
  326. // update dialog window menu and position
  327. RemoveMaximizeFromSysMenu (hwndDlg);
  328. PositionWindow (hwndDlg);
  329. // load clients to display
  330. LoadClientList (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  331. pAppInfo->szDistPath, CLT_FLOPPY_INSTALL, mszDirNameList);
  332. // set selection
  333. SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  334. LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
  335. // load drives to select from
  336. FillDriveList(hwndDlg);
  337. // update disk count to reflect default selection
  338. UpdateDiskCount (hwndDlg);
  339. // clear old Dialog and register current
  340. PostMessage (GetParent(hwndDlg), NCDU_CLEAR_DLG, (WPARAM)hwndDlg, IDOK);
  341. PostMessage (GetParent(hwndDlg), NCDU_REGISTER_DLG,
  342. NCDU_CREATE_INSTALL_DISKS_DLG, (LPARAM)hwndDlg);
  343. // set cursor and focus
  344. SetCursor(LoadCursor(NULL, IDC_ARROW));
  345. SetFocus (GetDlgItem(hwndDlg, NCDU_MAKE_DISKS));
  346. return FALSE;
  347. }
  348. static
  349. BOOL
  350. CopyFlopDlg_NCDU_MAKE_DISKS (
  351. IN HWND hwndDlg
  352. )
  353. /*++
  354. Routine Description:
  355. Function to copy the client files to the floppy disks.
  356. Selects the source directory using the client name and
  357. disk type then copies the files to the floppy disks
  358. sequentially assuming that the contents of each disk
  359. are stored in sub directory named "DiskX" where X is the
  360. decimal number indicating the disk sequence (e.g. 1, 2, 3, etc.)
  361. Arguments:
  362. IN HWND hwndDlg
  363. Handle to dialog box window
  364. Return Value:
  365. FALSE, always.
  366. --*/
  367. {
  368. MEDIA_TYPE mtFloppy;
  369. LPTSTR szFromPath;
  370. LPTSTR szInfName;
  371. TCHAR szSubDir[16];
  372. TCHAR szDestRoot[4];
  373. TCHAR szDriveRoot[8];
  374. LPTSTR szClientName;
  375. LPTSTR szDisplayName;
  376. LPTSTR szDirStart;
  377. LPTSTR szDiskName;
  378. LPTSTR szClientSection;
  379. LPTSTR szDisplayString;
  380. LPTSTR szVolumeLabel;
  381. DWORD dwFileAttr;
  382. BOOL bCopyFiles;
  383. int nSelIndex;
  384. int nClientIndex;
  385. int nCancelResult = 0;
  386. int nDiskNumber;
  387. CF_DLG_DATA cfData;
  388. BOOL bFormatDisks;
  389. #ifdef TERMSRV
  390. int nDiskCount;
  391. #endif // TERMSRV
  392. #ifdef JAPAN
  393. // fixed kkntbug #11940
  394. // Network client administrator can not make install disks on PC with C drive as FD
  395. //
  396. // Buffer for real FD path
  397. //
  398. TCHAR szDriveName[10];
  399. TCHAR szDriveDir[5];
  400. #endif
  401. szFromPath = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  402. szInfName = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  403. szClientName = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  404. szDisplayName = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  405. szDiskName = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  406. szClientSection = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  407. szVolumeLabel = (LPTSTR)GlobalAlloc (GPTR, MAX_PATH_BYTES);
  408. if ((szFromPath == NULL) ||
  409. (szClientName == NULL) ||
  410. (szClientSection == NULL) ||
  411. (szInfName == NULL) ||
  412. (szDiskName == NULL) ||
  413. (szVolumeLabel == NULL) ||
  414. (szDisplayName == NULL)) {
  415. // message not processed
  416. return FALSE;
  417. }
  418. // check floppy selection to see if it's supported
  419. //
  420. // This function is really flakey, so for now, (for ever?)
  421. // we'll assume they are using a HD disk drive
  422. //
  423. // mtFloppy = GetDriveTypeFromList (hwndDlg);
  424. //
  425. mtFloppy = F3_1Pt44_512;
  426. if ((mtFloppy == F5_1Pt2_512) || // 5.25 HD
  427. (mtFloppy == F3_1Pt44_512)) { // 3.5 HD
  428. // get format check box state
  429. bFormatDisks = (BOOL)(IsDlgButtonChecked (hwndDlg, NCDU_FORMAT_DISKS) == CHECKED);
  430. // then this is a supported format
  431. // make source path using:
  432. // dist tree + client type + "disks" + drive type
  433. //
  434. // get root dir of dist tree
  435. lstrcpy (szFromPath, pAppInfo->szDistPath);
  436. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  437. // append client sw subdir
  438. nClientIndex = (int)SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  439. LB_GETCURSEL, 0, 0);
  440. lstrcat (szFromPath, GetEntryInMultiSz (mszDirNameList, nClientIndex+1));
  441. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  442. lstrcat (szFromPath, cszDisksSubDir);
  443. // make INF file Name
  444. lstrcpy (szInfName, pAppInfo->szDistPath);
  445. if (szInfName[lstrlen(szInfName)-1] != cBackslash) lstrcat (szInfName, cszBackslash);
  446. lstrcat (szInfName, cszAppInfName);
  447. // get client name
  448. SendDlgItemMessage (hwndDlg, NCDU_CLIENT_SOFTWARE_LIST,
  449. LB_GETTEXT, (WPARAM)nClientIndex, (LPARAM)szClientName);
  450. if (szFromPath[lstrlen(szFromPath)-1] != cBackslash) lstrcat (szFromPath, cszBackslash);
  451. szDirStart = &szFromPath[lstrlen(szFromPath)];
  452. nSelIndex = (int)SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST,
  453. LB_GETCURSEL, 0, 0);
  454. #ifdef JAPAN
  455. // fixed kkntbug #11940
  456. // Network client administrator can not make install disks on PC with C drive as FD
  457. // get real FD path
  458. SendDlgItemMessage (hwndDlg, NCDU_DRIVE_LIST,
  459. LB_GETTEXT, nSelIndex, (LPARAM)szDriveDir);
  460. wsprintf(szDriveName, TEXT("%s%s%s%s"), cszBackslash,cszBackslash,cszColon,cszBackslash);
  461. lstrcat(szDriveName, szDriveDir);
  462. #endif
  463. // format client name key used to look up disk names in INF
  464. lstrcpy (szClientSection, GetEntryInMultiSz (mszDirNameList, nClientIndex+1));
  465. lstrcat (szClientSection, cszNames);
  466. // set the destination path
  467. #ifdef JAPAN
  468. // fixed kkntbug #11940
  469. // Network client administrator can not make install disks on PC with C drive as FD
  470. lstrcpy (szDestRoot, szDriveDir);
  471. lstrcpy (szDriveRoot, szDriveName);
  472. lstrcat (szDriveRoot, cszBackslash);
  473. #else
  474. lstrcpy (szDestRoot, szDriveDirs[nSelIndex]);
  475. lstrcpy (szDriveRoot, szDriveNames[nSelIndex]);
  476. lstrcat (szDriveRoot, cszBackslash);
  477. #endif
  478. nDiskNumber = 1;
  479. _stprintf (szSubDir, fmtDiskNumber, nDiskNumber);
  480. lstrcpy (szDirStart, szSubDir);
  481. if ((dwFileAttr = QuietGetFileAttributes(szFromPath)) != 0xFFFFFFFF) {
  482. bCopyFiles = TRUE;
  483. } else {
  484. bCopyFiles = FALSE;
  485. }
  486. // initialize counter fields
  487. cfData.dwFilesCopied = 0;
  488. cfData.dwDirsCreated = 0;
  489. while (bCopyFiles) {
  490. if ((dwFileAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) {
  491. // see if this disk has a name, if so display it, otherwise
  492. // just show the disk number
  493. if (QuietGetPrivateProfileString (szClientSection, szSubDir,
  494. cszEmptyString, szDiskName, MAX_PATH, szInfName) == 0) {
  495. lstrcpy (szDiskName, szSubDir);
  496. } else {
  497. // append "disk" to the name string
  498. lstrcat (szDiskName, cszDisk);
  499. }
  500. // display "load the floppy" message
  501. _stprintf (szDisplayName,
  502. GetStringResource (FMT_CLIENT_DISK_AND_DRIVE),
  503. #ifdef JAPAN
  504. // fixed kkntbug #11940
  505. // Network client administrator can not make install disks on PC with C drive as FD
  506. szClientName, szDiskName, szDriveDir);
  507. #else
  508. szClientName, szDiskName, szDriveDirs[nSelIndex]);
  509. #endif
  510. nCancelResult = MessageBox (
  511. hwndDlg,
  512. szDisplayName,
  513. GetStringResource (FMT_INSERT_FLOPPY),
  514. MB_OKCANCEL_TASK_INFO);
  515. if (nCancelResult == IDOK) {
  516. // format the copying files message
  517. _stprintf (szDisplayName,
  518. GetStringResource (FMT_CLIENT_DISPLAY_NAME),
  519. szClientName, szDiskName);
  520. // set the disk volume label if one is in the INF
  521. lstrcat (szSubDir, cszLabel);
  522. if (QuietGetPrivateProfileString (szClientSection, szSubDir,
  523. cszEmptyString, szVolumeLabel, MAX_PATH, szInfName) > 0) {
  524. }
  525. if (bFormatDisks) {
  526. while (!FormatDiskInDrive (hwndDlg,
  527. szDestRoot[0],
  528. szVolumeLabel,
  529. TRUE)) {
  530. // an error occured so see if they want to try again or bail out
  531. if (DisplayMessageBox (hwndDlg,
  532. IDS_CORRECT_FMT_ERROR,
  533. FMT_INSERT_FLOPPY,
  534. MB_OKCANCEL_TASK_EXCL) == IDCANCEL) {
  535. bCopyFiles = FALSE;
  536. nCancelResult = IDCANCEL;
  537. break; // now exit retry loop
  538. }
  539. }
  540. if (!bCopyFiles) continue; // bail out at the top
  541. }
  542. cfData.szDisplayName = szDisplayName;
  543. cfData.szSourceDir = szFromPath;
  544. cfData.szDestDir = szDestRoot;
  545. cfData.dwCopyFlags = CD_FLAGS_COPY_SUB_DIR | CD_FLAGS_COPY_ATTR | CD_FLAGS_IGNORE_ERROR;
  546. cfData.dwTotalSize = 0;
  547. if (bUseCleanDisks) {
  548. WIN32_FIND_DATA fdSearch;
  549. TCHAR filesToFind[8];
  550. HANDLE hSearch;
  551. BOOL bDiskContainsFiles;
  552. lstrcpy(filesToFind, szDestRoot);
  553. if (filesToFind[lstrlen(filesToFind)-1] != cBackslash) {
  554. lstrcat (filesToFind, cszBackslash);
  555. }
  556. lstrcat(filesToFind, cszWildcard);
  557. // loop till the user inserts an empty disk, or hits cancel.
  558. do {
  559. nCancelResult = IDOK;
  560. bDiskContainsFiles = FALSE;
  561. hSearch = FindFirstFile(filesToFind, &fdSearch);
  562. if(hSearch != INVALID_HANDLE_VALUE) {
  563. BOOL bSearching = TRUE;
  564. while (bSearching) {
  565. if (!DotOrDotDotDir(fdSearch.cFileName)) {
  566. //
  567. // looks like some files are already existing there..
  568. //
  569. bDiskContainsFiles = TRUE;
  570. nCancelResult = DisplayMessageBox (
  571. hwndDlg,
  572. NCDU_CLEAN_DISK_REQUIRED,
  573. 0,
  574. (MB_OKCANCEL | MB_ICONERROR | MB_TASKMODAL));
  575. break;
  576. }
  577. bSearching = FindNextFile(hSearch, &fdSearch);
  578. }
  579. FindClose(hSearch);
  580. }
  581. }
  582. while (bDiskContainsFiles && nCancelResult != IDCANCEL);
  583. if (nCancelResult == IDCANCEL) {
  584. bCopyFiles = FALSE;
  585. }
  586. }
  587. if (!bCopyFiles) continue; // bail out at the top
  588. nCancelResult = (int)DialogBoxParam (
  589. (HANDLE)GetWindowLongPtr(GetParent(hwndDlg), GWLP_HINSTANCE),
  590. MAKEINTRESOURCE(NCDU_COPYING_FILES_DLG),
  591. hwndDlg,
  592. CopyFileDlgProc,
  593. (LPARAM)&cfData);
  594. if (nCancelResult == IDCANCEL) {
  595. bCopyFiles = FALSE;
  596. } else {
  597. // set volume label (if not set already)
  598. if ((!bFormatDisks) & (lstrlen(szVolumeLabel) > 0)) {
  599. // set volume label here
  600. LabelDiskInDrive (hwndDlg, szDestRoot[0], szVolumeLabel);
  601. }
  602. }
  603. } else {
  604. bCopyFiles = FALSE;
  605. }
  606. }
  607. if (bCopyFiles) {
  608. _stprintf (szSubDir, fmtDiskNumber, ++nDiskNumber);
  609. lstrcpy (szDirStart, szSubDir);
  610. if ((dwFileAttr = QuietGetFileAttributes(szFromPath)) != 0xFFFFFFFF) {
  611. bCopyFiles = TRUE;
  612. } else {
  613. bCopyFiles = FALSE;
  614. }
  615. }
  616. }
  617. if (nCancelResult != IDCANCEL) {
  618. szDisplayString = GlobalAlloc (GPTR, MAX_PATH_BYTES);
  619. if (szDisplayString == NULL) {
  620. // unable to allocate string buffer so try default message
  621. DisplayMessageBox (
  622. hwndDlg,
  623. NCDU_COPY_COMPLETE,
  624. 0,
  625. MB_OK_TASK_INFO);
  626. } else {
  627. #ifdef TERMSRV
  628. nDiskCount = NumberOfDisks(hwndDlg);
  629. _stprintf (szDisplayString,
  630. GetStringResource (
  631. //(cfData.dwDirsCreated == 1) ?
  632. (nDiskCount == 1) ?
  633. FMT_COPY_COMPLETE_STATS1 :
  634. FMT_COPY_COMPLETE_STATS2),
  635. nDiskCount, cfData.dwFilesCopied);
  636. #else // TERMSRV
  637. _stprintf (szDisplayString,
  638. GetStringResource (FMT_COPY_COMPLETE_STATS),
  639. cfData.dwDirsCreated, cfData.dwFilesCopied);
  640. #endif // TERMSRV
  641. MessageBox (
  642. hwndDlg, szDisplayString,
  643. GetStringResource (SZ_APP_TITLE),
  644. MB_OK_TASK_INFO);
  645. FREE_IF_ALLOC (szDisplayString);
  646. }
  647. } else {
  648. DisplayMessageBox (
  649. hwndDlg,
  650. NCDU_DISK_NOT_DONE,
  651. 0,
  652. MB_OK_TASK_EXCL);
  653. }
  654. PostMessage (GetParent(hwndDlg), NCDU_SHOW_SW_CONFIG_DLG, 0, 0);
  655. SetCursor(LoadCursor(NULL, IDC_WAIT));
  656. } else {
  657. // unsupported format
  658. nCancelResult = DisplayMessageBox (
  659. hwndDlg,
  660. NCDU_UNKNOWN_FLOPPY,
  661. 0,
  662. MB_OK_TASK_EXCL);
  663. }
  664. FREE_IF_ALLOC (szFromPath);
  665. FREE_IF_ALLOC (szClientName);
  666. FREE_IF_ALLOC (szDisplayName);
  667. FREE_IF_ALLOC (szInfName);
  668. FREE_IF_ALLOC (szDiskName);
  669. FREE_IF_ALLOC (szVolumeLabel);
  670. FREE_IF_ALLOC (szClientSection);
  671. return TRUE;
  672. }
  673. static
  674. BOOL
  675. CopyFlopDlg_WM_COMMAND (
  676. IN HWND hwndDlg,
  677. IN WPARAM wParam,
  678. IN LPARAM lParam
  679. )
  680. /*++
  681. Routine Description:
  682. processes the WM_COMMAND windows message. The only buttons processed
  683. are:
  684. IDCANCEL which will cause the dlg box to exit.
  685. Make Disks start the copy file process
  686. Arguments:
  687. IN HWND hwndDlg
  688. Handle to dialog box window
  689. IN WPARAM wParam
  690. LOWORD has ID of control selected
  691. IN LPARAM lParam
  692. Not Used.
  693. Return Value:
  694. TRUE if message not processed,
  695. otherwise value returned by selected function
  696. --*/
  697. {
  698. switch (LOWORD(wParam)) {
  699. case IDCANCEL:
  700. switch (HIWORD(wParam)) {
  701. case BN_CLICKED:
  702. #ifdef TERMSRV
  703. if ( szCommandLineVal[0] != 0x00 )
  704. PostQuitMessage(ERROR_SUCCESS);
  705. #endif // TERMSRV
  706. PostMessage (GetParent(hwndDlg), NCDU_SHOW_SHARE_NET_SW_DLG, 0, 0);
  707. SetCursor(LoadCursor(NULL, IDC_WAIT));
  708. return TRUE;
  709. default:
  710. return FALSE;
  711. }
  712. case NCDU_CLIENT_SOFTWARE_LIST:
  713. switch (HIWORD(wParam)) {
  714. case LBN_SELCHANGE:
  715. // update the disk count for the currently selected client
  716. UpdateDiskCount (hwndDlg);
  717. return TRUE;
  718. case LBN_DBLCLK:
  719. // pretend that the OK buton was pressed
  720. PostMessage (hwndDlg, WM_COMMAND,
  721. MAKEWPARAM (NCDU_MAKE_DISKS, BN_CLICKED),
  722. (LPARAM)GetDlgItem(hwndDlg, NCDU_MAKE_DISKS));
  723. return TRUE;
  724. default:
  725. return FALSE;
  726. }
  727. case NCDU_MAKE_DISKS: return CopyFlopDlg_NCDU_MAKE_DISKS (hwndDlg);
  728. case NCDU_CREATE_INSTALL_DISKS_HELP:
  729. switch (HIWORD(wParam)) {
  730. case BN_CLICKED:
  731. // return ShowAppHelp (hwndDlg, LOWORD(wParam));
  732. return PostMessage (GetParent(hwndDlg), WM_HOTKEY,
  733. (WPARAM)NCDU_HELP_HOT_KEY, 0);
  734. default:
  735. return FALSE;
  736. }
  737. default: return TRUE;
  738. }
  739. }
  740. INT_PTR CALLBACK
  741. CopyFlopDlgProc (
  742. IN HWND hwndDlg,
  743. IN UINT message,
  744. IN WPARAM wParam,
  745. IN LPARAM lParam
  746. )
  747. /*++
  748. Routine Description:
  749. Main window processing routine. Processes the following messages by
  750. dispatching to the local processing routine. All other messages
  751. are handled by the default dialog procedure.
  752. WM_INITDIALOG: dialog box initialization
  753. WM_COMMAND: user input message
  754. WM_PAINT: for painting icon when minimized
  755. WM_MOVE: for saving the new location of the window
  756. WM_SYSCOMMAND: for processing menu messages
  757. Arguments:
  758. standard WNDPROC arguments
  759. Return Value:
  760. FALSE if message not processed here, otherwise
  761. value returned by dispatched routine.
  762. --*/
  763. {
  764. switch (message) {
  765. case WM_INITDIALOG: return (CopyFlopDlg_WM_INITDIALOG (hwndDlg, wParam, lParam));
  766. case WM_COMMAND: return (CopyFlopDlg_WM_COMMAND (hwndDlg, wParam, lParam));
  767. case WM_PAINT: return (Dlg_WM_PAINT (hwndDlg, wParam, lParam));
  768. case WM_MOVE: return (Dlg_WM_MOVE (hwndDlg, wParam, lParam));
  769. case WM_SYSCOMMAND: return (Dlg_WM_SYSCOMMAND (hwndDlg, wParam, lParam));
  770. default: return FALSE;
  771. }
  772. }