summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/fs/fs.cpp27
-rw-r--r--src/common/fs/fs_android.h5
-rw-r--r--src/common/fs/fs_paths.h1
-rw-r--r--src/common/fs/path_util.cpp1
-rw-r--r--src/common/fs/path_util.h1
-rw-r--r--src/common/settings.cpp32
-rw-r--r--src/common/settings.h2
-rw-r--r--src/common/time_zone.cpp63
-rw-r--r--src/common/time_zone.h6
-rw-r--r--src/common/uuid.cpp2
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 @@
#include "common/fs/file.h"
#include "common/fs/fs.h"
+#ifdef ANDROID
+#include "common/fs/fs_android.h"
+#endif
#include "common/fs/path_util.h"
#include "common/logging/log.h"
@@ -525,15 +528,39 @@ void IterateDirEntriesRecursively(const std::filesystem::path& path,
// Generic Filesystem Operations
bool Exists(const fs::path& path) {
+#ifdef ANDROID
+ if (Android::IsContentUri(path)) {
+ return Android::Exists(path);
+ } else {
+ return fs::exists(path);
+ }
+#else
return fs::exists(path);
+#endif
}
bool IsFile(const fs::path& path) {
+#ifdef ANDROID
+ if (Android::IsContentUri(path)) {
+ return !Android::IsDirectory(path);
+ } else {
+ return fs::is_regular_file(path);
+ }
+#else
return fs::is_regular_file(path);
+#endif
}
bool IsDir(const fs::path& path) {
+#ifdef ANDROID
+ if (Android::IsContentUri(path)) {
+ return Android::IsDirectory(path);
+ } else {
+ return fs::is_directory(path);
+ }
+#else
return fs::is_directory(path);
+#endif
}
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 @@
"openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
#define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
- V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J")
+ V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") \
+ V(IsDirectory, bool, is_directory, CallStaticBooleanMethod, "isDirectory", \
+ "(Ljava/lang/String;)Z") \
+ V(Exists, bool, file_exists, CallStaticBooleanMethod, "exists", "(Ljava/lang/String;)Z")
namespace Common::FS::Android {
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 @@
// Sub-directories contained within a yuzu data directory
+#define AMIIBO_DIR "amiibo"
#define CACHE_DIR "cache"
#define CONFIG_DIR "config"
#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:
#endif
GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path);
+ GenerateYuzuPath(YuzuPath::AmiiboDir, yuzu_path / AMIIBO_DIR);
GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path_cache);
GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path_config);
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 {
enum class YuzuPath {
YuzuDir, // Where yuzu stores its data.
+ AmiiboDir, // Where Amiibo backups are stored.
CacheDir, // Where cached filesystem data is stored.
ConfigDir, // Where config files are stored.
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 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
+#if __cpp_lib_chrono >= 201907L
+#include <chrono>
+#endif
#include <string_view>
#include "common/assert.h"
#include "common/fs/path_util.h"
#include "common/logging/log.h"
#include "common/settings.h"
+#include "common/time_zone.h"
namespace Settings {
@@ -14,18 +18,23 @@ Values values;
static bool configuring_global = true;
std::string GetTimeZoneString() {
- static constexpr std::array timezones{
- "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
- "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
- "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
- "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
- "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
- "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
- };
-
const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue());
- ASSERT(time_zone_index < timezones.size());
- return timezones[time_zone_index];
+ ASSERT(time_zone_index < Common::TimeZone::GetTimeZoneStrings().size());
+
+ std::string location_name;
+ if (time_zone_index == 0) { // Auto
+#if __cpp_lib_chrono >= 201907L
+ const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb();
+ const std::chrono::time_zone* current_zone = time_zone_data.current_zone();
+ std::string_view current_zone_name = current_zone->name();
+ location_name = current_zone_name;
+#else
+ location_name = Common::TimeZone::FindSystemTimeZone();
+#endif
+ } else {
+ location_name = Common::TimeZone::GetTimeZoneStrings()[time_zone_index];
+ }
+ return location_name;
}
void LogSettings() {
@@ -235,6 +244,7 @@ void RestoreGlobalState(bool is_powered_on) {
values.bg_green.SetGlobal(true);
values.bg_blue.SetGlobal(true);
values.enable_compute_pipelines.SetGlobal(true);
+ values.use_video_framerate.SetGlobal(true);
// System
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 {
SwitchableSetting<AstcRecompression, true> astc_recompression{
AstcRecompression::Uncompressed, AstcRecompression::Uncompressed, AstcRecompression::Bc3,
"astc_recompression"};
+ SwitchableSetting<bool> use_video_framerate{false, "use_video_framerate"};
+ SwitchableSetting<bool> barrier_feedback_loops{true, "barrier_feedback_loops"};
SwitchableSetting<u8> bg_red{0, "bg_red"};
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 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <chrono>
+#include <exception>
#include <iomanip>
#include <sstream>
+#include <stdexcept>
+#include <fmt/chrono.h>
+#include <fmt/core.h>
#include "common/logging/log.h"
+#include "common/settings.h"
#include "common/time_zone.h"
namespace Common::TimeZone {
+// Time zone strings
+constexpr std::array timezones{
+ "GMT", "GMT", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
+ "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
+ "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
+ "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
+ "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
+ "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
+};
+
+const std::array<const char*, 46>& GetTimeZoneStrings() {
+ return timezones;
+}
+
std::string GetDefaultTimeZone() {
return "GMT";
}
@@ -18,10 +37,7 @@ static std::string GetOsTimeZoneOffset() {
const std::time_t t{std::time(nullptr)};
const std::tm tm{*std::localtime(&t)};
- std::stringstream ss;
- ss << std::put_time(&tm, "%z"); // Get the current timezone offset, e.g. "-400", as a string
-
- return ss.str();
+ return fmt::format("{:%z}", tm);
}
static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) {
@@ -45,4 +61,43 @@ std::chrono::seconds GetCurrentOffsetSeconds() {
return std::chrono::seconds{seconds};
}
+// Key is [Hours * 100 + Minutes], multiplied by 100 if DST
+const static std::map<s64, const char*> off_timezones = {
+ {530, "Asia/Calcutta"}, {930, "Australia/Darwin"}, {845, "Australia/Eucla"},
+ {103000, "Australia/Adelaide"}, {1030, "Australia/Lord_Howe"}, {630, "Indian/Cocos"},
+ {1245, "Pacific/Chatham"}, {134500, "Pacific/Chatham"}, {-330, "Canada/Newfoundland"},
+ {-23000, "Canada/Newfoundland"}, {430, "Asia/Kabul"}, {330, "Asia/Tehran"},
+ {43000, "Asia/Tehran"}, {545, "Asia/Kathmandu"}, {-930, "Asia/Marquesas"},
+};
+
+std::string FindSystemTimeZone() {
+#if defined(MINGW)
+ // MinGW has broken strftime -- https://sourceforge.net/p/mingw-w64/bugs/793/
+ // e.g. fmt::format("{:%z}") -- returns "Eastern Daylight Time" when it should be "-0400"
+ return timezones[0];
+#else
+ const s64 seconds = static_cast<s64>(GetCurrentOffsetSeconds().count());
+
+ const s64 minutes = seconds / 60;
+ const s64 hours = minutes / 60;
+
+ const s64 minutes_off = minutes - hours * 60;
+
+ if (minutes_off != 0) {
+ const auto the_time = std::time(nullptr);
+ const struct std::tm& local = *std::localtime(&the_time);
+ const bool is_dst = local.tm_isdst != 0;
+
+ const s64 tz_index = (hours * 100 + minutes_off) * (is_dst ? 100 : 1);
+
+ try {
+ return off_timezones.at(tz_index);
+ } catch (std::out_of_range&) {
+ LOG_ERROR(Common, "Time zone {} not handled, defaulting to hour offset.", tz_index);
+ }
+ }
+ return fmt::format("Etc/GMT{:s}{:d}", hours > 0 ? "-" : "+", std::abs(hours));
+#endif
+}
+
} // 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 @@
#pragma once
+#include <array>
#include <chrono>
#include <string>
namespace Common::TimeZone {
+[[nodiscard]] const std::array<const char*, 46>& GetTimeZoneStrings();
+
/// Gets the default timezone, i.e. "GMT"
[[nodiscard]] std::string GetDefaultTimeZone();
/// Gets the offset of the current timezone (from the default), in seconds
[[nodiscard]] std::chrono::seconds GetCurrentOffsetSeconds();
+/// Searches time zone offsets for the closest offset to the system time zone
+[[nodiscard]] std::string FindSystemTimeZone();
+
} // 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) {
}
std::array<u8, 0x10> ConstructFromFormattedString(std::string_view formatted_string) {
- std::array<u8, 0x10> uuid;
+ std::array<u8, 0x10> uuid{};
size_t i = 0;