Changeset 538
- Timestamp:
- 11/13/2008 11:06:33 AM (5 years ago)
- Location:
- branches/eraser6/Installer/Bootstrapper
- Files:
-
- 3 edited
-
Bootstrapper.cpp (modified) (4 diffs)
-
Bootstrapper.h (modified) (1 diff)
-
Main.cpp (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Installer/Bootstrapper/Bootstrapper.cpp
r537 r538 82 82 s->FileRead += readSize; 83 83 84 SetProgress((float)((double)s->FileRead / s->FileSize)); 84 MainWindow& mainWin = Application::Get().GetTopWindow(); 85 mainWin.SetProgress((float)((double)s->FileRead / s->FileSize)); 85 86 } 86 87 … … 250 251 DWORD lastWait = 0; 251 252 while ((lastWait = WaitForSingleObject(pInfo.hProcess, 50)) == WAIT_TIMEOUT) 252 Yield();253 Application::Get().Yield(); 253 254 if (lastWait == WAIT_ABANDONED) 254 255 throw std::wstring(L"The condition waiting on the termination of the .NET installer was abandoned."); … … 270 271 { 271 272 //Update the UI 272 SetProgressIndeterminate(); 273 SetMessage(L"Installing .NET Framework..."); 273 MainWindow& mainWin = Application::Get().GetTopWindow(); 274 mainWin.SetProgressIndeterminate(); 275 mainWin.SetMessage(L"Installing .NET Framework..."); 274 276 275 277 //Get the path to the installer … … 285 287 bool InstallEraser(std::wstring tempDir) 286 288 { 287 SetProgressIndeterminate(); 288 SetMessage(L"Installing Eraser..."); 289 MainWindow& mainWin = Application::Get().GetTopWindow(); 290 mainWin.SetProgressIndeterminate(); 291 mainWin.SetMessage(L"Installing Eraser..."); 289 292 290 293 //Determine the system architecture. -
branches/eraser6/Installer/Bootstrapper/Bootstrapper.h
r536 r538 22 22 #pragma once 23 23 24 #include <windows.h> 24 25 #include <string> 25 26 26 27 #include "resource.h" 28 #undef Yield 29 30 class Application 31 { 32 public: 33 /// Gets the Singleton instance of the Application object. 34 static Application& Get(); 35 36 /// Processes messages in the message queue. 37 void Yield(); 38 39 /// Retrieves the MainWindow object representing the Application's top window. 40 class MainWindow& GetTopWindow(); 41 42 private: 43 Application(); 44 }; 45 46 class MainWindow 47 { 48 public: 49 /// Constructor. 50 MainWindow() 51 { 52 hWnd = hWndStatusLbl = hWndProgressBar = hWndCancelBtn = NULL; 53 } 54 55 /// Creates the Window. 56 bool Create(); 57 58 /// Sets the progress of the current operation. 59 /// 60 /// \param[in] progress The percentage of the operation complete. This is a real 61 /// number from 0 to 1. 62 void SetProgress(float progress); 63 64 /// Sets the progress bar to an indeterminate state. 65 void SetProgressIndeterminate(); 66 67 /// Sets the dialog label to display a short message. 68 void SetMessage(std::wstring message); 69 70 /// Gets the raw window handle. 71 HWND GetHandle() 72 { 73 return hWnd; 74 } 75 76 private: 77 HWND hWnd; 78 HWND hWndStatusLbl; 79 HWND hWndProgressBar; 80 HWND hWndCancelBtn; 81 82 private: 83 84 /// Registers the main window class and creates it. 85 bool InitInstance(); 86 }; 27 87 28 88 /// Formats the system error code using FormatMessage, returning the message as 29 89 /// a std::wstring. 30 90 std::wstring GetErrorMessage(DWORD lastError); 31 32 /// Processes existing messages, to prevent the application from being "unresponsive"33 #undef Yield34 void Yield();35 36 /// Retrieves the application's top level window.37 HWND GetTopWindow();38 39 void SetProgress(float progress);40 void SetProgressIndeterminate();41 void SetMessage(std::wstring message);42 91 43 92 /// Retrieves the path to the executable file. -
branches/eraser6/Installer/Bootstrapper/Main.cpp
r537 r538 37 37 //Static variables 38 38 HINSTANCE hInstance = NULL; 39 HWND hWndParent = NULL; 40 HWND hWndStatusLbl = NULL; 41 HWND hWndProgressBar = NULL; 42 HWND hWndCancelBtn = NULL; 39 MainWindow MainWin; 43 40 44 41 bool InitInstance(HINSTANCE hInstance, HWND& hWnd); … … 87 84 }; 88 85 89 /// Registers the main window class and creates it. 90 bool InitInstance(HINSTANCE hInstance, HWND& hWnd) 91 { 92 WNDCLASSEX wcex; 93 ::ZeroMemory(&wcex, sizeof(wcex)); 94 95 wcex.cbSize = sizeof(WNDCLASSEX); 96 wcex.style = CS_HREDRAW | CS_VREDRAW; 97 wcex.lpfnWndProc = WndProc; 98 wcex.cbClsExtra = 0; 99 wcex.cbWndExtra = 0; 100 wcex.hInstance = hInstance; 101 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 102 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 103 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 104 wcex.lpszClassName = szWindowClass; 105 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 106 RegisterClassExW(&wcex); 107 InitCommonControls(); 108 109 //Create the window 110 hWnd = CreateWindowW(szWindowClass, L"Eraser Setup", WS_CAPTION | WS_SYSMENU, 111 CW_USEDEFAULT, 0, 300, 130, NULL, NULL, hInstance, NULL); 112 113 if (!hWnd) 114 return false; 115 116 //Set default settings (font) 117 SetWindowFont(hWnd); 118 return true; 119 } 86 87 120 88 121 89 /// Helper function to set the window font for created windows to the system default. … … 186 154 //Create the parent window and the child controls 187 155 ::hInstance = hInstance; 188 if (!InitInstance(hInstance, hWndParent)) 156 MainWin.Create(); 157 158 try 159 { 160 //OK, now we do the hard work. Create a folder to place our payload into 161 wchar_t tempPath[MAX_PATH]; 162 DWORD result = GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath); 163 if (!result) 164 throw GetErrorMessage(GetLastError()); 165 166 std::wstring tempDir(tempPath, result); 167 if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 168 tempDir += L"\\"; 169 tempDir += L"eraserInstallBootstrapper\\"; 170 TempDir dir(tempDir); 171 ExtractTempFiles(tempDir); 172 173 //Install the .NET framework 174 if (!HasNetFramework()) 175 InstallNetFramework(tempDir); 176 177 //Then install Eraser! 178 InstallEraser(tempDir); 179 } 180 catch (const std::wstring& e) 181 { 182 MessageBoxW(Application::Get().GetTopWindow().GetHandle(), e.c_str(), 183 L"Eraser Setup", MB_OK | MB_ICONERROR); 184 } 185 186 return 0; 187 } 188 189 bool MainWindow::Create() 190 { 191 if (!InitInstance()) 189 192 return false; 190 193 191 194 HWND hWndPanel = CreateWindowExW(0, STATIC_CLASS, NULL, WS_CHILD | WS_VISIBLE, 192 0, 0, 294, 104, hWnd Parent, NULL, hInstance, NULL);195 0, 0, 294, 104, hWnd, NULL, hInstance, NULL); 193 196 hWndStatusLbl = CreateWindowExW(0, STATIC_CLASS, L"Extracting setup files...", 194 197 WS_CHILD | WS_VISIBLE, 13, 38, 270, 19, hWndPanel, NULL, hInstance, NULL); … … 208 211 SendMessage(hWndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000)); 209 212 210 ShowWindow(hWndParent, nCmdShow); 211 UpdateWindow(hWndParent); 212 213 try 214 { 215 //OK, now we do the hard work. Create a folder to place our payload into 216 wchar_t tempPath[MAX_PATH]; 217 DWORD result = GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath); 218 if (!result) 219 throw GetErrorMessage(GetLastError()); 220 221 std::wstring tempDir(tempPath, result); 222 if (std::wstring(L"\\/").find(tempDir[tempDir.length() - 1]) == std::wstring::npos) 223 tempDir += L"\\"; 224 tempDir += L"eraserInstallBootstrapper\\"; 225 TempDir dir(tempDir); 226 ExtractTempFiles(tempDir); 227 228 //Install the .NET framework 229 if (!HasNetFramework()) 230 InstallNetFramework(tempDir); 231 232 //Then install Eraser! 233 InstallEraser(tempDir); 234 } 235 catch (const std::wstring& e) 236 { 237 MessageBoxW(GetTopWindow(), e.c_str(), L"Eraser Setup", MB_OK | MB_ICONERROR); 238 } 239 240 return 0; 241 } 242 243 HWND GetTopWindow() 244 { 245 return hWndParent; 246 } 247 248 void SetProgress(float progress) 213 ShowWindow(hWnd, nCmdShow); 214 UpdateWindow(hWnd); 215 } 216 217 bool MainWindow::InitInstance() 218 { 219 WNDCLASSEX wcex; 220 ::ZeroMemory(&wcex, sizeof(wcex)); 221 222 wcex.cbSize = sizeof(WNDCLASSEX); 223 wcex.style = CS_HREDRAW | CS_VREDRAW; 224 wcex.lpfnWndProc = WndProc; 225 wcex.cbClsExtra = 0; 226 wcex.cbWndExtra = 0; 227 wcex.hInstance = hInstance; 228 wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 229 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 230 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 231 wcex.lpszClassName = szWindowClass; 232 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(BOOTSTRAPPER_ICON)); 233 RegisterClassExW(&wcex); 234 InitCommonControls(); 235 236 //Create the window 237 hWnd = CreateWindowW(szWindowClass, L"Eraser Setup", WS_CAPTION | WS_SYSMENU, 238 CW_USEDEFAULT, 0, 300, 130, NULL, NULL, hInstance, NULL); 239 240 if (!hWnd) 241 return false; 242 243 //Set default settings (font) 244 SetWindowFont(hWnd); 245 return true; 246 } 247 248 void MainWindow::SetProgress(float progress) 249 249 { 250 250 SetWindowLong(hWndProgressBar, GWL_STYLE, … … 253 253 } 254 254 255 void SetProgressIndeterminate()255 void MainWindow::SetProgressIndeterminate() 256 256 { 257 257 SetWindowLong(hWndProgressBar, GWL_STYLE, … … 260 260 } 261 261 262 void SetMessage(std::wstring message)263 { 264 } 265 266 void Yield()262 void MainWindow::SetMessage(std::wstring message) 263 { 264 } 265 266 void Application::Yield() 267 267 { 268 268 MSG msg;
Note: See TracChangeset
for help on using the changeset viewer.
