diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2017-04-30 03:00:00 +0300 |
---|---|---|
committer | Kornel <kornel@geekhood.net> | 2017-05-05 20:56:20 +0300 |
commit | 2efa10565ac395d2ce9a679ead46e70fb2f963eb (patch) | |
tree | 84c8df4deb69ec44ea15af9378f24347db55c357 /CPP/7zip/UI/FileManager/PanelItemOpen.cpp | |
parent | 603abd5528c97346e9448c0ff47949f818fe558c (diff) |
17.0017.00
Diffstat (limited to 'CPP/7zip/UI/FileManager/PanelItemOpen.cpp')
-rw-r--r-- | CPP/7zip/UI/FileManager/PanelItemOpen.cpp | 170 |
1 files changed, 130 insertions, 40 deletions
diff --git a/CPP/7zip/UI/FileManager/PanelItemOpen.cpp b/CPP/7zip/UI/FileManager/PanelItemOpen.cpp index cfbc5770..795e74b7 100644 --- a/CPP/7zip/UI/FileManager/PanelItemOpen.cpp +++ b/CPP/7zip/UI/FileManager/PanelItemOpen.cpp @@ -46,7 +46,7 @@ extern UInt64 g_RAM_Size; extern bool g_IsNT; #endif -static CFSTR kTempDirPrefix = FTEXT("7zO"); +#define kTempDirPrefix FTEXT("7zO") // #define SHOW_DEBUG_INFO @@ -534,23 +534,23 @@ HRESULT CPanel::OpenAsArc(IInStream *inStream, UString s2; if (!values[3].IsEmpty()) { - s2 = L"Can not open the file as [" + values[3] + L"] archive"; + s2 = "Can not open the file as [" + values[3] + "] archive"; if (level2 != 0) - s2 += L"\nThe file is open as [" + values[2] + L"] archive"; + s2 += "\nThe file is open as [" + values[2] + "] archive"; } if (!values[0].IsEmpty()) { if (!s2.IsEmpty()) s2.Add_LF(); - s2 += L"["; + s2 += "["; s2 += values[2]; - s2 += L"] Error: "; + s2 += "] Error: "; s2 += values[0]; } if (!s2.IsEmpty()) { if (!s.IsEmpty()) - s += L"--------------------\n"; + s += "--------------------\n"; s += values[1]; s.Add_LF(); s += s2; @@ -587,7 +587,7 @@ HRESULT CPanel::OpenAsArc_Msg(IInStream *inStream, if (showErrorMessage && encrypted) { - UString message = L"Error"; + UString message("Error"); if (res == S_FALSE) { message = MyFormatNew( @@ -663,11 +663,15 @@ HRESULT CPanel::OpenParentArchiveFolder() } -static const char *kStartExtensions = +static const char * const kExeExtensions = + " exe bat ps1 com" + " "; + +static const char * const kStartExtensions = #ifdef UNDER_CE " cab" #endif - " exe bat com" + " exe bat ps1 com" " chm" " msi doc xls ppt pps wps wpt wks xlr wdb vsd pub" @@ -718,6 +722,51 @@ static bool DoItemAlwaysStart(const UString &name) UString GetQuotedString(const UString &s); + +void SplitCmdLineSmart(const UString &cmd, UString &prg, UString ¶ms) +{ + params.Empty(); + prg = cmd; + prg.Trim(); + if (prg.Len() >= 2 && prg[0] == L'"') + { + int pos = prg.Find(L'"', 1); + if (pos >= 0) + { + if ((unsigned)pos + 1 == prg.Len() || prg[pos + 1] == ' ') + { + params = prg.Ptr(pos + 1); + params.Trim(); + prg.DeleteFrom(pos); + prg.DeleteFrontal(1); + } + } + } +} + + +static WRes StartAppWithParams(const UString &cmd, const UStringVector ¶mVector, CProcess &process) +{ + UString param; + UString prg; + + SplitCmdLineSmart(cmd, prg, param); + + param.Trim(); + + // int pos = params.Find(L"%1"); + + FOR_VECTOR (i, paramVector) + { + if (!param.IsEmpty() && param.Back() != ' ') + param.Add_Space(); + param += GetQuotedString(paramVector[i]); + } + + return process.Create(prg, param, NULL); +} + + static HRESULT StartEditApplication(const UString &path, bool useEditor, HWND window, CProcess &process) { UString command; @@ -725,7 +774,7 @@ static HRESULT StartEditApplication(const UString &path, bool useEditor, HWND wi if (command.IsEmpty()) { #ifdef UNDER_CE - command = L"\\Windows\\"; + command = "\\Windows\\"; #else FString winDir; if (!GetWindowsDir(winDir)) @@ -733,15 +782,19 @@ static HRESULT StartEditApplication(const UString &path, bool useEditor, HWND wi NName::NormalizeDirPathPrefix(winDir); command = fs2us(winDir); #endif - command += L"notepad.exe"; + command += "notepad.exe"; } - HRESULT res = process.Create(command, GetQuotedString(path), NULL); + UStringVector params; + params.Add(path); + + HRESULT res = StartAppWithParams(command, params, process); if (res != SZ_OK) ::MessageBoxW(window, LangString(IDS_CANNOT_START_EDITOR), L"7-Zip", MB_OK | MB_ICONSTOP); return res; } + void CApp::DiffFiles() { const CPanel &panel = GetFocusedPanel(); @@ -779,16 +832,21 @@ void CApp::DiffFiles() if (command.IsEmpty()) return; - UString param = GetQuotedString(path1); - param.Add_Space(); - param += GetQuotedString(path2); + UStringVector params; + params.Add(path1); + params.Add(path2); - HRESULT res = MyCreateProcess(command, param); + HRESULT res; + { + CProcess process; + res = StartAppWithParams(command, params, process); + } if (res == SZ_OK) return; ::MessageBoxW(_window, LangString(IDS_CANNOT_START_EDITOR), L"7-Zip", MB_OK | MB_ICONSTOP); } + #ifndef _UNICODE typedef BOOL (WINAPI * ShellExecuteExWP)(LPSHELLEXECUTEINFOW lpExecInfo); #endif @@ -802,7 +860,7 @@ static HRESULT StartApplication(const UString &dir, const UString &path, HWND wi int dot = path2.ReverseFind_Dot(); int separ = path2.ReverseFind_PathSepar(); if (dot < 0 || dot < separ) - path2 += L'.'; + path2 += '.'; } #endif @@ -841,8 +899,8 @@ static HRESULT StartApplication(const UString &dir, const UString &path, HWND wi ; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; - const CSysString sysPath = GetSystemString(path2); - const CSysString sysDir = GetSystemString(dir); + const CSysString sysPath (GetSystemString(path2)); + const CSysString sysDir (GetSystemString(dir)); execInfo.lpFile = sysPath; execInfo.lpParameters = NULL; execInfo.lpDirectory = @@ -896,27 +954,36 @@ void CPanel::EditItem(int index, bool useEditor) StartEditApplication(GetItemFullPath(index), useEditor, (HWND)*this, process); } + void CPanel::OpenFolderExternal(int index) { - UString fsPrefix = GetFsPath(); - UString name; + UString prefix = GetFsPath(); + UString path = prefix; + if (index == kParentIndex) { - int pos = fsPrefix.ReverseFind_PathSepar(); - if (pos >= 0 && pos == (int)fsPrefix.Len() - 1) - { - UString s = fsPrefix.Left(pos); - pos = s.ReverseFind_PathSepar(); - if (pos >= 0) - fsPrefix.SetFrom(s, pos + 1); - } - name = fsPrefix; + if (prefix.IsEmpty()) + return; + const wchar_t c = prefix.Back(); + if (!IS_PATH_SEPAR(c) && c != ':') + return; + prefix.DeleteBack(); + int pos = prefix.ReverseFind_PathSepar(); + if (pos < 0) + return; + prefix.DeleteFrom(pos + 1); + path = prefix; } else - name = fsPrefix + GetItemRelPath(index) + WCHAR_PATH_SEPARATOR; - StartApplicationDontWait(fsPrefix, name, (HWND)*this); + { + path += GetItemRelPath(index); + path.Add_PathSepar(); + } + + StartApplicationDontWait(prefix, path, (HWND)*this); } + bool CPanel::IsVirus_Message(const UString &name) { UString name2; @@ -928,12 +995,12 @@ bool CPanel::IsVirus_Message(const UString &name) if (name2.Find(cRLO) >= 0) { - UString badString = cRLO; + const UString badString(cRLO); name2.Replace(badString, L"[RLO]"); isVirus = true; } { - const wchar_t *kVirusSpaces = L" "; + const wchar_t * const kVirusSpaces = L" "; // const unsigned kNumSpaces = strlen(kVirusSpaces); for (;;) { @@ -945,6 +1012,27 @@ bool CPanel::IsVirus_Message(const UString &name) name2.Replace(kVirusSpaces, L" "); } } + + #ifdef _WIN32 + { + unsigned i; + for (i = name2.Len(); i != 0;) + { + wchar_t c = name2[i - 1]; + if (c != '.' && c != ' ') + break; + i--; + name2.ReplaceOneCharAtPos(i, '_'); + } + if (i != name2.Len()) + { + UString name3 = name2; + name3.DeleteFrom(i); + if (FindExt(kExeExtensions, name3)) + isVirus = true; + } + } + #endif if (!isVirus) return false; @@ -983,8 +1071,9 @@ void CPanel::OpenItem(int index, bool tryInternal, bool tryExternal, const wchar CDisableTimerProcessing disableTimerProcessing(*this); UString name = GetItemRelPath2(index); - if (IsVirus_Message(name)) - return; + if (tryExternal) + if (IsVirus_Message(name)) + return; if (!_parentFolders.IsEmpty()) { @@ -1330,7 +1419,7 @@ static THREAD_FUNC_DECL MyThreadFunction(void *param) #if defined(_WIN32) && !defined(UNDER_CE) -static const FChar *k_ZoneId_StreamName = FTEXT(":Zone.Identifier"); +static const FChar * const k_ZoneId_StreamName = FTEXT(":Zone.Identifier"); #endif @@ -1443,7 +1532,7 @@ HRESULT CBufSeqOutStream_WithFile::FlushToFile() { outFileStream.Release(); return E_FAIL; - // MessageBoxMyError(UString(L"Can't create file ") + fs2us(tempFilePath)); + // MessageBoxMyError(UString("Can't create file ") + fs2us(tempFilePath)); } } while (_fileWritePos != _pos) @@ -1494,8 +1583,9 @@ void CPanel::OpenItemInArchive(int index, bool tryInternal, bool tryExternal, bo const UString name = GetItemName(index); const UString relPath = GetItemRelPath(index); - if (IsVirus_Message(name)) - return; + if (tryExternal) + if (IsVirus_Message(name)) + return; if (!_folderOperations) { |