From 3d358ee7ea1c7438d1b266d7f1e44686bbef6cf4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 11 Jul 2016 12:29:01 -0700 Subject: [PATCH] Fix Windows compilation issues --- atom/browser/browser_win.cc | 54 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index 88c2df3b6a13..522fffa0191f 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -274,47 +274,35 @@ bool Browser::SetBadgeCount(int count) { } void Browser::SetLoginItemSettings(LoginItemSettings settings) { - base::FilePath path; - if (!PathService::Get(base::FILE_EXE, &path)) { - LOG(ERROR) << "Error getting app exe path"; - return; - } + std::wstring keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS); - // Main Registry Key - HKEY root = HKEY_CURRENT_USER; - std::string keyPathStr = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; - std::wstring keyPath = std::wstring(keyPathStr.begin(), keyPathStr.end()); - - // Executable Path - std::wstring exePath(path.value()); - base::win::RegKey key(root, keyPath.c_str(), KEY_ALL_ACCESS); - - if (settings.open_at_login) - key.WriteValue(GetAppUserModelID(), exePath.c_str()); - else { - key.DeleteValue(GetAppUserModelID()) + if (settings.open_at_login) { + base::FilePath path; + if (PathService::Get(base::FILE_EXE, &path)) { + std::wstring exePath(path.value()); + key.WriteValue(GetAppUserModelID(), exePath.c_str()); + } + } else { + key.DeleteValue(GetAppUserModelID()); } } -LoginItemSettings Browser::GetLoginItemSettings() { +Browser::LoginItemSettings Browser::GetLoginItemSettings() { LoginItemSettings settings; + std::wstring keyPath = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + base::win::RegKey key(HKEY_CURRENT_USER, keyPath.c_str(), KEY_ALL_ACCESS); + std::wstring keyVal; - base::FilePath path; - if (!PathService::Get(base::FILE_EXE, &path)) { - LOG(ERROR) << "Error getting app exe path"; - return; + if (!FAILED(key.ReadValue(GetAppUserModelID(), &keyVal))) { + base::FilePath path; + if (PathService::Get(base::FILE_EXE, &path)) { + std::wstring exePath(path.value()); + settings.open_at_login = keyVal == exePath; + } } - // Main Registry Key - HKEY root = HKEY_CURRENT_USER; - std::string keyPathStr = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"; - std::wstring keyPath = std::wstring(keyPathStr.begin(), keyPathStr.end()); - - // Executable Path - std::wstring exePath(path.value()); - base::win::RegKey key(root, keyPath.c_str(), KEY_ALL_ACCESS); - - settings.open_at_login = key.HasValue(GetAppUserModelID()); + return settings; }