summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.cpp2
-rw-r--r--src/common/settings.h2
-rw-r--r--src/core/CMakeLists.txt16
-rw-r--r--src/core/core.cpp13
-rw-r--r--src/core/core.h12
-rw-r--r--src/core/file_sys/vfs_libzip.cpp88
-rw-r--r--src/core/file_sys/vfs_libzip.h13
-rw-r--r--src/core/hle/service/am/am.cpp4
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp548
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.h64
-rw-r--r--src/core/hle/service/bcat/bcat_module.cpp7
-rw-r--r--src/core/network/network.cpp2
-rw-r--r--src/input_common/sdl/sdl_impl.cpp18
-rw-r--r--src/yuzu/CMakeLists.txt4
-rw-r--r--src/yuzu/applets/qt_web_browser.cpp3
-rw-r--r--src/yuzu/bootmanager.cpp5
-rw-r--r--src/yuzu/bootmanager.h4
-rw-r--r--src/yuzu/configuration/config.cpp4
-rw-r--r--src/yuzu/configuration/configure_network.cpp117
-rw-r--r--src/yuzu/configuration/configure_network.h5
-rw-r--r--src/yuzu/configuration/configure_network.ui86
-rw-r--r--src/yuzu/main.cpp7
-rw-r--r--src/yuzu/main.h1
-rw-r--r--src/yuzu_cmd/config.cpp4
-rw-r--r--src/yuzu_cmd/default_ini.h5
25 files changed, 64 insertions, 970 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 69f0bd8c0..9dd5e3efb 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -69,8 +69,6 @@ void LogSettings() {
69 log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir)); 69 log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
70 log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir)); 70 log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
71 log_setting("Debugging_ProgramArgs", values.program_args.GetValue()); 71 log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
72 log_setting("Services_BCATBackend", values.bcat_backend.GetValue());
73 log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue());
74 log_setting("Input_EnableMotion", values.motion_enabled.GetValue()); 72 log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
75 log_setting("Input_EnableVibration", values.vibration_enabled.GetValue()); 73 log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
76 log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue()); 74 log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
diff --git a/src/common/settings.h b/src/common/settings.h
index c53d5acc3..402339443 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -568,8 +568,6 @@ struct Values {
568 BasicSetting<bool> use_dev_keys{false, "use_dev_keys"}; 568 BasicSetting<bool> use_dev_keys{false, "use_dev_keys"};
569 569
570 // Network 570 // Network
571 BasicSetting<std::string> bcat_backend{"none", "bcat_backend"};
572 BasicSetting<bool> bcat_boxcat_local{false, "bcat_boxcat_local"};
573 BasicSetting<std::string> network_interface{std::string(), "network_interface"}; 571 BasicSetting<std::string> network_interface{std::string(), "network_interface"};
574 572
575 // WebService 573 // WebService
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 7140d0db8..aa3b26628 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -106,8 +106,6 @@ add_library(core STATIC
106 file_sys/vfs_concat.h 106 file_sys/vfs_concat.h
107 file_sys/vfs_layered.cpp 107 file_sys/vfs_layered.cpp
108 file_sys/vfs_layered.h 108 file_sys/vfs_layered.h
109 file_sys/vfs_libzip.cpp
110 file_sys/vfs_libzip.h
111 file_sys/vfs_offset.cpp 109 file_sys/vfs_offset.cpp
112 file_sys/vfs_offset.h 110 file_sys/vfs_offset.h
113 file_sys/vfs_real.cpp 111 file_sys/vfs_real.cpp
@@ -653,13 +651,6 @@ add_library(core STATIC
653 tools/freezer.h 651 tools/freezer.h
654) 652)
655 653
656if (YUZU_ENABLE_BOXCAT)
657 target_sources(core PRIVATE
658 hle/service/bcat/backend/boxcat.cpp
659 hle/service/bcat/backend/boxcat.h
660 )
661endif()
662
663if (MSVC) 654if (MSVC)
664 target_compile_options(core PRIVATE 655 target_compile_options(core PRIVATE
665 /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data 656 /we4242 # 'identifier': conversion from 'type1' to 'type2', possible loss of data
@@ -690,12 +681,7 @@ endif()
690create_target_directory_groups(core) 681create_target_directory_groups(core)
691 682
692target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) 683target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
693target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus zip) 684target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus)
694
695if (YUZU_ENABLE_BOXCAT)
696 target_compile_definitions(core PRIVATE -DYUZU_ENABLE_BOXCAT)
697 target_link_libraries(core PRIVATE httplib nlohmann_json::nlohmann_json)
698endif()
699 685
700if (ENABLE_WEB_SERVICE) 686if (ENABLE_WEB_SERVICE)
701 target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE) 687 target_compile_definitions(core PRIVATE -DENABLE_WEB_SERVICE)
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 50d5dab4b..bb268a319 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -421,6 +421,7 @@ struct System::Impl {
421 bool is_async_gpu{}; 421 bool is_async_gpu{};
422 422
423 ExecuteProgramCallback execute_program_callback; 423 ExecuteProgramCallback execute_program_callback;
424 ExitCallback exit_callback;
424 425
425 std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; 426 std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
426 std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{}; 427 std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{};
@@ -798,6 +799,18 @@ void System::ExecuteProgram(std::size_t program_index) {
798 } 799 }
799} 800}
800 801
802void System::RegisterExitCallback(ExitCallback&& callback) {
803 impl->exit_callback = std::move(callback);
804}
805
806void System::Exit() {
807 if (impl->exit_callback) {
808 impl->exit_callback();
809 } else {
810 LOG_CRITICAL(Core, "exit_callback must be initialized by the frontend");
811 }
812}
813
801void System::ApplySettings() { 814void System::ApplySettings() {
802 if (IsPoweredOn()) { 815 if (IsPoweredOn()) {
803 Renderer().RefreshBaseSettings(); 816 Renderer().RefreshBaseSettings();
diff --git a/src/core/core.h b/src/core/core.h
index 715ab88e7..a796472b2 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -387,6 +387,18 @@ public:
387 */ 387 */
388 void ExecuteProgram(std::size_t program_index); 388 void ExecuteProgram(std::size_t program_index);
389 389
390 /// Type used for the frontend to designate a callback for System to exit the application.
391 using ExitCallback = std::function<void()>;
392
393 /**
394 * Registers a callback from the frontend for System to exit the application.
395 * @param callback Callback from the frontend to exit the application.
396 */
397 void RegisterExitCallback(ExitCallback&& callback);
398
399 /// Instructs the frontend to exit the application.
400 void Exit();
401
390 /// Applies any changes to settings to this core instance. 402 /// Applies any changes to settings to this core instance.
391 void ApplySettings(); 403 void ApplySettings();
392 404
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp
deleted file mode 100644
index 00e256779..000000000
--- a/src/core/file_sys/vfs_libzip.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
1// Copyright 2019 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <string>
6
7#ifdef __GNUC__
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wshadow"
10#endif
11#include <zip.h>
12#ifdef __GNUC__
13#pragma GCC diagnostic pop
14#endif
15
16#include "common/fs/path_util.h"
17#include "core/file_sys/vfs.h"
18#include "core/file_sys/vfs_libzip.h"
19#include "core/file_sys/vfs_vector.h"
20
21namespace FileSys {
22
23VirtualDir ExtractZIP(VirtualFile file) {
24 zip_error_t error{};
25
26 const auto data = file->ReadAllBytes();
27 std::unique_ptr<zip_source_t, decltype(&zip_source_close)> src{
28 zip_source_buffer_create(data.data(), data.size(), 0, &error), zip_source_close};
29 if (src == nullptr)
30 return nullptr;
31
32 std::unique_ptr<zip_t, decltype(&zip_close)> zip{zip_open_from_source(src.get(), 0, &error),
33 zip_close};
34 if (zip == nullptr)
35 return nullptr;
36
37 std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>();
38
39 const auto num_entries = static_cast<std::size_t>(zip_get_num_entries(zip.get(), 0));
40
41 zip_stat_t stat{};
42 zip_stat_init(&stat);
43
44 for (std::size_t i = 0; i < num_entries; ++i) {
45 const auto stat_res = zip_stat_index(zip.get(), i, 0, &stat);
46 if (stat_res == -1)
47 return nullptr;
48
49 const std::string name(stat.name);
50 if (name.empty())
51 continue;
52
53 if (name.back() != '/') {
54 std::unique_ptr<zip_file_t, decltype(&zip_fclose)> file2{
55 zip_fopen_index(zip.get(), i, 0), zip_fclose};
56
57 std::vector<u8> buf(stat.size);
58 if (zip_fread(file2.get(), buf.data(), buf.size()) != s64(buf.size()))
59 return nullptr;
60
61 const auto parts = Common::FS::SplitPathComponents(stat.name);
62 const auto new_file = std::make_shared<VectorVfsFile>(buf, parts.back());
63
64 std::shared_ptr<VectorVfsDirectory> dtrv = out;
65 for (std::size_t j = 0; j < parts.size() - 1; ++j) {
66 if (dtrv == nullptr)
67 return nullptr;
68 const auto subdir = dtrv->GetSubdirectory(parts[j]);
69 if (subdir == nullptr) {
70 const auto temp = std::make_shared<VectorVfsDirectory>(
71 std::vector<VirtualFile>{}, std::vector<VirtualDir>{}, parts[j]);
72 dtrv->AddDirectory(temp);
73 dtrv = temp;
74 } else {
75 dtrv = std::dynamic_pointer_cast<VectorVfsDirectory>(subdir);
76 }
77 }
78
79 if (dtrv == nullptr)
80 return nullptr;
81 dtrv->AddFile(new_file);
82 }
83 }
84
85 return out;
86}
87
88} // namespace FileSys
diff --git a/src/core/file_sys/vfs_libzip.h b/src/core/file_sys/vfs_libzip.h
deleted file mode 100644
index f68af576a..000000000
--- a/src/core/file_sys/vfs_libzip.h
+++ /dev/null
@@ -1,13 +0,0 @@
1// Copyright 2019 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/file_sys/vfs_types.h"
8
9namespace FileSys {
10
11VirtualDir ExtractZIP(VirtualFile zip);
12
13} // namespace FileSys
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 8c2e2f920..49e9787a4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -332,10 +332,10 @@ ISelfController::~ISelfController() = default;
332void ISelfController::Exit(Kernel::HLERequestContext& ctx) { 332void ISelfController::Exit(Kernel::HLERequestContext& ctx) {
333 LOG_DEBUG(Service_AM, "called"); 333 LOG_DEBUG(Service_AM, "called");
334 334
335 system.Shutdown();
336
337 IPC::ResponseBuilder rb{ctx, 2}; 335 IPC::ResponseBuilder rb{ctx, 2};
338 rb.Push(ResultSuccess); 336 rb.Push(ResultSuccess);
337
338 system.Exit();
339} 339}
340 340
341void ISelfController::LockExit(Kernel::HLERequestContext& ctx) { 341void ISelfController::LockExit(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
deleted file mode 100644
index 7ca7f2aac..000000000
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ /dev/null
@@ -1,548 +0,0 @@
1// Copyright 2019 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <fmt/ostream.h>
6
7#ifdef __GNUC__
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wshadow"
10#ifndef __clang__
11#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
12#endif
13#endif
14#include <httplib.h>
15#include <mbedtls/sha256.h>
16#include <nlohmann/json.hpp>
17#ifdef __GNUC__
18#pragma GCC diagnostic pop
19#endif
20
21#include "common/fs/file.h"
22#include "common/fs/fs.h"
23#include "common/fs/path_util.h"
24#include "common/hex_util.h"
25#include "common/logging/log.h"
26#include "common/settings.h"
27#include "core/core.h"
28#include "core/file_sys/vfs.h"
29#include "core/file_sys/vfs_libzip.h"
30#include "core/file_sys/vfs_vector.h"
31#include "core/frontend/applets/error.h"
32#include "core/hle/service/am/applets/applets.h"
33#include "core/hle/service/bcat/backend/boxcat.h"
34
35namespace Service::BCAT {
36namespace {
37
38// Prevents conflicts with windows macro called CreateFile
39FileSys::VirtualFile VfsCreateFileWrap(FileSys::VirtualDir dir, std::string_view name) {
40 return dir->CreateFile(name);
41}
42
43// Prevents conflicts with windows macro called DeleteFile
44bool VfsDeleteFileWrap(FileSys::VirtualDir dir, std::string_view name) {
45 return dir->DeleteFile(name);
46}
47
48constexpr ResultCode ERROR_GENERAL_BCAT_FAILURE{ErrorModule::BCAT, 1};
49
50constexpr char BOXCAT_HOSTNAME[] = "api.yuzu-emu.org";
51
52// Formatted using fmt with arg[0] = hex title id
53constexpr char BOXCAT_PATHNAME_DATA[] = "/game-assets/{:016X}/boxcat";
54constexpr char BOXCAT_PATHNAME_LAUNCHPARAM[] = "/game-assets/{:016X}/launchparam";
55
56constexpr char BOXCAT_PATHNAME_EVENTS[] = "/game-assets/boxcat/events";
57
58constexpr char BOXCAT_API_VERSION[] = "1";
59constexpr char BOXCAT_CLIENT_TYPE[] = "yuzu";
60
61// HTTP status codes for Boxcat
62enum class ResponseStatus {
63 Ok = 200, ///< Operation completed successfully.
64 BadClientVersion = 301, ///< The Boxcat-Client-Version doesn't match the server.
65 NoUpdate = 304, ///< The digest provided would match the new data, no need to update.
66 NoMatchTitleId = 404, ///< The title ID provided doesn't have a boxcat implementation.
67 NoMatchBuildId = 406, ///< The build ID provided is blacklisted (potentially because of format
68 ///< issues or whatnot) and has no data.
69};
70
71enum class DownloadResult {
72 Success = 0,
73 NoResponse,
74 GeneralWebError,
75 NoMatchTitleId,
76 NoMatchBuildId,
77 InvalidContentType,
78 GeneralFSError,
79 BadClientVersion,
80};
81
82constexpr std::array<const char*, 8> DOWNLOAD_RESULT_LOG_MESSAGES{
83 "Success",
84 "There was no response from the server.",
85 "There was a general web error code returned from the server.",
86 "The title ID of the current game doesn't have a boxcat implementation. If you believe an "
87 "implementation should be added, contact yuzu support.",
88 "The build ID of the current version of the game is marked as incompatible with the current "
89 "BCAT distribution. Try upgrading or downgrading your game version or contacting yuzu support.",
90 "The content type of the web response was invalid.",
91 "There was a general filesystem error while saving the zip file.",
92 "The server is either too new or too old to serve the request. Try using the latest version of "
93 "an official release of yuzu.",
94};
95
96std::ostream& operator<<(std::ostream& os, DownloadResult result) {
97 return os << DOWNLOAD_RESULT_LOG_MESSAGES.at(static_cast<std::size_t>(result));
98}
99
100constexpr u32 PORT = 443;
101constexpr u32 TIMEOUT_SECONDS = 30;
102[[maybe_unused]] constexpr u64 VFS_COPY_BLOCK_SIZE = 1ULL << 24; // 4MB
103
104std::filesystem::path GetBINFilePath(u64 title_id) {
105 return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" /
106 fmt::format("{:016X}/launchparam.bin", title_id);
107}
108
109std::filesystem::path GetZIPFilePath(u64 title_id) {
110 return Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "bcat" /
111 fmt::format("{:016X}/data.zip", title_id);
112}
113
114// If the error is something the user should know about (build ID mismatch, bad client version),
115// display an error.
116void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manager,
117 DownloadResult res) {
118 if (res == DownloadResult::Success || res == DownloadResult::NoResponse ||
119 res == DownloadResult::GeneralWebError || res == DownloadResult::GeneralFSError ||
120 res == DownloadResult::NoMatchTitleId || res == DownloadResult::InvalidContentType) {
121 return;
122 }
123
124 const auto& frontend{applet_manager.GetAppletFrontendSet()};
125 frontend.error->ShowCustomErrorText(
126 ResultUnknown, "There was an error while attempting to use Boxcat.",
127 DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {});
128}
129
130bool VfsRawCopyProgress(FileSys::VirtualFile src, FileSys::VirtualFile dest,
131 std::string_view dir_name, ProgressServiceBackend& progress,
132 std::size_t block_size = 0x1000) {
133 if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
134 return false;
135 if (!dest->Resize(src->GetSize()))
136 return false;
137
138 progress.StartDownloadingFile(dir_name, src->GetName(), src->GetSize());
139
140 std::vector<u8> temp(std::min(block_size, src->GetSize()));
141 for (std::size_t i = 0; i < src->GetSize(); i += block_size) {
142 const auto read = std::min(block_size, src->GetSize() - i);
143
144 if (src->Read(temp.data(), read, i) != read) {
145 return false;
146 }
147
148 if (dest->Write(temp.data(), read, i) != read) {
149 return false;
150 }
151
152 progress.UpdateFileProgress(i);
153 }
154
155 progress.FinishDownloadingFile();
156
157 return true;
158}
159
160bool VfsRawCopyDProgressSingle(FileSys::VirtualDir src, FileSys::VirtualDir dest,
161 ProgressServiceBackend& progress, std::size_t block_size = 0x1000) {
162 if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
163 return false;
164
165 for (const auto& file : src->GetFiles()) {
166 const auto out_file = VfsCreateFileWrap(dest, file->GetName());
167 if (!VfsRawCopyProgress(file, out_file, src->GetName(), progress, block_size)) {
168 return false;
169 }
170 }
171 progress.CommitDirectory(src->GetName());
172
173 return true;
174}
175
176bool VfsRawCopyDProgress(FileSys::VirtualDir src, FileSys::VirtualDir dest,
177 ProgressServiceBackend& progress, std::size_t block_size = 0x1000) {
178 if (src == nullptr || dest == nullptr || !src->IsReadable() || !dest->IsWritable())
179 return false;
180
181 for (const auto& dir : src->GetSubdirectories()) {
182 const auto out = dest->CreateSubdirectory(dir->GetName());
183 if (!VfsRawCopyDProgressSingle(dir, out, progress, block_size)) {
184 return false;
185 }
186 }
187
188 return true;
189}
190
191} // Anonymous namespace
192
193class Boxcat::Client {
194public:
195 Client(std::filesystem::path path_, u64 title_id_, u64 build_id_)
196 : path(std::move(path_)), title_id(title_id_), build_id(build_id_) {}
197
198 DownloadResult DownloadDataZip() {
199 return DownloadInternal(fmt::format(BOXCAT_PATHNAME_DATA, title_id), TIMEOUT_SECONDS,
200 "application/zip");
201 }
202
203 DownloadResult DownloadLaunchParam() {
204 return DownloadInternal(fmt::format(BOXCAT_PATHNAME_LAUNCHPARAM, title_id),
205 TIMEOUT_SECONDS / 3, "application/octet-stream");
206 }
207
208private:
209 DownloadResult DownloadInternal(const std::string& resolved_path, u32 timeout_seconds,
210 const std::string& content_type_name) {
211 if (client == nullptr) {
212 client = std::make_unique<httplib::SSLClient>(BOXCAT_HOSTNAME, PORT);
213 client->set_connection_timeout(timeout_seconds);
214 client->set_read_timeout(timeout_seconds);
215 client->set_write_timeout(timeout_seconds);
216 }
217
218 httplib::Headers headers{
219 {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)},
220 {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)},
221 {std::string("Game-Build-Id"), fmt::format("{:016X}", build_id)},
222 };
223
224 if (Common::FS::Exists(path)) {
225 Common::FS::IOFile file{path, Common::FS::FileAccessMode::Read,
226 Common::FS::FileType::BinaryFile};
227 if (file.IsOpen()) {
228 std::vector<u8> bytes(file.GetSize());
229 void(file.Read(bytes));
230 const auto digest = DigestFile(bytes);
231 headers.insert({std::string("If-None-Match"), Common::HexToString(digest, false)});
232 }
233 }
234
235 const auto response = client->Get(resolved_path.c_str(), headers);
236 if (response == nullptr)
237 return DownloadResult::NoResponse;
238
239 if (response->status == static_cast<int>(ResponseStatus::NoUpdate))
240 return DownloadResult::Success;
241 if (response->status == static_cast<int>(ResponseStatus::BadClientVersion))
242 return DownloadResult::BadClientVersion;
243 if (response->status == static_cast<int>(ResponseStatus::NoMatchTitleId))
244 return DownloadResult::NoMatchTitleId;
245 if (response->status == static_cast<int>(ResponseStatus::NoMatchBuildId))
246 return DownloadResult::NoMatchBuildId;
247 if (response->status != static_cast<int>(ResponseStatus::Ok))
248 return DownloadResult::GeneralWebError;
249
250 const auto content_type = response->headers.find("content-type");
251 if (content_type == response->headers.end() ||
252 content_type->second.find(content_type_name) == std::string::npos) {
253 return DownloadResult::InvalidContentType;
254 }
255
256 if (!Common::FS::CreateDirs(path)) {
257 return DownloadResult::GeneralFSError;
258 }
259
260 Common::FS::IOFile file{path, Common::FS::FileAccessMode::Append,
261 Common::FS::FileType::BinaryFile};
262 if (!file.IsOpen()) {
263 return DownloadResult::GeneralFSError;
264 }
265
266 if (!file.SetSize(response->body.size())) {
267 return DownloadResult::GeneralFSError;
268 }
269
270 if (file.Write(response->body) != response->body.size()) {
271 return DownloadResult::GeneralFSError;
272 }
273
274 return DownloadResult::Success;
275 }
276
277 using Digest = std::array<u8, 0x20>;
278 static Digest DigestFile(std::vector<u8> bytes) {
279 Digest out{};
280 mbedtls_sha256_ret(bytes.data(), bytes.size(), out.data(), 0);
281 return out;
282 }
283
284 std::unique_ptr<httplib::SSLClient> client;
285 std::filesystem::path path;
286 u64 title_id;
287 u64 build_id;
288};
289
290Boxcat::Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter)
291 : Backend(std::move(getter)), applet_manager{applet_manager_} {}
292
293Boxcat::~Boxcat() = default;
294
295void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGetter dir_getter,
296 TitleIDVersion title, ProgressServiceBackend& progress,
297 std::optional<std::string> dir_name = {}) {
298 progress.SetNeedHLELock(true);
299
300 if (Settings::values.bcat_boxcat_local) {
301 LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download.");
302 const auto dir = dir_getter(title.title_id);
303 if (dir)
304 progress.SetTotalSize(dir->GetSize());
305 progress.FinishDownload(ResultSuccess);
306 return;
307 }
308
309 const auto zip_path = GetZIPFilePath(title.title_id);
310 Boxcat::Client client{zip_path, title.title_id, title.build_id};
311
312 progress.StartConnecting();
313
314 const auto res = client.DownloadDataZip();
315 if (res != DownloadResult::Success) {
316 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
317
318 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
319 Common::FS::RemoveFile(zip_path);
320 }
321
322 HandleDownloadDisplayResult(applet_manager, res);
323 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
324 return;
325 }
326
327 progress.StartProcessingDataList();
328
329 Common::FS::IOFile zip{zip_path, Common::FS::FileAccessMode::Read,
330 Common::FS::FileType::BinaryFile};
331 const auto size = zip.GetSize();
332 std::vector<u8> bytes(size);
333 if (!zip.IsOpen() || size == 0 || zip.Read(bytes) != bytes.size()) {
334 LOG_ERROR(Service_BCAT, "Boxcat failed to read ZIP file at path '{}'!",
335 Common::FS::PathToUTF8String(zip_path));
336 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
337 return;
338 }
339
340 const auto extracted = FileSys::ExtractZIP(std::make_shared<FileSys::VectorVfsFile>(bytes));
341 if (extracted == nullptr) {
342 LOG_ERROR(Service_BCAT, "Boxcat failed to extract ZIP file!");
343 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
344 return;
345 }
346
347 if (dir_name == std::nullopt) {
348 progress.SetTotalSize(extracted->GetSize());
349
350 const auto target_dir = dir_getter(title.title_id);
351 if (target_dir == nullptr || !VfsRawCopyDProgress(extracted, target_dir, progress)) {
352 LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!");
353 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
354 return;
355 }
356 } else {
357 const auto target_dir = dir_getter(title.title_id);
358 if (target_dir == nullptr) {
359 LOG_ERROR(Service_BCAT, "Boxcat failed to get directory for title ID!");
360 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
361 return;
362 }
363
364 const auto target_sub = target_dir->GetSubdirectory(*dir_name);
365 const auto source_sub = extracted->GetSubdirectory(*dir_name);
366
367 progress.SetTotalSize(source_sub->GetSize());
368
369 std::vector<std::string> filenames;
370 {
371 const auto files = target_sub->GetFiles();
372 std::transform(files.begin(), files.end(), std::back_inserter(filenames),
373 [](const auto& vfile) { return vfile->GetName(); });
374 }
375
376 for (const auto& filename : filenames) {
377 VfsDeleteFileWrap(target_sub, filename);
378 }
379
380 if (target_sub == nullptr || source_sub == nullptr ||
381 !VfsRawCopyDProgressSingle(source_sub, target_sub, progress)) {
382 LOG_ERROR(Service_BCAT, "Boxcat failed to copy extracted ZIP to target directory!");
383 progress.FinishDownload(ERROR_GENERAL_BCAT_FAILURE);
384 return;
385 }
386 }
387
388 progress.FinishDownload(ResultSuccess);
389}
390
391bool Boxcat::Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) {
392 is_syncing.exchange(true);
393
394 std::thread([this, title, &progress] {
395 SynchronizeInternal(applet_manager, dir_getter, title, progress);
396 }).detach();
397
398 return true;
399}
400
401bool Boxcat::SynchronizeDirectory(TitleIDVersion title, std::string name,
402 ProgressServiceBackend& progress) {
403 is_syncing.exchange(true);
404
405 std::thread([this, title, name, &progress] {
406 SynchronizeInternal(applet_manager, dir_getter, title, progress, name);
407 }).detach();
408
409 return true;
410}
411
412bool Boxcat::Clear(u64 title_id) {
413 if (Settings::values.bcat_boxcat_local) {
414 LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping clear.");
415 return true;
416 }
417
418 const auto dir = dir_getter(title_id);
419
420 std::vector<std::string> dirnames;
421
422 for (const auto& subdir : dir->GetSubdirectories())
423 dirnames.push_back(subdir->GetName());
424
425 for (const auto& subdir : dirnames) {
426 if (!dir->DeleteSubdirectoryRecursive(subdir))
427 return false;
428 }
429
430 return true;
431}
432
433void Boxcat::SetPassphrase(u64 title_id, const Passphrase& passphrase) {
434 LOG_DEBUG(Service_BCAT, "called, title_id={:016X}, passphrase={}", title_id,
435 Common::HexToString(passphrase));
436}
437
438std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title) {
439 const auto bin_file_path = GetBINFilePath(title.title_id);
440
441 if (Settings::values.bcat_boxcat_local) {
442 LOG_INFO(Service_BCAT, "Boxcat using local data by override, skipping download.");
443 } else {
444 Client launch_client{bin_file_path, title.title_id, title.build_id};
445
446 const auto res = launch_client.DownloadLaunchParam();
447 if (res != DownloadResult::Success) {
448 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
449
450 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
451 Common::FS::RemoveFile(bin_file_path);
452 }
453
454 HandleDownloadDisplayResult(applet_manager, res);
455 return std::nullopt;
456 }
457 }
458
459 Common::FS::IOFile bin{bin_file_path, Common::FS::FileAccessMode::Read,
460 Common::FS::FileType::BinaryFile};
461 const auto size = bin.GetSize();
462 std::vector<u8> bytes(size);
463 if (!bin.IsOpen() || size == 0 || bin.Read(bytes) != bytes.size()) {
464 LOG_ERROR(Service_BCAT, "Boxcat failed to read launch parameter binary at path '{}'!",
465 Common::FS::PathToUTF8String(bin_file_path));
466 return std::nullopt;
467 }
468
469 return bytes;
470}
471
472Boxcat::StatusResult Boxcat::GetStatus(std::optional<std::string>& global,
473 std::map<std::string, EventStatus>& games) {
474 httplib::SSLClient client{BOXCAT_HOSTNAME, static_cast<int>(PORT)};
475 client.set_connection_timeout(static_cast<int>(TIMEOUT_SECONDS));
476 client.set_read_timeout(static_cast<int>(TIMEOUT_SECONDS));
477 client.set_write_timeout(static_cast<int>(TIMEOUT_SECONDS));
478
479 httplib::Headers headers{
480 {std::string("Game-Assets-API-Version"), std::string(BOXCAT_API_VERSION)},
481 {std::string("Boxcat-Client-Type"), std::string(BOXCAT_CLIENT_TYPE)},
482 };
483
484 if (!client.is_valid()) {
485 LOG_ERROR(Service_BCAT, "Client is invalid, going offline!");
486 return StatusResult::Offline;
487 }
488
489 if (!client.is_socket_open()) {
490 LOG_ERROR(Service_BCAT, "Failed to open socket, going offline!");
491 return StatusResult::Offline;
492 }
493
494 const auto response = client.Get(BOXCAT_PATHNAME_EVENTS, headers);
495 if (response == nullptr)
496 return StatusResult::Offline;
497
498 if (response->status == static_cast<int>(ResponseStatus::BadClientVersion))
499 return StatusResult::BadClientVersion;
500
501 try {
502 nlohmann::json json = nlohmann::json::parse(response->body);
503
504 if (!json["online"].get<bool>())
505 return StatusResult::Offline;
506
507 if (json["global"].is_null())
508 global = std::nullopt;
509 else
510 global = json["global"].get<std::string>();
511
512 if (json["games"].is_array()) {
513 for (const auto& object : json["games"]) {
514 if (object.is_object() && object.find("name") != object.end()) {
515 EventStatus detail{};
516 if (object["header"].is_string()) {
517 detail.header = object["header"].get<std::string>();
518 } else {
519 detail.header = std::nullopt;
520 }
521
522 if (object["footer"].is_string()) {
523 detail.footer = object["footer"].get<std::string>();
524 } else {
525 detail.footer = std::nullopt;
526 }
527
528 if (object["events"].is_array()) {
529 for (const auto& event : object["events"]) {
530 if (!event.is_string())
531 continue;
532 detail.events.push_back(event.get<std::string>());
533 }
534 }
535
536 games.insert_or_assign(object["name"], std::move(detail));
537 }
538 }
539 }
540
541 return StatusResult::Success;
542 } catch (const nlohmann::json::parse_error& error) {
543 LOG_ERROR(Service_BCAT, "{}", error.what());
544 return StatusResult::ParseError;
545 }
546}
547
548} // namespace Service::BCAT
diff --git a/src/core/hle/service/bcat/backend/boxcat.h b/src/core/hle/service/bcat/backend/boxcat.h
deleted file mode 100644
index d65b42e58..000000000
--- a/src/core/hle/service/bcat/backend/boxcat.h
+++ /dev/null
@@ -1,64 +0,0 @@
1// Copyright 2019 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <atomic>
8#include <map>
9#include <optional>
10#include "core/hle/service/bcat/backend/backend.h"
11
12namespace Service::AM::Applets {
13class AppletManager;
14}
15
16namespace Service::BCAT {
17
18struct EventStatus {
19 std::optional<std::string> header;
20 std::optional<std::string> footer;
21 std::vector<std::string> events;
22};
23
24/// Boxcat is yuzu's custom backend implementation of Nintendo's BCAT service. It is free to use and
25/// doesn't require a switch or nintendo account. The content is controlled by the yuzu team.
26class Boxcat final : public Backend {
27 friend void SynchronizeInternal(AM::Applets::AppletManager& applet_manager,
28 DirectoryGetter dir_getter, TitleIDVersion title,
29 ProgressServiceBackend& progress,
30 std::optional<std::string> dir_name);
31
32public:
33 explicit Boxcat(AM::Applets::AppletManager& applet_manager_, DirectoryGetter getter);
34 ~Boxcat() override;
35
36 bool Synchronize(TitleIDVersion title, ProgressServiceBackend& progress) override;
37 bool SynchronizeDirectory(TitleIDVersion title, std::string name,
38 ProgressServiceBackend& progress) override;
39
40 bool Clear(u64 title_id) override;
41
42 void SetPassphrase(u64 title_id, const Passphrase& passphrase) override;
43
44 std::optional<std::vector<u8>> GetLaunchParameter(TitleIDVersion title) override;
45
46 enum class StatusResult {
47 Success,
48 Offline,
49 ParseError,
50 BadClientVersion,
51 };
52
53 static StatusResult GetStatus(std::optional<std::string>& global,
54 std::map<std::string, EventStatus>& games);
55
56private:
57 std::atomic_bool is_syncing{false};
58
59 class Client;
60 std::unique_ptr<Client> client;
61 AM::Applets::AppletManager& applet_manager;
62};
63
64} // namespace Service::BCAT
diff --git a/src/core/hle/service/bcat/bcat_module.cpp b/src/core/hle/service/bcat/bcat_module.cpp
index 72294eb2e..701f634f8 100644
--- a/src/core/hle/service/bcat/bcat_module.cpp
+++ b/src/core/hle/service/bcat/bcat_module.cpp
@@ -4,7 +4,6 @@
4 4
5#include <cctype> 5#include <cctype>
6#include <mbedtls/md5.h> 6#include <mbedtls/md5.h>
7#include "backend/boxcat.h"
8#include "common/hex_util.h" 7#include "common/hex_util.h"
9#include "common/logging/log.h" 8#include "common/logging/log.h"
10#include "common/settings.h" 9#include "common/settings.h"
@@ -578,12 +577,6 @@ void Module::Interface::CreateDeliveryCacheStorageServiceWithApplicationId(
578 577
579std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system, 578std::unique_ptr<Backend> CreateBackendFromSettings([[maybe_unused]] Core::System& system,
580 DirectoryGetter getter) { 579 DirectoryGetter getter) {
581#ifdef YUZU_ENABLE_BOXCAT
582 if (Settings::values.bcat_backend.GetValue() == "boxcat") {
583 return std::make_unique<Boxcat>(system.GetAppletManager(), std::move(getter));
584 }
585#endif
586
587 return std::make_unique<NullBackend>(std::move(getter)); 580 return std::make_unique<NullBackend>(std::move(getter));
588} 581}
589 582
diff --git a/src/core/network/network.cpp b/src/core/network/network.cpp
index 72eea52f0..a3e0664b9 100644
--- a/src/core/network/network.cpp
+++ b/src/core/network/network.cpp
@@ -366,8 +366,6 @@ std::optional<IPv4Address> GetHostIPv4Address() {
366 if (res != network_interfaces.end()) { 366 if (res != network_interfaces.end()) {
367 char ip_addr[16] = {}; 367 char ip_addr[16] = {};
368 ASSERT(inet_ntop(AF_INET, &res->ip_address, ip_addr, sizeof(ip_addr)) != nullptr); 368 ASSERT(inet_ntop(AF_INET, &res->ip_address, ip_addr, sizeof(ip_addr)) != nullptr);
369 LOG_INFO(Network, "IP address: {}", ip_addr);
370
371 return TranslateIPv4(res->ip_address); 369 return TranslateIPv4(res->ip_address);
372 } else { 370 } else {
373 LOG_ERROR(Network, "Couldn't find selected interface \"{}\"", selected_network_interface); 371 LOG_ERROR(Network, "Couldn't find selected interface \"{}\"", selected_network_interface);
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 03888b7cb..ab6211b29 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -254,11 +254,25 @@ public:
254 } 254 }
255 255
256 bool IsJoyconLeft() const { 256 bool IsJoyconLeft() const {
257 return std::strstr(GetControllerName().c_str(), "Joy-Con Left") != nullptr; 257 const std::string controller_name = GetControllerName();
258 if (std::strstr(controller_name.c_str(), "Joy-Con Left") != nullptr) {
259 return true;
260 }
261 if (std::strstr(controller_name.c_str(), "Joy-Con (L)") != nullptr) {
262 return true;
263 }
264 return false;
258 } 265 }
259 266
260 bool IsJoyconRight() const { 267 bool IsJoyconRight() const {
261 return std::strstr(GetControllerName().c_str(), "Joy-Con Right") != nullptr; 268 const std::string controller_name = GetControllerName();
269 if (std::strstr(controller_name.c_str(), "Joy-Con Right") != nullptr) {
270 return true;
271 }
272 if (std::strstr(controller_name.c_str(), "Joy-Con (R)") != nullptr) {
273 return true;
274 }
275 return false;
262 } 276 }
263 277
264 std::string GetControllerName() const { 278 std::string GetControllerName() const {
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index b6dda283d..402be6a78 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -290,10 +290,6 @@ if (YUZU_USE_QT_WEB_ENGINE)
290 target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE) 290 target_compile_definitions(yuzu PRIVATE -DYUZU_USE_QT_WEB_ENGINE)
291endif () 291endif ()
292 292
293if (YUZU_ENABLE_BOXCAT)
294 target_compile_definitions(yuzu PRIVATE -DYUZU_ENABLE_BOXCAT)
295endif ()
296
297if(UNIX AND NOT APPLE) 293if(UNIX AND NOT APPLE)
298 install(TARGETS yuzu RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") 294 install(TARGETS yuzu RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
299endif() 295endif()
diff --git a/src/yuzu/applets/qt_web_browser.cpp b/src/yuzu/applets/qt_web_browser.cpp
index 652d99570..7d433ca50 100644
--- a/src/yuzu/applets/qt_web_browser.cpp
+++ b/src/yuzu/applets/qt_web_browser.cpp
@@ -54,6 +54,9 @@ QtNXWebEngineView::QtNXWebEngineView(QWidget* parent, Core::System& system,
54 input_interpreter(std::make_unique<InputInterpreter>(system)), 54 input_interpreter(std::make_unique<InputInterpreter>(system)),
55 default_profile{QWebEngineProfile::defaultProfile()}, 55 default_profile{QWebEngineProfile::defaultProfile()},
56 global_settings{QWebEngineSettings::globalSettings()} { 56 global_settings{QWebEngineSettings::globalSettings()} {
57 default_profile->setPersistentStoragePath(QString::fromStdString(Common::FS::PathToUTF8String(
58 Common::FS::GetYuzuPath(Common::FS::YuzuPath::YuzuDir) / "qtwebengine")));
59
57 QWebEngineScript gamepad; 60 QWebEngineScript gamepad;
58 QWebEngineScript window_nx; 61 QWebEngineScript window_nx;
59 62
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 1519a46ed..8b9e186b0 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -302,12 +302,17 @@ GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread_,
302 connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); 302 connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
303 connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram, 303 connect(this, &GRenderWindow::ExecuteProgramSignal, parent, &GMainWindow::OnExecuteProgram,
304 Qt::QueuedConnection); 304 Qt::QueuedConnection);
305 connect(this, &GRenderWindow::ExitSignal, parent, &GMainWindow::OnExit, Qt::QueuedConnection);
305} 306}
306 307
307void GRenderWindow::ExecuteProgram(std::size_t program_index) { 308void GRenderWindow::ExecuteProgram(std::size_t program_index) {
308 emit ExecuteProgramSignal(program_index); 309 emit ExecuteProgramSignal(program_index);
309} 310}
310 311
312void GRenderWindow::Exit() {
313 emit ExitSignal();
314}
315
311GRenderWindow::~GRenderWindow() { 316GRenderWindow::~GRenderWindow() {
312 input_subsystem->Shutdown(); 317 input_subsystem->Shutdown();
313} 318}
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 402dd2ee1..54c4e2142 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -181,6 +181,9 @@ public:
181 */ 181 */
182 void ExecuteProgram(std::size_t program_index); 182 void ExecuteProgram(std::size_t program_index);
183 183
184 /// Instructs the window to exit the application.
185 void Exit();
186
184public slots: 187public slots:
185 void OnEmulationStarting(EmuThread* emu_thread); 188 void OnEmulationStarting(EmuThread* emu_thread);
186 void OnEmulationStopping(); 189 void OnEmulationStopping();
@@ -191,6 +194,7 @@ signals:
191 void Closed(); 194 void Closed();
192 void FirstFrameDisplayed(); 195 void FirstFrameDisplayed();
193 void ExecuteProgramSignal(std::size_t program_index); 196 void ExecuteProgramSignal(std::size_t program_index);
197 void ExitSignal();
194 void MouseActivity(); 198 void MouseActivity();
195 199
196private: 200private:
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index b5796a8fc..eb941ce02 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -709,8 +709,6 @@ void Config::ReadDebuggingValues() {
709 709
710void Config::ReadServiceValues() { 710void Config::ReadServiceValues() {
711 qt_config->beginGroup(QStringLiteral("Services")); 711 qt_config->beginGroup(QStringLiteral("Services"));
712 ReadBasicSetting(Settings::values.bcat_backend);
713 ReadBasicSetting(Settings::values.bcat_boxcat_local);
714 ReadBasicSetting(Settings::values.network_interface); 712 ReadBasicSetting(Settings::values.network_interface);
715 qt_config->endGroup(); 713 qt_config->endGroup();
716} 714}
@@ -1269,8 +1267,6 @@ void Config::SaveDebuggingValues() {
1269void Config::SaveNetworkValues() { 1267void Config::SaveNetworkValues() {
1270 qt_config->beginGroup(QStringLiteral("Services")); 1268 qt_config->beginGroup(QStringLiteral("Services"));
1271 1269
1272 WriteBasicSetting(Settings::values.bcat_backend);
1273 WriteBasicSetting(Settings::values.bcat_boxcat_local);
1274 WriteBasicSetting(Settings::values.network_interface); 1270 WriteBasicSetting(Settings::values.network_interface);
1275 1271
1276 qt_config->endGroup(); 1272 qt_config->endGroup();
diff --git a/src/yuzu/configuration/configure_network.cpp b/src/yuzu/configuration/configure_network.cpp
index ae22f1018..cc15d36c2 100644
--- a/src/yuzu/configuration/configure_network.cpp
+++ b/src/yuzu/configuration/configure_network.cpp
@@ -6,64 +6,25 @@
6#include <QtConcurrent/QtConcurrent> 6#include <QtConcurrent/QtConcurrent>
7#include "common/settings.h" 7#include "common/settings.h"
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/service/bcat/backend/boxcat.h"
10#include "core/network/network_interface.h" 9#include "core/network/network_interface.h"
11#include "ui_configure_network.h" 10#include "ui_configure_network.h"
12#include "yuzu/configuration/configure_network.h" 11#include "yuzu/configuration/configure_network.h"
13 12
14#ifdef YUZU_ENABLE_BOXCAT
15namespace {
16QString FormatEventStatusString(const Service::BCAT::EventStatus& status) {
17 QString out;
18
19 if (status.header.has_value()) {
20 out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.header));
21 }
22
23 if (status.events.size() == 1) {
24 out += QStringLiteral("%1<br>").arg(QString::fromStdString(status.events.front()));
25 } else {
26 for (const auto& event : status.events) {
27 out += QStringLiteral("- %1<br>").arg(QString::fromStdString(event));
28 }
29 }
30
31 if (status.footer.has_value()) {
32 out += QStringLiteral("<i>%1</i><br>").arg(QString::fromStdString(*status.footer));
33 }
34
35 return out;
36}
37} // Anonymous namespace
38#endif
39
40ConfigureNetwork::ConfigureNetwork(QWidget* parent) 13ConfigureNetwork::ConfigureNetwork(QWidget* parent)
41 : QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) { 14 : QWidget(parent), ui(std::make_unique<Ui::ConfigureNetwork>()) {
42 ui->setupUi(this); 15 ui->setupUi(this);
43 16
44 ui->bcat_source->addItem(QStringLiteral("None"));
45 ui->bcat_empty_label->setHidden(true);
46 ui->bcat_empty_header->setHidden(true);
47
48#ifdef YUZU_ENABLE_BOXCAT
49 ui->bcat_source->addItem(QStringLiteral("Boxcat"), QStringLiteral("boxcat"));
50#endif
51
52 ui->network_interface->addItem(tr("None")); 17 ui->network_interface->addItem(tr("None"));
53 for (const auto& iface : Network::GetAvailableNetworkInterfaces()) { 18 for (const auto& iface : Network::GetAvailableNetworkInterfaces()) {
54 ui->network_interface->addItem(QString::fromStdString(iface.name)); 19 ui->network_interface->addItem(QString::fromStdString(iface.name));
55 } 20 }
56 21
57 connect(ui->bcat_source, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
58 &ConfigureNetwork::OnBCATImplChanged);
59
60 this->SetConfiguration(); 22 this->SetConfiguration();
61} 23}
62 24
63ConfigureNetwork::~ConfigureNetwork() = default; 25ConfigureNetwork::~ConfigureNetwork() = default;
64 26
65void ConfigureNetwork::ApplyConfiguration() { 27void ConfigureNetwork::ApplyConfiguration() {
66 Settings::values.bcat_backend = ui->bcat_source->currentText().toLower().toStdString();
67 Settings::values.network_interface = ui->network_interface->currentText().toStdString(); 28 Settings::values.network_interface = ui->network_interface->currentText().toStdString();
68} 29}
69 30
@@ -74,86 +35,8 @@ void ConfigureNetwork::RetranslateUi() {
74void ConfigureNetwork::SetConfiguration() { 35void ConfigureNetwork::SetConfiguration() {
75 const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); 36 const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
76 37
77 const int index =
78 ui->bcat_source->findData(QString::fromStdString(Settings::values.bcat_backend.GetValue()));
79 ui->bcat_source->setCurrentIndex(index == -1 ? 0 : index);
80
81 const std::string& network_interface = Settings::values.network_interface.GetValue(); 38 const std::string& network_interface = Settings::values.network_interface.GetValue();
82 39
83 ui->network_interface->setCurrentText(QString::fromStdString(network_interface)); 40 ui->network_interface->setCurrentText(QString::fromStdString(network_interface));
84 ui->network_interface->setEnabled(runtime_lock); 41 ui->network_interface->setEnabled(runtime_lock);
85} 42}
86
87std::pair<QString, QString> ConfigureNetwork::BCATDownloadEvents() {
88#ifdef YUZU_ENABLE_BOXCAT
89 std::optional<std::string> global;
90 std::map<std::string, Service::BCAT::EventStatus> map;
91 const auto res = Service::BCAT::Boxcat::GetStatus(global, map);
92
93 switch (res) {
94 case Service::BCAT::Boxcat::StatusResult::Success:
95 break;
96 case Service::BCAT::Boxcat::StatusResult::Offline:
97 return {QString{},
98 tr("The boxcat service is offline or you are not connected to the internet.")};
99 case Service::BCAT::Boxcat::StatusResult::ParseError:
100 return {QString{},
101 tr("There was an error while processing the boxcat event data. Contact the yuzu "
102 "developers.")};
103 case Service::BCAT::Boxcat::StatusResult::BadClientVersion:
104 return {QString{},
105 tr("The version of yuzu you are using is either too new or too old for the server. "
106 "Try updating to the latest official release of yuzu.")};
107 }
108
109 if (map.empty()) {
110 return {QStringLiteral("Current Boxcat Events"),
111 tr("There are currently no events on boxcat.")};
112 }
113
114 QString out;
115
116 if (global.has_value()) {
117 out += QStringLiteral("%1<br>").arg(QString::fromStdString(*global));
118 }
119
120 for (const auto& [key, value] : map) {
121 out += QStringLiteral("%1<b>%2</b><br>%3")
122 .arg(out.isEmpty() ? QString{} : QStringLiteral("<br>"))
123 .arg(QString::fromStdString(key))
124 .arg(FormatEventStatusString(value));
125 }
126 return {tr("Current Boxcat Events"), std::move(out)};
127#else
128 return {tr("Current Boxcat Events"), tr("There are currently no events on boxcat.")};
129#endif
130}
131
132void ConfigureNetwork::OnBCATImplChanged() {
133#ifdef YUZU_ENABLE_BOXCAT
134 const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat");
135 ui->bcat_empty_header->setHidden(!boxcat);
136 ui->bcat_empty_label->setHidden(!boxcat);
137 ui->bcat_empty_header->setText(QString{});
138 ui->bcat_empty_label->setText(tr("Yuzu is retrieving the latest boxcat status..."));
139
140 if (!boxcat)
141 return;
142
143 const auto future = QtConcurrent::run([this] { return BCATDownloadEvents(); });
144
145 watcher.setFuture(future);
146 connect(&watcher, &QFutureWatcher<std::pair<QString, QString>>::finished, this,
147 [this] { OnUpdateBCATEmptyLabel(watcher.result()); });
148#endif
149}
150
151void ConfigureNetwork::OnUpdateBCATEmptyLabel(std::pair<QString, QString> string) {
152#ifdef YUZU_ENABLE_BOXCAT
153 const auto boxcat = ui->bcat_source->currentText() == QStringLiteral("Boxcat");
154 if (boxcat) {
155 ui->bcat_empty_header->setText(string.first);
156 ui->bcat_empty_label->setText(string.second);
157 }
158#endif
159}
diff --git a/src/yuzu/configuration/configure_network.h b/src/yuzu/configuration/configure_network.h
index 442b68e6b..028fd4acc 100644
--- a/src/yuzu/configuration/configure_network.h
+++ b/src/yuzu/configuration/configure_network.h
@@ -25,10 +25,5 @@ public:
25private: 25private:
26 void SetConfiguration(); 26 void SetConfiguration();
27 27
28 std::pair<QString, QString> BCATDownloadEvents();
29 void OnBCATImplChanged();
30 void OnUpdateBCATEmptyLabel(std::pair<QString, QString> string);
31
32 std::unique_ptr<Ui::ConfigureNetwork> ui; 28 std::unique_ptr<Ui::ConfigureNetwork> ui;
33 QFutureWatcher<std::pair<QString, QString>> watcher{this};
34}; 29};
diff --git a/src/yuzu/configuration/configure_network.ui b/src/yuzu/configuration/configure_network.ui
index 5f9b7e97b..9a79262f0 100644
--- a/src/yuzu/configuration/configure_network.ui
+++ b/src/yuzu/configuration/configure_network.ui
@@ -35,92 +35,6 @@
35 </layout> 35 </layout>
36 </widget> 36 </widget>
37 </item> 37 </item>
38 <item>
39 <widget class="QGroupBox" name="groupBox">
40 <property name="title">
41 <string>BCAT</string>
42 </property>
43 <layout class="QGridLayout" name="gridLayout">
44 <item row="3" column="0">
45 <widget class="QLabel" name="bcat_empty_header">
46 <property name="text">
47 <string/>
48 </property>
49 <property name="alignment">
50 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
51 </property>
52 <property name="wordWrap">
53 <bool>true</bool>
54 </property>
55 </widget>
56 </item>
57 <item row="0" column="0">
58 <widget class="QLabel" name="label">
59 <property name="maximumSize">
60 <size>
61 <width>16777215</width>
62 <height>16777215</height>
63 </size>
64 </property>
65 <property name="text">
66 <string>BCAT Backend</string>
67 </property>
68 </widget>
69 </item>
70 <item row="1" column="1" colspan="2">
71 <widget class="QLabel" name="label_2">
72 <property name="maximumSize">
73 <size>
74 <width>260</width>
75 <height>16777215</height>
76 </size>
77 </property>
78 <property name="text">
79 <string>BCAT is Nintendo's way of sending data to games to engage its community and unlock additional content.</string>
80 </property>
81 <property name="wordWrap">
82 <bool>true</bool>
83 </property>
84 </widget>
85 </item>
86 <item row="2" column="1" colspan="2">
87 <widget class="QLabel" name="label_3">
88 <property name="text">
89 <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://yuzu-emu.org/help/feature/boxcat&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;Learn more about BCAT, Boxcat, and Current Events&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
90 </property>
91 <property name="openExternalLinks">
92 <bool>true</bool>
93 </property>
94 </widget>
95 </item>
96 <item row="0" column="1" colspan="2">
97 <widget class="QComboBox" name="bcat_source"/>
98 </item>
99 <item row="3" column="1" colspan="2">
100 <widget class="QLabel" name="bcat_empty_label">
101 <property name="enabled">
102 <bool>true</bool>
103 </property>
104 <property name="maximumSize">
105 <size>
106 <width>260</width>
107 <height>16777215</height>
108 </size>
109 </property>
110 <property name="text">
111 <string/>
112 </property>
113 <property name="alignment">
114 <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
115 </property>
116 <property name="wordWrap">
117 <bool>true</bool>
118 </property>
119 </widget>
120 </item>
121 </layout>
122 </widget>
123 </item>
124 </layout> 38 </layout>
125 </item> 39 </item>
126 <item> 40 <item>
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 7eec8f5bb..552c2cc63 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1384,6 +1384,9 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
1384 system.RegisterExecuteProgramCallback( 1384 system.RegisterExecuteProgramCallback(
1385 [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); 1385 [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); });
1386 1386
1387 // Register an Exit callback such that Core can exit the currently running application.
1388 system.RegisterExitCallback([this]() { render_window->Exit(); });
1389
1387 connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); 1390 connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
1388 connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); 1391 connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity);
1389 // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views 1392 // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views
@@ -2469,6 +2472,10 @@ void GMainWindow::OnExecuteProgram(std::size_t program_index) {
2469 BootGame(last_filename_booted, 0, program_index); 2472 BootGame(last_filename_booted, 0, program_index);
2470} 2473}
2471 2474
2475void GMainWindow::OnExit() {
2476 OnStopGame();
2477}
2478
2472void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { 2479void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) {
2473 OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text, 2480 OverlayDialog dialog(render_window, Core::System::GetInstance(), error_code, error_text,
2474 QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter); 2481 QString{}, tr("OK"), Qt::AlignLeft | Qt::AlignVCenter);
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 36eed6103..60ce01471 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -153,6 +153,7 @@ signals:
153public slots: 153public slots:
154 void OnLoadComplete(); 154 void OnLoadComplete();
155 void OnExecuteProgram(std::size_t program_index); 155 void OnExecuteProgram(std::size_t program_index);
156 void OnExit();
156 void ControllerSelectorReconfigureControllers( 157 void ControllerSelectorReconfigureControllers(
157 const Core::Frontend::ControllerParameters& parameters); 158 const Core::Frontend::ControllerParameters& parameters);
158 void SoftwareKeyboardInitialize( 159 void SoftwareKeyboardInitialize(
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index d74eb7e2b..434518d53 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -518,10 +518,6 @@ void Config::ReadValues() {
518 ReadSetting("WebService", Settings::values.web_api_url); 518 ReadSetting("WebService", Settings::values.web_api_url);
519 ReadSetting("WebService", Settings::values.yuzu_username); 519 ReadSetting("WebService", Settings::values.yuzu_username);
520 ReadSetting("WebService", Settings::values.yuzu_token); 520 ReadSetting("WebService", Settings::values.yuzu_token);
521
522 // Services
523 ReadSetting("Services", Settings::values.bcat_backend);
524 ReadSetting("Services", Settings::values.bcat_boxcat_local);
525} 521}
526 522
527void Config::Reload() { 523void Config::Reload() {
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index 72f3213fb..8119a50d8 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -428,11 +428,6 @@ web_api_url = https://api.yuzu-emu.org
428yuzu_username = 428yuzu_username =
429yuzu_token = 429yuzu_token =
430 430
431[Services]
432# The name of the backend to use for BCAT
433# If this is set to 'boxcat' boxcat will be used, otherwise a null implementation will be used
434bcat_backend =
435
436[AddOns] 431[AddOns]
437# Used to disable add-ons 432# Used to disable add-ons
438# List of title IDs of games that will have add-ons disabled (separated by '|'): 433# List of title IDs of games that will have add-ons disabled (separated by '|'):