mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 01:15:00 -06:00
9.04 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
8874e4fbc9
commit
829409452d
@@ -44,12 +44,6 @@ static const wchar_t *kTempFolderPrefix = L"7zE";
|
||||
|
||||
using namespace NUpdateArchive;
|
||||
|
||||
static HRESULT CopyBlock(ISequentialInStream *inStream, ISequentialOutStream *outStream)
|
||||
{
|
||||
CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
|
||||
return copyCoder->Code(inStream, outStream, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
class COutMultiVolStream:
|
||||
public IOutStream,
|
||||
public CMyUnknownImp
|
||||
@@ -111,7 +105,7 @@ HRESULT COutMultiVolStream::Close()
|
||||
|
||||
STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if(processedSize != NULL)
|
||||
if (processedSize != NULL)
|
||||
*processedSize = 0;
|
||||
while(size > 0)
|
||||
{
|
||||
@@ -119,15 +113,15 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
|
||||
{
|
||||
CSubStreamInfo subStream;
|
||||
|
||||
wchar_t temp[32];
|
||||
ConvertUInt64ToString(_streamIndex + 1, temp);
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString(_streamIndex + 1, temp);
|
||||
UString res = temp;
|
||||
while (res.Length() < 3)
|
||||
res = UString(L'0') + res;
|
||||
UString name = Prefix + res;
|
||||
subStream.StreamSpec = new COutFileStream;
|
||||
subStream.Stream = subStream.StreamSpec;
|
||||
if(!subStream.StreamSpec->Create(name, false))
|
||||
if (!subStream.StreamSpec->Create(name, false))
|
||||
return ::GetLastError();
|
||||
{
|
||||
// NSynchronization::CCriticalSectionLock lock(g_TempPathsCS);
|
||||
@@ -173,7 +167,7 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
|
||||
_length = _absPos;
|
||||
if (_offsetPos > subStream.RealSize)
|
||||
subStream.RealSize = _offsetPos;
|
||||
if(processedSize != NULL)
|
||||
if (processedSize != NULL)
|
||||
*processedSize += realProcessed;
|
||||
if (subStream.Pos == volSize)
|
||||
{
|
||||
@@ -189,7 +183,7 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
|
||||
|
||||
STDMETHODIMP COutMultiVolStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
|
||||
{
|
||||
if(seekOrigin >= 3)
|
||||
if (seekOrigin >= 3)
|
||||
return STG_E_INVALIDFUNCTION;
|
||||
switch(seekOrigin)
|
||||
{
|
||||
@@ -261,6 +255,7 @@ bool CUpdateOptions::Init(const CCodecs *codecs, const CIntVector &formatIndices
|
||||
else
|
||||
{
|
||||
MethodMode.FormatIndex = codecs->FindFormatForArchiveName(arcPath);
|
||||
// It works incorrectly for update command if archive has some non-default extension!
|
||||
if (MethodMode.FormatIndex < 0)
|
||||
MethodMode.FormatIndex = codecs->FindFormatForArchiveType(kDefaultArchiveType);
|
||||
}
|
||||
@@ -292,7 +287,7 @@ struct CUpdateProduceCallbackImp: public IUpdateProduceCallback
|
||||
const CObjectVector<CArcItem> *_arcItems;
|
||||
IUpdateCallbackUI *_callback;
|
||||
|
||||
CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a,
|
||||
CUpdateProduceCallbackImp(const CObjectVector<CArcItem> *a,
|
||||
IUpdateCallbackUI *callback): _arcItems(a), _callback(callback) {}
|
||||
virtual HRESULT ShowDeleteFile(int arcIndex);
|
||||
};
|
||||
@@ -323,11 +318,11 @@ static HRESULT Compress(
|
||||
IUpdateCallbackUI *callback)
|
||||
{
|
||||
CMyComPtr<IOutArchive> outArchive;
|
||||
if(archive != NULL)
|
||||
if (archive != NULL)
|
||||
{
|
||||
CMyComPtr<IInArchive> archive2 = archive;
|
||||
HRESULT result = archive2.QueryInterface(IID_IOutArchive, &outArchive);
|
||||
if(result != S_OK)
|
||||
if (result != S_OK)
|
||||
throw kUpdateIsNotSupoorted;
|
||||
}
|
||||
else
|
||||
@@ -397,7 +392,7 @@ static HRESULT Compress(
|
||||
{
|
||||
UString resultPath;
|
||||
int pos;
|
||||
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
|
||||
if (!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
|
||||
throw 1417161;
|
||||
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
|
||||
}
|
||||
@@ -421,8 +416,8 @@ static HRESULT Compress(
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
wchar_t s[32];
|
||||
ConvertUInt64ToString(i, s);
|
||||
wchar_t s[16];
|
||||
ConvertUInt32ToString(i, s);
|
||||
archivePath.TempPostfix = s;
|
||||
}
|
||||
realPath = archivePath.GetTempPath();
|
||||
@@ -499,7 +494,7 @@ static HRESULT Compress(
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
RINOK(CopyBlock(sfxStream, sfxOutStream));
|
||||
RINOK(NCompress::CopyStream(sfxStream, sfxOutStream, NULL));
|
||||
if (outStreamSpec)
|
||||
{
|
||||
RINOK(outStreamSpec->Close());
|
||||
@@ -517,26 +512,22 @@ static HRESULT Compress(
|
||||
}
|
||||
|
||||
HRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,
|
||||
IInArchive *archive,
|
||||
const UString &defaultItemName,
|
||||
const NWindows::NFile::NFind::CFileInfoW &archiveFileInfo,
|
||||
const CArc &arc,
|
||||
CObjectVector<CArcItem> &arcItems)
|
||||
{
|
||||
arcItems.Clear();
|
||||
UInt32 numItems;
|
||||
IInArchive *archive = arc.Archive;
|
||||
RINOK(archive->GetNumberOfItems(&numItems));
|
||||
arcItems.Reserve(numItems);
|
||||
for (UInt32 i = 0; i < numItems; i++)
|
||||
{
|
||||
CArcItem ai;
|
||||
|
||||
RINOK(GetArchiveItemPath(archive, i, ai.Name));
|
||||
// check it: defaultItemName !!!
|
||||
if (ai.Name.IsEmpty())
|
||||
ai.Name = defaultItemName;
|
||||
RINOK(arc.GetItemPath(i, ai.Name));
|
||||
RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));
|
||||
ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);
|
||||
RINOK(GetArchiveItemFileTime(archive, i, archiveFileInfo.MTime, ai.MTime));
|
||||
RINOK(arc.GetItemMTime(i, ai.MTime, ai.MTimeDefined));
|
||||
|
||||
{
|
||||
CPropVariant prop;
|
||||
@@ -586,7 +577,7 @@ static HRESULT UpdateWithItemLists(
|
||||
CUpdateArchiveCommand &command = options.Commands[i];
|
||||
if (options.StdOutMode)
|
||||
{
|
||||
RINOK(callback->StartArchive(0, archive != 0));
|
||||
RINOK(callback->StartArchive(L"stdout", archive != 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -684,12 +675,10 @@ HRESULT UpdateArchive(
|
||||
|
||||
const UString archiveName = options.ArchivePath.GetFinalPath();
|
||||
|
||||
UString defaultItemName;
|
||||
CArchiveLink archiveLink;
|
||||
NFind::CFileInfoW archiveFileInfo;
|
||||
|
||||
CArchiveLink archiveLink;
|
||||
IInArchive *archive = 0;
|
||||
if (NFind::FindFile(archiveName, archiveFileInfo))
|
||||
if (archiveFileInfo.Find(archiveName))
|
||||
{
|
||||
if (archiveFileInfo.IsDir())
|
||||
throw "there is no such archive";
|
||||
@@ -698,7 +687,7 @@ HRESULT UpdateArchive(
|
||||
CIntVector formatIndices;
|
||||
if (options.MethodMode.FormatIndex >= 0)
|
||||
formatIndices.Add(options.MethodMode.FormatIndex);
|
||||
HRESULT result = MyOpenArchive(codecs, formatIndices, archiveName, archiveLink, openCallback);
|
||||
HRESULT result = archiveLink.Open2(codecs, formatIndices, false, NULL, archiveName, openCallback);
|
||||
if (result == E_ABORT)
|
||||
return result;
|
||||
RINOK(callback->OpenResult(archiveName, result));
|
||||
@@ -709,8 +698,10 @@ HRESULT UpdateArchive(
|
||||
errorInfo.Message = L"Updating for multivolume archives is not implemented";
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
archive = archiveLink.GetArchive();
|
||||
defaultItemName = archiveLink.GetDefaultItemName();
|
||||
|
||||
CArc &arc = archiveLink.Arcs.Back();
|
||||
arc.MTimeDefined = !archiveFileInfo.IsDevice;
|
||||
arc.MTime = archiveFileInfo.MTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -777,12 +768,15 @@ HRESULT UpdateArchive(
|
||||
CTempFiles tempFiles;
|
||||
|
||||
bool createTempFile = false;
|
||||
if(!options.StdOutMode && options.UpdateArchiveItself)
|
||||
|
||||
bool thereIsInArchive = archiveLink.IsOpen;
|
||||
|
||||
if (!options.StdOutMode && options.UpdateArchiveItself)
|
||||
{
|
||||
CArchivePath &ap = options.Commands[0].ArchivePath;
|
||||
ap = options.ArchivePath;
|
||||
// if ((archive != 0 && !usesTempDir) || !options.WorkingDir.IsEmpty())
|
||||
if ((archive != 0 || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)
|
||||
if ((thereIsInArchive || !options.WorkingDir.IsEmpty()) && !usesTempDir && options.VolumesSizes.Size() == 0)
|
||||
{
|
||||
createTempFile = true;
|
||||
ap.Temp = true;
|
||||
@@ -807,7 +801,7 @@ HRESULT UpdateArchive(
|
||||
if (i > 0 || !createTempFile)
|
||||
{
|
||||
const UString &path = ap.GetFinalPath();
|
||||
if (NFind::DoesFileExist(path))
|
||||
if (NFind::DoesFileOrDirExist(path))
|
||||
{
|
||||
errorInfo.SystemError = 0;
|
||||
errorInfo.Message = L"File already exists";
|
||||
@@ -818,29 +812,30 @@ HRESULT UpdateArchive(
|
||||
}
|
||||
|
||||
CObjectVector<CArcItem> arcItems;
|
||||
if (archive != NULL)
|
||||
if (thereIsInArchive)
|
||||
{
|
||||
RINOK(EnumerateInArchiveItems(censor,
|
||||
archive, defaultItemName, archiveFileInfo, arcItems));
|
||||
RINOK(EnumerateInArchiveItems(censor, archiveLink.Arcs.Back(), arcItems));
|
||||
}
|
||||
|
||||
RINOK(UpdateWithItemLists(codecs, options, archive, arcItems, dirItems,
|
||||
RINOK(UpdateWithItemLists(codecs, options,
|
||||
thereIsInArchive ? archiveLink.GetArchive() : 0,
|
||||
arcItems, dirItems,
|
||||
tempFiles, errorInfo, callback));
|
||||
|
||||
if (archive != NULL)
|
||||
if (thereIsInArchive)
|
||||
{
|
||||
RINOK(archiveLink.Close());
|
||||
archiveLink.Release();
|
||||
}
|
||||
|
||||
tempFiles.Paths.Clear();
|
||||
if(createTempFile)
|
||||
if (createTempFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
CArchivePath &ap = options.Commands[0].ArchivePath;
|
||||
const UString &tempPath = ap.GetTempPath();
|
||||
if (archive != NULL)
|
||||
if (thereIsInArchive)
|
||||
if (!NDirectory::DeleteFileAlways(archiveName))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
@@ -887,7 +882,7 @@ HRESULT UpdateArchive(
|
||||
{
|
||||
CArchivePath &ap = options.Commands[i].ArchivePath;
|
||||
UString arcPath;
|
||||
if(!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))
|
||||
if (!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
return E_FAIL;
|
||||
|
||||
Reference in New Issue
Block a user