2009-11-10 16:48:42 +01:00
|
|
|
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#if !defined(SFX_MODULE) && defined(_WIN_ALL)
|
|
|
|
void ExtractStreams20(Archive &Arc,const wchar *FileName)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
if (Arc.BrokenHeader)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
|
|
|
|
ErrHandler.SetErrorCode(RARX_CRC);
|
2009-11-10 16:48:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
if (Arc.StreamHead.Method<0x31 || Arc.StreamHead.Method>0x35 || Arc.StreamHead.UnpVer>VER_PACK)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
uiMsg(UIERROR_STREAMUNKNOWN,Arc.FileName,FileName);
|
|
|
|
ErrHandler.SetErrorCode(RARX_WARNING);
|
2009-11-10 16:48:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
wchar StreamName[NM+2];
|
2009-11-10 16:48:42 +01:00
|
|
|
if (FileName[0]!=0 && FileName[1]==0)
|
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
// Convert single character names like f:stream to .\f:stream to
|
|
|
|
// resolve the ambiguity with drive letters.
|
|
|
|
wcsncpyz(StreamName,L".\\",ASIZE(StreamName));
|
|
|
|
wcsncatz(StreamName,FileName,ASIZE(StreamName));
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
else
|
2020-07-15 00:40:26 +02:00
|
|
|
wcsncpyz(StreamName,FileName,ASIZE(StreamName));
|
|
|
|
if (wcslen(StreamName)+strlen(Arc.StreamHead.StreamName)>=ASIZE(StreamName) ||
|
2009-11-10 16:48:42 +01:00
|
|
|
Arc.StreamHead.StreamName[0]!=':')
|
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
|
|
|
|
ErrHandler.SetErrorCode(RARX_CRC);
|
2009-11-10 16:48:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
wchar StoredName[NM];
|
|
|
|
CharToWide(Arc.StreamHead.StreamName,StoredName,ASIZE(StoredName));
|
|
|
|
ConvertPath(StoredName+1,StoredName+1,ASIZE(StoredName)-1);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
wcsncatz(StreamName,StoredName,ASIZE(StreamName));
|
2009-11-10 16:48:42 +01:00
|
|
|
|
|
|
|
FindData fd;
|
2020-07-15 00:40:26 +02:00
|
|
|
bool Found=FindFile::FastFind(FileName,&fd);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
|
|
|
|
SetFileAttr(FileName,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
|
|
|
File CurFile;
|
|
|
|
if (CurFile.WCreate(StreamName))
|
|
|
|
{
|
|
|
|
ComprDataIO DataIO;
|
|
|
|
Unpack Unpack(&DataIO);
|
2020-07-15 00:40:26 +02:00
|
|
|
Unpack.Init(0x10000,false);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
|
|
|
DataIO.SetPackedSizeToRead(Arc.StreamHead.DataSize);
|
|
|
|
DataIO.EnableShowProgress(false);
|
|
|
|
DataIO.SetFiles(&Arc,&CurFile);
|
2020-07-15 00:40:26 +02:00
|
|
|
DataIO.UnpHash.Init(HASH_CRC32,1);
|
2009-11-10 16:48:42 +01:00
|
|
|
Unpack.SetDestSize(Arc.StreamHead.UnpSize);
|
|
|
|
Unpack.DoUnpack(Arc.StreamHead.UnpVer,false);
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
if (Arc.StreamHead.StreamCRC!=DataIO.UnpHash.GetCRC32())
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,StreamName);
|
|
|
|
ErrHandler.SetErrorCode(RARX_CRC);
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
CurFile.Close();
|
|
|
|
}
|
|
|
|
File HostFile;
|
2020-07-15 00:40:26 +02:00
|
|
|
if (Found && HostFile.Open(FileName,FMF_OPENSHARED|FMF_UPDATE))
|
2009-11-10 16:48:42 +01:00
|
|
|
SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
|
|
|
|
&fd.ftLastWriteTime);
|
2020-07-15 00:40:26 +02:00
|
|
|
if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
|
|
|
|
SetFileAttr(FileName,fd.FileAttr);
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#ifdef _WIN_ALL
|
|
|
|
void ExtractStreams(Archive &Arc,const wchar *FileName,bool TestMode)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
wchar FullName[NM+2];
|
|
|
|
if (FileName[0]!=0 && FileName[1]==0)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
// Convert single character names like f:stream to .\f:stream to
|
|
|
|
// resolve the ambiguity with drive letters.
|
|
|
|
wcsncpyz(FullName,L".\\",ASIZE(FullName));
|
|
|
|
wcsncatz(FullName,FileName,ASIZE(FullName));
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
else
|
2020-07-15 00:40:26 +02:00
|
|
|
wcsncpyz(FullName,FileName,ASIZE(FullName));
|
2009-11-10 16:48:42 +01:00
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
wchar StreamName[NM];
|
|
|
|
GetStreamNameNTFS(Arc,StreamName,ASIZE(StreamName));
|
|
|
|
if (*StreamName!=':')
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
uiMsg(UIERROR_STREAMBROKEN,Arc.FileName,FileName);
|
|
|
|
ErrHandler.SetErrorCode(RARX_CRC);
|
2009-11-10 16:48:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
if (TestMode)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
File CurFile;
|
|
|
|
Arc.ReadSubData(NULL,&CurFile,true);
|
2009-11-10 16:48:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
wcsncatz(FullName,StreamName,ASIZE(FullName));
|
2009-11-10 16:48:42 +01:00
|
|
|
|
|
|
|
FindData fd;
|
2020-07-15 00:40:26 +02:00
|
|
|
bool Found=FindFile::FastFind(FileName,&fd);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
if ((fd.FileAttr & FILE_ATTRIBUTE_READONLY)!=0)
|
|
|
|
SetFileAttr(FileName,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
|
2009-11-10 16:48:42 +01:00
|
|
|
File CurFile;
|
2020-07-15 00:40:26 +02:00
|
|
|
if (CurFile.WCreate(FullName) && Arc.ReadSubData(NULL,&CurFile,false))
|
2009-11-10 16:48:42 +01:00
|
|
|
CurFile.Close();
|
|
|
|
File HostFile;
|
2020-07-15 00:40:26 +02:00
|
|
|
if (Found && HostFile.Open(FileName,FMF_OPENSHARED|FMF_UPDATE))
|
2009-11-10 16:48:42 +01:00
|
|
|
SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
|
|
|
|
&fd.ftLastWriteTime);
|
|
|
|
|
|
|
|
// Restoring original file attributes. Important if file was read only
|
|
|
|
// or did not have "Archive" attribute
|
2020-07-15 00:40:26 +02:00
|
|
|
SetFileAttr(FileName,fd.FileAttr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void GetStreamNameNTFS(Archive &Arc,wchar *StreamName,size_t MaxSize)
|
|
|
|
{
|
|
|
|
byte *Data=&Arc.SubHead.SubData[0];
|
|
|
|
size_t DataSize=Arc.SubHead.SubData.Size();
|
|
|
|
if (Arc.Format==RARFMT15)
|
|
|
|
{
|
|
|
|
size_t DestSize=Min(DataSize/2,MaxSize-1);
|
|
|
|
RawToWide(Data,StreamName,DestSize);
|
|
|
|
StreamName[DestSize]=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char UtfString[NM*4];
|
|
|
|
size_t DestSize=Min(DataSize,ASIZE(UtfString)-1);
|
|
|
|
memcpy(UtfString,Data,DestSize);
|
|
|
|
UtfString[DestSize]=0;
|
|
|
|
UtfToWide(UtfString,StreamName,MaxSize);
|
|
|
|
}
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|