mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-03 00:38:58 +00:00
Fix log destination again on macOS
This commit is contained in:
@@ -651,7 +651,7 @@ static const std::string& GetHomeDirectory() {
|
|||||||
* @return The directory path
|
* @return The directory path
|
||||||
* @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
* @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
*/
|
*/
|
||||||
static const std::string GetUserDirectory(const std::string& envvar) {
|
std::string GetXDGDirectory(const std::string& envvar) {
|
||||||
const char* directory = getenv(envvar.c_str());
|
const char* directory = getenv(envvar.c_str());
|
||||||
|
|
||||||
std::string user_dir;
|
std::string user_dir;
|
||||||
@@ -715,7 +715,7 @@ UserPathType GetUserPathType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool normal_exists =
|
const bool normal_exists =
|
||||||
FileUtil::Exists(GetUserDirectory("XDG_DATA_HOME") + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
FileUtil::Exists(GetXDGDirectory("XDG_DATA_HOME") + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
||||||
const bool flatpak_exists = FileUtil::Exists(
|
const bool flatpak_exists = FileUtil::Exists(
|
||||||
GetHomeDirectory() + "/.var/app/org.citra_emu.citra/data" + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
GetHomeDirectory() + "/.var/app/org.citra_emu.citra/data" + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
||||||
if (!normal_exists || flatpak_exists) { // Flatpak takes precedence
|
if (!normal_exists || flatpak_exists) { // Flatpak takes precedence
|
||||||
@@ -785,9 +785,9 @@ void SetUserPath(const std::string& path) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UserPathType::Normal: {
|
case UserPathType::Normal: {
|
||||||
std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
|
std::string data_dir = GetXDGDirectory("XDG_DATA_HOME");
|
||||||
std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
|
std::string config_dir = GetXDGDirectory("XDG_CONFIG_HOME");
|
||||||
std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME");
|
std::string cache_dir = GetXDGDirectory("XDG_CACHE_HOME");
|
||||||
|
|
||||||
user_path = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
user_path = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
||||||
g_paths.emplace(UserPath::ConfigDir, config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
g_paths.emplace(UserPath::ConfigDir, config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
||||||
|
|||||||
@@ -157,6 +157,8 @@ std::string GetBundleDirectory();
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
const std::string& GetExeDirectory();
|
const std::string& GetExeDirectory();
|
||||||
std::string AppDataRoamingDirectory();
|
std::string AppDataRoamingDirectory();
|
||||||
|
#else
|
||||||
|
std::string GetXDGDirectory(const std::string& envvar);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
|
std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
|
||||||
|
|||||||
@@ -22,14 +22,16 @@ std::uint64_t GetLoggingTime() {
|
|||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FileUtil::IOFile g_log_file;
|
||||||
|
void InitializeLogging() {
|
||||||
#ifdef __WIN32
|
#ifdef __WIN32
|
||||||
// _SH_DENYWR allows read-only access for other programs.
|
g_log_file.Open(FileUtil::GetExeDirectory() + DIR_SEP LOG_FILE, "w", _SH_DENYWR);
|
||||||
static FileUtil::IOFile g_log_file{FileUtil::GetExeDirectory() + DIR_SEP LOG_FILE, "w", _SH_DENYWR};
|
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
static FileUtil::IOFile g_log_file{FileUtil::GetBundleDirectory() + "/../" LOG_FILE, "w"};
|
g_log_file.Open(FileUtil::GetXDGDirectory("XDG_DATA_HOME") + DIR_SEP LOG_FILE, "w");
|
||||||
#else
|
#else
|
||||||
static FileUtil::IOFile g_log_file{ROOT_DIR DIR_SEP LOG_FILE, "w"};
|
g_log_file.Open(ROOT_DIR DIR_SEP LOG_FILE, "w");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static std::array<Entry, 3> g_error_buffer{};
|
static std::array<Entry, 3> g_error_buffer{};
|
||||||
static int g_error_buffer_pos = 0;
|
static int g_error_buffer_pos = 0;
|
||||||
@@ -39,9 +41,11 @@ void WriteLog(Entry entry) {
|
|||||||
fmt::print(stderr, entry.style, entry.message);
|
fmt::print(stderr, entry.style, entry.message);
|
||||||
|
|
||||||
// log file
|
// log file
|
||||||
g_log_file.WriteString(entry.message);
|
if (g_log_file.IsOpen()) {
|
||||||
if (entry.level >= Level::Error) {
|
g_log_file.WriteString(entry.message);
|
||||||
g_log_file.Flush(); // Do not flush the file too often
|
if (entry.level >= Level::Error) {
|
||||||
|
g_log_file.Flush(); // Do not flush the file too often
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// log buffer
|
// log buffer
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ struct Entry {
|
|||||||
std::string message;
|
std::string message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void InitializeLogging();
|
||||||
void WriteLog(Entry entry);
|
void WriteLog(Entry entry);
|
||||||
|
|
||||||
// Returns up to 3 latest error messages
|
// Returns up to 3 latest error messages
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ bool SeedDB::AddFromFile(const std::string& path) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
u32_le count;
|
u32_le count;
|
||||||
if (!file.ReadBytes(&count, sizeof(count))) {
|
if (file.ReadBytes(&count, sizeof(count)) != sizeof(count)) {
|
||||||
LOG_ERROR(Service_FS, "Failed to read seed database count fully");
|
LOG_ERROR(Service_FS, "Failed to read seed database count fully");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ bool SeedDB::Save(const std::string& path) const {
|
|||||||
LOG_ERROR(Service_FS, "Failed to open seed database");
|
LOG_ERROR(Service_FS, "Failed to open seed database");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
u32 count{static_cast<u32>(seeds.size())};
|
u32_le count{static_cast<u32>(seeds.size())};
|
||||||
if (file.WriteBytes(&count, sizeof(count)) != sizeof(count)) {
|
if (file.WriteBytes(&count, sizeof(count)) != sizeof(count)) {
|
||||||
LOG_ERROR(Service_FS, "Failed to write seed database count fully");
|
LOG_ERROR(Service_FS, "Failed to write seed database count fully");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -251,6 +251,8 @@ int main(int argc, char* argv[]) {
|
|||||||
QCoreApplication::setOrganizationName(QStringLiteral("zhaowenlan1779"));
|
QCoreApplication::setOrganizationName(QStringLiteral("zhaowenlan1779"));
|
||||||
QCoreApplication::setApplicationName(QStringLiteral("threeSD"));
|
QCoreApplication::setApplicationName(QStringLiteral("threeSD"));
|
||||||
|
|
||||||
|
Common::Logging::InitializeLogging();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
|
std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
|
||||||
chdir(bin_path.c_str());
|
chdir(bin_path.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user