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.

324 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bkinst.c
  5. Abstract:
  6. Routine to install the on-line books to a local hard drive.
  7. Author:
  8. Ted Miller (tedm) 5-Jan-1995
  9. Revision History:
  10. --*/
  11. #include "books.h"
  12. //
  13. // Define structure that described a file to be copied.
  14. //
  15. typedef struct _FILETOCOPY {
  16. struct _FILETOCOPY *Next;
  17. WIN32_FIND_DATA FindData;
  18. } FILETOCOPY, *PFILETOCOPY;
  19. //
  20. // Header of a linked list describing the files to be copied.
  21. //
  22. PFILETOCOPY CopyList;
  23. //
  24. // Custom window message
  25. //
  26. #define WMX_I_AM_READY (WM_USER+567)
  27. VOID
  28. TearDownCopyList(
  29. VOID
  30. )
  31. /*++
  32. Routine Description:
  33. Delete the copy list structure, freeing all memory used by it.
  34. Arguments:
  35. None.
  36. Return Value:
  37. None. CopyList will be NULL on exit.
  38. --*/
  39. {
  40. PFILETOCOPY p,q;
  41. for(p=CopyList; p; p=q) {
  42. q = p->Next;
  43. MyFree(p);
  44. }
  45. CopyList = NULL;
  46. }
  47. BOOL
  48. BuildFileList(
  49. IN PWSTR Directory
  50. )
  51. /*++
  52. Routine Description:
  53. Build a list of files contained in a given directory.
  54. Arguments:
  55. Directory - supplies the directory whose contents are to be enumarated
  56. and placed in a list.
  57. Return Value:
  58. Boolean value indicating outcome. If the return value is TRUE then the
  59. global CopyList variable will point to a linked list of files in
  60. the directory.
  61. --*/
  62. {
  63. HANDLE h;
  64. PFILETOCOPY p;
  65. WCHAR SearchSpec[MAX_PATH];
  66. PFILETOCOPY Previous;
  67. BOOL b;
  68. Previous = NULL;
  69. lstrcpy(SearchSpec,Directory);
  70. lstrcat(SearchSpec,L"\\*");
  71. p = MyMalloc(sizeof(FILETOCOPY));
  72. h = FindFirstFile(SearchSpec,&p->FindData);
  73. if(h != INVALID_HANDLE_VALUE) {
  74. CopyList = p;
  75. Previous = p;
  76. do {
  77. p = MyMalloc(sizeof(FILETOCOPY));
  78. if(b = FindNextFile(h,&p->FindData)) {
  79. Previous->Next = p;
  80. Previous = p;
  81. }
  82. } while(b);
  83. FindClose(h);
  84. }
  85. MyFree(p);
  86. if(!(b = (GetLastError() == ERROR_NO_MORE_FILES))) {
  87. TearDownCopyList();
  88. }
  89. return(b);
  90. }
  91. DWORD WINAPI
  92. ThreadBuildFileList(
  93. IN PVOID ThreadParameter
  94. )
  95. /*++
  96. Routine Description:
  97. Entry point for worker thread that builds a list of files to be copied.
  98. This thread is designed to be started by the ActionWithBillboard().
  99. Arguments:
  100. ThreadParameter - supplies thread parameters. This is expected to point
  101. to a ACTIONTHREADPARAMS structure, from which we can determine the
  102. billboard dialog's window handle and the directory to be enumerated.
  103. Return Value:
  104. Always 0. The actual 'return value' is communicated buy posting a message
  105. to the billboard dialog, and is the value returned by BuildFileList().
  106. --*/
  107. {
  108. PACTIONTHREADPARAMS p;
  109. BOOL b;
  110. p = ThreadParameter;
  111. //
  112. // Allow time for billboard dialog to come up
  113. //
  114. Sleep(250);
  115. //
  116. // Do it.
  117. //
  118. b = BuildFileList(p->UserData);
  119. //
  120. // Tell the billboard that we're done.
  121. //
  122. PostMessage(p->hdlg,WM_COMMAND,IDOK,b);
  123. ExitThread(0);
  124. return 0; // prevent compiler warning
  125. }
  126. INT_PTR
  127. CALLBACK
  128. DlgProcInstall(
  129. IN HWND hdlg,
  130. IN UINT msg,
  131. IN WPARAM wParam,
  132. IN LPARAM lParam
  133. )
  134. {
  135. DWORD rc;
  136. WCHAR Directory[MAX_PATH];
  137. int i;
  138. switch(msg) {
  139. case WM_INITDIALOG:
  140. CenterDialogOnScreen(hdlg);
  141. GetWindowsDirectory(Directory,MAX_PATH);
  142. lstrcat(Directory,L"\\BOOKS");
  143. SetDlgItemText(hdlg,IDC_INSTALL_TO,Directory);
  144. SendDlgItemMessage(hdlg,IDC_INSTALL_TO,EM_SETSEL,0,(LPARAM)-1);
  145. SendDlgItemMessage(hdlg,IDC_INSTALL_TO,EM_LIMITTEXT,MAX_PATH-1,0);
  146. SetFocus(GetDlgItem(hdlg,IDC_INSTALL_TO));
  147. PostMessage(hdlg,WMX_I_AM_READY,0,lParam);
  148. //
  149. // Tell Windows we set the focus
  150. //
  151. return(FALSE);
  152. case WMX_I_AM_READY:
  153. do {
  154. rc = ActionWithBillboard(
  155. ThreadBuildFileList,
  156. hdlg,
  157. IDS_FILELIST_CAPTION,
  158. IDS_FILELIST,
  159. *(PWSTR *)lParam
  160. );
  161. //
  162. // If rc is 0, we could not build file list.
  163. //
  164. if(!rc) {
  165. //
  166. // See if user wants to cancel or retry.
  167. //
  168. i = MessageBoxFromMessage(
  169. hdlg,
  170. MSG_CANT_GET_FILE_LIST,
  171. 0,
  172. MB_RETRYCANCEL | MB_ICONSTOP | MB_SETFOREGROUND | MB_APPLMODAL
  173. );
  174. if(i = IDCANCEL) {
  175. EndDialog(hdlg,FALSE);
  176. break;
  177. }
  178. }
  179. } while(!rc);
  180. break;
  181. case WM_COMMAND:
  182. switch(HIWORD(wParam)) {
  183. case BN_CLICKED:
  184. switch(LOWORD(wParam)) {
  185. case IDOK:
  186. //
  187. // See whether the user gave us something reasonable
  188. // before attempting the copy.
  189. //
  190. return(FALSE);
  191. case IDCANCEL:
  192. EndDialog(hdlg,FALSE);
  193. return(FALSE);
  194. }
  195. break;
  196. }
  197. break;
  198. case WM_QUERYDRAGICON:
  199. return(MainIcon != 0);
  200. default:
  201. return(FALSE);
  202. }
  203. return(TRUE);
  204. }
  205. BOOL
  206. DoInstall(
  207. IN OUT PWSTR *Location
  208. )
  209. {
  210. BOOL rc;
  211. rc = (BOOL)DialogBoxParam(
  212. hInst,
  213. MAKEINTRESOURCE(DLG_INSTALL),
  214. NULL,
  215. DlgProcInstall,
  216. (LPARAM)Location
  217. );
  218. TearDownCopyList();
  219. return(rc);
  220. }