mirror of https://github.com/BOINC/boinc.git
client & MGR: On Windows, handle expansion of environment variables in the registry value that stores DATADIR.
This commit is contained in:
parent
640d6dc16a
commit
1bbc5e96e2
|
@ -815,8 +815,10 @@ void CBOINCGUIApp::DetectDataDirectory() {
|
||||||
//
|
//
|
||||||
LONG lReturnValue;
|
LONG lReturnValue;
|
||||||
HKEY hkSetupHive;
|
HKEY hkSetupHive;
|
||||||
LPTSTR lpszRegistryValue = NULL;
|
|
||||||
TCHAR szPath[MAX_PATH];
|
TCHAR szPath[MAX_PATH];
|
||||||
|
LPTSTR lpszValue = NULL;
|
||||||
|
LPTSTR lpszExpandedValue = NULL;
|
||||||
|
DWORD dwValueType = REG_EXPAND_SZ;
|
||||||
DWORD dwSize = 0;
|
DWORD dwSize = 0;
|
||||||
|
|
||||||
// change the current directory to the boinc data directory if it exists
|
// change the current directory to the boinc data directory if it exists
|
||||||
|
@ -833,27 +835,41 @@ void CBOINCGUIApp::DetectDataDirectory() {
|
||||||
hkSetupHive,
|
hkSetupHive,
|
||||||
_T("DATADIR"),
|
_T("DATADIR"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&dwValueType,
|
||||||
NULL,
|
NULL,
|
||||||
&dwSize
|
&dwSize
|
||||||
);
|
);
|
||||||
if (lReturnValue != ERROR_FILE_NOT_FOUND) {
|
if (lReturnValue != ERROR_FILE_NOT_FOUND) {
|
||||||
// Allocate the buffer space.
|
// Allocate the buffer space.
|
||||||
lpszRegistryValue = (LPTSTR) malloc(dwSize);
|
lpszValue = (LPTSTR) malloc(dwSize);
|
||||||
(*lpszRegistryValue) = NULL;
|
(*lpszValue) = NULL;
|
||||||
|
|
||||||
// Now get the data
|
// Now get the data
|
||||||
lReturnValue = RegQueryValueEx(
|
lReturnValue = RegQueryValueEx(
|
||||||
hkSetupHive,
|
hkSetupHive,
|
||||||
_T("DATADIR"),
|
_T("DATADIR"),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&dwValueType,
|
||||||
(LPBYTE)lpszRegistryValue,
|
(LPBYTE)lpszValue,
|
||||||
&dwSize
|
&dwSize
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Expand the Strings
|
||||||
|
// We need to get the size of the buffer needed
|
||||||
|
dwSize = 0;
|
||||||
|
lReturnValue = ExpandEnvironmentStrings(lpszValue, NULL, dwSize);
|
||||||
|
|
||||||
|
if (lReturnValue) {
|
||||||
|
// Make the buffer big enough for the expanded string
|
||||||
|
lpszExpandedValue = (LPTSTR) malloc(lReturnValue*sizeof(TCHAR));
|
||||||
|
(*lpszExpandedValue) = NULL;
|
||||||
|
dwSize = lReturnValue;
|
||||||
|
|
||||||
|
ExpandEnvironmentStrings(lpszValue, lpszExpandedValue, dwSize);
|
||||||
|
|
||||||
// Store the root directory for later use.
|
// Store the root directory for later use.
|
||||||
m_strBOINCMGRDataDirectory = lpszRegistryValue;
|
m_strBOINCMGRDataDirectory = lpszExpandedValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) {
|
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) {
|
||||||
|
@ -867,7 +883,8 @@ void CBOINCGUIApp::DetectDataDirectory() {
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
if (hkSetupHive) RegCloseKey(hkSetupHive);
|
if (hkSetupHive) RegCloseKey(hkSetupHive);
|
||||||
if (lpszRegistryValue) free(lpszRegistryValue);
|
if (lpszValue) free(lpszValue);
|
||||||
|
if (lpszExpandedValue) free(lpszExpandedValue);
|
||||||
#endif
|
#endif
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
m_strBOINCMGRDataDirectory = wxT("/Library/Application Support/BOINC Data");
|
m_strBOINCMGRDataDirectory = wxT("/Library/Application Support/BOINC Data");
|
||||||
|
|
|
@ -52,8 +52,10 @@ BOOL TerminateProcessById( DWORD dwProcessID ) {
|
||||||
void chdir_to_data_dir() {
|
void chdir_to_data_dir() {
|
||||||
LONG lReturnValue;
|
LONG lReturnValue;
|
||||||
HKEY hkSetupHive;
|
HKEY hkSetupHive;
|
||||||
LPSTR lpszRegistryValue = NULL;
|
|
||||||
char szPath[MAX_PATH];
|
char szPath[MAX_PATH];
|
||||||
|
LPSTR lpszValue = NULL;
|
||||||
|
LPSTR lpszExpandedValue = NULL;
|
||||||
|
DWORD dwValueType = REG_EXPAND_SZ;
|
||||||
DWORD dwSize = 0;
|
DWORD dwSize = 0;
|
||||||
|
|
||||||
// change the current directory to the boinc data directory if it exists
|
// change the current directory to the boinc data directory if it exists
|
||||||
|
@ -70,26 +72,40 @@ void chdir_to_data_dir() {
|
||||||
hkSetupHive,
|
hkSetupHive,
|
||||||
"DATADIR",
|
"DATADIR",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&dwValueType,
|
||||||
NULL,
|
NULL,
|
||||||
&dwSize
|
&dwSize
|
||||||
);
|
);
|
||||||
if (lReturnValue != ERROR_FILE_NOT_FOUND) {
|
if (lReturnValue != ERROR_FILE_NOT_FOUND) {
|
||||||
// Allocate the buffer space.
|
// Allocate the buffer space.
|
||||||
lpszRegistryValue = (LPSTR) malloc(dwSize);
|
lpszValue = (LPSTR) malloc(dwSize);
|
||||||
(*lpszRegistryValue) = NULL;
|
(*lpszValue) = NULL;
|
||||||
|
|
||||||
// Now get the data
|
// Now get the data
|
||||||
lReturnValue = RegQueryValueExA(
|
lReturnValue = RegQueryValueExA(
|
||||||
hkSetupHive,
|
hkSetupHive,
|
||||||
"DATADIR",
|
"DATADIR",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
&dwValueType,
|
||||||
(LPBYTE)lpszRegistryValue,
|
(LPBYTE)lpszValue,
|
||||||
&dwSize
|
&dwSize
|
||||||
);
|
);
|
||||||
|
|
||||||
SetCurrentDirectoryA(lpszRegistryValue);
|
// Expand the Strings
|
||||||
|
// We need to get the size of the buffer needed
|
||||||
|
dwSize = 0;
|
||||||
|
lReturnValue = ExpandEnvironmentStringsA(lpszValue, NULL, dwSize);
|
||||||
|
|
||||||
|
if (lReturnValue) {
|
||||||
|
// Make the buffer big enough for the expanded string
|
||||||
|
lpszExpandedValue = (LPSTR) malloc(lReturnValue);
|
||||||
|
(*lpszExpandedValue) = NULL;
|
||||||
|
dwSize = lReturnValue;
|
||||||
|
|
||||||
|
ExpandEnvironmentStringsA(lpszValue, lpszExpandedValue, dwSize);
|
||||||
|
|
||||||
|
SetCurrentDirectoryA(lpszExpandedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) {
|
if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szPath))) {
|
||||||
|
@ -101,7 +117,8 @@ void chdir_to_data_dir() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hkSetupHive) RegCloseKey(hkSetupHive);
|
if (hkSetupHive) RegCloseKey(hkSetupHive);
|
||||||
if (lpszRegistryValue) free(lpszRegistryValue);
|
if (lpszValue) free(lpszValue);
|
||||||
|
if (lpszExpandedValue) free(lpszExpandedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring A2W(const std::string& str) {
|
std::wstring A2W(const std::string& str) {
|
||||||
|
|
Loading…
Reference in New Issue