@@ -270,6 +270,7 @@ BOOL CALLBACK TwoFactorDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lP
270270 }
271271
272272 case WM_COMMAND:
273+ {
273274 switch (HIWORD (wParam))
274275 {
275276 case EN_CHANGE:
@@ -311,11 +312,99 @@ BOOL CALLBACK TwoFactorDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lP
311312 EndDialog (hwnd, IDCANCEL);
312313 break ;
313314 }
315+ break ;
316+ }
314317
315318 default :
316319 return FALSE ;
317320 }
318- return TRUE ;
321+ return FALSE ;
322+ }
323+
324+ BOOL CALLBACK ChooseTeamDlgProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
325+ {
326+ HWND okButton = GetDlgItem (hwnd, IDOK);
327+ HWND hwndList = GetDlgItem (hwnd, IDC_LIST_TEAM);
328+ switch (Message)
329+ {
330+ case WM_INITDIALOG:
331+ {
332+ std::vector<std::shared_ptr<Team>>* teams = (std::vector<std::shared_ptr<Team>>*)lParam;
333+ for (auto & team : *teams)
334+ {
335+ std::wstringstream item;
336+ auto name = team->name ();
337+ auto identifier = team->identifier ();
338+ switch (team->type ()) {
339+ case Team::Type::Organization:
340+ {
341+ item << " Organization: " ;
342+ break ;
343+ }
344+ case Team::Type::Free:
345+ {
346+ item << " Free: " ;
347+ break ;
348+ }
349+ case Team::Type::Individual:
350+ {
351+ item << " Individual: " ;
352+ break ;
353+ }
354+ default :
355+ {
356+ continue ;
357+ }
358+ }
359+ item << std::wstring (name.begin (), name.end ()) << " - " << std::wstring (identifier.begin (), identifier.end ());
360+
361+ int pos = (int )SendMessage (hwndList, LB_ADDSTRING, 0 , (LPARAM)item.str ().c_str ());
362+ // Set the array index of the player as item data.
363+ // This enables us to retrieve the item from the array
364+ // even after the items are sorted by the list box.
365+ SendMessage (hwndList, LB_SETITEMDATA, pos, (LPARAM)&team);
366+ }
367+ SetFocus (hwndList);
368+
369+ PostMessage (hwnd, WM_NEXTDLGCTL, (WPARAM)okButton, TRUE );
370+
371+ return TRUE ;
372+ }
373+
374+ case WM_COMMAND:
375+ {
376+ switch (LOWORD (wParam))
377+ {
378+ case IDC_LIST_TEAM:
379+ {
380+ switch (HIWORD (wParam))
381+ {
382+ case LBN_SELCHANGE:
383+ {
384+ Button_Enable (okButton, true );
385+ return TRUE ;
386+ }
387+ }
388+ return TRUE ;
389+ }
390+
391+ case IDOK:
392+ {
393+ int lbItem = (int )SendMessage (hwndList, LB_GETCURSEL, 0 , 0 );
394+ auto team = SendMessage (hwndList, LB_GETITEMDATA, lbItem, 0 );
395+ EndDialog (hwnd, team);
396+ return TRUE ;
397+ }
398+ case IDCANCEL:
399+ EndDialog (hwnd, IDCANCEL);
400+ return TRUE ;
401+ }
402+ }
403+
404+ default : break ;
405+ }
406+
407+ return FALSE ;
319408}
320409
321410VOID CALLBACK DetailedErrorMessageBoxCallback (LPHELPINFO lpHelpInfo)
@@ -999,25 +1088,14 @@ pplx::task<std::shared_ptr<Team>> AltServerApp::FetchTeam(std::shared_ptr<Accoun
9991088 auto task = AppleAPI::getInstance ()->FetchTeams (account, session)
10001089 .then ([](std::vector<std::shared_ptr<Team>> teams) {
10011090
1002- for (auto & team : teams)
1003- {
1004- if (team->type () == Team::Type::Individual)
1005- {
1006- return team;
1007- }
1008- }
1009-
1010- for (auto & team : teams)
1011- {
1012- if (team->type () == Team::Type::Free)
1013- {
1014- return team;
1015- }
1016- }
1017-
1018- for (auto & team : teams)
1019- {
1020- return team;
1091+ if (teams.size () == 1 && teams.front ()->type () != Team::Unknown) {
1092+ return teams.front ();
1093+ }
1094+ int result = DialogBoxParam (NULL , MAKEINTRESOURCE (IDD_CHOOSE_TEAM), 0 , ChooseTeamDlgProc, (LPARAM)&teams);
1095+ if (result != IDCANCEL)
1096+ {
1097+ auto team = (std::shared_ptr<Team>*)result;
1098+ return *team;
10211099 }
10221100
10231101 throw InstallError (InstallErrorCode::NoTeam);
0 commit comments