Changeset 542


Ignore:
Timestamp:
11/13/2008 12:20:40 PM (3 years ago)
Author:
lowjoel
Message:

Handle the Cancel button clicks.

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

Legend:

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

    r539 r542  
    114114    if (srcFile == INVALID_HANDLE_VALUE) 
    115115        throw GetErrorMessage(GetLastError()); 
    116  
    117     //Seek to the 128th kb. 
    118     LARGE_INTEGER fPos; 
    119     fPos.QuadPart = 0; 
    120116#else 
    121117    HANDLE srcFile = CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
     
    126122    //Seek to the 128th kb. 
    127123    LARGE_INTEGER fPos; 
    128     fPos.QuadPart = 128 * 1024; 
     124    fPos.QuadPart = DataOffset; 
     125 
     126    if (!SetFilePointerEx(srcFile, fPos, &fPos, FILE_BEGIN)) 
     127        throw GetErrorMessage(GetLastError()); 
    129128#endif 
    130  
    131     if (!SetFilePointerEx(srcFile, fPos, &fPos, FILE_BEGIN)) 
    132         throw GetErrorMessage(GetLastError()); 
    133129 
    134130    //7z archive database structure 
     
    183179                throw GetErrorMessage(GetLastError()); 
    184180            destFileSize -= bytesWritten; 
     181            Application::Get().Yield(); 
    185182        } 
    186183 
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.h

    r541 r542  
    2424#include <windows.h> 
    2525#include <string> 
     26#include <map> 
    2627 
    2728#include "resource.h" 
    2829#undef Yield 
     30#undef min 
    2931 
    3032class MainWindow 
     
    6062private: 
    6163    HWND hWnd; 
     64    HWND hWndPanel; 
    6265    HWND hWndStatusLbl; 
    6366    HWND hWndProgressBar; 
    6467    HWND hWndCancelBtn; 
     68 
     69    struct WndProcData 
     70    { 
     71        WndProcData(WNDPROC oldWndProc, MainWindow& owner) 
     72            : OldWndProc(oldWndProc), Owner(&owner) 
     73        { 
     74        } 
     75 
     76        WNDPROC OldWndProc; 
     77        MainWindow* Owner; 
     78    }; 
     79 
     80    static std::map<HWND, WndProcData> OldWndProcs; 
    6581 
    6682private: 
     
    6985 
    7086    /// Helper function to set the window font for created windows to the system default. 
     87    ///  
     88    /// \param[in] hWnd The window whose font needs to be set. 
    7189    void SetWindowFont(HWND hWnd); 
     90 
     91    /// Handles messages from user interactions. 
     92    LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, 
     93        bool& handled); 
     94 
     95    /// Subclasses the given window. 
     96    ///  
     97    /// \param[in] owner The owner of the window. 
     98    /// \param[in] hWnd The handle to the window to subclass. 
     99    /// \param[in] wndProc The window message processor. 
     100    static void SubclassWindow(MainWindow& owner, HWND hWnd, WNDPROC wndProc); 
     101 
     102    /// Processes messages for the main window. 
     103    static LRESULT __stdcall WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 
    72104}; 
    73105 
     
    96128}; 
    97129 
     130/// The offset where the package data is stored. 
     131const unsigned DataOffset = 160 * 1024; 
     132 
    98133/// Formats the system error code using FormatMessage, returning the message as 
    99134/// a std::wstring. 
  • branches/eraser6/Installer/Bootstrapper/Bootstrapper.vcproj

    r532 r542  
    6161            <Tool 
    6262                Name="VCLinkerTool" 
    63                 AdditionalDependencies="comctl32.lib 7z_C.lib" 
     63                AdditionalDependencies="comctl32.lib 7z_Cd.lib" 
    6464                LinkIncremental="2" 
    6565                GenerateDebugInformation="true" 
     
    134134            <Tool 
    135135                Name="VCLinkerTool" 
    136                 AdditionalDependencies="comctl32.lib D:\Development\Libraries\C++\LZMA\C\Archive\7z\LzDecode.obj" 
     136                AdditionalDependencies="comctl32.lib 7z_C.lib" 
    137137                LinkIncremental="1" 
    138138                GenerateDebugInformation="true" 
  • branches/eraser6/Installer/Bootstrapper/Main.cpp

    r541 r542  
    5050            : DirName(dirName) 
    5151        { 
     52            //Ensure there is a trailing slash 
    5253            if (std::wstring(L"\\/").find(dirName[dirName.length() - 1]) == std::wstring::npos) 
    5354                dirName += L"\\"; 
    5455 
    5556            if (!CreateDirectoryW(dirName.c_str(), NULL)) 
    56                 throw GetErrorMessage(GetLastError()); 
     57                switch (GetLastError()) 
     58                { 
     59                case ERROR_ALREADY_EXISTS: 
     60                    DeleteContents(); 
     61                    break; 
     62 
     63                default: 
     64                    throw GetErrorMessage(GetLastError()); 
     65                } 
    5766        } 
    5867 
    5968        ~TempDir() 
     69        { 
     70            DeleteContents(); 
     71            RemoveDirectoryW(DirName.c_str()); 
     72        } 
     73 
     74    private: 
     75        /// The path to the directory. 
     76        std::wstring DirName; 
     77 
     78    private: 
     79        void DeleteContents() 
    6080        { 
    6181            //Clean up the files in the directory. 
     
    7393            //Clean up. 
    7494            FindClose(findHandle); 
    75             RemoveDirectoryW(DirName.c_str()); 
    7695        } 
    77  
    78     private: 
    79         std::wstring DirName; 
    8096    }; 
    81  
    82     /// Processes messages for the main window. 
    83     ///  
    84     /// Current messages processed: 
    85     /// WM_COMMAND  - process the application menu 
    86     /// WM_PAINT    - Paint the main window 
    87     /// WM_DESTROY  - post a quit message and return 
    88     LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
    89     { 
    90         switch (message) 
    91         { 
    92         case WM_COMMAND: 
    93         { 
    94             /*int wmId    = LOWORD(wParam); 
    95             switch (wmId) 
    96             { 
    97             default: 
    98                  
    99             }*/ 
    100             return DefWindowProc(hWnd, message, wParam, lParam); 
    101         } 
    102  
    103         case WM_DESTROY: 
    104             PostQuitMessage(0); 
    105             break; 
    106  
    107         default: 
    108             return DefWindowProc(hWnd, message, wParam, lParam); 
    109         } 
    110  
    111         return 0; 
    112     } 
    11397} 
    11498 
     
    191175} 
    192176 
     177std::map<HWND, MainWindow::WndProcData> MainWindow::OldWndProcs; 
    193178bool MainWindow::Create() 
    194179{ 
     
    196181        return false; 
    197182 
    198     HWND hWndPanel = CreateWindowExW(0, STATIC_CLASS, NULL, WS_CHILD | WS_VISIBLE, 
     183    hWndPanel = CreateWindowExW(0, STATIC_CLASS, NULL, WS_CHILD | WS_VISIBLE, 
    199184        0, 0, 294, 104, hWnd, NULL, hInstance, NULL); 
    200185    hWndStatusLbl = CreateWindowExW(0, STATIC_CLASS, L"Extracting setup files...", 
     
    213198    SetWindowFont(hWndProgressBar); 
    214199    SetWindowFont(hWndCancelBtn); 
     200 
    215201    SendMessage(hWndProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000)); 
     202    SubclassWindow(*this, hWndCancelBtn, WndProc); 
     203    SubclassWindow(*this, hWndPanel, WndProc); 
    216204 
    217205    ShowWindow(hWnd, SW_SHOWDEFAULT); 
     
    281269void MainWindow::SetProgress(float progress) 
    282270{ 
    283     SetWindowLong(hWndProgressBar, GWL_STYLE, 
    284         GetWindowLong(hWndProgressBar, GWL_STYLE) & (~PBS_MARQUEE)); 
     271    SetWindowLongPtr(hWndProgressBar, GWL_STYLE, 
     272        GetWindowLongPtr(hWndProgressBar, GWL_STYLE) & (~PBS_MARQUEE)); 
    285273    SendMessage(hWndProgressBar, PBM_SETPOS, (int)(progress * 1000), 0); 
    286274} 
     
    288276void MainWindow::SetProgressIndeterminate() 
    289277{ 
    290     SetWindowLong(hWndProgressBar, GWL_STYLE, 
    291         GetWindowLong(hWndProgressBar, GWL_STYLE) | PBS_MARQUEE); 
     278    SetWindowLongPtr(hWndProgressBar, GWL_STYLE, 
     279        GetWindowLongPtr(hWndProgressBar, GWL_STYLE) | PBS_MARQUEE); 
    292280    SendMessage(hWndProgressBar, PBM_SETMARQUEE, true, 100); 
    293281} 
     
    296284{ 
    297285    SetWindowTextW(hWndStatusLbl, message.c_str()); 
     286} 
     287 
     288LRESULT MainWindow::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, 
     289    bool& handled) 
     290{ 
     291    handled = false; 
     292    switch (message) 
     293    { 
     294    case WM_COMMAND: 
     295        if (hWnd == hWndCancelBtn && HIWORD(wParam) == BN_CLICKED) 
     296            PostQuitMessage(1); 
     297        break; 
     298    } 
     299} 
     300 
     301void MainWindow::SubclassWindow(MainWindow& owner, HWND hWnd, WNDPROC wndProc) 
     302{ 
     303    OldWndProcs.insert(std::make_pair( 
     304        hWnd, WndProcData(reinterpret_cast<WNDPROC>(SetWindowLongPtr(hWnd, 
     305            GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(wndProc))), owner) 
     306    )); 
     307} 
     308 
     309LRESULT __stdcall MainWindow::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
     310{ 
     311    std::map<HWND, WndProcData>::const_iterator iter = OldWndProcs.find(hWnd); 
     312    if (iter != OldWndProcs.end()) 
     313    { 
     314        bool handled = false; 
     315        LRESULT result = iter->second.Owner->WindowProc(hWnd, message, wParam, 
     316            lParam, handled); 
     317        if (handled) 
     318            return result; 
     319 
     320        return CallWindowProc(iter->second.OldWndProc, hWnd, message, wParam, lParam); 
     321    } 
     322 
     323    switch (message) 
     324    { 
     325    case WM_DESTROY: 
     326        PostQuitMessage(0); 
     327        break; 
     328 
     329    default: 
     330        return DefWindowProc(hWnd, message, wParam, lParam); 
     331    } 
     332 
     333    return 0; 
    298334} 
    299335 
  • branches/eraser6/Installer/Bootstrapper/stdafx.h

    r532 r542  
    3131#include <windows.h> 
    3232#include <commctrl.h> 
    33 #undef min 
    3433 
    3534#include <tchar.h> 
    3635#include <string> 
     36#include <map> 
    3737 
    3838//7-zip SDK 
Note: See TracChangeset for help on using the changeset viewer.