From 5ef4caf8ab465eb917f7376bdd7e2d6b4f15ec55 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 3 Aug 2017 15:50:56 -0700 Subject: [PATCH 01/17] add ability to access logs in getPath() --- atom/browser/api/atom_api_app.cc | 2 ++ brightray/browser/brightray_paths.h | 1 + brightray/browser/browser_main_parts.cc | 6 +++++- brightray/browser/browser_main_parts.h | 2 ++ brightray/browser/browser_main_parts_mac.mm | 12 ++++++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 37ff0507d761..d8ce8170fb0b 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -375,6 +375,8 @@ int GetPathConstant(const std::string& name) { return brightray::DIR_CACHE; else if (name == "userCache") return brightray::DIR_USER_CACHE; + else if (name == "logs") + return brightray::DIR_APP_LOGS; else if (name == "home") return base::DIR_HOME; else if (name == "temp") diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index b12b10d08f3c..56525baeaab7 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -22,6 +22,7 @@ enum { DIR_USER_DATA = PATH_START, // Directory where user data can be written. DIR_USER_CACHE, // Directory where user cache can be written. + DIR_APP_LOGS, // Directory where app logs live #if defined(OS_LINUX) DIR_APP_DATA, // Application Data directory under the user profile. diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index d6336962fef6..a949a236f3a0 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -55,6 +55,8 @@ namespace brightray { +void OverrideMacAppLogsPath(); + namespace { #if defined(OS_WIN) @@ -160,7 +162,9 @@ void BrowserMainParts::PreEarlyInitialization() { std::unique_ptr feature_list(new base::FeatureList); feature_list->InitializeFromCommandLine("", ""); base::FeatureList::SetInstance(std::move(feature_list)); - +#if defined(OS_MACOSX) + OverrideMacAppLogsPath(); +#endif #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index d495e67b5ffa..53d3cf38b720 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,6 +9,8 @@ #include "base/compiler_specific.h" #include "base/macros.h" +#include "base/path_service.h" +#include "brightray/browser/brightray_paths.h" #include "content/public/browser/browser_main_parts.h" #include "ui/views/layout/layout_provider.h" diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 5e80eca442be..2e111caafc0e 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -6,6 +6,18 @@ namespace brightray { +void OverrideMacAppLogsPath() { + base::FilePath path; + NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] + objectForKey:@"CFBundleName"]; + NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName]; + + NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; + std::string libPathString = std::string([libraryPath UTF8String]); + + PathService::Override(DIR_APP_LOGS, base::FilePath(libPathString)); +} + // Replicates NSApplicationMain, but doesn't start a run loop. void BrowserMainParts::InitializeMainNib() { auto infoDictionary = base::mac::OuterBundle().infoDictionary; From f026bbb454e5d46b0e1c1c24001ff8211e1fc68d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 Aug 2017 13:22:10 -0700 Subject: [PATCH 02/17] add first go at linux log path override --- brightray/browser/browser_main_parts.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index a949a236f3a0..18ddb2f771ae 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -89,6 +89,18 @@ void OverrideLinuxAppDataPath() { PathService::Override(DIR_APP_DATA, path); } +// void OverrideWinAppLogsPath() { +// base::FilePath path; +// // should be in c:\program files\myapp\logs ? +// PathService::Override(DIR_APP_DATA, path); +// } + +void OverrideLinuxAppLogsPath() { + std::string appName = GetExecutableFileProductName(); + std::string logPath = '/var/log' + appName + PathService::Override(DIR_APP_DATA, base::FilePath(logPath)); +} + int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { if (!g_in_x11_io_error_handler) { base::ThreadTaskRunnerHandle::Get()->PostTask( @@ -165,6 +177,12 @@ void BrowserMainParts::PreEarlyInitialization() { #if defined(OS_MACOSX) OverrideMacAppLogsPath(); #endif +#if defined(OS_LINUX) + OverrideLinuxAppLogsPath(); +#endif +// #if defined(OS_WIN) +// OverrideWinAppLogsPath(); +// #endif #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); From 3de008035ad7821106716bc39802a81a1a441b1f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 Aug 2017 13:54:15 -0700 Subject: [PATCH 03/17] appeasing the linter --- brightray/browser/browser_main_parts.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 18ddb2f771ae..47a0e9df1e3b 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -11,6 +11,7 @@ #include "brightray/browser/browser_context.h" #include "brightray/browser/devtools_manager_delegate.h" #include "brightray/browser/web_ui_controller_factory.h" +#include "brightray/common/application_info.h" #include "brightray/common/main_delegate.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" @@ -96,9 +97,12 @@ void OverrideLinuxAppDataPath() { // } void OverrideLinuxAppLogsPath() { - std::string appName = GetExecutableFileProductName(); - std::string logPath = '/var/log' + appName - PathService::Override(DIR_APP_DATA, base::FilePath(logPath)); + std::string appName = GetApplicationName(); + std::string logPath = "/var/log" + + std::string appLogPath = logPath + appName + + PathService::Override(DIR_APP_DATA, base::FilePath(appLogPath)); } int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { From e096b5ce83c6d3de207b2c5c0e0a6676b6934462 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 Aug 2017 14:04:13 -0700 Subject: [PATCH 04/17] fix override path --- brightray/browser/browser_main_parts.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 47a0e9df1e3b..9bf2e104a949 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -98,11 +98,11 @@ void OverrideLinuxAppDataPath() { void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); - std::string logPath = "/var/log" + std::string logPath = "/var/log"; - std::string appLogPath = logPath + appName + std::string appLogPath = logPath + appName; - PathService::Override(DIR_APP_DATA, base::FilePath(appLogPath)); + PathService::Override(DIR_APP_LOGS base::FilePath(appLogPath)); } int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { From e81cf74b39bd208ee3442e3259a50db6acbb2f0c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 8 Aug 2017 10:17:03 -0700 Subject: [PATCH 05/17] add windows override path and cleanup linux --- brightray/browser/browser_main_parts.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 9bf2e104a949..dc210fca09a0 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,6 +4,8 @@ #include "brightray/browser/browser_main_parts.h" +#include + #include "base/command_line.h" #include "base/feature_list.h" #include "base/strings/string_number_conversions.h" @@ -90,19 +92,21 @@ void OverrideLinuxAppDataPath() { PathService::Override(DIR_APP_DATA, path); } -// void OverrideWinAppLogsPath() { -// base::FilePath path; -// // should be in c:\program files\myapp\logs ? -// PathService::Override(DIR_APP_DATA, path); -// } +void OverrideWinAppLogsPath() { + std::string appName = GetApplicationName(); + std::string logPath = "%systemdrive%%homepath%\AppData\Roaming\\"; + std::string appLogPath = logPath + appName + "\logs"; + + PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); +} void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); - std::string logPath = "/var/log"; + std::string logPath = "/var/log/"; std::string appLogPath = logPath + appName; - PathService::Override(DIR_APP_LOGS base::FilePath(appLogPath)); + PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); } int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { @@ -184,9 +188,9 @@ void BrowserMainParts::PreEarlyInitialization() { #if defined(OS_LINUX) OverrideLinuxAppLogsPath(); #endif -// #if defined(OS_WIN) -// OverrideWinAppLogsPath(); -// #endif +#if defined(OS_WIN) + OverrideWinAppLogsPath(); +#endif #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); From 2353fdb4000606452d2bd149ae03f38108faeebe Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 9 Aug 2017 08:55:46 -0700 Subject: [PATCH 06/17] add dir creation if none exists --- brightray/browser/browser_main_parts.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index dc210fca09a0..c7ed4c6752aa 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,6 +4,7 @@ #include "brightray/browser/browser_main_parts.h" +#include #include #include "base/command_line.h" @@ -58,6 +59,7 @@ namespace brightray { +// defined in browser_main_parts_mac void OverrideMacAppLogsPath(); namespace { @@ -94,17 +96,20 @@ void OverrideLinuxAppDataPath() { void OverrideWinAppLogsPath() { std::string appName = GetApplicationName(); - std::string logPath = "%systemdrive%%homepath%\AppData\Roaming\\"; + std::string logPath = "%HOMEDRIVE%%HOMEPATH%\AppData\Roaming\\"; std::string appLogPath = logPath + appName + "\logs"; + int status = mkdir(appLogPath, S_IRWXU | S_IRGRP | S_IROTH); + PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); } void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); - std::string logPath = "/var/log/"; + char* homePath = getenv("HOME"); + std::string appLogPath = homePath + "/.config/" + appName; - std::string appLogPath = logPath + appName; + int status = mkdir(appLogPath, S_IRWXU | S_IRGRP | S_IROTH); PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); } @@ -130,7 +135,7 @@ int BrowserX11IOErrorHandler(Display* d) { // Wait for the UI thread (which has a different connection to the X server) // to get the error. We can't call shutdown from this thread without // tripping an error. Doing it through a function so that we'll be able - // to see it in any crash dumps. + // to see it in any crash dumps.back WaitingForUIThreadToHandleIOError(); return 0; } From c1c8f7b0f1b0df84bf3c02e839c38804a04e19f3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 9 Aug 2017 10:33:27 -0700 Subject: [PATCH 07/17] fix string concat errors --- brightray/browser/browser_main_parts.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index c7ed4c6752aa..b3c25342916a 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -6,6 +6,7 @@ #include #include +#include #include "base/command_line.h" #include "base/feature_list.h" @@ -99,7 +100,7 @@ void OverrideWinAppLogsPath() { std::string logPath = "%HOMEDRIVE%%HOMEPATH%\AppData\Roaming\\"; std::string appLogPath = logPath + appName + "\logs"; - int status = mkdir(appLogPath, S_IRWXU | S_IRGRP | S_IROTH); + int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); } @@ -107,9 +108,9 @@ void OverrideWinAppLogsPath() { void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); char* homePath = getenv("HOME"); - std::string appLogPath = homePath + "/.config/" + appName; + std::string appLogPath = std:string(homePath) + "/.config/" + appName + "/logs"; - int status = mkdir(appLogPath, S_IRWXU | S_IRGRP | S_IROTH); + int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); } From d2d4b4cc23dbb74614577ba890826d4bad784dda Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 9 Aug 2017 16:40:19 -0700 Subject: [PATCH 08/17] fix escape backslashes --- 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 b3c25342916a..580c56611574 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -97,8 +97,8 @@ void OverrideLinuxAppDataPath() { void OverrideWinAppLogsPath() { std::string appName = GetApplicationName(); - std::string logPath = "%HOMEDRIVE%%HOMEPATH%\AppData\Roaming\\"; - std::string appLogPath = logPath + appName + "\logs"; + std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::string appLogPath = logPath + appName + "\\logs"; int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); @@ -113,6 +113,7 @@ void OverrideLinuxAppLogsPath() { int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); + return; } int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { From e05f6102c227460a5f035ac104a2b9eb42c1f5c2 Mon Sep 17 00:00:00 2001 From: Shelley Date: Sat, 12 Aug 2017 00:09:41 -0700 Subject: [PATCH 09/17] update docs for new getPath() path --- docs/api/app.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api/app.md b/docs/api/app.md index b3f4126c9763..6c8bdd1be8c5 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -458,6 +458,7 @@ You can request the following paths by the name: * `music` Directory for a user's music. * `pictures` Directory for a user's pictures. * `videos` Directory for a user's videos. +* `logs` Directory for your app's log folder. * `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin. ### `app.getFileIcon(path[, options], callback)` From fc443a8c2c5f3d7ce0353de90fb6ae9b45571afa Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 14 Aug 2017 08:47:37 -0700 Subject: [PATCH 10/17] fix header and line length lint errors --- brightray/browser/browser_main_parts.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 580c56611574..611db9452617 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -5,8 +5,8 @@ #include "brightray/browser/browser_main_parts.h" #include -#include #include +#include #include "base/command_line.h" #include "base/feature_list.h" @@ -107,8 +107,8 @@ void OverrideWinAppLogsPath() { void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); - char* homePath = getenv("HOME"); - std::string appLogPath = std:string(homePath) + "/.config/" + appName + "/logs"; + std::string homePath = std:string(getenv("HOME")); + std::string appLogPath = homePath + "/.config/" + appName + "/logs"; int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); From 94f46c9059dbb01c77709e45359a3c726663d44a Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Sun, 24 Sep 2017 10:44:08 +0900 Subject: [PATCH 11/17] fix typo in comment --- brightray/browser/browser_main_parts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 611db9452617..4a98e6ee3988 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -137,7 +137,7 @@ int BrowserX11IOErrorHandler(Display* d) { // Wait for the UI thread (which has a different connection to the X server) // to get the error. We can't call shutdown from this thread without // tripping an error. Doing it through a function so that we'll be able - // to see it in any crash dumps.back + // to see it in any crash dumps. WaitingForUIThreadToHandleIOError(); return 0; } From 223942bf990d7b2aaaefa46f6efc2a8a4e7aad15 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sat, 23 Sep 2017 22:55:52 -0400 Subject: [PATCH 12/17] fix incorrect std namespacing --- brightray/browser/browser_main_parts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 4a98e6ee3988..e45da0f324d3 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -107,7 +107,7 @@ void OverrideWinAppLogsPath() { void OverrideLinuxAppLogsPath() { std::string appName = GetApplicationName(); - std::string homePath = std:string(getenv("HOME")); + std::string homePath = std::string(getenv("HOME")); std::string appLogPath = homePath + "/.config/" + appName + "/logs"; int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); From 911e266e9a0ed30218a25c96e312a6bfd8f02325 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sun, 24 Sep 2017 14:16:18 -0400 Subject: [PATCH 13/17] add function signature declaration --- brightray/browser/browser_main_parts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index e45da0f324d3..a05a4f3ab3ee 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -60,8 +60,8 @@ namespace brightray { -// defined in browser_main_parts_mac void OverrideMacAppLogsPath(); +void OverrideWinAppLogsPath(); namespace { From 0dfadf7c099bf09abac0719e6272ae9912fa7771 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 26 Sep 2017 23:28:36 -0400 Subject: [PATCH 14/17] remove unresolved external symbol --- brightray/browser/browser_main_parts.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index a05a4f3ab3ee..e939eda1db38 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -61,7 +61,6 @@ namespace brightray { void OverrideMacAppLogsPath(); -void OverrideWinAppLogsPath(); namespace { From c620d0de05832d1723ccc195432ab4f7e5331bf8 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 28 Sep 2017 23:03:01 -0400 Subject: [PATCH 15/17] move overrides into the appropriate namespace --- brightray/browser/browser_main_parts.cc | 43 +++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index e939eda1db38..8e7e684032d5 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -94,27 +94,6 @@ void OverrideLinuxAppDataPath() { PathService::Override(DIR_APP_DATA, path); } -void OverrideWinAppLogsPath() { - std::string appName = GetApplicationName(); - std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; - std::string appLogPath = logPath + appName + "\\logs"; - - int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); - - PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); -} - -void OverrideLinuxAppLogsPath() { - std::string appName = GetApplicationName(); - std::string homePath = std::string(getenv("HOME")); - std::string appLogPath = homePath + "/.config/" + appName + "/logs"; - - int status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); - - PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); - return; -} - int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { if (!g_in_x11_io_error_handler) { base::ThreadTaskRunnerHandle::Get()->PostTask( @@ -184,6 +163,28 @@ BrowserMainParts::BrowserMainParts() { BrowserMainParts::~BrowserMainParts() { } +void OverrideWinAppLogsPath() { + int status; + std::string appName = GetApplicationName(); + std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::string appLogPath = logPath + appName + "\\logs"; + + status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); + + PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); +} + +void OverrideLinuxAppLogsPath() { + int status; + std::string appName = GetApplicationName(); + std::string homePath = std::string(getenv("HOME")); + std::string appLogPath = homePath + "/.config/" + appName + "/logs"; + + status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); + + PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); +} + void BrowserMainParts::PreEarlyInitialization() { std::unique_ptr feature_list(new base::FeatureList); feature_list->InitializeFromCommandLine("", ""); From e7bb553d3b041e175a6effd160702daf8c0eef0a Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 29 Sep 2017 09:32:30 -0400 Subject: [PATCH 16/17] consolidate code and rename for clarity --- brightray/browser/browser_main_parts.cc | 48 ++++++++------------- brightray/browser/browser_main_parts.h | 1 + brightray/browser/browser_main_parts_mac.mm | 6 +-- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 8e7e684032d5..d752430fe69f 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,7 +4,10 @@ #include "brightray/browser/browser_main_parts.h" +#if defined(OSX_POSIX) #include +#endif + #include #include @@ -60,8 +63,6 @@ namespace brightray { -void OverrideMacAppLogsPath(); - namespace { #if defined(OS_WIN) @@ -163,41 +164,26 @@ BrowserMainParts::BrowserMainParts() { BrowserMainParts::~BrowserMainParts() { } -void OverrideWinAppLogsPath() { - int status; - std::string appName = GetApplicationName(); - std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; - std::string appLogPath = logPath + appName + "\\logs"; - - status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); - - PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); -} - -void OverrideLinuxAppLogsPath() { - int status; - std::string appName = GetApplicationName(); - std::string homePath = std::string(getenv("HOME")); - std::string appLogPath = homePath + "/.config/" + appName + "/logs"; - - status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); - - PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); +#if defined(OS_WIN) || defined(OS_LINUX) +void OverrideAppLogsPath() { +#if defined(OS_WIN) + std::string app_name = GetApplicationName(); + std::string log_path = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::string app_log_path = log_path + app_name + "\\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"; +#endif + PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path)); } +#endif void BrowserMainParts::PreEarlyInitialization() { std::unique_ptr feature_list(new base::FeatureList); feature_list->InitializeFromCommandLine("", ""); base::FeatureList::SetInstance(std::move(feature_list)); -#if defined(OS_MACOSX) - OverrideMacAppLogsPath(); -#endif -#if defined(OS_LINUX) - OverrideLinuxAppLogsPath(); -#endif -#if defined(OS_WIN) - OverrideWinAppLogsPath(); -#endif + OverrideAppLogsPath(); #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 53d3cf38b720..45c69f15fb07 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -47,6 +47,7 @@ class BrowserMainParts : public content::BrowserMainParts { private: #if defined(OS_MACOSX) void InitializeMainNib(); + void OverrideAppLogsPath(); #endif #if defined(TOOLKIT_VIEWS) diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 2e111caafc0e..ebcb48ed6461 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -6,16 +6,14 @@ namespace brightray { -void OverrideMacAppLogsPath() { +void BrowserMainParts::OverrideAppLogsPath() { base::FilePath path; NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName]; - NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; - std::string libPathString = std::string([libraryPath UTF8String]); - PathService::Override(DIR_APP_LOGS, base::FilePath(libPathString)); + PathService::Override(DIR_APP_LOGS, base::FilePath([libraryPath UTF8String])); } // Replicates NSApplicationMain, but doesn't start a run loop. From 96f1a25bbd7abfac91f69f9e92c3e142ad6ffb53 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 29 Sep 2017 10:29:45 -0400 Subject: [PATCH 17/17] convert to wstring for windows --- brightray/browser/browser_main_parts.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index d752430fe69f..e5406e519a67 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -167,9 +167,9 @@ BrowserMainParts::~BrowserMainParts() { #if defined(OS_WIN) || defined(OS_LINUX) void OverrideAppLogsPath() { #if defined(OS_WIN) - std::string app_name = GetApplicationName(); - std::string log_path = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; - std::string app_log_path = log_path + app_name + "\\logs"; + std::wstring app_name = base::UTF8ToWide(GetApplicationName()); + std::wstring log_path = L"%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; + std::wstring app_log_path = log_path + app_name + L"\\logs"; #else std::string app_name = GetApplicationName(); std::string home_path = std::string(getenv("HOME"));