diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2022-01-22 21:43:09 +0300 |
---|---|---|
committer | Kornel <kornel@geekhood.net> | 2022-01-22 21:43:09 +0300 |
commit | c3529a41f527101f05e9e834a19205ee33a3b097 (patch) | |
tree | 2a76fa3119a75a39cf3ea7418877f53f1a64b7b4 /CPP/7zip/UI | |
parent | 52eeaf1ad614fcd03b48423009182e3e3d1ff694 (diff) |
21.0721.07
Diffstat (limited to 'CPP/7zip/UI')
27 files changed, 338 insertions, 104 deletions
diff --git a/CPP/7zip/UI/Agent/Agent.cpp b/CPP/7zip/UI/Agent/Agent.cpp index 31c91e29..cdb0e5d1 100644 --- a/CPP/7zip/UI/Agent/Agent.cpp +++ b/CPP/7zip/UI/Agent/Agent.cpp @@ -1887,23 +1887,23 @@ STDMETHODIMP CAgent::GetArcProp(UInt32 level, PROPID propID, PROPVARIANT *value) break; case kpidErrorFlags: { - UInt32 flags = arc.ErrorInfo.GetErrorFlags(); + const UInt32 flags = arc.ErrorInfo.GetErrorFlags(); if (flags != 0) prop = flags; break; } case kpidWarningFlags: { - UInt32 flags = arc.ErrorInfo.GetWarningFlags(); + const UInt32 flags = arc.ErrorInfo.GetWarningFlags(); if (flags != 0) prop = flags; break; } case kpidOffset: { - Int64 v = arc.GetGlobalOffset(); + const Int64 v = arc.GetGlobalOffset(); if (v != 0) - prop = v; + prop.Set_Int64(v); break; } case kpidTailSize: diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp index 47e4a852..91ef0382 100644 --- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp +++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp @@ -151,6 +151,7 @@ enum Enum kCaseSensitive, kArcNameMode, + kUseSlashMark, kDisableWildcardParsing, kElimDup, kFullPathMode, @@ -294,6 +295,7 @@ static const CSwitchForm kSwitchForms[] = { "ssc", SWFRM_MINUS }, { "sa", NSwitchType::kChar, false, 1, k_ArcNameMode_PostCharSet }, + { "spm", SWFRM_STRING_SINGL(0) }, { "spd", SWFRM_SIMPLE }, { "spe", SWFRM_MINUS }, { "spf", SWFRM_STRING_SINGL(0) }, @@ -407,12 +409,28 @@ static bool ParseArchiveCommand(const UString &commandString, CArcCommand &comma // ------------------------------------------------------------------ // filenames functions +struct CNameOption +{ + bool Include; + bool WildcardMatching; + Byte MarkMode; + NRecursedType::EEnum RecursedType; + + CNameOption(): + Include(true), + WildcardMatching(true), + MarkMode(NWildcard::kMark_FileOrDir), + RecursedType(NRecursedType::kNonRecursed) + {} +}; + + static void AddNameToCensor(NWildcard::CCensor &censor, - const UString &name, bool include, NRecursedType::EEnum type, bool wildcardMatching) + const CNameOption &nop, const UString &name) { bool recursed = false; - switch (type) + switch (nop.RecursedType) { case NRecursedType::kWildcardOnlyRecursed: recursed = DoesNameContainWildcard(name); @@ -423,7 +441,12 @@ static void AddNameToCensor(NWildcard::CCensor &censor, default: break; } - censor.AddPreItem(include, name, recursed, wildcardMatching); + + NWildcard::CCensorPathProps props; + props.Recursive = recursed; + props.WildcardMatching = nop.WildcardMatching; + props.MarkMode = nop.MarkMode; + censor.AddPreItem(nop.Include, name, props); } static void AddRenamePair(CObjectVector<CRenamePair> *renamePairs, @@ -454,7 +477,7 @@ static void AddRenamePair(CObjectVector<CRenamePair> *renamePairs, static void AddToCensorFromListFile( CObjectVector<CRenamePair> *renamePairs, NWildcard::CCensor &censor, - LPCWSTR fileName, bool include, NRecursedType::EEnum type, bool wildcardMatching, UInt32 codePage) + const CNameOption &nop, LPCWSTR fileName, UInt32 codePage) { UStringVector names; /* @@ -481,12 +504,12 @@ static void AddToCensorFromListFile( for (unsigned i = 0; i < names.Size(); i += 2) { // change type !!!! - AddRenamePair(renamePairs, names[i], names[i + 1], type, wildcardMatching); + AddRenamePair(renamePairs, names[i], names[i + 1], nop.RecursedType, nop.WildcardMatching); } } else FOR_VECTOR (i, names) - AddNameToCensor(censor, names[i], include, type, wildcardMatching); + AddNameToCensor(censor, nop, names[i]); } static void AddToCensorFromNonSwitchesStrings( @@ -495,14 +518,27 @@ static void AddToCensorFromNonSwitchesStrings( NWildcard::CCensor &censor, const UStringVector &nonSwitchStrings, int stopSwitchIndex, - NRecursedType::EEnum type, - bool wildcardMatching, + const CNameOption &nop, bool thereAreSwitchIncludes, UInt32 codePage) { + // another default if ((renamePairs || nonSwitchStrings.Size() == startIndex) && !thereAreSwitchIncludes) - AddNameToCensor(censor, UString(kUniversalWildcard), true, type, - true // wildcardMatching - ); + { + /* for rename command: -i switch sets the mask for archive item reading. + if (thereAreSwitchIncludes), { we don't use UniversalWildcard. } + also for non-rename command: we set UniversalWildcard, only if there are no nonSwitches. */ + // we use default fileds in (CNameOption) for UniversalWildcard. + CNameOption nop2; + // recursive mode is not important for UniversalWildcard (*) + // nop2.RecursedType = nop.RecursedType; // we don't need it + /* + nop2.RecursedType = NRecursedType::kNonRecursed; + nop2.Include = true; + nop2.WildcardMatching = true; + nop2.MarkMode = NWildcard::kMark_FileOrDir; + */ + AddNameToCensor(censor, nop2, UString(kUniversalWildcard)); + } int oldIndex = -1; @@ -515,7 +551,7 @@ static void AddToCensorFromNonSwitchesStrings( if (s.IsEmpty()) throw CArcCmdLineException(kEmptyFilePath); if (i < (unsigned)stopSwitchIndex && s[0] == kFileListID) - AddToCensorFromListFile(renamePairs, censor, s.Ptr(1), true, type, wildcardMatching, codePage); + AddToCensorFromListFile(renamePairs, censor, nop, s.Ptr(1), codePage); else if (renamePairs) { if (oldIndex == -1) @@ -523,13 +559,13 @@ static void AddToCensorFromNonSwitchesStrings( else { // NRecursedType::EEnum type is used for global wildcard (-i! switches) - AddRenamePair(renamePairs, nonSwitchStrings[(unsigned)oldIndex], s, NRecursedType::kNonRecursed, wildcardMatching); + AddRenamePair(renamePairs, nonSwitchStrings[(unsigned)oldIndex], s, NRecursedType::kNonRecursed, nop.WildcardMatching); // AddRenamePair(renamePairs, nonSwitchStrings[oldIndex], s, type); oldIndex = -1; } } else - AddNameToCensor(censor, s, true, type, wildcardMatching); + AddNameToCensor(censor, nop, s); } if (oldIndex != -1) @@ -557,9 +593,8 @@ static const char * const k_IncorrectMapCommand = "Incorrect Map command"; static const char *ParseMapWithPaths( NWildcard::CCensor &censor, - const UString &s2, bool include, - NRecursedType::EEnum commonRecursedType, - bool wildcardMatching) + const UString &s2, + const CNameOption &nop) { UString s (s2); int pos = s.Find(L':'); @@ -598,7 +633,7 @@ static const char *ParseMapWithPaths( if (c == 0) { // MessageBoxW(0, name, L"7-Zip", 0); - AddNameToCensor(censor, name, include, commonRecursedType, wildcardMatching); + AddNameToCensor(censor, nop, name); name.Empty(); } else @@ -614,9 +649,8 @@ static const char *ParseMapWithPaths( static void AddSwitchWildcardsToCensor( NWildcard::CCensor &censor, - const UStringVector &strings, bool include, - NRecursedType::EEnum commonRecursedType, - bool wildcardMatching, + const UStringVector &strings, + const CNameOption &nop, UInt32 codePage) { const char *errorMessage = NULL; @@ -624,7 +658,6 @@ static void AddSwitchWildcardsToCensor( for (i = 0; i < strings.Size(); i++) { const UString &name = strings[i]; - NRecursedType::EEnum recursedType; unsigned pos = 0; if (name.Len() < kSomeCludePostStringMinSize) @@ -633,7 +666,7 @@ static void AddSwitchWildcardsToCensor( break; } - if (!include) + if (!nop.Include) { if (name.IsEqualTo_Ascii_NoCase("td")) { @@ -647,20 +680,85 @@ static void AddSwitchWildcardsToCensor( } } - if (::MyCharLower_Ascii(name[pos]) == kRecursedIDChar) + CNameOption nop2 = nop; + + bool type_WasUsed = false; + bool recursed_WasUsed = false; + bool matching_WasUsed = false; + bool error = false; + + for (;;) { - pos++; - wchar_t c = name[pos]; - int index = -1; - if (c <= 0x7F) - index = FindCharPosInString(kRecursedPostCharSet, (char)c); - recursedType = GetRecursedTypeFromIndex(index); - if (index >= 0) + wchar_t c = ::MyCharLower_Ascii(name[pos]); + if (c == kRecursedIDChar) + { + if (recursed_WasUsed) + { + error = true; + break; + } + recursed_WasUsed = true; pos++; + c = name[pos]; + int index = -1; + if (c <= 0x7F) + index = FindCharPosInString(kRecursedPostCharSet, (char)c); + nop2.RecursedType = GetRecursedTypeFromIndex(index); + if (index >= 0) + { + pos++; + continue; + } + } + + if (c == 'w') + { + if (matching_WasUsed) + { + error = true; + break; + } + matching_WasUsed = true; + nop2.WildcardMatching = true; + pos++; + if (name[pos] == '-') + { + nop2.WildcardMatching = false; + pos++; + } + } + else if (c == 'm') + { + if (type_WasUsed) + { + error = true; + break; + } + type_WasUsed = true; + pos++; + nop2.MarkMode = NWildcard::kMark_StrictFile; + c = name[pos]; + if (c == '-') + { + nop2.MarkMode = NWildcard::kMark_FileOrDir; + pos++; + } + else if (c == '2') + { + nop2.MarkMode = NWildcard::kMark_StrictFile_IfWildcard; + pos++; + } + } + else + break; } - else - recursedType = commonRecursedType; + if (error) + { + errorMessage = "inorrect switch"; + break; + } + if (name.Len() < pos + kSomeCludeAfterRecursedPostStringMinSize) { errorMessage = "Too short switch"; @@ -668,15 +766,17 @@ static void AddSwitchWildcardsToCensor( } const UString tail = name.Ptr(pos + 1); - - if (name[pos] == kImmediateNameID) - AddNameToCensor(censor, tail, include, recursedType, wildcardMatching); - else if (name[pos] == kFileListID) - AddToCensorFromListFile(NULL, censor, tail, include, recursedType, wildcardMatching, codePage); + + const wchar_t c = name[pos]; + + if (c == kImmediateNameID) + AddNameToCensor(censor, nop2, tail); + else if (c == kFileListID) + AddToCensorFromListFile(NULL, censor, nop2, tail, codePage); #ifdef _WIN32 - else if (name[pos] == kMapNameID) + else if (c == kMapNameID) { - errorMessage = ParseMapWithPaths(censor, tail, include, recursedType, wildcardMatching); + errorMessage = ParseMapWithPaths(censor, tail, nop2); if (errorMessage) break; } @@ -687,6 +787,7 @@ static void AddSwitchWildcardsToCensor( break; } } + if (i != strings.Size()) throw CArcCmdLineException(errorMessage, strings[i]); } @@ -1165,32 +1266,48 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) if (parser[NKey::kNameTrailReplace].ThereIs) g_PathTrailReplaceMode = !parser[NKey::kNameTrailReplace].WithMinus; - NRecursedType::EEnum recursedType; + CNameOption nop; + if (parser[NKey::kRecursed].ThereIs) - recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex); - else - recursedType = NRecursedType::kNonRecursed; + nop.RecursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex); - bool wildcardMatching = true; if (parser[NKey::kDisableWildcardParsing].ThereIs) - wildcardMatching = false; + nop.WildcardMatching = false; + + if (parser[NKey::kUseSlashMark].ThereIs) + { + const UString &s = parser[NKey::kUseSlashMark].PostStrings[0]; + if (s.IsEmpty()) + nop.MarkMode = NWildcard::kMark_StrictFile; + else if (s.IsEqualTo_Ascii_NoCase("-")) + nop.MarkMode = NWildcard::kMark_FileOrDir; + else if (s.IsEqualTo_Ascii_NoCase("2")) + nop.MarkMode = NWildcard::kMark_StrictFile_IfWildcard; + else + throw CArcCmdLineException("Unsupported -spm:", s); + } + options.ConsoleCodePage = FindCharset(parser, NKey::kConsoleCharSet, true, -1); UInt32 codePage = (UInt32)FindCharset(parser, NKey::kListfileCharSet, false, CP_UTF8); bool thereAreSwitchIncludes = false; - + if (parser[NKey::kInclude].ThereIs) { thereAreSwitchIncludes = true; + nop.Include = true; AddSwitchWildcardsToCensor(options.Censor, - parser[NKey::kInclude].PostStrings, true, recursedType, wildcardMatching, codePage); + parser[NKey::kInclude].PostStrings, nop, codePage); } if (parser[NKey::kExclude].ThereIs) + { + nop.Include = false; AddSwitchWildcardsToCensor(options.Censor, - parser[NKey::kExclude].PostStrings, false, recursedType, wildcardMatching, codePage); + parser[NKey::kExclude].PostStrings, nop, codePage); + } unsigned curCommandIndex = kCommandIndex + 1; bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs && @@ -1198,9 +1315,9 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) options.Command.CommandType != NCommandType::kInfo && options.Command.CommandType != NCommandType::kHash; - bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); - bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList; - bool isRename = options.Command.CommandType == NCommandType::kRename; + const bool isExtractGroupCommand = options.Command.IsFromExtractGroup(); + const bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList; + const bool isRename = options.Command.CommandType == NCommandType::kRename; if ((isExtractOrList || isRename) && options.StdInMode) thereIsArchiveName = false; @@ -1220,10 +1337,11 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) #endif } + nop.Include = true; AddToCensorFromNonSwitchesStrings(isRename ? &options.UpdateOptions.RenamePairs : NULL, curCommandIndex, options.Censor, nonSwitchStrings, parser.StopSwitchIndex, - recursedType, wildcardMatching, + nop, thereAreSwitchIncludes, codePage); options.YesToAll = parser[NKey::kYes].ThereIs; @@ -1317,13 +1435,28 @@ void CArcCmdLineParser::Parse2(CArcCmdLineOptions &options) NWildcard::CCensor &arcCensor = options.arcCensor; + CNameOption nopArc; + // nopArc.RecursedType = NRecursedType::kNonRecursed; // default: we don't want recursing for archives, if -r specified + // is it OK, external switches can disable WildcardMatching and MarcMode for arc. + nopArc.WildcardMatching = nop.WildcardMatching; + nopArc.MarkMode = nop.MarkMode; + if (parser[NKey::kArInclude].ThereIs) - AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, wildcardMatching, codePage); + { + nopArc.Include = true; + AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArInclude].PostStrings, nopArc, codePage); + } if (parser[NKey::kArExclude].ThereIs) - AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, wildcardMatching, codePage); + { + nopArc.Include = false; + AddSwitchWildcardsToCensor(arcCensor, parser[NKey::kArExclude].PostStrings, nopArc, codePage); + } if (thereIsArchiveName) - AddNameToCensor(arcCensor, options.ArchiveName, true, NRecursedType::kNonRecursed, wildcardMatching); + { + nopArc.Include = true; + AddNameToCensor(arcCensor, nopArc, options.ArchiveName); + } arcCensor.AddPathsToCensor(NWildcard::k_RelatPath); @@ -1515,7 +1648,7 @@ FString GetModuleDirPrefix() { FString s; - s = g_ModuleDirPrefix; + s = fas2fs(g_ModuleDirPrefix); if (s.IsEmpty()) s = FTEXT(".") FSTRING_PATH_SEPARATOR; return s; diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp index 9fea6dc2..73c191e4 100644 --- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp @@ -1000,8 +1000,8 @@ HRESULT CArchiveExtractCallback::CheckExistFile(FString &fullProcessedPath, bool if (_overwriteMode == NExtract::NOverwriteMode::kAsk) { - int slashPos = fullProcessedPath.ReverseFind_PathSepar(); - FString realFullProcessedPath (fullProcessedPath.Left((unsigned)(slashPos + 1)) + fileInfo.Name); + const int slashPos = fullProcessedPath.ReverseFind_PathSepar(); + const FString realFullProcessedPath = fullProcessedPath.Left((unsigned)(slashPos + 1)) + fileInfo.Name; /* (fileInfo) can be symbolic link. we can show final file properties here. */ diff --git a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp index d3e0d3ce..d5926f8f 100644 --- a/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp +++ b/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp @@ -48,7 +48,7 @@ STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value) else switch (propID) { - case kpidName: prop = _fileInfo.Name; break; + case kpidName: prop = fs2us(_fileInfo.Name); break; case kpidIsDir: prop = _fileInfo.IsDir(); break; case kpidSize: prop = _fileInfo.Size; break; case kpidAttrib: prop = (UInt32)_fileInfo.Attrib; break; @@ -103,12 +103,20 @@ STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStre if (!IsSafePath(name2)) return S_FALSE; - // #ifdef _WIN32 - // we don't want to support wildcards in names here here - if (name2.Find(L'?') >= 0 || - name2.Find(L'*') >= 0) + #ifdef _WIN32 + /* WIN32 allows wildcards in Find() function + and doesn't allow wildcard in File.Open() + so we can work without the following wildcard check here */ + if (name2.Find(L'*') >= 0) return S_FALSE; - // #endif + { + int startPos = 0; + if (name2.IsPrefixedBy_Ascii_NoCase("\\\\?\\")) + startPos = 3; + if (name2.Find(L'?', startPos) >= 0) + return S_FALSE; + } + #endif #endif diff --git a/CPP/7zip/UI/Common/Bench.cpp b/CPP/7zip/UI/Common/Bench.cpp index 2ee29913..cc0cfd0c 100644 --- a/CPP/7zip/UI/Common/Bench.cpp +++ b/CPP/7zip/UI/Common/Bench.cpp @@ -866,7 +866,7 @@ struct CAffinityMode DWORD_PTR GetAffinityMask(UInt32 bundleIndex, CCpuSet *cpuSet) const; bool NeedAffinity() const { return NumBundleThreads != 0; } - WRes CreateThread_WithAffinity(NWindows::CThread &thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter, UInt32 bundleIndex) const + WRes CreateThread_WithAffinity(NWindows::CThread &thread, THREAD_FUNC_TYPE startAddress, LPVOID parameter, UInt32 bundleIndex) const { if (NeedAffinity()) { diff --git a/CPP/7zip/UI/Common/CompressCall.cpp b/CPP/7zip/UI/Common/CompressCall.cpp index 84a8d22f..c7efa99e 100644 --- a/CPP/7zip/UI/Common/CompressCall.cpp +++ b/CPP/7zip/UI/Common/CompressCall.cpp @@ -33,12 +33,16 @@ using namespace NWindows; #define k7zGui "7zG.exe" +// 21.07 : we can disable wildcard +// #define ISWITCH_NO_WILDCARD_POSTFIX "w-" +#define ISWITCH_NO_WILDCARD_POSTFIX + #define kShowDialogSwitch " -ad" #define kEmailSwitch " -seml." -#define kIncludeSwitch " -i" #define kArchiveTypeSwitch " -t" -#define kArcIncludeSwitches " -an -ai" -#define kHashIncludeSwitches " -i" +#define kIncludeSwitch " -i" ISWITCH_NO_WILDCARD_POSTFIX +#define kArcIncludeSwitches " -an -ai" ISWITCH_NO_WILDCARD_POSTFIX +#define kHashIncludeSwitches kIncludeSwitch #define kStopSwitchParsing " --" extern HWND g_HWND; diff --git a/CPP/7zip/UI/Common/CompressCall2.cpp b/CPP/7zip/UI/Common/CompressCall2.cpp index e6e42d64..762342d6 100644 --- a/CPP/7zip/UI/Common/CompressCall2.cpp +++ b/CPP/7zip/UI/Common/CompressCall2.cpp @@ -124,7 +124,7 @@ HRESULT CompressFiles( NWildcard::CCensor censor; FOR_VECTOR (i, names) { - censor.AddPreItem(names[i]); + censor.AddPreItem_NoWildcard(names[i]); } bool messageWasDisplayed = false; @@ -178,7 +178,7 @@ static HRESULT ExtractGroupCommand(const UStringVector &arcPaths, NWildcard::CCensor arcCensor; FOR_VECTOR (i, arcPaths) { - arcCensor.AddPreItem(arcPaths[i]); + arcCensor.AddPreItem_NoWildcard(arcPaths[i]); } arcCensor.AddPathsToCensor(NWildcard::k_RelatPath); CDirItemsStat st; @@ -268,7 +268,7 @@ void CalcChecksum(const UStringVector &paths, NWildcard::CCensor censor; FOR_VECTOR (i, paths) { - censor.AddPreItem(paths[i]); + censor.AddPreItem_NoWildcard(paths[i]); } censor.AddPathsToCensor(NWildcard::k_RelatPath); diff --git a/CPP/7zip/UI/Common/EnumDirItems.cpp b/CPP/7zip/UI/Common/EnumDirItems.cpp index 59baa092..89cce2ba 100644 --- a/CPP/7zip/UI/Common/EnumDirItems.cpp +++ b/CPP/7zip/UI/Common/EnumDirItems.cpp @@ -767,6 +767,15 @@ static HRESULT EnumerateDirItems( const UString &name = item.PathParts.Front(); FString fullPath = phyPrefix + us2fs(name); + /* + // not possible now + if (!item.ForDir && !item.ForFile) + { + RINOK(dirItems.AddError(fullPath, ERROR_INVALID_PARAMETER)); + continue; + } + */ + #if defined(_WIN32) && !defined(UNDER_CE) bool needAltStreams = true; #endif @@ -823,9 +832,20 @@ static HRESULT EnumerateDirItems( continue; } + /* + #ifdef _WIN32 + #define MY_ERROR_IS_DIR ERROR_FILE_NOT_FOUND + #define MY_ERROR_NOT_DIR DI_DEFAULT_ERROR + #else + #define MY_ERROR_IS_DIR EISDIR + #define MY_ERROR_NOT_DIR ENOTDIR + #endif + */ + const bool isDir = fi.IsDir(); - if ((isDir && !item.ForDir) || (!isDir && !item.ForFile)) + if (isDir ? !item.ForDir : !item.ForFile) { + // RINOK(dirItems.AddError(fullPath, isDir ? MY_ERROR_IS_DIR: MY_ERROR_NOT_DIR)); RINOK(dirItems.AddError(fullPath, DI_DEFAULT_ERROR)); continue; } diff --git a/CPP/7zip/UI/Common/HashCalc.cpp b/CPP/7zip/UI/Common/HashCalc.cpp index 654da86b..24177085 100644 --- a/CPP/7zip/UI/Common/HashCalc.cpp +++ b/CPP/7zip/UI/Common/HashCalc.cpp @@ -900,7 +900,7 @@ bool CHashPair::Parse(const char *s) return false; if (escape) { - AString temp = Name; + const AString temp (Name); return CSum_Name_EscapeToOriginal(temp, Name); } return true; diff --git a/CPP/7zip/UI/Common/Update.cpp b/CPP/7zip/UI/Common/Update.cpp index 4bd690d6..032a876d 100644 --- a/CPP/7zip/UI/Common/Update.cpp +++ b/CPP/7zip/UI/Common/Update.cpp @@ -974,6 +974,17 @@ static HRESULT Compress( +static bool Censor_AreAllAllowed(const NWildcard::CCensor &censor) +{ + if (censor.Pairs.Size() != 1) + return false; + const NWildcard::CPair &pair = censor.Pairs[0]; + /* Censor_CheckPath() ignores (CPair::Prefix). + So we also ignore (CPair::Prefix) here */ + // if (!pair.Prefix.IsEmpty()) return false; + return pair.Head.AreAllAllowed(); +} + bool CensorNode_CheckPath2(const NWildcard::CCensorNode &node, const CReadArcItem &item, bool &include); static bool Censor_CheckPath(const NWildcard::CCensor &censor, const CReadArcItem &item) @@ -981,9 +992,13 @@ static bool Censor_CheckPath(const NWildcard::CCensor &censor, const CReadArcIte bool finded = false; FOR_VECTOR (i, censor.Pairs) { + /* (CPair::Prefix) in not used for matching items in archive. + So we ignore (CPair::Prefix) here */ bool include; if (CensorNode_CheckPath2(censor.Pairs[i].Head, item, include)) { + // Check it and FIXME !!!! + // here we can exclude item via some Pair, that is still allowed by another Pair if (!include) return false; finded = true; @@ -1006,6 +1021,8 @@ static HRESULT EnumerateInArchiveItems( CReadArcItem item; + const bool allFilesAreAllowed = Censor_AreAllAllowed(censor); + for (UInt32 i = 0; i < numItems; i++) { CArcItem ai; @@ -1024,7 +1041,10 @@ static HRESULT EnumerateInArchiveItems( if (!storeStreamsMode && ai.IsAltStream) continue; */ - ai.Censored = Censor_CheckPath(censor, item); + if (allFilesAreAllowed) + ai.Censored = true; + else + ai.Censored = Censor_CheckPath(censor, item); RINOK(arc.GetItemMTime(i, ai.MTime, ai.MTimeDefined)); RINOK(arc.GetItemSize(i, ai.Size, ai.SizeDefined)); @@ -1418,7 +1438,7 @@ HRESULT UpdateArchive( UString s; s = "It is not allowed to include archive to itself"; s.Add_LF(); - s += path; + s += fs2us(path); throw s; } } diff --git a/CPP/7zip/UI/Console/HashCon.cpp b/CPP/7zip/UI/Console/HashCon.cpp index 1bd75c15..5a349765 100644 --- a/CPP/7zip/UI/Console/HashCon.cpp +++ b/CPP/7zip/UI/Console/HashCon.cpp @@ -138,7 +138,7 @@ static unsigned GetColumnWidth(unsigned digestSize) AString CHashCallbackConsole::GetFields() const { - AString s = PrintFields; + AString s (PrintFields); if (s.IsEmpty()) s = "hsn"; s.MakeLower_Ascii(); @@ -313,7 +313,7 @@ HRESULT CHashCallbackConsole::SetOperationResult(UInt64 fileSize, const CHashBun s = kEmptyFileAlias; else { - UString temp = _fileName; + UString temp (_fileName); _so->Normalize_UString(temp); _so->Convert_UString_to_AString(temp, s); } diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp index 14d83eb9..9000e57a 100644 --- a/CPP/7zip/UI/Console/List.cpp +++ b/CPP/7zip/UI/Console/List.cpp @@ -840,7 +840,7 @@ static void UString_Replace_CRLF_to_LF(UString &s) static void PrintPropVal_MultiLine(CStdOutStream &so, const wchar_t *val) { - UString s = val; + UString s (val); if (s.Find(L'\n') >= 0) { so << endl; @@ -869,7 +869,7 @@ static void PrintPropPair(CStdOutStream &so, const char *name, const wchar_t *va PrintPropVal_MultiLine(so, val); return; } - UString s = val; + UString s (val); so.Normalize_UString(s); so << s; so << endl; diff --git a/CPP/7zip/UI/Explorer/ContextMenu.cpp b/CPP/7zip/UI/Explorer/ContextMenu.cpp index 8a0842e1..69070211 100644 --- a/CPP/7zip/UI/Explorer/ContextMenu.cpp +++ b/CPP/7zip/UI/Explorer/ContextMenu.cpp @@ -947,7 +947,7 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, else name = fs2us(fi0.Name); name += ".sha256"; - cmi.Folder= folderPrefix; + cmi.Folder = fs2us(folderPrefix); cmi.ArcName = name; s = "SHA-256 -> "; s += name; diff --git a/CPP/7zip/UI/Explorer/MyExplorerCommand.h b/CPP/7zip/UI/Explorer/MyExplorerCommand.h index 6004d929..227b9e02 100644 --- a/CPP/7zip/UI/Explorer/MyExplorerCommand.h +++ b/CPP/7zip/UI/Explorer/MyExplorerCommand.h @@ -13,6 +13,48 @@ #else +/* IShellItem is defined: + ShObjIdl.h : old Windows SDK + ShObjIdl_core.h : new Windows 10 SDK */ + +#include <ShObjIdl.h> + +#ifndef __IShellItem_INTERFACE_DEFINED__ +#define __IShellItem_INTERFACE_DEFINED__ + +// For MINGW we define IShellItem + +// #error Stop_Compiling__NOT_DEFINED__IShellItem_INTERFACE_DEFINED__ + +typedef +enum +{ SIGDN_NORMALDISPLAY = 0, + SIGDN_PARENTRELATIVEPARSING = 0x80018001, + SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8001c001, + SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000, + SIGDN_PARENTRELATIVEEDITING = 0x80031001, + SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000, + SIGDN_FILESYSPATH = 0x80058000, + SIGDN_URL = 0x80068000 +} SIGDN; + + +typedef DWORD SICHINTF; +typedef ULONG SFGAOF; + +struct IShellItem : public IUnknown +{ + virtual HRESULT STDMETHODCALLTYPE BindToHandler(IBindCtx *pbc, REFGUID rbhid, REFIID riid, void **ppvOut) = 0; + virtual HRESULT STDMETHODCALLTYPE GetParent(IShellItem **ppsi) = 0; + virtual HRESULT STDMETHODCALLTYPE GetDisplayName(SIGDN sigdnName, LPOLESTR *ppszName) = 0; + virtual HRESULT STDMETHODCALLTYPE GetAttributes(SFGAOF sfgaoMask, SFGAOF *psfgaoAttribs) = 0; + virtual HRESULT STDMETHODCALLTYPE Compare(IShellItem *psi, SICHINTF hint, int *piOrder) = 0; +}; + +#endif // __IShellItem_INTERFACE_DEFINED__ + + + #ifndef __IShellItemArray_INTERFACE_DEFINED__ #define __IShellItemArray_INTERFACE_DEFINED__ diff --git a/CPP/7zip/UI/Far/FarUtils.cpp b/CPP/7zip/UI/Far/FarUtils.cpp index ddca3cab..3bdb9895 100644 --- a/CPP/7zip/UI/Far/FarUtils.cpp +++ b/CPP/7zip/UI/Far/FarUtils.cpp @@ -213,7 +213,7 @@ void CStartupInfo::RestoreScreen(HANDLE handle) CSysString CStartupInfo::GetFullKeyName(const char *keyName) const { - AString s = m_RegistryPath; + AString s (m_RegistryPath); if (keyName && *keyName) { s += kRegistryKeyDelimiter; diff --git a/CPP/7zip/UI/FileManager/FSDrives.cpp b/CPP/7zip/UI/FileManager/FSDrives.cpp index 208cea4e..c563907f 100644 --- a/CPP/7zip/UI/FileManager/FSDrives.cpp +++ b/CPP/7zip/UI/FileManager/FSDrives.cpp @@ -224,14 +224,14 @@ STDMETHODIMP CFSDrives::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIANT switch (propID) { case kpidIsDir: prop = !_volumeMode; break; - case kpidName: prop = di.Name; break; + case kpidName: prop = fs2us(di.Name); break; case kpidOutName: if (!di.Name.IsEmpty() && di.Name.Back() == ':') { FString s = di.Name; s.DeleteBack(); AddExt(s, itemIndex); - prop = s; + prop = fs2us(s); } break; diff --git a/CPP/7zip/UI/FileManager/FSFolder.cpp b/CPP/7zip/UI/FileManager/FSFolder.cpp index d82ddc27..f3e04b3c 100644 --- a/CPP/7zip/UI/FileManager/FSFolder.cpp +++ b/CPP/7zip/UI/FileManager/FSFolder.cpp @@ -515,7 +515,7 @@ STDMETHODIMP CFSFolder::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *va } case kpidPrefix: if (fi.Parent >= 0) - prop = Folders[fi.Parent]; + prop = fs2us(Folders[fi.Parent]); break; case kpidNumSubDirs: if (fi.IsDir() && fi.FolderStat_Defined) prop = fi.NumFolders; break; case kpidNumSubFiles: if (fi.IsDir() && fi.FolderStat_Defined) prop = fi.NumFiles; break; diff --git a/CPP/7zip/UI/FileManager/FSFolderCopy.cpp b/CPP/7zip/UI/FileManager/FSFolderCopy.cpp index 9b78ba0a..ff444b3b 100644 --- a/CPP/7zip/UI/FileManager/FSFolderCopy.cpp +++ b/CPP/7zip/UI/FileManager/FSFolderCopy.cpp @@ -473,7 +473,10 @@ static HRESULT CopyFile_Ask( static FString CombinePath(const FString &folderPath, const FString &fileName) { - return folderPath + FCHAR_PATH_SEPARATOR + fileName; + FString s (folderPath); + s.Add_PathSepar(); // FCHAR_PATH_SEPARATOR + s += fileName; + return s; } static bool IsDestChild(const FString &src, const FString &dest) diff --git a/CPP/7zip/UI/FileManager/MyLoadMenu.cpp b/CPP/7zip/UI/FileManager/MyLoadMenu.cpp index 63167d63..d87dfe38 100644 --- a/CPP/7zip/UI/FileManager/MyLoadMenu.cpp +++ b/CPP/7zip/UI/FileManager/MyLoadMenu.cpp @@ -486,6 +486,8 @@ void CFileMenu::Load(HMENU hMenu, unsigned startPos) ReadRegDiff(diffPath); unsigned numRealItems = startPos; + + const bool isBigScreen = NControl::IsDialogSizeOK(40, 200, g_HWND); for (unsigned i = 0;; i++) { @@ -568,8 +570,6 @@ void CFileMenu::Load(HMENU hMenu, unsigned startPos) if (item.wID == IDM_ALT_STREAMS) disable = !isAltStreamsSupported; - bool isBigScreen = NControl::IsDialogSizeOK(40, 200); - if (!isBigScreen && (disable || item.IsSeparator())) continue; diff --git a/CPP/7zip/UI/FileManager/OpenCallback.cpp b/CPP/7zip/UI/FileManager/OpenCallback.cpp index ddec3877..e2e03f5e 100644 --- a/CPP/7zip/UI/FileManager/OpenCallback.cpp +++ b/CPP/7zip/UI/FileManager/OpenCallback.cpp @@ -69,7 +69,7 @@ STDMETHODIMP COpenArchiveCallback::GetProperty(PROPID propID, PROPVARIANT *value { switch (propID) { - case kpidName: prop = _fileInfo.Name; break; + case kpidName: prop = fs2us(_fileInfo.Name); break; case kpidIsDir: prop = _fileInfo.IsDir(); break; case kpidSize: prop = _fileInfo.Size; break; case kpidAttrib: prop = (UInt32)_fileInfo.Attrib; break; diff --git a/CPP/7zip/UI/FileManager/PanelCrc.cpp b/CPP/7zip/UI/FileManager/PanelCrc.cpp index 6c49e897..1d483ca1 100644 --- a/CPP/7zip/UI/FileManager/PanelCrc.cpp +++ b/CPP/7zip/UI/FileManager/PanelCrc.cpp @@ -289,7 +289,7 @@ HRESULT CThreadCrc::ProcessVirt() } if (isFirstFile) { - Hash.FirstFileName = path; + Hash.FirstFileName = fs2us(path); isFirstFile = false; } sync.Set_FilePath(fs2us(path)); @@ -375,7 +375,7 @@ HRESULT CApp::CalculateCrc2(const UString &methodName) t.Enumerator.FilePaths.Add(us2fs(srcPanel.GetItemRelPath(indices[i]))); if (t.Enumerator.FilePaths.Size() == 1) - t.Hash.MainName = t.Enumerator.FilePaths[0]; + t.Hash.MainName = fs2us(t.Enumerator.FilePaths[0]); UString basePrefix = srcPanel.GetFsPath(); UString basePrefix2 = basePrefix; diff --git a/CPP/7zip/UI/FileManager/PanelOperations.cpp b/CPP/7zip/UI/FileManager/PanelOperations.cpp index 6c59ea38..e34e74f7 100644 --- a/CPP/7zip/UI/FileManager/PanelOperations.cpp +++ b/CPP/7zip/UI/FileManager/PanelOperations.cpp @@ -511,7 +511,7 @@ void CPanel::ChangeComment() LangString(IDS_COMMENT2, dlg.Static); if (dlg.Create(GetParent()) != IDOK) return; - NCOM::CPropVariant propVariant = dlg.Value.Ptr(); + NCOM::CPropVariant propVariant (dlg.Value); CDisableNotify disableNotify(*this); HRESULT result = _folderOperations->SetProperty(realIndex, kpidComment, &propVariant, NULL); diff --git a/CPP/7zip/UI/FileManager/ProgressDialog2a.rc b/CPP/7zip/UI/FileManager/ProgressDialog2a.rc index d2fee8cf..dc7d797f 100644 --- a/CPP/7zip/UI/FileManager/ProgressDialog2a.rc +++ b/CPP/7zip/UI/FileManager/ProgressDialog2a.rc @@ -65,7 +65,7 @@ CAPTION "Progress" RTEXT "", IDT_PROGRESS_ELAPSED_VAL, x1, y0, x1s, MY_TEXT_NOPREFIX RTEXT "", IDT_PROGRESS_REMAINING_VAL, x1, y1, x1s, MY_TEXT_NOPREFIX RTEXT "", IDT_PROGRESS_FILES_VAL, x1, y2, x1s, MY_TEXT_NOPREFIX - RTEXT "", IDT_PROGRESS_FILES_TOTAL x1, y3, x1s, MY_TEXT_NOPREFIX + RTEXT "", IDT_PROGRESS_FILES_TOTAL, x1, y3, x1s, MY_TEXT_NOPREFIX RTEXT "", IDT_PROGRESS_ERRORS_VAL, x1, y4, x1s, MY_TEXT_NOPREFIX RTEXT "", IDT_PROGRESS_TOTAL_VAL, x3, y0, x3s, MY_TEXT_NOPREFIX diff --git a/CPP/7zip/UI/FileManager/VerCtrl.cpp b/CPP/7zip/UI/FileManager/VerCtrl.cpp index 3eea3942..4bb034f8 100644 --- a/CPP/7zip/UI/FileManager/VerCtrl.cpp +++ b/CPP/7zip/UI/FileManager/VerCtrl.cpp @@ -389,11 +389,11 @@ void CApp::VerCtrl(unsigned id) dialog.OldFileInfo.SetTime(&fdi.Info.ftLastWriteTime); dialog.OldFileInfo.SetSize(fdi.GetSize()); - dialog.OldFileInfo.Name = path; + dialog.OldFileInfo.Name = fs2us(path); dialog.NewFileInfo.SetTime(&fdi2.Info.ftLastWriteTime); dialog.NewFileInfo.SetSize(fdi2.GetSize()); - dialog.NewFileInfo.Name = path2; + dialog.NewFileInfo.Name = fs2us(path2); dialog.ShowExtraButtons = false; dialog.DefaultButton_is_NO = true; diff --git a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp index 44d25035..71d28e8d 100644 --- a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp +++ b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp @@ -341,10 +341,10 @@ public: CBenchmarkDialog(): _timer(0), - TotalMode(false), WasStopped_in_GUI(false), ExitWasAsked_in_GUI(false), - NeedRestart(false) + NeedRestart(false), + TotalMode(false) {} ~CBenchmarkDialog(); diff --git a/CPP/7zip/UI/GUI/CompressDialog.cpp b/CPP/7zip/UI/GUI/CompressDialog.cpp index 0ede8292..16a35854 100644 --- a/CPP/7zip/UI/GUI/CompressDialog.cpp +++ b/CPP/7zip/UI/GUI/CompressDialog.cpp @@ -1436,7 +1436,7 @@ UString CCompressDialog::GetMethodSpec(UString &estimatedName) UString s; if (methodId >= 0) { - if (methodId < ARRAY_SIZE(kMethodsNames)) + if ((unsigned)methodId < ARRAY_SIZE(kMethodsNames)) estimatedName = kMethodsNames[methodId]; else estimatedName = ExternalMethods[methodId - ARRAY_SIZE(kMethodsNames)]; diff --git a/CPP/7zip/UI/GUI/UpdateGUI.cpp b/CPP/7zip/UI/GUI/UpdateGUI.cpp index 6fd1b60b..a3a1d889 100644 --- a/CPP/7zip/UI/GUI/UpdateGUI.cpp +++ b/CPP/7zip/UI/GUI/UpdateGUI.cpp @@ -112,9 +112,13 @@ static void ParseAndAddPropertires(CObjectVector<CProperty> &properties, SplitString(propertiesString, strings); FOR_VECTOR (i, strings) { - const UString &s = strings[i]; + UString s = strings[i]; + if (s.Len() > 2 + && s[0] == '-' + && MyCharLower_Ascii(s[1]) == 'm') + s.DeleteFrontal(2); CProperty property; - int index = s.Find(L'='); + const int index = s.Find(L'='); if (index < 0) property.Name = s; else |