From: <man...@us...> - 2013-04-16 16:40:39
|
Revision: 1891 http://sourceforge.net/p/modplug/code/1891 Author: manxorist Date: 2013-04-16 16:40:31 +0000 (Tue, 16 Apr 2013) Log Message: ----------- [Ref] Move handling of the different archive formats out of soundlib and into the unarchiver project. Modified Paths: -------------- trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/unarchiver/unarchiver_08.vcproj trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj.filters Added Paths: ----------- trunk/OpenMPT/unarchiver/unarchiver.cpp trunk/OpenMPT/unarchiver/unarchiver.h Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-16 15:22:13 UTC (rev 1890) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-16 16:40:31 UTC (rev 1891) @@ -24,29 +24,11 @@ #ifndef NO_MMCMP_SUPPORT #define MMCMP_SUPPORT #endif // NO_MMCMP_SUPPORT + #ifndef NO_ARCHIVE_SUPPORT -#define UNRAR_SUPPORT -#define UNLHA_SUPPORT -#define UNGZIP_SUPPORT -#define ZIPPED_MOD_SUPPORT +#include "../unarchiver/unarchiver.h" #endif // NO_ARCHIVE_SUPPORT -#ifdef ZIPPED_MOD_SUPPORT -#include "../unarchiver/unzip.h" -#endif - -#ifdef UNRAR_SUPPORT -#include "../unarchiver/unrar.h" -#endif - -#ifdef UNLHA_SUPPORT -#include "../unarchiver/unlha.h" -#endif - -#ifdef UNGZIP_SUPPORT -#include "../unarchiver/ungzip.h" -#endif - #ifdef MMCMP_SUPPORT extern BOOL MMCMP_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength); #endif @@ -543,50 +525,15 @@ { FileReader file(lpStream, dwMemLength); - const std::vector<const char *> modExtensions = GetSupportedExtensions(true); - -#ifdef ZIPPED_MOD_SUPPORT - CZipArchive unzip(file, modExtensions); - if(unzip.IsArchive() && unzip.ExtractFile()) +#ifndef NO_ARCHIVE_SUPPORT + CUnarchiver unarchiver(file, GetSupportedExtensions(true)); + if(unarchiver.IsArchive() && unarchiver.ExtractFile()) { - file = unzip.GetOutputFile(); + file = unarchiver.GetOutputFile(); lpStream = (LPCBYTE)file.GetRawData(); dwMemLength = file.GetLength(); } #endif -#ifdef UNRAR_SUPPORT - CRarArchive unrar((LPBYTE)lpStream, dwMemLength); - if(unrar.IsArchive()) - { - if(unrar.ExtrFile() && unrar.GetOutputFile()) - { - lpStream = unrar.GetOutputFile(); - dwMemLength = unrar.GetOutputFileLength(); - file = FileReader(lpStream, dwMemLength); - } - } -#endif -#ifdef UNLHA_SUPPORT - CLhaArchive unlha((LPBYTE)lpStream, dwMemLength); - if(unlha.IsArchive()) - { - if(unlha.ExtractFile() && unlha.GetOutputFile()) - { - lpStream = unlha.GetOutputFile(); - dwMemLength = unlha.GetOutputFileLength(); - file = FileReader(lpStream, dwMemLength); - } - } -#endif -#ifdef UNGZIP_SUPPORT - CGzipArchive ungzip(file); - if(ungzip.IsArchive() && ungzip.ExtractFile()) - { - file = ungzip.GetOutputFile(); - lpStream = (LPCBYTE)file.GetRawData(); - dwMemLength = file.GetLength(); - } -#endif #ifdef MMCMP_SUPPORT BOOL bMMCmp = MMCMP_Unpack(&lpStream, &dwMemLength); @@ -639,11 +586,11 @@ m_nType = MOD_TYPE_NONE; } -#ifdef ZIPPED_MOD_SUPPORT +#ifndef NO_ARCHIVE_SUPPORT // Read archive comment if there is no song comment - if(!songMessage.empty() && unzip.GetComments(false)) + if(!songMessage.empty() && unarchiver.GetComments(false)) { - songMessage.assign(unzip.GetComments(true)); + songMessage.assign(unarchiver.GetComments(true)); } #endif #ifdef MMCMP_SUPPORT Added: trunk/OpenMPT/unarchiver/unarchiver.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver.cpp (rev 0) +++ trunk/OpenMPT/unarchiver/unarchiver.cpp 2013-04-16 16:40:31 UTC (rev 1891) @@ -0,0 +1,102 @@ +/* + * unarchiver.cpp + * -------------- + * Purpose: archive loader + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#include "../common/stdafx.h" + +#include "unarchiver.h" + +#include "../soundlib/FileReader.h" + +CUnarchiver::CUnarchiver(FileReader &file, const std::vector<const char *> &extensions) : +inFile(file), +zipArchive(inFile, extensions), +rarArchive((LPBYTE)inFile.GetRawData(), inFile.GetLength()), +lhaArchive((LPBYTE)inFile.GetRawData(), inFile.GetLength()), +gzipArchive(inFile) +//--------------------------------------------------------------------------------- +{ + inFile.Rewind(); +} + + +CUnarchiver::~CUnarchiver() +//------------------------- +{ + return; +} + + +bool CUnarchiver::IsArchive() const +//--------------------------------- +{ + return false +#ifdef ZIPPED_MOD_SUPPORT + || zipArchive.IsArchive() +#endif +#ifdef UNRAR_SUPPORT + || rarArchive.IsArchive() +#endif +#ifdef UNLHA_SUPPORT + || lhaArchive.IsArchive() +#endif +#ifdef UNGZIP_SUPPORT + || gzipArchive.IsArchive() +#endif + ; +} + + +bool CUnarchiver::ExtractFile() +//----------------------------- +{ +#ifdef ZIPPED_MOD_SUPPORT + if(zipArchive.IsArchive()) + { + if(!zipArchive.ExtractFile()) return false; + outFile = zipArchive.GetOutputFile(); + return outFile.GetRawData()?true:false; + } +#endif +#ifdef UNRAR_SUPPORT + if(rarArchive.IsArchive()) + { + if(!rarArchive.ExtrFile()) return false; + outFile = FileReader(rarArchive.GetOutputFile(), rarArchive.GetOutputFileLength()); + return outFile.GetRawData()?true:false; + } +#endif +#ifdef UNLHA_SUPPORT + if(lhaArchive.IsArchive()) + { + if(!lhaArchive.ExtractFile()) return false; + outFile = FileReader(lhaArchive.GetOutputFile(), lhaArchive.GetOutputFileLength()); + return outFile.GetRawData()?true:false; + } +#endif +#ifdef UNGZIP_SUPPORT + if(gzipArchive.IsArchive()) + { + if(!gzipArchive.ExtractFile()) return false; + outFile = gzipArchive.GetOutputFile(); + return outFile.GetRawData()?true:false; + } +#endif + return false; +} + + +const char *CUnarchiver::GetComments(bool get) +{ +#ifdef ZIPPED_MOD_SUPPORT + if(!zipArchive.IsArchive()) return nullptr; + return zipArchive.GetComments(get); +#else + return nullptr; +#endif +} Property changes on: trunk/OpenMPT/unarchiver/unarchiver.cpp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-c++src \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/unarchiver/unarchiver.h =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver.h (rev 0) +++ trunk/OpenMPT/unarchiver/unarchiver.h 2013-04-16 16:40:31 UTC (rev 1891) @@ -0,0 +1,57 @@ +/* + * unarchiver.h + * ------------ + * Purpose: archive loader + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#pragma once + +#include "../soundlib/FileReader.h" + +#define UNGZIP_SUPPORT +#define UNLHA_SUPPORT +#define UNRAR_SUPPORT +#define ZIPPED_MOD_SUPPORT + +#ifdef ZIPPED_MOD_SUPPORT +#include "unzip.h" +#endif +#ifdef UNRAR_SUPPORT +#include "unrar.h" +#endif +#ifdef UNLHA_SUPPORT +#include "unlha.h" +#endif +#ifdef UNGZIP_SUPPORT +#include "ungzip.h" +#endif + +//=============== +class CUnarchiver +//=============== +{ +protected: + FileReader inFile; + +private: + CZipArchive zipArchive; + mutable CRarArchive rarArchive; + mutable CLhaArchive lhaArchive; + CGzipArchive gzipArchive; + +protected: + FileReader outFile; + +public: + + FileReader GetOutputFile() const { return outFile; } + bool IsArchive() const; + bool ExtractFile(); + const char *GetComments(bool get); + + CUnarchiver(FileReader &file, const std::vector<const char *> & extensions); + ~CUnarchiver(); +}; Property changes on: trunk/OpenMPT/unarchiver/unarchiver.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/unarchiver/unarchiver_08.vcproj =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver_08.vcproj 2013-04-16 15:22:13 UTC (rev 1890) +++ trunk/OpenMPT/unarchiver/unarchiver_08.vcproj 2013-04-16 16:40:31 UTC (rev 1891) @@ -151,6 +151,10 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > <File + RelativePath=".\unarchiver.cpp" + > + </File> + <File RelativePath=".\ungzip.cpp" > </File> @@ -601,6 +605,10 @@ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > <File + RelativePath=".\unarchiver.h" + > + </File> + <File RelativePath=".\ungzip.h" > </File> Modified: trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj 2013-04-16 15:22:13 UTC (rev 1890) +++ trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj 2013-04-16 16:40:31 UTC (rev 1891) @@ -11,6 +11,7 @@ </ProjectConfiguration> </ItemGroup> <ItemGroup> + <ClCompile Include="unarchiver.cpp" /> <ClCompile Include="ungzip.cpp" /> <ClCompile Include="unlha.cpp" /> <ClCompile Include="unlha\DHUF.CPP"> @@ -89,6 +90,7 @@ <ClCompile Include="unzip.cpp" /> </ItemGroup> <ItemGroup> + <ClInclude Include="unarchiver.h" /> <ClInclude Include="ungzip.h" /> <ClInclude Include="unlha.h" /> <ClInclude Include="unlha\LHARC.H"> Modified: trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj.filters 2013-04-16 15:22:13 UTC (rev 1890) +++ trunk/OpenMPT/unarchiver/unarchiver_10.vcxproj.filters 2013-04-16 16:40:31 UTC (rev 1891) @@ -67,6 +67,7 @@ <ClCompile Include="unlha\SLIDE.CPP"> <Filter>unlha</Filter> </ClCompile> + <ClCompile Include="unarchiver.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="ungzip.h" /> @@ -82,5 +83,6 @@ <ClInclude Include="unlha\SLIDEHUF.H"> <Filter>unlha</Filter> </ClInclude> + <ClInclude Include="unarchiver.h" /> </ItemGroup> </Project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |