Changeset 539


Ignore:
Timestamp:
11/13/2008 11:26:52 AM (6 years ago)
Author:
lowjoel
Message:

Further extend the Application class.

Location:
branches/eraser6/Installer/Bootstrapper
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.cpp

    r538 r539  
    110110    //Open the file 
    111111#if _DEBUG 
    112     HANDLE srcFile = CreateFileW((GetApplicationPath() + L".7z").c_str(), GENERIC_READ, FILE_SHARE_READ, 
    113         NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL , NULL); 
     112    HANDLE srcFile = CreateFileW((Application::Get().GetPath() + L".7z").c_str(), 
     113        GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    114114    if (srcFile == INVALID_HANDLE_VALUE) 
    115115        throw GetErrorMessage(GetLastError()); 
     
    119119    fPos.QuadPart = 0; 
    120120#else 
    121     HANDLE srcFile = CreateFileW(GetApplicationPath().c_str(), GENERIC_READ, FILE_SHARE_READ, 
    122         NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL , NULL); 
     121    HANDLE srcFile = CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
     122        FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    123123    if (srcFile == INVALID_HANDLE_VALUE) 
    124124        throw GetErrorMessage(GetLastError()); 
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.h

    r538 r539  
    2727#include "resource.h" 
    2828#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 }; 
    4529 
    4630class MainWindow 
     
    8670}; 
    8771 
     72class Application 
     73{ 
     74public: 
     75    /// Gets the Singleton instance of the Application object. 
     76    static Application& Get(); 
     77 
     78    /// Retrieves the path to the executable file. 
     79    std::wstring GetPath(); 
     80 
     81    /// Processes messages in the message queue. 
     82    void Yield(); 
     83 
     84    /// Retrieves the MainWindow object representing the Application's top window. 
     85    MainWindow& GetTopWindow(); 
     86 
     87private: 
     88    /// Constructor. 
     89    Application(); 
     90 
     91private: 
     92    /// The Application main window. 
     93    MainWindow MainWin; 
     94}; 
     95 
    8896/// Formats the system error code using FormatMessage, returning the message as 
    8997/// a std::wstring. 
    9098std::wstring GetErrorMessage(DWORD lastError); 
    91  
    92 /// Retrieves the path to the executable file. 
    93 std::wstring GetApplicationPath(); 
    9499 
    95100/// Extracts the setup files to the users' temporary folder. 
  • branches/eraser6/Installer/Bootstrapper/Main.cpp

    r538 r539  
    3737    //Static variables 
    3838    HINSTANCE hInstance = NULL; 
    39     MainWindow MainWin; 
    4039 
    4140    bool              InitInstance(HINSTANCE hInstance, HWND& hWnd); 
     
    150149 
    151150int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, 
    152                        LPTSTR /*lpCmdLine*/, int nCmdShow) 
     151                       LPTSTR /*lpCmdLine*/, int /*nCmdShow*/) 
    153152{ 
    154153    //Create the parent window and the child controls 
    155154    ::hInstance = hInstance; 
    156     MainWin.Create(); 
     155    Application::Get(); 
    157156 
    158157    try 
     
    185184 
    186185    return 0; 
     186} 
     187 
     188Application::Application() 
     189{ 
     190    MainWin.Create(); 
     191} 
     192 
     193Application& Application::Get() 
     194{ 
     195    static Application Instance; 
     196    return Instance; 
     197} 
     198 
     199MainWindow& Application::GetTopWindow() 
     200{ 
     201    return MainWin; 
     202} 
     203 
     204void Application::Yield() 
     205{ 
     206    MSG msg; 
     207    while (PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT) 
     208    { 
     209        if (GetMessageW(&msg, NULL, 0, 0) == 0) 
     210            return; 
     211 
     212        TranslateMessage(&msg); 
     213        DispatchMessage(&msg); 
     214    } 
     215} 
     216 
     217std::wstring Application::GetPath() 
     218{ 
     219    wchar_t filePath[MAX_PATH]; 
     220    DWORD result = GetModuleFileNameW(hInstance, filePath, 
     221        sizeof(filePath) / sizeof(filePath[0])); 
     222 
     223    if (result == 0) 
     224        throw GetErrorMessage(GetLastError()); 
     225    return std::wstring(filePath, result); 
    187226} 
    188227 
     
    211250    SendMessage(hWndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000)); 
    212251 
    213     ShowWindow(hWnd, nCmdShow); 
     252    ShowWindow(hWnd, SW_SHOWDEFAULT); 
    214253    UpdateWindow(hWnd); 
     254    return true; 
    215255} 
    216256 
     
    264304} 
    265305 
    266 void Application::Yield() 
    267 { 
    268     MSG msg; 
    269     while (PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT) 
    270     { 
    271         if (GetMessageW(&msg, NULL, 0, 0) == 0) 
    272             return; 
    273  
    274         TranslateMessage(&msg); 
    275         DispatchMessage(&msg); 
    276     } 
    277 } 
    278  
    279 std::wstring GetApplicationPath() 
    280 { 
    281     wchar_t filePath[MAX_PATH]; 
    282     DWORD result = GetModuleFileNameW(hInstance, filePath, 
    283         sizeof(filePath) / sizeof(filePath[0])); 
    284  
    285     if (result == 0) 
    286         throw GetErrorMessage(GetLastError()); 
    287     return std::wstring(filePath, result); 
    288 } 
    289  
    290306std::wstring GetErrorMessage(DWORD lastError) 
    291307{ 
Note: See TracChangeset for help on using the changeset viewer.