DiscIO: Make factory methods return unique_ptrs

Rather than rely on the developer to do the right thing,
just make the default behavior safely deallocate resources.

If shared semantics are ever needed in the future, the
constructor that takes a unique_ptr for shared_ptr can
be used.
This commit is contained in:
Lioncash
2015-12-06 23:15:51 -05:00
parent a0ac2b8673
commit edbbf493f8
22 changed files with 204 additions and 231 deletions

View File

@ -105,14 +105,14 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
, OpenGameListItem(game_list_item)
{
// Load ISO data
OpenISO = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName());
m_open_iso = DiscIO::CreateVolumeFromFilename(OpenGameListItem.GetFileName());
game_id = OpenISO->GetUniqueID();
game_id = m_open_iso->GetUniqueID();
// Load game INIs
GameIniFileLocal = File::GetUserPath(D_GAMESETTINGS_IDX) + game_id + ".ini";
GameIniDefault = SConfig::LoadDefaultGameIni(game_id, OpenISO->GetRevision());
GameIniLocal = SConfig::LoadLocalGameIni(game_id, OpenISO->GetRevision());
GameIniDefault = SConfig::LoadDefaultGameIni(game_id, m_open_iso->GetRevision());
GameIniLocal = SConfig::LoadLocalGameIni(game_id, m_open_iso->GetRevision());
// Setup GUI
bRefreshList = false;
@ -123,9 +123,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
// Disk header and apploader
m_InternalName->SetValue(StrToWxStr(OpenISO->GetInternalName()));
m_GameID->SetValue(StrToWxStr(OpenISO->GetUniqueID()));
switch (OpenISO->GetCountry())
m_InternalName->SetValue(StrToWxStr(m_open_iso->GetInternalName()));
m_GameID->SetValue(StrToWxStr(m_open_iso->GetUniqueID()));
switch (m_open_iso->GetCountry())
{
case DiscIO::IVolume::COUNTRY_AUSTRALIA:
m_Country->SetValue(_("Australia"));
@ -172,14 +172,14 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
break;
}
wxString temp = "0x" + StrToWxStr(OpenISO->GetMakerID());
wxString temp = "0x" + StrToWxStr(m_open_iso->GetMakerID());
m_MakerID->SetValue(temp);
m_Revision->SetValue(StrToWxStr(std::to_string(OpenISO->GetRevision())));
m_Date->SetValue(StrToWxStr(OpenISO->GetApploaderDate()));
m_FST->SetValue(StrToWxStr(std::to_string(OpenISO->GetFSTSize())));
m_Revision->SetValue(StrToWxStr(std::to_string(m_open_iso->GetRevision())));
m_Date->SetValue(StrToWxStr(m_open_iso->GetApploaderDate()));
m_FST->SetValue(StrToWxStr(std::to_string(m_open_iso->GetFSTSize())));
// Here we set all the info to be shown + we set the window title
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
bool wii = m_open_iso->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
ChangeBannerDetails(SConfig::GetInstance().GetCurrentLanguage(wii));
m_Banner->SetBitmap(OpenGameListItem.GetBitmap());
@ -187,9 +187,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
// Filesystem browser/dumper
// TODO : Should we add a way to browse the wad file ?
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD)
if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD)
{
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{
int partition_count = 0;
for (int group = 0; group < 4; group++)
@ -225,9 +225,9 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
}
else
{
pFileSystem = DiscIO::CreateFileSystem(OpenISO);
if (pFileSystem)
CreateDirectoryTree(RootId, pFileSystem->GetFileList());
m_filesystem = DiscIO::CreateFileSystem(m_open_iso.get());
if (m_filesystem)
CreateDirectoryTree(RootId, m_filesystem->GetFileList());
}
m_Treectrl->Expand(RootId);
@ -236,9 +236,6 @@ CISOProperties::CISOProperties(const GameListItem& game_list_item, wxWindow* par
CISOProperties::~CISOProperties()
{
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC && pFileSystem)
delete pFileSystem;
delete OpenISO;
}
size_t CISOProperties::CreateDirectoryTree(wxTreeItemId& parent, const std::vector<DiscIO::SFileInfo>& fileInfos)
@ -396,7 +393,7 @@ void CISOProperties::CreateGUIControls()
sbCoreOverrides->Add(sGPUDeterminism, 0, wxEXPAND|wxALL, 5);
wxStaticBoxSizer * const sbWiiOverrides = new wxStaticBoxSizer(wxVERTICAL, m_GameConfig, _("Wii Console"));
if (OpenISO->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::GAMECUBE_DISC)
{
sbWiiOverrides->ShowItems(false);
EnableWideScreen->Hide();
@ -484,7 +481,7 @@ void CISOProperties::CreateGUIControls()
wxStaticText* const m_LangText = new wxStaticText(m_Information, wxID_ANY, _("Show Language:"));
bool wii = OpenISO->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
bool wii = m_open_iso->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;
DiscIO::IVolume::ELanguage preferred_language = SConfig::GetInstance().GetCurrentLanguage(wii);
std::vector<DiscIO::IVolume::ELanguage> languages = OpenGameListItem.GetLanguages();
@ -595,10 +592,10 @@ void CISOProperties::CreateGUIControls()
sInfoPage->Add(sbBannerDetails, 0, wxEXPAND|wxALL, 5);
m_Information->SetSizer(sInfoPage);
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_WAD)
if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_WAD)
{
wxPanel* const m_Filesystem = new wxPanel(m_Notebook, ID_FILESYSTEM);
m_Notebook->AddPage(m_Filesystem, _("Filesystem"));
wxPanel* const filesystem_panel = new wxPanel(m_Notebook, ID_FILESYSTEM);
m_Notebook->AddPage(filesystem_panel, _("Filesystem"));
// Filesystem icons
wxImageList* const m_iconList = new wxImageList(16, 16);
@ -607,13 +604,13 @@ void CISOProperties::CreateGUIControls()
m_iconList->Add(wxBitmap(file_xpm), wxNullBitmap); // 2
// Filesystem tree
m_Treectrl = new wxTreeCtrl(m_Filesystem, ID_TREECTRL);
m_Treectrl = new wxTreeCtrl(filesystem_panel, ID_TREECTRL);
m_Treectrl->AssignImageList(m_iconList);
RootId = m_Treectrl->AddRoot(_("Disc"), 0, 0, nullptr);
wxBoxSizer* sTreePage = new wxBoxSizer(wxVERTICAL);
sTreePage->Add(m_Treectrl, 1, wxEXPAND|wxALL, 5);
m_Filesystem->SetSizer(sTreePage);
filesystem_panel->SetSizer(sTreePage);
}
wxSizer* sButtons = CreateButtonSizer(wxNO_DEFAULT);
@ -623,7 +620,7 @@ void CISOProperties::CreateGUIControls()
// If there is no default gameini, disable the button.
bool game_ini_exists = false;
for (const std::string& ini_filename : SConfig::GetGameIniFilenames(game_id, OpenISO->GetRevision()))
for (const std::string& ini_filename : SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
{
if (File::Exists(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + ini_filename))
{
@ -703,7 +700,7 @@ void CISOProperties::OnRightClickOnTree(wxTreeEvent& event)
popupMenu.Append(IDM_EXTRACTALL, _("Extract All Files..."));
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC ||
if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC ||
(m_Treectrl->GetItemImage(m_Treectrl->GetSelection()) == 0 &&
m_Treectrl->GetFirstVisibleItem() != m_Treectrl->GetSelection()))
{
@ -746,7 +743,7 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
m_Treectrl->SelectItem(m_Treectrl->GetItemParent(m_Treectrl->GetSelection()));
}
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{
const wxTreeItemId tree_selection = m_Treectrl->GetSelection();
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection));
@ -756,13 +753,13 @@ void CISOProperties::OnExtractFile(wxCommandEvent& WXUNUSED (event))
}
else
{
pFileSystem->ExportFile(WxStrToStr(File), WxStrToStr(Path));
m_filesystem->ExportFile(WxStrToStr(File), WxStrToStr(Path));
}
}
void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string& _rExportFolder, const WiiPartition* partition)
{
DiscIO::IFileSystem* const fs = OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC ? partition->FileSystem.get() : pFileSystem;
DiscIO::IFileSystem* const fs = m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC ? partition->FileSystem.get() : m_filesystem.get();
const std::vector<DiscIO::SFileInfo>& fst = fs->GetFileList();
@ -776,7 +773,7 @@ void CISOProperties::ExportDir(const std::string& _rFullPath, const std::string&
size = (u32)fst.size();
fs->ExportApploader(_rExportFolder);
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC)
fs->ExportDOL(_rExportFolder);
}
else
@ -861,7 +858,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
if (event.GetId() == IDM_EXTRACTALL)
{
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{
wxTreeItemIdValue cookie;
wxTreeItemId root = m_Treectrl->GetRootItem();
@ -890,7 +887,7 @@ void CISOProperties::OnExtractDir(wxCommandEvent& event)
Directory += DIR_SEP_CHR;
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{
const wxTreeItemId tree_selection = m_Treectrl->GetSelection();
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(tree_selection));
@ -912,14 +909,14 @@ void CISOProperties::OnExtractDataFromHeader(wxCommandEvent& event)
if (Path.empty())
return;
if (OpenISO->GetVolumeType() == DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() == DiscIO::IVolume::WII_DISC)
{
WiiPartition* partition = reinterpret_cast<WiiPartition*>(m_Treectrl->GetItemData(m_Treectrl->GetSelection()));
FS = partition->FileSystem.get();
}
else
{
FS = pFileSystem;
FS = m_filesystem.get();
}
bool ret = false;
@ -958,7 +955,7 @@ void CISOProperties::CheckPartitionIntegrity(wxCommandEvent& event)
{
// Normally we can't enter this function if we aren't analyzing a Wii disc
// anyway, but let's still check to be sure.
if (OpenISO->GetVolumeType() != DiscIO::IVolume::WII_DISC)
if (m_open_iso->GetVolumeType() != DiscIO::IVolume::WII_DISC)
return;
wxProgressDialog dialog(_("Checking integrity..."), _("Working..."), 1000, this,
@ -1082,7 +1079,7 @@ void CISOProperties::LoadGameConfig()
PatchList_Load();
ActionReplayList_Load();
m_geckocode_panel->LoadCodes(GameIniDefault, GameIniLocal, OpenISO->GetUniqueID());
m_geckocode_panel->LoadCodes(GameIniDefault, GameIniLocal, m_open_iso->GetUniqueID());
}
void CISOProperties::SaveGameIniValueFrom3StateCheckbox(const char* section, const char* key, wxCheckBox* checkbox)
@ -1279,7 +1276,7 @@ void CISOProperties::OnComputeMD5Sum(wxCommandEvent& WXUNUSED (event))
// they will all be opened, but there is usually only one
void CISOProperties::OnShowDefaultConfig(wxCommandEvent& WXUNUSED (event))
{
for (const std::string& filename : SConfig::GetGameIniFilenames(game_id, OpenISO->GetRevision()))
for (const std::string& filename : SConfig::GetGameIniFilenames(game_id, m_open_iso->GetRevision()))
{
std::string path = File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename;
if (File::Exists(path))