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