From: <sag...@us...> - 2012-12-12 00:50:18
|
Revision: 1455 http://sourceforge.net/p/modplug/code/1455 Author: saga-games Date: 2012-12-12 00:50:08 +0000 (Wed, 12 Dec 2012) Log Message: ----------- [Ref] Removed oooold unzip project and replaced it by a new one, making use of the already existing minizip code from the zlib contrib package. [Ref] Moved zlib/ to include/zlib TODO: Update VS2008 project files. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters trunk/OpenMPT/include/zlib/contrib/vstudio/vc9/zlibstat.vcproj trunk/OpenMPT/mptrack/MPTRACK_08.sln trunk/OpenMPT/mptrack/MPTRACK_10.sln trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/soundlib/FileReader.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/load_j2b.cpp trunk/OpenMPT/ungzip/ungzip.cpp trunk/OpenMPT/ungzip/ungzip.h trunk/OpenMPT/ungzip/ungzip_10.vcxproj Added Paths: ----------- trunk/OpenMPT/include/zlib/ trunk/OpenMPT/unzip/unzip.cpp trunk/OpenMPT/unzip/unzip.h trunk/OpenMPT/unzip/unzip_08.vcproj trunk/OpenMPT/unzip/unzip_10.vcxproj Removed Paths: ------------- trunk/OpenMPT/ungzip/ungzip.vcproj trunk/OpenMPT/unzip/Extract.cpp trunk/OpenMPT/unzip/File_io.cpp trunk/OpenMPT/unzip/Inflate.cpp trunk/OpenMPT/unzip/Mapname.cpp trunk/OpenMPT/unzip/Misc.cpp trunk/OpenMPT/unzip/Unimplod.cpp trunk/OpenMPT/unzip/Unreduce.cpp trunk/OpenMPT/unzip/Unshrink.cpp trunk/OpenMPT/unzip/Unzip.cpp trunk/OpenMPT/unzip/Unzip32.h trunk/OpenMPT/unzip/unzip.dsp trunk/OpenMPT/unzip/unzip.vcproj trunk/OpenMPT/unzip/unzip_08.vcproj trunk/OpenMPT/unzip/unzip_10.vcxproj trunk/OpenMPT/zlib/ Property Changed: ---------------- trunk/OpenMPT/mptrack/ Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/common/misc_util.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -12,6 +12,8 @@ #include "misc_util.h" #include <ctime> +#ifdef MODPLUG_TRACKER + /* * Loads resource. * [in] lpName and lpType: parameters passed to FindResource(). @@ -60,6 +62,7 @@ return msg; } +#endif // MODPLUG_TRACKER std::basic_string<TCHAR> Util::sdTime::GetDateTimeStr() Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/common/misc_util.h 2012-12-12 00:50:08 UTC (rev 1455) @@ -31,21 +31,21 @@ //Convert string to number. template<class T> -inline T ConvertStrTo(LPCSTR psz) -//------------------------------- +inline T ConvertStrTo(const char *str) +//------------------------------------ { #if _HAS_TR1 static_assert(std::tr1::is_const<T>::value == false && std::tr1::is_volatile<T>::value == false, "Const and volatile types are not handled correctly."); #endif if(std::numeric_limits<T>::is_integer) - return static_cast<T>(atoi(psz)); + return static_cast<T>(atoi(str)); else - return static_cast<T>(atof(psz)); + return static_cast<T>(atof(str)); } -template<> inline uint32 ConvertStrTo(LPCSTR psz) {return strtoul(psz, nullptr, 10);} -template<> inline int64 ConvertStrTo(LPCSTR psz) {return _strtoi64(psz, nullptr, 10);} -template<> inline uint64 ConvertStrTo(LPCSTR psz) {return _strtoui64(psz, nullptr, 10);} +template<> inline uint32 ConvertStrTo(const char *str) {return strtoul(str, nullptr, 10);} +template<> inline int64 ConvertStrTo(const char *str) {return _strtoi64(str, nullptr, 10);} +template<> inline uint64 ConvertStrTo(const char *str) {return _strtoui64(str, nullptr, 10);} // Memset given object to zero. @@ -114,8 +114,10 @@ #endif +#ifdef MODPLUG_TRACKER LPCCH LoadResource(LPCTSTR lpName, LPCTSTR lpType, LPCCH& pData, size_t& nSize, HGLOBAL& hglob); CString GetErrorMessage(DWORD nErrorCode); +#endif // MODPLUG_TRACKER namespace utilImpl { @@ -310,6 +312,7 @@ }; +#ifdef MODPLUG_TRACKER namespace Util { namespace sdTime { // Returns string containing date and time ended with newline. @@ -326,3 +329,4 @@ inline bool IsPathFileAvailable(LPCTSTR pszFilePath, FileMode fm) {return (_taccess(pszFilePath, fm) == 0);} } } // namespace Util::sdOs +#endif // MODPLUG_TRACKER Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/common/typedefs.h 2012-12-12 00:50:08 UTC (rev 1455) @@ -23,7 +23,9 @@ //Compile time assert. #define STATIC_ASSERT(expr) C_ASSERT(expr) +#ifndef static_assert #define static_assert(expr, msg) C_ASSERT(expr) +#endif typedef __int8 int8; Modified: trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj =================================================================== --- trunk/OpenMPT/zlib/contrib/vstudio/vc10/zlibstat.vcxproj 2012-12-03 00:35:49 UTC (rev 1444) +++ trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj 2012-12-12 00:50:08 UTC (rev 1455) @@ -441,7 +441,6 @@ <ClCompile Include="..\..\..\trees.c" /> <ClCompile Include="..\..\..\uncompr.c" /> <ClCompile Include="..\..\minizip\unzip.c" /> - <ClCompile Include="..\..\minizip\zip.c" /> <ClCompile Include="..\..\..\zutil.c" /> </ItemGroup> <ItemGroup> Modified: trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters =================================================================== --- trunk/OpenMPT/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters 2012-12-03 00:35:49 UTC (rev 1444) +++ trunk/OpenMPT/include/zlib/contrib/vstudio/vc10/zlibstat.vcxproj.filters 2012-12-12 00:50:08 UTC (rev 1455) @@ -57,9 +57,6 @@ <ClCompile Include="..\..\minizip\unzip.c"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="..\..\minizip\zip.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="..\..\..\zutil.c"> <Filter>Source Files</Filter> </ClCompile> Modified: trunk/OpenMPT/include/zlib/contrib/vstudio/vc9/zlibstat.vcproj =================================================================== --- trunk/OpenMPT/zlib/contrib/vstudio/vc9/zlibstat.vcproj 2012-12-03 00:35:49 UTC (rev 1444) +++ trunk/OpenMPT/include/zlib/contrib/vstudio/vc9/zlibstat.vcproj 2012-12-12 00:50:08 UTC (rev 1455) @@ -813,10 +813,6 @@ > </File> <File - RelativePath="..\..\minizip\zip.c" - > - </File> - <File RelativePath=".\zlib.rc" > </File> Property changes on: trunk/OpenMPT/mptrack ___________________________________________________________________ Modified: svn:ignore - Debug *.user *.suo *.sdf *.opensdf Release + *.opensdf *.sdf *.suo *.user Debug Release ipch Modified: trunk/OpenMPT/mptrack/MPTRACK_08.sln =================================================================== --- trunk/OpenMPT/mptrack/MPTRACK_08.sln 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/mptrack/MPTRACK_08.sln 2012-12-12 00:50:08 UTC (rev 1455) @@ -20,7 +20,7 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\soundtouch\soundtouch_08.vcproj", "{CF3C2CA5-5D45-4635-BBA4-C1F435E10896}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "..\zlib\contrib\vstudio\vc9\zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "..\include\zlib\contrib\vstudio\vc9\zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ungzip", "..\ungzip\ungzip_08.vcproj", "{94CD7910-649A-4075-9F33-7EBEE614FD45}" ProjectSection(ProjectDependencies) = postProject Modified: trunk/OpenMPT/mptrack/MPTRACK_10.sln =================================================================== --- trunk/OpenMPT/mptrack/MPTRACK_10.sln 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/mptrack/MPTRACK_10.sln 2012-12-12 00:50:08 UTC (rev 1455) @@ -9,18 +9,18 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unrar", "..\unrar\unrar_10.vcxproj", "{FF541CE2-DAA1-4F84-9883-0A0F111BAA0B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unzip", "..\unzip\unzip_10.vcxproj", "{44316F22-904E-48AA-B841-5A3A6AC77319}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xsoundlib", "..\xsoundlib\xsoundlib_10.vcxproj", "{DCC2BB2F-6778-4FD3-9C00-D6CD8DC917B8}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\soundtouch\soundtouch_10.vcxproj", "{CF3C2CA5-5D45-4635-BBA4-C1F435E10896}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ungzip", "..\ungzip\ungzip_10.vcxproj", "{94CD7910-649A-4075-9F33-7EBEE614FD45}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "..\zlib\contrib\vstudio\vc10\zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "..\include\zlib\contrib\vstudio\vc10\zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libFLAC_static", "..\include\flac\src\libFLAC\libFLAC_static_10.vcxproj", "{4CEFBC84-C215-11DB-8314-0800200C9A66}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unzip", "..\unzip\unzip_10.vcxproj", "{F23CC68D-1D58-4EB1-9425-A28F5058EB31}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,10 +39,6 @@ {FF541CE2-DAA1-4F84-9883-0A0F111BAA0B}.Debug|Win32.Build.0 = Debug|Win32 {FF541CE2-DAA1-4F84-9883-0A0F111BAA0B}.Release|Win32.ActiveCfg = Release|Win32 {FF541CE2-DAA1-4F84-9883-0A0F111BAA0B}.Release|Win32.Build.0 = Release|Win32 - {44316F22-904E-48AA-B841-5A3A6AC77319}.Debug|Win32.ActiveCfg = Debug|Win32 - {44316F22-904E-48AA-B841-5A3A6AC77319}.Debug|Win32.Build.0 = Debug|Win32 - {44316F22-904E-48AA-B841-5A3A6AC77319}.Release|Win32.ActiveCfg = Release|Win32 - {44316F22-904E-48AA-B841-5A3A6AC77319}.Release|Win32.Build.0 = Release|Win32 {DCC2BB2F-6778-4FD3-9C00-D6CD8DC917B8}.Debug|Win32.ActiveCfg = Debug|Win32 {DCC2BB2F-6778-4FD3-9C00-D6CD8DC917B8}.Debug|Win32.Build.0 = Debug|Win32 {DCC2BB2F-6778-4FD3-9C00-D6CD8DC917B8}.Release|Win32.ActiveCfg = Release|Win32 @@ -63,6 +59,10 @@ {4CEFBC84-C215-11DB-8314-0800200C9A66}.Debug|Win32.Build.0 = Debug|Win32 {4CEFBC84-C215-11DB-8314-0800200C9A66}.Release|Win32.ActiveCfg = Release|Win32 {4CEFBC84-C215-11DB-8314-0800200C9A66}.Release|Win32.Build.0 = Release|Win32 + {F23CC68D-1D58-4EB1-9425-A28F5058EB31}.Debug|Win32.ActiveCfg = Debug|Win32 + {F23CC68D-1D58-4EB1-9425-A28F5058EB31}.Debug|Win32.Build.0 = Debug|Win32 + {F23CC68D-1D58-4EB1-9425-A28F5058EB31}.Release|Win32.ActiveCfg = Release|Win32 + {F23CC68D-1D58-4EB1-9425-A28F5058EB31}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2012-12-12 00:50:08 UTC (rev 1455) @@ -63,7 +63,7 @@ <ClCompile> <AdditionalOptions>/EHsc %(AdditionalOptions)</AdditionalOptions> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>..\unlha;..\unzip;..\unrar;..\soundlib;..\include;..\include\vstsdk2.4\;..\include\ASIOSDK2\common\;..\xsoundlib;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\soundlib;..\include;..\include\vstsdk2.4\;..\include\ASIOSDK2\common\;..\xsoundlib;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;ENABLE_EQ;MODPLUG_TRACKER;NO_PACKING;HAVE_DOT_NET;ENABLE_AMD;ENABLE_SSE;ENABLE_AMDNOW;ENABLE_MMX;%(PreprocessorDefinitions)</PreprocessorDefinitions> <StringPooling>true</StringPooling> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> @@ -88,7 +88,7 @@ </ResourceCompile> <Link> <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions> - <AdditionalDependencies>winmm.lib;strmiids.lib;dmoguids.lib;version.lib;Rpcrt4.lib;delayimp.lib;../include/flac/lib/libFLAC_staticd.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies>winmm.lib;strmiids.lib;dmoguids.lib;version.lib;Rpcrt4.lib;delayimp.lib;%(AdditionalDependencies)</AdditionalDependencies> <OutputFile>.\Debug/mptrack.exe</OutputFile> <Version>5.0</Version> <SuppressStartupBanner>true</SuppressStartupBanner> @@ -119,7 +119,7 @@ <ClCompile> <Optimization>MaxSpeed</Optimization> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> - <AdditionalIncludeDirectories>..\unlha;..\unzip;..\unrar;..\soundlib;..\include;..\include\vstsdk2.4\;..\include\ASIOSDK2\common\;..\xsoundlib;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\soundlib;..\include;..\include\vstsdk2.4\;..\include\ASIOSDK2\common\;..\xsoundlib;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>NDEBUG;WIN32;_WINDOWS;ENABLE_MMX;ENABLE_EQ;MODPLUG_TRACKER;NO_PACKING;HAVE_DOT_NET;ENABLE_AMD;ENABLE_SSE;ENABLE_AMDNOW;%(PreprocessorDefinitions)</PreprocessorDefinitions> <StringPooling>true</StringPooling> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> @@ -147,7 +147,7 @@ </ResourceCompile> <Link> <AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions> - <AdditionalDependencies>winmm.lib;strmiids.lib;dmoguids.lib;version.lib;Rpcrt4.lib;delayimp.lib;wininet.lib;../include/flac/lib/libFLAC_static.lib;%(AdditionalDependencies)</AdditionalDependencies> + <AdditionalDependencies>winmm.lib;strmiids.lib;dmoguids.lib;version.lib;Rpcrt4.lib;delayimp.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies> <OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile> <Version>5.0</Version> <SuppressStartupBanner>true</SuppressStartupBanner> @@ -454,6 +454,12 @@ <None Include="VTune\mptrack.vpj" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\include\flac\src\libFLAC\libFLAC_static_10.vcxproj"> + <Project>{4cefbc84-c215-11db-8314-0800200c9a66}</Project> + </ProjectReference> + <ProjectReference Include="..\include\zlib\contrib\vstudio\vc10\zlibstat.vcxproj"> + <Project>{745dec58-ebb3-47a9-a9b8-4c6627c01bf8}</Project> + </ProjectReference> <ProjectReference Include="..\soundtouch\soundtouch_10.vcxproj"> <Project>{cf3c2ca5-5d45-4635-bba4-c1f435e10896}</Project> <ReferenceOutputAssembly>false</ReferenceOutputAssembly> @@ -471,12 +477,8 @@ <ReferenceOutputAssembly>false</ReferenceOutputAssembly> </ProjectReference> <ProjectReference Include="..\unzip\unzip_10.vcxproj"> - <Project>{44316f22-904e-48aa-b841-5a3a6ac77319}</Project> - <ReferenceOutputAssembly>false</ReferenceOutputAssembly> + <Project>{f23cc68d-1d58-4eb1-9425-a28f5058eb31}</Project> </ProjectReference> - <ProjectReference Include="..\zlib\contrib\vstudio\vc10\zlibstat.vcxproj"> - <Project>{745dec58-ebb3-47a9-a9b8-4c6627c01bf8}</Project> - </ProjectReference> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> Modified: trunk/OpenMPT/soundlib/FileReader.h =================================================================== --- trunk/OpenMPT/soundlib/FileReader.h 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/soundlib/FileReader.h 2012-12-12 00:50:08 UTC (rev 1455) @@ -15,6 +15,7 @@ #include "Endianness.h" #include <vector> #include <algorithm> +#include <assert.h> //============== @@ -108,7 +109,7 @@ // Return byte count between cursor position and end of file, i.e. how many bytes can still be read. off_t BytesLeft() const { - ASSERT(streamPos <= streamLength); + assert(streamPos <= streamLength); return streamLength - streamPos; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -41,11 +41,11 @@ #endif #ifdef ZIPPED_MOD_SUPPORT -#include "unzip32.h" +#include "../unzip/unzip.h" #endif #ifdef UNRAR_SUPPORT -#include "unrar32.h" +#include "../unrar/unrar32.h" #endif #ifdef UNLHA_SUPPORT @@ -547,56 +547,55 @@ } if (lpStream) { + FileReader file(reinterpret_cast<const char*>(lpStream), dwMemLength); + #ifdef ZIPPED_MOD_SUPPORT - CZipArchive archive(glpszModExtensions); - if (CZipArchive::IsArchive((LPBYTE)lpStream, dwMemLength)) + CZipArchive unzip(file, glpszModExtensions); + if(unzip.IsArchive() && unzip.ExtractFile()) { - if (archive.UnzipArchive((LPBYTE)lpStream, dwMemLength) && archive.GetOutputFile()) - { - lpStream = archive.GetOutputFile(); - dwMemLength = archive.GetOutputFileLength(); - } + file = unzip.GetOutputFile(); + lpStream = (LPCBYTE)file.GetRawData(); + dwMemLength = file.GetLength(); } #endif #ifdef UNRAR_SUPPORT CRarArchive unrar((LPBYTE)lpStream, dwMemLength, glpszModExtensions); - if (unrar.IsArchive()) + if(unrar.IsArchive()) { - if (unrar.ExtrFile() && unrar.GetOutputFile()) + if(unrar.ExtrFile() && unrar.GetOutputFile()) { lpStream = unrar.GetOutputFile(); dwMemLength = unrar.GetOutputFileLength(); + file = FileReader((char *)lpStream, dwMemLength); } } #endif #ifdef UNLHA_SUPPORT CLhaArchive unlha((LPBYTE)lpStream, dwMemLength, glpszModExtensions); - if (unlha.IsArchive()) + if(unlha.IsArchive()) { - if (unlha.ExtractFile() && unlha.GetOutputFile()) + if(unlha.ExtractFile() && unlha.GetOutputFile()) { lpStream = unlha.GetOutputFile(); dwMemLength = unlha.GetOutputFileLength(); + file = FileReader((char *)lpStream, dwMemLength); } } #endif #ifdef UNGZIP_SUPPORT - CGzipArchive ungzip((LPBYTE)lpStream, dwMemLength); - if (ungzip.IsArchive()) + CGzipArchive ungzip(file); + if(ungzip.IsArchive() && ungzip.ExtractFile()) { - if (ungzip.ExtractFile() && ungzip.GetOutputFile()) - { - lpStream = ungzip.GetOutputFile(); - dwMemLength = ungzip.GetOutputFileLength(); - } + file = ungzip.GetOutputFile(); + lpStream = (LPCBYTE)file.GetRawData(); + dwMemLength = file.GetLength(); } #endif + #ifdef MMCMP_SUPPORT BOOL bMMCmp = MMCMP_Unpack(&lpStream, &dwMemLength); #endif - FileReader file(reinterpret_cast<const char*>(lpStream), dwMemLength); - if(!ReadXM(file) // -> CODE#0023 // -> DESC="IT project files (.itp)" @@ -644,13 +643,14 @@ } #ifdef ZIPPED_MOD_SUPPORT - if ((!m_lpszSongComments) && (archive.GetComments(FALSE))) + // Read archive comment if there is no song comment + if((!m_lpszSongComments) && unzip.GetComments(false)) { - m_lpszSongComments = archive.GetComments(TRUE); + m_lpszSongComments = (LPSTR)unzip.GetComments(true); } #endif #ifdef MMCMP_SUPPORT - if (bMMCmp) + if(bMMCmp) { GlobalFreePtr(lpStream); lpStream = NULL; Modified: trunk/OpenMPT/soundlib/load_j2b.cpp =================================================================== --- trunk/OpenMPT/soundlib/load_j2b.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/soundlib/load_j2b.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -17,7 +17,7 @@ #ifndef ZLIB_WINAPI #define ZLIB_WINAPI #endif // ZLIB_WINAPI -#include "../zlib/zlib.h" +#include <zlib/zlib.h> // First off, a nice vibrato translation LUT. Modified: trunk/OpenMPT/ungzip/ungzip.cpp =================================================================== --- trunk/OpenMPT/ungzip/ungzip.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/ungzip/ungzip.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -7,152 +7,125 @@ * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. */ +#define static_assert // DIRTY! +#include "../soundlib/FileReader.h" #include "ungzip.h" -#include "../soundlib/Endianness.h" +#ifndef ZLIB_WINAPI +#define ZLIB_WINAPI +#endif // ZLIB_WINAPI +#include <zlib/zlib.h> -CGzipArchive::CGzipArchive(LPBYTE lpStream, DWORD dwMemLength) -//------------------------------------------------------------ + +CGzipArchive::CGzipArchive(FileReader &file) : inFile(file) +//--------------------------------------------------------- { - m_lpStream = lpStream; - m_dwStreamLen = dwMemLength; - m_pOutputFile = nullptr; - m_dwOutputLen = 0; + inFile.Rewind(); + inFile.Read(header); } CGzipArchive::~CGzipArchive() //--------------------------- { - if(m_pOutputFile != nullptr) - { - delete[] m_pOutputFile; - } + delete[] outFile.GetRawData(); } bool CGzipArchive::IsArchive() const //---------------------------------- { - if(m_lpStream == nullptr || m_dwStreamLen <= (sizeof(GZheader) + sizeof(GZtrailer))) + if(inFile.GetLength() <= (sizeof(GZheader) + sizeof(GZtrailer))) + { return false; + } // Check header data - GZheader *pHeader = (GZheader *)m_lpStream; - if(pHeader->magic1 != GZ_HMAGIC1 || pHeader->magic2 != GZ_HMAGIC2 || pHeader->method != GZ_HMDEFLATE || (pHeader->flags & GZ_FRESERVED) != 0) - return false; - - // Seems to be OK... - return true; + return (header.magic1 == GZ_HMAGIC1 && header.magic2 == GZ_HMAGIC2 && header.method == GZ_HMDEFLATE && (header.flags & GZ_FRESERVED) == 0); } bool CGzipArchive::ExtractFile() //------------------------------ { - #define ASSERT_CAN_READ(x) \ - if( dwMemPos > m_dwStreamLen || x > m_dwStreamLen - dwMemPos ) return false; - if(!IsArchive()) + { return false; + } - DWORD dwMemPos = 0; - GZheader *pHeader = (GZheader *)m_lpStream; - GZtrailer *pTrailer = (GZtrailer *)(m_lpStream + m_dwStreamLen - sizeof(GZtrailer)); + // Read trailer + GZtrailer trailer; + inFile.Seek(inFile.GetLength() - sizeof(GZtrailer)); + inFile.ReadConvertEndianness(trailer); - dwMemPos += sizeof(GZheader); + // Continue reading header + inFile.Seek(sizeof(GZheader)); - // Extra block present? (ignore) - if(pHeader->flags & GZ_FEXTRA) + // Extra block present? (skip the extra data) + if(header.flags & GZ_FEXTRA) { - ASSERT_CAN_READ(sizeof(uint16)); - uint16 xlen = LittleEndianW(*((uint16 *)m_lpStream + dwMemPos)); - dwMemPos += sizeof(uint16); - // We skip this. - ASSERT_CAN_READ(xlen); - dwMemPos += xlen; + inFile.Skip(inFile.ReadUint16LE()); } // Filename present? (ignore) - if(pHeader->flags & GZ_FNAME) + if(header.flags & GZ_FNAME) { - do - { - ASSERT_CAN_READ(1); - } while (m_lpStream[dwMemPos++] != 0); + while(inFile.ReadUint8() != 0); } // Comment present? (ignore) - if(pHeader->flags & GZ_FCOMMENT) + if(header.flags & GZ_FCOMMENT) { - do - { - ASSERT_CAN_READ(1); - } while (m_lpStream[dwMemPos++] != 0); + while(inFile.ReadUint8() != 0); } - // CRC16 present? - if(pHeader->flags & GZ_FHCRC) + // CRC16 present? (ignore) + if(header.flags & GZ_FHCRC) { - ASSERT_CAN_READ(sizeof(uint16)); - uint16 crc16_h = LittleEndianW(*((uint16 *)m_lpStream + dwMemPos)); - uint16 crc16_f = (uint16)(crc32(0, m_lpStream, dwMemPos) & 0xFFFF); - dwMemPos += sizeof(uint16); - if(crc16_h != crc16_f) - return false; + inFile.Skip(2); } - // Well, this is a bit small when inflated. - if(pTrailer->isize == 0) + // Well, this is a bit small when inflated / deflated. + if(trailer.isize == 0 || inFile.BytesLeft() < sizeof(GZtrailer)) + { return false; + } - // Check if the deflated data is a bit small as well. - ASSERT_CAN_READ(sizeof(GZtrailer) + 1); + delete[] outFile.GetRawData(); - // Clear the output buffer, if necessary. - if(m_pOutputFile != nullptr) + char *data = new (std::nothrow) char[trailer.isize]; + if(data == nullptr) { - delete[] m_pOutputFile; + return false; } - DWORD destSize = LittleEndian(pTrailer->isize); - - m_pOutputFile = new Bytef[destSize]; - if(m_pOutputFile == nullptr) - return false; - // Inflate! z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; - strm.avail_in = m_dwStreamLen - (dwMemPos + sizeof(GZtrailer)); - strm.next_in = &m_lpStream[dwMemPos]; + strm.avail_in = inFile.BytesLeft() - sizeof(GZtrailer); + strm.next_in = (Bytef *)(inFile.GetRawData()); if(inflateInit2(&strm, -15) != Z_OK) + { return false; - strm.avail_out = destSize; - strm.next_out = m_pOutputFile; + } + strm.avail_out = trailer.isize; + strm.next_out = (Bytef *)data; - int nRetVal = inflate(&strm, Z_NO_FLUSH); + int retVal = inflate(&strm, Z_NO_FLUSH); inflateEnd(&strm); // Everything went OK? Check return code, number of written bytes and CRC32. - if(nRetVal == Z_STREAM_END && destSize == strm.total_out && LittleEndian(pTrailer->crc32) == crc32(0, m_pOutputFile, destSize)) + if(retVal == Z_STREAM_END && trailer.isize == strm.total_out && trailer.crc32 == crc32(0, (Bytef *)data, trailer.isize)) { // Success! :) - m_dwOutputLen = destSize; + outFile = FileReader(data, trailer.isize); return true; } else { // Fail :( - if(m_pOutputFile != nullptr) - { - delete[] m_pOutputFile; - } - m_pOutputFile = nullptr; - m_lpStream = nullptr; + delete[] outFile.GetRawData(); return false; } - - #undef ASSERT_CAN_READ } Modified: trunk/OpenMPT/ungzip/ungzip.h =================================================================== --- trunk/OpenMPT/ungzip/ungzip.h 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/ungzip/ungzip.h 2012-12-12 00:50:08 UTC (rev 1455) @@ -9,37 +9,12 @@ #pragma once -#ifndef ZLIB_WINAPI -#define ZLIB_WINAPI -#endif // ZLIB_WINAPI -#include "../zlib/zlib.h" -#include "../common/typedefs.h" - - -// magic bytes -#define GZ_HMAGIC1 0x1F -#define GZ_HMAGIC2 0x8B -#define GZ_HMDEFLATE 0x08 -// header flags -#define GZ_FTEXT 0x01 // File is probably ASCII text (who cares) -#define GZ_FHCRC 0x02 // CRC16 present -#define GZ_FEXTRA 0x04 // Extra fields present -#define GZ_FNAME 0x08 // Original filename present -#define GZ_FCOMMENT 0x10 // Comment is present -#define GZ_FRESERVED (~(GZ_FTEXT | GZ_FHCRC | GZ_FEXTRA | GZ_FNAME | GZ_FCOMMENT)) - - //================ class CGzipArchive //================ { protected: - // in - LPBYTE m_lpStream; - DWORD m_dwStreamLen; - // out - Bytef *m_pOutputFile; - DWORD m_dwOutputLen; + FileReader inFile, outFile; #pragma pack(push, 1) @@ -58,17 +33,41 @@ { uint32 crc32; // CRC32 of decompressed data uint32 isize; // Size of decompressed data + + void ConvertEndianness() + { + SwapBytesLE(crc32); + SwapBytesLE(isize); + } }; #pragma pack(pop) + enum MagicBytes + { + GZ_HMAGIC1 = 0x1F, + GZ_HMAGIC2 = 0x8B, + GZ_HMDEFLATE = 0x08, + }; + + enum HeaderFlags + { + GZ_FTEXT = 0x01, // File is probably ASCII text (who cares) + GZ_FHCRC = 0x02, // CRC16 present + GZ_FEXTRA = 0x04, // Extra fields present + GZ_FNAME = 0x08, // Original filename present + GZ_FCOMMENT = 0x10, // Comment is present + GZ_FRESERVED = (~(GZ_FTEXT | GZ_FHCRC | GZ_FEXTRA | GZ_FNAME | GZ_FCOMMENT)) + }; + + GZheader header; + public: - LPBYTE GetOutputFile() const { return m_pOutputFile; } - DWORD GetOutputFileLength() const { return m_dwOutputLen; } + FileReader GetOutputFile() const { return outFile; } bool IsArchive() const; bool ExtractFile(); - CGzipArchive(LPBYTE lpStream, DWORD dwMemLength); + CGzipArchive(FileReader &file); ~CGzipArchive(); }; Deleted: trunk/OpenMPT/ungzip/ungzip.vcproj =================================================================== --- trunk/OpenMPT/ungzip/ungzip.vcproj 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/ungzip/ungzip.vcproj 2012-12-12 00:50:08 UTC (rev 1455) @@ -1,124 +0,0 @@ -<?xml version="1.0" encoding="Windows-1252"?> -<VisualStudioProject - ProjectType="Visual C++" - Version="7.10" - Name="ungzip" - ProjectGUID="{20BF96C8-0202-4251-80C9-6C62BE845DAE}" - Keyword="Win32Proj"> - <Platforms> - <Platform - Name="Win32"/> - </Platforms> - <Configurations> - <Configuration - Name="Debug|Win32" - OutputDirectory="Debug" - IntermediateDirectory="Debug" - ConfigurationType="4" - CharacterSet="0"> - <Tool - Name="VCCLCompilerTool" - Optimization="0" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB;ZLIB_WINAPI" - MinimalRebuild="TRUE" - BasicRuntimeChecks="3" - RuntimeLibrary="3" - BufferSecurityCheck="TRUE" - ForceConformanceInForLoopScope="TRUE" - UsePrecompiledHeader="0" - WarningLevel="4" - Detect64BitPortabilityProblems="TRUE" - DebugInformationFormat="4"/> - <Tool - Name="VCCustomBuildTool"/> - <Tool - Name="VCLibrarianTool" - OutputFile="$(OutDir)/ungzip.lib"/> - <Tool - Name="VCMIDLTool"/> - <Tool - Name="VCPostBuildEventTool"/> - <Tool - Name="VCPreBuildEventTool"/> - <Tool - Name="VCPreLinkEventTool"/> - <Tool - Name="VCResourceCompilerTool"/> - <Tool - Name="VCWebServiceProxyGeneratorTool"/> - <Tool - Name="VCXMLDataGeneratorTool"/> - <Tool - Name="VCManagedWrapperGeneratorTool"/> - <Tool - Name="VCAuxiliaryManagedWrapperGeneratorTool"/> - </Configuration> - <Configuration - Name="Release|Win32" - OutputDirectory="Release" - IntermediateDirectory="Release" - ConfigurationType="4" - CharacterSet="0"> - <Tool - Name="VCCLCompilerTool" - AdditionalOptions="/O2" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB;ZLIB_WINAPI" - RuntimeLibrary="0" - ForceConformanceInForLoopScope="TRUE" - UsePrecompiledHeader="0" - WarningLevel="3" - Detect64BitPortabilityProblems="TRUE" - DebugInformationFormat="3"/> - <Tool - Name="VCCustomBuildTool"/> - <Tool - Name="VCLibrarianTool" - OutputFile="$(OutDir)/ungzip.lib"/> - <Tool - Name="VCMIDLTool"/> - <Tool - Name="VCPostBuildEventTool"/> - <Tool - Name="VCPreBuildEventTool"/> - <Tool - Name="VCPreLinkEventTool"/> - <Tool - Name="VCResourceCompilerTool"/> - <Tool - Name="VCWebServiceProxyGeneratorTool"/> - <Tool - Name="VCXMLDataGeneratorTool"/> - <Tool - Name="VCManagedWrapperGeneratorTool"/> - <Tool - Name="VCAuxiliaryManagedWrapperGeneratorTool"/> - </Configuration> - </Configurations> - <References> - </References> - <Files> - <Filter - Name="Source Files" - Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" - UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> - <File - RelativePath=".\ungzip.cpp"> - </File> - </Filter> - <Filter - Name="Header Files" - Filter="h;hpp;hxx;hm;inl;inc;xsd" - UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> - <File - RelativePath=".\ungzip.h"> - </File> - </Filter> - <Filter - Name="Resource Files" - Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" - UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> - </Filter> - </Files> - <Globals> - </Globals> -</VisualStudioProject> Modified: trunk/OpenMPT/ungzip/ungzip_10.vcxproj =================================================================== --- trunk/OpenMPT/ungzip/ungzip_10.vcxproj 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/ungzip/ungzip_10.vcxproj 2012-12-12 00:50:08 UTC (rev 1455) @@ -52,6 +52,7 @@ <WarningLevel>Level3</WarningLevel> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <OmitDefaultLibName>true</OmitDefaultLibName> + <AdditionalIncludeDirectories>../include/</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> @@ -66,6 +67,7 @@ </DebugInformationFormat> <OmitDefaultLibName>true</OmitDefaultLibName> <MultiProcessorCompilation>true</MultiProcessorCompilation> + <AdditionalIncludeDirectories>../include/</AdditionalIncludeDirectories> </ClCompile> </ItemDefinitionGroup> <ItemGroup> Deleted: trunk/OpenMPT/unzip/Extract.cpp =================================================================== --- trunk/OpenMPT/unzip/Extract.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/unzip/Extract.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -1,368 +0,0 @@ -/*--------------------------------------------------------------------------- - - extract.c - - This file contains the high-level routines ("driver routines") for extrac- - ting and testing zipfile members. It calls the low-level routines in files - inflate.c, unimplod.c, unreduce.c and unshrink.c. - - ---------------------------------------------------------------------------*/ - - -/**************************************/ -/* Function extract_or_test_files() */ -/**************************************/ - -// return PK-type error code -int CZipArchive::ExtractOrTestFiles() -//----------------------------------- -{ - BYTE *cd_inptr; - int cd_incnt, error, error_in_archive=0; - int renamed, query, filnum=-1, blknum=0; - WORD i, j, members_remaining, num_skipped=0; - long int cd_bufstart, bufstart, inbuf_offset, request; - -/*--------------------------------------------------------------------------- - The basic idea of this function is as follows. Since the central di- - rectory lies at the end of the zipfile and the member files lie at the - beginning or middle or wherever, it is not very desirable to simply - read a central directory entry, jump to the member and extract it, and - then jump back to the central directory. In the case of a large zipfile - this would lead to a whole lot of disk-grinding, especially if each mem- - ber file is small. Instead, we read from the central directory the per- - tinent information for a block of files, then go extract/test the whole - block. Thus this routine contains two small(er) loops within a very - large outer loop: the first of the small ones reads a block of files - from the central directory; the second extracts or tests each file; and - the outer one loops over blocks. There's some file-pointer positioning - stuff in between, but that's about it. Btw, it's because of this jump- - ing around that we can afford to be lenient if an error occurs in one of - the member files: we should still be able to go find the other members, - since we know the offset of each from the beginning of the zipfile. - - Begin main loop over blocks of member files. We know the entire central - directory is on this disk: we would not have any of this information un- - less the end-of-central-directory record was on this disk, and we would - not have gotten to this routine unless this is also the disk on which - the central directory starts. In practice, this had better be the ONLY - disk in the archive, but maybe someday we'll add multi-disk support. - ---------------------------------------------------------------------------*/ - - pInfo = info; - members_remaining = ecrec.total_entries_central_dir; - - while (members_remaining) - { - j = 0; - - // Loop through files in central directory, storing offsets, file - // attributes, and case-conversion flags until block size is reached. - while (members_remaining && (j < DIR_BLKSIZ)) - { - --members_remaining; - pInfo = &info[j]; - if (ReadBuf(sig, 4) <= 0) - { - error_in_archive = 51; /* 51: unexpected EOF */ - members_remaining = 0; /* ...so no more left to do */ - break; - } - if (strncmp(sig, central_hdr_sig, 4)) - { /* just to make sure */ - // sig not found - // check binary transfers - error_in_archive = 3; // 3: error in zipfile - members_remaining = 0; // ...so no more left to do - break; - } - /* process_cdir_file_hdr() sets pInfo->hostnum, pInfo->lcflag */ - if ((error = ProcessCDirFileHdr()) != 0) - { - error_in_archive = error; /* only 51 (EOF) defined */ - members_remaining = 0; /* ...so no more left to do */ - break; - } - if ((error = DoString(crec.filename_length, FILENAME)) != 0) - { - if (error > error_in_archive) - error_in_archive = error; - if (error > 1) - { // fatal: no more left to do - members_remaining = 0; - break; - } - } - if ((error = DoString(crec.extra_field_length, EXTRA_FIELD)) != 0) - { - if (error > error_in_archive) - error_in_archive = error; - if (error > 1) - { // fatal - members_remaining = 0; - break; - } - } - if ((error = DoString(crec.file_comment_length, SKIP)) != 0) { - if (error > error_in_archive) - error_in_archive = error; - if (error > 1) - { // fatal - members_remaining = 0; - break; - } - } - if (StoreInfo()) - ++num_skipped; - else - ++j; /* file is OK: save info[] and continue with next */ - } /* end while-loop (adding files to current block) */ - - /* save position in central directory so can come back later */ - cd_bufstart = cur_zipfile_bufstart; - cd_inptr = inptr; - cd_incnt = incnt; - - /*----------------------------------------------------------------------- - Second loop: process files in current block, extracting or testing - each one. - -----------------------------------------------------------------------*/ - - for (i = 0; i < j; ++i) - { - filnum = i + blknum*DIR_BLKSIZ; - pInfo = &info[i]; - /* - * if the target position is not within the current input buffer - * (either haven't yet read far enough, or (maybe) skipping back- - * ward) skip to the target position and reset readbuf(). - */ - request = pInfo->offset + extra_bytes; - inbuf_offset = request % INBUFSIZ; - bufstart = request - inbuf_offset; - - if (request < 0) - { - error_in_archive = 3; // 3: severe error in zipfile, - continue; // but can still go on - } else if (bufstart != cur_zipfile_bufstart) - { - cur_zipfile_bufstart = m_dwPos = bufstart; - if ((incnt = Read(inbuf,INBUFSIZ)) <= 0) - { - error_in_archive = 3; // 3: error in zipfile, but - continue; // can still do next file - } - inptr = inbuf + inbuf_offset; - incnt -= inbuf_offset; - } else { - incnt += (inptr-inbuf) - inbuf_offset; - inptr = inbuf + inbuf_offset; - } - - // should be in proper position now, so check for sig - if (ReadBuf(sig, 4) <= 0) - { // bad offset - error_in_archive = 3; // 3: error in zipfile - continue; // but can still try next one - } - if (strncmp(sig, local_hdr_sig, 4)) - { - error_in_archive = 3; - continue; - } - if ((error = ProcessLocalFileHdr()) != 0) - { - error_in_archive = error; // only 51 (EOF) defined - continue; // can still try next one - } - if ((error = DoString(lrec.filename_length, FILENAME)) != 0) - { - if (error > error_in_archive) - error_in_archive = error; - if (error > 1) - { - continue; // go on to next one - } - } - if ((error = DoString(lrec.extra_field_length, EXTRA_FIELD)) != 0) - { - if (error > error_in_archive) - error_in_archive = error; - if (error > 1) - { - continue; // go on - } - } - - /* - * just about to extract file: if extracting to disk, check if - * already exists, and if so, take appropriate action according to - * fflag/uflag/overwrite_all/etc. (we couldn't do this in upper - * loop because we don't store the possibly renamed filename[] in - * info[]) - */ - renamed = FALSE; // user hasn't renamed output file yet - query = FALSE; - // mapname can create dirs if not freshening or if renamed - if ((error = MapName()) > 1) // Skip - { - if ((error > 2) && (error_in_archive < 2)) - error_in_archive = 2; // (weak) error in zipfile - continue; // go on to next file - } - - if ((error = ExtractOrTestMember()) != 0) - { - if (error > error_in_archive) - error_in_archive = error; // ...and keep going - } - } // end for-loop (i: files in current block) - - - /* - * Jump back to where we were in the central directory, then go and do - * the next batch of files. - */ - - cur_zipfile_bufstart = m_dwPos = cd_bufstart; - Read(inbuf, INBUFSIZ); // were there b4 ==> no error - inptr = cd_inptr; - incnt = cd_incnt; - ++blknum; - - } // end while-loop (blocks of files in central directory) - -/*--------------------------------------------------------------------------- - Double-check that we're back at the end-of-central-directory record, and - print quick summary of results, if we were just testing the archive. We - send the summary to stdout so that people doing the testing in the back- - ground and redirecting to a file can just do a "tail" on the output file. - ---------------------------------------------------------------------------*/ - - ReadBuf(sig, 4); - if (strncmp(sig, end_central_sig, 4)) - { // just to make sure again - if (!error_in_archive) // don't overwrite stronger error - error_in_archive = 1; // 1: warning error - } - if ((num_skipped > 0) && !error_in_archive) // files not tested or - error_in_archive = 1; // extracted: warning - - return (error_in_archive); - -} // end function extract_or_test_files() - - - - - -/***************************/ -/* Function store_info() */ -/***************************/ - -// return 1 if skipping, 0 if OK -int CZipArchive::StoreInfo() -{ -#define UNKN_COMPR (crec.compression_method>IMPLODED && crec.compression_method!=DEFLATED) - -// Check central directory info for version/compatibility requirements. - pInfo->encrypted = crec.general_purpose_bit_flag & 1; // bit field - pInfo->ExtLocHdr = (crec.general_purpose_bit_flag & 8) == 8; // bit - pInfo->text = crec.internal_file_attributes & 1; // bit field - - if (crec.version_needed_to_extract[1] == VMS_) - { - if (crec.version_needed_to_extract[0] > VMS_VERSION) return 1; - // usual file type: don't need VMS to extract - } else - if (crec.version_needed_to_extract[0] > UNZIP_VERSION) return 1; - if UNKN_COMPR return 1; - // Skipping encrypted data - if (pInfo->encrypted) return 1; - -// Store some central-directory information (encryption, offsets) for later use. - pInfo->offset = (long int) crec.relative_offset_local_header; - return 0; -} // end function StoreInfo() - - - - - -/***************************************/ -/* Function extract_or_test_member() */ -/***************************************/ - -// return PK-type error code -int CZipArchive::ExtractOrTestMember() -//------------------------------------ -{ - int error=0; - WORD b; - -// Initialize variables, buffers, etc. - bits_left = 0; - bitbuf = 0L; - outpos = 0L; - outcnt = 0; - outptr = outbuf; - zipeof = 0; - crc32val = 0xFFFFFFFFL; - - memset(outbuf, 0, OUTBUFSIZ); - if (CreateOutputFile()) return 50; // 50: disk full (?) - -// Unpack the file. - switch (lrec.compression_method) - { - case STORED: - while (ReadByte(&b)) OUTB(b); - break; - - case SHRUNK: - unShrink(); - break; - - case REDUCED1: - case REDUCED2: - case REDUCED3: - case REDUCED4: - unReduce(); - break; - - case IMPLODED: - unImplode(); - break; - - case DEFLATED: - if (inflate() != 0) return 3; - break; - - default: // should never get to this point - return 1; - - } // end switch (compression method) - -/*--------------------------------------------------------------------------- - Write the last partial buffer, if any; set the file date and time; and - close the file (not necessarily in that order). Then make sure CRC came - out OK and print result. [Note: crc32val must be logical-ANDed with - 32 bits of 1's, or else machines whose longs are bigger than 32 bits will - report bad CRCs (because of the upper bits being filled with 1's instead - of 0's).] - ---------------------------------------------------------------------------*/ - - if (FlushOutput()) error = 1; - if ((crc32val = ((~crc32val) & 0xFFFFFFFFL)) != lrec.crc32) - { - /* if quietflg is set, we haven't output the filename yet: do it */ - error = 1; // 1: warning error - } - return error; -} // end function ExtractOrTestMember() - - - - - Deleted: trunk/OpenMPT/unzip/File_io.cpp =================================================================== --- trunk/OpenMPT/unzip/File_io.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/unzip/File_io.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -1,229 +0,0 @@ -/*--------------------------------------------------------------------------- - - file_io.c - - This file contains routines for doing direct input/output, file-related - sorts of things. Most of the system-specific code for unzip is contained - here, including the non-echoing password code for decryption (bottom). - - ---------------------------------------------------------------------------*/ - - -/**********************/ -/* Function readbuf() */ -/**********************/ - -// return number of bytes read into buf -int CZipArchive::ReadBuf(char *buf, unsigned int size) -//---------------------------------------------------- -{ - int count; - int n; - - n = size; - while (size) - { - if (incnt == 0) - { - if ((incnt = Read(inbuf, INBUFSIZ)) <= 0) return (n-size); - // buffer ALWAYS starts on a block boundary: - cur_zipfile_bufstart += INBUFSIZ; - inptr = inbuf; - } - count = min((int)size, incnt); - memcpy(buf, inptr, count); - buf += count; - inptr += count; - incnt -= count; - size -= count; - } - return n; -} - - - -/*********************************/ -/* Function create_output_file() */ -/*********************************/ - -// return non-0 if creat failed -int CZipArchive::CreateOutputFile() -//--------------------------------- -{ - CHAR s[64], *filenameext; - int l; - - m_bExtractingComments = FALSE; - l = lstrlen(filename); - while ((l>0) && (filename[l-1] != '.') && (filename[l-1] != '\\')) l--; - if (l<0) l = 0; - filenameext = filename+l; - if ((!lstrcmpi(filenameext, "diz")) - || (!lstrcmpi(filenameext, "nfo")) - || (!lstrcmpi(filenameext, "txt"))) - { - if ((!lstrcmpi(filenameext, "diz")) && (m_lpszComments)) return 2; - m_bExtractingComments = TRUE; - if (m_lpszComments) delete m_lpszComments; - m_lpszComments = NULL; - m_dwCommentsLen = 0; - m_dwCommentsAllocated = 4096; - m_lpszComments = new CHAR[m_dwCommentsAllocated]; - return (m_lpszComments) ? 0 : 1; - } else - { - if (m_lpszExtensions) - { - int i = 0, j = 0; - while (m_lpszExtensions[i]) - { - char c = m_lpszExtensions[i]; - s[j] = c; - if (c == '|') - { - s[j] = 0; - j = 0; - if (!lstrcmpi(filenameext, s)) - { - if (m_lpOutFile) GlobalFreePtr(m_lpOutFile); - m_lpOutFile = NULL; - m_dwOutFileLength = m_dwOutFilePos = 0; - break; - } - } else j++; - i++; - } - } - // Create memory file - if (!m_lpOutFile) - { - m_dwOutFilePos = 0; - m_dwOutFileLength = ziplen * 2 + 1024; - m_lpOutFile = (LPBYTE)GlobalAllocPtr(GHND, m_dwOutFileLength); - if (!m_lpOutFile) return 1; - } - } - return 0; -} - - - - -/**************************** - * Function FillBitBuffer() * - ****************************/ -/* - * Fill bitbuf, which is 32 bits. This function is only used by the - * READBIT and PEEKBIT macros (which are used by all of the uncompression - * routines). - */ -int CZipArchive::FillBitBuffer() -//------------------------------ -{ - WORD temp; - - zipeof = 1; - while ((bits_left < 25) && (ReadByte(&temp) == 8)) - { - bitbuf |= (ULONG)temp << bits_left; - bits_left += 8; - zipeof = 0; - } - return 0; -} - - - - - -/***********************/ -/* Function ReadByte() */ -/***********************/ - -int CZipArchive::ReadByte(WORD *x) -//-------------------------------- -{ - // read a byte; return 8 if byte available, 0 if not - if (csize-- <= 0) return 0; - if (incnt == 0) - { - if ((incnt = Read(inbuf, INBUFSIZ)) <= 0) return 0; - // buffer ALWAYS starts on a block boundary: - cur_zipfile_bufstart += INBUFSIZ; - inptr = inbuf; - } - *x = *inptr++; - --incnt; - return 8; -} - - -int CZipArchive::Write(LPBYTE p, int len) -//--------------------------------------- -{ - if (m_bExtractingComments) - { - if (m_dwCommentsLen+len+1 > m_dwCommentsAllocated) - { - DWORD newlen = m_dwCommentsAllocated + len + 4096; - LPSTR tmp = new CHAR[newlen]; - if (!tmp) return 0; - if (m_lpszComments) memcpy(tmp, m_lpszComments, m_dwCommentsAllocated); - delete m_lpszComments; - m_lpszComments = tmp; - m_dwCommentsAllocated = newlen; - } - if (m_lpszComments) - { - memcpy(m_lpszComments+m_dwCommentsLen, p, len); - m_dwCommentsLen += len; - m_lpszComments[m_dwCommentsLen] = 0; - } - } else - { - if (m_dwOutFilePos+len > m_dwOutFileLength) - { - DWORD newlen = m_dwOutFileLength + len + 16384; - LPBYTE tmp = (LPBYTE)GlobalAllocPtr(GHND, newlen); - if (!tmp) return 0; - memcpy(tmp, m_lpOutFile, m_dwOutFilePos); - GlobalFreePtr(m_lpOutFile); - m_lpOutFile = tmp; - m_dwOutFileLength = newlen; - } - memcpy(m_lpOutFile+m_dwOutFilePos, p, len); - m_dwOutFilePos += len; - } - return len; -} - - - -/**************************/ -/* Function FlushOutput() */ -/**************************/ - -int CZipArchive::FlushOutput() -//---------------------------- -{ - // flush contents of output buffer; return PK-type error code - int len; - - if (outcnt) - { - UpdateCRC(outbuf, outcnt); - len = outcnt; - if (Write(outbuf, len) != len) return 50; - outpos += outcnt; - outcnt = 0; - outptr = outbuf; - } - return 0; // 0: no error -} - - - - - - - Deleted: trunk/OpenMPT/unzip/Inflate.cpp =================================================================== --- trunk/OpenMPT/unzip/Inflate.cpp 2012-12-11 17:38:58 UTC (rev 1454) +++ trunk/OpenMPT/unzip/Inflate.cpp 2012-12-12 00:50:08 UTC (rev 1455) @@ -1,911 +0,0 @@ -/* inflate.c -- put in the public domain by Mark Adler - version c14v, 8 November 1995 */ - - -/* - Inflate deflated (PKZIP's method 8 compressed) data. The compression - method searches for as much of the current string of bytes (up to a - length of 258) in the previous 32K bytes. If it doesn't find any - matches (of at least length 3), it codes the next byte. Otherwise, it - codes the length of the matched string and its distance backwards from - the current position. There is a single Huffman code that codes both - single bytes (called "literals") and match lengths. A second Huffman - code codes the distance information, which follows a length code. Each - length or distance code actually represents a base value and a number - of "extra" (sometimes zero) bits to get to add to the base value. At - the end of each deflated block is a special end-of-block (EOB) literal/ - length code. The decoding process is basically: get a literal/length - code; if EOB then done; if a literal, emit the decoded byte; if a - length then get the distance and emit the referred-to bytes from the - sliding window of previously emitted data. - - There are (currently) three kinds of inflate blocks: stored, fixed, and - dynamic. The compressor outputs a chunk of data at a time and decides - which method to use on a chunk-by-chunk basis. A chunk might typically - be 32K to 64K, uncompressed. If the chunk is uncompressible, then the - "stored" method is used. In this case, the bytes are simply stored as - is, eight bits per byte, with none of the above coding. The bytes are - preceded by a count, since there is no longer an EOB code. - - If the data are compressible, then either the fixed or dynamic methods - are used. In the dynamic method, the compressed data are preceded by - an encoding of the literal/length and distance Huffman codes that are - to be used to decode this block. The representation is itself Huffman - coded, and so is preceded by a description of that code. These code - descriptions take up a little space, and so for small blocks, there is - a predefined set of codes, called the fixed codes. The fixed method is - used if the block ends up smaller that way (usually for quite small - chunks); otherwise the dynamic method is used. In the latter case, the - codes are customized to the probabilities in the current block and so - can code it much better than the pre-determined fixed codes can. - - The Huffman codes themselves are decoded using a multi-level table - lookup, in order to maximize the speed of decoding plus the speed of - building the decoding tables. See the comments below that precede the - lbits and dbits tuning parameters. - - GRR: return values(?) - 0 OK - 1 incomplete table - 2 bad input - 3 not enough memory - */ - - -/* - Notes beyond the 1.93a appnote.txt: - - 1. Distance pointers never point before the beginning of the output - stream. - 2. Distance pointers can point back across blocks, up to 32k away. - 3. There is an implied maximum of 7 bits for the bit length table and - 15 bits for the actual data. - 4. If only one code exists, then it is encoded using one bit. (Zero - would be more efficient, but perhaps a little confusing.) If two - codes exist, they are coded using one bit each (0 and 1). - 5. There is no way of sending zero distance codes--a dummy must be - sent if there are none. (History: a pre 2.0 version of PKZIP would - store blocks with no distance codes, but this was discovered to be - too harsh a criterion.) Valid only for 1.93a. 2.04c does allow - zero distance codes, which is sent as one code of zero bits in - length. - 6. There are up to 286 literal/length codes. Code 256 represents the - end-of-block. Note however that the static length tree defines - 288 codes just to fill out the Huffman codes. Codes 286 and 287 - cannot be used though, since there is no length base or extra bits - defined for them. Similarily, there are up to 30 distance codes. - However, static trees define 32 codes (all 5 bits) to fill out the - Huffman codes, but the last two had better not show up in the data. - 7. Unzip can check dynamic Huffman blocks for complete code sets. - The exception is that a single code would not be complete (see #4). - 8. The five bits following the block type is really the number of - literal codes sent minus 257. - 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits - (1+6+6). Therefore, to output three times the length, you output - three codes (1+1+1), whereas to output four times the same length, - you only need two codes (1+3). Hmm. - 10. In the tree reconstruction algorithm, Code = Code + Increment - only if BitLength(i) is not zero. (Pretty obvious.) - 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19) - 12. Note: length code 284 can represent 227-258, but length code 285 - really is 258. The last length deserves its own, short code - since it gets used a lot in very redundant files. The length - 258 is special since 258 - 3 (the min match length) is 255. - 13. The literal/length and distance code bit lengths are read as a - single stream of lengths. It is possible (and advantageous) for - a repeat code (16, 17, or 18) to go across the boundary between - the two sets of lengths. - */ - - -#define PKZIP_BUG_WORKAROUND /* PKZIP 1.93a problem--live with it */ - -/* - inflate.h must supply the uch slide[WSIZE] array, the zvoid typedef - (void if (void *) is accepted, else char) and the NEXTBYTE, - FLUSH() and memzero macros. If the window size is not 32K, it - should also define WSIZE. If INFMOD is defined, it can include - compiled functions to support the NEXTBYTE and/or FLUSH() macros. - There are defaults for NEXTBYTE and FLUSH() below for use as - examples of what those functions need to do. Normally, you would - also want FLUSH() to compute a crc on the data. inflate.h also - needs to provide these typedefs: - - typedef unsigned char uch; - typedef unsigned short ush; - typedef unsigned long ulg; - - */ - - -#define EOF (-1) -#define wsize WSIZE // wsize is a constant -#define FLUSH(n) Write(redirSlide, n) // return value not used - - -/* The inflate algorithm uses a sliding 32K byte window on the uncompressed - stream to find repeated byte strings. This is implemented here as a - circular buffer. The index is updated simply by incrementing and then - and'ing with 0x7fff (32K-1). */ -/* It is left to other modules to supply the 32K area. It is assumed - to be usable as if it were declared "uch slide[32768];" or as just - "uch *slide;" and then malloc'ed in the latter case. The definition - must be in unzip.h, included above. */ - - -/* Tables for deflate from PKZIP's appnote.txt. */ -static unsigned border[] = { /* Order of the bit length code lengths */ - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; -static WORD cplens[] = { /* Copy lengths for literal codes 257..285 */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - /* note: see note #13 above about the 258 in this list. */ -static WORD cplext[] = { /* Extra bits for literal codes 257..285 */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ -static WORD cpdist[] = { /* Copy offsets for distance codes 0..29 */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577}; -static WORD cpdext[] = { /* Extra bits for distance codes */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13}; - - -// And'ing with mask_bits[n] masks the lower n bits -extern DWORD mask_bits[33]; - -/* Macros for inflate() bit peeking and grabbing. - The usage is: - - NEEDBITS(j) - x = b & mask_bits[j]; - DUMPBITS(j) - - ... [truncated message content] |