tools/installer/PerformInstall.cpp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/tools/installer/PerformInstall.cpp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,244 +0,0 @@
     1.4 -#include "InstallerMain.h"
     1.5 -#include "InstallerUtil.h"
     1.6 -#include "PerformInstall.h"
     1.7 -
     1.8 -struct folder_t
     1.9 -{
    1.10 -	TCHAR path[MAX_PATH];
    1.11 -};
    1.12 -
    1.13 -ICopyMethod *g_pCopyMethod = NULL;
    1.14 -bool do_not_copy_binaries = false;
    1.15 -TCHAR source_path[MAX_PATH];
    1.16 -
    1.17 -void SetInstallMethod(ICopyMethod *pCopyMethod)
    1.18 -{
    1.19 -	g_pCopyMethod = pCopyMethod;
    1.20 -}
    1.21 -
    1.22 -bool CopyStructureRecursively(const TCHAR *basepath,
    1.23 -							  const TCHAR *local_path,
    1.24 -							  TCHAR *errbuf,
    1.25 -							  size_t maxchars)
    1.26 -{
    1.27 -	HANDLE hFind;
    1.28 -	WIN32_FIND_DATA fd;
    1.29 -	TCHAR search_path[MAX_PATH];
    1.30 -	folder_t *folder_list = NULL;
    1.31 -	unsigned int folder_count = 0;
    1.32 -
    1.33 -	if (local_path == NULL)
    1.34 -	{
    1.35 -		UTIL_PathFormat(search_path,
    1.36 -			sizeof(search_path) / sizeof(TCHAR),
    1.37 -			_T("%s\\*.*"),
    1.38 -			basepath);
    1.39 -	}
    1.40 -	else
    1.41 -	{
    1.42 -		UTIL_PathFormat(search_path,
    1.43 -			sizeof(search_path) / sizeof(TCHAR),
    1.44 -			_T("%s\\%s\\*.*"),
    1.45 -			basepath,
    1.46 -			local_path);
    1.47 -	}
    1.48 -
    1.49 -	if (!g_pCopyMethod->SetCurrentFolder(local_path, errbuf, maxchars))
    1.50 -	{
    1.51 -		/* :TODO: set fail state */
    1.52 -		return false;
    1.53 -	}
    1.54 -
    1.55 -	if ((hFind = FindFirstFile(search_path, &fd)) == INVALID_HANDLE_VALUE)
    1.56 -	{
    1.57 -		/* :TODO: set a fail state */
    1.58 -		return false;
    1.59 -	}
    1.60 -
    1.61 -	do
    1.62 -	{
    1.63 -		if (tstrcasecmp(fd.cFileName, _T(".")) == 0
    1.64 -			|| tstrcasecmp(fd.cFileName, _T("..")) == 0)
    1.65 -		{
    1.66 -			continue;
    1.67 -		}
    1.68 -
    1.69 -		if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
    1.70 -		{
    1.71 -			/* We cache the folder list so we don't have to keep changing folders back and forth, 
    1.72 -			 * which could be annoying on a slow copy connection.
    1.73 -			 */
    1.74 -			if (folder_list == NULL)
    1.75 -			{
    1.76 -				folder_list = (folder_t *)malloc(sizeof(folder_t) * (folder_count + 1));
    1.77 -			}
    1.78 -			else
    1.79 -			{
    1.80 -				folder_list = (folder_t *)realloc(folder_list, sizeof(folder_t) * (folder_count + 1));
    1.81 -			}
    1.82 -
    1.83 -			UTIL_Format(folder_list[folder_count].path, MAX_PATH, _T("%s"), fd.cFileName);
    1.84 -			folder_count++;
    1.85 -		}
    1.86 -		else
    1.87 -		{
    1.88 -			TCHAR file_path[MAX_PATH];
    1.89 -
    1.90 -			if (local_path == NULL)
    1.91 -			{
    1.92 -				UTIL_PathFormat(file_path,
    1.93 -					sizeof(file_path),
    1.94 -					_T("%s\\%s"),
    1.95 -					basepath,
    1.96 -					fd.cFileName);
    1.97 -			}
    1.98 -			else
    1.99 -			{
   1.100 -				UTIL_PathFormat(file_path,
   1.101 -					sizeof(file_path),
   1.102 -					_T("%s\\%s\\%s"),
   1.103 -					basepath,
   1.104 -					local_path,
   1.105 -					fd.cFileName);
   1.106 -			}
   1.107 -
   1.108 -			if (!g_pCopyMethod->SendFile(file_path, errbuf, maxchars))
   1.109 -			{
   1.110 -				FindClose(hFind);
   1.111 -				free(folder_list);
   1.112 -				return false;
   1.113 -			}
   1.114 -		}
   1.115 -	} while (FindNextFile(hFind, &fd));
   1.116 -
   1.117 -	FindClose(hFind);
   1.118 -
   1.119 -	/* Now copy folders */
   1.120 -	for (unsigned int i = 0; i < folder_count; i++)
   1.121 -	{
   1.122 -		/* Try creating the folder */
   1.123 -		if (!g_pCopyMethod->CreateFolder(folder_list[i].path, errbuf, maxchars))
   1.124 -		{
   1.125 -			free(folder_list);
   1.126 -			return false;
   1.127 -		}
   1.128 -
   1.129 -		TCHAR new_local_path[MAX_PATH];
   1.130 -		if (local_path == NULL)
   1.131 -		{
   1.132 -			UTIL_PathFormat(new_local_path,
   1.133 -				sizeof(new_local_path) / sizeof(TCHAR),
   1.134 -				_T("%s"),
   1.135 -				folder_list[i].path);
   1.136 -		}
   1.137 -		else
   1.138 -		{
   1.139 -			UTIL_PathFormat(new_local_path,
   1.140 -				sizeof(new_local_path) / sizeof(TCHAR),
   1.141 -				_T("%s\\%s"),
   1.142 -				local_path,
   1.143 -				folder_list[i].path);
   1.144 -		}
   1.145 -
   1.146 -		if (!CopyStructureRecursively(basepath, new_local_path, errbuf, maxchars))
   1.147 -		{
   1.148 -			free(folder_list);
   1.149 -			return false;
   1.150 -		}
   1.151 -	}
   1.152 -
   1.153 -	free(folder_list);
   1.154 -
   1.155 -	return true;
   1.156 -}
   1.157 -
   1.158 -bool StartInstallProcess(HWND hWnd)
   1.159 -{
   1.160 -	if (g_pCopyMethod->CheckForExistingInstall())
   1.161 -	{
   1.162 -		int val = MessageBox(
   1.163 -			hWnd, 
   1.164 -			_T("It looks like a previous SourceMod installation exists.  Do you want to upgrade?  Select \"Yes\" to upgrade and keep configuration files.  Select \"No\" to perform a full re-install."),
   1.165 -			_T("SourceMod Installer"), 
   1.166 -			MB_YESNO|MB_ICONQUESTION);
   1.167 -
   1.168 -		if (val == 0 || val == IDYES)
   1.169 -		{
   1.170 -			do_not_copy_binaries = true;
   1.171 -		}
   1.172 -		else
   1.173 -		{
   1.174 -			do_not_copy_binaries = false;
   1.175 -		}
   1.176 -	}
   1.177 -
   1.178 -	TCHAR cur_path[MAX_PATH];
   1.179 -	if (_tgetcwd(cur_path, sizeof(cur_path)) == NULL)
   1.180 -	{
   1.181 -		MessageBox(
   1.182 -			hWnd,
   1.183 -			_T("Could not locate current directory!"),
   1.184 -			_T("SourceMod Installer"),
   1.185 -			MB_OK|MB_ICONERROR);
   1.186 -		return false;
   1.187 -	}
   1.188 -
   1.189 -	UTIL_PathFormat(source_path,
   1.190 -		sizeof(source_path) / sizeof(TCHAR),
   1.191 -		_T("%s\\files"),
   1.192 -		cur_path);
   1.193 -
   1.194 -	if (GetFileAttributes(source_path) == INVALID_FILE_ATTRIBUTES)
   1.195 -	{
   1.196 -		MessageBox(
   1.197 -			hWnd,
   1.198 -			_T("Could not locate the source installation files!"),
   1.199 -			_T("SourceMod Installer"),
   1.200 -			MB_OK|MB_ICONERROR);
   1.201 -		return false;
   1.202 -	}
   1.203 -
   1.204 -
   1.205 -
   1.206 -	return true;
   1.207 -}
   1.208 -
   1.209 -INT_PTR CALLBACK PerformInstallHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
   1.210 -{
   1.211 -	switch (message)
   1.212 -	{
   1.213 -	case WM_INITDIALOG:
   1.214 -		{
   1.215 -			return (INT_PTR)TRUE;
   1.216 -		}
   1.217 -	case WM_COMMAND:
   1.218 -		{
   1.219 -			if (LOWORD(wParam) == ID_INSTALL_CANCEL
   1.220 -				|| LOWORD(wParam) == ID_CLOSE)
   1.221 -			{
   1.222 -				/* :TODO: enhance */
   1.223 -				EndDialog(hDlg, NULL);
   1.224 -				return (INT_PTR)TRUE;
   1.225 -			}
   1.226 -			break;
   1.227 -		}
   1.228 -	}
   1.229 -
   1.230 -	return (INT_PTR)FALSE;
   1.231 -}
   1.232 -
   1.233 -void *DisplayPerformInstall(HWND hWnd)
   1.234 -{
   1.235 -	INT_PTR val;
   1.236 -
   1.237 -	if ((val = DialogBox(
   1.238 -		g_hInstance, 
   1.239 -		MAKEINTRESOURCE(IDD_PERFORM_INSTALL),
   1.240 -		hWnd,
   1.241 -		PerformInstallHandler)) == -1)
   1.242 -	{
   1.243 -		return NULL;
   1.244 -	}
   1.245 -
   1.246 -	return (void *)val;
   1.247 -}