From 3ed1e767b150f8b18370f27873dab1a682129139 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 6 Apr 2015 18:29:59 +0200 Subject: [PATCH] [BUG_FIXED] Fix Settings on Cloud Google Drive not working issue. --- PowerEditor/src/Parameters.cpp | 41 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 2cfea798..9682adfd 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -990,11 +990,11 @@ generic_string NppParameters::getCloudSettingsPath(CloudChoice cloudChoice) // Get value from registry generic_string settingsPath4OneDrive = TEXT(""); - HKEY hKey; - LRESULT res = ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SkyDrive"), 0, KEY_READ, &hKey); + HKEY hOneDriveKey; + LRESULT res = ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SkyDrive"), 0, KEY_READ, &hOneDriveKey); if (res != ERROR_SUCCESS) { - res = ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\SkyDrive"), 0, KEY_READ, &hKey); + res = ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\SkyDrive"), 0, KEY_READ, &hOneDriveKey); } if (res == ERROR_SUCCESS) @@ -1002,30 +1002,39 @@ generic_string NppParameters::getCloudSettingsPath(CloudChoice cloudChoice) TCHAR valData[MAX_PATH]; int valDataLen = MAX_PATH * sizeof(TCHAR); int valType; - ::RegQueryValueEx(hKey, TEXT("UserFolder"), NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); + ::RegQueryValueEx(hOneDriveKey, TEXT("UserFolder"), NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); if (::PathFileExists(valData)) { settingsPath4OneDrive = valData; _nppGUI._availableClouds |= ONEDRIVE_AVAILABLE; } - ::RegCloseKey(hKey); + ::RegCloseKey(hOneDriveKey); } // // TODO: check if google drive is present // - ITEMIDLIST *pidl2; - const HRESULT specialFolderLocationResult_2 = SHGetSpecialFolderLocation(NULL, CSIDL_LOCAL_APPDATA, &pidl2); - if ( !SUCCEEDED( specialFolderLocationResult_2 ) ) - { - return TEXT( "" ); - } - TCHAR tmp2[MAX_PATH]; - SHGetPathFromIDList(pidl2, tmp2); - generic_string googleDriveInfoDB = tmp2; + generic_string googleDriveInfoDB = TEXT(""); - PathAppend(googleDriveInfoDB, TEXT("Google\\Drive\\sync_config.db")); + HKEY hGoogleDriveKey; + res = ::RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Google\\Drive"), 0, KEY_READ, &hGoogleDriveKey); + + if (res == ERROR_SUCCESS) + { + TCHAR valData[MAX_PATH]; + int valDataLen = MAX_PATH * sizeof(TCHAR); + int valType; + ::RegQueryValueEx(hGoogleDriveKey, TEXT("Path"), NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); + + if (::PathFileExists(valData)) + { + googleDriveInfoDB = valData; + } + ::RegCloseKey(hGoogleDriveKey); + } + + PathAppend(googleDriveInfoDB, TEXT("\\user_default\\sync_config.db")); generic_string settingsPath4GoogleDrive = TEXT(""); @@ -1090,7 +1099,6 @@ generic_string NppParameters::getCloudSettingsPath(CloudChoice cloudChoice) } else if (cloudChoice == oneDrive) { - _nppGUI._cloudChoice = oneDrive; cloudSettingsPath = settingsPath4OneDrive; PathAppend(cloudSettingsPath, TEXT("Notepad++")); @@ -1102,7 +1110,6 @@ generic_string NppParameters::getCloudSettingsPath(CloudChoice cloudChoice) } else if (cloudChoice == googleDrive) { - _nppGUI._cloudChoice = googleDrive; cloudSettingsPath = settingsPath4GoogleDrive; PathAppend(cloudSettingsPath, TEXT("Notepad++"));