From df64327cca1711f2a993d749c30c3508086723cc Mon Sep 17 00:00:00 2001 From: Alex Alabuzhev Date: Fri, 21 Jul 2017 18:29:41 +0000 Subject: [PATCH] fix 4989 --- far/changelog | 4 ++++ far/farwinapi.cpp | 10 ++++++++++ far/farwinapi.hpp | 4 ++++ far/filelist.cpp | 19 +++++++++++++------ far/filelist.hpp | 4 ++-- far/interf.cpp | 4 ++-- far/new_handler.cpp | 5 +++-- far/plugins.cpp | 13 +++++++++++-- far/plugins.hpp | 2 +- far/vbuild.m4 | 2 +- 10 files changed, 51 insertions(+), 16 deletions(-) diff --git a/far/changelog b/far/changelog index 62a7174a23..92bbf576de 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,7 @@ +drkns 21.07.2017 19:29:12 +0000 - build 4991 + +1. Уточнение 4989. + drkns 20.07.2017 23:10:16 +0000 - build 4990 1. Вернём защиту от нехваток памяти, добавленную в 1741 и потерянную в 3791. diff --git a/far/farwinapi.cpp b/far/farwinapi.cpp index d41e3c8657..6535f70d15 100644 --- a/far/farwinapi.cpp +++ b/far/farwinapi.cpp @@ -1861,6 +1861,16 @@ handle OpenCurrentThread() return os::handle(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &Handle, 0, FALSE, DUPLICATE_SAME_ACCESS) ? Handle : nullptr); } +handle OpenConsoleInputBuffer() +{ + return handle(CreateFile(L"CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr)); +} + +handle OpenConsoleActiveScreenBuffer() +{ + return handle(CreateFile(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr)); +} + namespace reg { key open_key(HKEY RootKey, const wchar_t* SubKey, DWORD SamDesired) diff --git a/far/farwinapi.hpp b/far/farwinapi.hpp index 318f802c98..7485f612d0 100644 --- a/far/farwinapi.hpp +++ b/far/farwinapi.hpp @@ -166,6 +166,10 @@ namespace os handle OpenCurrentThread(); + handle OpenConsoleInputBuffer(); + handle OpenConsoleActiveScreenBuffer(); + + namespace fs { using drives_set = std::bitset<26>; diff --git a/far/filelist.cpp b/far/filelist.cpp index 28c3478d17..d37a027839 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -2669,8 +2669,13 @@ void FileList::ProcessEnter(bool EnableExec,bool SeparateWindow,bool EnableAssoc { const auto IsItExecutable = IsExecutable(strFileName); - if (!IsItExecutable && !SeparateWindow && (OpenedPlugin = OpenFilePlugin(strFileName, TRUE, Type) != nullptr) != false) - return; + auto StopProcessing = false; + if (!IsItExecutable && !SeparateWindow) + { + OpenedPlugin = OpenFilePlugin(strFileName, TRUE, Type, &StopProcessing) != nullptr; + if (OpenedPlugin || StopProcessing) + return; + } if (IsItExecutable || SeparateWindow || Global->Opt->UseRegisteredTypes) { @@ -5092,7 +5097,7 @@ bool FileList::GetPrevDirectoriesFirst() const return (m_PanelMode == panel_mode::PLUGIN_PANEL && !PluginsList.empty())?PluginsList.front().m_PrevDirectoriesFirst:m_DirectoriesFirst; } -plugin_panel* FileList::OpenFilePlugin(const string& FileName, int PushPrev, OPENFILEPLUGINTYPE Type) +plugin_panel* FileList::OpenFilePlugin(const string& FileName, int PushPrev, OPENFILEPLUGINTYPE Type, bool* StopProcessing) { if (!PushPrev && m_PanelMode == panel_mode::PLUGIN_PANEL) { @@ -5100,6 +5105,8 @@ plugin_panel* FileList::OpenFilePlugin(const string& FileName, int PushPrev, OPE { if (ProcessPluginEvent(FE_CLOSE,nullptr)) { + if (StopProcessing) + *StopProcessing = true; return nullptr; } @@ -5108,7 +5115,7 @@ plugin_panel* FileList::OpenFilePlugin(const string& FileName, int PushPrev, OPE } } - auto hNewPlugin = OpenPluginForFile(FileName, 0, Type); + auto hNewPlugin = OpenPluginForFile(FileName, 0, Type, StopProcessing); auto hNewPluginRawCopy = hNewPlugin.get(); @@ -5673,14 +5680,14 @@ FileListItem::FileListItem(const PluginPanelItem& pi) } -std::unique_ptr FileList::OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type) +std::unique_ptr FileList::OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type, bool* StopProcessing) { if (FileName.empty() || FileAttr & FILE_ATTRIBUTE_DIRECTORY) return nullptr; SetCurPath(); Parent()->GetAnotherPanel(this)->CloseFile(); - return Global->CtrlObject->Plugins->OpenFilePlugin(&FileName, OPM_NONE, Type); + return Global->CtrlObject->Plugins->OpenFilePlugin(&FileName, OPM_NONE, Type, StopProcessing); } diff --git a/far/filelist.hpp b/far/filelist.hpp index e0493712f5..f241ef10e3 100644 --- a/far/filelist.hpp +++ b/far/filelist.hpp @@ -244,7 +244,7 @@ class FileList:public Panel const FileListItem* GetItem(size_t Index) const; const FileListItem* GetLastSelectedItem() const; - plugin_panel* OpenFilePlugin(const string& FileName, int PushPrev, OPENFILEPLUGINTYPE Type); + plugin_panel* OpenFilePlugin(const string& FileName, int PushPrev, OPENFILEPLUGINTYPE Type, bool* StopProcessing = nullptr); void ProcessHostFile(); bool GetPluginInfo(PluginInfo *PInfo) const; void PluginGetPanelInfo(PanelInfo &Info); @@ -329,7 +329,7 @@ class FileList:public Panel bool ApplyCommand(); void DescribeFiles(); std::vector CreatePluginItemList(bool AddTwoDot = true); - std::unique_ptr OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type); + std::unique_ptr OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type, bool* StopProcessing = nullptr); int PreparePanelView(PanelViewSettings *PanelView); int PrepareColumnWidths(std::vector& Columns, bool FullScreen, bool StatusLine); void PrepareViewSettings(int ViewMode); diff --git a/far/interf.cpp b/far/interf.cpp index 2f100b78cc..dbd9d51ccc 100644 --- a/far/interf.cpp +++ b/far/interf.cpp @@ -298,12 +298,12 @@ void InitConsole(int FirstInit) DWORD Mode; if(!Console().GetMode(Console().GetInputHandle(), Mode)) { - static const os::handle ConIn(CreateFile(L"CONIN$", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr)); + static const auto ConIn = os::OpenConsoleInputBuffer(); SetStdHandle(STD_INPUT_HANDLE, ConIn.native_handle()); } if(!Console().GetMode(Console().GetOutputHandle(), Mode)) { - static const os::handle ConOut(CreateFile(L"CONOUT$", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr)); + static const auto ConOut = os::OpenConsoleActiveScreenBuffer(); SetStdHandle(STD_OUTPUT_HANDLE, ConOut.native_handle()); SetStdHandle(STD_ERROR_HANDLE, ConOut.native_handle()); } diff --git a/far/new_handler.cpp b/far/new_handler.cpp index a7e7b5ba56..4d27375dbf 100644 --- a/far/new_handler.cpp +++ b/far/new_handler.cpp @@ -43,11 +43,12 @@ new_handler::new_handler(): if (!m_Screen) return; - SMALL_RECT WindowInfo{ 0, 0, 79, 24 }; + const COORD BufferSize{ 80, 25 }; + + const SMALL_RECT WindowInfo{ 0, 0, BufferSize.X - 1, BufferSize.Y - 1 }; if (!SetConsoleWindowInfo(m_Screen.native_handle(), true, &WindowInfo)) return; - const COORD BufferSize{ 80, 25 }; if (!SetConsoleScreenBufferSize(m_Screen.native_handle(), BufferSize)) return; diff --git a/far/plugins.cpp b/far/plugins.cpp index 5a2a614b38..25f7bd5e79 100644 --- a/far/plugins.cpp +++ b/far/plugins.cpp @@ -462,8 +462,11 @@ void PluginManager::LoadPluginsFromCache() } } -std::unique_ptr PluginManager::OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type) +std::unique_ptr PluginManager::OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type, bool* StopProcessingPtr) { + bool StopProcessing_Unused; + auto& StopProcessing = StopProcessingPtr? *StopProcessingPtr : StopProcessing_Unused; + SCOPED_ACTION(ChangePriority)(THREAD_PRIORITY_NORMAL); // We're conditionally messing with the title down there. @@ -550,6 +553,7 @@ std::unique_ptr PluginManager::OpenFilePlugin(const string* Name, const auto hPlugin = i->OpenFilePlugin(Name? Name->data() : nullptr, (BYTE*)Info.Buffer, Info.BufferSize, OpMode); if (hPlugin == PANEL_STOP) //сразу на выход, плагин решил нагло обработать все сам (Autorun/PictureView)!!! { + StopProcessing = true; break; } @@ -596,7 +600,11 @@ std::unique_ptr PluginManager::OpenFilePlugin(const string* Name, } const auto ExitCode = menu->Run(); - if (ExitCode >= 0) + if (ExitCode < 0) + { + StopProcessing = true; + } + else { pResult = std::next(items.begin(), ExitCode); } @@ -619,6 +627,7 @@ std::unique_ptr PluginManager::OpenFilePlugin(const string* Name, const auto h = pResult->first.plugin()->Open(&oInfo); if (h == PANEL_STOP) { + StopProcessing = true; pResult = items.end(); } else if (h) diff --git a/far/plugins.hpp b/far/plugins.hpp index 012057234b..907f1c3233 100644 --- a/far/plugins.hpp +++ b/far/plugins.hpp @@ -124,7 +124,7 @@ class PluginManager: noncopyable // API functions std::unique_ptr Open(Plugin *pPlugin,int OpenFrom,const GUID& Guid,intptr_t Item) const; - std::unique_ptr OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type); + std::unique_ptr OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type, bool* StopProcessing = nullptr); std::unique_ptr OpenFindListPlugin(const PluginPanelItem *PanelItem,size_t ItemsNumber); static void ClosePanel(std::unique_ptr&& hPlugin); static void GetOpenPanelInfo(const plugin_panel* hPlugin, OpenPanelInfo *Info); diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 61ce09666a..06060a2428 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,4990)m4_dnl +m4_define(BUILD,4991)m4_dnl