Skip to content

Commit a28005f

Browse files
committed
Add Team Selector dialog after login
Will not show when there is only a team.
1 parent 1abf7a3 commit a28005f

3 files changed

Lines changed: 102 additions & 22 deletions

File tree

AltServer/AltServerApp.cpp

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

321410
VOID 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);

AltServer/Resource.rc

1.26 KB
Binary file not shown.

AltServer/resource.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define IDD_FORMVIEW 101
99
#define ID_FOLDER 101
1010
#define IMG_MENUBAR 113
11+
#define IDD_CHOOSE_TEAM 114
1112
#define IDC_EDIT1 1001
1213
#define IDC_EDIT2 1002
1314
#define IDC_DESCRIPTION 1008
@@ -16,14 +17,15 @@
1617
#define IDCANCEL2 1009
1718
#define ID_ITUNES_MISSING_32 1010
1819
#define ID_ITUNES_MISSING_64 1011
20+
#define IDC_LIST_TEAM 1012
1921

2022
// Next default values for new objects
2123
//
2224
#ifdef APSTUDIO_INVOKED
2325
#ifndef APSTUDIO_READONLY_SYMBOLS
24-
#define _APS_NEXT_RESOURCE_VALUE 114
26+
#define _APS_NEXT_RESOURCE_VALUE 115
2527
#define _APS_NEXT_COMMAND_VALUE 40001
26-
#define _APS_NEXT_CONTROL_VALUE 1010
28+
#define _APS_NEXT_CONTROL_VALUE 1013
2729
#define _APS_NEXT_SYMED_VALUE 101
2830
#endif
2931
#endif

0 commit comments

Comments
 (0)