consolidate code and rename for clarity

This commit is contained in:
Shelley Vohr 2017-09-29 09:32:30 -04:00
parent c620d0de05
commit e7bb553d3b
No known key found for this signature in database
GPG key ID: F13993A75599653C
3 changed files with 20 additions and 35 deletions

View file

@ -4,7 +4,10 @@
#include "brightray/browser/browser_main_parts.h" #include "brightray/browser/browser_main_parts.h"
#if defined(OSX_POSIX)
#include <stdlib.h> #include <stdlib.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <string> #include <string>
@ -60,8 +63,6 @@
namespace brightray { namespace brightray {
void OverrideMacAppLogsPath();
namespace { namespace {
#if defined(OS_WIN) #if defined(OS_WIN)
@ -163,41 +164,26 @@ BrowserMainParts::BrowserMainParts() {
BrowserMainParts::~BrowserMainParts() { BrowserMainParts::~BrowserMainParts() {
} }
void OverrideWinAppLogsPath() { #if defined(OS_WIN) || defined(OS_LINUX)
int status; void OverrideAppLogsPath() {
std::string appName = GetApplicationName(); #if defined(OS_WIN)
std::string logPath = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\"; std::string app_name = GetApplicationName();
std::string appLogPath = logPath + appName + "\\logs"; std::string log_path = "%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\";
std::string app_log_path = log_path + app_name + "\\logs";
status = mkdir(appLogPath.c_str(), S_IRWXU | S_IRGRP | S_IROTH); #else
std::string app_name = GetApplicationName();
PathService::Override(DIR_APP_LOGS, base::FilePath(appLogPath)); std::string home_path = std::string(getenv("HOME"));
} std::string app_log_path = home_path + "/.config/" + app_name + "/logs";
#endif
void OverrideLinuxAppLogsPath() { PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path));
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));
} }
#endif
void BrowserMainParts::PreEarlyInitialization() { void BrowserMainParts::PreEarlyInitialization() {
std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
feature_list->InitializeFromCommandLine("", ""); feature_list->InitializeFromCommandLine("", "");
base::FeatureList::SetInstance(std::move(feature_list)); base::FeatureList::SetInstance(std::move(feature_list));
#if defined(OS_MACOSX) OverrideAppLogsPath();
OverrideMacAppLogsPath();
#endif
#if defined(OS_LINUX)
OverrideLinuxAppLogsPath();
#endif
#if defined(OS_WIN)
OverrideWinAppLogsPath();
#endif
#if defined(USE_X11) #if defined(USE_X11)
views::LinuxUI::SetInstance(BuildGtkUi()); views::LinuxUI::SetInstance(BuildGtkUi());
OverrideLinuxAppDataPath(); OverrideLinuxAppDataPath();

View file

@ -47,6 +47,7 @@ class BrowserMainParts : public content::BrowserMainParts {
private: private:
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
void InitializeMainNib(); void InitializeMainNib();
void OverrideAppLogsPath();
#endif #endif
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)

View file

@ -6,16 +6,14 @@
namespace brightray { namespace brightray {
void OverrideMacAppLogsPath() { void BrowserMainParts::OverrideAppLogsPath() {
base::FilePath path; base::FilePath path;
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] NSString* bundleName = [[[NSBundle mainBundle] infoDictionary]
objectForKey:@"CFBundleName"]; objectForKey:@"CFBundleName"];
NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName]; NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName];
NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; 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. // Replicates NSApplicationMain, but doesn't start a run loop.