diff options
| author | Lioncash <mathew1800@gmail.com> | 2015-12-06 23:15:51 -0500 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2015-12-07 05:57:37 -0500 |
| commit | edbbf493f807ed94b9b32cfb7463f9b7f8f27852 (patch) | |
| tree | 1babef3faeba508560effc1db476cbb722a9a709 /Source/Core/DiscIO/FileMonitor.cpp | |
| parent | a0ac2b867368aa6f82ee3c471fea2cf1a450b37c (diff) | |
DiscIO: Make factory methods return unique_ptrs
Rather than rely on the developer to do the right thing,
just make the default behavior safely deallocate resources.
If shared semantics are ever needed in the future, the
constructor that takes a unique_ptr for shared_ptr can
be used.
Diffstat (limited to 'Source/Core/DiscIO/FileMonitor.cpp')
| -rw-r--r-- | Source/Core/DiscIO/FileMonitor.cpp | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/Source/Core/DiscIO/FileMonitor.cpp b/Source/Core/DiscIO/FileMonitor.cpp index 0583d17a44..469fa4d460 100644 --- a/Source/Core/DiscIO/FileMonitor.cpp +++ b/Source/Core/DiscIO/FileMonitor.cpp @@ -5,6 +5,7 @@ #include <algorithm> #include <cctype> #include <cstring> +#include <memory> #include <string> #include <unordered_set> #include <vector> @@ -25,8 +26,8 @@ namespace FileMon { -static DiscIO::IVolume *OpenISO = nullptr; -static DiscIO::IFileSystem *pFileSystem = nullptr; +static std::unique_ptr<DiscIO::IVolume> s_open_iso; +static std::unique_ptr<DiscIO::IFileSystem> s_filesystem; static std::string ISOFile = "", CurrentFile = ""; static bool FileAccess = true; @@ -61,26 +62,18 @@ bool IsSoundFile(const std::string& filename) void ReadFileSystem(const std::string& filename) { // Should have an actual Shutdown procedure or something - if (OpenISO != nullptr) - { - delete OpenISO; - OpenISO = nullptr; - } - if (pFileSystem != nullptr) - { - delete pFileSystem; - pFileSystem = nullptr; - } + s_open_iso.reset(); + s_filesystem.reset(); - OpenISO = DiscIO::CreateVolumeFromFilename(filename); - if (!OpenISO) + s_open_iso = DiscIO::CreateVolumeFromFilename(filename); + if (!s_open_iso) return; - if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD) + if (s_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD) { - pFileSystem = DiscIO::CreateFileSystem(OpenISO); + s_filesystem = DiscIO::CreateFileSystem(s_open_iso.get()); - if (!pFileSystem) + if (!s_filesystem) return; } @@ -130,7 +123,7 @@ void FindFilename(u64 offset) if (!FileAccess) return; - if (!pFileSystem || ISOFile != SConfig::GetInstance().m_LastFilename) + if (!s_filesystem || ISOFile != SConfig::GetInstance().m_LastFilename) { FileAccess = false; ReadFileSystem(SConfig::GetInstance().m_LastFilename); @@ -139,27 +132,18 @@ void FindFilename(u64 offset) return; } - const std::string filename = pFileSystem->GetFileName(offset); + const std::string filename = s_filesystem->GetFileName(offset); if (filename.empty()) return; - CheckFile(filename, pFileSystem->GetFileSize(filename)); + CheckFile(filename, s_filesystem->GetFileSize(filename)); } void Close() { - if (OpenISO != nullptr) - { - delete OpenISO; - OpenISO = nullptr; - } - - if (pFileSystem != nullptr) - { - delete pFileSystem; - pFileSystem = nullptr; - } + s_open_iso.reset(); + s_filesystem.reset(); ISOFile = ""; CurrentFile = ""; |
