Changeset 1445


Ignore:
Timestamp:
1/4/2010 10:12:06 AM (5 years ago)
Author:
lowjoel
Message:

-Ensure that the bootstrapper checks the service pack level for the installed .NET framework; currently we check for .NET 3.5 SP1.
-Minor code cleanup (factored out the Handle class to be a template, allowing any abstract handle to be used)

Location:
branches/eraser6/6.0
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/eraser6/6.0

  • branches/eraser6/6.0/Installer/Bootstrapper/Bootstrapper.cpp

    r1360 r1445  
    2222#include "stdafx.h" 
    2323#include "Bootstrapper.h" 
    24  
    25 class Handle 
    26 { 
    27 public: 
    28     Handle(HANDLE handle) 
    29     { 
    30         thisHandle = handle; 
    31     } 
    32  
    33     ~Handle() 
    34     { 
    35         CloseHandle(thisHandle); 
    36     } 
    37  
    38     operator HANDLE() 
    39     { 
    40         return thisHandle; 
    41     } 
    42  
    43 private: 
    44     HANDLE thisHandle; 
    45 }; 
     24#include "Handle.h" 
    4625 
    4726const wchar_t *ResourceName = MAKEINTRESOURCE(101); 
     
    5231    DWORD lastOperation = 0; 
    5332    { 
    54         Handle srcFile(CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
     33        Handle<HANDLE> srcFile(CreateFileW(Application::Get().GetPath().c_str(), GENERIC_READ, 
    5534            FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
    5635        if (srcFile == INVALID_HANDLE_VALUE) 
     
    5837 
    5938        //Copy ourselves 
    60         Handle destFile(CreateFileW(destItem.c_str(), GENERIC_WRITE, 0, NULL, 
     39        Handle<HANDLE> destFile(CreateFileW(destItem.c_str(), GENERIC_WRITE, 0, NULL, 
    6140            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
    6241        if (destFile == INVALID_HANDLE_VALUE) 
     
    7453 
    7554    //Read the package into memory 
    76     Handle packageFile(CreateFileW(package.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, 
     55    Handle<HANDLE> packageFile(CreateFileW(package.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, 
    7756        OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
    7857    if (packageFile == INVALID_HANDLE_VALUE) 
     
    271250            sizeof(fileName) / sizeof(fileName[0]) - wcslen(baseFileName), fileExt); 
    272251 
    273         Handle destFile(CreateFileW((pathToExtract + fileName).c_str(), GENERIC_WRITE, 0, 
    274             NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
     252        Handle<HANDLE> destFile(CreateFileW((pathToExtract + fileName).c_str(), GENERIC_WRITE, 
     253            0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); 
    275254        if (destFile == INVALID_HANDLE_VALUE) 
    276255            throw GetErrorMessage(GetLastError()); 
     
    300279bool HasNetFramework() 
    301280{ 
    302     HKEY key; 
    303     std::wstring highestVer; 
    304     std::wstring keys[] = { L"v3.5" }; 
    305  
    306     for (int i = 0, j = sizeof(keys) / sizeof(keys[0]); i != j; ++i) 
    307     { 
    308         //Open the key for reading 
    309         DWORD result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
    310             (L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\" + keys[i]).c_str(), 
    311             0, KEY_READ, &key); 
    312  
    313         //Retry for 64-bit WoW 
     281    const std::wstring versionKey(L"v3.5"); 
     282 
     283    //Open the key for reading 
     284    Handle<HKEY> key; 
     285    DWORD result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
     286        (L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\" + versionKey).c_str(), 
     287        0, KEY_READ, key); 
     288 
     289    //Retry for 64-bit WoW 
     290    if (result == ERROR_FILE_NOT_FOUND) 
     291    { 
     292        result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
     293            (L"SOFTWARE\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\" + versionKey).c_str(), 
     294            0, KEY_READ, key); 
     295 
    314296        if (result == ERROR_FILE_NOT_FOUND) 
    315         { 
    316             result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, 
    317                 (L"SOFTWARE\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\" + keys[i]).c_str(), 
    318                 0, KEY_READ, &key); 
    319  
    320             if (result == ERROR_FILE_NOT_FOUND) 
    321                 continue; 
    322         } 
    323  
    324         if (result != ERROR_SUCCESS) 
    325             throw GetErrorMessage(result); 
    326  
    327         //Query the Installed string 
    328         DWORD installedVal = 0; 
    329         DWORD bufferSize = sizeof(installedVal); 
    330         result = RegQueryValueExW(key, L"Install", NULL, NULL, (BYTE*)&installedVal, 
    331             &bufferSize); 
    332         if (result != ERROR_SUCCESS && result != ERROR_MORE_DATA) 
    333             throw GetErrorMessage(result); 
    334         if (installedVal == 1) 
    335             highestVer = keys[i].substr(1); 
    336         RegCloseKey(key); 
    337     } 
    338  
    339     return !highestVer.empty(); 
     297            return false; 
     298    } 
     299 
     300    if (result != ERROR_SUCCESS) 
     301        throw GetErrorMessage(result); 
     302 
     303    //Query the Install string 
     304    wchar_t buffer[32]; 
     305    DWORD bufferSize = sizeof(buffer); 
     306    ::ZeroMemory(buffer, sizeof(buffer)); 
     307    result = RegQueryValueExW(key, L"Install", NULL, NULL, reinterpret_cast<BYTE*>(buffer), 
     308        &bufferSize); 
     309    if (result != ERROR_SUCCESS && result != ERROR_MORE_DATA) 
     310        throw GetErrorMessage(result); 
     311     
     312    //If we got more data than we wanted or if the value is not zero, it's invalid. 
     313    if (bufferSize != sizeof(DWORD) || *reinterpret_cast<DWORD*>(buffer) == 0) 
     314        return false; 
     315 
     316    //Next get the exact version installed 
     317    bufferSize = sizeof(buffer); 
     318    ::ZeroMemory(buffer, sizeof(buffer)); 
     319    result = RegQueryValueExW(key, L"Version", NULL, NULL, reinterpret_cast<BYTE*>(buffer), 
     320        &bufferSize); 
     321    if ((result != ERROR_SUCCESS && result != ERROR_MORE_DATA) || bufferSize == sizeof(buffer)) 
     322        throw GetErrorMessage(result); 
     323 
     324    //Ensure that the version string is NULL terminated 
     325    buffer[bufferSize / sizeof(wchar_t)] = L'\0'; 
     326 
     327    //Split the version into its four components 
     328    int versionComponents[] = { 0, 0, 0, 0 }; 
     329    wchar_t* previousDot = buffer - 1; 
     330    wchar_t* nextDot = NULL; 
     331    for (unsigned i = 0; i < sizeof(versionComponents) / sizeof(versionComponents[0]); ++i) 
     332    { 
     333        nextDot = wcschr(previousDot + 1, L'.'); 
     334        versionComponents[i] = boost::lexical_cast<int>( 
     335            nextDot ? std::wstring(++previousDot, nextDot) : std::wstring(++previousDot)); 
     336        if (!nextDot) 
     337            break; 
     338 
     339        previousDot = nextDot; 
     340    } 
     341 
     342    return versionComponents[0] == 3 && versionComponents[1] == 5 && versionComponents[2] >= 30729; 
    340343} 
    341344 
  • branches/eraser6/6.0/Installer/Bootstrapper/Bootstrapper.vcproj

    r1277 r1445  
    218218            </File> 
    219219            <File 
     220                RelativePath=".\Handle.h" 
     221                > 
     222            </File> 
     223            <File 
    220224                RelativePath=".\Resource.h" 
    221225                > 
  • branches/eraser6/6.0/Installer/Bootstrapper/stdafx.h

    r1360 r1445  
    4545    #include <C/Archive/7z/7zExtract.h> 
    4646} 
     47 
     48//Boost 
     49#include <boost/lexical_cast.hpp> 
Note: See TracChangeset for help on using the changeset viewer.