From 1e8bdc15e20ad9ad179ec2efff9c4927234d73dc Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 25 Oct 2017 10:40:38 -0400 Subject: [PATCH 1/6] use _wgetenv to get windows env variables --- brightray/browser/browser_main_parts.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index e5406e519a67..6b7c47f5c7e2 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -168,7 +168,9 @@ BrowserMainParts::~BrowserMainParts() { void OverrideAppLogsPath() { #if defined(OS_WIN) std::wstring app_name = base::UTF8ToWide(GetApplicationName()); - std::wstring log_path = L"%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::wstring drive = _wgetenv(L"HOMEDRIVE")); + std::wstring path = _wgetenv(L"HOMEPATH")); + std::wstring log_path = drive + "\\" + path + L"\\AppData\\Roaming\\"; std::wstring app_log_path = log_path + app_name + L"\\logs"; #else std::string app_name = GetApplicationName(); From 3c1c5a409919234a6402299132885a214a518991 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 25 Oct 2017 11:46:51 -0400 Subject: [PATCH 2/6] combine homepath and homedrive into single line --- brightray/browser/browser_main_parts.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 6b7c47f5c7e2..c5ee689c1002 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -168,9 +168,8 @@ BrowserMainParts::~BrowserMainParts() { void OverrideAppLogsPath() { #if defined(OS_WIN) std::wstring app_name = base::UTF8ToWide(GetApplicationName()); - std::wstring drive = _wgetenv(L"HOMEDRIVE")); - std::wstring path = _wgetenv(L"HOMEPATH")); - std::wstring log_path = drive + "\\" + path + L"\\AppData\\Roaming\\"; + std::wstring home = _wgetenv(L"HOMEDRIVE") + "\\" +_wgetenv(L"HOMEPATH"); + std::wstring log_path = home + L"\\AppData\\Roaming\\"; std::wstring app_log_path = log_path + app_name + L"\\logs"; #else std::string app_name = GetApplicationName(); From 06811cc557e1621fb24addfb593c975f54a33a4f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 25 Oct 2017 12:02:50 -0400 Subject: [PATCH 3/6] appropriately cast pointers to strings --- brightray/browser/browser_main_parts.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index c5ee689c1002..fe9cc7073b47 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -168,8 +168,9 @@ BrowserMainParts::~BrowserMainParts() { void OverrideAppLogsPath() { #if defined(OS_WIN) std::wstring app_name = base::UTF8ToWide(GetApplicationName()); - std::wstring home = _wgetenv(L"HOMEDRIVE") + "\\" +_wgetenv(L"HOMEPATH"); - std::wstring log_path = home + L"\\AppData\\Roaming\\"; + std::wstring home = std::wstring(_wgetenv(L"HOMEDRIVE")); + std::wstring drive = std::wstring(_wgetenv(L"HOMEPATH")); + std::wstring log_path = home + L"\\" + drive + L"\\AppData\\Roaming\\"; std::wstring app_log_path = log_path + app_name + L"\\logs"; #else std::string app_name = GetApplicationName(); From 246c808222c99c8406b379fbd27001d3da0c0b60 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 00:18:55 -0400 Subject: [PATCH 4/6] move away from wstring --- brightray/browser/browser_main_parts.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index fe9cc7073b47..ec08763038f7 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -166,18 +166,17 @@ BrowserMainParts::~BrowserMainParts() { #if defined(OS_WIN) || defined(OS_LINUX) void OverrideAppLogsPath() { + base::FilePath path; + bool success = PathService::Get(brightray::DIR_APP_DATA, &path); + if (success) { + path = path.Append(base::UTF8ToWide(GetApplicationName())); #if defined(OS_WIN) - std::wstring app_name = base::UTF8ToWide(GetApplicationName()); - std::wstring home = std::wstring(_wgetenv(L"HOMEDRIVE")); - std::wstring drive = std::wstring(_wgetenv(L"HOMEPATH")); - std::wstring log_path = home + L"\\" + drive + L"\\AppData\\Roaming\\"; - std::wstring app_log_path = log_path + app_name + L"\\logs"; + path = path.Append(L"logs"); #else - std::string app_name = GetApplicationName(); - std::string home_path = std::string(getenv("HOME")); - std::string app_log_path = home_path + "/.config/" + app_name + "/logs"; + path = path.Append("logs"); #endif - PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path)); + PathService::Override(DIR_APP_LOGS, base::FilePath(path)); + } } #endif From c9dca6b8ad9aeddd5fbab4ca01daa2a481ed575c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 00:21:52 -0400 Subject: [PATCH 5/6] remove unnecessary boolean --- brightray/browser/browser_main_parts.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index ec08763038f7..74008dd23ddc 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -167,8 +167,7 @@ BrowserMainParts::~BrowserMainParts() { #if defined(OS_WIN) || defined(OS_LINUX) void OverrideAppLogsPath() { base::FilePath path; - bool success = PathService::Get(brightray::DIR_APP_DATA, &path); - if (success) { + if (PathService::Get(brightray::DIR_APP_DATA, &path)) { path = path.Append(base::UTF8ToWide(GetApplicationName())); #if defined(OS_WIN) path = path.Append(L"logs"); From fc920ffd06210875653dee854d94e91a26ff41c3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 26 Oct 2017 00:27:27 -0400 Subject: [PATCH 6/6] base::UTF8ToWide --> base::FromUTF8Unsafe --- brightray/browser/browser_main_parts.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 74008dd23ddc..f3ab093af067 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -168,13 +168,9 @@ BrowserMainParts::~BrowserMainParts() { void OverrideAppLogsPath() { base::FilePath path; if (PathService::Get(brightray::DIR_APP_DATA, &path)) { - path = path.Append(base::UTF8ToWide(GetApplicationName())); -#if defined(OS_WIN) - path = path.Append(L"logs"); -#else - path = path.Append("logs"); -#endif - PathService::Override(DIR_APP_LOGS, base::FilePath(path)); + path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + path = path.Append(base::FilePath::FromUTF8Unsafe("logs")); + PathService::Override(DIR_APP_LOGS, path); } } #endif