tools/installer/SelectGame.cpp
changeset 1723 befc8cfb4f3c
parent 1722 2c16f160f5dd
child 2289 44045ead61cd
     1.1 --- a/tools/installer/SelectGame.cpp	Sun Nov 25 04:46:18 2007 +0000
     1.2 +++ b/tools/installer/SelectGame.cpp	Sun Nov 25 18:03:59 2007 +0000
     1.3 @@ -7,25 +7,32 @@
     1.4  #include "LocalCopyMethod.h"
     1.5  
     1.6  int selected_game_index = -1;
     1.7 -mod_info_t **game_sel_list = NULL;
     1.8 -unsigned int game_sel_count = 0;
     1.9  
    1.10 -void AppendSelectableGame(mod_info_t *mod)
    1.11 +void UpdateGameListBox(HWND hDlg, game_list_t *gl)
    1.12  {
    1.13 -	if (game_sel_list == NULL)
    1.14 +	HWND lbox = GetDlgItem(hDlg, IDC_SELGAME_LIST);
    1.15 +
    1.16 +	SendMessage(lbox, LB_RESETCONTENT, 0, 0);
    1.17 +
    1.18 +	for (unsigned int i = 0; i < gl->game_count; i++)
    1.19  	{
    1.20 -		game_sel_list = 
    1.21 -			(mod_info_t **)malloc(sizeof(mod_info_t *) * (game_sel_count + 1));
    1.22 +		LRESULT res = SendMessage(lbox,
    1.23 +			LB_ADDSTRING,
    1.24 +			0,
    1.25 +			(LPARAM)g_games.game_list[gl->games[i]].name);
    1.26 +
    1.27 +		if (res == LB_ERR || res == LB_ERRSPACE)
    1.28 +		{
    1.29 +			continue;
    1.30 +		}
    1.31 +
    1.32 +		SendMessage(lbox, LB_SETITEMDATA, i, gl->games[i]);
    1.33  	}
    1.34 -	else
    1.35 -	{
    1.36 -		game_sel_list = 
    1.37 -			(mod_info_t **)realloc(game_sel_list, 
    1.38 -			sizeof(mod_info_t *) * (game_sel_count + 1));
    1.39 -	}
    1.40 +	
    1.41 +	UpdateWindow(lbox);
    1.42 +}
    1.43  
    1.44 -	game_sel_list[game_sel_count++] = mod;
    1.45 -}
    1.46 +#include "windowsx.h"
    1.47  
    1.48  INT_PTR CALLBACK ChooseGameHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    1.49  {
    1.50 @@ -33,24 +40,23 @@
    1.51  	{
    1.52  	case WM_INITDIALOG:
    1.53  		{
    1.54 -			HWND lbox = GetDlgItem(hDlg, IDC_SELGAME_LIST);
    1.55 -
    1.56 -			for (unsigned int i = 0; i < g_mod_count; i++)
    1.57 +			HWND cbox = GetDlgItem(hDlg, IDC_SELGROUP_ACCOUNT);
    1.58 +			SendMessage(cbox, CB_RESETCONTENT, 0, 0);
    1.59 +			for (unsigned int i = 0; i < g_game_group->list_count; i++)
    1.60  			{
    1.61 -				LRESULT res = SendMessage(lbox,
    1.62 -					LB_ADDSTRING,
    1.63 -					0,
    1.64 -					(LPARAM)g_mod_list[i].name);
    1.65 -
    1.66 -				if (res == LB_ERR || res == LB_ERRSPACE)
    1.67 +				LRESULT res = SendMessage(cbox, 
    1.68 +					CB_ADDSTRING, 
    1.69 +					0, 
    1.70 +					(LPARAM)g_game_group->lists[i]->root_name);
    1.71 +				if (res == CB_ERR || res == CB_ERRSPACE)
    1.72  				{
    1.73  					continue;
    1.74  				}
    1.75 -
    1.76 -				AppendSelectableGame(&g_mod_list[i]);
    1.77 +				SendMessage(cbox, CB_SETITEMDATA, i, (LPARAM)g_game_group->lists[i]);
    1.78  			}
    1.79 -
    1.80 -			UpdateWindow(lbox);
    1.81 +			SendMessage(cbox, CB_SETCURSEL, 0, 0);
    1.82 +			UpdateWindow(cbox);
    1.83 +			UpdateGameListBox(hDlg, g_game_group->lists[0]);
    1.84  
    1.85  			SetToGlobalPosition(hDlg);
    1.86  			
    1.87 @@ -69,6 +75,29 @@
    1.88  				EndDialog(hDlg, (INT_PTR)DisplayChooseMethod);
    1.89  				return (INT_PTR)TRUE;
    1.90  			}
    1.91 +			else if (LOWORD(wParam) == IDC_SELGROUP_ACCOUNT)
    1.92 +			{
    1.93 +				if (HIWORD(wParam) == CBN_SELCHANGE)
    1.94 +				{
    1.95 +					HWND cbox = (HWND)lParam;
    1.96 +					LRESULT cursel = SendMessage(cbox, CB_GETCURSEL, 0, 0);
    1.97 +
    1.98 +					if (cursel == LB_ERR)
    1.99 +					{
   1.100 +						break;
   1.101 +					}
   1.102 +
   1.103 +					LRESULT data = SendMessage(cbox, CB_GETITEMDATA, cursel, 0);
   1.104 +					if (data == CB_ERR)
   1.105 +					{
   1.106 +						break;
   1.107 +					}
   1.108 +
   1.109 +					game_list_t *gl = (game_list_t *)data;
   1.110 +					UpdateGameListBox(hDlg, gl);
   1.111 +				}
   1.112 +				break;
   1.113 +			}
   1.114  			else if (LOWORD(wParam) == IDC_SELGAME_LIST)
   1.115  			{
   1.116  				if (HIWORD(wParam) == LBN_SELCHANGE)
   1.117 @@ -83,12 +112,13 @@
   1.118  						break;
   1.119  					}
   1.120  
   1.121 -					if (cursel >= (LRESULT)g_mod_count)
   1.122 +					LRESULT item = SendMessage(lbox, LB_GETITEMDATA, cursel, 0);
   1.123 +					if (item == LB_ERR)
   1.124  					{
   1.125  						break;
   1.126  					}
   1.127  
   1.128 -					selected_game_index = (int)cursel;
   1.129 +					selected_game_index = (int)item;
   1.130  
   1.131  					HWND button = GetDlgItem(hDlg, ID_SELGAME_NEXT);
   1.132  					EnableWindow(button, TRUE);
   1.133 @@ -101,7 +131,7 @@
   1.134  					break;
   1.135  				}
   1.136  
   1.137 -				g_LocalCopier.SetOutputPath(game_sel_list[selected_game_index]->mod_path);
   1.138 +				g_LocalCopier.SetOutputPath(g_games.game_list[selected_game_index].game_path);
   1.139  				SetInstallMethod(&g_LocalCopier);
   1.140  
   1.141  				UpdateGlobalPosition(hDlg);
   1.142 @@ -113,10 +143,7 @@
   1.143  		}
   1.144  	case WM_DESTROY:
   1.145  		{
   1.146 -			ReleaseGamesList();
   1.147 -			free(game_sel_list);
   1.148 -			game_sel_list = NULL;
   1.149 -			game_sel_count = 0;
   1.150 +			ReleaseGameDB();
   1.151  			break;
   1.152  		}
   1.153  	}