appdefaults.c 20 KB

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