MemcardManager: Use unique_ptr over raw pointers
This commit is contained in:
parent
f20113fce2
commit
d72cf81dea
|
@ -2,9 +2,12 @@
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "DolphinWX/MemcardManager.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wx/bitmap.h>
|
#include <wx/bitmap.h>
|
||||||
|
@ -27,7 +30,6 @@
|
||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "Core/HW/GCMemcard.h"
|
#include "Core/HW/GCMemcard.h"
|
||||||
#include "DolphinWX/MemcardManager.h"
|
|
||||||
#include "DolphinWX/WxUtils.h"
|
#include "DolphinWX/WxUtils.h"
|
||||||
|
|
||||||
#define FIRSTPAGE 0
|
#define FIRSTPAGE 0
|
||||||
|
@ -102,16 +104,6 @@ CMemcardManager::CMemcardManager(wxWindow* parent)
|
||||||
|
|
||||||
CMemcardManager::~CMemcardManager()
|
CMemcardManager::~CMemcardManager()
|
||||||
{
|
{
|
||||||
if (memoryCard[SLOT_A])
|
|
||||||
{
|
|
||||||
delete memoryCard[SLOT_A];
|
|
||||||
memoryCard[SLOT_A] = nullptr;
|
|
||||||
}
|
|
||||||
if (memoryCard[SLOT_B])
|
|
||||||
{
|
|
||||||
delete memoryCard[SLOT_B];
|
|
||||||
memoryCard[SLOT_B] = nullptr;
|
|
||||||
}
|
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +295,7 @@ void CMemcardManager::ChangePath(int slot)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (memoryCard[slot])
|
memoryCard[slot].reset();
|
||||||
{
|
|
||||||
delete memoryCard[slot];
|
|
||||||
memoryCard[slot] = nullptr;
|
|
||||||
}
|
|
||||||
mcmSettings.twoCardsLoaded = false;
|
mcmSettings.twoCardsLoaded = false;
|
||||||
m_MemcardPath[slot]->SetPath(wxEmptyString);
|
m_MemcardPath[slot]->SetPath(wxEmptyString);
|
||||||
m_MemcardList[slot]->ClearAll();
|
m_MemcardList[slot]->ClearAll();
|
||||||
|
@ -622,11 +610,8 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
||||||
|
|
||||||
bool CMemcardManager::ReloadMemcard(const std::string& fileName, int card)
|
bool CMemcardManager::ReloadMemcard(const std::string& fileName, int card)
|
||||||
{
|
{
|
||||||
if (memoryCard[card])
|
|
||||||
delete memoryCard[card];
|
|
||||||
|
|
||||||
// TODO: add error checking and animate icons
|
// TODO: add error checking and animate icons
|
||||||
memoryCard[card] = new GCMemcard(fileName);
|
memoryCard[card] = std::make_unique<GCMemcard>(fileName);
|
||||||
|
|
||||||
if (!memoryCard[card]->IsValid())
|
if (!memoryCard[card]->IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
#include <wx/listctrl.h>
|
#include <wx/listctrl.h>
|
||||||
|
@ -93,7 +95,7 @@ private:
|
||||||
NUMBER_OF_COLUMN
|
NUMBER_OF_COLUMN
|
||||||
};
|
};
|
||||||
|
|
||||||
GCMemcard* memoryCard[2];
|
std::array<std::unique_ptr<GCMemcard>, 2> memoryCard;
|
||||||
|
|
||||||
void CreateGUIControls();
|
void CreateGUIControls();
|
||||||
void CopyDeleteClick(wxCommandEvent& event);
|
void CopyDeleteClick(wxCommandEvent& event);
|
||||||
|
|
Loading…
Reference in New Issue