Skip to content

Commit

Permalink
[Var] unrar: Update to v7.0.7.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@20181 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Mar 2, 2024
1 parent 6035ce7 commit 794345b
Show file tree
Hide file tree
Showing 124 changed files with 4,468 additions and 3,114 deletions.
8 changes: 4 additions & 4 deletions include/unrar/OpenMPT.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This folder is based on https://rarlab.com/rar/unrarsrc-6.2.10.tar.gz
This folder is based on https://rarlab.com/rar/unrarsrc-7.0.7.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.
Expand All @@ -10,9 +10,9 @@ Optimizations have been done to elimiate effectively dead code that would
never be used in OpenMPT's context.

The following files have been modified:
arcread.cpp, extract.cpp, filcreat.cpp, file.cpp, filefn.cpp, find.cpp,
match.cpp, os.hpp, pathfn.cpp, rdwrfn.cpp, secpassword.cpp, system.cpp,
volume.cpp, win32acl.cpp, win32lnk.cpp
extract.cpp, filcreat.cpp, file.cpp, filefn.cpp, find.cpp, match.cpp,
os.hpp, pathfn.cpp, rdwrfn.cpp, secpassword.cpp, volume.cpp,
win32acl.cpp, win32lnk.cpp

For building, premake is used to generate Visual Studio project files.
See ../build/premake/ for details.
66 changes: 32 additions & 34 deletions include/unrar/arccmt.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
static bool IsAnsiEscComment(const wchar *Data,size_t Size);

bool Archive::GetComment(Array<wchar> *CmtData)
bool Archive::GetComment(std::wstring &CmtData)
{
if (!MainComment)
return false;
Expand All @@ -11,7 +11,7 @@ bool Archive::GetComment(Array<wchar> *CmtData)
}


bool Archive::DoGetComment(Array<wchar> *CmtData)
bool Archive::DoGetComment(std::wstring &CmtData)
{
#ifndef SFX_MODULE
uint CmtLength;
Expand Down Expand Up @@ -101,67 +101,64 @@ bool Archive::DoGetComment(Array<wchar> *CmtData)
// 4x memory for OEM to UTF-8 output here.
OemToCharBuffA((char *)UnpData,(char *)UnpData,(DWORD)UnpDataSize);
#endif
CmtData->Alloc(UnpDataSize+1);
memset(CmtData->Addr(0),0,CmtData->Size()*sizeof(wchar));
CharToWide((char *)UnpData,CmtData->Addr(0),CmtData->Size());
CmtData->Alloc(wcslen(CmtData->Addr(0)));
// CmtData.resize(UnpDataSize+1);
CharToWide((const char *)UnpData,CmtData);
// CmtData.resize(wcslen(CmtData->data()));
}
}
}
else
{
if (CmtLength==0)
return false;
Array<byte> CmtRaw(CmtLength);
int ReadSize=Read(&CmtRaw[0],CmtLength);
std::vector<byte> CmtRaw(CmtLength);
int ReadSize=Read(CmtRaw.data(),CmtLength);
if (ReadSize>=0 && (uint)ReadSize<CmtLength) // Comment is shorter than declared.
{
CmtLength=ReadSize;
CmtRaw.Alloc(CmtLength);
CmtRaw.resize(CmtLength);
}

if (Format!=RARFMT14 && CommHead.CommCRC!=(~CRC32(0xffffffff,&CmtRaw[0],CmtLength)&0xffff))
{
uiMsg(UIERROR_CMTBROKEN,FileName);
return false;
}
CmtData->Alloc(CmtLength+1);
CmtRaw.Push(0);
// CmtData.resize(CmtLength+1);
CmtRaw.push_back(0);
#ifdef _WIN_ALL
// If we ever decide to extend it to Android, we'll need to alloc
// 4x memory for OEM to UTF-8 output here.
OemToCharA((char *)&CmtRaw[0],(char *)&CmtRaw[0]);
OemToCharA((char *)CmtRaw.data(),(char *)CmtRaw.data());
#endif
CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
CmtData->Alloc(wcslen(CmtData->Addr(0)));
CharToWide((const char *)CmtRaw.data(),CmtData);
// CmtData->resize(wcslen(CmtData->data()));
}
#endif
return CmtData->Size() > 0;
return CmtData.size() > 0;
}


bool Archive::ReadCommentData(Array<wchar> *CmtData)
bool Archive::ReadCommentData(std::wstring &CmtData)
{
Array<byte> CmtRaw;
std::vector<byte> CmtRaw;
if (!ReadSubData(&CmtRaw,NULL,false))
return false;
size_t CmtSize=CmtRaw.Size();
CmtRaw.Push(0);
CmtData->Alloc(CmtSize+1);
size_t CmtSize=CmtRaw.size();
CmtRaw.push_back(0);
// CmtData->resize(CmtSize+1);
if (Format==RARFMT50)
UtfToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
UtfToWide((char *)CmtRaw.data(),CmtData);
else
if ((SubHead.SubFlags & SUBHEAD_FLAGS_CMT_UNICODE)!=0)
{
RawToWide(&CmtRaw[0],CmtData->Addr(0),CmtSize/2);
(*CmtData)[CmtSize/2]=0;

CmtData=RawToWide(CmtRaw);
}
else
{
CharToWide((char *)&CmtRaw[0],CmtData->Addr(0),CmtData->Size());
CharToWide((const char *)CmtRaw.data(),CmtData);
}
CmtData->Alloc(wcslen(CmtData->Addr(0))); // Set buffer size to actual comment length.
// CmtData->resize(wcslen(CmtData->data())); // Set buffer size to actual comment length.
return true;
}

Expand All @@ -170,15 +167,16 @@ void Archive::ViewComment()
{
if (Cmd->DisableComment)
return;
Array<wchar> CmtBuf;
if (GetComment(&CmtBuf)) // In GUI too, so "Test" command detects broken comments.
std::wstring CmtBuf;
if (GetComment(CmtBuf)) // In GUI too, so "Test" command detects broken comments.
{
size_t CmtSize=CmtBuf.Size();
wchar *ChPtr=wcschr(&CmtBuf[0],0x1A);
if (ChPtr!=NULL)
CmtSize=ChPtr-&CmtBuf[0];
mprintf(L"\n");
OutComment(&CmtBuf[0],CmtSize);
size_t CmtSize=CmtBuf.size();
auto EndPos=CmtBuf.find(0x1A);
if (EndPos!=std::wstring::npos)
CmtSize=EndPos;
mprintf(St(MArcComment));
mprintf(L":\n");
OutComment(CmtBuf);
}
}

Expand Down
33 changes: 26 additions & 7 deletions include/unrar/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Archive::Archive(CommandData *InitCmd)
VolWrite=0;
AddingFilesSize=0;
AddingHeadersSize=0;
*FirstVolumeName=0;

Splitting=false;
NewArchive=false;
Expand Down Expand Up @@ -74,15 +73,15 @@ void Archive::CheckArc(bool EnableBroken)


#if !defined(SFX_MODULE)
void Archive::CheckOpen(const wchar *Name)
void Archive::CheckOpen(const std::wstring &Name)
{
TOpen(Name);
CheckArc(false);
}
#endif


bool Archive::WCheckOpen(const wchar *Name)
bool Archive::WCheckOpen(const std::wstring &Name)
{
if (!WOpen(Name))
return false;
Expand Down Expand Up @@ -148,9 +147,9 @@ bool Archive::IsArchive(bool EnableBroken)
}
else
{
Array<char> Buffer(MAXSFXSIZE);
std::vector<char> Buffer(MAXSFXSIZE);
long CurPos=(long)Tell();
int ReadSize=Read(&Buffer[0],Buffer.Size()-16);
int ReadSize=Read(Buffer.data(),Buffer.size()-16);
for (int I=0;I<ReadSize;I++)
if (Buffer[I]==0x52 && (Type=IsSignature((byte *)&Buffer[I],ReadSize-I))!=RARFMT_NONE)
{
Expand Down Expand Up @@ -265,7 +264,7 @@ bool Archive::IsArchive(bool EnableBroken)
Seek(SavePos,SEEK_SET);
}
if (!Volume || FirstVolume)
wcsncpyz(FirstVolumeName,FileName,ASIZE(FirstVolumeName));
FirstVolumeName=FileName;

return true;
}
Expand Down Expand Up @@ -301,7 +300,7 @@ uint Archive::FullHeaderSize(size_t Size)


#ifdef USE_QOPEN
bool Archive::Open(const wchar *Name,uint Mode)
bool Archive::Open(const std::wstring &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'.
Expand Down Expand Up @@ -336,3 +335,23 @@ int64 Archive::Tell()
}
#endif


// Return 0 if dictionary size is invalid. If size is RAR7 only, return
// the adjusted nearest bottom value. Return header flags in Flags.
uint64 Archive::GetWinSize(uint64 Size,uint &Flags)
{
Flags=0;
// Allow 128 KB - 1 TB range.
if (Size<0x20000 || Size>0x10000000000ULL)
return 0;
uint64 Pow2=0x20000; // Power of 2 dictionary size.
for (;2*Pow2<=Size;Pow2*=2)
Flags+=FCI_DICT_BIT0;
if (Size==Pow2)
return Size; // If 'Size' is the power of 2, return it as is.

// Get the number of Pow2/32 to add to Pow2 for nearest value not exceeding 'Size'.
uint64 Fraction=(Size-Pow2)/(Pow2/32);
Flags+=(uint)Fraction*FCI_DICT_FRACT0;
return Pow2+Fraction*(Pow2/32);
}
40 changes: 23 additions & 17 deletions include/unrar/archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Archive:public File
{
private:
void UpdateLatestTime(FileHeader *CurBlock);
void ConvertNameCase(wchar *Name);
void ConvertNameCase(std::wstring &Name);
void ConvertFileHeader(FileHeader *hd);
size_t ReadHeader14();
size_t ReadHeader15();
Expand All @@ -36,9 +36,9 @@ class Archive:public File
void RequestArcPassword(RarCheckPassword *SelPwd);
void UnexpEndArcMsg();
void BrokenHeaderMsg();
void UnkEncVerMsg(const wchar *Name,const wchar *Info);
bool DoGetComment(Array<wchar> *CmtData);
bool ReadCommentData(Array<wchar> *CmtData);
void UnkEncVerMsg(const std::wstring &Name,const std::wstring &Info);
bool DoGetComment(std::wstring &CmtData);
bool ReadCommentData(std::wstring &CmtData);

#if !defined(RAR_NOCRYPT)
CryptData HeadersCrypt;
Expand Down Expand Up @@ -67,9 +67,9 @@ class Archive:public File
size_t SearchRR();
size_t ReadHeader();
void CheckArc(bool EnableBroken);
void CheckOpen(const wchar *Name);
bool WCheckOpen(const wchar *Name);
bool GetComment(Array<wchar> *CmtData);
void CheckOpen(const std::wstring &Name);
bool WCheckOpen(const std::wstring &Name);
bool GetComment(std::wstring &CmtData);
void ViewComment();
void SetLatestTime(RarTime *NewTime);
void SeekToNext();
Expand All @@ -79,23 +79,25 @@ class Archive:public File
void VolSubtractHeaderSize(size_t SubSize);
uint FullHeaderSize(size_t Size);
int64 GetStartPos();
void AddSubData(byte *SrcData,uint64 DataSize,File *SrcFile,
void AddSubData(const byte *SrcData,uint64 DataSize,File *SrcFile,
const wchar *Name,uint Flags);
bool ReadSubData(Array<byte> *UnpData,File *DestFile,bool TestMode);
bool ReadSubData(std::vector<byte> *UnpData,File *DestFile,bool TestMode);
HEADER_TYPE GetHeaderType() {return CurHeaderType;}
CommandData* GetCommandData() {return Cmd;}
void SetSilentOpen(bool Mode) {SilentOpen=Mode;}
#if 0
void GetRecoveryInfo(bool Required,int64 *Size,int *Percent);
#endif
#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();
bool Open(const std::wstring &Name,uint Mode=FMF_READ) override;
int Read(void *Data,size_t Size) override;
void Seek(int64 Offset,int Method) override;
int64 Tell() override;
void QOpenUnload() {QOpen.Unload();}
void SetProhibitQOpen(bool Mode) {ProhibitQOpen=Mode;}
#endif
static uint64 GetWinSize(uint64 Size,uint &Flags);

// Needed to see wstring based Open from File. Otherwise compiler finds
// Open in Archive and doesn't check the base class overloads.
using File::Open;

BaseBlock ShortBlock;
MarkHeader MarkHead;
Expand Down Expand Up @@ -135,12 +137,16 @@ class Archive:public File

uint VolNumber;
int64 VolWrite;

// Total size of files adding to archive. Might also include the size of
// files repacked in solid archive.
uint64 AddingFilesSize;

uint64 AddingHeadersSize;

bool NewArchive;

wchar FirstVolumeName[NM];
std::wstring FirstVolumeName;
};


Expand Down
Loading

0 comments on commit 794345b

Please sign in to comment.