Skip to content

Commit

Permalink
Используем везде unique_ptr<FilterOverride> вместо сырых указателей.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksoid1978 committed Feb 16, 2024
1 parent 12445d9 commit 0e65d7d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 136 deletions.
75 changes: 32 additions & 43 deletions src/apps/mplayerc/FakeFilterMapper2.cpp
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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&REG_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&REG_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;
Expand Down
10 changes: 6 additions & 4 deletions src/apps/mplayerc/FakeFilterMapper2.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -21,6 +21,8 @@

#pragma once

#include <memory>

class FilterOverride
{
public:
Expand All @@ -38,7 +40,7 @@ class FilterOverride
int iLoadType = 0;
DWORD dwMerit = 0;

FilterOverride() {}
FilterOverride() = default;
FilterOverride(FilterOverride* f)
: fDisabled (f->fDisabled)
, fTemporary(f->fTemporary)
Expand Down Expand Up @@ -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;
Expand All @@ -120,6 +122,6 @@ class CFilterMapper2 : protected CUnknown, public IFilterMapper2
static void Init();

static IFilterMapper2* m_pFilterMapper2;
std::list<FilterOverride*> m_filters;
std::list<std::unique_ptr<FilterOverride>> m_filters;
void Register(CString path);
};
29 changes: 11 additions & 18 deletions src/apps/mplayerc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilterOverride> 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));

Expand Down
100 changes: 43 additions & 57 deletions src/apps/mplayerc/PPageExternalFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilterOverride> 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" <not found!>";
}
if (f->type == FilterOverride::EXTERNAL) {
if (!CPath(MakeFullPath(f->path)).FileExists()) {
name += L" <not found!>";
}
}

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();
}
}
}
Expand Down Expand Up @@ -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<FilterOverride> 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);
Expand Down
11 changes: 1 addition & 10 deletions src/apps/mplayerc/RegFilterChooserDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -133,16 +126,14 @@ 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();
f->clsid = fgf.GetCLSID();
f->guids = fgf.GetTypes();
f->dwMerit = fgf.GetMeritForDirectShow();
f->iLoadType = FilterOverride::MERIT;
m_filters.emplace_back(f);
}

__super::OnOK();
Expand Down
9 changes: 5 additions & 4 deletions src/apps/mplayerc/RegFilterChooserDlg.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -22,6 +22,7 @@
#pragma once

#include <afxwin.h>
#include <memory>
#include <ExtLib/ui/ResizableLib/ResizableDialog.h>

// CRegFilterChooserDlg dialog
Expand All @@ -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<FilterOverride*> m_filters;
std::list<std::unique_ptr<FilterOverride>> m_filters;

enum { IDD = IDD_ADDREGFILTER };
CListCtrl m_list;
Expand Down

0 comments on commit 0e65d7d

Please sign in to comment.