From 0e65d7ddea8de1f3a63a03f7a935412bea401732 Mon Sep 17 00:00:00 2001 From: Aleksoid Date: Fri, 16 Feb 2024 13:35:49 +1000 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D0=B5=D0=BC=20=D0=B2=D0=B5=D0=B7=D0=B4=D0=B5=20unique=5F?= =?UTF-8?q?ptr=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20?= =?UTF-8?q?=D1=81=D1=8B=D1=80=D1=8B=D1=85=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/mplayerc/FakeFilterMapper2.cpp | 75 +++++++--------- src/apps/mplayerc/FakeFilterMapper2.h | 10 ++- src/apps/mplayerc/MainFrm.cpp | 29 +++--- src/apps/mplayerc/PPageExternalFilters.cpp | 100 +++++++++------------ src/apps/mplayerc/RegFilterChooserDlg.cpp | 11 +-- src/apps/mplayerc/RegFilterChooserDlg.h | 9 +- 6 files changed, 98 insertions(+), 136 deletions(-) diff --git a/src/apps/mplayerc/FakeFilterMapper2.cpp b/src/apps/mplayerc/FakeFilterMapper2.cpp index 3529ed0ffd..46f1805eba 100644 --- a/src/apps/mplayerc/FakeFilterMapper2.cpp +++ b/src/apps/mplayerc/FakeFilterMapper2.cpp @@ -1,6 +1,6 @@ /* * (C) 2003-2006 Gabest - * (C) 2006-2023 see Authors.txt + * (C) 2006-2024 see Authors.txt * * This file is part of MPC-BE. * @@ -577,13 +577,6 @@ CFilterMapper2::CFilterMapper2(bool fRefCounted, bool fAllowUnreg, LPUNKNOWN pUn } } -CFilterMapper2::~CFilterMapper2() -{ - for (const auto& filter : m_filters) { - delete filter; - } -} - STDMETHODIMP CFilterMapper2::NonDelegatingQueryInterface(REFIID riid, void** ppv) { if (riid == __uuidof(IFilterMapper2)) { @@ -645,48 +638,44 @@ STDMETHODIMP CFilterMapper2::UnregisterFilter(const CLSID* pclsidCategory, const STDMETHODIMP CFilterMapper2::RegisterFilter(REFCLSID clsidFilter, LPCWSTR Name, IMoniker** ppMoniker, const CLSID* pclsidCategory, const OLECHAR* szInstance, const REGFILTER2* prf2) { if (!m_path.IsEmpty()) { - if (FilterOverride* f = DNew FilterOverride) { - f->fDisabled = false; - f->type = FilterOverride::EXTERNAL; - f->path = m_path; - f->name = CStringW(Name); - f->clsid = clsidFilter; - f->iLoadType = FilterOverride::MERIT; - f->dwMerit = prf2->dwMerit; - - if (prf2->dwVersion == 1) { - for (ULONG i = 0; i < prf2->cPins; i++) { - const REGFILTERPINS& rgPin = prf2->rgPins[i]; - if (rgPin.bOutput) { - continue; - } + auto& f = m_filters.emplace_back(DNew FilterOverride); + f->type = FilterOverride::EXTERNAL; + f->path = m_path; + f->name = Name; + f->clsid = clsidFilter; + f->dwMerit = prf2->dwMerit; + f->iLoadType = FilterOverride::MERIT; + + if (prf2->dwVersion == 1) { + for (ULONG i = 0; i < prf2->cPins; i++) { + const REGFILTERPINS& rgPin = prf2->rgPins[i]; + if (rgPin.bOutput) { + continue; + } - for (UINT j = 0; j < rgPin.nMediaTypes; j++) { - if (!rgPin.lpMediaType[j].clsMajorType || !rgPin.lpMediaType[j].clsMinorType) { - break; - } - f->guids.emplace_back(*rgPin.lpMediaType[j].clsMajorType); - f->guids.emplace_back(*rgPin.lpMediaType[j].clsMinorType); + for (UINT j = 0; j < rgPin.nMediaTypes; j++) { + if (!rgPin.lpMediaType[j].clsMajorType || !rgPin.lpMediaType[j].clsMinorType) { + break; } + f->guids.emplace_back(*rgPin.lpMediaType[j].clsMajorType); + f->guids.emplace_back(*rgPin.lpMediaType[j].clsMinorType); + } + } + } else if (prf2->dwVersion == 2) { + for (ULONG i = 0; i < prf2->cPins2; i++) { + const REGFILTERPINS2& rgPin = prf2->rgPins2[i]; + if (rgPin.dwFlags®_PINFLAG_B_OUTPUT) { + continue; } - } else if (prf2->dwVersion == 2) { - for (ULONG i = 0; i < prf2->cPins2; i++) { - const REGFILTERPINS2& rgPin = prf2->rgPins2[i]; - if (rgPin.dwFlags®_PINFLAG_B_OUTPUT) { - continue; - } - for (UINT j = 0; j < rgPin.nMediaTypes; j++) { - if (!rgPin.lpMediaType[j].clsMajorType || !rgPin.lpMediaType[j].clsMinorType) { - break; - } - f->guids.emplace_back(*rgPin.lpMediaType[j].clsMajorType); - f->guids.emplace_back(*rgPin.lpMediaType[j].clsMinorType); + for (UINT j = 0; j < rgPin.nMediaTypes; j++) { + if (!rgPin.lpMediaType[j].clsMajorType || !rgPin.lpMediaType[j].clsMinorType) { + break; } + f->guids.emplace_back(*rgPin.lpMediaType[j].clsMajorType); + f->guids.emplace_back(*rgPin.lpMediaType[j].clsMinorType); } } - - m_filters.emplace_back(f); } return S_OK; diff --git a/src/apps/mplayerc/FakeFilterMapper2.h b/src/apps/mplayerc/FakeFilterMapper2.h index cefd47f74d..31567a527f 100644 --- a/src/apps/mplayerc/FakeFilterMapper2.h +++ b/src/apps/mplayerc/FakeFilterMapper2.h @@ -1,6 +1,6 @@ /* * (C) 2003-2006 Gabest - * (C) 2006-2023 see Authors.txt + * (C) 2006-2024 see Authors.txt * * This file is part of MPC-BE. * @@ -21,6 +21,8 @@ #pragma once +#include + class FilterOverride { public: @@ -38,7 +40,7 @@ class FilterOverride int iLoadType = 0; DWORD dwMerit = 0; - FilterOverride() {} + FilterOverride() = default; FilterOverride(FilterOverride* f) : fDisabled (f->fDisabled) , fTemporary(f->fTemporary) @@ -111,7 +113,7 @@ class CFilterMapper2 : protected CUnknown, public IFilterMapper2 public: CFilterMapper2(bool fRefCounted, bool fAllowUnreg = false, LPUNKNOWN pUnkOuter = nullptr); - virtual ~CFilterMapper2(); + virtual ~CFilterMapper2() = default; void SetInner(IUnknown* pUnk) { m_pFM2 = pUnk; @@ -120,6 +122,6 @@ class CFilterMapper2 : protected CUnknown, public IFilterMapper2 static void Init(); static IFilterMapper2* m_pFilterMapper2; - std::list m_filters; + std::list> m_filters; void Register(CString path); }; diff --git a/src/apps/mplayerc/MainFrm.cpp b/src/apps/mplayerc/MainFrm.cpp index 8ffc4275a7..31d2950bec 100644 --- a/src/apps/mplayerc/MainFrm.cpp +++ b/src/apps/mplayerc/MainFrm.cpp @@ -5459,27 +5459,20 @@ LRESULT CMainFrame::HandleCmdLine(WPARAM wParam, LPARAM lParam) CFilterMapper2 fm2(false); fm2.Register(path + fd.cFileName); - while (!fm2.m_filters.empty()) { - FilterOverride* f = fm2.m_filters.back(); - fm2.m_filters.pop_back(); - - if (f) { - f->fTemporary = true; - bool bFound = false; - - for (auto& f2 : s.m_ExternalFilters) { - if (f2->type == FilterOverride::EXTERNAL && !f2->path.CompareNoCase(f->path)) { - bFound = true; - delete f; - break; - } - } + for (auto& f : fm2.m_filters) { + f->fTemporary = true; + bool bFound = false; - if (!bFound) { - std::unique_ptr p(f); - s.m_ExternalFilters.emplace_front(std::move(p)); + for (auto& f2 : s.m_ExternalFilters) { + if (f2->type == FilterOverride::EXTERNAL && !f2->path.CompareNoCase(f->path)) { + bFound = true; + break; } } + + if (!bFound) { + s.m_ExternalFilters.emplace_front(std::move(f)); + } } } while (FindNextFileW(hFind, &fd)); diff --git a/src/apps/mplayerc/PPageExternalFilters.cpp b/src/apps/mplayerc/PPageExternalFilters.cpp index 306470353d..cc76102931 100644 --- a/src/apps/mplayerc/PPageExternalFilters.cpp +++ b/src/apps/mplayerc/PPageExternalFilters.cpp @@ -377,45 +377,38 @@ void CPPageExternalFilters::OnAddRegistered() { CRegFilterChooserDlg dlg(this); if (dlg.DoModal() == IDOK) { - while (!dlg.m_filters.empty()) { - FilterOverride* f = dlg.m_filters.front(); - dlg.m_filters.pop_front(); - - if (f) { - std::unique_ptr p(f); - - if (f->name.IsEmpty() && !f->guids.size() && !f->dwMerit) { - // skip something strange - continue; - } - else if (IsSupportedExternalVideoRenderer(f->clsid)) { - // supported external video renderers that must be selected in the "Video" settings - CStringW strMessage; - strMessage.Format(ResStr(IDS_BLOCK_EXTERNAL_VR), f->name); - AfxMessageBox(strMessage, MB_OK); - continue; - } + for (auto& f : dlg.m_filters) { + if (f->name.IsEmpty() && !f->guids.size() && !f->dwMerit) { + // skip something strange + continue; + } + else if (IsSupportedExternalVideoRenderer(f->clsid)) { + // supported external video renderers that must be selected in the "Video" settings + CStringW strMessage; + strMessage.Format(ResStr(IDS_BLOCK_EXTERNAL_VR), f->name); + AfxMessageBox(strMessage, MB_OK); + continue; + } - CString name = f->name; + CString name = f->name; - if (f->type == FilterOverride::EXTERNAL) { - if (!CPath(MakeFullPath(f->path)).FileExists()) { - name += L" "; - } + if (f->type == FilterOverride::EXTERNAL) { + if (!CPath(MakeFullPath(f->path)).FileExists()) { + name += L" "; } + } - int i = m_filters.AddString(name); - m_ExtFilters.emplace_back(std::move(p)); - m_filters.SetItemDataPtr(i, m_ExtFilters.back().get()); - m_filters.SetCheck(i, BST_CHECKED); + int i = m_filters.AddString(name); + auto& p = m_ExtFilters.emplace_back(std::move(f)); + m_filters.SetItemDataPtr(i, p.get()); + m_filters.SetCheck(i, BST_CHECKED); - if (dlg.m_filters.empty()) { - m_filters.SetCurSel(i); - OnLbnSelchangeList1(); - } - - SetModified(); + if (dlg.m_filters.empty()) { + m_filters.SetCurSel(i); + OnLbnSelchangeList1(); } + + SetModified(); } } } @@ -780,33 +773,26 @@ void CPPageExternalFilters::OnDropFiles(HDROP hDropInfo) CFilterMapper2 fm2(false); fm2.Register(szFileName); - while (!fm2.m_filters.empty()) { - FilterOverride* f = fm2.m_filters.front(); - fm2.m_filters.pop_front(); - - if (f) { - std::unique_ptr p(f); - - if (IsSupportedExternalVideoRenderer(f->clsid)) { - // supported external video renderers that must be selected in the "Video" settings - CStringW strMessage; - strMessage.Format(ResStr(IDS_BLOCK_EXTERNAL_VR), f->name); - AfxMessageBox(strMessage, MB_OK); - continue; - } - - int i = m_filters.AddString(f->name); - m_ExtFilters.emplace_back(std::move(p)); - m_filters.SetItemDataPtr(i, m_ExtFilters.back().get()); - m_filters.SetCheck(i, BST_CHECKED); + for (auto& f : fm2.m_filters) { + if (IsSupportedExternalVideoRenderer(f->clsid)) { + // supported external video renderers that must be selected in the "Video" settings + CStringW strMessage; + strMessage.Format(ResStr(IDS_BLOCK_EXTERNAL_VR), f->name); + AfxMessageBox(strMessage, MB_OK); + continue; + } - if (fm2.m_filters.empty()) { - m_filters.SetCurSel(i); - OnLbnSelchangeList1(); - } + int i = m_filters.AddString(f->name); + auto& p = m_ExtFilters.emplace_back(std::move(f)); + m_filters.SetItemDataPtr(i, p.get()); + m_filters.SetCheck(i, BST_CHECKED); - SetModified(); + if (fm2.m_filters.empty()) { + m_filters.SetCurSel(i); + OnLbnSelchangeList1(); } + + SetModified(); } } ::DragFinish(hDropInfo); diff --git a/src/apps/mplayerc/RegFilterChooserDlg.cpp b/src/apps/mplayerc/RegFilterChooserDlg.cpp index b71c16f45d..e1a1c67cea 100644 --- a/src/apps/mplayerc/RegFilterChooserDlg.cpp +++ b/src/apps/mplayerc/RegFilterChooserDlg.cpp @@ -34,13 +34,6 @@ CRegFilterChooserDlg::CRegFilterChooserDlg(CWnd* pParent) { } -CRegFilterChooserDlg::~CRegFilterChooserDlg() -{ - for (auto& filter : m_filters) { - delete filter; - } -} - void CRegFilterChooserDlg::DoDataExchange(CDataExchange* pDX) { __super::DoDataExchange(pDX); @@ -133,8 +126,7 @@ void CRegFilterChooserDlg::OnBnClickedOk() } if (pMoniker) { CFGFilterRegistry fgf(pMoniker); - FilterOverride* f = DNew FilterOverride; - f->fDisabled = false; + auto& f = m_filters.emplace_back(DNew FilterOverride); f->type = FilterOverride::REGISTERED; f->name = fgf.GetName(); f->dispname = fgf.GetDisplayName(); @@ -142,7 +134,6 @@ void CRegFilterChooserDlg::OnBnClickedOk() f->guids = fgf.GetTypes(); f->dwMerit = fgf.GetMeritForDirectShow(); f->iLoadType = FilterOverride::MERIT; - m_filters.emplace_back(f); } __super::OnOK(); diff --git a/src/apps/mplayerc/RegFilterChooserDlg.h b/src/apps/mplayerc/RegFilterChooserDlg.h index f58491d102..27c01907f1 100644 --- a/src/apps/mplayerc/RegFilterChooserDlg.h +++ b/src/apps/mplayerc/RegFilterChooserDlg.h @@ -1,6 +1,6 @@ /* * (C) 2003-2006 Gabest - * (C) 2006-2023 see Authors.txt + * (C) 2006-2024 see Authors.txt * * This file is part of MPC-BE. * @@ -22,6 +22,7 @@ #pragma once #include +#include #include // CRegFilterChooserDlg dialog @@ -34,10 +35,10 @@ class CRegFilterChooserDlg : public CResizableDialog void AddToList(IMoniker* pMoniker); public: - CRegFilterChooserDlg(CWnd* pParent = nullptr); - virtual ~CRegFilterChooserDlg(); + CRegFilterChooserDlg(CWnd* pParent); + virtual ~CRegFilterChooserDlg() = default; - std::list m_filters; + std::list> m_filters; enum { IDD = IDD_ADDREGFILTER }; CListCtrl m_list;