X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsysutils.cpp;h=95867b70fcfb1b21cdca897bef91633a40bdcf53;hb=451ef4f33b5a57dcb56bd7cb671bed359ac86247;hp=8fa3d4894924333581810cb9d19a015c26573057;hpb=58727f8fb2a4840b3170806bb87a058b03194e12;p=builder.git diff --git a/source/sysutils.cpp b/source/sysutils.cpp index 8fa3d48..95867b7 100644 --- a/source/sysutils.cpp +++ b/source/sysutils.cpp @@ -1,9 +1,16 @@ +#define _WIN32_WINNT _WIN32_WINNT_VISTA #define WIN32_LEAN_AND_MEAN +#define INITGUID #ifdef _WIN32 #include +#include +#include #else #include #endif +#include +#include +#include #include #include #include "sysutils.h" @@ -33,3 +40,74 @@ string get_system_type() return string(); } + +FS::Path get_program_files_x86_dir() +{ +#ifdef _WIN32 + wchar_t *program_files_x86_ptr = 0; + HRESULT err = SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, 0, NULL, &program_files_x86_ptr); + if(err!=S_OK) + throw runtime_error("Can't get Program Files path"); + + unsigned len = wcslen(program_files_x86_ptr); + FS::Path program_files_x86 = StringCodec::transcode( + string(reinterpret_cast(program_files_x86_ptr), len*sizeof(wchar_t))); + + CoTaskMemFree(program_files_x86_ptr); + + return program_files_x86; +#else + return "/mnt/c/Program Files (x86)"; +#endif +} + +template<> +string get_registry_value(const string &path) +{ +#ifdef _WIN32 + string::size_type first_sep = path.find('\\'); + string::size_type last_sep = path.rfind('\\'); + string root = path.substr(0, first_sep); + string key_path = path.substr(first_sep+1, last_sep-first_sep-1); + string value_name = path.substr(last_sep+1); + + HKEY root_handle; + if(root=="HKCR") + root_handle = HKEY_CLASSES_ROOT; + else if(root=="HKCC") + root_handle = HKEY_CURRENT_CONFIG; + else if(root=="HKCU") + root_handle = HKEY_CURRENT_USER; + else if(root=="HKLM") + root_handle = HKEY_LOCAL_MACHINE; + else if(root=="HKU") + root_handle = HKEY_USERS; + else + throw invalid_argument("get_registry_value"); + + HKEY key; + LSTATUS err = RegOpenKeyEx(root_handle, key_path.c_str(), 0, KEY_READ, &key); + if(err!=ERROR_SUCCESS) + throw Msp::system_error("RegOpenKey", err); + + DWORD value_len; + err = RegGetValue(key, 0, value_name.c_str(), RRF_RT_REG_SZ, 0, 0, &value_len); + if(err!=ERROR_SUCCESS) + throw Msp::system_error("RegGetValue", err); + + char *buffer = new char[value_len]; + err = RegGetValue(key, 0, value_name.c_str(), RRF_RT_REG_SZ, 0, buffer, &value_len); + if(err!=ERROR_SUCCESS) + { + delete[] buffer; + throw Msp::system_error("RegGetValue", err); + } + + string result(buffer); + delete[] buffer; + return result; +#else + (void)path; + return string(); +#endif +}