From: <sag...@us...> - 2014-06-19 16:24:28
|
Revision: 4140 http://sourceforge.net/p/modplug/code/4140 Author: saga-games Date: 2014-06-19 16:24:09 +0000 (Thu, 19 Jun 2014) Log Message: ----------- [Mod] Update UnRAR library to version 5.1.6 Modified Paths: -------------- trunk/OpenMPT/build/gen/UnRAR.vcproj trunk/OpenMPT/build/gen/UnRAR.vcxproj trunk/OpenMPT/include/premake4.lua trunk/OpenMPT/include/unrar/OpenMPT.txt trunk/OpenMPT/include/unrar/arccmt.cpp trunk/OpenMPT/include/unrar/archive.cpp trunk/OpenMPT/include/unrar/archive.hpp trunk/OpenMPT/include/unrar/arcread.cpp trunk/OpenMPT/include/unrar/blake2s.cpp trunk/OpenMPT/include/unrar/blake2s_sse.cpp trunk/OpenMPT/include/unrar/cmddata.cpp trunk/OpenMPT/include/unrar/coder.hpp trunk/OpenMPT/include/unrar/compress.hpp trunk/OpenMPT/include/unrar/consio.cpp trunk/OpenMPT/include/unrar/consio.hpp trunk/OpenMPT/include/unrar/crc.cpp trunk/OpenMPT/include/unrar/crypt2.cpp trunk/OpenMPT/include/unrar/crypt3.cpp trunk/OpenMPT/include/unrar/dll.cpp trunk/OpenMPT/include/unrar/dll.hpp trunk/OpenMPT/include/unrar/errhnd.cpp trunk/OpenMPT/include/unrar/errhnd.hpp trunk/OpenMPT/include/unrar/extract.cpp trunk/OpenMPT/include/unrar/extract.hpp trunk/OpenMPT/include/unrar/filcreat.cpp trunk/OpenMPT/include/unrar/filcreat.hpp trunk/OpenMPT/include/unrar/file.cpp trunk/OpenMPT/include/unrar/file.hpp trunk/OpenMPT/include/unrar/filefn.cpp trunk/OpenMPT/include/unrar/find.cpp trunk/OpenMPT/include/unrar/hardlinks.cpp trunk/OpenMPT/include/unrar/loclang.hpp trunk/OpenMPT/include/unrar/log.cpp trunk/OpenMPT/include/unrar/makefile trunk/OpenMPT/include/unrar/model.cpp trunk/OpenMPT/include/unrar/model.hpp trunk/OpenMPT/include/unrar/options.cpp trunk/OpenMPT/include/unrar/options.hpp trunk/OpenMPT/include/unrar/os.hpp trunk/OpenMPT/include/unrar/pathfn.cpp trunk/OpenMPT/include/unrar/pathfn.hpp trunk/OpenMPT/include/unrar/rar.cpp trunk/OpenMPT/include/unrar/rar.hpp trunk/OpenMPT/include/unrar/rardefs.hpp trunk/OpenMPT/include/unrar/raros.hpp trunk/OpenMPT/include/unrar/rarvm.cpp trunk/OpenMPT/include/unrar/rawread.cpp trunk/OpenMPT/include/unrar/rawread.hpp trunk/OpenMPT/include/unrar/rdwrfn.cpp trunk/OpenMPT/include/unrar/rdwrfn.hpp trunk/OpenMPT/include/unrar/recvol.cpp trunk/OpenMPT/include/unrar/recvol3.cpp trunk/OpenMPT/include/unrar/recvol5.cpp trunk/OpenMPT/include/unrar/resource.cpp trunk/OpenMPT/include/unrar/rijndael.cpp trunk/OpenMPT/include/unrar/rijndael.hpp trunk/OpenMPT/include/unrar/scantree.cpp trunk/OpenMPT/include/unrar/sha1.cpp trunk/OpenMPT/include/unrar/sha1.hpp trunk/OpenMPT/include/unrar/sha256.cpp trunk/OpenMPT/include/unrar/strfn.cpp trunk/OpenMPT/include/unrar/strfn.hpp trunk/OpenMPT/include/unrar/suballoc.cpp trunk/OpenMPT/include/unrar/suballoc.hpp trunk/OpenMPT/include/unrar/threadmisc.cpp trunk/OpenMPT/include/unrar/threadpool.cpp trunk/OpenMPT/include/unrar/threadpool.hpp trunk/OpenMPT/include/unrar/timefn.cpp trunk/OpenMPT/include/unrar/timefn.hpp trunk/OpenMPT/include/unrar/ulinks.cpp trunk/OpenMPT/include/unrar/unicode.cpp trunk/OpenMPT/include/unrar/unicode.hpp trunk/OpenMPT/include/unrar/unpack.cpp trunk/OpenMPT/include/unrar/unpack.hpp trunk/OpenMPT/include/unrar/unpack50.cpp trunk/OpenMPT/include/unrar/unpack50frag.cpp trunk/OpenMPT/include/unrar/unpack50mt.cpp trunk/OpenMPT/include/unrar/uowners.cpp trunk/OpenMPT/include/unrar/version.hpp trunk/OpenMPT/include/unrar/volume.cpp trunk/OpenMPT/include/unrar/volume.hpp trunk/OpenMPT/include/unrar/win32acl.cpp trunk/OpenMPT/include/unrar/win32lnk.cpp trunk/OpenMPT/include/unrar/win32stm.cpp trunk/OpenMPT/unarchiver/unrar.cpp Added Paths: ----------- trunk/OpenMPT/include/unrar/ui.cpp trunk/OpenMPT/include/unrar/ui.hpp trunk/OpenMPT/include/unrar/uicommon.cpp trunk/OpenMPT/include/unrar/uiconsole.cpp trunk/OpenMPT/include/unrar/uisilent.cpp Modified: trunk/OpenMPT/build/gen/UnRAR.vcproj =================================================================== --- trunk/OpenMPT/build/gen/UnRAR.vcproj 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/build/gen/UnRAR.vcproj 2014-06-19 16:24:09 UTC (rev 4140) @@ -678,6 +678,10 @@ > </File> <File + RelativePath="..\..\include\unrar\ui.cpp" + > + </File> + <File RelativePath="..\..\include\unrar\unicode.cpp" > </File> @@ -938,6 +942,10 @@ > </File> <File + RelativePath="..\..\include\unrar\ui.hpp" + > + </File> + <File RelativePath="..\..\include\unrar\unicode.hpp" > </File> Modified: trunk/OpenMPT/build/gen/UnRAR.vcxproj =================================================================== --- trunk/OpenMPT/build/gen/UnRAR.vcxproj 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/build/gen/UnRAR.vcxproj 2014-06-19 16:24:09 UTC (rev 4140) @@ -342,6 +342,7 @@ <ClInclude Include="..\..\include\unrar\threadpool.hpp" /> <ClInclude Include="..\..\include\unrar\timefn.hpp" /> <ClInclude Include="..\..\include\unrar\ulinks.hpp" /> + <ClInclude Include="..\..\include\unrar\ui.hpp" /> <ClInclude Include="..\..\include\unrar\unicode.hpp" /> <ClInclude Include="..\..\include\unrar\unpack.hpp" /> <ClInclude Include="..\..\include\unrar\version.hpp" /> @@ -440,6 +441,8 @@ </ClCompile> <ClCompile Include="..\..\include\unrar\timefn.cpp"> </ClCompile> + <ClCompile Include="..\..\include\unrar\ui.cpp"> + </ClCompile> <ClCompile Include="..\..\include\unrar\unicode.cpp"> </ClCompile> <ClCompile Include="..\..\include\unrar\unpack.cpp"> Modified: trunk/OpenMPT/include/premake4.lua =================================================================== --- trunk/OpenMPT/include/premake4.lua 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/premake4.lua 2014-06-19 16:24:09 UTC (rev 4140) @@ -52,6 +52,7 @@ "../include/unrar/system.cpp", "../include/unrar/threadpool.cpp", "../include/unrar/timefn.cpp", + "../include/unrar/ui.cpp", "../include/unrar/unicode.cpp", "../include/unrar/unpack.cpp", "../include/unrar/volume.cpp", @@ -119,6 +120,7 @@ "../include/unrar/threadpool.hpp", "../include/unrar/timefn.hpp", "../include/unrar/ulinks.hpp", + "../include/unrar/ui.hpp", "../include/unrar/unicode.hpp", "../include/unrar/unpack.hpp", "../include/unrar/version.hpp", Modified: trunk/OpenMPT/include/unrar/OpenMPT.txt =================================================================== --- trunk/OpenMPT/include/unrar/OpenMPT.txt 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/OpenMPT.txt 2014-06-19 16:24:09 UTC (rev 4140) @@ -1,4 +1,4 @@ -This folder is based on http://www.rarlab.com/rar/unrarsrc-5.0.12.tar.gz +This folder is based on http://www.rarlab.com/rar/unrarsrc-5.1.6.tar.gz All modifications to existing files have been done in a manner so that no existing lines were edited; only new lines were added. Modified: trunk/OpenMPT/include/unrar/arccmt.cpp =================================================================== --- trunk/OpenMPT/include/unrar/arccmt.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/arccmt.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -28,14 +28,14 @@ { // Current (RAR 3.0+) version of archive comment. Seek(GetStartPos(),SEEK_SET); - return(SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData)); + return SearchSubBlock(SUBHEAD_TYPE_CMT)!=0 && ReadCommentData(CmtData); } #ifndef SFX_MODULE // Old style (RAR 2.9) comment header embedded into the main // archive header. if (BrokenHeader) { - Log(FileName,St(MLogCommHead)); + uiMsg(UIERROR_CMTBROKEN,FileName); return false; } CmtLength=CommHead.HeadSize-SIZEOF_COMMHEAD; @@ -75,7 +75,7 @@ if (Format!=RARFMT14 && (DataIO.UnpHash.GetCRC32()&0xffff)!=CommHead.CommCRC) { - Log(FileName,St(MLogCommBrk)); + uiMsg(UIERROR_CMTBROKEN,FileName); return false; } else @@ -99,7 +99,7 @@ if (Format!=RARFMT14 && CommHead.CommCRC!=(~CRC32(0xffffffff,&CmtRaw[0],CmtLength)&0xffff)) { - Log(FileName,St(MLogCommBrk)); + uiMsg(UIERROR_CMTBROKEN,FileName); return false; } CmtData->Alloc(CmtLength+1); Modified: trunk/OpenMPT/include/unrar/archive.cpp =================================================================== --- trunk/OpenMPT/include/unrar/archive.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/archive.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -49,6 +49,7 @@ NewArchive=false; SilentOpen=false; + } @@ -67,9 +68,7 @@ // If FailedHeaderDecryption is set, we already reported that archive // password is incorrect. if (!FailedHeaderDecryption) - { - Log(FileName,St(MBadArc),FileName); - } + uiMsg(UIERROR_BADARCHIVE,FileName); ErrHandler.Exit(RARX_FATAL); } } @@ -91,9 +90,7 @@ return false; if (!IsArchive(false)) { -#ifndef SHELL_EXT - Log(FileName,St(MNotRAR),FileName); -#endif + uiMsg(UIERROR_BADARCHIVE,FileName); Close(); return false; } @@ -132,25 +129,16 @@ { Encrypted=false; BrokenHeader=false; // Might be left from previous volume. -#ifdef USE_QOPEN - QOpen.Unload(); -#endif - - // Important if we reuse Archive object and it has virtual QOpen - // file position not matching real. For example, for 'l -v volname'. - Seek(0,SEEK_SET); #ifndef SFX_MODULE if (IsDevice()) { -#ifndef SHELL_EXT - Log(FileName,St(MInvalidName),FileName); -#endif + uiMsg(UIERROR_INVALIDNAME,FileName,FileName); return false; } #endif if (Read(MarkHead.Mark,SIZEOF_MARKHEAD3)!=SIZEOF_MARKHEAD3) - return(false); + return false; SFXSize=0; RARFORMAT Type; @@ -158,7 +146,7 @@ { Format=Type; if (Format==RARFMT14) - Seek(0,SEEK_SET); + Seek(Tell()-SIZEOF_MARKHEAD3,SEEK_SET); } else { @@ -186,9 +174,7 @@ } if (Format==RARFMT_FUTURE) { -#if !defined(SHELL_EXT) && !defined(SFX_MODULE) - Log(FileName,St(MNewRarFormat)); -#endif + uiMsg(UIERROR_NEWRARFORMAT,FileName); return false; } if (Format==RARFMT50) // RAR 5.0 signature is by one byte longer. @@ -201,6 +187,15 @@ else MarkHead.HeadSize=SIZEOF_MARKHEAD3; +#ifdef RARDLL + // If callback function is not set, we cannot get the password, + // so we skip the initial header processing for encrypted header archive. + // It leads to skipped archive comment, but the rest of archive data + // is processed correctly. + if (Cmd->Callback==NULL) + SilentOpen=true; +#endif + // Skip the archive encryption header if any and read the main header. while (ReadHeader()!=0) { @@ -219,40 +214,13 @@ return false; SeekToNext(); - if (BrokenHeader) + if (BrokenHeader) // Main archive header is corrupt. { -#ifndef SHELL_EXT - Log(FileName,St(MMainHeaderBroken)); -#endif + uiMsg(UIERROR_MHEADERBROKEN,FileName); if (!EnableBroken) return false; } -/* - if (MainHead.EncryptVer>VER_UNPACK) - { -#ifdef RARDLL - Cmd->DllError=ERAR_UNKNOWN_FORMAT; -#else - ErrHandler.SetErrorCode(RARX_WARNING); - #if !defined(SILENT) && !defined(SFX_MODULE) - Log(FileName,St(MUnknownMeth),FileName); - Log(FileName,St(MVerRequired),MainHead.EncryptVer/10,MainHead.EncryptVer%10); - #endif -#endif - return(false); - } -*/ - -#ifdef RARDLL - // If callback function is not set, we cannot get the password, - // so we skip the initial header processing for encrypted header archive. - // It leads to skipped archive comment, but the rest of archive data - // is processed correctly. - if (Cmd->Callback==NULL) - SilentOpen=true; -#endif - MainComment=MainHead.CommentInHeader; // If we process non-encrypted archive or can request a password, @@ -271,12 +239,13 @@ { HEADER_TYPE HeaderType=GetHeaderType(); if (HeaderType==HEAD_SERVICE) - FirstVolume=!SubHead.SplitBefore; + FirstVolume=Volume && !SubHead.SplitBefore; else - { - FirstVolume=HeaderType==HEAD_FILE && !FileHead.SplitBefore; - break; - } + if (HeaderType==HEAD_FILE) + { + FirstVolume=Volume && !FileHead.SplitBefore; + break; + } SeekToNext(); } CurBlockPos=SaveCurBlockPos; @@ -319,6 +288,16 @@ #ifdef USE_QOPEN +bool Archive::Open(const wchar *Name,uint Mode) +{ + // Important if we reuse Archive object and it has virtual QOpen + // file position not matching real. For example, for 'l -v volname'. + QOpen.Unload(); + + return File::Open(Name,Mode); +} + + int Archive::Read(void *Data,size_t Size) { size_t Result; Modified: trunk/OpenMPT/include/unrar/archive.hpp =================================================================== --- trunk/OpenMPT/include/unrar/archive.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/archive.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -86,10 +86,10 @@ const wchar *Name,uint Flags); bool ReadSubData(Array<byte> *UnpData,File *DestFile); HEADER_TYPE GetHeaderType() {return(CurHeaderType);}; - void WriteCommentData(byte *Data,size_t DataSize,bool FileComment); RAROptions* GetRAROptions() {return(Cmd);} void SetSilentOpen(bool Mode) {SilentOpen=Mode;} #ifdef USE_QOPEN + bool Open(const wchar *Name,uint Mode=FMF_READ); int Read(void *Data,size_t Size); void Seek(int64 Offset,int Method); int64 Tell(); Modified: trunk/OpenMPT/include/unrar/arcread.cpp =================================================================== --- trunk/OpenMPT/include/unrar/arcread.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/arcread.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -88,11 +88,9 @@ // If block positions are equal to file size, this is not an error. // It can happen when we reached the end of older RAR 1.5 archive, // which did not have the end of archive block. - if (CurBlockPos>ArcSize || NextBlockPos>ArcSize) + if (CurBlockPos!=ArcSize || NextBlockPos!=ArcSize) { -#ifndef SHELL_EXT - Log(FileName,St(MLogUnexpEOF)); -#endif + uiMsg(UIERROR_UNEXPEOF,FileName); ErrHandler.SetErrorCode(RARX_WARNING); } } @@ -100,9 +98,7 @@ void Archive::BrokenHeaderMsg() { -#ifndef SHELL_EXT - Log(FileName,St(MHeaderBroken)); -#endif + uiMsg(UIERROR_HEADERBROKEN,FileName); BrokenHeader=true; ErrHandler.SetErrorCode(RARX_CRC); } @@ -110,9 +106,7 @@ void Archive::UnkEncVerMsg(const wchar *Name) { -#ifndef SHELL_EXT - Log(FileName,St(MUnkEncMethod),Name); -#endif + uiMsg(UIERROR_UNKNOWNENCMETHOD,FileName,Name); ErrHandler.SetErrorCode(RARX_WARNING); } @@ -316,15 +310,10 @@ { EncodeFileName NameCoder; size_t Length=strlen(FileName); - if (Length==NameSize) - UtfToWide(FileName,hd->FileName,ASIZE(hd->FileName)-1); - else - { - Length++; - NameCoder.Decode(FileName,(byte *)FileName+Length, - NameSize-Length,hd->FileName, - ASIZE(hd->FileName)); - } + Length++; + NameCoder.Decode(FileName,(byte *)FileName+Length, + NameSize-Length,hd->FileName, + ASIZE(hd->FileName)); } else *hd->FileName=0; @@ -419,11 +408,7 @@ // to have anything sensible in file name field, so it is useless // to display the file name. if (!Decrypt) - { -#ifndef SHELL_EXT - Log(Archive::FileName,St(MLogFileHead),hd->FileName); -#endif - } + uiMsg(UIERROR_FHEADERBROKEN,Archive::FileName,hd->FileName); } } break; @@ -551,9 +536,7 @@ if (Decrypt) { -#ifndef SILENT - Log(FileName,St(MEncrBadCRC),FileName); -#endif + uiMsg(UIERROR_CHECKSUMENC,FileName,FileName); FailedHeaderDecryption=true; return 0; } @@ -595,7 +578,7 @@ // Verify password validity. if (CryptHead.UsePswCheck && memcmp(PswCheck,CryptHead.PswCheck,SIZE_PSWCHECK)!=0) { - Log(FileName,St(MWrongPassword)); + uiMsg(UIERROR_BADPSW,FileName); FailedHeaderDecryption=true; ErrHandler.SetErrorCode(RARX_BADPWD); return 0; @@ -608,8 +591,12 @@ // Header size must not occupy more than 3 variable length integer bytes // resulting in 2 MB maximum header size, so here we read 4 byte CRC32 // followed by 3 bytes or less of header size. - const size_t FirstReadSize=7; - Raw.Read(FirstReadSize); + const size_t FirstReadSize=7; // Smallest possible block size. + if (Raw.Read(FirstReadSize)<FirstReadSize) + { + UnexpEndArcMsg(); + return 0; + } ShortBlock.Reset(); ShortBlock.HeadCRC=Raw.Get4(); @@ -618,7 +605,7 @@ if (BlockSize==0 || SizeBytes==0) { - UnexpEndArcMsg(); // Incomplete or broken block size field. + BrokenHeaderMsg(); return 0; } @@ -659,9 +646,7 @@ if (Decrypt) { -#ifndef SILENT - Log(FileName,St(MEncrBadCRC),FileName); -#endif + uiMsg(UIERROR_CHECKSUMENC,FileName,FileName); FailedHeaderDecryption=true; return 0; } @@ -845,13 +830,8 @@ MainComment=true; - if (BadCRC) - { - // Add the file name to broken header message displayed above. -#ifndef SHELL_EXT - Log(Archive::FileName,St(MLogFileHead),hd->FileName); -#endif - } + if (BadCRC) // Add the file name to broken header message displayed above. + uiMsg(UIERROR_FHEADERBROKEN,Archive::FileName,hd->FileName); } break; case HEAD_ENDARC: @@ -906,9 +886,10 @@ ErrHandler.Exit(RARX_USERBREAK); } #else - if (!GetPassword(PASSWORD_ARCHIVE,FileName,&Cmd->Password)) + if (!uiGetPassword(UIPASSWORD_ARCHIVE,FileName,&Cmd->Password)) { Close(); + uiMsg(UIERROR_INCERRCOUNT); ErrHandler.Exit(RARX_USERBREAK); } #endif @@ -1068,6 +1049,9 @@ Raw->GetB(UtfName,NameSize); UtfName[NameSize]=0; } +#ifdef _WIN_ALL + UnixSlashToDos(UtfName,UtfName,ASIZE(UtfName)); +#endif UtfToWide(UtfName,hd->RedirName,ASIZE(hd->RedirName)); } break; @@ -1175,6 +1159,7 @@ char FileName[NM]; Raw.GetB((byte *)FileName,Min(NameSize,ASIZE(FileName))); FileName[NameSize]=0; + IntToExt(FileName,FileName,ASIZE(FileName)); CharToWide(FileName,FileHead.FileName,ASIZE(FileHead.FileName)); ConvertNameCase(FileHead.FileName); @@ -1215,6 +1200,10 @@ // when creating a file or directory. The typical default value // for the process umask is S_IWGRP | S_IWOTH (octal 022), // resulting in 0644 mode for new files. + // Normally umask is applied automatically when creating a file, + // but we set attributes with chmod later, so we need to calculate + // resulting attributes here. We do it only for non-Unix archives. + // We restore native Unix attributes as is, because it can be backup. static mode_t mask = (mode_t) -1; if (mask == (mode_t) -1) @@ -1329,17 +1318,13 @@ return false; // OPENMPT ADDITION if (BrokenHeader) { -#ifndef SHELL_EXT - Log(FileName,St(MSubHeadCorrupt)); -#endif + uiMsg(UIERROR_SUBHEADERBROKEN,FileName); ErrHandler.SetErrorCode(RARX_CRC); return false; } if (SubHead.Method>5 || SubHead.UnpVer>(Format==RARFMT50 ? VER_UNPACK5:VER_UNPACK)) { -#ifndef SHELL_EXT - Log(FileName,St(MSubHeadUnknown)); -#endif + uiMsg(UIERROR_SUBHEADERUNKNOWN,FileName); return false; } @@ -1355,9 +1340,7 @@ if (SubHead.UnpSize>0x1000000) { // So huge allocation must never happen in valid archives. -#ifndef SHELL_EXT - Log(FileName,St(MSubHeadUnknown)); -#endif + uiMsg(UIERROR_SUBHEADERUNKNOWN,FileName); return false; } UnpData->Alloc((size_t)SubHead.UnpSize); @@ -1384,9 +1367,7 @@ if (!SubDataIO.UnpHash.Cmp(&SubHead.FileHash,SubHead.UseHashKey ? SubHead.HashKey:NULL)) { -#ifndef SHELL_EXT - Log(FileName,St(MSubHeadDataCRC),SubHead.FileName); -#endif + uiMsg(UIERROR_SUBHEADERDATABROKEN,FileName,SubHead.FileName); ErrHandler.SetErrorCode(RARX_CRC); if (UnpData!=NULL) UnpData->Reset(); Modified: trunk/OpenMPT/include/unrar/blake2s.cpp =================================================================== --- trunk/OpenMPT/include/unrar/blake2s.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/blake2s.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -57,6 +57,11 @@ /* init2 xors IV with input parameter block */ void blake2s_init_param( blake2s_state *S, uint32 node_offset, uint32 node_depth) { +#ifdef USE_SSE + if (_SSE_Version>=SSE_SSE2) + blake2s_init_sse(); +#endif + S->init(); // Clean data. for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i]; Modified: trunk/OpenMPT/include/unrar/blake2s_sse.cpp =================================================================== --- trunk/OpenMPT/include/unrar/blake2s_sse.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/blake2s_sse.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -2,6 +2,35 @@ extern const byte blake2s_sigma[10][16]; +// Initialization vector. +static __m128i blake2s_IV_0_3, blake2s_IV_4_7; + +#ifdef _WIN_64 +// Constants for cyclic rotation. Used in 64-bit mode in mm_rotr_epi32 macro. +static __m128i crotr8, crotr16; +#endif + +static void blake2s_init_sse() +{ + // We cannot initialize these 128 bit variables in place when declaring + // them globally, because global scope initialization is performed before + // our SSE check and it would make code incompatible with older non-SSE2 + // CPUs. Also we cannot initialize them as static inside of function + // using these variables, because SSE static initialization is not thread + // safe: first thread starts initialization and sets "init done" flag even + // if it is not done yet, second thread can attempt to access half-init + // SSE data. So we moved init code here. + + blake2s_IV_0_3 = _mm_setr_epi32( 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A ); + blake2s_IV_4_7 = _mm_setr_epi32( 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 ); + +#ifdef _WIN_64 + crotr8 = _mm_set_epi8( 12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1 ); + crotr16 = _mm_set_epi8( 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 ); +#endif +} + + #define LOAD(p) _mm_load_si128( (__m128i *)(p) ) #define STORE(p,r) _mm_store_si128((__m128i *)(p), r) @@ -72,21 +101,6 @@ static int blake2s_compress_sse( blake2s_state *S, const byte block[BLAKE2S_BLOCKBYTES] ) { - // Initialization vector. Moving them outside of function would provide - // ~5% speed gain in 32-bit mode, but would make code incompatible - // with older non-SSE2 compatible CPUs. Global static initialization - // is performed before our SSE check. - static const __m128i blake2s_IV_0_3 = _mm_setr_epi32( 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A ); - static const __m128i blake2s_IV_4_7 = _mm_setr_epi32( 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 ); - -#ifdef _WIN_64 - // Constants for cyclic rotation. We use them in 64-bit mode - // in mm_rotr_epi32 macro above. We must not define in global scope - // to be compatible with non-SSE CPU. - static const __m128i crotr8 = _mm_set_epi8( 12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1 ); - static const __m128i crotr16 = _mm_set_epi8( 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 ); -#endif - __m128i row[4]; __m128i ff0, ff1; Modified: trunk/OpenMPT/include/unrar/cmddata.cpp =================================================================== --- trunk/OpenMPT/include/unrar/cmddata.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/cmddata.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -1,6 +1,5 @@ #include "rar.hpp" - CommandData::CommandData() { Init(); @@ -45,7 +44,7 @@ } -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ParseCommandLine(bool Preprocess,int argc, char *argv[]) { #ifdef CUSTOM_CMDLINE_PARSER @@ -90,7 +89,7 @@ #endif -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ParseArg(wchar *Arg) { if (IsSwitch(*Arg) && !NoMoreSwitches) @@ -182,7 +181,7 @@ } -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ParseEnvVar() { char *EnvStr=getenv("RAR"); @@ -197,7 +196,7 @@ -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) // Preprocess those parameters, which must be processed before the rest of // command line. Return 'false' to stop further processing. bool CommandData::PreprocessSwitch(const wchar *Switch) @@ -235,7 +234,7 @@ #endif -#if !defined(GUI) && !defined(SFX_MODULE) +#if !defined(GUI) && !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ReadConfig() { StringList List; @@ -254,7 +253,7 @@ #endif -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ProcessSwitchesString(const wchar *Str) { wchar *Par; @@ -268,7 +267,7 @@ #endif -#if !defined(SFX_MODULE) +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::ProcessSwitch(const wchar *Switch) { @@ -366,17 +365,14 @@ break; } break; - case 'E': - ProcessEA=false; - break; default: if (Switch[1]=='+') { - InclFileAttr=GetExclAttr(Switch+2); + InclFileAttr|=GetExclAttr(Switch+2); InclAttrSet=true; } else - ExclFileAttr=GetExclAttr(Switch+1); + ExclFileAttr|=GetExclAttr(Switch+1); break; } break; @@ -399,7 +395,7 @@ else if (!Password.IsSet()) { - GetPassword(PASSWORD_GLOBAL,NULL,&Password); + uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password); eprintf(L"\n"); } break; @@ -534,7 +530,7 @@ Names++; wchar Mask[NM]; if (wcspbrk(Names,L"*?.")==NULL) - swprintf(Mask,ASIZE(Mask),L"*.%s",Names); + swprintf(Mask,ASIZE(Mask),L"*.%ls",Names); else wcsncpyz(Mask,Names,ASIZE(Mask)); StoreArgs.AddString(Mask); @@ -630,7 +626,7 @@ case 'P': if (Switch[1]==0) { - GetPassword(PASSWORD_GLOBAL,NULL,&Password); + uiGetPassword(UIPASSWORD_GLOBAL,NULL,&Password); eprintf(L"\n"); } else @@ -885,7 +881,7 @@ #endif -#ifndef SFX_MODULE +#if !defined(SFX_MODULE) && !defined(_ANDROID) void CommandData::BadSwitch(const wchar *Switch) { mprintf(St(MUnknownOption),Switch); @@ -931,7 +927,7 @@ // If MSGID is const char*, we cannot compare pointers only. // Pointers to different instances of same string can differ, // so we need to compare complete strings. - return strcmp(i1,i2)==0; + return wcscmp(i1,i2)==0; #endif } @@ -952,9 +948,10 @@ MCHelpSwDH,MCHelpSwEP,MCHelpSwEP3,MCHelpSwF,MCHelpSwIDP,MCHelpSwIERR, MCHelpSwINUL,MCHelpSwIOFF,MCHelpSwKB,MCHelpSwN,MCHelpSwNa,MCHelpSwNal, MCHelpSwO,MCHelpSwOC,MCHelpSwOR,MCHelpSwOW,MCHelpSwP, - MCHelpSwPm,MCHelpSwR,MCHelpSwRI,MCHelpSwSL,MCHelpSwSM,MCHelpSwTA, - MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU,MCHelpSwVUnr, - MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal,MCHelpSwY + MCHelpSwPm,MCHelpSwR,MCHelpSwRI,MCHelpSwSC,MCHelpSwSL,MCHelpSwSM, + MCHelpSwTA,MCHelpSwTB,MCHelpSwTN,MCHelpSwTO,MCHelpSwTS,MCHelpSwU, + MCHelpSwVUnr,MCHelpSwVER,MCHelpSwVP,MCHelpSwX,MCHelpSwXa,MCHelpSwXal, + MCHelpSwY #else #endif }; @@ -995,16 +992,7 @@ if (CmpMSGID(Help[I],MCHelpSwMT)) continue; #endif - if (CmpMSGID(Help[I],MCHelpSwEE)) - { -#if defined(_EMX) && !defined(_DJGPP) - if (_osmode != OS2_MODE) - continue; -#else - continue; #endif - } -#endif mprintf(St(Help[I])); } mprintf(L"\n"); @@ -1228,7 +1216,7 @@ case 'I': { CmdExtract Extract(this); - Extract.DoExtract(this); + Extract.DoExtract(); } break; #ifndef SILENT @@ -1334,37 +1322,23 @@ if (Format==RARFMT15) { if (HashType!=HASH_CRC32) - { - mprintf(St(MIncompatSwitch),L"-ht",4); - } + uiMsg(UIERROR_INCOMPATSWITCH,L"-ht",4); #ifdef _WIN_ALL if (SaveSymLinks) - { - mprintf(St(MIncompatSwitch),L"-ol",4); - } + uiMsg(UIERROR_INCOMPATSWITCH,L"-ol",4); #endif if (SaveHardLinks) - { - mprintf(St(MIncompatSwitch),L"-oh",4); - } + uiMsg(UIERROR_INCOMPATSWITCH,L"-oh",4); #ifdef _WIN_ALL + // Do not report a wrong dictionary size here, because we are not sure + // yet about archive format. We can switch to RAR5 mode later + // if we update RAR5 archive. #endif if (QOpenMode!=QOPEN_AUTO) - { - mprintf(St(MIncompatSwitch),L"-qo",4); - } -/* - // We use 64 MB for both formats and reduce it for RAR 4.x later. - if (WinSize>0x400000) - { - wchar SwMD[10]; - swprintf(SwMD,ASIZE(SwMD),L"-md%dm",WinSize/0x100000); - mprintf(St(MIncompatSwitch),SwMD,4); - } -*/ + uiMsg(UIERROR_INCOMPATSWITCH,L"-qo",4); } if (Format==RARFMT50) { Modified: trunk/OpenMPT/include/unrar/coder.hpp =================================================================== --- trunk/OpenMPT/include/unrar/coder.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/coder.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -2,9 +2,7 @@ * Contents: 'Carryless rangecoder' by Dmitry Subbotin * ****************************************************************************/ -const uint TOP=1 << 24, BOT=1 << 15; - class RangeCoder { public: Modified: trunk/OpenMPT/include/unrar/compress.hpp =================================================================== --- trunk/OpenMPT/include/unrar/compress.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/compress.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -1,38 +1,45 @@ #ifndef _RAR_COMPRESS_ #define _RAR_COMPRESS_ -#define MAX_LZ_MATCH 0x1001 -#define MAX3_LZ_MATCH 0x101 // Maximum match length for RAR v3. +// Combine pack and unpack constants to class to avoid polluting global +// namespace with numerous short names. +class PackDef +{ + public: + static const uint MAX_LZ_MATCH = 0x1001; + static const uint MAX3_LZ_MATCH = 0x101; // Maximum match length for RAR v3. + static const uint LOW_DIST_REP_COUNT = 16; -#define LOW_DIST_REP_COUNT 16 + static const uint NC = 306; /* alphabet = {0, 1, 2, ..., NC - 1} */ + static const uint DC = 64; + static const uint LDC = 16; + static const uint RC = 44; + static const uint HUFF_TABLE_SIZE = NC + DC + RC + LDC; + static const uint BC = 20; -#define NC 306 /* alphabet = {0, 1, 2, ..., NC - 1} */ -#define DC 64 -#define LDC 16 -#define RC 44 -#define HUFF_TABLE_SIZE (NC+DC+RC+LDC) -#define BC 20 + static const uint NC30 = 299; /* alphabet = {0, 1, 2, ..., NC - 1} */ + static const uint DC30 = 60; + static const uint LDC30 = 17; + static const uint RC30 = 28; + static const uint BC30 = 20; + static const uint HUFF_TABLE_SIZE30 = NC30 + DC30 + RC30 + LDC30; -#define NC30 299 /* alphabet = {0, 1, 2, ..., NC - 1} */ -#define DC30 60 -#define LDC30 17 -#define RC30 28 -#define BC30 20 -#define HUFF_TABLE_SIZE30 (NC30+DC30+RC30+LDC30) + static const uint NC20 = 298; /* alphabet = {0, 1, 2, ..., NC - 1} */ + static const uint DC20 = 48; + static const uint RC20 = 28; + static const uint BC20 = 19; + static const uint MC20 = 257; -#define NC20 298 /* alphabet = {0, 1, 2, ..., NC - 1} */ -#define DC20 48 -#define RC20 28 -#define BC20 19 -#define MC20 257 + // Largest alphabet size among all values listed above. + static const uint LARGEST_TABLE_SIZE = 306; -// Largest alphabet size among all values listed above. -#define LARGEST_TABLE_SIZE 306 + enum { + CODE_HUFFMAN, CODE_LZ, CODE_REPEATLZ, CODE_CACHELZ, CODE_STARTFILE, + CODE_ENDFILE, CODE_FILTER, CODE_FILTERDATA + }; +}; -enum {CODE_HUFFMAN,CODE_LZ,CODE_REPEATLZ,CODE_CACHELZ, - CODE_STARTFILE,CODE_ENDFILE,CODE_FILTER,CODE_FILTERDATA}; - enum FilterType { // These values must not be changed, because we use them directly // in RAR5 compression and decompression code. Modified: trunk/OpenMPT/include/unrar/consio.cpp =================================================================== --- trunk/OpenMPT/include/unrar/consio.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/consio.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -2,7 +2,6 @@ #include "log.cpp" static MESSAGE_TYPE MsgStream=MSG_STDOUT; -static bool Sound=false; const int MaxMsgSize=2*NM+2048; #ifdef _WIN_ALL @@ -47,10 +46,9 @@ } -void InitConsoleOptions(MESSAGE_TYPE MsgStream,bool Sound) +void InitConsoleOptions(MESSAGE_TYPE MsgStream) { ::MsgStream=MsgStream; - ::Sound=Sound; } @@ -125,25 +123,6 @@ #ifndef SILENT -void Alarm() -{ - if (Sound) - { - static clock_t LastTime=clock(); - if ((clock()-LastTime)/CLOCKS_PER_SEC>5) - { -#ifdef _WIN_ALL - MessageBeep(-1); -#else - putwchar('\007'); -#endif - } - } -} -#endif - - -#ifndef SILENT static void GetPasswordText(wchar *Str,uint MaxLength) { if (MaxLength==0) @@ -181,22 +160,22 @@ #ifndef SILENT -bool GetConsolePassword(PASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password) +bool GetConsolePassword(UIPASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password) { - Alarm(); + uiAlarm(UIALARM_QUESTION); while (true) { - if (Type==PASSWORD_GLOBAL) + if (Type==UIPASSWORD_GLOBAL) eprintf(L"\n%s: ",St(MAskPsw)); else eprintf(St(MAskPswFor),FileName); wchar PlainPsw[MAXPASSWORD]; GetPasswordText(PlainPsw,ASIZE(PlainPsw)); - if (*PlainPsw==0 && Type==PASSWORD_GLOBAL) + if (*PlainPsw==0 && Type==UIPASSWORD_GLOBAL) return false; - if (Type==PASSWORD_GLOBAL) + if (Type==UIPASSWORD_GLOBAL) { eprintf(St(MReAskPsw)); wchar CmpStr[MAXPASSWORD]; @@ -264,9 +243,13 @@ #ifndef SILENT +// We allow this function to return 0 in case of invalid input, +// because it might be convenient to press Enter to some not dangerous +// prompts like "insert disk with next volume". We should call this function +// again in case of 0 in dangerous prompt such as overwriting file. int Ask(const wchar *AskStr) { - Alarm(); + uiAlarm(UIALARM_QUESTION); const int MaxItems=10; wchar Item[MaxItems][40]; Modified: trunk/OpenMPT/include/unrar/consio.hpp =================================================================== --- trunk/OpenMPT/include/unrar/consio.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/consio.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -2,11 +2,11 @@ #define _RAR_CONSIO_ void InitConsole(); -void InitConsoleOptions(MESSAGE_TYPE MsgStream,bool Sound); +void InitConsoleOptions(MESSAGE_TYPE MsgStream); void OutComment(const wchar *Comment,size_t Size); #ifndef SILENT -bool GetConsolePassword(PASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password); +bool GetConsolePassword(UIPASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password); #endif #ifdef SILENT Modified: trunk/OpenMPT/include/unrar/crc.cpp =================================================================== --- trunk/OpenMPT/include/unrar/crc.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/crc.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -56,7 +56,7 @@ byte *Data=(byte *)Addr; // Align Data to 8 for better performance. - for (;Size>0 && ((long)Data & 7);Size--,Data++) + for (;Size>0 && ((size_t)Data & 7);Size--,Data++) StartCRC=crc_tables[0][(byte)(StartCRC^Data[0])]^(StartCRC>>8); for (;Size>=8;Size-=8,Data+=8) Modified: trunk/OpenMPT/include/unrar/crypt2.cpp =================================================================== --- trunk/OpenMPT/include/unrar/crypt2.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/crypt2.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -62,7 +62,7 @@ void CryptData::EncryptBlock20(byte *Buf) { uint A,B,C,D,T,TA,TB; -#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_NOT_ALIGNED_INT) +#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_MISALIGNED) A=((uint)Buf[0]|((uint)Buf[1]<<8)|((uint)Buf[2]<<16)|((uint)Buf[3]<<24))^Key20[0]; B=((uint)Buf[4]|((uint)Buf[5]<<8)|((uint)Buf[6]<<16)|((uint)Buf[7]<<24))^Key20[1]; C=((uint)Buf[8]|((uint)Buf[9]<<8)|((uint)Buf[10]<<16)|((uint)Buf[11]<<24))^Key20[2]; @@ -85,7 +85,7 @@ C=TA; D=TB; } -#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_NOT_ALIGNED_INT) +#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_MISALIGNED) C^=Key20[0]; Buf[0]=(byte)C; Buf[1]=(byte)(C>>8); @@ -120,7 +120,7 @@ { byte InBuf[16]; uint A,B,C,D,T,TA,TB; -#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_NOT_ALIGNED_INT) +#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_MISALIGNED) A=((uint)Buf[0]|((uint)Buf[1]<<8)|((uint)Buf[2]<<16)|((uint)Buf[3]<<24))^Key20[0]; B=((uint)Buf[4]|((uint)Buf[5]<<8)|((uint)Buf[6]<<16)|((uint)Buf[7]<<24))^Key20[1]; C=((uint)Buf[8]|((uint)Buf[9]<<8)|((uint)Buf[10]<<16)|((uint)Buf[11]<<24))^Key20[2]; @@ -144,7 +144,7 @@ C=TA; D=TB; } -#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_NOT_ALIGNED_INT) +#if defined(BIG_ENDIAN) || !defined(PRESENT_INT32) || !defined(ALLOW_MISALIGNED) C^=Key20[0]; Buf[0]=(byte)C; Buf[1]=(byte)(C>>8); Modified: trunk/OpenMPT/include/unrar/crypt3.cpp =================================================================== --- trunk/OpenMPT/include/unrar/crypt3.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/crypt3.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -47,28 +47,28 @@ memcpy(RawPsw+RawLength,Salt,SIZE_SALT30); RawLength+=SIZE_SALT30; } - hash_context c; - hash_initial(&c); + sha1_context c; + sha1_init(&c); const int HashRounds=0x40000; for (int I=0;I<HashRounds;I++) { - hash_process( &c, RawPsw, RawLength, false); + sha1_process( &c, RawPsw, RawLength, false); byte PswNum[3]; PswNum[0]=(byte)I; PswNum[1]=(byte)(I>>8); PswNum[2]=(byte)(I>>16); - hash_process( &c, PswNum, 3, false); + sha1_process( &c, PswNum, 3, false); if (I%(HashRounds/16)==0) { - hash_context tempc=c; + sha1_context tempc=c; uint32 digest[5]; - hash_final( &tempc, digest, false); + sha1_done( &tempc, digest, false); AESInit[I/(HashRounds/16)]=(byte)digest[4]; } } uint32 digest[5]; - hash_final( &c, digest, false); + sha1_done( &c, digest, false); for (int I=0;I<4;I++) for (int J=0;J<4;J++) AESKey[I*4+J]=(byte)(digest[I]>>(J*8)); Modified: trunk/OpenMPT/include/unrar/dll.cpp =================================================================== --- trunk/OpenMPT/include/unrar/dll.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/dll.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -65,7 +65,10 @@ Data->Cmd.Callback=r->Callback; Data->Cmd.UserData=r->UserData; - if (!Data->Arc.Open(ArcName,0)) + // Open shared mode is added by request of dll users, who need to + // browse and unpack archives while downloading. + Data->Cmd.OpenShared = true; + if (!Data->Arc.Open(ArcName,FMF_OPENSHARED)) { r->OpenResult=ERAR_EOPEN; delete Data; @@ -73,7 +76,16 @@ } if (!Data->Arc.IsArchive(false)) { - r->OpenResult=Data->Cmd.DllError!=0 ? Data->Cmd.DllError:ERAR_BAD_ARCHIVE; + if (Data->Cmd.DllError!=0) + r->OpenResult=Data->Cmd.DllError; + else + { + RAR_EXIT ErrCode=ErrHandler.GetErrorCode(); + if (ErrCode!=RARX_SUCCESS && ErrCode!=RARX_WARNING) + r->OpenResult=RarErrorToDll(ErrCode); + else + r->OpenResult=ERAR_BAD_ARCHIVE; + } delete Data; return NULL; } @@ -113,7 +125,7 @@ } else r->CmtState=r->CmtSize=0; - Data->Extract.ExtractArchiveInit(&Data->Cmd,Data->Arc); + Data->Extract.ExtractArchiveInit(Data->Arc); return (HANDLE)Data; } catch (RAR_EXIT ErrCode) @@ -126,7 +138,7 @@ delete Data; return NULL; } - catch (std::bad_alloc) // Catch 'new' exception. + catch (std::bad_alloc&) // Catch 'new' exception. { r->OpenResult=ERAR_NO_MEMORY; if (Data != NULL) @@ -186,7 +198,16 @@ } else return ERAR_EOPEN; - return(Data->Arc.BrokenHeader ? ERAR_BAD_DATA:ERAR_END_ARCHIVE); + + if (Data->Arc.BrokenHeader) + return ERAR_BAD_DATA; + + // Might be necessary if RARSetPassword is still called instead of + // open callback for RAR5 archives and if password is invalid. + if (Data->Arc.FailedHeaderDecryption) + return ERAR_BAD_PASSWORD; + + return ERAR_END_ARCHIVE; } FileHeader *hd=&Data->Arc.FileHead; if (Data->OpenMode==RAR_OM_LIST && hd->SplitBefore) @@ -197,7 +218,7 @@ else return Code; } - wcsncpy(D->ArcNameW,hd->FileName,ASIZE(D->ArcNameW)); + wcsncpy(D->ArcNameW,Data->Arc.FileName,ASIZE(D->ArcNameW)); WideToChar(D->ArcNameW,D->ArcName,ASIZE(D->ArcName)); wcsncpy(D->FileNameW,hd->FileName,ASIZE(D->FileNameW)); @@ -290,10 +311,12 @@ if (DestPath!=NULL) { char ExtrPathA[NM]; + strncpyz(ExtrPathA,DestPath,ASIZE(ExtrPathA)-2); #ifdef _WIN_ALL - OemToCharBuffA(DestPath,ExtrPathA,ASIZE(ExtrPathA)-2); -#else - strncpyz(ExtrPathA,DestPath,ASIZE(ExtrPathA)-2); + // We must not apply OemToCharBuffA directly to DestPath, + // because we do not know DestPath length and OemToCharBuffA + // does not stop at 0. + OemToCharA(ExtrPathA,ExtrPathA); #endif CharToWide(ExtrPathA,Data->Cmd.ExtrPath,ASIZE(Data->Cmd.ExtrPath)); AddEndSlash(Data->Cmd.ExtrPath,ASIZE(Data->Cmd.ExtrPath)); @@ -301,10 +324,12 @@ if (DestName!=NULL) { char DestNameA[NM]; + strncpyz(DestNameA,DestName,ASIZE(DestNameA)-2); #ifdef _WIN_ALL - OemToCharBuffA(DestName,DestNameA,ASIZE(DestNameA)-2); -#else - strncpyz(DestNameA,DestName,ASIZE(DestNameA)-2); + // We must not apply OemToCharBuffA directly to DestName, + // because we do not know DestName length and OemToCharBuffA + // does not stop at 0. + OemToCharA(DestNameA,DestNameA); #endif CharToWide(DestNameA,Data->Cmd.DllDestName,ASIZE(Data->Cmd.DllDestName)); } @@ -321,7 +346,7 @@ wcscpy(Data->Cmd.Command,Operation==RAR_EXTRACT ? L"X":L"T"); Data->Cmd.Test=Operation!=RAR_EXTRACT; bool Repeat=false; - Data->Extract.ExtractCurrentFile(&Data->Cmd,Data->Arc,Data->HeaderSize,Repeat); + Data->Extract.ExtractCurrentFile(Data->Arc,Data->HeaderSize,Repeat); // Now we process extra file information if any. // @@ -333,13 +358,13 @@ while (Data->Arc.IsOpened() && Data->Arc.ReadHeader()!=0 && Data->Arc.GetHeaderType()==HEAD_SERVICE) { - Data->Extract.ExtractCurrentFile(&Data->Cmd,Data->Arc,Data->HeaderSize,Repeat); + Data->Extract.ExtractCurrentFile(Data->Arc,Data->HeaderSize,Repeat); Data->Arc.SeekToNext(); } Data->Arc.Seek(Data->Arc.CurBlockPos,SEEK_SET); } } - catch (std::bad_alloc) + catch (std::bad_alloc&) { return ERAR_NO_MEMORY; } @@ -419,6 +444,8 @@ return ERAR_ECREATE; case RARX_MEMORY: return ERAR_NO_MEMORY; + case RARX_BADPWD: + return ERAR_BAD_PASSWORD; case RARX_SUCCESS: return ERAR_SUCCESS; // 0. default: Modified: trunk/OpenMPT/include/unrar/dll.hpp =================================================================== --- trunk/OpenMPT/include/unrar/dll.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/dll.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -17,6 +17,8 @@ #define ERAR_SMALL_BUF 20 #define ERAR_UNKNOWN 21 #define ERAR_MISSING_PASSWORD 22 +#define ERAR_EREFERENCE 23 +#define ERAR_BAD_PASSWORD 24 #define RAR_OM_LIST 0 #define RAR_OM_EXTRACT 1 Modified: trunk/OpenMPT/include/unrar/errhnd.cpp =================================================================== --- trunk/OpenMPT/include/unrar/errhnd.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/errhnd.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -1,6 +1,5 @@ #include "rar.hpp" - ErrorHandler::ErrorHandler() { Clean(); @@ -22,7 +21,7 @@ void ErrorHandler::MemoryError() { MemoryErrorMsg(); - Throw(RARX_MEMORY); + Exit(RARX_MEMORY); } @@ -30,22 +29,20 @@ { #ifndef SILENT OpenErrorMsg(FileName); - Throw(RARX_OPEN); + Exit(RARX_OPEN); #endif } void ErrorHandler::CloseError(const wchar *FileName) { -#ifndef SILENT if (!UserBreak) { - Log(NULL,St(MErrFClose),FileName); + uiMsg(UIERROR_FILECLOSE,FileName); SysErrMsg(); } -#endif #if !defined(SILENT) || defined(RARDLL) - Throw(RARX_FATAL); + Exit(RARX_FATAL); #endif } @@ -56,7 +53,7 @@ ReadErrorMsg(FileName); #endif #if !defined(SILENT) || defined(RARDLL) - Throw(RARX_FATAL); + Exit(RARX_FATAL); #endif } @@ -67,9 +64,7 @@ if (!Silent) { SysErrMsg(); - mprintf(L"\n"); - Log(NULL,St(MErrRead),FileName); - return Ask(St(MRetryAbort))==1; + return uiAskRepeatRead(FileName); } #endif return false; @@ -82,7 +77,7 @@ WriteErrorMsg(ArcName,FileName); #endif #if !defined(SILENT) || defined(RARDLL) - Throw(RARX_WRITE); + Exit(RARX_WRITE); #endif } @@ -90,12 +85,10 @@ #ifdef _WIN_ALL void ErrorHandler::WriteErrorFAT(const wchar *FileName) { -#if !defined(SILENT) && !defined(SFX_MODULE) SysErrMsg(); - Log(NULL,St(MNTFSRequired),FileName); -#endif + uiMsg(UIERROR_NTFSREQUIRED,FileName); #if !defined(SILENT) && !defined(SFX_MODULE) || defined(RARDLL) - Throw(RARX_WRITE); + Exit(RARX_WRITE); #endif } #endif @@ -107,9 +100,7 @@ if (!Silent) { SysErrMsg(); - mprintf(L"\n"); - Log(NULL,St(DiskFull ? MNotEnoughDisk:MErrWrite),FileName); - return Ask(St(MRetryAbort))==1; + return uiAskRepeatWrite(FileName,DiskFull); } #endif return false; @@ -118,15 +109,13 @@ void ErrorHandler::SeekError(const wchar *FileName) { -#ifndef SILENT if (!UserBreak) { - Log(NULL,St(MErrSeek),FileName); + uiMsg(UIERROR_FILESEEK,FileName); SysErrMsg(); } -#endif #if !defined(SILENT) || defined(RARDLL) - Throw(RARX_FATAL); + Exit(RARX_FATAL); #endif } @@ -136,21 +125,26 @@ va_list arglist; va_start(arglist,fmt); wchar Msg[1024]; +#ifdef _ANDROID + // vswprintf does not work in Android NDK. Conversion below should be ok + // as long as we do not pass Unicode strings in arguments. + char fmtA[NM],MsgA[ASIZE(Msg)]; + WideToChar(fmt,fmtA,ASIZE(fmtA)); + vsnprintf(MsgA,ASIZE(MsgA),fmtA,arglist); + CharToWide(MsgA,Msg,ASIZE(Msg)); +#else vswprintf(Msg,ASIZE(Msg),fmt,arglist); -#ifndef SILENT - Log(NULL,L"%ls",Msg); - mprintf(L"\n"); +#endif + uiMsg(UIERROR_GENERALERRMSG,Msg); SysErrMsg(); -#endif va_end(arglist); } void ErrorHandler::MemoryErrorMsg() { -#ifndef SILENT - Log(NULL,St(MErrOutMem)); -#endif + uiMsg(UIERROR_MEMORY); + SetErrorCode(RARX_MEMORY); } @@ -162,11 +156,9 @@ void ErrorHandler::OpenErrorMsg(const wchar *ArcName,const wchar *FileName) { -#ifndef SILENT - if (FileName!=NULL) - Log(ArcName,St(MCannotOpen),FileName); + uiMsg(UIERROR_FILEOPEN,ArcName,FileName); SysErrMsg(); -#endif + SetErrorCode(RARX_OPEN); } @@ -178,40 +170,12 @@ void ErrorHandler::CreateErrorMsg(const wchar *ArcName,const wchar *FileName) { -#ifndef SILENT - Log(ArcName,St(MCannotCreate),FileName); - -#if defined(_WIN_ALL) && defined(MAX_PATH) - CheckLongPathErrMsg(FileName); -#endif - + uiMsg(UIERROR_FILECREATE,ArcName,FileName); SysErrMsg(); -#endif + SetErrorCode(RARX_CREATE); } -// Check the path length and display the error message if it is too long. -void ErrorHandler::CheckLongPathErrMsg(const wchar *FileName) -{ -#if defined(_WIN_ALL) && !defined (SILENT) && defined(MAX_PATH) - if (GetLastError()==ERROR_PATH_NOT_FOUND) - { - size_t NameLength=wcslen(FileName); - if (!IsFullPath(FileName)) - { - wchar CurDir[NM]; - GetCurrentDirectory(ASIZE(CurDir),CurDir); - NameLength+=wcslen(CurDir)+1; - } - if (NameLength>MAX_PATH) - { - Log(NULL,St(MMaxPathLimit),MAX_PATH); - } - } -#endif -} - - void ErrorHandler::ReadErrorMsg(const wchar *FileName) { ReadErrorMsg(NULL,FileName); @@ -220,26 +184,45 @@ void ErrorHandler::ReadErrorMsg(const wchar *ArcName,const wchar *FileName) { -#ifndef SILENT - Log(ArcName,St(MErrRead),FileName); + uiMsg(UIERROR_FILEREAD,ArcName,FileName); SysErrMsg(); -#endif + SetErrorCode(RARX_FATAL); } void ErrorHandler::WriteErrorMsg(const wchar *ArcName,const wchar *FileName) { -#ifndef SILENT - Log(ArcName,St(MErrWrite),FileName); + uiMsg(UIERROR_FILEWRITE,ArcName,FileName); SysErrMsg(); -#endif + SetErrorCode(RARX_WRITE); } +void ErrorHandler::ArcBrokenMsg(const wchar *ArcName) +{ + uiMsg(UIERROR_ARCBROKEN,ArcName); + SetErrorCode(RARX_CRC); +} + + +void ErrorHandler::ChecksumFailedMsg(const wchar *ArcName,const wchar *FileName) +{ + uiMsg(UIERROR_CHECKSUM,ArcName,FileName); + SetErrorCode(RARX_CRC); +} + + +void ErrorHandler::UnknownMethodMsg(const wchar *ArcName,const wchar *FileName) +{ + uiMsg(UIERROR_UNKNOWNMETHOD,ArcName,FileName); + ErrHandler.SetErrorCode(RARX_FATAL); +} + + void ErrorHandler::Exit(RAR_EXIT ExitCode) { #ifndef GUI - Alarm(); + uiAlarm(UIALARM_ERROR); #endif Throw(ExitCode); } @@ -254,6 +237,10 @@ if (ExitCode==RARX_SUCCESS) ExitCode=Code; break; + case RARX_CRC: + if (ExitCode!=RARX_BADPWD) + ExitCode=Code; + break; case RARX_FATAL: if (ExitCode==RARX_SUCCESS || ExitCode==RARX_WARNING) ExitCode=RARX_FATAL; @@ -320,7 +307,6 @@ #ifndef GUI #ifdef _WIN_ALL SetConsoleCtrlHandler(Enable ? ProcessSignal:NULL,TRUE); -// signal(SIGBREAK,Enable ? ProcessSignal:SIG_IGN); #else signal(SIGINT,Enable ? ProcessSignal:SIG_IGN); signal(SIGTERM,Enable ? ProcessSignal:SIG_IGN); @@ -338,7 +324,7 @@ if (Code!=RARX_SUCCESS && Code!=RARX_USERERROR) mprintf(L"\n%s\n",St(MProgAborted)); #endif - ErrHandler.SetErrorCode(Code); + SetErrorCode(Code); throw Code; } @@ -368,7 +354,7 @@ *EndMsg=0; EndMsg++; } - Log(NULL,L"\n%ls",CurMsg); + uiMsg(UIERROR_SYSERRMSG,CurMsg); CurMsg=EndMsg; } } @@ -378,12 +364,18 @@ #if defined(_UNIX) || defined(_EMX) if (errno!=0) { +#ifdef _ANDROID + // Android NDK sets errno to confusing "not a typewriter" ENOTTY code + // after write error reported by write(). + if (errno == ENOTTY) + return; +#endif char *err=strerror(errno); if (err!=NULL) { - wchar MsgW[1024]; - CharToWide(err,MsgW,ASIZE(MsgW)); - Log(NULL,L"\n%s",MsgW); + wchar Msg[1024]; + CharToWide(err,Msg,ASIZE(Msg)); + uiMsg(UIERROR_SYSERRMSG,Msg); } } #endif Modified: trunk/OpenMPT/include/unrar/errhnd.hpp =================================================================== --- trunk/OpenMPT/include/unrar/errhnd.hpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/errhnd.hpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -44,13 +44,15 @@ void OpenErrorMsg(const wchar *ArcName,const wchar *FileName); void CreateErrorMsg(const wchar *FileName); void CreateErrorMsg(const wchar *ArcName,const wchar *FileName); - void CheckLongPathErrMsg(const wchar *FileName); void ReadErrorMsg(const wchar *FileName); void ReadErrorMsg(const wchar *ArcName,const wchar *FileName); void WriteErrorMsg(const wchar *ArcName,const wchar *FileName); + void ArcBrokenMsg(const wchar *ArcName); + void ChecksumFailedMsg(const wchar *ArcName,const wchar *FileName); + void UnknownMethodMsg(const wchar *ArcName,const wchar *FileName); void Exit(RAR_EXIT ExitCode); void SetErrorCode(RAR_EXIT Code); - RAR_EXIT GetErrorCode() {return(ExitCode);} + RAR_EXIT GetErrorCode() {return ExitCode;} uint GetErrorCount() {return ErrCount;} void SetSignalHandlers(bool Enable); void Throw(RAR_EXIT Code); Modified: trunk/OpenMPT/include/unrar/extract.cpp =================================================================== --- trunk/OpenMPT/include/unrar/extract.cpp 2014-06-19 12:53:01 UTC (rev 4139) +++ trunk/OpenMPT/include/unrar/extract.cpp 2014-06-19 16:24:09 UTC (rev 4140) @@ -2,6 +2,8 @@ CmdExtract::CmdExtract(CommandData *Cmd) { + CmdExtract::Cmd=Cmd; + *ArcName=0; *DestFileName=0; @@ -21,7 +23,7 @@ } -void CmdExtract::DoExtract(CommandData *Cmd) +void CmdExtract::DoExtract() { PasswordCancelled=false; DataIO.SetCurrentCommand(Cmd->Command[0]); @@ -39,7 +41,7 @@ SecPassword PrevCmdPassword; PrevCmdPassword=Cmd->Password; - EXTRACT_ARC_CODE Code=ExtractArchive(Cmd); + EXTRACT_ARC_CODE Code=ExtractArchive(); // Restore Cmd->Password, which could be changed in IsArchive() call // for next header encrypted archive. @@ -56,9 +58,7 @@ ErrHandler.GetErrorCode()!=RARX_BADPWD) // Not in case of wrong archive password. { if (!PasswordCancelled) - { - mprintf(St(MExtrNoFiles)); - } + uiMsg(UIERROR_NOFILESTOEXTRACT,ArcName); ErrHandler.SetErrorCode(RARX_NOFILES); } #ifndef GUI @@ -75,7 +75,7 @@ } -void CmdExtract::ExtractArchiveInit(CommandData *Cmd,Archive &Arc) +void CmdExtract::ExtractArchiveInit(Archive &Arc) { DataIO.UnpArcSize=Arc.FileLength(); @@ -100,14 +100,11 @@ } -EXTRACT_ARC_CODE CmdExtract::ExtractArchive(CommandData *Cmd) +EXTRACT_ARC_CODE CmdExtract::ExtractArchive() { Archive Arc(Cmd); if (!Arc.WOpen(ArcName)) - { - ErrHandler.SetErrorCode(RARX_OPEN); return EXTRACT_ARC_NEXT; - } if (!Arc.IsArchive(true)) { @@ -126,7 +123,7 @@ if (Arc.Volume && !Arc.FirstVolume) { wchar FirstVolName[NM]; - VolNameToFirstName(ArcName,FirstVolName,Arc.NewNumbering); + VolNameToFirstName(ArcName,FirstVolName,ASIZE(FirstVolName),Arc.NewNumbering); // If several volume names from same volume set are specified // and current volume is not first in set and first volume is present @@ -162,21 +159,20 @@ DataIO.TotalArcSize+=VolumeSetSize; } - ExtractArchiveInit(Cmd,Arc); + ExtractArchiveInit(Arc); if (*Cmd->Command=='T' || *Cmd->Command=='I') Cmd->Test=true; -#ifndef GUI if (*Cmd->Command=='I') + { +#ifndef GUI Cmd->DisablePercentage=true; +#endif + } else - if (Cmd->Test) - mprintf(St(MExtrTest),ArcName); - else - mprintf(St(MExtracting),ArcName); -#endif + uiStartArchiveExtract(!Cmd->Test,ArcName); Arc.ViewComment(); @@ -187,7 +183,7 @@ bool Repeat=false; - if (!ExtractCurrentFile(Cmd,Arc,Size,Repeat)) + if (!ExtractCurrentFile(Arc,Size,Repeat)) if (Repeat) { // If we started extraction from not first volume and need to @@ -210,7 +206,7 @@ } -bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderSize,bool &Repeat) +bool CmdExtract::ExtractCurrentFile(Archive &Arc,size_t HeaderSize,bool &Repeat) { wchar Command=Cmd->Command[0]; if (HeaderSize==0) @@ -287,7 +283,7 @@ { wchar CurVolName[NM]; wcsncpyz(CurVolName,ArcName,ASIZE(CurVolName)); - VolNameToFirstName(ArcName,ArcName,Arc.NewNumbering); + VolNameToFirstName(ArcName,ArcName,ASIZE(ArcName),Arc.NewNumbering); if (wcsicomp(ArcName,CurVolName)!=0 && FileExist(ArcName)) { @@ -300,7 +296,6 @@ if (!ReconstructDone) { ReconstructDone=true; - if (RecVolumesRestore(Cmd,Arc.FileName,true)) { Repeat=true; @@ -345,7 +340,7 @@ { if (ExactMatch) { - Log(Arc.FileName,St(MUnpCannotMerge),ArcFileName); + uiMsg(UIERROR_NEEDPREVVOL,Arc.FileName,ArcFileName); #ifdef RARDLL Cmd->DllError=ERAR_BAD_DATA; #endif @@ -359,8 +354,13 @@ if (ExactMatch || (SkipSolid=Arc.Solid)!=0) { + // First common call of uiStartFileExtract. It is done before overwrite + // prompts, so if SkipSolid state is changed below, we'll need to make + // additional uiStartFileExtract calls with updated parameters. + if (!uiStartFileExtract(ArcFileName,!Cmd->Test,Cmd->Test && Command!='I',SkipSolid)) + return false; - ExtrPrepareName(Cmd,Arc,ArcFileName,DestFileName,ASIZE(DestFileName)); + ExtrPrepareName(Arc,ArcFileName,DestFileName,ASIZE(DestFileName)); // DestFileName can be set empty in case of excessive -ap switch. ExtrFile=!SkipSolid && *DestFileName!=0 && !Arc.FileHead.SplitBefore; @@ -392,10 +392,10 @@ if (Arc.FileHead.Encrypted) { #ifdef RARDLL - if (!ExtrDllGetPassword(Cmd)) + if (!ExtrDllGetPassword()) return false; #else - if (!ExtrGetPassword(Cmd,Arc,ArcFileName)) + if (!ExtrGetPassword(Arc,ArcFileName)) { PasswordCancelled=true; return false; @@ -426,12 +426,13 @@ if (!CheckUnpVer(Arc,ArcFileName)) { ExtrFile=false; - ErrHandler.SetErrorCode(RARX_WARNING); + ErrHandler.SetErrorCode(RARX_FATAL); #ifdef RARDLL Cmd->DllError=ERAR_UNKNOWN_FORMAT; #endif } + File CurFile; bool LinkEntry=Arc.FileHead.RedirType!=FSREDIR_NONE; @@ -442,7 +443,7 @@ // Overwrite prompt for symbolic and hard links. bool UserReject=false; if (FileExist(DestFileName) && !UserReject) - FileCreate(Cmd,NULL,DestFileName,ASIZE(DestFileName),Cmd->Overwrite,&UserReject,Arc.FileHead.UnpSize,&Arc.FileHead.mtime); + FileCreate(Cmd,NULL,DestFileName,ASIZE(DestFileName),&UserReject,Arc.FileHead.UnpSize,&Arc.FileHead.mtime); if (UserReject) ExtrFile=false; } @@ -453,18 +454,25 @@ if (!ExtrFile || Command=='P' || Command=='I' || Command=='E' || Cmd->ExclPath==EXCL_SKIPWHOLEPATH) return true; TotalFileCount++; - ExtrCreateDir(Cmd,Arc,ArcFileName); + ExtrCreateDir(Arc,ArcFileName); return true; } else if (ExtrFile) // Create files and file copies (FSREDIR_FILECOPY). - ExtrFile=ExtrCreateFile(Cmd,Arc,CurFile); + ExtrFile=ExtrCreateFile(Arc,CurFile); if (!ExtrFile && Arc.Solid) { SkipSolid=true; ExtrFile=true; + // We changed SkipSolid, so we need to call uiStartFileExtract + // with "Skip" parameter to change the operation status + // from "extracting" to "skipping". For example, it can be necessary + // if user answered "No" to overwrite prompt when unpacking + // a solid archive. + if (!uiStartFileExtract(ArcFileName,false,false,true)) + return false; } if (ExtrFile) { @@ -474,7 +482,7 @@ { if (!TestMode && Command!='P' && CurFile.IsDevice()) { - Log(Arc.FileName,St(MInvalidName),DestFileName); + uiMsg(UIERROR_INVALIDNAME,Arc.FileName,DestFileName); ErrHandler.WriteError(Arc.FileName,DestFileName); } TotalFileCount++; @@ -522,7 +530,7 @@ memcmp(Arc.FileHead.PswCheck,PswCheck,SIZE_PSWCHECK)!... [truncated message content] |