1 #include "InstallerMain.h"
2 #include "InstallerUtil.h"
3 #include "ChooseMethod.h"
6 #include "SelectGame.h"
7 #include "PerformInstall.h"
8 #include "LocalCopyMethod.h"
10 game_group_t *g_game_group = NULL;
11 unsigned int method_chosen = 0;
12 TCHAR method_path[MAX_PATH];
14 bool SelectFolder(HWND hOwner)
20 if (FAILED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
25 info.hwndOwner = hOwner;
27 info.pszDisplayName = path;
28 info.lpszTitle = _T("Select a game/mod folder");
29 info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
34 if ((pidlist = SHBrowseForFolder(&info)) == NULL)
40 /* This hellish code is from MSDN and translate shortcuts to real targets.
41 * God almighty, I wish Window used real symlinks.
43 bool acquire_success = false;
45 IShellFolder *psf = NULL;
46 LPCITEMIDLIST new_item_list;
49 hr = SHBindToParent(pidlist, IID_IShellFolder, (void **)&psf, &new_item_list);
52 IShellLink *psl = NULL;
54 hr = psf->GetUIObjectOf(hOwner, 1, &new_item_list, IID_IShellLink, NULL, (void **)&psl);
57 LPITEMIDLIST new_item_list;
59 hr = psl->GetIDList(&new_item_list);
64 hr = SHGetPathFromIDList(new_item_list, method_path);
67 acquire_success = true;
70 CoTaskMemFree(new_item_list);
77 if (!acquire_success && !is_link)
79 hr = SHGetPathFromIDList(pidlist, method_path);
82 acquire_success = true;
86 /* That was awful. shoo, shoo, COM */
87 CoTaskMemFree(pidlist);
90 return acquire_success;
93 INT_PTR CALLBACK ChooseMethodHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
99 if (LOWORD(wParam) == ID_METHOD_BACK)
101 UpdateGlobalPosition(hDlg);
102 EndDialog(hDlg, (INT_PTR)DisplayWelcome);
103 return (INT_PTR)TRUE;
105 else if (LOWORD(wParam) == ID_METHOD_EXIT
106 || LOWORD(wParam) == ID_CLOSE)
108 return AskToExit(hDlg);
110 else if (LOWORD(wParam) == IDC_METHOD_DED_SERVER
111 || LOWORD(wParam) == IDC_METHOD_ALONE_SERVER
112 || LOWORD(wParam) == IDC_METHOD_LISTEN_SERVER
113 || LOWORD(wParam) == IDC_METHOD_UPLOAD_FTP
114 || LOWORD(wParam) == IDC_METHOD_CUSTOM_FOLDER)
116 method_chosen = LOWORD(wParam);
117 HWND button = GetDlgItem(hDlg, ID_METHOD_NEXT);
118 EnableWindow(button, TRUE);
121 else if (LOWORD(wParam) == ID_METHOD_NEXT)
123 unsigned int game_type = 0;
125 switch (method_chosen)
127 case IDC_METHOD_DED_SERVER:
129 game_type = GAMES_DEDICATED;
132 case IDC_METHOD_ALONE_SERVER:
134 game_type = GAMES_STANDALONE;
137 case IDC_METHOD_LISTEN_SERVER:
139 game_type = GAMES_LISTEN;
142 case IDC_METHOD_UPLOAD_FTP:
146 case IDC_METHOD_CUSTOM_FOLDER:
150 if (!SelectFolder(hDlg))
155 val = IsValidFolder(method_path);
156 if (val != GAMEINFO_IS_USABLE)
158 DisplayBadFolderDialog(hDlg, val);
162 g_LocalCopier.SetOutputPath(method_path);
163 SetInstallMethod(&g_LocalCopier);
165 UpdateGlobalPosition(hDlg);
166 EndDialog(hDlg, (INT_PTR)DisplayPerformInstall);
176 if (game_type == GAMES_DEDICATED)
178 g_game_group = &g_games.dedicated;
180 else if (game_type == GAMES_LISTEN)
182 g_game_group = &g_games.listen;
184 else if (game_type == GAMES_STANDALONE)
186 g_game_group = &g_games.standalone;
189 if (g_game_group == NULL)
191 return (INT_PTR)TRUE;
194 if (g_game_group->list_count == 0)
196 DisplayBadGamesDialog(hDlg, g_game_group->error_code);
197 return (INT_PTR)TRUE;
200 /* If we got a valid games list, we can display the next
203 UpdateGlobalPosition(hDlg);
204 EndDialog(hDlg, (INT_PTR)DisplaySelectGame);
205 return (INT_PTR)TRUE;
212 SetToGlobalPosition(hDlg);
213 return (INT_PTR)TRUE;
217 return (INT_PTR)FALSE;
220 void *DisplayChooseMethod(HWND hWnd)
224 if ((val = DialogBox(
226 MAKEINTRESOURCE(IDD_CHOOSE_METHOD),
228 ChooseMethodHandler)) == -1)