appdefaults.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. /*
  2. * WineCfg app settings tabsheet
  3. *
  4. * Copyright 2004 Robert van Herk
  5. * Copyright 2004 Chris Morgan
  6. * Copyright 2004 Mike Hearn
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  21. *
  22. */
  23. #define WIN32_LEAN_AND_MEAN
  24. #include <windows.h>
  25. #include <commdlg.h>
  26. #include <wine/debug.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <assert.h>
  30. #include "wine/heap.h"
  31. #include "winecfg.h"
  32. #include "resource.h"
  33. WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
  34. struct win_version
  35. {
  36. const WCHAR *szVersion;
  37. const WCHAR *szDescription;
  38. DWORD dwMajorVersion;
  39. DWORD dwMinorVersion;
  40. DWORD dwBuildNumber;
  41. DWORD dwPlatformId;
  42. const WCHAR *szCSDVersion;
  43. WORD wServicePackMajor;
  44. WORD wServicePackMinor;
  45. const WCHAR *szProductType;
  46. };
  47. static const struct win_version win_versions[] =
  48. {
  49. { L"win10", L"Windows 10", 10, 0, 0x4563,VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
  50. { L"win81", L"Windows 8.1", 6, 3, 0x2580,VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
  51. { L"win8", L"Windows 8", 6, 2, 0x23F0,VER_PLATFORM_WIN32_NT, L"", 0, 0, L"WinNT"},
  52. { L"win2008r2", L"Windows 2008 R2", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, L"Service Pack 1", 1, 0, L"ServerNT"},
  53. { L"win7", L"Windows 7", 6, 1, 0x1DB1,VER_PLATFORM_WIN32_NT, L"Service Pack 1", 1, 0, L"WinNT"},
  54. { L"win2008", L"Windows 2008", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"ServerNT"},
  55. { L"vista", L"Windows Vista", 6, 0, 0x1772,VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"WinNT"},
  56. { L"win2003", L"Windows 2003", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"ServerNT"},
  57. #ifdef _WIN64
  58. { L"winxp64", L"Windows XP", 5, 2, 0xECE, VER_PLATFORM_WIN32_NT, L"Service Pack 2", 2, 0, L"WinNT"},
  59. #else
  60. { L"winxp", L"Windows XP", 5, 1, 0xA28, VER_PLATFORM_WIN32_NT, L"Service Pack 3", 3, 0, L"WinNT"},
  61. { L"win2k", L"Windows 2000", 5, 0, 0x893, VER_PLATFORM_WIN32_NT, L"Service Pack 4", 4, 0, L"WinNT"},
  62. { L"winme", L"Windows ME", 4, 90, 0xBB8, VER_PLATFORM_WIN32_WINDOWS, L" ", 0, 0, L""},
  63. { L"win98", L"Windows 98", 4, 10, 0x8AE, VER_PLATFORM_WIN32_WINDOWS, L" A ", 0, 0, L""},
  64. { L"win95", L"Windows 95", 4, 0, 0x3B6, VER_PLATFORM_WIN32_WINDOWS, L"", 0, 0, L""},
  65. { L"nt40", L"Windows NT 4.0", 4, 0, 0x565, VER_PLATFORM_WIN32_NT, L"Service Pack 6a", 6, 0, L"WinNT"},
  66. { L"nt351", L"Windows NT 3.51", 3, 51, 0x421, VER_PLATFORM_WIN32_NT, L"Service Pack 5", 5, 0, L"WinNT"},
  67. { L"win31", L"Windows 3.1", 3, 10, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""},
  68. { L"win30", L"Windows 3.0", 3, 0, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""},
  69. { L"win20", L"Windows 2.0", 2, 0, 0, VER_PLATFORM_WIN32s, L"Win32s 1.3", 0, 0, L""}
  70. #endif
  71. };
  72. #define DEFAULT_WIN_VERSION L"win7"
  73. static const WCHAR szKey9x[] = L"Software\\Microsoft\\Windows\\CurrentVersion";
  74. static const WCHAR szKeyNT[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion";
  75. static const WCHAR szKeyProdNT[] = L"System\\CurrentControlSet\\Control\\ProductOptions";
  76. static int get_registry_version(void)
  77. {
  78. int i, best = -1, platform, major, minor = 0, build = 0;
  79. WCHAR *p, *ver, *type = NULL;
  80. if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL )))
  81. {
  82. WCHAR *build_str;
  83. platform = VER_PLATFORM_WIN32_NT;
  84. build_str = get_reg_key( HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL );
  85. build = wcstol(build_str, NULL, 10);
  86. type = get_reg_key( HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL );
  87. }
  88. else if ((ver = get_reg_key( HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL )))
  89. platform = VER_PLATFORM_WIN32_WINDOWS;
  90. else
  91. return -1;
  92. if ((p = wcschr( ver, '.' )))
  93. {
  94. WCHAR *minor_str = p;
  95. *minor_str++ = 0;
  96. if ((p = wcschr( minor_str, '.' )))
  97. {
  98. WCHAR *build_str = p;
  99. *build_str++ = 0;
  100. build = wcstol(build_str, NULL, 10);
  101. }
  102. minor = wcstol(minor_str, NULL, 10);
  103. }
  104. major = wcstol(ver, NULL, 10);
  105. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  106. {
  107. if (win_versions[i].dwPlatformId != platform) continue;
  108. if (win_versions[i].dwMajorVersion != major) continue;
  109. if (type && wcsicmp(win_versions[i].szProductType, type)) continue;
  110. best = i;
  111. if ((win_versions[i].dwMinorVersion == minor) &&
  112. (win_versions[i].dwBuildNumber == build))
  113. return i;
  114. }
  115. return best;
  116. }
  117. static void update_comboboxes(HWND dialog)
  118. {
  119. int i, ver;
  120. WCHAR *winver;
  121. /* retrieve the registry values */
  122. winver = get_reg_key(config_key, keypath(L""), L"Version", L"");
  123. ver = get_registry_version();
  124. if (!winver || !winver[0])
  125. {
  126. HeapFree(GetProcessHeap(), 0, winver);
  127. if (current_app) /* no explicit setting */
  128. {
  129. WINE_TRACE("setting winver combobox to default\n");
  130. SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL, 0, 0);
  131. return;
  132. }
  133. if (ver != -1) winver = strdupW( win_versions[ver].szVersion );
  134. else winver = strdupW(DEFAULT_WIN_VERSION);
  135. }
  136. WINE_TRACE("winver is %s\n", debugstr_w(winver));
  137. /* normalize the version strings */
  138. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  139. {
  140. if (!wcsicmp(win_versions[i].szVersion, winver))
  141. {
  142. SendDlgItemMessageW(dialog, IDC_WINVER, CB_SETCURSEL,
  143. i + (current_app?1:0), 0);
  144. WINE_TRACE("match with %s\n", debugstr_w(win_versions[i].szVersion));
  145. break;
  146. }
  147. }
  148. HeapFree(GetProcessHeap(), 0, winver);
  149. }
  150. static void
  151. init_comboboxes (HWND dialog)
  152. {
  153. int i;
  154. SendDlgItemMessageW(dialog, IDC_WINVER, CB_RESETCONTENT, 0, 0);
  155. /* add the default entries (automatic) which correspond to no setting */
  156. if (current_app)
  157. {
  158. WCHAR str[256];
  159. LoadStringW(GetModuleHandleW(NULL), IDS_USE_GLOBAL_SETTINGS, str, ARRAY_SIZE(str));
  160. SendDlgItemMessageW (dialog, IDC_WINVER, CB_ADDSTRING, 0, (LPARAM)str);
  161. }
  162. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  163. {
  164. SendDlgItemMessageW(dialog, IDC_WINVER, CB_ADDSTRING,
  165. 0, (LPARAM) win_versions[i].szDescription);
  166. }
  167. }
  168. static void add_listview_item(HWND listview, WCHAR *text, void *association)
  169. {
  170. LVITEMW item;
  171. item.mask = LVIF_TEXT | LVIF_PARAM;
  172. item.pszText = text;
  173. item.cchTextMax = lstrlenW(text);
  174. item.lParam = (LPARAM) association;
  175. item.iItem = SendMessageW( listview, LVM_GETITEMCOUNT, 0, 0 );
  176. item.iSubItem = 0;
  177. SendMessageW(listview, LVM_INSERTITEMW, 0, (LPARAM) &item);
  178. }
  179. /* Called when the application is initialized (cannot reinit!) */
  180. static void init_appsheet(HWND dialog)
  181. {
  182. HWND listview;
  183. LVITEMW item;
  184. HKEY key;
  185. int i;
  186. DWORD size;
  187. WCHAR appname[1024];
  188. WINE_TRACE("()\n");
  189. listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  190. /* we use the lparam field of the item so we can alter the presentation later and not change code
  191. * for instance, to use the tile view or to display the EXEs embedded 'display name' */
  192. LoadStringW(GetModuleHandleW(NULL), IDS_DEFAULT_SETTINGS, appname, ARRAY_SIZE(appname));
  193. add_listview_item(listview, appname, NULL);
  194. /* because this list is only populated once, it's safe to bypass the settings list here */
  195. if (RegOpenKeyW(config_key, L"AppDefaults", &key) == ERROR_SUCCESS)
  196. {
  197. i = 0;
  198. size = ARRAY_SIZE(appname);
  199. while (RegEnumKeyExW (key, i, appname, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
  200. {
  201. add_listview_item(listview, appname, strdupW(appname));
  202. i++;
  203. size = ARRAY_SIZE(appname);
  204. }
  205. RegCloseKey(key);
  206. }
  207. init_comboboxes(dialog);
  208. /* Select the default settings listview item */
  209. item.iItem = 0;
  210. item.iSubItem = 0;
  211. item.mask = LVIF_STATE;
  212. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  213. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  214. SendMessageW(listview, LVM_SETITEMW, 0, (LPARAM) &item);
  215. }
  216. /* there has to be an easier way than this */
  217. static int get_listview_selection(HWND listview)
  218. {
  219. int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
  220. int i;
  221. for (i = 0; i < count; i++)
  222. {
  223. if (SendMessageW( listview, LVM_GETITEMSTATE, i, LVIS_SELECTED )) return i;
  224. }
  225. return -1;
  226. }
  227. /* called when the user selects a different application */
  228. static void on_selection_change(HWND dialog, HWND listview)
  229. {
  230. LVITEMW item;
  231. WCHAR* oldapp = current_app;
  232. WINE_TRACE("()\n");
  233. item.iItem = get_listview_selection(listview);
  234. item.iSubItem = 0;
  235. item.mask = LVIF_PARAM;
  236. WINE_TRACE("item.iItem=%d\n", item.iItem);
  237. if (item.iItem == -1) return;
  238. SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
  239. current_app = (WCHAR*) item.lParam;
  240. if (current_app)
  241. {
  242. WINE_TRACE("current_app is now %s\n", wine_dbgstr_w (current_app));
  243. enable(IDC_APP_REMOVEAPP);
  244. }
  245. else
  246. {
  247. WINE_TRACE("current_app=NULL, editing global settings\n");
  248. /* focus will never be on the button in this callback so it's safe */
  249. disable(IDC_APP_REMOVEAPP);
  250. }
  251. /* reset the combo boxes if we changed from/to global/app-specific */
  252. if ((oldapp && !current_app) || (!oldapp && current_app))
  253. init_comboboxes(dialog);
  254. update_comboboxes(dialog);
  255. set_window_title(dialog);
  256. }
  257. static BOOL list_contains_file(HWND listview, WCHAR *filename)
  258. {
  259. LVFINDINFOW find_info = { LVFI_STRING, filename, 0, {0, 0}, 0 };
  260. int index;
  261. index = ListView_FindItemW(listview, -1, &find_info);
  262. return (index != -1);
  263. }
  264. static void on_add_app_click(HWND dialog)
  265. {
  266. WCHAR filetitle[MAX_PATH];
  267. WCHAR file[MAX_PATH];
  268. WCHAR programsFilter[100], filter[MAX_PATH];
  269. WCHAR selectExecutableStr[100];
  270. OPENFILENAMEW ofn = { sizeof(OPENFILENAMEW),
  271. dialog, /*hInst*/0, 0, NULL, 0, 0, NULL,
  272. 0, NULL, 0, L"C:\\", 0,
  273. OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_ENABLESIZING,
  274. 0, 0, NULL, 0, NULL };
  275. LoadStringW (GetModuleHandleW(NULL), IDS_SELECT_EXECUTABLE, selectExecutableStr,
  276. ARRAY_SIZE(selectExecutableStr));
  277. LoadStringW (GetModuleHandleW(NULL), IDS_EXECUTABLE_FILTER, programsFilter,
  278. ARRAY_SIZE(programsFilter));
  279. swprintf( filter, MAX_PATH, L"%s%c*.exe;*.exe.so%c", programsFilter, 0, 0 );
  280. ofn.lpstrTitle = selectExecutableStr;
  281. ofn.lpstrFilter = filter;
  282. ofn.lpstrFileTitle = filetitle;
  283. ofn.lpstrFileTitle[0] = '\0';
  284. ofn.nMaxFileTitle = ARRAY_SIZE(filetitle);
  285. ofn.lpstrFile = file;
  286. ofn.lpstrFile[0] = '\0';
  287. ofn.nMaxFile = ARRAY_SIZE(file);
  288. if (GetOpenFileNameW (&ofn))
  289. {
  290. HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  291. int count = SendMessageW(listview, LVM_GETITEMCOUNT, 0, 0);
  292. WCHAR* new_app;
  293. LVITEMW item;
  294. if (list_contains_file(listview, filetitle))
  295. return;
  296. new_app = strdupW(filetitle);
  297. WINE_TRACE("adding %s\n", wine_dbgstr_w (new_app));
  298. add_listview_item(listview, new_app, new_app);
  299. item.mask = LVIF_STATE;
  300. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  301. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  302. SendMessageW(listview, LVM_SETITEMSTATE, count, (LPARAM)&item );
  303. SetFocus(listview);
  304. }
  305. else WINE_TRACE("user cancelled\n");
  306. }
  307. static void on_remove_app_click(HWND dialog)
  308. {
  309. HWND listview = GetDlgItem(dialog, IDC_APP_LISTVIEW);
  310. int selection = get_listview_selection(listview);
  311. LVITEMW item;
  312. item.iItem = selection;
  313. item.iSubItem = 0;
  314. item.mask = LVIF_PARAM;
  315. WINE_TRACE("selection=%d\n", selection);
  316. assert( selection != 0 ); /* user cannot click this button when "default settings" is selected */
  317. set_reg_key(config_key, keypath(L""), NULL, NULL); /* delete the section */
  318. SendMessageW(listview, LVM_GETITEMW, 0, (LPARAM) &item);
  319. HeapFree (GetProcessHeap(), 0, (void*)item.lParam);
  320. SendMessageW(listview, LVM_DELETEITEM, selection, 0);
  321. item.mask = LVIF_STATE;
  322. item.state = LVIS_SELECTED | LVIS_FOCUSED;
  323. item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  324. SendMessageW(listview, LVM_SETITEMSTATE, 0, (LPARAM)&item);
  325. SetFocus(listview);
  326. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  327. }
  328. static void set_winver(const struct win_version *version)
  329. {
  330. static const WCHAR szKeyWindNT[] = L"System\\CurrentControlSet\\Control\\Windows";
  331. static const WCHAR szKeyEnvNT[] = L"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
  332. WCHAR buffer[40];
  333. switch (version->dwPlatformId)
  334. {
  335. case VER_PLATFORM_WIN32_WINDOWS:
  336. swprintf(buffer, ARRAY_SIZE(buffer), L"%d.%d.%d", version->dwMajorVersion,
  337. version->dwMinorVersion, version->dwBuildNumber);
  338. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", buffer);
  339. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", version->szCSDVersion);
  340. swprintf(buffer, ARRAY_SIZE(buffer), L"Microsoft %s", version->szDescription);
  341. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", buffer);
  342. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", NULL);
  343. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL);
  344. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMajorVersionNumber", NULL);
  345. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMinorVersionNumber", NULL);
  346. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", NULL);
  347. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL);
  348. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", NULL);
  349. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL);
  350. set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion", NULL);
  351. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", NULL);
  352. set_reg_key(config_key, keypath(L""), L"Version", NULL);
  353. break;
  354. case VER_PLATFORM_WIN32_NT:
  355. swprintf(buffer, ARRAY_SIZE(buffer), L"%d.%d", version->dwMajorVersion,
  356. version->dwMinorVersion);
  357. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", buffer);
  358. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMajorVersionNumber", version->dwMajorVersion);
  359. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentMinorVersionNumber", version->dwMinorVersion);
  360. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", version->szCSDVersion);
  361. swprintf(buffer, ARRAY_SIZE(buffer), L"%d", version->dwBuildNumber);
  362. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", buffer);
  363. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", buffer);
  364. swprintf(buffer, ARRAY_SIZE(buffer), L"Microsoft %s", version->szDescription);
  365. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", buffer);
  366. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", version->szProductType);
  367. set_reg_key_dword(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion",
  368. MAKEWORD( version->wServicePackMinor,
  369. version->wServicePackMajor ));
  370. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", L"Windows_NT");
  371. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL);
  372. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", NULL);
  373. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", NULL);
  374. set_reg_key(config_key, keypath(L""), L"Version", NULL);
  375. break;
  376. case VER_PLATFORM_WIN32s:
  377. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CSDVersion", NULL);
  378. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentVersion", NULL);
  379. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuild", NULL);
  380. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"CurrentBuildNumber", NULL);
  381. set_reg_key(HKEY_LOCAL_MACHINE, szKeyNT, L"ProductName", NULL);
  382. set_reg_key(HKEY_LOCAL_MACHINE, szKeyProdNT, L"ProductType", NULL);
  383. set_reg_key(HKEY_LOCAL_MACHINE, szKeyWindNT, L"CSDVersion", NULL);
  384. set_reg_key(HKEY_LOCAL_MACHINE, szKeyEnvNT, L"OS", NULL);
  385. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"VersionNumber", NULL);
  386. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"SubVersionNumber", NULL);
  387. set_reg_key(HKEY_LOCAL_MACHINE, szKey9x, L"ProductName", NULL);
  388. set_reg_key(config_key, keypath(L""), L"Version", version->szVersion);
  389. break;
  390. }
  391. }
  392. BOOL set_winver_from_string(const WCHAR *version)
  393. {
  394. int i;
  395. WINE_TRACE("desired winver: %s\n", debugstr_w(version));
  396. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  397. {
  398. if (!wcsicmp(win_versions[i].szVersion, version))
  399. {
  400. WINE_TRACE("match with %s\n", debugstr_w(win_versions[i].szVersion));
  401. set_winver(&win_versions[i]);
  402. apply();
  403. return TRUE;
  404. }
  405. }
  406. return FALSE;
  407. }
  408. void print_windows_versions(void)
  409. {
  410. int i;
  411. for (i = 0; i < ARRAY_SIZE(win_versions); i++)
  412. {
  413. wprintf(L" %10s %s\n", win_versions[i].szVersion, win_versions[i].szDescription);
  414. }
  415. }
  416. void print_current_winver(void)
  417. {
  418. WCHAR *winver = get_reg_key(config_key, keypath(L""), L"Version", L"");
  419. if (!winver || !winver[0])
  420. {
  421. int ver = get_registry_version();
  422. wprintf(L"%s\n", ver == -1 ? DEFAULT_WIN_VERSION : win_versions[ver].szVersion);
  423. }
  424. else
  425. wprintf(L"%s\n", winver);
  426. heap_free(winver);
  427. }
  428. static void on_winver_change(HWND dialog)
  429. {
  430. int selection = SendDlgItemMessageW(dialog, IDC_WINVER, CB_GETCURSEL, 0, 0);
  431. if (current_app)
  432. {
  433. if (!selection)
  434. {
  435. WINE_TRACE("default selected so removing current setting\n");
  436. set_reg_key(config_key, keypath(L""), L"Version", NULL);
  437. }
  438. else
  439. {
  440. WINE_TRACE("setting Version key to value %s\n", debugstr_w(win_versions[selection-1].szVersion));
  441. set_reg_key(config_key, keypath(L""), L"Version", win_versions[selection-1].szVersion);
  442. }
  443. }
  444. else /* global version only */
  445. {
  446. set_winver(&win_versions[selection]);
  447. }
  448. /* enable the apply button */
  449. SendMessageW(GetParent(dialog), PSM_CHANGED, (WPARAM) dialog, 0);
  450. }
  451. INT_PTR CALLBACK
  452. AppDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  453. {
  454. switch (uMsg)
  455. {
  456. case WM_INITDIALOG:
  457. init_appsheet(hDlg);
  458. break;
  459. case WM_SHOWWINDOW:
  460. set_window_title(hDlg);
  461. break;
  462. case WM_NOTIFY:
  463. switch (((LPNMHDR)lParam)->code)
  464. {
  465. case LVN_ITEMCHANGED:
  466. on_selection_change(hDlg, GetDlgItem(hDlg, IDC_APP_LISTVIEW));
  467. break;
  468. case PSN_APPLY:
  469. apply();
  470. SetWindowLongPtrW(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  471. break;
  472. }
  473. break;
  474. case WM_COMMAND:
  475. switch(HIWORD(wParam))
  476. {
  477. case CBN_SELCHANGE:
  478. switch(LOWORD(wParam))
  479. {
  480. case IDC_WINVER:
  481. on_winver_change(hDlg);
  482. break;
  483. }
  484. case BN_CLICKED:
  485. switch(LOWORD(wParam))
  486. {
  487. case IDC_APP_ADDAPP:
  488. on_add_app_click(hDlg);
  489. break;
  490. case IDC_APP_REMOVEAPP:
  491. on_remove_app_click(hDlg);
  492. break;
  493. }
  494. break;
  495. }
  496. break;
  497. }
  498. return 0;
  499. }