From: <man...@us...> - 2014-10-20 13:33:11
|
Revision: 4452 http://sourceforge.net/p/modplug/code/4452 Author: manxorist Date: 2014-10-20 13:32:53 +0000 (Mon, 20 Oct 2014) Log Message: ----------- [Ref] If applicable, make CMappedFile and FileReader aware of the filename they are currently representing. Modified Paths: -------------- trunk/OpenMPT/mptrack/MemoryMappedFile.cpp trunk/OpenMPT/mptrack/MemoryMappedFile.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/soundlib/FileReader.h trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/Load_mt2.cpp Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.cpp =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2014-10-20 13:32:53 UTC (rev 4452) @@ -38,6 +38,7 @@ m_hFile = nullptr; return false; } + m_FileName = filename; return true; } @@ -45,6 +46,7 @@ void CMappedFile::Close() //----------------------- { + m_FileName = mpt::PathString(); // Unlock file if(m_hFMap) { @@ -141,7 +143,7 @@ FileReader CMappedFile::GetFile() //------------------------------- { - return FileReader(Lock(), GetLength()); + return FileReader(Lock(), GetLength(), &m_FileName); } Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.h =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.h 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.h 2014-10-20 13:32:53 UTC (rev 4452) @@ -25,6 +25,7 @@ HANDLE m_hFile; HANDLE m_hFMap; void *m_pData; + mpt::PathString m_FileName; public: CMappedFile() : m_hFile(nullptr), m_hFMap(nullptr), m_pData(nullptr) { } Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2014-10-20 13:32:53 UTC (rev 4452) @@ -221,7 +221,7 @@ BeginWaitCursor(); #if defined(MPT_FILEREADER_STD_ISTREAM) mpt::ifstream f(filename, std::ios_base::binary); - m_SndFile.Create(FileReader(&f), CSoundFile::loadCompleteModule, this); + m_SndFile.Create(FileReader(&f, &filename), CSoundFile::loadCompleteModule, this); #else { CMappedFile f; Modified: trunk/OpenMPT/soundlib/FileReader.h =================================================================== --- trunk/OpenMPT/soundlib/FileReader.h 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/soundlib/FileReader.h 2014-10-20 13:32:53 UTC (rev 4452) @@ -57,42 +57,82 @@ off_t streamPos; // Cursor location in the file +#if defined(MODPLUG_TRACKER) + mpt::PathString *fileName; // Filename that corresponds to this FileReader. It is only set if this FileReader represents the whole contents of fileName. May be nullptr. + #define MPT_FILEREADER_INIT_FILENAME ,fileName(nullptr) +#else + #define MPT_FILEREADER_INIT_FILENAME +#endif + public: #if defined(MPT_FILEREADER_STD_ISTREAM) // Initialize invalid file reader object. - FileReader() : data(new FileDataContainerDummy()), streamPos(0) { } + FileReader() : data(new FileDataContainerDummy()), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } // Initialize file reader object with pointer to data and data length. - FileReader(const void *voiddata, off_t length) : data(new FileDataContainerMemory(static_cast<const char *>(voiddata), length)), streamPos(0) { } - FileReader(const char *chardata, off_t length) : data(new FileDataContainerMemory(chardata, length)), streamPos(0) { } - FileReader(const uint8 *uint8data, off_t length) : data(new FileDataContainerMemory(reinterpret_cast<const char *>(uint8data), length)), streamPos(0) { } + FileReader(const void *voiddata, off_t length) : data(new FileDataContainerMemory(static_cast<const char *>(voiddata), length)), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } + FileReader(const char *chardata, off_t length) : data(new FileDataContainerMemory(chardata, length)), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } + FileReader(const uint8 *uint8data, off_t length) : data(new FileDataContainerMemory(reinterpret_cast<const char *>(uint8data), length)), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } +#if defined(MODPLUG_TRACKER) + FileReader(const void *voiddata, off_t length, mpt::PathString *filename) : data(new FileDataContainerMemory(static_cast<const char *>(voiddata), length)), streamPos(0), fileName(filename) { } + FileReader(const char *chardata, off_t length, mpt::PathString *filename) : data(new FileDataContainerMemory(chardata, length)), streamPos(0), fileName(filename) { } + FileReader(const uint8 *uint8data, off_t length, mpt::PathString *filename) : data(new FileDataContainerMemory(reinterpret_cast<const char *>(uint8data), length)), streamPos(0), fileName(filename) { } +#endif // Initialize file reader object with a std::istream. - FileReader(std::istream *s) : data(new FileDataContainerStdStream(s)), streamPos(0) { } + FileReader(std::istream *s) : data(new FileDataContainerStdStream(s)), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } +#if defined(MODPLUG_TRACKER) + FileReader(std::istream *s, mpt::PathString *filename) : data(new FileDataContainerStdStream(s)), streamPos(0), fileName(filename) { } +#endif // Initialize file reader object based on an existing file reader object window. - FileReader(MPT_SHARED_PTR<IFileDataContainer> other) : data(other), streamPos(0) { } + FileReader(MPT_SHARED_PTR<IFileDataContainer> other) : data(other), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } // Initialize file reader object based on an existing file reader object. The other object's stream position is copied. - FileReader(const FileReader &other) : data(other.data), streamPos(other.streamPos) { } + FileReader(const FileReader &other) : data(other.data), streamPos(other.streamPos) +#if defined(MODPLUG_TRACKER) + , fileName(other.fileName) +#endif + { } #else // Initialize invalid file reader object. - FileReader() : data(nullptr, 0), streamPos(0) { } + FileReader() : data(nullptr, 0), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } // Initialize file reader object with pointer to data and data length. - FileReader(const void *voiddata, off_t length) : data(static_cast<const char *>(voiddata), length), streamPos(0) { } - FileReader(const char *chardata, off_t length) : data(chardata, length), streamPos(0) { } - FileReader(const uint8 *uint8data, off_t length) : data(reinterpret_cast<const char *>(uint8data), length), streamPos(0) { } + FileReader(const void *voiddata, off_t length) : data(static_cast<const char *>(voiddata), length), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } + FileReader(const char *chardata, off_t length) : data(chardata, length), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } + FileReader(const uint8 *uint8data, off_t length) : data(reinterpret_cast<const char *>(uint8data), length), streamPos(0) MPT_FILEREADER_INIT_FILENAME { } +#if defined(MODPLUG_TRACKER) + FileReader(const void *voiddata, off_t length, mpt::PathString *filename) : data(static_cast<const char *>(voiddata), length), streamPos(0), fileName(filename) { } + FileReader(const char *chardata, off_t length, mpt::PathString *filename) : data(chardata, length), streamPos(0), fileName(filename) { } + FileReader(const uint8 *uint8data, off_t length, mpt::PathString *filename) : data(reinterpret_cast<const char *>(uint8data), length), streamPos(0), fileName(filename) { } +#endif // Initialize file reader object based on an existing file reader object. The other object's stream position is copied. - FileReader(const FileReader &other) : data(other.data), streamPos(other.streamPos) { } + FileReader(const FileReader &other) : data(other.data), streamPos(other.streamPos) +#if defined(MODPLUG_TRACKER) + , fileName(other.fileName) +#endif + { } #endif + +#if defined(MODPLUG_TRACKER) + mpt::PathString GetFileName() const + { + if(!fileName) + { + return mpt::PathString(); + } + return *fileName; + } +#endif + // Returns true if the object points to a valid stream. bool IsValid() const { Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2014-10-20 13:32:53 UTC (rev 4452) @@ -166,8 +166,11 @@ } m_szInstrumentPath[ins] = mpt::PathString::FromUTF8(path); - if(GetpModDoc() != nullptr) + if(!file.GetFileName().empty()) { + m_szInstrumentPath[ins] = m_szInstrumentPath[ins].RelativePathToAbsolute(file.GetFileName().GetPath()); + } else if(GetpModDoc() != nullptr) + { m_szInstrumentPath[ins] = m_szInstrumentPath[ins].RelativePathToAbsolute(GetpModDoc()->GetPathNameMpt().GetPath()); } } @@ -264,7 +267,7 @@ mpt::ifstream f(m_szInstrumentPath[ins], std::ios_base::binary); if(!f.good()) continue; - FileReader file(&f); + FileReader file(&f, &m_szInstrumentPath[ins]); #else CMappedFile f; if(!f.Open(m_szInstrumentPath[ins])) Modified: trunk/OpenMPT/soundlib/Load_mt2.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mt2.cpp 2014-10-20 13:31:38 UTC (rev 4451) +++ trunk/OpenMPT/soundlib/Load_mt2.cpp 2014-10-20 13:32:53 UTC (rev 4452) @@ -1060,8 +1060,16 @@ #ifdef MODPLUG_TRACKER mpt::PathString path(mpt::PathString::FromLocale(filename)); - if(GetpModDoc() != nullptr) + mpt::PathString mt2FileName; + if(!file.GetFileName().empty()) { + mt2FileName = file.GetFileName(); + } else if(GetpModDoc() != nullptr) + { + mt2FileName = GetpModDoc()->GetPathNameMpt(); + } + if(!mt2FileName.empty()) + { std::wstring pathStart = path.ToWide().substr(0, 2); if(pathStart.length() >= 2 && pathStart.at(0) != L'\\' @@ -1070,13 +1078,13 @@ // Relative path in sub directory path = MPT_PATHSTRING(".\\") + path; } - path = path.RelativePathToAbsolute(GetpModDoc()->GetPathNameMpt().GetPath()); + path = path.RelativePathToAbsolute(mt2FileName.GetPath()); } #if defined(MPT_FILEREADER_STD_ISTREAM) mpt::ifstream f(path, std::ios_base::binary); if(f.good()) - sampleFile = FileReader(&f); + sampleFile = FileReader(&f, &path); #else CMappedFile f; FileReader sampleFile; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |