1.1 --- a/tools/installer/LocalCopyMethod.cpp Fri Oct 02 02:35:25 2009 -0700
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,167 +0,0 @@
1.4 -#include "InstallerUtil.h"
1.5 -#include "LocalCopyMethod.h"
1.6 -
1.7 -LocalCopyMethod g_LocalCopier;
1.8 -
1.9 -DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize,
1.10 - LARGE_INTEGER TotalBytesTransferred,
1.11 - LARGE_INTEGER StreamSize,
1.12 - LARGE_INTEGER StreamBytesTransferred,
1.13 - DWORD dwStreamNumber,
1.14 - DWORD dwCallbackReason,
1.15 - HANDLE hSourceFile,
1.16 - HANDLE hDestinationFile,
1.17 - LPVOID lpData)
1.18 -{
1.19 - ICopyProgress *progress = (ICopyProgress *)lpData;
1.20 -
1.21 - progress->UpdateProgress((size_t)TotalBytesTransferred.QuadPart,
1.22 - (size_t)TotalFileSize.QuadPart);
1.23 -
1.24 - return PROGRESS_CONTINUE;
1.25 -}
1.26 -
1.27 -LocalCopyMethod::LocalCopyMethod()
1.28 -{
1.29 - m_pProgress = NULL;
1.30 -}
1.31 -
1.32 -void LocalCopyMethod::SetOutputPath(const TCHAR *path)
1.33 -{
1.34 - UTIL_PathFormat(m_OutputPath,
1.35 - sizeof(m_OutputPath) / sizeof(TCHAR),
1.36 - _T("%s"),
1.37 - path);
1.38 -
1.39 - UTIL_PathFormat(m_CurrentPath,
1.40 - sizeof(m_CurrentPath) / sizeof(TCHAR),
1.41 - _T("%s"),
1.42 - path);
1.43 -}
1.44 -
1.45 -void LocalCopyMethod::TrackProgress(ICopyProgress *pProgress)
1.46 -{
1.47 - m_pProgress = pProgress;
1.48 -}
1.49 -
1.50 -bool LocalCopyMethod::CreateFolder(const TCHAR *name, TCHAR *buffer, size_t maxchars)
1.51 -{
1.52 - TCHAR path[MAX_PATH];
1.53 -
1.54 - UTIL_PathFormat(path,
1.55 - sizeof(path) / sizeof(TCHAR),
1.56 - _T("%s\\%s"),
1.57 - m_CurrentPath,
1.58 - name);
1.59 -
1.60 - if (CreateDirectory(path, NULL))
1.61 - {
1.62 - return true;
1.63 - }
1.64 -
1.65 - DWORD error = GetLastError();
1.66 - if (error == ERROR_ALREADY_EXISTS)
1.67 - {
1.68 - return true;
1.69 - }
1.70 -
1.71 - GenerateErrorMessage(error, buffer, maxchars);
1.72 -
1.73 - return false;
1.74 -}
1.75 -
1.76 -bool LocalCopyMethod::SetCurrentFolder(const TCHAR *path, TCHAR *buffer, size_t maxchars)
1.77 -{
1.78 - if (path == NULL)
1.79 - {
1.80 - UTIL_PathFormat(m_CurrentPath,
1.81 - sizeof(m_CurrentPath) / sizeof(TCHAR),
1.82 - _T("%s"),
1.83 - m_OutputPath);
1.84 - }
1.85 - else
1.86 - {
1.87 - UTIL_PathFormat(m_CurrentPath,
1.88 - sizeof(m_CurrentPath) / sizeof(TCHAR),
1.89 - _T("%s\\%s"),
1.90 - m_OutputPath,
1.91 - path);
1.92 - }
1.93 -
1.94 - return true;
1.95 -}
1.96 -
1.97 -bool LocalCopyMethod::SendFile(const TCHAR *path, TCHAR *buffer, size_t maxchars)
1.98 -{
1.99 - const TCHAR *filename = GetFileFromPath(path);
1.100 -
1.101 - if (filename == NULL)
1.102 - {
1.103 - UTIL_Format(buffer, maxchars, _T("Invalid filename"));
1.104 - return false;
1.105 - }
1.106 -
1.107 - TCHAR new_path[MAX_PATH];
1.108 - UTIL_PathFormat(new_path,
1.109 - sizeof(new_path) / sizeof(TCHAR),
1.110 - _T("%s\\%s"),
1.111 - m_CurrentPath,
1.112 - filename);
1.113 -
1.114 - m_bCancelStatus = FALSE;
1.115 -
1.116 - if (m_pProgress != NULL)
1.117 - {
1.118 - m_pProgress->StartingNewFile(filename);
1.119 - }
1.120 -
1.121 - if (CopyFileEx(path,
1.122 - new_path,
1.123 - m_pProgress ? CopyProgressRoutine : NULL,
1.124 - m_pProgress,
1.125 - &m_bCancelStatus,
1.126 - 0) == 0)
1.127 - {
1.128 - /* Delete the file in case it was a partial copy */
1.129 - DeleteFile(new_path);
1.130 -
1.131 - GenerateErrorMessage(GetLastError(), buffer, maxchars);
1.132 -
1.133 - return false;
1.134 - }
1.135 -
1.136 - if (m_pProgress != NULL)
1.137 - {
1.138 - m_pProgress->FileDone(UTIL_GetFileSize(path));
1.139 - }
1.140 -
1.141 - return true;
1.142 -}
1.143 -
1.144 -void LocalCopyMethod::CancelCurrentCopy()
1.145 -{
1.146 - m_bCancelStatus = TRUE;
1.147 -}
1.148 -
1.149 -bool LocalCopyMethod::CheckForExistingInstall()
1.150 -{
1.151 - TCHAR path[MAX_PATH];
1.152 -
1.153 - UTIL_PathFormat(path,
1.154 - sizeof(path) / sizeof(TCHAR),
1.155 - _T("%s\\addons\\sourcemod"),
1.156 - m_CurrentPath);
1.157 - if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES)
1.158 - {
1.159 - UTIL_PathFormat(path,
1.160 - sizeof(path) / sizeof(TCHAR),
1.161 - _T("%s\\cfg\\sourcemod"),
1.162 - m_CurrentPath);
1.163 - if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES)
1.164 - {
1.165 - return false;
1.166 - }
1.167 - }
1.168 -
1.169 - return true;
1.170 -}