diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/fs/fs.cpp | 27 | ||||
| -rw-r--r-- | src/common/fs/fs_android.h | 5 | ||||
| -rw-r--r-- | src/common/fs/fs_paths.h | 1 | ||||
| -rw-r--r-- | src/common/fs/path_util.cpp | 1 | ||||
| -rw-r--r-- | src/common/fs/path_util.h | 1 | ||||
| -rw-r--r-- | src/common/settings.cpp | 32 | ||||
| -rw-r--r-- | src/common/settings.h | 2 | ||||
| -rw-r--r-- | src/common/time_zone.cpp | 63 | ||||
| -rw-r--r-- | src/common/time_zone.h | 6 | ||||
| -rw-r--r-- | src/common/uuid.cpp | 2 |
10 files changed, 123 insertions, 17 deletions
diff --git a/src/common/fs/fs.cpp b/src/common/fs/fs.cpp index e1716c62d..6d66c926d 100644 --- a/src/common/fs/fs.cpp +++ b/src/common/fs/fs.cpp | |||
| @@ -3,6 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | #include "common/fs/file.h" | 4 | #include "common/fs/file.h" |
| 5 | #include "common/fs/fs.h" | 5 | #include "common/fs/fs.h" |
| 6 | #ifdef ANDROID | ||
| 7 | #include "common/fs/fs_android.h" | ||
| 8 | #endif | ||
| 6 | #include "common/fs/path_util.h" | 9 | #include "common/fs/path_util.h" |
| 7 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 8 | 11 | ||
| @@ -525,15 +528,39 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path, | |||
| 525 | // Generic Filesystem Operations | 528 | // Generic Filesystem Operations |
| 526 | 529 | ||
| 527 | bool Exists(const fs::path& path) { | 530 | bool Exists(const fs::path& path) { |
| 531 | #ifdef ANDROID | ||
| 532 | if (Android::IsContentUri(path)) { | ||
| 533 | return Android::Exists(path); | ||
| 534 | } else { | ||
| 535 | return fs::exists(path); | ||
| 536 | } | ||
| 537 | #else | ||
| 528 | return fs::exists(path); | 538 | return fs::exists(path); |
| 539 | #endif | ||
| 529 | } | 540 | } |
| 530 | 541 | ||
| 531 | bool IsFile(const fs::path& path) { | 542 | bool IsFile(const fs::path& path) { |
| 543 | #ifdef ANDROID | ||
| 544 | if (Android::IsContentUri(path)) { | ||
| 545 | return !Android::IsDirectory(path); | ||
| 546 | } else { | ||
| 547 | return fs::is_regular_file(path); | ||
| 548 | } | ||
| 549 | #else | ||
| 532 | return fs::is_regular_file(path); | 550 | return fs::is_regular_file(path); |
| 551 | #endif | ||
| 533 | } | 552 | } |
| 534 | 553 | ||
| 535 | bool IsDir(const fs::path& path) { | 554 | bool IsDir(const fs::path& path) { |
| 555 | #ifdef ANDROID | ||
| 556 | if (Android::IsContentUri(path)) { | ||
| 557 | return Android::IsDirectory(path); | ||
| 558 | } else { | ||
| 559 | return fs::is_directory(path); | ||
| 560 | } | ||
| 561 | #else | ||
| 536 | return fs::is_directory(path); | 562 | return fs::is_directory(path); |
| 563 | #endif | ||
| 537 | } | 564 | } |
| 538 | 565 | ||
| 539 | fs::path GetCurrentDir() { | 566 | fs::path GetCurrentDir() { |
diff --git a/src/common/fs/fs_android.h b/src/common/fs/fs_android.h index bb8a52648..b441c2a12 100644 --- a/src/common/fs/fs_android.h +++ b/src/common/fs/fs_android.h | |||
| @@ -12,7 +12,10 @@ | |||
| 12 | "openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I") | 12 | "openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I") |
| 13 | 13 | ||
| 14 | #define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \ | 14 | #define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \ |
| 15 | V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") | 15 | V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") \ |
| 16 | V(IsDirectory, bool, is_directory, CallStaticBooleanMethod, "isDirectory", \ | ||
| 17 | "(Ljava/lang/String;)Z") \ | ||
| 18 | V(Exists, bool, file_exists, CallStaticBooleanMethod, "exists", "(Ljava/lang/String;)Z") | ||
| 16 | 19 | ||
| 17 | namespace Common::FS::Android { | 20 | namespace Common::FS::Android { |
| 18 | 21 | ||
diff --git a/src/common/fs/fs_paths.h b/src/common/fs/fs_paths.h index c77c112f1..61bac9eba 100644 --- a/src/common/fs/fs_paths.h +++ b/src/common/fs/fs_paths.h | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | // Sub-directories contained within a yuzu data directory | 11 | // Sub-directories contained within a yuzu data directory |
| 12 | 12 | ||
| 13 | #define AMIIBO_DIR "amiibo" | ||
| 13 | #define CACHE_DIR "cache" | 14 | #define CACHE_DIR "cache" |
| 14 | #define CONFIG_DIR "config" | 15 | #define CONFIG_DIR "config" |
| 15 | #define DUMP_DIR "dump" | 16 | #define DUMP_DIR "dump" |
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index e026a13d9..d71cfacc6 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp | |||
| @@ -114,6 +114,7 @@ public: | |||
| 114 | #endif | 114 | #endif |
| 115 | 115 | ||
| 116 | GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path); | 116 | GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path); |
| 117 | GenerateYuzuPath(YuzuPath::AmiiboDir, yuzu_path / AMIIBO_DIR); | ||
| 117 | GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path_cache); | 118 | GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path_cache); |
| 118 | GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path_config); | 119 | GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path_config); |
| 119 | GenerateYuzuPath(YuzuPath::DumpDir, yuzu_path / DUMP_DIR); | 120 | GenerateYuzuPath(YuzuPath::DumpDir, yuzu_path / DUMP_DIR); |
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h index 7cfe85b70..ba28964d0 100644 --- a/src/common/fs/path_util.h +++ b/src/common/fs/path_util.h | |||
| @@ -12,6 +12,7 @@ namespace Common::FS { | |||
| 12 | 12 | ||
| 13 | enum class YuzuPath { | 13 | enum class YuzuPath { |
| 14 | YuzuDir, // Where yuzu stores its data. | 14 | YuzuDir, // Where yuzu stores its data. |
| 15 | AmiiboDir, // Where Amiibo backups are stored. | ||
| 15 | CacheDir, // Where cached filesystem data is stored. | 16 | CacheDir, // Where cached filesystem data is stored. |
| 16 | ConfigDir, // Where config files are stored. | 17 | ConfigDir, // Where config files are stored. |
| 17 | DumpDir, // Where dumped data is stored. | 18 | DumpDir, // Where dumped data is stored. |
diff --git a/src/common/settings.cpp b/src/common/settings.cpp index ff53e80bb..66dffc9bf 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp | |||
| @@ -1,12 +1,16 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #if __cpp_lib_chrono >= 201907L | ||
| 5 | #include <chrono> | ||
| 6 | #endif | ||
| 4 | #include <string_view> | 7 | #include <string_view> |
| 5 | 8 | ||
| 6 | #include "common/assert.h" | 9 | #include "common/assert.h" |
| 7 | #include "common/fs/path_util.h" | 10 | #include "common/fs/path_util.h" |
| 8 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 9 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| 13 | #include "common/time_zone.h" | ||
| 10 | 14 | ||
| 11 | namespace Settings { | 15 | namespace Settings { |
| 12 | 16 | ||
| @@ -14,18 +18,23 @@ Values values; | |||
| 14 | static bool configuring_global = true; | 18 | static bool configuring_global = true; |
| 15 | 19 | ||
| 16 | std::string GetTimeZoneString() { | 20 | std::string GetTimeZoneString() { |
| 17 | static constexpr std::array timezones{ | ||
| 18 | "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire", | ||
| 19 | "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0", | ||
| 20 | "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan", | ||
| 21 | "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT", | ||
| 22 | "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey", | ||
| 23 | "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu", | ||
| 24 | }; | ||
| 25 | |||
| 26 | const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue()); | 21 | const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue()); |
| 27 | ASSERT(time_zone_index < timezones.size()); | 22 | ASSERT(time_zone_index < Common::TimeZone::GetTimeZoneStrings().size()); |
| 28 | return timezones[time_zone_index]; | 23 | |
| 24 | std::string location_name; | ||
| 25 | if (time_zone_index == 0) { // Auto | ||
| 26 | #if __cpp_lib_chrono >= 201907L | ||
| 27 | const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb(); | ||
| 28 | const std::chrono::time_zone* current_zone = time_zone_data.current_zone(); | ||
| 29 | std::string_view current_zone_name = current_zone->name(); | ||
| 30 | location_name = current_zone_name; | ||
| 31 | #else | ||
| 32 | location_name = Common::TimeZone::FindSystemTimeZone(); | ||
| 33 | #endif | ||
| 34 | } else { | ||
| 35 | location_name = Common::TimeZone::GetTimeZoneStrings()[time_zone_index]; | ||
| 36 | } | ||
| 37 | return location_name; | ||
| 29 | } | 38 | } |
| 30 | 39 | ||
| 31 | void LogSettings() { | 40 | void LogSettings() { |
| @@ -235,6 +244,7 @@ void RestoreGlobalState(bool is_powered_on) { | |||
| 235 | values.bg_green.SetGlobal(true); | 244 | values.bg_green.SetGlobal(true); |
| 236 | values.bg_blue.SetGlobal(true); | 245 | values.bg_blue.SetGlobal(true); |
| 237 | values.enable_compute_pipelines.SetGlobal(true); | 246 | values.enable_compute_pipelines.SetGlobal(true); |
| 247 | values.use_video_framerate.SetGlobal(true); | ||
| 238 | 248 | ||
| 239 | // System | 249 | // System |
| 240 | values.language_index.SetGlobal(true); | 250 | values.language_index.SetGlobal(true); |
diff --git a/src/common/settings.h b/src/common/settings.h index 7f865b2a7..3aedf3850 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -482,6 +482,8 @@ struct Values { | |||
| 482 | SwitchableSetting<AstcRecompression, true> astc_recompression{ | 482 | SwitchableSetting<AstcRecompression, true> astc_recompression{ |
| 483 | AstcRecompression::Uncompressed, AstcRecompression::Uncompressed, AstcRecompression::Bc3, | 483 | AstcRecompression::Uncompressed, AstcRecompression::Uncompressed, AstcRecompression::Bc3, |
| 484 | "astc_recompression"}; | 484 | "astc_recompression"}; |
| 485 | SwitchableSetting<bool> use_video_framerate{false, "use_video_framerate"}; | ||
| 486 | SwitchableSetting<bool> barrier_feedback_loops{true, "barrier_feedback_loops"}; | ||
| 485 | 487 | ||
| 486 | SwitchableSetting<u8> bg_red{0, "bg_red"}; | 488 | SwitchableSetting<u8> bg_red{0, "bg_red"}; |
| 487 | SwitchableSetting<u8> bg_green{0, "bg_green"}; | 489 | SwitchableSetting<u8> bg_green{0, "bg_green"}; |
diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp index 126836b01..d8d7896c6 100644 --- a/src/common/time_zone.cpp +++ b/src/common/time_zone.cpp | |||
| @@ -2,14 +2,33 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <chrono> | 4 | #include <chrono> |
| 5 | #include <exception> | ||
| 5 | #include <iomanip> | 6 | #include <iomanip> |
| 6 | #include <sstream> | 7 | #include <sstream> |
| 8 | #include <stdexcept> | ||
| 9 | #include <fmt/chrono.h> | ||
| 10 | #include <fmt/core.h> | ||
| 7 | 11 | ||
| 8 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 13 | #include "common/settings.h" | ||
| 9 | #include "common/time_zone.h" | 14 | #include "common/time_zone.h" |
| 10 | 15 | ||
| 11 | namespace Common::TimeZone { | 16 | namespace Common::TimeZone { |
| 12 | 17 | ||
| 18 | // Time zone strings | ||
| 19 | constexpr std::array timezones{ | ||
| 20 | "GMT", "GMT", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire", | ||
| 21 | "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0", | ||
| 22 | "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan", | ||
| 23 | "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT", | ||
| 24 | "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey", | ||
| 25 | "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu", | ||
| 26 | }; | ||
| 27 | |||
| 28 | const std::array<const char*, 46>& GetTimeZoneStrings() { | ||
| 29 | return timezones; | ||
| 30 | } | ||
| 31 | |||
| 13 | std::string GetDefaultTimeZone() { | 32 | std::string GetDefaultTimeZone() { |
| 14 | return "GMT"; | 33 | return "GMT"; |
| 15 | } | 34 | } |
| @@ -18,10 +37,7 @@ static std::string GetOsTimeZoneOffset() { | |||
| 18 | const std::time_t t{std::time(nullptr)}; | 37 | const std::time_t t{std::time(nullptr)}; |
| 19 | const std::tm tm{*std::localtime(&t)}; | 38 | const std::tm tm{*std::localtime(&t)}; |
| 20 | 39 | ||
| 21 | std::stringstream ss; | 40 | return fmt::format("{:%z}", tm); |
| 22 | ss << std::put_time(&tm, "%z"); // Get the current timezone offset, e.g. "-400", as a string | ||
| 23 | |||
| 24 | return ss.str(); | ||
| 25 | } | 41 | } |
| 26 | 42 | ||
| 27 | static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) { | 43 | static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) { |
| @@ -45,4 +61,43 @@ std::chrono::seconds GetCurrentOffsetSeconds() { | |||
| 45 | return std::chrono::seconds{seconds}; | 61 | return std::chrono::seconds{seconds}; |
| 46 | } | 62 | } |
| 47 | 63 | ||
| 64 | // Key is [Hours * 100 + Minutes], multiplied by 100 if DST | ||
| 65 | const static std::map<s64, const char*> off_timezones = { | ||
| 66 | {530, "Asia/Calcutta"}, {930, "Australia/Darwin"}, {845, "Australia/Eucla"}, | ||
| 67 | {103000, "Australia/Adelaide"}, {1030, "Australia/Lord_Howe"}, {630, "Indian/Cocos"}, | ||
| 68 | {1245, "Pacific/Chatham"}, {134500, "Pacific/Chatham"}, {-330, "Canada/Newfoundland"}, | ||
| 69 | {-23000, "Canada/Newfoundland"}, {430, "Asia/Kabul"}, {330, "Asia/Tehran"}, | ||
| 70 | {43000, "Asia/Tehran"}, {545, "Asia/Kathmandu"}, {-930, "Asia/Marquesas"}, | ||
| 71 | }; | ||
| 72 | |||
| 73 | std::string FindSystemTimeZone() { | ||
| 74 | #if defined(MINGW) | ||
| 75 | // MinGW has broken strftime -- https://sourceforge.net/p/mingw-w64/bugs/793/ | ||
| 76 | // e.g. fmt::format("{:%z}") -- returns "Eastern Daylight Time" when it should be "-0400" | ||
| 77 | return timezones[0]; | ||
| 78 | #else | ||
| 79 | const s64 seconds = static_cast<s64>(GetCurrentOffsetSeconds().count()); | ||
| 80 | |||
| 81 | const s64 minutes = seconds / 60; | ||
| 82 | const s64 hours = minutes / 60; | ||
| 83 | |||
| 84 | const s64 minutes_off = minutes - hours * 60; | ||
| 85 | |||
| 86 | if (minutes_off != 0) { | ||
| 87 | const auto the_time = std::time(nullptr); | ||
| 88 | const struct std::tm& local = *std::localtime(&the_time); | ||
| 89 | const bool is_dst = local.tm_isdst != 0; | ||
| 90 | |||
| 91 | const s64 tz_index = (hours * 100 + minutes_off) * (is_dst ? 100 : 1); | ||
| 92 | |||
| 93 | try { | ||
| 94 | return off_timezones.at(tz_index); | ||
| 95 | } catch (std::out_of_range&) { | ||
| 96 | LOG_ERROR(Common, "Time zone {} not handled, defaulting to hour offset.", tz_index); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | return fmt::format("Etc/GMT{:s}{:d}", hours > 0 ? "-" : "+", std::abs(hours)); | ||
| 100 | #endif | ||
| 101 | } | ||
| 102 | |||
| 48 | } // namespace Common::TimeZone | 103 | } // namespace Common::TimeZone |
diff --git a/src/common/time_zone.h b/src/common/time_zone.h index 99cae6ef2..f574d5c04 100644 --- a/src/common/time_zone.h +++ b/src/common/time_zone.h | |||
| @@ -3,15 +3,21 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <array> | ||
| 6 | #include <chrono> | 7 | #include <chrono> |
| 7 | #include <string> | 8 | #include <string> |
| 8 | 9 | ||
| 9 | namespace Common::TimeZone { | 10 | namespace Common::TimeZone { |
| 10 | 11 | ||
| 12 | [[nodiscard]] const std::array<const char*, 46>& GetTimeZoneStrings(); | ||
| 13 | |||
| 11 | /// Gets the default timezone, i.e. "GMT" | 14 | /// Gets the default timezone, i.e. "GMT" |
| 12 | [[nodiscard]] std::string GetDefaultTimeZone(); | 15 | [[nodiscard]] std::string GetDefaultTimeZone(); |
| 13 | 16 | ||
| 14 | /// Gets the offset of the current timezone (from the default), in seconds | 17 | /// Gets the offset of the current timezone (from the default), in seconds |
| 15 | [[nodiscard]] std::chrono::seconds GetCurrentOffsetSeconds(); | 18 | [[nodiscard]] std::chrono::seconds GetCurrentOffsetSeconds(); |
| 16 | 19 | ||
| 20 | /// Searches time zone offsets for the closest offset to the system time zone | ||
| 21 | [[nodiscard]] std::string FindSystemTimeZone(); | ||
| 22 | |||
| 17 | } // namespace Common::TimeZone | 23 | } // namespace Common::TimeZone |
diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index 89e1ed225..035df7fe0 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp | |||
| @@ -48,7 +48,7 @@ std::array<u8, 0x10> ConstructFromRawString(std::string_view raw_string) { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | std::array<u8, 0x10> ConstructFromFormattedString(std::string_view formatted_string) { | 50 | std::array<u8, 0x10> ConstructFromFormattedString(std::string_view formatted_string) { |
| 51 | std::array<u8, 0x10> uuid; | 51 | std::array<u8, 0x10> uuid{}; |
| 52 | 52 | ||
| 53 | size_t i = 0; | 53 | size_t i = 0; |
| 54 | 54 | ||