tools/installer/SelectGame.cpp
author Scott Ehlert <ds@alliedmods.net>
Sun Sep 14 03:01:05 2008 -0500 (2008-09-14)
changeset 2289 44045ead61cd
parent 1952 b7aa2b626807
parent 1723 befc8cfb4f3c
permissions -rw-r--r--
Eliminated head: da55a80522cf, a remnant of sourcemod-1.1.0 branch
     1 #include "InstallerMain.h"
     2 #include "InstallerUtil.h"
     3 #include "SelectGame.h"
     4 #include "GamesList.h"
     5 #include "ChooseMethod.h"
     6 #include "PerformInstall.h"
     7 #include "LocalCopyMethod.h"
     8 
     9 int selected_game_index = -1;
    10 
    11 void UpdateGameListBox(HWND hDlg, game_list_t *gl)
    12 {
    13 	HWND lbox = GetDlgItem(hDlg, IDC_SELGAME_LIST);
    14 
    15 	SendMessage(lbox, LB_RESETCONTENT, 0, 0);
    16 
    17 	for (unsigned int i = 0; i < gl->game_count; i++)
    18 	{
    19 		LRESULT res = SendMessage(lbox,
    20 			LB_ADDSTRING,
    21 			0,
    22 			(LPARAM)g_games.game_list[gl->games[i]].name);
    23 
    24 		if (res == LB_ERR || res == LB_ERRSPACE)
    25 		{
    26 			continue;
    27 		}
    28 
    29 		SendMessage(lbox, LB_SETITEMDATA, i, gl->games[i]);
    30 	}
    31 	
    32 	UpdateWindow(lbox);
    33 }
    34 
    35 #include "windowsx.h"
    36 
    37 INT_PTR CALLBACK ChooseGameHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    38 {
    39 	switch (message)
    40 	{
    41 	case WM_INITDIALOG:
    42 		{
    43 			HWND cbox = GetDlgItem(hDlg, IDC_SELGROUP_ACCOUNT);
    44 			SendMessage(cbox, CB_RESETCONTENT, 0, 0);
    45 			for (unsigned int i = 0; i < g_game_group->list_count; i++)
    46 			{
    47 				LRESULT res = SendMessage(cbox, 
    48 					CB_ADDSTRING, 
    49 					0, 
    50 					(LPARAM)g_game_group->lists[i]->root_name);
    51 				if (res == CB_ERR || res == CB_ERRSPACE)
    52 				{
    53 					continue;
    54 				}
    55 				SendMessage(cbox, CB_SETITEMDATA, i, (LPARAM)g_game_group->lists[i]);
    56 			}
    57 			SendMessage(cbox, CB_SETCURSEL, 0, 0);
    58 			UpdateWindow(cbox);
    59 			UpdateGameListBox(hDlg, g_game_group->lists[0]);
    60 
    61 			SetToGlobalPosition(hDlg);
    62 			
    63 			return (INT_PTR)TRUE;
    64 		}
    65 	case WM_COMMAND:
    66 		{
    67 			if (LOWORD(wParam) == ID_SELGAME_EXIT
    68 				|| LOWORD(wParam) == ID_CLOSE)
    69 			{
    70 				return AskToExit(hDlg);
    71 			}
    72 			else if (LOWORD(wParam) == ID_SELGAME_BACK)
    73 			{
    74 				UpdateGlobalPosition(hDlg);
    75 				EndDialog(hDlg, (INT_PTR)DisplayChooseMethod);
    76 				return (INT_PTR)TRUE;
    77 			}
    78 			else if (LOWORD(wParam) == IDC_SELGROUP_ACCOUNT)
    79 			{
    80 				if (HIWORD(wParam) == CBN_SELCHANGE)
    81 				{
    82 					HWND cbox = (HWND)lParam;
    83 					LRESULT cursel = SendMessage(cbox, CB_GETCURSEL, 0, 0);
    84 
    85 					if (cursel == LB_ERR)
    86 					{
    87 						break;
    88 					}
    89 
    90 					LRESULT data = SendMessage(cbox, CB_GETITEMDATA, cursel, 0);
    91 					if (data == CB_ERR)
    92 					{
    93 						break;
    94 					}
    95 
    96 					game_list_t *gl = (game_list_t *)data;
    97 					UpdateGameListBox(hDlg, gl);
    98 				}
    99 				break;
   100 			}
   101 			else if (LOWORD(wParam) == IDC_SELGAME_LIST)
   102 			{
   103 				if (HIWORD(wParam) == LBN_SELCHANGE)
   104 				{
   105 					HWND lbox = (HWND)lParam;
   106 					LRESULT cursel = SendMessage(lbox, LB_GETCURSEL, 0, 0);
   107 
   108 					selected_game_index = -1;
   109 
   110 					if (cursel == LB_ERR)
   111 					{
   112 						break;
   113 					}
   114 
   115 					LRESULT item = SendMessage(lbox, LB_GETITEMDATA, cursel, 0);
   116 					if (item == LB_ERR)
   117 					{
   118 						break;
   119 					}
   120 
   121 					selected_game_index = (int)item;
   122 
   123 					HWND button = GetDlgItem(hDlg, ID_SELGAME_NEXT);
   124 					EnableWindow(button, TRUE);
   125 				}
   126 			}
   127 			else if (LOWORD(wParam) == ID_SELGAME_NEXT)
   128 			{
   129 				if (selected_game_index == -1)
   130 				{
   131 					break;
   132 				}
   133 
   134 				g_LocalCopier.SetOutputPath(g_games.game_list[selected_game_index].game_path);
   135 				SetInstallMethod(&g_LocalCopier);
   136 
   137 				UpdateGlobalPosition(hDlg);
   138 				EndDialog(hDlg, (INT_PTR)DisplayPerformInstall);
   139 
   140 				return (INT_PTR)TRUE;
   141 			}
   142 			break;
   143 		}
   144 	case WM_DESTROY:
   145 		{
   146 			ReleaseGameDB();
   147 			break;
   148 		}
   149 	}
   150 
   151 	return (INT_PTR)FALSE;
   152 }
   153 
   154 void *DisplaySelectGame(HWND hWnd)
   155 {
   156 	INT_PTR val;
   157 	
   158 	if ((val = DialogBox(
   159 		g_hInstance, 
   160 		MAKEINTRESOURCE(IDD_SELECT_GAME),
   161 		hWnd,
   162 		ChooseGameHandler)) == -1)
   163 	{
   164 		return NULL;
   165 	}
   166 
   167 	return (void *)val;
   168 }
   169