diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index eb0679d358..e148b6638c 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -37,6 +37,9 @@ protected: NonCopyable() {} NonCopyable(const NonCopyable&&) {} void operator=(const NonCopyable&&) {} +private: + NonCopyable(NonCopyable&); + NonCopyable& operator=(NonCopyable& other); }; #endif diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 24f853c0c4..8792321bf0 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -853,7 +853,7 @@ IOFile::IOFile(IOFile&& other) IOFile& IOFile::operator=(IOFile&& other) { - IOFile((IOFile&&)other).Swap(*this); + Swap(other); return *this; } diff --git a/Source/Core/Common/Src/FileUtil.h b/Source/Core/Common/Src/FileUtil.h index b0391f4b74..40aba0037d 100644 --- a/Source/Core/Common/Src/FileUtil.h +++ b/Source/Core/Common/Src/FileUtil.h @@ -211,6 +211,9 @@ public: std::FILE* m_file; bool m_good; +private: + IOFile(IOFile&); + IOFile& operator=(IOFile& other); }; } // namespace diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp index 21a9c94c82..dcad297f7d 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -182,6 +182,10 @@ bool CWII_IPC_HLE_Device_es::Close(u32 _CommandAddress, bool _bForce) { // Leave deletion of the INANDContentLoader objects to CNANDContentManager, don't do it here! m_NANDContent.clear(); + for (auto itr = m_ContentAccessMap.begin(); itr != m_ContentAccessMap.end(); ++itr) + { + delete itr->second.m_pFile; + } m_ContentAccessMap.clear(); m_pContentLoader = NULL; m_TitleIDs.clear(); @@ -222,15 +226,15 @@ u32 CWII_IPC_HLE_Device_es::OpenTitleContent(u32 CFD, u64 TitleID, u16 Index) std::string Filename = pContent->m_Filename; INFO_LOG(WII_IPC_ES, "ES: load %s", Filename.c_str()); - Access.m_File.Open(Filename, "rb"); - if (!Access.m_File.IsGood()) + Access.m_pFile = new File::IOFile(Filename, "rb"); + if (!Access.m_pFile->IsGood()) { WARN_LOG(WII_IPC_ES, "ES: couldn't load %s", Filename.c_str()); return 0xffffffff; } } - m_ContentAccessMap[CFD] = std::move(Access); + m_ContentAccessMap[CFD] = Access; return CFD; } @@ -392,7 +396,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) } else { - File::IOFile* pFile = &rContent.m_File; + auto& pFile = rContent.m_pFile; if (!pFile->Seek(rContent.m_Position, SEEK_SET)) { ERROR_LOG(WII_IPC_ES, "ES: couldn't seek!"); @@ -423,10 +427,18 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) u32 CFD = Memory::Read_U32(Buffer.InBuffer[0].m_Address); - m_ContentAccessMap.erase(CFD); - INFO_LOG(WII_IPC_ES, "IOCTL_ES_CLOSECONTENT: CFD %x", CFD); + auto itr = m_ContentAccessMap.find(CFD); + if (itr == m_ContentAccessMap.end()) + { + Memory::Write_U32(-1, _CommandAddress + 0x4); + return true; + } + + delete itr->second.m_pFile; + m_ContentAccessMap.erase(itr); + Memory::Write_U32(0, _CommandAddress + 0x4); return true; } diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h index f77cea969c..ddc1f3613f 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.h @@ -8,6 +8,7 @@ #include #include "WII_IPC_HLE_Device.h" #include "NANDContentLoader.h" +#include class CWII_IPC_HLE_Device_es : public IWII_IPC_HLE_Device { @@ -112,12 +113,13 @@ private: ES_HASH_SIZE_WRONG = -2014, // HASH !=20 }; - struct SContentAccess : public NonCopyable + struct SContentAccess { u32 m_Position; u64 m_TitleID; const DiscIO::SNANDContent* m_pContent; - File::IOFile m_File; + // This is a (raw) pointer to work around a MSVC bug. + File::IOFile* m_pFile; }; typedef std::map CContentAccessMap;