This commit is contained in:
Igor Pavlov
2011-04-11 00:00:00 +00:00
committed by Kornel Lesiński
parent de4f8c22fe
commit 35596517f2
322 changed files with 9989 additions and 7759 deletions

View File

@@ -283,9 +283,9 @@ static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)
{
UStringVector names;
if (!NFind::DoesFileExist(fileName))
if (!NFind::DoesFileExist(us2fs(fileName)))
throw kCannotFindListFile;
if (!ReadNamesFromListFile(fileName, names, codePage))
if (!ReadNamesFromListFile(us2fs(fileName), names, codePage))
throw kIncorrectListFile;
for (int i = 0; i < names.Size(); i++)
AddNameToCensor(wildcardCensor, names[i], include, type);
@@ -420,9 +420,9 @@ static void ConvertToLongName(const UString &prefix, UString &name)
{
if (name.IsEmpty() || DoesNameContainWildCard(name))
return;
NFind::CFileInfoW fi;
if (fi.Find(prefix + name))
name = fi.Name;
NFind::CFileInfo fi;
if (fi.Find(us2fs(prefix + name)))
name = fs2us(fi.Name);
}
static void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)
@@ -463,7 +463,7 @@ static void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &no
for (i = 0; i < node.SubNodes.Size(); i++)
{
NWildcard::CCensorNode &nextNode = node.SubNodes[i];
ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);
ConvertToLongNames(prefix + nextNode.Name + WCHAR_PATH_SEPARATOR, nextNode);
}
}
@@ -647,11 +647,11 @@ static void SetAddCommandOptions(
if (postString.IsEmpty())
NDirectory::MyGetTempPath(options.WorkingDir);
else
options.WorkingDir = postString;
options.WorkingDir = us2fs(postString);
}
options.SfxMode = parser[NKey::kSfx].ThereIs;
if (options.SfxMode)
options.SfxModule = parser[NKey::kSfx].PostStrings[0];
options.SfxModule = us2fs(parser[NKey::kSfx].PostStrings[0]);
if (parser[NKey::kVolume].ThereIs)
{
@@ -670,7 +670,6 @@ static void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &pr
{
if (parser[NKey::kProperty].ThereIs)
{
// options.MethodMode.Properties.Clear();
for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
{
CProperty property;
@@ -774,7 +773,7 @@ void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
{
CDirItems dirItems;
{
UStringVector errorPaths;
FStringVector errorPaths;
CRecordVector<DWORD> errorCodes;
HRESULT res = EnumerateItems(wildcardCensor, dirItems, NULL, errorPaths, errorCodes);
if (res != S_OK || errorPaths.Size() > 0)
@@ -796,9 +795,9 @@ void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
int i;
for (i = 0; i < paths.Size(); i++)
{
UString fullPath;
NFile::NDirectory::MyGetFullPathName(paths[i], fullPath);
fullPaths.Add(fullPath);
FString fullPath;
NFile::NDirectory::MyGetFullPathName(us2fs(paths[i]), fullPath);
fullPaths.Add(fs2us(fullPath));
}
CIntVector indices;
SortFileNames(fullPaths, indices);
@@ -886,6 +885,8 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
if (parser[NKey::kArchiveType].ThereIs)
options.ArcType = parser[NKey::kArchiveType].PostStrings[0];
SetMethodOptions(parser, options.Properties);
if (isExtractOrList)
{
if (!options.WildcardCensor.AllAreRelative())
@@ -924,12 +925,11 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
if (isExtractGroupCommand)
{
SetMethodOptions(parser, options.ExtractProperties);
if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)
throw kSameTerminalError;
if (parser[NKey::kOutputDir].ThereIs)
{
options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];
options.OutputDir = us2fs(parser[NKey::kOutputDir].PostStrings[0]);
NFile::NName::NormalizeDirPathPrefix(options.OutputDir);
}
@@ -946,7 +946,7 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);
SetMethodOptions(parser, updateOptions.MethodMode.Properties);
updateOptions.MethodMode.Properties = options.Properties;
if (parser[NKey::kShareForWrite].ThereIs)
updateOptions.OpenShareForWrite = true;
@@ -988,50 +988,12 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
}
else if (options.Command.CommandType == NCommandType::kBenchmark)
{
options.NumThreads = (UInt32)-1;
options.DictionarySize = (UInt32)-1;
options.NumIterations = 1;
if (curCommandIndex < numNonSwitchStrings)
{
if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))
ThrowUserErrorException();
}
for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
{
UString postString = parser[NKey::kProperty].PostStrings[i];
postString.MakeUpper();
if (postString.Length() < 2)
ThrowUserErrorException();
if (postString[0] == 'D')
{
int pos = 1;
if (postString[pos] == '=')
pos++;
UInt32 logSize;
if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))
ThrowUserErrorException();
if (logSize > 31)
ThrowUserErrorException();
options.DictionarySize = 1 << logSize;
}
else if (postString[0] == 'M' && postString[1] == 'T' )
{
int pos = 2;
if (postString[pos] == '=')
pos++;
if (postString[pos] != 0)
if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))
ThrowUserErrorException();
}
else if (postString[0] == 'M' && postString[1] == '=' )
{
int pos = 2;
if (postString[pos] != 0)
options.Method = postString.Mid(2);
}
else
ThrowUserErrorException();
}
}
else if (options.Command.CommandType == NCommandType::kInfo)
{

View File

@@ -75,11 +75,11 @@ struct CArchiveCommandLineOptions
// Extract
bool CalcCrc;
bool AppendName;
UString OutputDir;
FString OutputDir;
NExtract::NOverwriteMode::EEnum OverwriteMode;
UStringVector ArchivePathsSorted;
UStringVector ArchivePathsFullSorted;
CObjectVector<CProperty> ExtractProperties;
CObjectVector<CProperty> Properties;
CUpdateOptions UpdateOptions;
UString ArcType;
@@ -87,10 +87,6 @@ struct CArchiveCommandLineOptions
// Benchmark
UInt32 NumIterations;
UInt32 NumThreads;
UInt32 DictionarySize;
UString Method;
CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};
};

View File

@@ -3,10 +3,12 @@
#include "StdAfx.h"
#include "Common/ComTry.h"
#include "Common/StringConvert.h"
#include "Common/Wildcard.h"
#include "Windows/FileDir.h"
#include "Windows/FileFind.h"
#include "Windows/FileName.h"
#include "Windows/PropVariant.h"
#include "Windows/PropVariantConversions.h"
@@ -18,16 +20,16 @@
using namespace NWindows;
static const wchar_t *kCantAutoRename = L"ERROR: Can not create file with auto name";
static const wchar_t *kCantRenameFile = L"ERROR: Can not rename existing file ";
static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file ";
static const char *kCantAutoRename = "ERROR: Can not create file with auto name";
static const char *kCantRenameFile = "ERROR: Can not rename existing file ";
static const char *kCantDeleteOutputFile = "ERROR: Can not delete output file ";
void CArchiveExtractCallback::Init(
const NWildcard::CCensorNode *wildcardCensor,
const CArc *arc,
IFolderArchiveExtractCallback *extractCallback2,
bool stdOutMode, bool testMode, bool crcMode,
const UString &directoryPath,
const FString &directoryPath,
const UStringVector &removePathParts,
UInt64 packSize)
{
@@ -107,14 +109,14 @@ STDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const U
COM_TRY_END
}
void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)
void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, FString &fullPath)
{
fullPath = _directoryPath;
for (int i = 0; i < dirPathParts.Size(); i++)
{
if (i > 0)
fullPath += wchar_t(NFile::NName::kDirDelimiter);
fullPath += dirPathParts[i];
fullPath += FCHAR_PATH_SEPARATOR;
fullPath += us2fs(dirPathParts[i]);
NFile::NDirectory::MyCreateDirectory(fullPath);
}
}
@@ -136,12 +138,12 @@ HRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &fil
HRESULT CArchiveExtractCallback::GetUnpackSize()
{
NCOM::CPropVariant prop;
RINOK(_arc->Archive->GetProperty(_index, kpidSize, &prop));
_curSizeDefined = (prop.vt != VT_EMPTY);
if (_curSizeDefined)
_curSize = ConvertPropVariantToUInt64(prop);
return S_OK;
return _arc->GetItemSize(_index, _curSize, _curSizeDefined);
}
HRESULT CArchiveExtractCallback::SendMessageError(const char *message, const FString &path)
{
return _extractCallback2->MessageError(GetUnicodeString(message) + fs2us(path));
}
STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)
@@ -256,7 +258,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
if (!pathParts.IsEmpty())
{
UString fullPathNew;
FString fullPathNew;
CreateComplexDirectory(pathParts, fullPathNew);
if (_fi.IsDir)
NFile::NDirectory::SetDirTime(fullPathNew,
@@ -267,7 +269,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
}
UString fullProcessedPath = _directoryPath + processedPath;
FString fullProcessedPath = _directoryPath + us2fs(processedPath);
if (_fi.IsDir)
{
@@ -279,7 +281,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
if (!_isSplit)
{
NFile::NFind::CFileInfoW fileInfo;
NFile::NFind::CFileInfo fileInfo;
if (fileInfo.Find(fullProcessedPath))
{
switch(_overwriteMode)
@@ -290,7 +292,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
{
Int32 overwiteResult;
RINOK(_extractCallback2->AskOverwrite(
fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,
fs2us(fullProcessedPath), &fileInfo.MTime, &fileInfo.Size, fullPath,
_fi.MTimeDefined ? &_fi.MTime : NULL,
_curSizeDefined ? &_curSize : NULL,
&overwiteResult))
@@ -321,32 +323,28 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
{
if (!AutoRenamePath(fullProcessedPath))
{
UString message = UString(kCantAutoRename) + fullProcessedPath;
RINOK(_extractCallback2->MessageError(message));
RINOK(SendMessageError(kCantAutoRename, fullProcessedPath));
return E_FAIL;
}
}
else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)
{
UString existPath = fullProcessedPath;
FString existPath = fullProcessedPath;
if (!AutoRenamePath(existPath))
{
UString message = kCantAutoRename + fullProcessedPath;
RINOK(_extractCallback2->MessageError(message));
RINOK(SendMessageError(kCantAutoRename, fullProcessedPath));
return E_FAIL;
}
if (!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))
{
UString message = UString(kCantRenameFile) + fullProcessedPath;
RINOK(_extractCallback2->MessageError(message));
RINOK(SendMessageError(kCantRenameFile, fullProcessedPath));
return E_FAIL;
}
}
else
if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
{
UString message = UString(kCantDeleteOutputFile) + fullProcessedPath;
RINOK(_extractCallback2->MessageError(message));
RINOK(SendMessageError(kCantDeleteOutputFile, fullProcessedPath));
return S_OK;
// return E_FAIL;
}
@@ -360,8 +358,7 @@ STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStre
{
// if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)
{
UString message = L"can not open output file " + fullProcessedPath;
RINOK(_extractCallback2->MessageError(message));
RINOK(SendMessageError("can not open output file ", fullProcessedPath));
return S_OK;
}
}
@@ -485,4 +482,3 @@ STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
return _cryptoGetTextPassword->CryptoGetTextPassword(password);
COM_TRY_END
}

View File

@@ -31,11 +31,11 @@ class CArchiveExtractCallback:
CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;
CMyComPtr<ICompressProgressInfo> _compressProgress;
CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
UString _directoryPath;
FString _directoryPath;
NExtract::NPathMode::EEnum _pathMode;
NExtract::NOverwriteMode::EEnum _overwriteMode;
UString _diskFilePath;
FString _diskFilePath;
UString _filePath;
UInt64 _position;
bool _isSplit;
@@ -83,10 +83,12 @@ class CArchiveExtractCallback:
UInt64 _packTotal;
UInt64 _unpTotal;
void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);
void CreateComplexDirectory(const UStringVector &dirPathParts, FString &fullPath);
HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);
HRESULT GetUnpackSize();
HRESULT SendMessageError(const char *message, const FString &path);
public:
CLocalProgress *LocalProgressSpec;
@@ -134,7 +136,7 @@ public:
const CArc *arc,
IFolderArchiveExtractCallback *extractCallback2,
bool stdOutMode, bool testMode, bool crcMode,
const UString &directoryPath,
const FString &directoryPath,
const UStringVector &removePathParts,
UInt64 packSize);

View File

@@ -9,19 +9,19 @@
using namespace NWindows;
static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool keepName)
static FString CreateArchiveName2(const FString &srcName, bool fromPrev, bool keepName)
{
UString resultName = L"Archive";
FString resultName = FTEXT("Archive");
if (fromPrev)
{
UString dirPrefix;
FString dirPrefix;
if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))
{
if (dirPrefix.Length() > 0)
if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)
if (dirPrefix.Back() == FCHAR_PATH_SEPARATOR)
{
dirPrefix.Delete(dirPrefix.Length() - 1);
NFile::NFind::CFileInfoW fileInfo;
dirPrefix.DeleteBack();
NFile::NFind::CFileInfo fileInfo;
if (fileInfo.Find(dirPrefix))
resultName = fileInfo.Name;
}
@@ -29,7 +29,7 @@ static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool ke
}
else
{
NFile::NFind::CFileInfoW fileInfo;
NFile::NFind::CFileInfo fileInfo;
if (!fileInfo.Find(srcName))
// return resultName;
return srcName;
@@ -39,8 +39,8 @@ static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool ke
int dotPos = resultName.ReverseFind('.');
if (dotPos > 0)
{
UString archiveName2 = resultName.Left(dotPos);
if (archiveName2.ReverseFind('.') < 0)
FString archiveName2 = resultName.Left(dotPos);
if (archiveName2.ReverseFind(FTEXT('.')) < 0)
resultName = archiveName2;
}
}
@@ -50,5 +50,5 @@ static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool ke
UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)
{
return GetCorrectFsPath(CreateArchiveName2(srcName, fromPrev, keepName));
return GetCorrectFsPath(fs2us(CreateArchiveName2(us2fs(srcName), fromPrev, keepName)));
}

View File

@@ -2,7 +2,6 @@
#include "StdAfx.h"
#include "Common/StringConvert.h"
#include "Common/ComTry.h"
#include "Windows/PropVariant.h"
@@ -94,7 +93,7 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre
RINOK(Callback->Open_CheckBreak());
}
*inStream = NULL;
UString fullPath = _folderPrefix + name;
FString fullPath = _folderPrefix + us2fs(name);
if (!_fileInfo.Find(fullPath))
return S_FALSE;
if (_fileInfo.IsDir())
@@ -130,4 +129,3 @@ STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)
COM_TRY_END
}
#endif

View File

@@ -77,8 +77,8 @@ public:
}
private:
UString _folderPrefix;
NWindows::NFile::NFind::CFileInfoW _fileInfo;
FString _folderPrefix;
NWindows::NFile::NFind::CFileInfo _fileInfo;
bool _subArchiveMode;
UString _subArchiveName;
public:
@@ -88,7 +88,7 @@ public:
UInt64 TotalSize;
COpenCallbackImp(): Callback(NULL) {}
void Init(const UString &folderPrefix, const UString &fileName)
void Init(const FString &folderPrefix, const FString &fileName)
{
_folderPrefix = folderPrefix;
if (!_fileInfo.Find(_folderPrefix + fileName))

View File

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
#define __7ZIP_BENCH_H
#include "../../Common/CreateCoder.h"
#include "../../UI/Common/Property.h"
struct CBenchInfo
{
@@ -14,7 +15,10 @@ struct CBenchInfo
UInt64 UnpackSize;
UInt64 PackSize;
UInt32 NumIterations;
CBenchInfo(): NumIterations(0) {}
UInt64 GetUsage() const;
UInt64 GetRatingPerUsage(UInt64 rating) const;
};
struct IBenchCallback
@@ -23,20 +27,27 @@ struct IBenchCallback
virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
};
UInt64 GetUsage(const CBenchInfo &benchOnfo);
UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);
UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
UInt64 GetCompressRating(UInt32 dictSize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);
HRESULT LzmaBench(
DECL_EXTERNAL_CODECS_LOC_VARS
UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);
const int kBenchMinDicLogSize = 18;
UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);
bool CrcInternalTest();
HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);
struct IBenchPrintCallback
{
virtual void Print(const char *s) = 0;
virtual void NewLine() = 0;
virtual HRESULT CheckBreak() = 0;
};
HRESULT Bench(
DECL_EXTERNAL_CODECS_LOC_VARS
IBenchPrintCallback *printCallback,
IBenchCallback *benchCallback,
const CObjectVector<CProperty> props,
UInt32 numIterations,
bool multiDict
);
#endif

View File

@@ -7,12 +7,13 @@
#include "Common/Random.h"
#include "Common/StringConvert.h"
#include "Windows/DLL.h"
#include "Windows/Error.h"
#include "Windows/FileDir.h"
#include "Windows/FileMapping.h"
#include "Windows/Process.h"
#include "Windows/Synchronization.h"
#include "../FileManager/ProgramLocation.h"
#include "../FileManager/RegistryUtils.h"
#include "CompressCall.h"
@@ -31,10 +32,13 @@ static LPCWSTR kArcIncludeSwitches = L" -an -ai";
static LPCWSTR kStopSwitchParsing = L" --";
static LPCWSTR kLargePagesDisable = L" -slp-";
extern HWND g_HWND;
UString GetQuotedString(const UString &s)
{
return UString(L'\"') + s + UString(L'\"');
}
static void ErrorMessage(LPCWSTR message)
{
MessageBoxW(g_HWND, message, L"7-Zip", MB_ICONERROR | MB_OK);
@@ -42,7 +46,7 @@ static void ErrorMessage(LPCWSTR message)
static void ErrorMessageHRESULT(HRESULT res, LPCWSTR s = NULL)
{
UString s2 = HResultToMessage(res);
UString s2 = NError::MyFormatMessageW(res);
if (s)
{
s2 += L'\n';
@@ -80,9 +84,7 @@ static void AddLagePagesSwitch(UString &params)
static UString Get7zGuiPath()
{
UString path;
GetProgramFolderPath(path);
return path + L"7zG.exe";
return fs2us(NWindows::NDLL::GetModuleDirPrefix()) + L"7zG.exe";
}
class CRandNameGenerator
@@ -238,9 +240,9 @@ HRESULT TestArchives(const UStringVector &arcPaths)
MY_TRY_FINISH
}
HRESULT Benchmark()
HRESULT Benchmark(bool totalMode)
{
MY_TRY_BEGIN
return MyCreateProcess(Get7zGuiPath(), L'b', 0, false, NULL);
return MyCreateProcess(Get7zGuiPath(), totalMode ? L"b -mm=*" : L"b", 0, false, NULL);
MY_TRY_FINISH
}

View File

@@ -7,9 +7,6 @@
UString GetQuotedString(const UString &s);
extern HWND g_HWND;
UString HResultToMessage(HRESULT errorCode);
HRESULT CompressFiles(
const UString &arcPathPrefix,
const UString &arcName,
@@ -19,6 +16,6 @@ HRESULT CompressFiles(
HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog);
HRESULT TestArchives(const UStringVector &arcPaths);
HRESULT Benchmark();
HRESULT Benchmark(bool totalMode);
#endif

View File

@@ -14,6 +14,8 @@
#include "CompressCall.h"
extern HWND g_HWND;
#define MY_TRY_BEGIN try {
#define MY_TRY_FINISH } \
catch(CSystemException &e) { result = e.ErrorCode; } \
@@ -110,7 +112,7 @@ static HRESULT ExtractGroupCommand(const UStringVector &arcPaths,
CREATE_CODECS
CExtractOptions eo;
eo.OutputDir = outFolder;
eo.OutputDir = us2fs(outFolder);
eo.TestMode = testMode;
CExtractCallbackImp *ecs = new CExtractCallbackImp;
@@ -158,7 +160,7 @@ HRESULT TestArchives(const UStringVector &arcPaths)
return ExtractGroupCommand(arcPaths, true, UString(), true);
}
HRESULT Benchmark()
HRESULT Benchmark(bool totalMode)
{
HRESULT result;
MY_TRY_BEGIN
@@ -168,11 +170,19 @@ HRESULT Benchmark()
CObjectVector<CCodecInfoEx> externalCodecs;
RINOK(LoadExternalCodecs(codecs, externalCodecs));
#endif
CObjectVector<CProperty> props;
if (totalMode)
{
CProperty prop;
prop.Name = L"m";
prop.Value = L"*";
props.Add(prop);
}
result = Benchmark(
#ifdef EXTERNAL_CODECS
codecs, &externalCodecs,
#endif
(UInt32)-1, (UInt32)-1, g_HWND);
props, g_HWND);
MY_TRY_FINISH
return result;
}

View File

@@ -39,14 +39,14 @@ public:
int AddPrefix(int phyParent, int logParent, const UString &prefix);
void DeleteLastPrefix();
void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,
UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
void EnumerateDirectory(int phyParent, int logParent, const FString &phyPrefix,
FStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
void EnumerateDirItems2(
const UString &phyPrefix,
const FString &phyPrefix,
const UString &logPrefix,
const UStringVector &filePaths,
UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
const FStringVector &filePaths,
FStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
void ReserveDown();
};

View File

@@ -2,6 +2,8 @@
#include "StdAfx.h"
#include "Windows/FileName.h"
#include "EnumDirItems.h"
using namespace NWindows;
@@ -9,7 +11,7 @@ using namespace NFile;
using namespace NName;
void AddDirFileInfo(int phyParent, int logParent,
const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)
const NFind::CFileInfo &fi, CObjectVector<CDirItem> &dirItems)
{
CDirItem di;
di.Size = fi.Size;
@@ -19,7 +21,7 @@ void AddDirFileInfo(int phyParent, int logParent,
di.Attrib = fi.Attrib;
di.PhyParent = phyParent;
di.LogParent = logParent;
di.Name = fi.Name;
di.Name = fs2us(fi.Name);
dirItems.Add(di);
}
@@ -79,13 +81,13 @@ void CDirItems::DeleteLastPrefix()
Prefixes.DeleteBack();
}
void CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,
UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
void CDirItems::EnumerateDirectory(int phyParent, int logParent, const FString &phyPrefix,
FStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
{
NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);
NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
for (;;)
{
NFind::CFileInfoW fi;
NFind::CFileInfo fi;
bool found;
if (!enumerator.Next(fi, found))
{
@@ -98,43 +100,43 @@ void CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &
AddDirFileInfo(phyParent, logParent, fi, Items);
if (fi.IsDir())
{
const UString name2 = fi.Name + (wchar_t)kDirDelimiter;
int parent = AddPrefix(phyParent, logParent, name2);
const FString name2 = fi.Name + FCHAR_PATH_SEPARATOR;
int parent = AddPrefix(phyParent, logParent, fs2us(name2));
EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);
}
}
}
void CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,
const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
void CDirItems::EnumerateDirItems2(const FString &phyPrefix, const UString &logPrefix,
const FStringVector &filePaths, FStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
{
int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);
int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, fs2us(phyPrefix));
int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);
for (int i = 0; i < filePaths.Size(); i++)
{
const UString &filePath = filePaths[i];
NFind::CFileInfoW fi;
const UString phyPath = phyPrefix + filePath;
const FString &filePath = filePaths[i];
NFind::CFileInfo fi;
const FString phyPath = phyPrefix + filePath;
if (!fi.Find(phyPath))
{
errorCodes.Add(::GetLastError());
errorPaths.Add(phyPath);
continue;
}
int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);
UString phyPrefixCur;
int delimiter = filePath.ReverseFind(FCHAR_PATH_SEPARATOR);
FString phyPrefixCur;
int phyParentCur = phyParent;
if (delimiter >= 0)
{
phyPrefixCur = filePath.Left(delimiter + 1);
phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);
phyParentCur = AddPrefix(phyParent, logParent, fs2us(phyPrefixCur));
}
AddDirFileInfo(phyParentCur, logParent, fi, Items);
if (fi.IsDir())
{
const UString name2 = fi.Name + (wchar_t)kDirDelimiter;
int parent = AddPrefix(phyParentCur, logParent, name2);
const FString name2 = fi.Name + FCHAR_PATH_SEPARATOR;
int parent = AddPrefix(phyParentCur, logParent, fs2us(name2));
EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);
}
}
@@ -142,27 +144,27 @@ void CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logP
}
static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
int phyParent, int logParent, const UString &phyPrefix,
int phyParent, int logParent, const FString &phyPrefix,
const UStringVector &addArchivePrefix,
CDirItems &dirItems,
bool enterToSubFolders,
IEnumDirItemCallback *callback,
UStringVector &errorPaths,
FStringVector &errorPaths,
CRecordVector<DWORD> &errorCodes);
static HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,
int phyParent, int logParent, const UString &curFolderName,
const UString &phyPrefix,
int phyParent, int logParent, const FString &curFolderName,
const FString &phyPrefix,
const UStringVector &addArchivePrefix,
CDirItems &dirItems,
bool enterToSubFolders,
IEnumDirItemCallback *callback,
UStringVector &errorPaths,
FStringVector &errorPaths,
CRecordVector<DWORD> &errorCodes)
{
const UString name2 = curFolderName + (wchar_t)kDirDelimiter;
int parent = dirItems.AddPrefix(phyParent, logParent, name2);
const FString name2 = curFolderName + FCHAR_PATH_SEPARATOR;
int parent = dirItems.AddPrefix(phyParent, logParent, fs2us(name2));
int numItems = dirItems.Items.Size();
HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,
addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);
@@ -173,19 +175,19 @@ static HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,
static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
int phyParent, int logParent, const UString &phyPrefix,
int phyParent, int logParent, const FString &phyPrefix,
const UStringVector &addArchivePrefix, // prefix from curNode
CDirItems &dirItems,
bool enterToSubFolders,
IEnumDirItemCallback *callback,
UStringVector &errorPaths,
FStringVector &errorPaths,
CRecordVector<DWORD> &errorCodes)
{
if (!enterToSubFolders)
if (curNode.NeedCheckSubDirs())
enterToSubFolders = true;
if (callback)
RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));
RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), fs2us(phyPrefix)));
// try direct_names case at first
if (addArchivePrefix.IsEmpty() && !enterToSubFolders)
@@ -210,8 +212,8 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
{
const NWildcard::CItem &item = curNode.IncludeItems[i];
const UString &name = item.PathParts.Front();
const UString fullPath = phyPrefix + name;
NFind::CFileInfoW fi;
const FString fullPath = phyPrefix + us2fs(name);
NFind::CFileInfo fi;
if (!fi.Find(fullPath))
{
errorCodes.Add(::GetLastError());
@@ -227,7 +229,7 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
}
{
UStringVector pathParts;
pathParts.Add(fi.Name);
pathParts.Add(fs2us(fi.Name));
if (curNode.CheckPathToRoot(false, pathParts, !isDir))
continue;
}
@@ -260,8 +262,8 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
if (!needEnterVector[i])
continue;
const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];
const UString fullPath = phyPrefix + nextNode.Name;
NFind::CFileInfoW fi;
const FString fullPath = phyPrefix + us2fs(nextNode.Name);
NFind::CFileInfo fi;
if (!fi.Find(fullPath))
{
if (!nextNode.AreThereIncludeItems())
@@ -285,10 +287,10 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
}
NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));
NFind::CEnumerator enumerator(phyPrefix + FCHAR_ANY_MASK);
for (int ttt = 0; ; ttt++)
{
NFind::CFileInfoW fi;
NFind::CFileInfo fi;
bool found;
if (!enumerator.Next(fi, found))
{
@@ -300,8 +302,8 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
break;
if (callback && (ttt & 0xFF) == 0xFF)
RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));
const UString &name = fi.Name;
RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), fs2us(phyPrefix)));
const UString &name = fs2us(fi.Name);
bool enterToSubFolders2 = enterToSubFolders;
UStringVector addArchivePrefixNew = addArchivePrefix;
addArchivePrefixNew.Add(name);
@@ -336,7 +338,7 @@ static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
addArchivePrefixNew.Add(name);
}
RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,
RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,
addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));
}
return S_OK;
@@ -346,14 +348,14 @@ HRESULT EnumerateItems(
const NWildcard::CCensor &censor,
CDirItems &dirItems,
IEnumDirItemCallback *callback,
UStringVector &errorPaths,
FStringVector &errorPaths,
CRecordVector<DWORD> &errorCodes)
{
for (int i = 0; i < censor.Pairs.Size(); i++)
{
const NWildcard::CPair &pair = censor.Pairs[i];
int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);
RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,
RINOK(EnumerateDirItems(pair.Head, phyParent, -1, us2fs(pair.Prefix), UStringVector(), dirItems, false,
callback, errorPaths, errorCodes));
}
dirItems.ReserveDown();

View File

@@ -8,7 +8,7 @@
#include "DirItem.h"
void AddDirFileInfo(int phyParent, int logParent,
const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);
const NWindows::NFile::NFind::CFileInfo &fi, CObjectVector<CDirItem> &dirItems);
struct IEnumDirItemCallback
{
@@ -19,7 +19,7 @@ HRESULT EnumerateItems(
const NWildcard::CCensor &censor,
CDirItems &dirItems,
IEnumDirItemCallback *callback,
UStringVector &errorPaths,
FStringVector &errorPaths,
CRecordVector<DWORD> &errorCodes);
#endif

View File

@@ -52,8 +52,8 @@ static HRESULT DecompressArchive(
UStringVector removePathParts;
UString outDir = options.OutputDir;
outDir.Replace(L"*", GetCorrectFsPath(arc.DefaultName));
FString outDir = options.OutputDir;
outDir.Replace(FSTRING_ANY_MASK, us2fs(GetCorrectFsPath(arc.DefaultName)));
#ifdef _WIN32
// GetCorrectFullFsPath doesn't like "..".
// outDir.TrimRight();
@@ -66,7 +66,7 @@ static HRESULT DecompressArchive(
HRESULT res = ::GetLastError();
if (res == S_OK)
res = E_FAIL;
errorMessage = ((UString)L"Can not create output directory ") + outDir;
errorMessage = ((UString)L"Can not create output directory ") + fs2us(outDir);
return res;
}
@@ -118,11 +118,11 @@ HRESULT DecompressArchives(
for (i = 0; i < numArcs; i++)
{
NFile::NFind::CFileInfoW fi;
NFile::NFind::CFileInfo fi;
fi.Size = 0;
if (!options.StdInMode)
{
const UString &arcPath = arcPaths[i];
const FString &arcPath = us2fs(arcPaths[i]);
if (!fi.Find(arcPath))
throw "there is no such archive";
if (fi.IsDir())
@@ -142,7 +142,7 @@ HRESULT DecompressArchives(
for (i = 0; i < numArcs; i++)
{
const UString &arcPath = arcPaths[i];
NFile::NFind::CFileInfoW fi;
NFile::NFind::CFileInfo fi;
if (options.StdInMode)
{
fi.Size = 0;
@@ -150,7 +150,7 @@ HRESULT DecompressArchives(
}
else
{
if (!fi.Find(arcPath) || fi.IsDir())
if (!fi.Find(us2fs(arcPath)) || fi.IsDir())
throw "there is no such archive";
}

View File

@@ -23,7 +23,7 @@ struct CExtractOptions
bool CalcCrc;
NExtract::NPathMode::EEnum PathMode;
NExtract::NOverwriteMode::EEnum OverwriteMode;
UString OutputDir;
FString OutputDir;
// bool ShowDialog;
// bool PasswordEnabled;

View File

@@ -20,8 +20,8 @@ static UString ReplaceIncorrectChars(const UString &s)
res += c;
}
res.TrimRight();
while (!res.IsEmpty() && res[res.Length() - 1] == '.')
res.Delete(res.Length() - 1);
while (!res.IsEmpty() && res.Back() == '.')
res.DeleteBack();
return res;
#else
return s;
@@ -132,8 +132,8 @@ UString GetCorrectFullFsPath(const UString &path)
{
UString &s = parts[i];
#ifdef _WIN32
while (!s.IsEmpty() && s[s.Length() - 1] == '.')
s.Delete(s.Length() - 1);
while (!s.IsEmpty() && s.Back() == '.')
s.DeleteBack();
if (!IsSupportedName(s))
s = (UString)L"_" + s;
#endif

View File

@@ -22,6 +22,7 @@ static const UINT kIconTypesResId = 100;
#endif
#ifdef _WIN32
#include "Windows/FileName.h"
#include "Windows/Registry.h"
#endif
@@ -32,53 +33,52 @@ using namespace NFile;
extern HINSTANCE g_hInstance;
#endif
static CSysString GetLibraryFolderPrefix()
{
#ifdef _WIN32
TCHAR fullPath[MAX_PATH + 1];
::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);
CSysString path = fullPath;
int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
return path.Left(pos + 1);
#else
return CSysString(); // FIX IT
#endif
}
#define kCodecsFolderName TEXT("Codecs")
#define kFormatsFolderName TEXT("Formats")
static const TCHAR *kMainDll = TEXT("7z.dll");
#define kCodecsFolderName FTEXT("Codecs")
#define kFormatsFolderName FTEXT("Formats")
static CFSTR kMainDll = FTEXT("7z.dll");
#ifdef _WIN32
static LPCTSTR kRegistryPath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-zip");
static LPCTSTR kProgramPathValue = TEXT("Path");
static bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)
static LPCWSTR kProgramPathValue = L"Path";
static LPCWSTR kProgramPath2Value = L"Path"
#ifdef _WIN64
L"64";
#else
L"32";
#endif
static bool ReadPathFromRegistry(HKEY baseKey, LPCWSTR value, FString &path)
{
NRegistry::CKey key;
if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)
if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)
if (key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)
{
UString pathU;
if (key.QueryValue(value, pathU) == ERROR_SUCCESS)
{
path = us2fs(pathU);
NName::NormalizeDirPathPrefix(path);
return true;
return NFind::DoesFileExist(path + kMainDll);
}
}
return false;
}
#endif
CSysString GetBaseFolderPrefixFromRegistry()
static FString GetBaseFolderPrefixFromRegistry()
{
CSysString moduleFolderPrefix = GetLibraryFolderPrefix();
FString moduleFolderPrefix = NDLL::GetModuleDirPrefix();
#ifdef _WIN32
if (!NFind::DoesFileExist(moduleFolderPrefix + kMainDll) &&
!NFind::DoesDirExist(moduleFolderPrefix + kCodecsFolderName) &&
!NFind::DoesDirExist(moduleFolderPrefix + kFormatsFolderName))
{
CSysString path;
if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))
return path;
if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))
return path;
FString path;
if (ReadPathFromRegistry(HKEY_CURRENT_USER, kProgramPath2Value, path)) return path;
if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, kProgramPath2Value, path)) return path;
if (ReadPathFromRegistry(HKEY_CURRENT_USER, kProgramPathValue, path)) return path;
if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, kProgramPathValue, path)) return path;
}
#endif
return moduleFolderPrefix;
@@ -210,6 +210,14 @@ static void SplitString(const UString &srcString, UStringVector &destStrings)
destStrings.Add(s);
}
int CArcInfoEx::FindExtension(const UString &ext) const
{
for (int i = 0; i < Exts.Size(); i++)
if (ext.CompareNoCase(Exts[i].Ext) == 0)
return i;
return -1;
}
void CArcInfoEx::AddExts(const wchar_t *ext, const wchar_t *addExt)
{
UStringVector exts, addExts;
@@ -344,7 +352,7 @@ extern "C"
}
#endif
HRESULT CCodecs::LoadDll(const CSysString &dllPath, bool needCheckDll)
HRESULT CCodecs::LoadDll(const FString &dllPath, bool needCheckDll)
{
if (needCheckDll)
{
@@ -393,9 +401,9 @@ HRESULT CCodecs::LoadDll(const CSysString &dllPath, bool needCheckDll)
return res;
}
HRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)
HRESULT CCodecs::LoadDllsFromFolder(const FString &folderPrefix)
{
NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT("*")));
NFile::NFind::CEnumerator enumerator(folderPrefix + FCHAR_ANY_MASK);
NFile::NFind::CFileInfo fi;
while (enumerator.Next(fi))
{
@@ -443,10 +451,10 @@ HRESULT CCodecs::Load()
Formats.Add(item);
}
#ifdef EXTERNAL_CODECS
const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();
const FString baseFolder = GetBaseFolderPrefixFromRegistry();
RINOK(LoadDll(baseFolder + kMainDll, false));
RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));
RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));
RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName FSTRING_PATH_SEPARATOR));
RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName FSTRING_PATH_SEPARATOR));
#endif
return S_OK;
}
@@ -455,12 +463,11 @@ HRESULT CCodecs::Load()
int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
{
int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);
int slashPos2 = arcPath.ReverseFind(L'.');
int slashPos = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);
int dotPos = arcPath.ReverseFind(L'.');
if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)
if (dotPos < 0 || dotPos < slashPos)
return -1;
UString ext = arcPath.Mid(dotPos + 1);
const UString ext = arcPath.Mid(dotPos + 1);
for (int i = 0; i < Formats.Size(); i++)
{
const CArcInfoEx &arc = Formats[i];

View File

@@ -1,9 +1,8 @@
// LoadCodecs.h
#ifndef __LOADCODECS_H
#define __LOADCODECS_H
#ifndef __LOAD_CODECS_H
#define __LOAD_CODECS_H
#include "../../../Common/Types.h"
#include "../../../Common/MyCom.h"
#include "../../../Common/MyString.h"
#include "../../../Common/Buffer.h"
@@ -58,19 +57,16 @@ struct CArcInfoEx
#endif
#endif
bool KeepName;
UString GetMainExt() const
{
if (Exts.IsEmpty())
return UString();
return Exts[0].Ext;
}
int FindExtension(const UString &ext) const
{
for (int i = 0; i < Exts.Size(); i++)
if (ext.CompareNoCase(Exts[i].Ext) == 0)
return i;
return -1;
}
int FindExtension(const UString &ext) const;
/*
UString GetAllExtensions() const
{
UString s;
@@ -82,6 +78,7 @@ struct CArcInfoEx
}
return s;
}
*/
void AddExts(const wchar_t* ext, const wchar_t* addExt);
@@ -125,7 +122,7 @@ struct CCodecLib
GetMethodPropertyFunc GetMethodProperty;
CreateObjectFunc CreateObject;
#ifdef NEW_FOLDER_INTERFACE
CSysString Path;
FString Path;
void LoadIcons() { CCodecIcons::LoadIcons((HMODULE)Lib); }
#endif
CCodecLib(): GetMethodProperty(0) {}
@@ -151,8 +148,8 @@ public:
HRESULT LoadCodecs();
HRESULT LoadFormats();
HRESULT LoadDll(const CSysString &path, bool needCheckDll);
HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);
HRESULT LoadDll(const FString &path, bool needCheckDll);
HRESULT LoadDllsFromFolder(const FString &folderPrefix);
HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const
{

View File

@@ -63,6 +63,25 @@ HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
return S_OK;
}
HRESULT CArc::GetItemSize(UInt32 index, UInt64 &size, bool &defined) const
{
NCOM::CPropVariant prop;
defined = false;
size = 0;
RINOK(Archive->GetProperty(index, kpidSize, &prop));
switch (prop.vt)
{
case VT_UI1: size = prop.bVal; break;
case VT_UI2: size = prop.uiVal; break;
case VT_UI4: size = prop.ulVal; break;
case VT_UI8: size = (UInt64)prop.uhVal.QuadPart; break;
case VT_EMPTY: return S_OK;
default: return E_FAIL;
}
defined = true;
return S_OK;
}
HRESULT CArc::GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const
{
NCOM::CPropVariant prop;
@@ -339,7 +358,7 @@ HRESULT CArc::OpenStreamOrFile(
{
CInFileStream *fileStreamSpec = new CInFileStream;
fileStream = fileStreamSpec;
if (!fileStreamSpec->Open(Path))
if (!fileStreamSpec->Open(us2fs(Path)))
return GetLastError();
stream = fileStream;
}
@@ -461,7 +480,7 @@ HRESULT CArchiveLink::Open(
return S_OK;
}
static void SetCallback(const UString &filePath,
static void SetCallback(const FString &filePath,
IOpenCallbackUI *callbackUI,
IArchiveOpenCallback *reOpenCallback,
CMyComPtr<IArchiveOpenCallback> &callback)
@@ -471,12 +490,9 @@ static void SetCallback(const UString &filePath,
openCallbackSpec->Callback = callbackUI;
openCallbackSpec->ReOpenCallback = reOpenCallback;
UString fullName;
int fileNamePartStartIndex;
NFile::NDirectory::MyGetFullPathName(filePath, fullName, fileNamePartStartIndex);
openCallbackSpec->Init(
fullName.Left(fileNamePartStartIndex),
fullName.Mid(fileNamePartStartIndex));
FString dirPrefix, fileName;
NFile::NDirectory::GetFullPathAndSplit(filePath, dirPrefix, fileName);
openCallbackSpec->Init(dirPrefix, fileName);
}
HRESULT CArchiveLink::Open2(CCodecs *codecs,
@@ -491,14 +507,10 @@ HRESULT CArchiveLink::Open2(CCodecs *codecs,
CMyComPtr<IArchiveOpenCallback> callback = openCallbackSpec;
openCallbackSpec->Callback = callbackUI;
UString fullName, prefix, name;
FString prefix, name;
if (!stream && !stdInMode)
{
int fileNamePartStartIndex;
if (!NFile::NDirectory::MyGetFullPathName(filePath, fullName, fileNamePartStartIndex))
return GetLastError();
prefix = fullName.Left(fileNamePartStartIndex);
name = fullName.Mid(fileNamePartStartIndex);
NFile::NDirectory::GetFullPathAndSplit(us2fs(filePath), prefix, name);
openCallbackSpec->Init(prefix, name);
}
else
@@ -507,9 +519,9 @@ HRESULT CArchiveLink::Open2(CCodecs *codecs,
}
RINOK(Open(codecs, formatIndices, stdInMode, stream, filePath, callback));
VolumePaths.Add(prefix + name);
VolumePaths.Add(fs2us(prefix + name));
for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)
VolumePaths.Add(prefix + openCallbackSpec->FileNames[i]);
VolumePaths.Add(fs2us(prefix) + openCallbackSpec->FileNames[i]);
VolumesSize = openCallbackSpec->TotalSize;
return S_OK;
}
@@ -524,11 +536,11 @@ HRESULT CArchiveLink::ReOpen(CCodecs *codecs, const UString &filePath,
return Open2(codecs, CIntVector(), false, NULL, filePath, 0);
CMyComPtr<IArchiveOpenCallback> openCallbackNew;
SetCallback(filePath, NULL, callback, openCallbackNew);
SetCallback(us2fs(filePath), NULL, callback, openCallbackNew);
CInFileStream *fileStreamSpec = new CInFileStream;
CMyComPtr<IInStream> stream(fileStreamSpec);
if (!fileStreamSpec->Open(filePath))
if (!fileStreamSpec->Open(us2fs(filePath)))
return GetLastError();
HRESULT res = GetArchive()->Open(stream, &kMaxCheckStartPosition, callback);
IsOpen = (res == S_OK);

View File

@@ -29,6 +29,7 @@ struct CArc
CArc(): MTimeDefined(false) {}
HRESULT GetItemPath(UInt32 index, UString &result) const;
HRESULT GetItemSize(UInt32 index, UInt64 &size, bool &defined) const;
HRESULT GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const;
HRESULT IsItemAnti(UInt32 index, bool &result) const
{ return GetArchiveItemBoolProp(Archive, index, kpidIsAnti, result); }

View File

@@ -1,9 +1,9 @@
// Property.h
#ifndef __PROPERTY_H
#define __PROPERTY_H
#ifndef __7Z_PROPERTY_H
#define __7Z_PROPERTY_H
#include "Common/MyString.h"
#include "../../../Common/MyString.h"
struct CProperty
{

View File

@@ -49,13 +49,13 @@ HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &propert
{
if (!name.IsEmpty())
{
wchar_t c = name[name.Length() - 1];
wchar_t c = name.Back();
if (c == L'-')
propVariant = false;
else if (c == L'+')
propVariant = true;
if (propVariant.vt != VT_EMPTY)
name = name.Left(name.Length() - 1);
name.DeleteBack();
}
}
else

View File

@@ -5,16 +5,15 @@
#include "TempFiles.h"
#include "Windows/FileDir.h"
#include "Windows/FileIO.h"
using namespace NWindows;
using namespace NFile;
void CTempFiles::Clear()
{
while(!Paths.IsEmpty())
while (!Paths.IsEmpty())
{
NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());
NDirectory::DeleteFileAlways(Paths.Back());
Paths.DeleteBack();
}
}

View File

@@ -1,7 +1,7 @@
// TempFiles.h
#ifndef __TEMPFILES_H
#define __TEMPFILES_H
#ifndef __TEMP_FILES_H
#define __TEMP_FILES_H
#include "Common/MyString.h"
@@ -9,7 +9,7 @@ class CTempFiles
{
void Clear();
public:
UStringVector Paths;
FStringVector Paths;
~CTempFiles() { Clear(); }
};

View File

@@ -7,10 +7,7 @@
#include "Common/IntToString.h"
#include "Common/StringConvert.h"
#ifdef _WIN32
#include "Windows/DLL.h"
#endif
#include "Windows/FileDir.h"
#include "Windows/FileFind.h"
#include "Windows/FileName.h"
@@ -40,7 +37,7 @@ using namespace NCOM;
using namespace NFile;
using namespace NName;
static const wchar_t *kTempFolderPrefix = L"7zE";
static CFSTR kTempFolderPrefix = FTEXT("7zE");
using namespace NUpdateArchive;
@@ -57,7 +54,7 @@ class COutMultiVolStream:
{
COutFileStream *StreamSpec;
CMyComPtr<IOutStream> Stream;
UString Name;
FString Name;
UInt64 Pos;
UInt64 RealSize;
};
@@ -65,7 +62,7 @@ class COutMultiVolStream:
public:
// CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
CRecordVector<UInt64> Sizes;
UString Prefix;
FString Prefix;
CTempFiles *TempFiles;
void Init()
@@ -107,18 +104,18 @@ STDMETHODIMP COutMultiVolStream::Write(const void *data, UInt32 size, UInt32 *pr
{
if (processedSize != NULL)
*processedSize = 0;
while(size > 0)
while (size > 0)
{
if (_streamIndex >= Streams.Size())
{
CSubStreamInfo subStream;
wchar_t temp[16];
FChar temp[16];
ConvertUInt32ToString(_streamIndex + 1, temp);
UString res = temp;
FString res = temp;
while (res.Length() < 3)
res = UString(L'0') + res;
UString name = Prefix + res;
res = FString(FTEXT('0')) + res;
FString name = Prefix + res;
subStream.StreamSpec = new COutFileStream;
subStream.Stream = subStream.StreamSpec;
if (!subStream.StreamSpec->Create(name, false))
@@ -311,7 +308,7 @@ static HRESULT Compress(
bool stdOutMode,
const CDirItems &dirItems,
bool sfxMode,
const UString &sfxModule,
const FString &sfxModule,
const CRecordVector<UInt64> &volumesSizes,
CTempFiles &tempFiles,
CUpdateErrorInfo &errorInfo,
@@ -389,11 +386,10 @@ static HRESULT Compress(
if (!stdOutMode)
{
UString resultPath;
int pos;
if (!NFile::NDirectory::MyGetFullPathName(archivePath.GetFinalPath(), resultPath, pos))
FString dirPrefix;
if (!NFile::NDirectory::GetOnlyDirPrefix(us2fs(archivePath.GetFinalPath()), dirPrefix))
throw 1417161;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
NFile::NDirectory::CreateComplexDirectory(dirPrefix);
}
COutFileStream *outStreamSpec = NULL;
@@ -408,21 +404,21 @@ static HRESULT Compress(
outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
bool isOK = false;
UString realPath;
FString realPath;
for (int i = 0; i < (1 << 16); i++)
{
if (archivePath.Temp)
{
if (i > 0)
{
wchar_t s[16];
FChar s[16];
ConvertUInt32ToString(i, s);
archivePath.TempPostfix = s;
}
realPath = archivePath.GetTempPath();
}
else
realPath = archivePath.GetFinalPath();
realPath = us2fs(archivePath.GetFinalPath());
if (outStreamSpec->Create(realPath, false))
{
tempFiles.Paths.Add(realPath);
@@ -450,7 +446,7 @@ static HRESULT Compress(
volStreamSpec = new COutMultiVolStream;
outStream = volStreamSpec;
volStreamSpec->Sizes = volumesSizes;
volStreamSpec->Prefix = archivePath.GetFinalPath() + UString(L".");
volStreamSpec->Prefix = us2fs(archivePath.GetFinalPath() + L".");
volStreamSpec->TempFiles = &tempFiles;
volStreamSpec->Init();
@@ -484,7 +480,7 @@ static HRESULT Compress(
{
outStreamSpec = new COutFileStream;
sfxOutStream = outStreamSpec;
UString realPath = archivePath.GetFinalPath();
FString realPath = us2fs(archivePath.GetFinalPath());
if (!outStreamSpec->Create(realPath, false))
{
errorInfo.SystemError = ::GetLastError();
@@ -527,14 +523,7 @@ HRESULT EnumerateInArchiveItems(const NWildcard::CCensor &censor,
RINOK(IsArchiveItemFolder(archive, i, ai.IsDir));
ai.Censored = censor.CheckPath(ai.Name, !ai.IsDir);
RINOK(arc.GetItemMTime(i, ai.MTime, ai.MTimeDefined));
{
CPropVariant prop;
RINOK(archive->GetProperty(i, kpidSize, &prop));
ai.SizeDefined = (prop.vt != VT_EMPTY);
if (ai.SizeDefined)
ai.Size = ConvertPropVariantToUInt64(prop);
}
RINOK(arc.GetItemSize(i, ai.Size, ai.SizeDefined));
{
CPropVariant prop;
@@ -608,11 +597,11 @@ static HRESULT UpdateWithItemLists(
#if defined(_WIN32) && !defined(UNDER_CE)
class CCurrentDirRestorer
{
UString _path;
FString _path;
public:
CCurrentDirRestorer() { NFile::NDirectory::MyGetCurrentDirectory(_path); }
~CCurrentDirRestorer() { RestoreDirectory();}
bool RestoreDirectory() { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(_path)); }
bool RestoreDirectory() const { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(_path)); }
};
#endif
@@ -661,17 +650,25 @@ HRESULT UpdateArchive(
errorInfo.Message = L"SFX file is not specified";
return E_FAIL;
}
UString name = options.SfxModule;
#ifdef UNDER_CE
if (!NFind::DoesFileExist(name))
#else
if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))
#endif
bool found = false;
if (options.SfxModule.Find(FCHAR_PATH_SEPARATOR) < 0)
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"7-Zip cannot find specified SFX module";
errorInfo.FileName = name;
return E_FAIL;
const FString fullName = NDLL::GetModuleDirPrefix() + options.SfxModule;
if (NFind::DoesFileExist(fullName))
{
options.SfxModule = fullName;
found = true;
}
}
if (!found)
{
if (!NFind::DoesFileExist(options.SfxModule))
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"7-Zip cannot find specified SFX module";
errorInfo.FileName = options.SfxModule;
return E_FAIL;
}
}
}
@@ -681,8 +678,8 @@ HRESULT UpdateArchive(
if (!options.ArchivePath.OriginalPath.IsEmpty())
{
NFind::CFileInfoW fi;
if (fi.Find(arcPath))
NFind::CFileInfo fi;
if (fi.Find(us2fs(arcPath)))
{
if (fi.IsDir())
throw "there is no such archive";
@@ -738,12 +735,12 @@ HRESULT UpdateArchive(
CEnumDirItemUpdateCallback enumCallback;
enumCallback.Callback = callback;
RINOK(callback->StartScanning());
UStringVector errorPaths;
FStringVector errorPaths;
CRecordVector<DWORD> errorCodes;
HRESULT res = EnumerateItems(censor, dirItems, &enumCallback, errorPaths, errorCodes);
for (int i = 0; i < errorPaths.Size(); i++)
{
RINOK(callback->CanNotFindError(errorPaths[i], errorCodes[i]));
RINOK(callback->CanNotFindError(fs2us(errorPaths[i]), errorCodes[i]));
}
if (res != S_OK)
{
@@ -755,11 +752,11 @@ HRESULT UpdateArchive(
}
}
UString tempDirPrefix;
FString tempDirPrefix;
bool usesTempDir = false;
#ifdef _WIN32
NDirectory::CTempDirectoryW tempDirectory;
NDirectory::CTempDir tempDirectory;
if (options.EMailMode && options.EMailRemoveAfter)
{
tempDirectory.Create(kTempFolderPrefix);
@@ -792,20 +789,20 @@ HRESULT UpdateArchive(
}
}
for(int i = 0; i < options.Commands.Size(); i++)
for (int i = 0; i < options.Commands.Size(); i++)
{
CArchivePath &ap = options.Commands[i].ArchivePath;
if (usesTempDir)
{
// Check it
ap.Prefix = tempDirPrefix;
ap.Prefix = fs2us(tempDirPrefix);
// ap.Temp = true;
// ap.TempPrefix = tempDirPrefix;
}
if (!options.StdOutMode &&
(i > 0 || !createTempFile))
{
const UString &path = ap.GetFinalPath();
const FString path = us2fs(ap.GetFinalPath());
if (NFind::DoesFileOrDirExist(path))
{
errorInfo.SystemError = 0;
@@ -839,21 +836,21 @@ HRESULT UpdateArchive(
try
{
CArchivePath &ap = options.Commands[0].ArchivePath;
const UString &tempPath = ap.GetTempPath();
const FString &tempPath = ap.GetTempPath();
if (thereIsInArchive)
if (!NDirectory::DeleteFileAlways(arcPath))
if (!NDirectory::DeleteFileAlways(us2fs(arcPath)))
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"7-Zip cannot delete the file";
errorInfo.FileName = arcPath;
errorInfo.FileName = us2fs(arcPath);
return E_FAIL;
}
if (!NDirectory::MyMoveFile(tempPath, arcPath))
if (!NDirectory::MyMoveFile(tempPath, us2fs(arcPath)))
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"7-Zip cannot move the file";
errorInfo.FileName = tempPath;
errorInfo.FileName2 = arcPath;
errorInfo.FileName2 = us2fs(arcPath);
return E_FAIL;
}
}
@@ -867,7 +864,7 @@ HRESULT UpdateArchive(
if (options.EMailMode)
{
NDLL::CLibrary mapiLib;
if (!mapiLib.Load(TEXT("Mapi32.dll")))
if (!mapiLib.Load(FTEXT("Mapi32.dll")))
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"7-Zip cannot load Mapi32.dll";
@@ -880,13 +877,13 @@ HRESULT UpdateArchive(
errorInfo.Message = L"7-Zip cannot find MAPISendDocuments function";
return E_FAIL;
}
UStringVector fullPaths;
FStringVector fullPaths;
int i;
for(i = 0; i < options.Commands.Size(); i++)
for (i = 0; i < options.Commands.Size(); i++)
{
CArchivePath &ap = options.Commands[i].ArchivePath;
UString arcPath;
if (!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))
FString arcPath;
if (!NFile::NDirectory::MyGetFullPathName(us2fs(ap.GetFinalPath()), arcPath))
{
errorInfo.SystemError = ::GetLastError();
errorInfo.Message = L"GetFullPathName error";
@@ -895,9 +892,9 @@ HRESULT UpdateArchive(
fullPaths.Add(arcPath);
}
CCurrentDirRestorer curDirRestorer;
for(i = 0; i < fullPaths.Size(); i++)
for (i = 0; i < fullPaths.Size(); i++)
{
UString arcPath = fullPaths[i];
UString arcPath = fs2us(fullPaths[i]);
UString fileName = ExtractFileNameFromPath(arcPath);
AString path = GetAnsiString(arcPath);
AString name = GetAnsiString(fileName);

View File

@@ -21,8 +21,8 @@ struct CArchivePath
UString VolExtension; // archive type extension for volumes
bool Temp;
UString TempPrefix; // path(folder) for temp location
UString TempPostfix;
FString TempPrefix; // path(folder) for temp location
FString TempPostfix;
CArchivePath(): Temp(false) {};
@@ -63,12 +63,12 @@ struct CArchivePath
}
UString GetTempPath() const
FString GetTempPath() const
{
UString path = TempPrefix + Name;
FString path = TempPrefix + us2fs(Name);
if (!BaseExtension.IsEmpty())
path += UString(L'.') + BaseExtension;
path += L".tmp";
path += FString(FTEXT('.')) + us2fs(BaseExtension);
path += FTEXT(".tmp");
path += TempPostfix;
return path;
}
@@ -97,7 +97,7 @@ struct CUpdateOptions
CArchivePath ArchivePath;
bool SfxMode;
UString SfxModule;
FString SfxModule;
bool OpenShareForWrite;
@@ -109,7 +109,7 @@ struct CUpdateOptions
bool EMailRemoveAfter;
UString EMailAddress;
UString WorkingDir;
FString WorkingDir;
bool Init(const CCodecs *codecs, const CIntVector &formatIndices, const UString &arcPath);
@@ -137,8 +137,8 @@ struct CUpdateOptions
struct CErrorInfo
{
DWORD SystemError;
UString FileName;
UString FileName2;
FString FileName;
FString FileName2;
UString Message;
// UStringVector ErrorPaths;
// CRecordVector<DWORD> ErrorCodes;

View File

@@ -22,7 +22,8 @@ CArchiveUpdateCallback::CArchiveUpdateCallback():
DirItems(0),
ArcItems(0),
UpdatePairs(0),
NewNames(0)
NewNames(0),
KeepOriginalItemNames(0)
{}
@@ -120,7 +121,22 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
const CDirItem &di = DirItems->Items[up.DirIndex];
switch(propID)
{
case kpidPath: prop = DirItems->GetLogPath(up.DirIndex); break;
case kpidPath:
{
if (KeepOriginalItemNames)
{
if (up.ExistInArchive() && Archive)
{
UInt32 indexInArchive;
if (ArcItems == 0)
indexInArchive = up.ArcIndex;
else
indexInArchive = (*ArcItems)[up.ArcIndex].IndexInServer;
return Archive->GetProperty(indexInArchive, propID, value);
}
}
prop = DirItems->GetLogPath(up.DirIndex); break;
}
case kpidIsDir: prop = di.IsDir(); break;
case kpidSize: prop = di.Size; break;
case kpidAttrib: prop = di.Attrib; break;
@@ -186,7 +202,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream
CInFileStream *inStreamSpec = new CInFileStream;
CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
const UString path = DirItems->GetPhyPath(up.DirIndex);
if (!inStreamSpec->OpenShared(path, ShareForWrite))
if (!inStreamSpec->OpenShared(us2fs(path), ShareForWrite))
{
return Callback->OpenFileError(path, ::GetLastError());
}
@@ -216,12 +232,12 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
{
COM_TRY_BEGIN
wchar_t temp[16];
FChar temp[16];
ConvertUInt32ToString(index + 1, temp);
UString res = temp;
FString res = temp;
while (res.Length() < 2)
res = UString(L'0') + res;
UString fileName = VolName;
res = FString(FTEXT('0')) + res;
FString fileName = VolName;
fileName += L'.';
fileName += res;
fileName += VolExt;

View File

@@ -55,8 +55,8 @@ public:
public:
CRecordVector<UInt64> VolumesSizes;
UString VolName;
UString VolExt;
FString VolName;
FString VolExt;
IUpdateCallbackUI *Callback;
@@ -67,6 +67,7 @@ public:
const CRecordVector<CUpdatePair2> *UpdatePairs;
const UStringVector *NewNames;
CMyComPtr<IInArchive> Archive;
bool KeepOriginalItemNames;
CArchiveUpdateCallback();
};

View File

@@ -5,23 +5,23 @@
#include "Common/StringConvert.h"
#include "Common/Wildcard.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
#include "WorkDir.h"
using namespace NWindows;
using namespace NFile;
using namespace NDirectory;
UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FString &fileName)
{
NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
#ifndef UNDER_CE
if (workDirInfo.ForRemovableOnly)
{
mode = NWorkDir::NMode::kCurrent;
UString prefix = path.Left(3);
if (prefix[1] == L':' && prefix[2] == L'\\')
FString prefix = path.Left(3);
if (prefix[1] == FTEXT(':') && prefix[2] == FTEXT('\\'))
{
UINT driveType = GetDriveType(GetSystemString(prefix, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP));
if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
@@ -36,24 +36,56 @@ UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
*/
}
#endif
switch(mode)
int pos = path.ReverseFind(FCHAR_PATH_SEPARATOR) + 1;
fileName = path.Mid(pos);
switch (mode)
{
case NWorkDir::NMode::kCurrent:
{
return ExtractDirPrefixFromPath(path);
return path.Left(pos);;
}
case NWorkDir::NMode::kSpecified:
{
UString tempDir = workDirInfo.Path;
FString tempDir = workDirInfo.Path;
NName::NormalizeDirPathPrefix(tempDir);
return tempDir;
}
default:
{
UString tempDir;
if (!NDirectory::MyGetTempPath(tempDir))
FString tempDir;
if (!MyGetTempPath(tempDir))
throw 141717;
return tempDir;
}
}
}
HRESULT CWorkDirTempFile::CreateTempFile(const FString &originalPath)
{
NWorkDir::CInfo workDirInfo;
workDirInfo.Load();
FString namePart;
FString workDir = GetWorkDir(workDirInfo, originalPath, namePart);
CreateComplexDirectory(workDir);
CTempFile tempFile;
_outStreamSpec = new COutFileStream;
OutStream = _outStreamSpec;
if (!_tempFile.Create(workDir + namePart, &_outStreamSpec->File))
{
DWORD error = GetLastError();
return error ? error : E_FAIL;
}
_originalPath = originalPath;
return S_OK;
}
HRESULT CWorkDirTempFile::MoveToOriginal(bool deleteOriginal)
{
OutStream.Release();
if (!_tempFile.MoveTo(_originalPath, deleteOriginal))
{
DWORD error = GetLastError();
return error ? error : E_FAIL;
}
return S_OK;
}

View File

@@ -1,10 +1,26 @@
// WorkDir.h
#ifndef __WORKDIR_H
#define __WORKDIR_H
#ifndef __WORK_DIR_H
#define __WORK_DIR_H
#include "Windows/FileDir.h"
#include "ZipRegistry.h"
UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path);
#include "../../Common/FileStreams.h"
FString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const FString &path, FString &fileName);
class CWorkDirTempFile
{
FString _originalPath;
NWindows::NFile::NDirectory::CTempFile _tempFile;
COutFileStream *_outStreamSpec;
public:
CMyComPtr<IOutStream> OutStream;
HRESULT CreateTempFile(const FString &originalPath);
HRESULT MoveToOriginal(bool deleteOriginal);
};
#endif

View File

@@ -3,7 +3,6 @@
#include "StdAfx.h"
#include "Common/IntToString.h"
#include "Common/StringConvert.h"
#include "Windows/FileDir.h"
#include "Windows/Registry.h"
@@ -53,6 +52,13 @@ void CInfo::Save() const
key.SetValue_Strings(kPathHistory, Paths);
}
void Save_ShowPassword(bool showPassword)
{
CS_LOCK
CKey key;
CreateMainKey(key, kKeyName);
key.SetValue(kShowPassword, showPassword);
}
void CInfo::Load()
{
@@ -75,6 +81,17 @@ void CInfo::Load()
key.GetValue_IfOk(kShowPassword, ShowPassword);
}
bool Read_ShowPassword()
{
CS_LOCK
CKey key;
bool showPassword = false;
if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS)
return showPassword;
key.GetValue_IfOk(kShowPassword, showPassword);
return showPassword;
}
}
namespace NCompression
@@ -234,7 +251,7 @@ void CInfo::Save()const
CKey key;
CreateMainKey(key, kOptionsInfoKeyName);
key.SetValue(kWorkDirType, (UInt32)Mode);
key.SetValue(kWorkDirPath, Path);
key.SetValue(kWorkDirPath, fs2us(Path));
key.SetValue(kTempRemovableOnly, ForRemovableOnly);
}
@@ -257,7 +274,10 @@ void CInfo::Load()
case NMode::kSpecified:
Mode = (NMode::EEnum)dirType;
}
if (key.QueryValue(kWorkDirPath, Path) != ERROR_SUCCESS)
UString pathU;
if (key.QueryValue(kWorkDirPath, pathU) == ERROR_SUCCESS)
Path = us2fs(pathU);
else
{
Path.Empty();
if (Mode == NMode::kSpecified)

View File

@@ -20,6 +20,8 @@ namespace NExtract
void Save() const;
void Load();
};
void Save_ShowPassword(bool showPassword);
bool Read_ShowPassword();
}
namespace NCompression
@@ -76,7 +78,7 @@ namespace NWorkDir
struct CInfo
{
NMode::EEnum Mode;
UString Path;
FString Path;
bool ForRemovableOnly;
void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }