summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-03 11:51:48 -0400
committerGravatar Zach Hilman2018-08-08 21:18:45 -0400
commit4b471f0554146463f3b82eed14ff3922a5584e9f (patch)
tree677b35914dd914343700be24a1e4098db292615c /src
parentvfs: Add unreachable assert to file permissions converter (diff)
downloadyuzu-4b471f0554146463f3b82eed14ff3922a5584e9f.tar.gz
yuzu-4b471f0554146463f3b82eed14ff3922a5584e9f.tar.xz
yuzu-4b471f0554146463f3b82eed14ff3922a5584e9f.zip
core: Port core to VfsFilesystem for file access
Diffstat (limited to 'src')
-rw-r--r--src/core/core.cpp8
-rw-r--r--src/core/core.h12
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp14
-rw-r--r--src/core/hle/service/filesystem/filesystem.h2
-rw-r--r--src/core/hle/service/service.cpp4
-rw-r--r--src/core/hle/service/service.h7
-rw-r--r--src/yuzu/game_list.cpp7
-rw-r--r--src/yuzu/game_list.h3
-rw-r--r--src/yuzu/game_list_p.h3
-rw-r--r--src/yuzu/main.cpp10
-rw-r--r--src/yuzu/main.h3
-rw-r--r--src/yuzu_cmd/yuzu.cpp1
12 files changed, 52 insertions, 22 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 085ba68d0..69c45c026 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -89,7 +89,7 @@ System::ResultStatus System::SingleStep() {
89} 89}
90 90
91System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& filepath) { 91System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& filepath) {
92 app_loader = Loader::GetLoader(std::make_shared<FileSys::RealVfsFile>(filepath)); 92 app_loader = Loader::GetLoader(virtual_filesystem->OpenFile(filepath, FileSys::Mode::Read));
93 93
94 if (!app_loader) { 94 if (!app_loader) {
95 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); 95 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
@@ -174,6 +174,10 @@ System::ResultStatus System::Init(EmuWindow& emu_window) {
174 174
175 CoreTiming::Init(); 175 CoreTiming::Init();
176 176
177 // Create a default fs if one doesn't already exist.
178 if (virtual_filesystem == nullptr)
179 virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>();
180
177 current_process = Kernel::Process::Create("main"); 181 current_process = Kernel::Process::Create("main");
178 182
179 cpu_barrier = std::make_shared<CpuBarrier>(); 183 cpu_barrier = std::make_shared<CpuBarrier>();
@@ -186,7 +190,7 @@ System::ResultStatus System::Init(EmuWindow& emu_window) {
186 service_manager = std::make_shared<Service::SM::ServiceManager>(); 190 service_manager = std::make_shared<Service::SM::ServiceManager>();
187 191
188 Kernel::Init(); 192 Kernel::Init();
189 Service::Init(service_manager); 193 Service::Init(service_manager, virtual_filesystem);
190 GDBStub::Init(); 194 GDBStub::Init();
191 195
192 renderer = VideoCore::CreateRenderer(emu_window); 196 renderer = VideoCore::CreateRenderer(emu_window);
diff --git a/src/core/core.h b/src/core/core.h
index c8ca4b247..7cf7ea4e1 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -17,6 +17,8 @@
17#include "core/memory.h" 17#include "core/memory.h"
18#include "core/perf_stats.h" 18#include "core/perf_stats.h"
19#include "core/telemetry_session.h" 19#include "core/telemetry_session.h"
20#include "file_sys/vfs_real.h"
21#include "hle/service/filesystem/filesystem.h"
20#include "video_core/debug_utils/debug_utils.h" 22#include "video_core/debug_utils/debug_utils.h"
21#include "video_core/gpu.h" 23#include "video_core/gpu.h"
22 24
@@ -211,6 +213,14 @@ public:
211 return debug_context; 213 return debug_context;
212 } 214 }
213 215
216 void SetFilesystem(FileSys::VirtualFilesystem vfs) {
217 virtual_filesystem = std::move(vfs);
218 }
219
220 FileSys::VirtualFilesystem GetFilesystem() const {
221 return virtual_filesystem;
222 }
223
214private: 224private:
215 System(); 225 System();
216 226
@@ -225,6 +235,8 @@ private:
225 */ 235 */
226 ResultStatus Init(EmuWindow& emu_window); 236 ResultStatus Init(EmuWindow& emu_window);
227 237
238 /// RealVfsFilesystem instance
239 FileSys::VirtualFilesystem virtual_filesystem;
228 /// AppLoader used to load the current executing application 240 /// AppLoader used to load the current executing application
229 std::unique_ptr<Loader::AppLoader> app_loader; 241 std::unique_ptr<Loader::AppLoader> app_loader;
230 std::unique_ptr<VideoCore::RendererBase> renderer; 242 std::unique_ptr<VideoCore::RendererBase> renderer;
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index 9b87e3484..5e416cde2 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -281,15 +281,15 @@ ResultVal<FileSys::VirtualDir> OpenSDMC() {
281 return sdmc_factory->Open(); 281 return sdmc_factory->Open();
282} 282}
283 283
284void RegisterFileSystems() { 284void RegisterFileSystems(const FileSys::VirtualFilesystem& vfs) {
285 romfs_factory = nullptr; 285 romfs_factory = nullptr;
286 save_data_factory = nullptr; 286 save_data_factory = nullptr;
287 sdmc_factory = nullptr; 287 sdmc_factory = nullptr;
288 288
289 auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( 289 auto nand_directory = vfs->OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir),
290 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::ReadWrite); 290 FileSys::Mode::ReadWrite);
291 auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( 291 auto sd_directory = vfs->OpenDirectory(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir),
292 FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::ReadWrite); 292 FileSys::Mode::ReadWrite);
293 293
294 auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); 294 auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory));
295 save_data_factory = std::move(savedata); 295 save_data_factory = std::move(savedata);
@@ -298,8 +298,8 @@ void RegisterFileSystems() {
298 sdmc_factory = std::move(sdcard); 298 sdmc_factory = std::move(sdcard);
299} 299}
300 300
301void InstallInterfaces(SM::ServiceManager& service_manager) { 301void InstallInterfaces(SM::ServiceManager& service_manager, const FileSys::VirtualFilesystem& vfs) {
302 RegisterFileSystems(); 302 RegisterFileSystems(vfs);
303 std::make_shared<FSP_LDR>()->InstallAsService(service_manager); 303 std::make_shared<FSP_LDR>()->InstallAsService(service_manager);
304 std::make_shared<FSP_PR>()->InstallAsService(service_manager); 304 std::make_shared<FSP_PR>()->InstallAsService(service_manager);
305 std::make_shared<FSP_SRV>()->InstallAsService(service_manager); 305 std::make_shared<FSP_SRV>()->InstallAsService(service_manager);
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h
index d4483daa5..462c13f20 100644
--- a/src/core/hle/service/filesystem/filesystem.h
+++ b/src/core/hle/service/filesystem/filesystem.h
@@ -36,7 +36,7 @@ ResultVal<FileSys::VirtualDir> OpenSDMC();
36// ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenBIS(); 36// ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenBIS();
37 37
38/// Registers all Filesystem services with the specified service manager. 38/// Registers all Filesystem services with the specified service manager.
39void InstallInterfaces(SM::ServiceManager& service_manager); 39void InstallInterfaces(SM::ServiceManager& service_manager, const FileSys::VirtualFilesystem& vfs);
40 40
41// A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of 41// A class that wraps a VfsDirectory with methods that return ResultVal and ResultCode instead of
42// pointers and booleans. This makes using a VfsDirectory with switch services much easier and 42// pointers and booleans. This makes using a VfsDirectory with switch services much easier and
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 6f286ea74..11951adaf 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -198,7 +198,7 @@ void AddNamedPort(std::string name, SharedPtr<ClientPort> port) {
198} 198}
199 199
200/// Initialize ServiceManager 200/// Initialize ServiceManager
201void Init(std::shared_ptr<SM::ServiceManager>& sm) { 201void Init(std::shared_ptr<SM::ServiceManager>& sm, const FileSys::VirtualFilesystem& rfs) {
202 // NVFlinger needs to be accessed by several services like Vi and AppletOE so we instantiate it 202 // NVFlinger needs to be accessed by several services like Vi and AppletOE so we instantiate it
203 // here and pass it into the respective InstallInterfaces functions. 203 // here and pass it into the respective InstallInterfaces functions.
204 auto nv_flinger = std::make_shared<NVFlinger::NVFlinger>(); 204 auto nv_flinger = std::make_shared<NVFlinger::NVFlinger>();
@@ -221,7 +221,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm) {
221 EUPLD::InstallInterfaces(*sm); 221 EUPLD::InstallInterfaces(*sm);
222 Fatal::InstallInterfaces(*sm); 222 Fatal::InstallInterfaces(*sm);
223 FGM::InstallInterfaces(*sm); 223 FGM::InstallInterfaces(*sm);
224 FileSystem::InstallInterfaces(*sm); 224 FileSystem::InstallInterfaces(*sm, rfs);
225 Friend::InstallInterfaces(*sm); 225 Friend::InstallInterfaces(*sm);
226 GRC::InstallInterfaces(*sm); 226 GRC::InstallInterfaces(*sm);
227 HID::InstallInterfaces(*sm); 227 HID::InstallInterfaces(*sm);
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 046c5e18d..8a294c0f2 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -22,6 +22,10 @@ class ServerSession;
22class HLERequestContext; 22class HLERequestContext;
23} // namespace Kernel 23} // namespace Kernel
24 24
25namespace FileSys {
26struct VfsFilesystem;
27}
28
25namespace Service { 29namespace Service {
26 30
27namespace SM { 31namespace SM {
@@ -177,7 +181,8 @@ private:
177}; 181};
178 182
179/// Initialize ServiceManager 183/// Initialize ServiceManager
180void Init(std::shared_ptr<SM::ServiceManager>& sm); 184void Init(std::shared_ptr<SM::ServiceManager>& sm,
185 const std::shared_ptr<FileSys::VfsFilesystem>& vfs);
181 186
182/// Shutdown ServiceManager 187/// Shutdown ServiceManager
183void Shutdown(); 188void Shutdown();
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp
index 5f47f5a2b..e150a0684 100644
--- a/src/yuzu/game_list.cpp
+++ b/src/yuzu/game_list.cpp
@@ -197,7 +197,8 @@ void GameList::onFilterCloseClicked() {
197 main_window->filterBarSetChecked(false); 197 main_window->filterBarSetChecked(false);
198} 198}
199 199
200GameList::GameList(GMainWindow* parent) : QWidget{parent} { 200GameList::GameList(FileSys::VirtualFilesystem vfs, GMainWindow* parent)
201 : QWidget{parent}, vfs(std::move(vfs)) {
201 watcher = new QFileSystemWatcher(this); 202 watcher = new QFileSystemWatcher(this);
202 connect(watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory); 203 connect(watcher, &QFileSystemWatcher::directoryChanged, this, &GameList::RefreshGameDirectory);
203 204
@@ -341,7 +342,7 @@ void GameList::PopulateAsync(const QString& dir_path, bool deep_scan) {
341 342
342 emit ShouldCancelWorker(); 343 emit ShouldCancelWorker();
343 344
344 GameListWorker* worker = new GameListWorker(dir_path, deep_scan); 345 GameListWorker* worker = new GameListWorker(vfs, dir_path, deep_scan);
345 346
346 connect(worker, &GameListWorker::EntryReady, this, &GameList::AddEntry, Qt::QueuedConnection); 347 connect(worker, &GameListWorker::EntryReady, this, &GameList::AddEntry, Qt::QueuedConnection);
347 connect(worker, &GameListWorker::Finished, this, &GameList::DonePopulating, 348 connect(worker, &GameListWorker::Finished, this, &GameList::DonePopulating,
@@ -436,7 +437,7 @@ void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, unsign
436 if (!is_dir && 437 if (!is_dir &&
437 (HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) { 438 (HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
438 std::unique_ptr<Loader::AppLoader> loader = 439 std::unique_ptr<Loader::AppLoader> loader =
439 Loader::GetLoader(std::make_shared<FileSys::RealVfsFile>(physical_name)); 440 Loader::GetLoader(vfs->OpenFile(physical_name, FileSys::Mode::Read));
440 if (!loader || ((loader->GetFileType() == Loader::FileType::Unknown || 441 if (!loader || ((loader->GetFileType() == Loader::FileType::Unknown ||
441 loader->GetFileType() == Loader::FileType::Error) && 442 loader->GetFileType() == Loader::FileType::Error) &&
442 !UISettings::values.show_unknown)) 443 !UISettings::values.show_unknown))
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h
index 3bc14f07f..afe624b32 100644
--- a/src/yuzu/game_list.h
+++ b/src/yuzu/game_list.h
@@ -59,7 +59,7 @@ public:
59 QToolButton* button_filter_close = nullptr; 59 QToolButton* button_filter_close = nullptr;
60 }; 60 };
61 61
62 explicit GameList(GMainWindow* parent = nullptr); 62 explicit GameList(FileSys::VirtualFilesystem vfs, GMainWindow* parent = nullptr);
63 ~GameList() override; 63 ~GameList() override;
64 64
65 void clearFilter(); 65 void clearFilter();
@@ -90,6 +90,7 @@ private:
90 void PopupContextMenu(const QPoint& menu_location); 90 void PopupContextMenu(const QPoint& menu_location);
91 void RefreshGameDirectory(); 91 void RefreshGameDirectory();
92 92
93 FileSys::VirtualFilesystem vfs;
93 SearchField* search_field; 94 SearchField* search_field;
94 GMainWindow* main_window = nullptr; 95 GMainWindow* main_window = nullptr;
95 QVBoxLayout* layout = nullptr; 96 QVBoxLayout* layout = nullptr;
diff --git a/src/yuzu/game_list_p.h b/src/yuzu/game_list_p.h
index a22025e67..49a3f6181 100644
--- a/src/yuzu/game_list_p.h
+++ b/src/yuzu/game_list_p.h
@@ -139,7 +139,7 @@ class GameListWorker : public QObject, public QRunnable {
139 Q_OBJECT 139 Q_OBJECT
140 140
141public: 141public:
142 GameListWorker(QString dir_path, bool deep_scan) 142 GameListWorker(FileSys::VirtualFilesystem vfs, QString dir_path, bool deep_scan)
143 : dir_path(std::move(dir_path)), deep_scan(deep_scan) {} 143 : dir_path(std::move(dir_path)), deep_scan(deep_scan) {}
144 144
145public slots: 145public slots:
@@ -163,6 +163,7 @@ signals:
163 void Finished(QStringList watch_list); 163 void Finished(QStringList watch_list);
164 164
165private: 165private:
166 FileSys::VirtualFilesystem vfs;
166 QStringList watch_list; 167 QStringList watch_list;
167 QString dir_path; 168 QString dir_path;
168 bool deep_scan; 169 bool deep_scan;
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index a6241e63e..f7812a392 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -24,6 +24,7 @@
24#include "common/string_util.h" 24#include "common/string_util.h"
25#include "core/core.h" 25#include "core/core.h"
26#include "core/crypto/key_manager.h" 26#include "core/crypto/key_manager.h"
27#include "core/file_sys/vfs_real.h"
27#include "core/gdbstub/gdbstub.h" 28#include "core/gdbstub/gdbstub.h"
28#include "core/loader/loader.h" 29#include "core/loader/loader.h"
29#include "core/settings.h" 30#include "core/settings.h"
@@ -81,9 +82,9 @@ static void ShowCalloutMessage(const QString& message, CalloutFlag flag) {
81 82
82void GMainWindow::ShowCallouts() {} 83void GMainWindow::ShowCallouts() {}
83 84
84const int GMainWindow::max_recent_files_item; 85GMainWindow::GMainWindow()
85 86 : config(new Config()), emu_thread(nullptr),
86GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { 87 vfs(std::make_shared<FileSys::RealVfsFilesystem>()) {
87 88
88 debug_context = Tegra::DebugContext::Construct(); 89 debug_context = Tegra::DebugContext::Construct();
89 90
@@ -132,7 +133,7 @@ void GMainWindow::InitializeWidgets() {
132 render_window = new GRenderWindow(this, emu_thread.get()); 133 render_window = new GRenderWindow(this, emu_thread.get());
133 render_window->hide(); 134 render_window->hide();
134 135
135 game_list = new GameList(this); 136 game_list = new GameList(vfs, this);
136 ui.horizontalLayout->addWidget(game_list); 137 ui.horizontalLayout->addWidget(game_list);
137 138
138 // Create status bar 139 // Create status bar
@@ -406,6 +407,7 @@ bool GMainWindow::LoadROM(const QString& filename) {
406 } 407 }
407 408
408 Core::System& system{Core::System::GetInstance()}; 409 Core::System& system{Core::System::GetInstance()};
410 system.SetFilesystem(vfs);
409 411
410 system.SetGPUDebugContext(debug_context); 412 system.SetGPUDebugContext(debug_context);
411 413
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 6e335b8f8..74487c58c 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -161,6 +161,9 @@ private:
161 bool emulation_running = false; 161 bool emulation_running = false;
162 std::unique_ptr<EmuThread> emu_thread; 162 std::unique_ptr<EmuThread> emu_thread;
163 163
164 // FS
165 FileSys::VirtualFilesystem vfs;
166
164 // Debugger panes 167 // Debugger panes
165 ProfilerWidget* profilerWidget; 168 ProfilerWidget* profilerWidget;
166 MicroProfileDialog* microProfileDialog; 169 MicroProfileDialog* microProfileDialog;
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index d637dbd0c..0605c92e3 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -161,6 +161,7 @@ int main(int argc, char** argv) {
161 } 161 }
162 162
163 Core::System& system{Core::System::GetInstance()}; 163 Core::System& system{Core::System::GetInstance()};
164 system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>());
164 165
165 SCOPE_EXIT({ system.Shutdown(); }); 166 SCOPE_EXIT({ system.Shutdown(); });
166 167