very crappy RecentFiles save/load to config
This commit is contained in:
parent
1f192a6530
commit
ab8b3972c9
|
@ -6,7 +6,7 @@
|
||||||
<ProductVersion>9.0.21022</ProductVersion>
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{DD448B37-BA3F-4544-9754-5406E8094723}</ProjectGuid>
|
<ProjectGuid>{DD448B37-BA3F-4544-9754-5406E8094723}</ProjectGuid>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>BizHawk.MultiClient</RootNamespace>
|
<RootNamespace>BizHawk.MultiClient</RootNamespace>
|
||||||
<AssemblyName>BizHawk.MultiClient</AssemblyName>
|
<AssemblyName>BizHawk.MultiClient</AssemblyName>
|
||||||
|
@ -81,9 +81,11 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<EmbeddedResource Include="MainForm.resx">
|
<EmbeddedResource Include="MainForm.resx">
|
||||||
<DependentUpon>MainForm.cs</DependentUpon>
|
<DependentUpon>MainForm.cs</DependentUpon>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="NameStateForm.resx">
|
<EmbeddedResource Include="NameStateForm.resx">
|
||||||
<DependentUpon>NameStateForm.cs</DependentUpon>
|
<DependentUpon>NameStateForm.cs</DependentUpon>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Properties\Resources.resx">
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
<Generator>ResXFileCodeGenerator</Generator>
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
public bool SoundEnabled = true;
|
public bool SoundEnabled = true;
|
||||||
public string LastRomPath = ".";
|
public string LastRomPath = ".";
|
||||||
public bool AutoLoadMostRecentRom = false; //TODO: eventually make a class or struct for all the auto-loads, which will include recent roms, movies, etc, as well as autoloading any modeless dialog
|
public bool AutoLoadMostRecentRom = false; //TODO: eventually make a class or struct for all the auto-loads, which will include recent roms, movies, etc, as well as autoloading any modeless dialog
|
||||||
|
public RecentFiles RecentRoms = new RecentFiles(8);
|
||||||
|
|
||||||
// Client Hotkey Bindings
|
// Client Hotkey Bindings
|
||||||
public string HardResetBinding = "LeftShift+Tab";
|
public string HardResetBinding = "LeftShift+Tab";
|
||||||
|
|
|
@ -3,6 +3,11 @@ using System.IO;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
|
public interface IConfigSerializable
|
||||||
|
{
|
||||||
|
void Deserialize(string str);
|
||||||
|
}
|
||||||
|
|
||||||
public static class ConfigService
|
public static class ConfigService
|
||||||
{
|
{
|
||||||
public static T Load<T>(string filepath) where T : new()
|
public static T Load<T>(string filepath) where T : new()
|
||||||
|
@ -50,6 +55,16 @@ namespace BizHawk.MultiClient
|
||||||
field.SetValue(config, bool.Parse(value));
|
field.SetValue(config, bool.Parse(value));
|
||||||
else if (fieldType == typeof(char))
|
else if (fieldType == typeof(char))
|
||||||
field.SetValue(config, char.Parse(value));
|
field.SetValue(config, char.Parse(value));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var iface = fieldType.GetInterface("IConfigSerializable");
|
||||||
|
if (iface != null)
|
||||||
|
{
|
||||||
|
IConfigSerializable i = (IConfigSerializable) Activator.CreateInstance(fieldType);
|
||||||
|
i.Deserialize(value);
|
||||||
|
field.SetValue(config, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch { } // If anything fails to parse, just move on / use defaults, don't crash.
|
catch { } // If anything fails to parse, just move on / use defaults, don't crash.
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
private Control renderTarget;
|
private Control renderTarget;
|
||||||
private RetainedViewportPanel retainedPanel;
|
private RetainedViewportPanel retainedPanel;
|
||||||
private RecentFiles RecentRoms = new RecentFiles(8);
|
|
||||||
|
|
||||||
|
|
||||||
private int SaveSlot = 0; //Saveslot sytem
|
private int SaveSlot = 0; //Saveslot sytem
|
||||||
|
|
||||||
|
@ -198,7 +196,7 @@ namespace BizHawk.MultiClient
|
||||||
Global.Emulator.LoadGame(game);
|
Global.Emulator.LoadGame(game);
|
||||||
Text = game.Name;
|
Text = game.Name;
|
||||||
ResetRewindBuffer();
|
ResetRewindBuffer();
|
||||||
RecentRoms.Add(file.FullName);
|
Global.Config.RecentRoms.Add(file.FullName);
|
||||||
if (File.Exists(game.SaveRamPath))
|
if (File.Exists(game.SaveRamPath))
|
||||||
LoadSaveRam();
|
LoadSaveRam();
|
||||||
}
|
}
|
||||||
|
@ -587,7 +585,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
|
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
RecentRoms.Clear();
|
Global.Config.RecentRoms.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAutoLoadRecentRom()
|
private void UpdateAutoLoadRecentRom()
|
||||||
|
@ -683,15 +681,15 @@ namespace BizHawk.MultiClient
|
||||||
//repopulate it with an up to date list
|
//repopulate it with an up to date list
|
||||||
recentROMToolStripMenuItem.DropDownItems.Clear();
|
recentROMToolStripMenuItem.DropDownItems.Clear();
|
||||||
|
|
||||||
if (RecentRoms.IsEmpty())
|
if (Global.Config.RecentRoms.IsEmpty())
|
||||||
{
|
{
|
||||||
recentROMToolStripMenuItem.DropDownItems.Add("None");
|
recentROMToolStripMenuItem.DropDownItems.Add("None");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int x = 0; x < RecentRoms.Length(); x++)
|
for (int x = 0; x < Global.Config.RecentRoms.Length(); x++)
|
||||||
{
|
{
|
||||||
string path = RecentRoms.GetRecentFileByPosition(x);
|
string path = Global.Config.RecentRoms.GetRecentFileByPosition(x);
|
||||||
var item = new ToolStripMenuItem();
|
var item = new ToolStripMenuItem();
|
||||||
item.Text = path;
|
item.Text = path;
|
||||||
item.Click += (o, ev) => LoadRom(path);
|
item.Click += (o, ev) => LoadRom(path);
|
||||||
|
@ -703,7 +701,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
var clearitem = new ToolStripMenuItem();
|
var clearitem = new ToolStripMenuItem();
|
||||||
clearitem.Text = "&Clear";
|
clearitem.Text = "&Clear";
|
||||||
clearitem.Click += (o, ev) => RecentRoms.Clear();
|
clearitem.Click += (o, ev) => Global.Config.RecentRoms.Clear();
|
||||||
recentROMToolStripMenuItem.DropDownItems.Add(clearitem);
|
recentROMToolStripMenuItem.DropDownItems.Add(clearitem);
|
||||||
|
|
||||||
var auto = new ToolStripMenuItem();
|
var auto = new ToolStripMenuItem();
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace BizHawk.MultiClient
|
namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
class RecentFiles
|
public class RecentFiles : IConfigSerializable
|
||||||
{
|
{
|
||||||
private int MAX_RECENT_FILES; //Maximum number of files
|
private int MAX_RECENT_FILES; //Maximum number of files
|
||||||
private List<string> recentlist; //List of recent files
|
private List<string> recentlist; //List of recent files
|
||||||
|
|
||||||
|
public RecentFiles() : this(8) {}
|
||||||
public RecentFiles(int max)
|
public RecentFiles(int max)
|
||||||
{
|
{
|
||||||
recentlist = new List<string>();
|
recentlist = new List<string>();
|
||||||
|
@ -84,5 +83,26 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
return recentlist[position];
|
return recentlist[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append(MAX_RECENT_FILES);
|
||||||
|
sb.Append("@");
|
||||||
|
foreach (string file in recentlist)
|
||||||
|
sb.AppendFormat("\"{0}\"|", file);
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deserialize(string str)
|
||||||
|
{
|
||||||
|
var sections = str.Split('@');
|
||||||
|
MAX_RECENT_FILES = int.Parse(sections[0]);
|
||||||
|
var files = sections[1].Split('|');
|
||||||
|
recentlist.Clear();
|
||||||
|
foreach (string file in files)
|
||||||
|
if (string.IsNullOrEmpty(file) == false)
|
||||||
|
recentlist.Add(file.Replace("\"", ""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue