Simplify some VFS-related code.

This commit is contained in:
Lioncash 2014-03-27 00:34:55 -04:00
parent 457455b71d
commit 8e44bcdbda
4 changed files with 63 additions and 84 deletions

View file

@ -1,3 +1,4 @@
#include <vector>
#include "stdafx.h" #include "stdafx.h"
#include "VFS.h" #include "VFS.h"
#include "Emu/HDD/HDD.h" #include "Emu/HDD/HDD.h"
@ -260,35 +261,35 @@ void VFS::Init(const wxString& path)
{ {
UnMountAll(); UnMountAll();
Array<VFSManagerEntry> entries; std::vector<VFSManagerEntry> entries;
SaveLoadDevices(entries, true); SaveLoadDevices(entries, true);
for(uint i=0; i<entries.GetCount(); ++i) for(const VFSManagerEntry& entry : entries)
{ {
vfsDevice* dev; vfsDevice* dev;
switch(entries[i].device) switch(entry.device)
{ {
case vfsDevice_LocalFile: case vfsDevice_LocalFile:
dev = new vfsDeviceLocalFile(); dev = new vfsDeviceLocalFile();
break; break;
case vfsDevice_HDD: case vfsDevice_HDD:
dev = new vfsDeviceHDD(entries[i].device_path); dev = new vfsDeviceHDD(entry.device_path);
break; break;
default: default:
continue; continue;
} }
wxString mpath = entries[i].path; wxString mpath = entry.path;
mpath.Replace("$(EmulatorDir)", wxGetCwd()); mpath.Replace("$(EmulatorDir)", wxGetCwd());
mpath.Replace("$(GameDir)", vfsDevice::GetRoot(path)); mpath.Replace("$(GameDir)", vfsDevice::GetRoot(path));
Mount(entries[i].mount, mpath, dev); Mount(entry.mount, mpath, dev);
} }
} }
void VFS::SaveLoadDevices(Array<VFSManagerEntry>& res, bool is_load) void VFS::SaveLoadDevices(std::vector<VFSManagerEntry>& res, bool is_load)
{ {
IniEntry<int> entries_count; IniEntry<int> entries_count;
entries_count.Init("count", "VFSManager"); entries_count.Init("count", "VFSManager");
@ -300,61 +301,25 @@ void VFS::SaveLoadDevices(Array<VFSManagerEntry>& res, bool is_load)
if(!count) if(!count)
{ {
int idx; res.emplace_back(vfsDevice_LocalFile, "$(EmulatorDir)/dev_hdd0/", "/dev_hdd0/");
idx = res.Move(new VFSManagerEntry()); res.emplace_back(vfsDevice_LocalFile, "$(EmulatorDir)/dev_hdd1/", "/dev_hdd1/");
res[idx].path = "$(EmulatorDir)/dev_hdd0/"; res.emplace_back(vfsDevice_LocalFile, "$(EmulatorDir)/dev_flash/", "/dev_flash/");
res[idx].mount = "/dev_hdd0/"; res.emplace_back(vfsDevice_LocalFile, "$(EmulatorDir)/dev_usb000/", "/dev_usb000/");
res[idx].device = vfsDevice_LocalFile; res.emplace_back(vfsDevice_LocalFile, "$(EmulatorDir)/dev_usb000/", "/dev_usb/");
res.emplace_back(vfsDevice_LocalFile, "$(GameDir)", "/app_home/");
idx = res.Move(new VFSManagerEntry()); res.emplace_back(vfsDevice_LocalFile, "$(GameDir)/../", "/dev_bdvd/");
res[idx].path = "$(EmulatorDir)/dev_hdd1/"; res.emplace_back(vfsDevice_LocalFile, "", "/host_root/");
res[idx].mount = "/dev_hdd1/"; res.emplace_back(vfsDevice_LocalFile, "$(GameDir)", "/");
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(EmulatorDir)/dev_flash/";
res[idx].mount = "/dev_flash/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(EmulatorDir)/dev_usb000/";
res[idx].mount = "/dev_usb000/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(EmulatorDir)/dev_usb000/";
res[idx].mount = "/dev_usb/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(GameDir)";
res[idx].mount = "/app_home/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(GameDir)/../";
res[idx].mount = "/dev_bdvd/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "";
res[idx].mount = "/host_root/";
res[idx].device = vfsDevice_LocalFile;
idx = res.Move(new VFSManagerEntry());
res[idx].path = "$(GameDir)";
res[idx].mount = "/";
res[idx].device = vfsDevice_LocalFile;
return; return;
} }
res.SetCount(count); res.resize(count);
} }
else else
{ {
count = res.GetCount(); count = res.size();
entries_count.SaveValue(res.GetCount()); entries_count.SaveValue(res.size());
} }
for(int i=0; i<count; ++i) for(int i=0; i<count; ++i)
@ -371,7 +336,7 @@ void VFS::SaveLoadDevices(Array<VFSManagerEntry>& res, bool is_load)
if(is_load) if(is_load)
{ {
new (res + i) VFSManagerEntry(); res[i] = VFSManagerEntry();
res[i].path = strdup(entry_path.LoadValue(wxEmptyString).c_str()); res[i].path = strdup(entry_path.LoadValue(wxEmptyString).c_str());
res[i].device_path = strdup(entry_device_path.LoadValue(wxEmptyString).c_str()); res[i].device_path = strdup(entry_device_path.LoadValue(wxEmptyString).c_str());
res[i].mount = strdup(entry_mount.LoadValue(wxEmptyString).c_str()); res[i].mount = strdup(entry_mount.LoadValue(wxEmptyString).c_str());

View file

@ -1,4 +1,6 @@
#pragma once #pragma once
#include <vector>
#include "vfsDevice.h" #include "vfsDevice.h"
enum vfsDeviceType enum vfsDeviceType
@ -15,10 +17,10 @@ static const char* vfsDeviceTypeNames[] =
struct VFSManagerEntry struct VFSManagerEntry
{ {
char* device_path;
char* path;
char* mount;
vfsDeviceType device; vfsDeviceType device;
const char* device_path;
const char* path;
const char* mount;
VFSManagerEntry() VFSManagerEntry()
: device(vfsDevice_LocalFile) : device(vfsDevice_LocalFile)
@ -27,6 +29,15 @@ struct VFSManagerEntry
, mount("") , mount("")
{ {
} }
VFSManagerEntry(const vfsDeviceType& device, const char* path, const char* mount)
: device(device)
, device_path("")
, path(path)
, mount(mount)
{
}
}; };
struct VFS struct VFS
@ -51,5 +62,5 @@ struct VFS
vfsDevice* GetDeviceLocal(const wxString& local_path, wxString& path) const; vfsDevice* GetDeviceLocal(const wxString& local_path, wxString& path) const;
void Init(const wxString& path); void Init(const wxString& path);
void SaveLoadDevices(Array<VFSManagerEntry>& res, bool is_load); void SaveLoadDevices(std::vector<VFSManagerEntry>& res, bool is_load);
}; };

View file

@ -2,7 +2,7 @@
#include "VFSManager.h" #include "VFSManager.h"
VFSEntrySettingsDialog::VFSEntrySettingsDialog(wxWindow* parent, VFSManagerEntry& entry) VFSEntrySettingsDialog::VFSEntrySettingsDialog(wxWindow* parent, VFSManagerEntry& entry)
: wxDialog(parent, wxID_ANY, "Mount configuration", wxDefaultPosition) : wxDialog(parent, wxID_ANY, "Mount configuration")
, m_entry(entry) , m_entry(entry)
{ {
m_tctrl_dev_path = new wxTextCtrl(this, wxID_ANY); m_tctrl_dev_path = new wxTextCtrl(this, wxID_ANY);
@ -111,7 +111,7 @@ enum
}; };
VFSManagerDialog::VFSManagerDialog(wxWindow* parent) VFSManagerDialog::VFSManagerDialog(wxWindow* parent)
: wxDialog(parent, wxID_ANY, "Virtual File System Manager", wxDefaultPosition) : wxDialog(parent, wxID_ANY, "Virtual File System Manager")
{ {
m_list = new wxListView(this); m_list = new wxListView(this);
@ -141,7 +141,7 @@ void VFSManagerDialog::UpdateList()
{ {
m_list->Freeze(); m_list->Freeze();
m_list->DeleteAllItems(); m_list->DeleteAllItems();
for(uint i=0; i<m_entries.GetCount(); ++i) for(size_t i=0; i<m_entries.size(); ++i)
{ {
m_list->InsertItem(i, m_entries[i].mount); m_list->InsertItem(i, m_entries[i].mount);
m_list->SetItem(i, 1, m_entries[i].path); m_list->SetItem(i, 1, m_entries[i].path);
@ -180,9 +180,10 @@ void VFSManagerDialog::OnRightClick(wxCommandEvent& event)
void VFSManagerDialog::OnAdd(wxCommandEvent& event) void VFSManagerDialog::OnAdd(wxCommandEvent& event)
{ {
u32 idx = m_entries.Move(new VFSManagerEntry()); m_entries.emplace_back(VFSManagerEntry());
UpdateList(); UpdateList();
u32 idx = m_entries.size() - 1;
for(int i=0; i<m_list->GetItemCount(); ++i) for(int i=0; i<m_list->GetItemCount(); ++i)
{ {
m_list->SetItemState(i, i == idx ? wxLIST_STATE_SELECTED : ~wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); m_list->SetItemState(i, i == idx ? wxLIST_STATE_SELECTED : ~wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
@ -196,7 +197,7 @@ void VFSManagerDialog::OnRemove(wxCommandEvent& event)
{ {
for(int sel = m_list->GetNextSelected(-1), offs = 0; sel != wxNOT_FOUND; sel = m_list->GetNextSelected(sel), --offs) for(int sel = m_list->GetNextSelected(-1), offs = 0; sel != wxNOT_FOUND; sel = m_list->GetNextSelected(sel), --offs)
{ {
m_entries.RemoveAt(sel + offs); m_entries.erase(m_entries.begin() + (sel + offs));
} }
UpdateList(); UpdateList();
@ -210,7 +211,7 @@ void VFSManagerDialog::OnClose(wxCloseEvent& event)
void VFSManagerDialog::LoadEntries() void VFSManagerDialog::LoadEntries()
{ {
m_entries.Clear(); m_entries.clear();
Emu.GetVFS().SaveLoadDevices(m_entries, true); Emu.GetVFS().SaveLoadDevices(m_entries, true);
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <vector>
class VFSEntrySettingsDialog : public wxDialog class VFSEntrySettingsDialog : public wxDialog
{ {
wxTextCtrl* m_tctrl_dev_path; wxTextCtrl* m_tctrl_dev_path;
@ -21,7 +23,7 @@ public:
class VFSManagerDialog : public wxDialog class VFSManagerDialog : public wxDialog
{ {
wxListView* m_list; wxListView* m_list;
Array<VFSManagerEntry> m_entries; std::vector<VFSManagerEntry> m_entries;
public: public:
VFSManagerDialog(wxWindow* parent); VFSManagerDialog(wxWindow* parent);