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.

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