diff --git a/lib/win_util.cpp b/lib/win_util.cpp index 394940bd15..ab675b5332 100644 --- a/lib/win_util.cpp +++ b/lib/win_util.cpp @@ -26,6 +26,8 @@ #endif #include "diagnostics.h" +#include "util.h" +#include "filesys.h" #include "win_util.h" /** @@ -748,22 +750,23 @@ GetAccountSid( void chdir_to_data_dir() { LONG lReturnValue; HKEY hkSetupHive; - LPTSTR lpszRegistryValue = NULL; + LPSTR lpszRegistryValue = NULL; + char szPath[MAX_PATH]; DWORD dwSize = 0; // change the current directory to the boinc data directory if it exists - lReturnValue = RegOpenKeyEx( + lReturnValue = RegOpenKeyExA( HKEY_LOCAL_MACHINE, - _T("SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup"), + "SOFTWARE\\Space Sciences Laboratory, U.C. Berkeley\\BOINC Setup", 0, KEY_READ, &hkSetupHive ); if (lReturnValue == ERROR_SUCCESS) { // How large does our buffer need to be? - lReturnValue = RegQueryValueEx( + lReturnValue = RegQueryValueExA( hkSetupHive, - _T("DATADIR"), + "DATADIR", NULL, NULL, NULL, @@ -771,20 +774,27 @@ void chdir_to_data_dir() { ); if (lReturnValue != ERROR_FILE_NOT_FOUND) { // Allocate the buffer space. - lpszRegistryValue = (LPTSTR) malloc(dwSize); + lpszRegistryValue = (LPSTR) malloc(dwSize); (*lpszRegistryValue) = NULL; // Now get the data - lReturnValue = RegQueryValueEx( + lReturnValue = RegQueryValueExA( hkSetupHive, - _T("DATADIR"), + "DATADIR", NULL, NULL, (LPBYTE)lpszRegistryValue, &dwSize ); - SetCurrentDirectory(lpszRegistryValue); + SetCurrentDirectoryA(lpszRegistryValue); + } + } else { + if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) { + strncat(szPath, "\\boinc", (sizeof(szPath) - strlen(szPath))); + if (boinc_file_exists(szPath)) { + SetCurrentDirectoryA(szPath); + } } } diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 764accaf48..d4dcef6262 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -64,6 +64,7 @@ #include "boinc_api.h" #include "diagnostics.h" #include "filesys.h" +#include "md5_file.h" #include "parse.h" #include "str_util.h" #include "str_replace.h" @@ -399,12 +400,26 @@ int main(int argc, char** argv) { } } + memset(&boinc_options, 0, sizeof(boinc_options)); + boinc_options.main_program = true; + boinc_options.check_heartbeat = true; + boinc_options.handle_process_control = true; + boinc_init_options(&boinc_options); + + // Prepare environment for detecting system conditions + // + boinc_get_init_data_p(&aid); + + // Log banner + // fprintf( stderr, "%s vboxwrapper: starting\n", vboxwrapper_msg_prefix(buf, sizeof(buf)) ); + // Log important information + // #if defined(_WIN32) && defined(USE_WINSOCK) WSADATA wsdata; retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata); @@ -419,11 +434,6 @@ int main(int argc, char** argv) { } #endif - memset(&boinc_options, 0, sizeof(boinc_options)); - boinc_options.main_program = true; - boinc_options.check_heartbeat = true; - boinc_options.handle_process_control = true; - if (trickle_period > 0.0) { fprintf( stderr, @@ -433,12 +443,6 @@ int main(int argc, char** argv) { boinc_options.handle_trickle_ups = true; } - boinc_init_options(&boinc_options); - - // Prepare environment for detecting system conditions - // - boinc_get_init_data_p(&aid); - // Check for architecture incompatibilities // #if defined(_WIN32) && defined(_M_IX86) @@ -582,8 +586,7 @@ int main(int argc, char** argv) { vm.floppy_image_filename = buf; } } else { - sprintf(buf, "_slot_%d", aid.slot); - vm.vm_master_name += buf; + vm.vm_master_name += md5_string(std::string(aid.result_name)).substr(0, 16); vm.vm_master_description = aid.result_name; if (vm.enable_floppyio) { sprintf(buf, "%s_%d.%s", FLOPPY_IMAGE_FILENAME, aid.slot, FLOPPY_IMAGE_FILENAME_EXTENSION); diff --git a/win_build/vboxwrapper.vcproj b/win_build/vboxwrapper.vcproj index 63f8a56f4e..73709b368b 100644 --- a/win_build/vboxwrapper.vcproj +++ b/win_build/vboxwrapper.vcproj @@ -82,13 +82,13 @@ @@ -183,13 +183,13 @@