Skip to content

Commit

Permalink
fix 4989
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 21, 2017
1 parent 7687c39 commit df64327
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 16 deletions.
4 changes: 4 additions & 0 deletions 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.
Expand Down
10 changes: 10 additions & 0 deletions far/farwinapi.cpp
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions far/farwinapi.hpp
Expand Up @@ -166,6 +166,10 @@ namespace os

handle OpenCurrentThread();

handle OpenConsoleInputBuffer();
handle OpenConsoleActiveScreenBuffer();


namespace fs
{
using drives_set = std::bitset<26>;
Expand Down
19 changes: 13 additions & 6 deletions far/filelist.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -5092,14 +5097,16 @@ 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)
{
for (;;)
{
if (ProcessPluginEvent(FE_CLOSE,nullptr))
{
if (StopProcessing)
*StopProcessing = true;
return nullptr;
}

Expand All @@ -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();

Expand Down Expand Up @@ -5673,14 +5680,14 @@ FileListItem::FileListItem(const PluginPanelItem& pi)
}


std::unique_ptr<plugin_panel> FileList::OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type)
std::unique_ptr<plugin_panel> 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);
}


Expand Down
4 changes: 2 additions & 2 deletions far/filelist.hpp
Expand Up @@ -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);
Expand Down Expand Up @@ -329,7 +329,7 @@ class FileList:public Panel
bool ApplyCommand();
void DescribeFiles();
std::vector<PluginPanelItem> CreatePluginItemList(bool AddTwoDot = true);
std::unique_ptr<plugin_panel> OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type);
std::unique_ptr<plugin_panel> OpenPluginForFile(const string& FileName, DWORD FileAttr, OPENFILEPLUGINTYPE Type, bool* StopProcessing = nullptr);
int PreparePanelView(PanelViewSettings *PanelView);
int PrepareColumnWidths(std::vector<column>& Columns, bool FullScreen, bool StatusLine);
void PrepareViewSettings(int ViewMode);
Expand Down
4 changes: 2 additions & 2 deletions far/interf.cpp
Expand Up @@ -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());
}
Expand Down
5 changes: 3 additions & 2 deletions far/new_handler.cpp
Expand Up @@ -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;

Expand Down
13 changes: 11 additions & 2 deletions far/plugins.cpp
Expand Up @@ -462,8 +462,11 @@ void PluginManager::LoadPluginsFromCache()
}
}

std::unique_ptr<plugin_panel> PluginManager::OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type)
std::unique_ptr<plugin_panel> 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.
Expand Down Expand Up @@ -550,6 +553,7 @@ std::unique_ptr<plugin_panel> 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;
}

Expand Down Expand Up @@ -596,7 +600,11 @@ std::unique_ptr<plugin_panel> 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);
}
Expand All @@ -619,6 +627,7 @@ std::unique_ptr<plugin_panel> 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)
Expand Down
2 changes: 1 addition & 1 deletion far/plugins.hpp
Expand Up @@ -124,7 +124,7 @@ class PluginManager: noncopyable

// API functions
std::unique_ptr<plugin_panel> Open(Plugin *pPlugin,int OpenFrom,const GUID& Guid,intptr_t Item) const;
std::unique_ptr<plugin_panel> OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type);
std::unique_ptr<plugin_panel> OpenFilePlugin(const string* Name, OPERATION_MODES OpMode, OPENFILEPLUGINTYPE Type, bool* StopProcessing = nullptr);
std::unique_ptr<plugin_panel> OpenFindListPlugin(const PluginPanelItem *PanelItem,size_t ItemsNumber);
static void ClosePanel(std::unique_ptr<plugin_panel>&& hPlugin);
static void GetOpenPanelInfo(const plugin_panel* hPlugin, OpenPanelInfo *Info);
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4990)m4_dnl
m4_define(BUILD,4991)m4_dnl

0 comments on commit df64327

Please sign in to comment.