1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Merge pull request #125 from lioncash/ui

Simplify some VFS-related code.
This commit is contained in:
Alexandro Sánchez Bach 2014-03-27 16:08:04 +01:00
commit c541176a32
4 changed files with 63 additions and 84 deletions

View File

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

View File

@ -1,4 +1,6 @@
#pragma once
#include <vector>
#include "vfsDevice.h"
enum vfsDeviceType
@ -15,10 +17,10 @@ static const char* vfsDeviceTypeNames[] =
struct VFSManagerEntry
{
char* device_path;
char* path;
char* mount;
vfsDeviceType device;
const char* device_path;
const char* path;
const char* mount;
VFSManagerEntry()
: device(vfsDevice_LocalFile)
@ -27,6 +29,15 @@ struct VFSManagerEntry
, mount("")
{
}
VFSManagerEntry(const vfsDeviceType& device, const char* path, const char* mount)
: device(device)
, device_path("")
, path(path)
, mount(mount)
{
}
};
struct VFS
@ -51,5 +62,5 @@ struct VFS
vfsDevice* GetDeviceLocal(const wxString& local_path, wxString& path) const;
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"
VFSEntrySettingsDialog::VFSEntrySettingsDialog(wxWindow* parent, VFSManagerEntry& entry)
: wxDialog(parent, wxID_ANY, "Mount configuration", wxDefaultPosition)
: wxDialog(parent, wxID_ANY, "Mount configuration")
, m_entry(entry)
{
m_tctrl_dev_path = new wxTextCtrl(this, wxID_ANY);
@ -111,7 +111,7 @@ enum
};
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);
@ -141,7 +141,7 @@ void VFSManagerDialog::UpdateList()
{
m_list->Freeze();
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->SetItem(i, 1, m_entries[i].path);
@ -180,9 +180,10 @@ void VFSManagerDialog::OnRightClick(wxCommandEvent& event)
void VFSManagerDialog::OnAdd(wxCommandEvent& event)
{
u32 idx = m_entries.Move(new VFSManagerEntry());
m_entries.emplace_back(VFSManagerEntry());
UpdateList();
u32 idx = m_entries.size() - 1;
for(int i=0; i<m_list->GetItemCount(); ++i)
{
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)
{
m_entries.RemoveAt(sel + offs);
m_entries.erase(m_entries.begin() + (sel + offs));
}
UpdateList();
@ -210,7 +211,7 @@ void VFSManagerDialog::OnClose(wxCloseEvent& event)
void VFSManagerDialog::LoadEntries()
{
m_entries.Clear();
m_entries.clear();
Emu.GetVFS().SaveLoadDevices(m_entries, true);
}

View File

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