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.

292 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. winmine.c
  5. Abstract:
  6. This source file implements the operations needed to properly migrate
  7. Minesweeper settings from Windows 9x to Windows NT. This is part of the
  8. Setup Migration DLL.
  9. Author:
  10. Ovidiu Temereanca (ovidiut) 07-Jul-1999
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. #include "setupmigp.h"
  15. #define S_WINMINE_INI "WINMINE.INI"
  16. #define S_ALREADYPLAYED "AlreadyPlayed"
  17. #define S_WINMINE "Software\\Microsoft\\winmine"
  18. BOOL
  19. WinMine_Attach (
  20. IN HINSTANCE DllInstance
  21. )
  22. {
  23. return TRUE;
  24. }
  25. BOOL
  26. WinMine_Detach (
  27. IN HINSTANCE DllInstance
  28. )
  29. {
  30. return TRUE;
  31. }
  32. LONG
  33. WinMine_QueryVersion (
  34. IN PCSTR *ExeNamesBuf
  35. )
  36. {
  37. CHAR Path[MAX_PATH];
  38. PSTR p;
  39. if (!GetWindowsDirectoryA (Path, MAX_PATH)) {
  40. return GetLastError ();
  41. }
  42. p = AppendWackA (Path);
  43. StringCopyA (p, S_WINMINE_INI);
  44. if (DoesFileExistA (Path)) {
  45. return ERROR_SUCCESS;
  46. }
  47. return ERROR_NOT_INSTALLED;
  48. }
  49. LONG
  50. WinMine_Initialize9x (
  51. IN PCSTR WorkingDirectory,
  52. IN PCSTR SourceDirectories
  53. )
  54. {
  55. return ERROR_SUCCESS;
  56. }
  57. LONG
  58. WinMine_MigrateUser9x (
  59. IN HWND ParentWnd,
  60. IN PCSTR UnattendFile,
  61. IN HKEY UserRegKey,
  62. IN PCSTR UserName
  63. )
  64. {
  65. return ERROR_SUCCESS;
  66. }
  67. LONG
  68. WinMine_MigrateSystem9x (
  69. IN HWND ParentWnd,
  70. IN PCSTR UnattendFile
  71. )
  72. {
  73. CHAR Path[MAX_PATH];
  74. PSTR p;
  75. if (!GetWindowsDirectoryA (Path, MAX_PATH)) {
  76. return GetLastError ();
  77. }
  78. p = AppendWackA (Path);
  79. StringCopyA (p, S_WINMINE_INI);
  80. //
  81. // write this file to Handled
  82. //
  83. if (!WritePrivateProfileStringA (S_HANDLED, Path, "FILE", g_MigrateInfPath)) {
  84. DEBUGMSGA ((DBG_ERROR, "WinMine migration DLL: Could not write winmine.ini as handled."));
  85. }
  86. return ERROR_SUCCESS;
  87. }
  88. BOOL
  89. pGetUINT (
  90. IN PCSTR Value,
  91. OUT PUINT ui
  92. )
  93. {
  94. INT i = 0;
  95. CHAR ch;
  96. if (!Value || !*Value) {
  97. return FALSE;
  98. }
  99. while((ch = (CHAR)_mbsnextc (Value)) != 0) {
  100. if (ch < '0' || ch > '9') {
  101. return FALSE;
  102. }
  103. i = i * 10 + ch - '0';
  104. if (i < 0) {
  105. return FALSE;
  106. }
  107. Value = _mbsinc (Value);
  108. }
  109. *ui = i;
  110. return TRUE;
  111. }
  112. LONG
  113. WinMine_InitializeNT (
  114. IN PCWSTR WorkingDirectory,
  115. IN PCWSTR SourceDirectories
  116. )
  117. {
  118. return ERROR_SUCCESS;
  119. }
  120. LONG
  121. WinMine_MigrateUserNT (
  122. IN HINF UnattendFile,
  123. IN HKEY UserRegKey,
  124. IN PCWSTR UserName
  125. )
  126. {
  127. HKEY Key;
  128. LONG rc = ERROR_SUCCESS;
  129. DWORD Value = 1;
  130. CHAR Path[MAX_PATH];
  131. CHAR SectBuffer[MAX_PATH];
  132. CHAR KeyBuffer[MAX_PATH];
  133. CHAR String[MAX_PATH];
  134. PSTR p;
  135. UINT ui;
  136. if (!GetWindowsDirectoryA (Path, MAX_PATH)) {
  137. return GetLastError ();
  138. }
  139. p = AppendWackA (Path);
  140. StringCopyA (p, S_WINMINE_INI);
  141. if (!DoesFileExistA (Path)) {
  142. DEBUGMSGA ((DBG_ERROR, "Could not find %s", Path));
  143. return ERROR_FILE_NOT_FOUND;
  144. }
  145. rc = TrackedRegCreateKeyA (
  146. UserRegKey,
  147. S_WINMINE,
  148. &Key
  149. );
  150. if (rc != ERROR_SUCCESS) {
  151. DEBUGMSGA ((DBG_ERROR, "Could not create user key %s", S_WINMINE));
  152. return rc;
  153. }
  154. rc = RegSetValueExA (
  155. Key,
  156. S_ALREADYPLAYED,
  157. 0,
  158. REG_DWORD,
  159. (PCBYTE)&Value,
  160. sizeof (Value)
  161. );
  162. if (rc == ERROR_SUCCESS) {
  163. Value = GetPrivateProfileStringA (NULL, NULL, "", SectBuffer, sizeof (SectBuffer), Path);
  164. if (Value > 0 && Value < sizeof (SectBuffer) - 2) {
  165. //
  166. // there should be only one section
  167. //
  168. if (*(SectBuffer + SizeOfStringA (SectBuffer)) == 0) {
  169. //
  170. // get all keys with numeric values and put them in the registry
  171. // as REG_DWORD; the rest of them migrate as text
  172. //
  173. Value = GetPrivateProfileStringA (
  174. SectBuffer,
  175. NULL,
  176. "",
  177. KeyBuffer,
  178. sizeof (KeyBuffer),
  179. Path
  180. );
  181. if (Value > 0 && Value < sizeof (KeyBuffer) - 1) {
  182. p = KeyBuffer;
  183. while (rc == ERROR_SUCCESS && *p) {
  184. Value = GetPrivateProfileStringA (
  185. SectBuffer,
  186. p,
  187. "",
  188. String,
  189. sizeof (String),
  190. Path
  191. );
  192. if (Value > 0) {
  193. if (pGetUINT (String, &ui)) {
  194. MYASSERT (sizeof (ui) == sizeof (DWORD));
  195. rc = RegSetValueExA (
  196. Key,
  197. p,
  198. 0,
  199. REG_DWORD,
  200. (PCBYTE)&ui,
  201. sizeof (ui)
  202. );
  203. if (rc == ERROR_SUCCESS) {
  204. DEBUGMSGA ((DBG_VERBOSE, "Migrated value %s=%lu", p, ui));
  205. } else {
  206. DEBUGMSGA ((DBG_ERROR, "Couldn't migrate value %s", p));
  207. }
  208. } else {
  209. rc = RegSetValueExA (
  210. Key,
  211. p,
  212. 0,
  213. REG_SZ,
  214. (PCBYTE)String,
  215. Value + 1
  216. );
  217. if (rc == ERROR_SUCCESS) {
  218. DEBUGMSGA ((DBG_VERBOSE, "Migrated value %s=%s", p, String));
  219. } else {
  220. DEBUGMSGA ((DBG_ERROR, "Couldn't migrate value %s", p));
  221. }
  222. }
  223. }
  224. p += SizeOfStringA (p);
  225. }
  226. }
  227. }
  228. ELSE_DEBUGMSGA ((DBG_WARNING, "Found multiple sections in winmine.ini"));
  229. }
  230. }
  231. ELSE_DEBUGMSGA ((DBG_ERROR, "Could not create Value %s", S_ALREADYPLAYED));
  232. CloseRegKey (Key);
  233. return rc;
  234. }
  235. LONG
  236. WinMine_MigrateSystemNT (
  237. IN HINF UnattendFile
  238. )
  239. {
  240. return ERROR_SUCCESS;
  241. }