From 8fcd19e09f82c2c79f63e21fd78b73344ffc77c4 Mon Sep 17 00:00:00 2001 From: Pavel Yosifovich Date: Sun, 18 Dec 2022 19:15:49 -0500 Subject: [PATCH] remove unneeded code --- WFPCore/WFPEngine.cpp | 51 -------------------------------------- WFPCore/WFPEngine.h | 6 ----- WFPExplorer/LayersView.cpp | 27 +++++++++++++++++--- WFPExplorer/LayersView.h | 4 +++ WFPExplorer/WFPExplorer.rc | 6 +++++ 5 files changed, 34 insertions(+), 60 deletions(-) diff --git a/WFPCore/WFPEngine.cpp b/WFPCore/WFPEngine.cpp index 27453e8..90a67bb 100644 --- a/WFPCore/WFPEngine.cpp +++ b/WFPCore/WFPEngine.cpp @@ -80,57 +80,6 @@ WFPObject WFPEngine::GetSublayerByKey(GUID const& key) const { return WFPObject(sublayer); } -WFPProviderContextInfo WFPEngine::InitProviderContext(FWPM_PROVIDER_CONTEXT* p, bool includeData) { - WFPProviderContextInfo pi; - pi.Name = ParseMUIString(p->displayData.name); - pi.Desc = ParseMUIString(p->displayData.description); - pi.ProviderContextKey = p->providerContextKey; - pi.ProviderContextId = p->providerContextId; - pi.Flags = static_cast(p->flags); - pi.ProviderDataSize = p->providerData.size; - pi.ProviderKey = p->providerKey ? *p->providerKey : GUID_NULL; - pi.Type = static_cast(p->type); - if (includeData) { - pi.ProviderData.resize(p->providerData.size); - memcpy(pi.ProviderData.data(), p->providerData.data, p->providerData.size); - } - return pi; -} - -std::wstring WFPEngine::ParseMUIString(PCWSTR input) { - if (input == nullptr) - return L""; - - if (*input && input[0] == L'@') { - WCHAR result[256]; - if (::SHLoadIndirectString(input, result, _countof(result), nullptr) == S_OK) - return result; - } - return input; -} - -std::vector WFPEngine::EnumProviderContexts(bool includeData) const { - HANDLE hEnum; - std::vector info; - m_LastError = FwpmProviderContextCreateEnumHandle(m_hEngine, nullptr, &hEnum); - if (m_LastError) - return info; - FWPM_PROVIDER_CONTEXT** contexts; - UINT32 count; - m_LastError = FwpmProviderContextEnum(m_hEngine, hEnum, 128, &contexts, &count); - if (m_LastError == ERROR_SUCCESS && count > 0) { - info.reserve(count); - for (UINT32 i = 0; i < count; i++) { - auto p = contexts[i]; - info.emplace_back(std::move(InitProviderContext(p, includeData))); - } - FwpmFreeMemory((void**)&contexts); - } - m_LastError = FwpmProviderContextDestroyEnumHandle(m_hEngine, hEnum); - - return info; -} - WFPObject WFPEngine::GetCalloutByKey(GUID const& key) const { FWPM_CALLOUT* co = nullptr; FwpmCalloutGetByKey(m_hEngine, &key, &co); diff --git a/WFPCore/WFPEngine.h b/WFPCore/WFPEngine.h index 59353e2..107ac77 100644 --- a/WFPCore/WFPEngine.h +++ b/WFPCore/WFPEngine.h @@ -73,8 +73,6 @@ public: uint32_t GetFilterCount(GUID const& layer = GUID_NULL) const; uint32_t GetCalloutCount(GUID const& layer = GUID_NULL) const; - std::vector EnumProviderContexts(bool includeData = false) const; - // // providers API // @@ -104,10 +102,6 @@ public: WFPObject GetCalloutById(UINT32 id) const; private: - // - // helpers - // - static std::wstring ParseMUIString(PCWSTR input); static WFPProviderContextInfo InitProviderContext(FWPM_PROVIDER_CONTEXT* p, bool full = false); HANDLE m_hEngine{ nullptr }; diff --git a/WFPExplorer/LayersView.cpp b/WFPExplorer/LayersView.cpp index c19957d..0c52918 100644 --- a/WFPExplorer/LayersView.cpp +++ b/WFPExplorer/LayersView.cpp @@ -5,6 +5,8 @@ #include "WFPHelper.h" #include "LayerGeneralPage.h" #include +#include +#include CLayersView::CLayersView(IMainFrame* frame, WFPEngine& engine) : CFrameView(frame), m_Engine(engine) { } @@ -146,8 +148,8 @@ void CLayersView::OnStateChanged(HWND, int from, int to, UINT oldState, UINT new UpdateUI(); } -bool CLayersView::OnDoubleClickList(HWND, int row, int col, POINT const& pt) { - LRESULT result; +bool CLayersView::OnDoubleClickList(HWND, int, int, POINT const&) { + LRESULT result = 0; return ProcessWindowMessage(m_hWnd, WM_COMMAND, ID_EDIT_PROPERTIES, 0, result, 1); } @@ -157,8 +159,27 @@ CString const& CLayersView::LayerInfo::Name() const { return m_Name; } -CString const& CLayersView::LayerInfo::Desc() const { +CString const& CLayersView::LayerInfo::Desc() const { if (m_Desc.IsEmpty()) m_Desc = StringHelper::ParseMUIString(Data->displayData.description); return m_Desc; } + +LRESULT CLayersView::OnSave(WORD, WORD, HWND, BOOL&) { + CSimpleFileDialog dlg(FALSE, L"csv", L"layers.csv", OFN_EXPLORER | OFN_ENABLESIZING | OFN_OVERWRITEPROMPT, + L"CSV Files (*.csv)\0*.csv\0Text Files (*.txt)\0*.txt\0All Files\0*.*\0", m_hWnd); + ThemeHelper::Suspend(); + auto ok = IDOK == dlg.DoModal(); + ThemeHelper::Resume(); + if (ok && !ListViewHelper::SaveAll(dlg.m_szFileName, m_List, L",")) { + AtlMessageBox(m_hWnd, L"Error in opening file", IDS_TITLE, MB_ICONERROR); + } + return 0; +} + +LRESULT CLayersView::OnCopy(WORD, WORD, HWND, BOOL&) { + auto text = ListViewHelper::GetSelectedRowsAsString(m_List, L","); + ClipboardHelper::CopyText(m_hWnd, text); + + return 0; +} diff --git a/WFPExplorer/LayersView.h b/WFPExplorer/LayersView.h index 53e2a48..5886635 100644 --- a/WFPExplorer/LayersView.h +++ b/WFPExplorer/LayersView.h @@ -32,6 +32,8 @@ public: ALT_MSG_MAP(1) COMMAND_ID_HANDLER(ID_EDIT_PROPERTIES, OnProperties) COMMAND_ID_HANDLER(ID_VIEW_REFRESH, OnRefresh) + COMMAND_ID_HANDLER(ID_EDIT_COPY, OnCopy) + COMMAND_ID_HANDLER(ID_FILE_SAVE, OnSave) END_MSG_MAP() // Handler prototypes (uncomment arguments if needed): @@ -64,6 +66,8 @@ private: LRESULT OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); LRESULT OnRefresh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnProperties(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnSave(WORD, WORD, HWND, BOOL&); + LRESULT OnCopy(WORD, WORD, HWND, BOOL&); WFPEngine& m_Engine; diff --git a/WFPExplorer/WFPExplorer.rc b/WFPExplorer/WFPExplorer.rc index c297c19..9258b43 100644 --- a/WFPExplorer/WFPExplorer.rc +++ b/WFPExplorer/WFPExplorer.rc @@ -120,6 +120,12 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Properties...\tAlt+Enter", ID_EDIT_PROPERTIES END + POPUP "layer" + BEGIN + MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY + MENUITEM SEPARATOR + MENUITEM "Properties...\tAlt+Enter", ID_EDIT_PROPERTIES + END END