Skip to content

Commit

Permalink
Merge branch 'unrar_temp', with changes in unrar 4.0.3 and 4.0.4.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pecl/rar/trunk@307448 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
cataphract committed Jan 13, 2011
2 parents bf0df5d + 14afaf3 commit 9cdbc65
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 29 deletions.
8 changes: 5 additions & 3 deletions unrar/cmddata.cpp
Expand Up @@ -62,6 +62,9 @@ void CommandData::ParseArg(char *Arg,wchar *ArgW)

#ifndef GUI
*Command=etoupper(*Command);
// 'I' and 'S' commands can contain case sensitive strings after
// the first character, so we must not modify their case.
// 'S' can contain SFX name, which case is important in Unix.
if (*Command!='I' && *Command!='S')
strupper(Command);
#endif
Expand Down Expand Up @@ -166,7 +169,6 @@ void CommandData::ParseEnvVar()

// Return 'false' if -cfg- is present and preprocess switches
// which must be processed before the rest of command line.

#ifndef SFX_MODULE
bool CommandData::IsConfigEnabled(int argc,char *argv[])
{
Expand All @@ -181,8 +183,8 @@ bool CommandData::IsConfigEnabled(int argc,char *argv[])
#ifndef GUI
if (strnicomp(&argv[I][1],"ilog",4)==0)
{
// ensure that correct log file name is already set
// if we need to report an error when processing the command line
// Ensure that correct log file name is already set
// if we need to report an error when processing the command line.
ProcessSwitch(&argv[I][1]);
InitLogOptions(LogName);
}
Expand Down
21 changes: 17 additions & 4 deletions unrar/errhnd.cpp
Expand Up @@ -177,7 +177,20 @@ void ErrorHandler::CreateErrorMsg(const char *ArcName,const wchar *ArcNameW,cons
if (FileName!=NULL)
Log(ArcName,St(MCannotCreate),FileName);
Alarm();
#if defined(_WIN_ALL) && !defined(_WIN_CE) && !defined(SFX_MODULE) && defined(MAX_PATH)

#if defined(_WIN_ALL) && !defined(_WIN_CE) && defined(MAX_PATH)
CheckLongPathErrMsg(FileName,FileNameW);
#endif

SysErrMsg();
#endif
}


// Check the path length and display the error message if it is too long.
void ErrorHandler::CheckLongPathErrMsg(const char *FileName,const wchar *FileNameW)
{
#if defined(_WIN_ALL) && !defined(_WIN_CE) && !defined (SILENT) && defined(MAX_PATH)
if (GetLastError()==ERROR_PATH_NOT_FOUND)
{
wchar WideFileName[NM];
Expand All @@ -191,11 +204,9 @@ void ErrorHandler::CreateErrorMsg(const char *ArcName,const wchar *ArcNameW,cons
}
if (NameLength>MAX_PATH)
{
Log(ArcName,St(MMaxPathLimit),MAX_PATH);
Log(NULL,St(MMaxPathLimit),MAX_PATH);
}
}
#endif
SysErrMsg();
#endif
}

Expand Down Expand Up @@ -281,6 +292,8 @@ void _stdfunction ProcessSignal(int SigType)
#endif
{
#ifdef _WIN_ALL
// When a console application is run as a service, this allows the service
// to continue running after the user logs off.
if (SigType==CTRL_LOGOFF_EVENT)
return(TRUE);
#endif
Expand Down
1 change: 1 addition & 0 deletions unrar/errhnd.hpp
Expand Up @@ -40,6 +40,7 @@ class ErrorHandler
void OpenErrorMsg(const char *ArcName,const wchar *ArcNameW,const char *FileName,const wchar *FileNameW);
void CreateErrorMsg(const char *FileName,const wchar *FileNameW=NULL);
void CreateErrorMsg(const char *ArcName,const wchar *ArcNameW,const char *FileName,const wchar *FileNameW);
void CheckLongPathErrMsg(const char *FileName,const wchar *FileNameW);
void ReadErrorMsg(const char *ArcName,const wchar *ArcNameW,const char *FileName,const wchar *FileNameW);
void WriteErrorMsg(const char *ArcName,const wchar *ArcNameW,const char *FileName,const wchar *FileNameW);
void Exit(int ExitCode);
Expand Down
23 changes: 19 additions & 4 deletions unrar/extract.cpp
Expand Up @@ -358,7 +358,7 @@ bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderS
Arc.ConvertAttributes();

#ifndef SFX_MODULE
if ((Arc.NewLhd.Flags & LHD_SPLIT_BEFORE) && FirstFile)
if ((Arc.NewLhd.Flags & LHD_SPLIT_BEFORE)!=0 && FirstFile)
{
char CurVolName[NM];
strcpy(CurVolName,ArcName);
Expand Down Expand Up @@ -504,7 +504,11 @@ bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderS
}
#endif

// Use -ep3 only in systems, where disk letters are exist, not in Unix.
bool AbsPaths=Cmd->ExclPath==EXCL_ABSPATH && Command=='X' && IsDriveDiv(':');

// We do not use any user specified destination paths when extracting
// absolute paths in -ep3 mode.
if (AbsPaths)
*DestFileName=0;

Expand All @@ -515,9 +519,19 @@ bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderS

char DiskLetter=etoupper(DestFileName[0]);

if (AbsPaths && DestFileName[1]=='_' && IsPathDiv(DestFileName[2]) &&
DiskLetter>='A' && DiskLetter<='Z')
DestFileName[1]=':';
if (AbsPaths)
{
if (DestFileName[1]=='_' && IsPathDiv(DestFileName[2]) &&
DiskLetter>='A' && DiskLetter<='Z')
DestFileName[1]=':';
else
if (DestFileName[0]=='_' && DestFileName[1]=='_')
{
// Convert __server\share to \\server\share.
DestFileName[0]=CPATHDIVIDER;
DestFileName[1]=CPATHDIVIDER;
}
}

#ifndef SFX_MODULE
if (!WideName && *Cmd->ExtrPathW!=0)
Expand Down Expand Up @@ -701,6 +715,7 @@ bool CmdExtract::ExtractCurrentFile(CommandData *Cmd,Archive &Arc,size_t HeaderS
else
{
Log(Arc.FileName,St(MExtrErrMkDir),DestFileName);
ErrHandler.CheckLongPathErrMsg(DestFileName,DestNameW);
ErrHandler.SysErrMsg();
#ifdef RARDLL
Cmd->DllError=ERAR_ECREATE;
Expand Down
4 changes: 2 additions & 2 deletions unrar/list.cpp
Expand Up @@ -257,12 +257,12 @@ void ListFileHeader(FileHeader &hd,bool Verbose,bool Technical,bool &TitleShown,
mprintf(" %d.%d",hd.UnpVer/10,hd.UnpVer%10);

static const char *RarOS[]={
"DOS","OS/2","Win95/NT","Unix","MacOS","BeOS","WinCE","","",""
"DOS","OS/2","Windows","Unix","Mac OS","BeOS","WinCE","","",""
};

if (Technical)
mprintf("\n%22s %8s %4s",
(hd.HostOS<sizeof(RarOS)/sizeof(RarOS[0]) ? RarOS[hd.HostOS]:""),
(hd.HostOS<ASIZE(RarOS) ? RarOS[hd.HostOS]:""),
(hd.Flags & LHD_SOLID) ? St(MYes):St(MNo),
(hd.Flags & LHD_VERSION) ? St(MYes):St(MNo));
}
Expand Down
2 changes: 1 addition & 1 deletion unrar/loclang.hpp
Expand Up @@ -298,7 +298,7 @@
#define MErrCreateLnk "\nWARNING: Cannot create link %s"
#define MSymLinkExists "\nWARNING: Symbolic link %s already exists"
#define MAskRetryCreate "\nCannot create %s. Retry ?"
#define MListMACHead1 "\n MacOS file type: %c%c%c%c ; "
#define MListMACHead1 "\n Mac OS file type: %c%c%c%c ; "
#define MListMACHead2 "file creator: %c%c%c%c\n"
#define MDataBadCRC "\n%-20s : packed data CRC failed in volume %s"
#define MFileRO "\n%s is read-only"
Expand Down
2 changes: 2 additions & 0 deletions unrar/options.cpp
Expand Up @@ -8,6 +8,8 @@ RAROptions::RAROptions()

RAROptions::~RAROptions()
{
// It is important for security reasons, so we do not have the unnecessary
// password data left in memory.
memset(this,0,sizeof(RAROptions));
}

Expand Down
11 changes: 9 additions & 2 deletions unrar/options.hpp
Expand Up @@ -6,8 +6,15 @@
#define DEFAULT_RECVOLUMES -10

enum PATH_EXCL_MODE {
EXCL_UNCHANGED,EXCL_BASEPATH,EXCL_SKIPWHOLEPATH,EXCL_SAVEFULLPATH,
EXCL_SKIPABSPATH,EXCL_ABSPATH
EXCL_UNCHANGED, // Process paths as is (default).
EXCL_SKIPWHOLEPATH, // -ep (exclude the path completely)
EXCL_BASEPATH, // -ep1 (exclude the base part of path)
EXCL_SAVEFULLPATH, // -ep2 (the full path without the disk letter)
EXCL_ABSPATH, // -ep3 (the full path with the disk letter)

EXCL_SKIPABSPATH // Works as EXCL_BASEPATH for fully qualified paths
// and as EXCL_UNCHANGED for relative paths.
// Used by WinRAR GUI only.
};

enum {SOLID_NONE=0,SOLID_NORMAL=1,SOLID_COUNT=2,SOLID_FILEEXT=4,
Expand Down
19 changes: 16 additions & 3 deletions unrar/pathfn.cpp
Expand Up @@ -46,7 +46,7 @@ char* ConvertPath(const char *SrcPath,char *DestPath)
DestPtr=s+4;

// Remove any sequence of . and \ in the beginning of path string.
while (*DestPtr)
while (*DestPtr!=0)
{
const char *s=DestPtr;
if (s[0] && IsDriveDiv(s[1]))
Expand Down Expand Up @@ -88,10 +88,14 @@ char* ConvertPath(const char *SrcPath,char *DestPath)
wchar* ConvertPath(const wchar *SrcPath,wchar *DestPath)
{
const wchar *DestPtr=SrcPath;

// Prevent \..\ in any part of path string.
for (const wchar *s=DestPtr;*s!=0;s++)
if (IsPathDiv(s[0]) && s[1]=='.' && s[2]=='.' && IsPathDiv(s[3]))
DestPtr=s+4;
while (*DestPtr)

// Remove any sequence of . and \ in the beginning of path string.
while (*DestPtr!=0)
{
const wchar *s=DestPtr;
if (s[0] && IsDriveDiv(s[1]))
Expand All @@ -112,10 +116,17 @@ wchar* ConvertPath(const wchar *SrcPath,wchar *DestPath)
break;
DestPtr=s;
}

// Code above does not remove last "..", doing here.
if (DestPtr[0]=='.' && DestPtr[1]=='.' && DestPtr[2]==0)
DestPtr+=2;

if (DestPath!=NULL)
{
// SrcPath and DestPath can point to same memory area,
// so we use the temporary buffer for copying.
wchar TmpStr[NM];
wcsncpy(TmpStr,DestPtr,sizeof(TmpStr)/sizeof(TmpStr[0])-1);
wcsncpyz(TmpStr,DestPtr,ASIZE(TmpStr));
wcscpy(DestPath,TmpStr);
}
return((wchar *)DestPtr);
Expand Down Expand Up @@ -1126,6 +1137,8 @@ wchar* GetWideName(const char *Name,const wchar *NameW,wchar *DestW,size_t DestS
}


// Unlike WideToChar, always returns the zero terminated string,
// even if the destination buffer size is not enough.
char* GetAsciiName(const wchar *NameW,char *Name,size_t DestSize)
{
if (DestSize>0)
Expand Down
20 changes: 17 additions & 3 deletions unrar/recvol.cpp
Expand Up @@ -3,8 +3,6 @@
// Buffer size for all volumes involved.
static const size_t TotalBufferSize=0x4000000;

#define RECVOL_BUFSIZE 0x10000

RecVolumes::RecVolumes()
{
Buf.Alloc(TotalBufferSize);
Expand Down Expand Up @@ -301,7 +299,23 @@ bool RecVolumes::Restore(RAROptions *Cmd,const char *Name,
}
if (!ValidVolume)
{
NewFile->TCreate(ArcName,ArcNameW);
// It is important to return 'false' instead of aborting here,
// so if we are called from extraction, we will be able to continue
// extracting. It may happen if .rar and .rev are on read-only disks
// like CDs.
if (!NewFile->Create(ArcName,ArcNameW))
{
// We need to display the title of operation before the error message,
// to make clear for user that create error is related to recovery
// volumes. This is why we cannot use WCreate call here. Title must be
// before create error, not after that.
#ifndef SILENT
mprintf(St(MReconstructing));
#endif
ErrHandler.CreateErrorMsg(ArcName,ArcNameW);
return false;
}

WriteFlags[CurArcNum]=true;
MissingVolumes++;

Expand Down
8 changes: 4 additions & 4 deletions unrar/strfn.cpp
Expand Up @@ -45,7 +45,7 @@ void IntToExt(const char *Src,char *Dest)
char* strlower(char *Str)
{
#ifdef _WIN_ALL
CharLower((LPTSTR)Str);
CharLowerA((LPSTR)Str);
#else
for (char *ChPtr=Str;*ChPtr;ChPtr++)
*ChPtr=(char)loctolower(*ChPtr);
Expand All @@ -57,7 +57,7 @@ char* strlower(char *Str)
char* strupper(char *Str)
{
#ifdef _WIN_ALL
CharUpper((LPTSTR)Str);
CharUpperA((LPSTR)Str);
#else
for (char *ChPtr=Str;*ChPtr;ChPtr++)
*ChPtr=(char)loctoupper(*ChPtr);
Expand Down Expand Up @@ -112,7 +112,7 @@ unsigned char loctolower(unsigned char ch)
{
#ifdef _WIN_ALL
// Convert to LPARAM first to avoid a warning in 64 bit mode.
return((int)(LPARAM)CharLower((LPTSTR)ch));
return((int)(LPARAM)CharLowerA((LPSTR)ch));
#else
return(tolower(ch));
#endif
Expand All @@ -123,7 +123,7 @@ unsigned char loctoupper(unsigned char ch)
{
#ifdef _WIN_ALL
// Convert to LPARAM first to avoid a warning in 64 bit mode.
return((int)(LPARAM)CharUpper((LPTSTR)ch));
return((int)(LPARAM)CharUpperA((LPSTR)ch));
#else
return(toupper(ch));
#endif
Expand Down
2 changes: 2 additions & 0 deletions unrar/unicode.hpp
Expand Up @@ -29,6 +29,8 @@ int uni_done();
// Borland C++ Builder 5 uses the old style swprintf without the buffer size,
// so we replace it with snwprintf in our custom sprintfw definition.
#define sprintfw snwprintf
#elif defined (__OpenBSD__)
#define sprintfw(s,...) *(s)=0
#else
#define sprintfw swprintf
#endif
Expand Down
6 changes: 3 additions & 3 deletions unrar/version.hpp
@@ -1,7 +1,7 @@
#define RARVER_MAJOR 4
#define RARVER_MINOR 0
#define RARVER_BETA 2
#define RARVER_BETA 4
#define RARVER_PATCH 1
#define RARVER_DAY 9
#define RARVER_MONTH 12
#define RARVER_DAY 13
#define RARVER_MONTH 01
#define RARVER_YEAR 2010

0 comments on commit 9cdbc65

Please sign in to comment.