2015-07-03 00:12:02 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Config
|
|
|
|
|
{
|
|
|
|
|
public class Configuration
|
|
|
|
|
{
|
|
|
|
|
private const int MaxRecentFiles = 10;
|
|
|
|
|
|
2016-06-12 22:41:41 -04:00
|
|
|
|
public string MesenVersion = "0.2.2";
|
2016-01-17 14:21:31 -05:00
|
|
|
|
public PreferenceInfo PreferenceInfo;
|
2015-07-17 20:58:57 -04:00
|
|
|
|
public AudioInfo AudioInfo;
|
2015-07-17 21:18:57 -04:00
|
|
|
|
public VideoInfo VideoInfo;
|
2016-02-05 23:14:27 -05:00
|
|
|
|
public InputInfo InputInfo;
|
2016-06-21 18:58:22 -04:00
|
|
|
|
public EmulationInfo EmulationInfo;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
public List<string> RecentFiles;
|
2016-04-30 20:08:53 -04:00
|
|
|
|
public List<VsConfigInfo> VsConfig;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
public List<CheatInfo> Cheats;
|
2015-07-05 19:05:33 -04:00
|
|
|
|
public bool ShowOnlyCheatsForCurrentGame;
|
2015-07-21 23:05:27 -04:00
|
|
|
|
public NesModel Region;
|
2016-01-17 14:21:31 -05:00
|
|
|
|
public ClientConnectionInfo ClientConnectionInfo;
|
|
|
|
|
public ServerInfo ServerInfo;
|
|
|
|
|
public PlayerProfile Profile;
|
2016-06-04 14:43:13 -04:00
|
|
|
|
public DebugInfo DebugInfo;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
|
|
|
|
|
public Configuration()
|
|
|
|
|
{
|
|
|
|
|
Profile = new PlayerProfile();
|
|
|
|
|
ClientConnectionInfo = new ClientConnectionInfo();
|
|
|
|
|
ServerInfo = new ServerInfo();
|
2015-07-17 20:58:57 -04:00
|
|
|
|
AudioInfo = new AudioInfo();
|
2015-07-17 21:18:57 -04:00
|
|
|
|
VideoInfo = new VideoInfo();
|
2015-12-27 22:05:45 -05:00
|
|
|
|
PreferenceInfo = new PreferenceInfo();
|
2016-06-21 18:58:22 -04:00
|
|
|
|
EmulationInfo = new EmulationInfo();
|
2015-07-03 00:12:02 -04:00
|
|
|
|
RecentFiles = new List<string>();
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InputInfo = new InputInfo();
|
2016-01-16 19:33:10 -05:00
|
|
|
|
Cheats = new List<CheatInfo>();
|
2016-05-02 20:22:17 -04:00
|
|
|
|
VsConfig = new List<VsConfigInfo>();
|
2016-06-04 14:43:13 -04:00
|
|
|
|
DebugInfo = new DebugInfo();
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 23:05:27 -04:00
|
|
|
|
public void ApplyConfig()
|
|
|
|
|
{
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InputInfo.ApplyConfig();
|
2015-07-21 23:05:27 -04:00
|
|
|
|
VideoInfo.ApplyConfig();
|
|
|
|
|
AudioInfo.ApplyConfig();
|
2015-12-27 22:05:45 -05:00
|
|
|
|
PreferenceInfo.ApplyConfig();
|
2016-06-21 18:58:22 -04:00
|
|
|
|
EmulationInfo.ApplyConfig();
|
2015-07-21 23:05:27 -04:00
|
|
|
|
|
|
|
|
|
InteropEmu.SetNesModel(Region);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-16 19:33:10 -05:00
|
|
|
|
public void InitializeDefaults()
|
2015-07-10 21:07:24 -04:00
|
|
|
|
{
|
2016-02-05 23:14:27 -05:00
|
|
|
|
InputInfo.InitializeDefaults();
|
2015-07-10 21:07:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-03 00:12:02 -04:00
|
|
|
|
public void AddRecentFile(string filepath)
|
|
|
|
|
{
|
|
|
|
|
if(RecentFiles.Contains(filepath)) {
|
|
|
|
|
RecentFiles.Remove(filepath);
|
|
|
|
|
}
|
|
|
|
|
RecentFiles.Insert(0, filepath);
|
|
|
|
|
if(RecentFiles.Count > Configuration.MaxRecentFiles) {
|
|
|
|
|
RecentFiles.RemoveAt(Configuration.MaxRecentFiles);
|
|
|
|
|
}
|
|
|
|
|
ConfigManager.ApplyChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Configuration Deserialize(string configFile)
|
|
|
|
|
{
|
2015-07-10 21:07:24 -04:00
|
|
|
|
Configuration config;
|
2016-02-11 18:37:52 -05:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
|
|
|
|
using(TextReader textReader = new StreamReader(configFile)) {
|
|
|
|
|
config = (Configuration)xmlSerializer.Deserialize(textReader);
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
config = new Configuration();
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
2015-07-10 21:07:24 -04:00
|
|
|
|
|
|
|
|
|
config.InitializeDefaults();
|
|
|
|
|
return config;
|
2015-07-03 00:12:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Serialize(string configFile)
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
|
|
|
|
using(TextWriter textWriter = new StreamWriter(configFile)) {
|
|
|
|
|
xmlSerializer.Serialize(textWriter, this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Configuration Clone()
|
|
|
|
|
{
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
|
xmlSerializer.Serialize(stringWriter, this);
|
|
|
|
|
|
|
|
|
|
StringReader stringReader = new StringReader(stringWriter.ToString());
|
|
|
|
|
return (Configuration)xmlSerializer.Deserialize(stringReader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|