1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 20:22:30 +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 "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,15 +2,15 @@
#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);
m_btn_select_dev_path = new wxButton(this, wxID_ANY, "..."); m_btn_select_dev_path = new wxButton(this, wxID_ANY, "...");
m_tctrl_path = new wxTextCtrl(this, wxID_ANY); m_tctrl_path = new wxTextCtrl(this, wxID_ANY);
m_btn_select_path = new wxButton(this, wxID_ANY, "..."); m_btn_select_path = new wxButton(this, wxID_ANY, "...");
m_tctrl_mount = new wxTextCtrl(this, wxID_ANY); m_tctrl_mount = new wxTextCtrl(this, wxID_ANY);
m_ch_type = new wxChoice(this, wxID_ANY); m_ch_type = new wxChoice(this, wxID_ANY);
wxBoxSizer& s_type(*new wxBoxSizer(wxHORIZONTAL)); wxBoxSizer& s_type(*new wxBoxSizer(wxHORIZONTAL));
s_type.Add(m_ch_type, 1, wxEXPAND); s_type.Add(m_ch_type, 1, wxEXPAND);
@ -48,10 +48,10 @@ VFSEntrySettingsDialog::VFSEntrySettingsDialog(wxWindow* parent, VFSManagerEntry
m_ch_type->Append(i); m_ch_type->Append(i);
} }
Connect(m_ch_type->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectType)); Connect(m_ch_type->GetId(), wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectType));
Connect(m_btn_select_path->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectPath)); Connect(m_btn_select_path->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectPath));
Connect(m_btn_select_dev_path->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectDevPath)); Connect(m_btn_select_dev_path->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnSelectDevPath));
Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnOk)); Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(VFSEntrySettingsDialog::OnOk));
m_tctrl_dev_path->SetValue(m_entry.device_path); m_tctrl_dev_path->SetValue(m_entry.device_path);
m_tctrl_path->SetValue(m_entry.path); m_tctrl_path->SetValue(m_entry.path);
@ -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);
@ -126,11 +126,11 @@ VFSManagerDialog::VFSManagerDialog(wxWindow* parent)
m_list->InsertColumn(2, "Path to Device"); m_list->InsertColumn(2, "Path to Device");
m_list->InsertColumn(3, "Device"); m_list->InsertColumn(3, "Device");
Connect(m_list->GetId(), wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxCommandEventHandler(VFSManagerDialog::OnEntryConfig)); Connect(m_list->GetId(), wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxCommandEventHandler(VFSManagerDialog::OnEntryConfig));
Connect(m_list->GetId(), wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(VFSManagerDialog::OnRightClick)); Connect(m_list->GetId(), wxEVT_COMMAND_RIGHT_CLICK, wxCommandEventHandler(VFSManagerDialog::OnRightClick));
Connect(id_add, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnAdd)); Connect(id_add, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnAdd));
Connect(id_remove, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnRemove)); Connect(id_remove, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnRemove));
Connect(id_config, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnEntryConfig)); Connect(id_config, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(VFSManagerDialog::OnEntryConfig));
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(VFSManagerDialog::OnClose)); Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(VFSManagerDialog::OnClose));
LoadEntries(); LoadEntries();
@ -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);
@ -171,18 +171,19 @@ void VFSManagerDialog::OnRightClick(wxCommandEvent& event)
int idx = m_list->GetFirstSelected(); int idx = m_list->GetFirstSelected();
menu->Append(id_add, "Add"); menu->Append(id_add, "Add");
menu->Append(id_remove, "Remove")->Enable(idx != wxNOT_FOUND); menu->Append(id_remove, "Remove")->Enable(idx != wxNOT_FOUND);
menu->AppendSeparator(); menu->AppendSeparator();
menu->Append(id_config, "Config")->Enable(idx != wxNOT_FOUND); menu->Append(id_config, "Config")->Enable(idx != wxNOT_FOUND);
PopupMenu( menu ); PopupMenu( menu );
} }
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);