diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index a2cf13efcd..a96a62457b 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -50,12 +50,12 @@ void VFS::UnMountAll() } } -std::shared_ptr VFS::OpenFile(const wxString& ps3_path, vfsOpenMode mode) const +vfsFileBase* VFS::OpenFile(const wxString& ps3_path, vfsOpenMode mode) const { wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewFileStream()) + if(vfsFileBase* res = dev->GetNewFileStream()) { res->Open(path, mode); return res; @@ -65,13 +65,13 @@ std::shared_ptr VFS::OpenFile(const wxString& ps3_path, vfsOpenMode return nullptr; } -std::shared_ptr VFS::OpenDir(const wxString& ps3_path) const +vfsDirBase* VFS::OpenDir(const wxString& ps3_path) const { wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewDirStream()) + if(vfsDirBase* res = dev->GetNewDirStream()) { res->Open(path); return res; @@ -86,7 +86,9 @@ bool VFS::CreateFile(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewFileStream()) + std::shared_ptr res(dev->GetNewFileStream()); + + if(res) { return res->Create(path); } @@ -100,7 +102,9 @@ bool VFS::CreateDir(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewDirStream()) + std::shared_ptr res(dev->GetNewDirStream()); + + if(res) { return res->Create(path); } @@ -114,7 +118,9 @@ bool VFS::RemoveFile(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewFileStream()) + std::shared_ptr res(dev->GetNewFileStream()); + + if(res) { return res->Remove(path); } @@ -128,7 +134,9 @@ bool VFS::RemoveDir(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewDirStream()) + std::shared_ptr res(dev->GetNewDirStream()); + + if(res) { return res->Remove(path); } @@ -142,7 +150,9 @@ bool VFS::ExistsFile(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewFileStream()) + std::shared_ptr res(dev->GetNewFileStream()); + + if(res) { return res->Exists(path); } @@ -156,7 +166,9 @@ bool VFS::ExistsDir(const wxString& ps3_path) const wxString path; if(vfsDevice* dev = GetDevice(ps3_path, path)) { - if(std::shared_ptr res = dev->GetNewDirStream()) + std::shared_ptr res(dev->GetNewDirStream()); + + if(res) { return res->IsExists(path); } @@ -170,7 +182,9 @@ bool VFS::RenameFile(const wxString& ps3_path_from, const wxString& ps3_path_to) wxString path; if(vfsDevice* dev = GetDevice(ps3_path_from, path)) { - if(std::shared_ptr res = dev->GetNewFileStream()) + std::shared_ptr res(dev->GetNewFileStream()); + + if(res) { return res->Rename(path, ps3_path_to); } @@ -184,7 +198,9 @@ bool VFS::RenameDir(const wxString& ps3_path_from, const wxString& ps3_path_to) wxString path; if(vfsDevice* dev = GetDevice(ps3_path_from, path)) { - if(std::shared_ptr res = dev->GetNewDirStream()) + std::shared_ptr res(dev->GetNewDirStream()); + + if(res) { return res->Rename(path, ps3_path_to); } diff --git a/rpcs3/Emu/FS/VFS.h b/rpcs3/Emu/FS/VFS.h index e10fedea36..8876726bb8 100644 --- a/rpcs3/Emu/FS/VFS.h +++ b/rpcs3/Emu/FS/VFS.h @@ -36,8 +36,8 @@ struct VFS void UnMount(const wxString& ps3_path); void UnMountAll(); - std::shared_ptr OpenFile(const wxString& ps3_path, vfsOpenMode mode) const; - std::shared_ptr OpenDir(const wxString& ps3_path) const; + vfsFileBase* OpenFile(const wxString& ps3_path, vfsOpenMode mode) const; + vfsDirBase* OpenDir(const wxString& ps3_path) const; bool CreateFile(const wxString& ps3_path) const; bool CreateDir(const wxString& ps3_path) const; bool RemoveFile(const wxString& ps3_path) const; diff --git a/rpcs3/Emu/FS/vfsDevice.h b/rpcs3/Emu/FS/vfsDevice.h index 2b52e46c5a..76a9bee378 100644 --- a/rpcs3/Emu/FS/vfsDevice.h +++ b/rpcs3/Emu/FS/vfsDevice.h @@ -12,8 +12,8 @@ public: vfsDevice(const wxString& ps3_path, const wxString& local_path); vfsDevice() {} - virtual std::shared_ptr GetNewFileStream()=0; - virtual std::shared_ptr GetNewDirStream()=0; + virtual vfsFileBase* GetNewFileStream()=0; + virtual vfsDirBase* GetNewDirStream()=0; wxString GetLocalPath() const; wxString GetPs3Path() const; diff --git a/rpcs3/Emu/FS/vfsDeviceLocalFile.cpp b/rpcs3/Emu/FS/vfsDeviceLocalFile.cpp index c89bd8dd2e..3210a268e0 100644 --- a/rpcs3/Emu/FS/vfsDeviceLocalFile.cpp +++ b/rpcs3/Emu/FS/vfsDeviceLocalFile.cpp @@ -3,12 +3,12 @@ #include "vfsLocalFile.h" #include "vfsLocalDir.h" -std::shared_ptr vfsDeviceLocalFile::GetNewFileStream() +vfsFileBase* vfsDeviceLocalFile::GetNewFileStream() { - return std::make_shared(this); + return new vfsLocalFile(this); } -std::shared_ptr vfsDeviceLocalFile::GetNewDirStream() +vfsDirBase* vfsDeviceLocalFile::GetNewDirStream() { - return std::make_shared(this); + return new vfsLocalDir(this); } diff --git a/rpcs3/Emu/FS/vfsDeviceLocalFile.h b/rpcs3/Emu/FS/vfsDeviceLocalFile.h index bab7bfb75c..fc73fa3886 100644 --- a/rpcs3/Emu/FS/vfsDeviceLocalFile.h +++ b/rpcs3/Emu/FS/vfsDeviceLocalFile.h @@ -4,6 +4,6 @@ class vfsDeviceLocalFile : public vfsDevice { public: - virtual std::shared_ptr GetNewFileStream() override; - virtual std::shared_ptr GetNewDirStream() override; + virtual vfsFileBase* GetNewFileStream() override; + virtual vfsDirBase* GetNewDirStream() override; }; \ No newline at end of file diff --git a/rpcs3/Emu/FS/vfsDir.cpp b/rpcs3/Emu/FS/vfsDir.cpp index ff7d7f4a81..7ce119601d 100644 --- a/rpcs3/Emu/FS/vfsDir.cpp +++ b/rpcs3/Emu/FS/vfsDir.cpp @@ -18,7 +18,7 @@ bool vfsDir::Open(const wxString& path) { Close(); - m_stream = Emu.GetVFS().OpenDir(path); + m_stream.reset(Emu.GetVFS().OpenDir(path)); return m_stream && m_stream->IsOpened(); } diff --git a/rpcs3/Emu/FS/vfsFile.cpp b/rpcs3/Emu/FS/vfsFile.cpp index 79d7bd99ed..924b4a80ee 100644 --- a/rpcs3/Emu/FS/vfsFile.cpp +++ b/rpcs3/Emu/FS/vfsFile.cpp @@ -18,7 +18,7 @@ bool vfsFile::Open(const wxString& path, vfsOpenMode mode) { Close(); - m_stream = Emu.GetVFS().OpenFile(path, mode); + m_stream.reset(Emu.GetVFS().OpenFile(path, mode)); return m_stream && m_stream->IsOpened(); } diff --git a/rpcs3/Emu/HDD/HDD.cpp b/rpcs3/Emu/HDD/HDD.cpp index 7281289705..4d8937b4b5 100644 --- a/rpcs3/Emu/HDD/HDD.cpp +++ b/rpcs3/Emu/HDD/HDD.cpp @@ -5,12 +5,12 @@ vfsDeviceHDD::vfsDeviceHDD(const std::string& hdd_path) : m_hdd_path(hdd_path) { } -std::shared_ptr vfsDeviceHDD::GetNewFileStream() +vfsFileBase* vfsDeviceHDD::GetNewFileStream() { - return std::make_shared(this, m_hdd_path); + return new vfsHDD(this, m_hdd_path); } -std::shared_ptr vfsDeviceHDD::GetNewDirStream() +vfsDirBase* vfsDeviceHDD::GetNewDirStream() { return nullptr; } diff --git a/rpcs3/Emu/HDD/HDD.h b/rpcs3/Emu/HDD/HDD.h index b8d4773f08..3478d30fbb 100644 --- a/rpcs3/Emu/HDD/HDD.h +++ b/rpcs3/Emu/HDD/HDD.h @@ -416,8 +416,8 @@ class vfsDeviceHDD : public vfsDevice public: vfsDeviceHDD(const std::string& hdd_path); - virtual std::shared_ptr GetNewFileStream() override; - virtual std::shared_ptr GetNewDirStream() override; + virtual vfsFileBase* GetNewFileStream() override; + virtual vfsDirBase* GetNewDirStream() override; }; class vfsHDD : public vfsFileBase diff --git a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp index 494b542610..a5ada78529 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNpTrophy.cpp @@ -115,7 +115,8 @@ int sceNpTrophyCreateContext(mem32_t context, mem_ptr_t co { if (entry->flags & DirEntry_TypeDir) { - auto f = Emu.GetVFS().OpenFile("/app_home/TROPDIR/" + entry->name + "/TROPHY.TRP", vfsRead); + std::shared_ptr f(Emu.GetVFS().OpenFile("/app_home/TROPDIR/" + entry->name + "/TROPHY.TRP", vfsRead)); + if (f && f->IsOpened()) { sceNpTrophyInternalContext ctxt; diff --git a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp index 0982a7c2d4..f0edaa2e46 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp @@ -35,8 +35,8 @@ bool sdata_check(u32 version, u32 flags, u64 filesizeInput, u64 filesizeTmp) int sdata_unpack(wxString packed_file, wxString unpacked_file) { - auto packed_stream = Emu.GetVFS().OpenFile(packed_file, vfsRead); - auto unpacked_stream = Emu.GetVFS().OpenFile(unpacked_file, vfsWrite); + std::shared_ptr packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead)); + std::shared_ptr unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, vfsWrite)); if(!packed_stream || !packed_stream->IsOpened()) { @@ -126,9 +126,7 @@ int cellFsSdataOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) int ret = sdata_unpack(path, unpacked_path); if (ret) return ret; - auto stream = Emu.GetVFS().OpenFile(unpacked_path, vfsRead); - fd = sys_fs.GetNewId(stream.get(), flags); - stream = nullptr; + fd = sys_fs.GetNewId(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), flags); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp index 59ffd76135..7ec0e6f3c8 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_FileSystem.cpp @@ -67,7 +67,7 @@ int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) return CELL_EINVAL; } - auto stream = Emu.GetVFS().OpenFile(ppath, o_mode); + vfsFileBase* stream = Emu.GetVFS().OpenFile(ppath, o_mode); if(!stream || !stream->IsOpened()) { @@ -75,8 +75,7 @@ int cellFsOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) return CELL_ENOENT; } - fd = sys_fs.GetNewId(stream.get(), flags); - stream = nullptr; + fd = sys_fs.GetNewId(stream, flags); ConLog.Warning("*** cellFsOpen(path=\"%s\"): fd = %d", path.wx_str(), fd.GetValue()); return CELL_OK; @@ -142,14 +141,14 @@ int cellFsOpendir(u32 path_addr, mem32_t fd) if(!Memory.IsGoodAddr(path_addr) || !fd.IsGood()) return CELL_EFAULT; - std::shared_ptr dir = Emu.GetVFS().OpenDir(path); - if(!dir->IsOpened()) + vfsDirBase* dir = Emu.GetVFS().OpenDir(path); + if(!dir || !dir->IsOpened()) { + delete dir; return CELL_ENOENT; } - fd = sys_fs.GetNewId(dir.get()); - dir = nullptr; + fd = sys_fs.GetNewId(dir); return CELL_OK; }