summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/file_util.cpp49
-rw-r--r--src/common/file_util.h15
-rw-r--r--src/core/hle/service/aoc/aoc_u.cpp69
-rw-r--r--src/yuzu/configuration/configure_dialog.cpp3
-rw-r--r--src/yuzu/configuration/configure_hotkeys.cpp38
-rw-r--r--src/yuzu/configuration/configure_hotkeys.h6
-rw-r--r--src/yuzu/util/sequence_dialog/sequence_dialog.cpp13
-rw-r--r--src/yuzu_cmd/config.cpp4
8 files changed, 98 insertions, 99 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index aecb66c32..2d9374783 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -78,16 +78,17 @@ namespace FileUtil {
// Remove any ending forward slashes from directory paths
// Modifies argument.
static void StripTailDirSlashes(std::string& fname) {
- if (fname.length() > 1) {
- std::size_t i = fname.length();
- while (i > 0 && fname[i - 1] == DIR_SEP_CHR)
- --i;
- fname.resize(i);
+ if (fname.length() <= 1) {
+ return;
+ }
+
+ std::size_t i = fname.length();
+ while (i > 0 && fname[i - 1] == DIR_SEP_CHR) {
+ --i;
}
- return;
+ fname.resize(i);
}
-// Returns true if file filename exists
bool Exists(const std::string& filename) {
struct stat file_info;
@@ -107,7 +108,6 @@ bool Exists(const std::string& filename) {
return (result == 0);
}
-// Returns true if filename is a directory
bool IsDirectory(const std::string& filename) {
struct stat file_info;
@@ -132,8 +132,6 @@ bool IsDirectory(const std::string& filename) {
return S_ISDIR(file_info.st_mode);
}
-// Deletes a given filename, return true on success
-// Doesn't supports deleting a directory
bool Delete(const std::string& filename) {
LOG_TRACE(Common_Filesystem, "file {}", filename);
@@ -165,7 +163,6 @@ bool Delete(const std::string& filename) {
return true;
}
-// Returns true if successful, or path already exists.
bool CreateDir(const std::string& path) {
LOG_TRACE(Common_Filesystem, "directory {}", path);
#ifdef _WIN32
@@ -194,7 +191,6 @@ bool CreateDir(const std::string& path) {
#endif
}
-// Creates the full path of fullPath returns true on success
bool CreateFullPath(const std::string& fullPath) {
int panicCounter = 100;
LOG_TRACE(Common_Filesystem, "path {}", fullPath);
@@ -230,7 +226,6 @@ bool CreateFullPath(const std::string& fullPath) {
}
}
-// Deletes a directory filename, returns true on success
bool DeleteDir(const std::string& filename) {
LOG_TRACE(Common_Filesystem, "directory {}", filename);
@@ -252,7 +247,6 @@ bool DeleteDir(const std::string& filename) {
return false;
}
-// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string& srcFilename, const std::string& destFilename) {
LOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename);
#ifdef _WIN32
@@ -268,7 +262,6 @@ bool Rename(const std::string& srcFilename, const std::string& destFilename) {
return false;
}
-// copies file srcFilename to destFilename, returns true on success
bool Copy(const std::string& srcFilename, const std::string& destFilename) {
LOG_TRACE(Common_Filesystem, "{} --> {}", srcFilename, destFilename);
#ifdef _WIN32
@@ -324,7 +317,6 @@ bool Copy(const std::string& srcFilename, const std::string& destFilename) {
#endif
}
-// Returns the size of filename (64bit)
u64 GetSize(const std::string& filename) {
if (!Exists(filename)) {
LOG_ERROR(Common_Filesystem, "failed {}: No such file", filename);
@@ -351,7 +343,6 @@ u64 GetSize(const std::string& filename) {
return 0;
}
-// Overloaded GetSize, accepts file descriptor
u64 GetSize(const int fd) {
struct stat buf;
if (fstat(fd, &buf) != 0) {
@@ -361,7 +352,6 @@ u64 GetSize(const int fd) {
return buf.st_size;
}
-// Overloaded GetSize, accepts FILE*
u64 GetSize(FILE* f) {
// can't use off_t here because it can be 32-bit
u64 pos = ftello(f);
@@ -377,7 +367,6 @@ u64 GetSize(FILE* f) {
return size;
}
-// creates an empty file filename, returns true on success
bool CreateEmptyFile(const std::string& filename) {
LOG_TRACE(Common_Filesystem, "{}", filename);
@@ -502,7 +491,6 @@ bool DeleteDirRecursively(const std::string& directory, unsigned int recursion)
return true;
}
-// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path) {
#ifndef _WIN32
if (source_path == dest_path)
@@ -539,8 +527,7 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
#endif
}
-// Returns the current directory
-std::string GetCurrentDir() {
+std::optional<std::string> GetCurrentDir() {
// Get the current working directory (getcwd uses malloc)
#ifdef _WIN32
wchar_t* dir;
@@ -550,7 +537,7 @@ std::string GetCurrentDir() {
if (!(dir = getcwd(nullptr, 0))) {
#endif
LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
- return nullptr;
+ return {};
}
#ifdef _WIN32
std::string strDir = Common::UTF16ToUTF8(dir);
@@ -561,7 +548,6 @@ std::string GetCurrentDir() {
return strDir;
}
-// Sets the current directory to the given directory
bool SetCurrentDir(const std::string& directory) {
#ifdef _WIN32
return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0;
@@ -673,8 +659,6 @@ std::string GetSysDirectory() {
return sysDir;
}
-// Returns a string with a yuzu data dir or file in the user's home
-// directory. To be used in "multi-user" mode (that is, installed).
const std::string& GetUserPath(UserPath path, const std::string& new_path) {
static std::unordered_map<UserPath, std::string> paths;
auto& user_path = paths[UserPath::UserDir];
@@ -762,11 +746,11 @@ std::string GetNANDRegistrationDir(bool system) {
return GetUserPath(UserPath::NANDDir) + "user/Contents/registered/";
}
-std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
- return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
+std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) {
+ return IOFile(filename, text_file ? "w" : "wb").WriteString(str);
}
-std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str) {
+std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str) {
IOFile file(filename, text_file ? "r" : "rb");
if (!file.IsOpen())
@@ -776,13 +760,6 @@ std::size_t ReadFileToString(bool text_file, const char* filename, std::string&
return file.ReadArray(&str[0], str.size());
}
-/**
- * Splits the filename into 8.3 format
- * Loosely implemented following https://en.wikipedia.org/wiki/8.3_filename
- * @param filename The normal filename to use
- * @param short_name A 9-char array in which the short name will be written
- * @param extension A 4-char array in which the extension will be written
- */
void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name,
std::array<char, 4>& extension) {
const std::string forbidden_characters = ".\"/\\[]:;=, ";
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 38cc7f059..cde7ddf2d 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -9,6 +9,7 @@
#include <fstream>
#include <functional>
#include <limits>
+#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
@@ -118,7 +119,7 @@ u64 ScanDirectoryTree(const std::string& directory, FSTEntry& parent_entry,
bool DeleteDirRecursively(const std::string& directory, unsigned int recursion = 256);
// Returns the current directory
-std::string GetCurrentDir();
+std::optional<std::string> GetCurrentDir();
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path);
@@ -146,9 +147,9 @@ const std::string& GetExeDirectory();
std::string AppDataRoamingDirectory();
#endif
-std::size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename);
+std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str);
-std::size_t ReadFileToString(bool text_file, const char* filename, std::string& str);
+std::size_t ReadFileToString(bool text_file, const std::string& filename, std::string& str);
/**
* Splits the filename into 8.3 format
@@ -257,8 +258,8 @@ public:
return WriteArray(&object, 1);
}
- std::size_t WriteString(const std::string& str) {
- return WriteArray(str.c_str(), str.length());
+ std::size_t WriteString(std::string_view str) {
+ return WriteArray(str.data(), str.length());
}
bool IsOpen() const {
@@ -286,8 +287,8 @@ private:
template <typename T>
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) {
#ifdef _MSC_VER
- fstream.open(Common::UTF8ToUTF16W(filename).c_str(), openmode);
+ fstream.open(Common::UTF8ToUTF16W(filename), openmode);
#else
- fstream.open(filename.c_str(), openmode);
+ fstream.open(filename, openmode);
#endif
}
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp
index bd4e38461..d3e97776b 100644
--- a/src/core/hle/service/aoc/aoc_u.cpp
+++ b/src/core/hle/service/aoc/aoc_u.cpp
@@ -9,7 +9,6 @@
#include "core/file_sys/content_archive.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/nca_metadata.h"
-#include "core/file_sys/partition_filesystem.h"
#include "core/file_sys/patch_manager.h"
#include "core/file_sys/registered_cache.h"
#include "core/hle/ipc_helpers.h"
@@ -18,7 +17,6 @@
#include "core/hle/kernel/readable_event.h"
#include "core/hle/kernel/writable_event.h"
#include "core/hle/service/aoc/aoc_u.h"
-#include "core/hle/service/filesystem/filesystem.h"
#include "core/loader/loader.h"
#include "core/settings.h"
@@ -75,7 +73,15 @@ AOC_U::AOC_U() : ServiceFramework("aoc:u"), add_on_content(AccumulateAOCTitleIDs
AOC_U::~AOC_U() = default;
void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) {
- LOG_DEBUG(Service_AOC, "called");
+ struct Parameters {
+ u64 process_id;
+ };
+ static_assert(sizeof(Parameters) == 8);
+
+ IPC::RequestParser rp{ctx};
+ const auto params = rp.PopRaw<Parameters>();
+
+ LOG_DEBUG(Service_AOC, "called. process_id={}", params.process_id);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
@@ -94,23 +100,32 @@ void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) {
}
void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) {
+ struct Parameters {
+ u32 offset;
+ u32 count;
+ u64 process_id;
+ };
+ static_assert(sizeof(Parameters) == 16);
+
IPC::RequestParser rp{ctx};
+ const auto [offset, count, process_id] = rp.PopRaw<Parameters>();
- const auto offset = rp.PopRaw<u32>();
- auto count = rp.PopRaw<u32>();
- LOG_DEBUG(Service_AOC, "called with offset={}, count={}", offset, count);
+ LOG_DEBUG(Service_AOC, "called with offset={}, count={}, process_id={}", offset, count,
+ process_id);
const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID();
std::vector<u32> out;
- for (size_t i = 0; i < add_on_content.size(); ++i) {
- if ((add_on_content[i] & DLC_BASE_TITLE_ID_MASK) == current)
- out.push_back(static_cast<u32>(add_on_content[i] & 0x7FF));
- }
-
const auto& disabled = Settings::values.disabled_addons[current];
- if (std::find(disabled.begin(), disabled.end(), "DLC") != disabled.end())
- out = {};
+ if (std::find(disabled.begin(), disabled.end(), "DLC") == disabled.end()) {
+ for (u64 content_id : add_on_content) {
+ if ((content_id & DLC_BASE_TITLE_ID_MASK) != current) {
+ continue;
+ }
+
+ out.push_back(static_cast<u32>(content_id & 0x7FF));
+ }
+ }
if (out.size() < offset) {
IPC::ResponseBuilder rb{ctx, 2};
@@ -119,22 +134,31 @@ void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) {
return;
}
- count = static_cast<u32>(std::min<size_t>(out.size() - offset, count));
+ const auto out_count = static_cast<u32>(std::min<size_t>(out.size() - offset, count));
std::rotate(out.begin(), out.begin() + offset, out.end());
- out.resize(count);
+ out.resize(out_count);
ctx.WriteBuffer(out);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
- rb.Push(count);
+ rb.Push(out_count);
}
void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) {
- LOG_DEBUG(Service_AOC, "called");
+ struct Parameters {
+ u64 process_id;
+ };
+ static_assert(sizeof(Parameters) == 8);
+
+ IPC::RequestParser rp{ctx};
+ const auto params = rp.PopRaw<Parameters>();
+
+ LOG_DEBUG(Service_AOC, "called. process_id={}", params.process_id);
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS);
+
const auto title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
FileSys::PatchManager pm{title_id};
@@ -148,10 +172,17 @@ void AOC_U::GetAddOnContentBaseId(Kernel::HLERequestContext& ctx) {
}
void AOC_U::PrepareAddOnContent(Kernel::HLERequestContext& ctx) {
+ struct Parameters {
+ s32 addon_index;
+ u64 process_id;
+ };
+ static_assert(sizeof(Parameters) == 16);
+
IPC::RequestParser rp{ctx};
+ const auto [addon_index, process_id] = rp.PopRaw<Parameters>();
- const auto aoc_id = rp.PopRaw<u32>();
- LOG_WARNING(Service_AOC, "(STUBBED) called with aoc_id={:08X}", aoc_id);
+ LOG_WARNING(Service_AOC, "(STUBBED) called with addon_index={}, process_id={}", addon_index,
+ process_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp
index 32c05b797..8086f9d6b 100644
--- a/src/yuzu/configuration/configure_dialog.cpp
+++ b/src/yuzu/configuration/configure_dialog.cpp
@@ -25,9 +25,6 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry)
adjustSize();
ui->selectorList->setCurrentRow(0);
-
- // Synchronise lists upon initialisation
- ui->hotkeysTab->EmitHotkeysChanged();
}
ConfigureDialog::~ConfigureDialog() = default;
diff --git a/src/yuzu/configuration/configure_hotkeys.cpp b/src/yuzu/configuration/configure_hotkeys.cpp
index a7a8752e5..9fb970c21 100644
--- a/src/yuzu/configuration/configure_hotkeys.cpp
+++ b/src/yuzu/configuration/configure_hotkeys.cpp
@@ -31,22 +31,6 @@ ConfigureHotkeys::ConfigureHotkeys(QWidget* parent)
ConfigureHotkeys::~ConfigureHotkeys() = default;
-void ConfigureHotkeys::EmitHotkeysChanged() {
- emit HotkeysChanged(GetUsedKeyList());
-}
-
-QList<QKeySequence> ConfigureHotkeys::GetUsedKeyList() const {
- QList<QKeySequence> list;
- for (int r = 0; r < model->rowCount(); r++) {
- const QStandardItem* parent = model->item(r, 0);
- for (int r2 = 0; r2 < parent->rowCount(); r2++) {
- const QStandardItem* keyseq = parent->child(r2, 1);
- list << QKeySequence::fromString(keyseq->text(), QKeySequence::NativeText);
- }
- }
- return list;
-}
-
void ConfigureHotkeys::Populate(const HotkeyRegistry& registry) {
for (const auto& group : registry.hotkey_groups) {
auto* parent_item = new QStandardItem(group.first);
@@ -83,16 +67,29 @@ void ConfigureHotkeys::Configure(QModelIndex index) {
}
if (IsUsedKey(key_sequence) && key_sequence != QKeySequence(previous_key.toString())) {
- QMessageBox::critical(this, tr("Error in inputted key"),
- tr("You're using a key that's already bound."));
+ QMessageBox::warning(this, tr("Conflicting Key Sequence"),
+ tr("The entered key sequence is already assigned to another hotkey."));
} else {
model->setData(index, key_sequence.toString(QKeySequence::NativeText));
- EmitHotkeysChanged();
}
}
bool ConfigureHotkeys::IsUsedKey(QKeySequence key_sequence) const {
- return GetUsedKeyList().contains(key_sequence);
+ for (int r = 0; r < model->rowCount(); r++) {
+ const QStandardItem* const parent = model->item(r, 0);
+
+ for (int r2 = 0; r2 < parent->rowCount(); r2++) {
+ const QStandardItem* const key_seq_item = parent->child(r2, 1);
+ const auto key_seq_str = key_seq_item->text();
+ const auto key_seq = QKeySequence::fromString(key_seq_str, QKeySequence::NativeText);
+
+ if (key_sequence == key_seq) {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
@@ -114,7 +111,6 @@ void ConfigureHotkeys::applyConfiguration(HotkeyRegistry& registry) {
}
registry.SaveHotkeys();
- Settings::Apply();
}
void ConfigureHotkeys::retranslateUi() {
diff --git a/src/yuzu/configuration/configure_hotkeys.h b/src/yuzu/configuration/configure_hotkeys.h
index 73fb8a175..e77d73c35 100644
--- a/src/yuzu/configuration/configure_hotkeys.h
+++ b/src/yuzu/configuration/configure_hotkeys.h
@@ -24,8 +24,6 @@ public:
void applyConfiguration(HotkeyRegistry& registry);
void retranslateUi();
- void EmitHotkeysChanged();
-
/**
* Populates the hotkey list widget using data from the provided registry.
* Called everytime the Configure dialog is opened.
@@ -33,13 +31,9 @@ public:
*/
void Populate(const HotkeyRegistry& registry);
-signals:
- void HotkeysChanged(QList<QKeySequence> new_key_list);
-
private:
void Configure(QModelIndex index);
bool IsUsedKey(QKeySequence key_sequence) const;
- QList<QKeySequence> GetUsedKeyList() const;
std::unique_ptr<Ui::ConfigureHotkeys> ui;
diff --git a/src/yuzu/util/sequence_dialog/sequence_dialog.cpp b/src/yuzu/util/sequence_dialog/sequence_dialog.cpp
index d3edf6ec3..bb5f74ec4 100644
--- a/src/yuzu/util/sequence_dialog/sequence_dialog.cpp
+++ b/src/yuzu/util/sequence_dialog/sequence_dialog.cpp
@@ -9,16 +9,19 @@
SequenceDialog::SequenceDialog(QWidget* parent) : QDialog(parent) {
setWindowTitle(tr("Enter a hotkey"));
- auto* layout = new QVBoxLayout(this);
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
key_sequence = new QKeySequenceEdit;
- layout->addWidget(key_sequence);
- auto* buttons =
- new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
+
+ auto* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttons->setCenterButtons(true);
+
+ auto* const layout = new QVBoxLayout(this);
+ layout->addWidget(key_sequence);
layout->addWidget(buttons);
+
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
- setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
SequenceDialog::~SequenceDialog() = default;
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index d0ae058fd..730956427 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -26,12 +26,12 @@ Config::Config() {
Config::~Config() = default;
bool Config::LoadINI(const std::string& default_contents, bool retry) {
- const char* location = this->sdl2_config_loc.c_str();
+ const std::string& location = this->sdl2_config_loc;
if (sdl2_config->ParseError() < 0) {
if (retry) {
LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", location);
FileUtil::CreateFullPath(location);
- FileUtil::WriteStringToFile(true, default_contents, location);
+ FileUtil::WriteStringToFile(true, location, default_contents);
sdl2_config = std::make_unique<INIReader>(location); // Reopen file
return LoadINI(default_contents, false);