1 using System;
2 using System.Collections.Generic;
3 using Mesen.GUI.Forms;
4 
5 namespace Mesen.GUI.Config
6 {
7 	public class PreferenceInfo
8 	{
9 		public Language DisplayLanguage = Language.SystemDefault;
10 
11 		public bool SingleInstance = true;
12 		public bool PauseWhenInBackground = false;
13 		public bool PauseWhenInMenusAndConfig = false;
14 		public bool PauseWhenInDebuggingTools = false;
15 		public bool AllowBackgroundInput = false;
16 		public bool AutoLoadIpsPatches = true;
17 
18 		public bool DisplayMovieIcons = false;
19 		public bool HidePauseOverlay = false;
20 		public bool AutoHideMenu = false;
21 		public bool DisplayTitleBarInfo = false;
22 
23 		public bool DisableMouseResize = false;
24 
25 		public bool AutoSave = true;
26 		public Int32 AutoSaveDelay = 5;
27 		public bool AutoSaveNotify = false;
28 		public bool AllowMismatchingSaveStates = false;
29 
30 		public bool FdsAutoLoadDisk = true;
31 		public bool FdsFastForwardOnLoad = false;
32 		public bool FdsAutoInsertDisk = false;
33 
34 		public bool AssociateNesFiles = false;
35 		public bool AssociateFdsFiles = false;
36 		public bool AssociateMmoFiles = false;
37 		public bool AssociateNsfFiles = false;
38 		public bool AssociateMstFiles = false;
39 		public bool AssociateUnfFiles = false;
40 
41 		public VsDualOutputOption VsDualVideoOutput = VsDualOutputOption.Both;
42 		public VsDualOutputOption VsDualAudioOutput = VsDualOutputOption.Both;
43 
44 		public bool NsfEnableApuIrqs = false;
45 		public bool NsfMoveToNextTrackAfterTime = true;
46 		public Int32 NsfMoveToNextTrackTime = 120;
47 		public bool NsfAutoDetectSilence = true;
48 		public Int32 NsfAutoDetectSilenceDelay = 3000;
49 		public bool NsfRepeat = false;
50 		public bool NsfShuffle = false;
51 
52 		public bool DisplayDebugInfo = false;
53 
54 		public bool PauseOnMovieEnd = true;
55 		public bool AutomaticallyCheckForUpdates = true;
56 
57 		public bool CloudSaveIntegration = false;
58 		public DateTime CloudLastSync = DateTime.MinValue;
59 
60 		public bool DefaultsInitialized = false;
61 		public List<ShortcutKeyInfo> ShortcutKeys1;
62 		public List<ShortcutKeyInfo> ShortcutKeys2;
63 
64 		public bool AlwaysOnTop = false;
65 
66 		public bool DisableGameDatabase = false;
67 		public bool DisableHighResolutionTimer = false;
68 		public bool DisableOsd = false;
69 
70 		public bool ShowFullPathInRecents = false;
71 
72 		public bool ShowFrameCounter = false;
73 		public bool ShowGameTimer = false;
74 		public bool ShowVsConfigOnLoad = false;
75 
76 		public bool DisableGameSelectionScreen = false;
77 		public bool GameSelectionScreenResetGame = false;
78 
79 		public bool ConfirmExitResetPower = false;
80 
81 		public bool DeveloperMode = false;
82 
83 		public UInt32 RewindBufferSize = 300;
84 
85 		public bool OverrideGameFolder = false;
86 		public bool OverrideAviFolder = false;
87 		public bool OverrideMovieFolder = false;
88 		public bool OverrideSaveDataFolder = false;
89 		public bool OverrideSaveStateFolder = false;
90 		public bool OverrideScreenshotFolder = false;
91 		public bool OverrideWaveFolder = false;
92 
93 		public string GameFolder = "";
94 		public string AviFolder = "";
95 		public string MovieFolder = "";
96 		public string SaveDataFolder = "";
97 		public string SaveStateFolder = "";
98 		public string ScreenshotFolder = "";
99 		public string WaveFolder = "";
100 
PreferenceInfo()101 		public PreferenceInfo()
102 		{
103 		}
104 
InitializeDefaults()105 		public void InitializeDefaults()
106 		{
107 			if(!DefaultsInitialized) {
108 				ShortcutKeys1 = new List<ShortcutKeyInfo>();
109 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.FastForward, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Tab") }));
110 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Rewind, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Backspace") }));
111 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.IncreaseSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("=") }));
112 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.DecreaseSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("-") }));
113 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.MaxSpeed, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F9") }));
114 
115 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.ToggleFps, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F10") }));
116 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.ToggleFullscreen, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F11") }));
117 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.ToggleKeyboardMode, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Scroll Lock") }));
118 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.TakeScreenshot, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F12") }));
119 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadRandomGame, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("Insert") }));
120 
121 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SwitchDiskSide, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("B") }));
122 
123 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Reset, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("R") }));
124 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.PowerCycle, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("T") }));
125 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.Pause, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Esc") }));
126 
127 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale1x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("1") }));
128 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale2x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("2") }));
129 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale3x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("3") }));
130 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale4x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("4") }));
131 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale5x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("5") }));
132 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SetScale6x, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Alt"), Key2 = InteropEmu.GetKeyCode("6") }));
133 
134 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.OpenFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("O") }));
135 
136 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot1, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F1") }));
137 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot2, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F2") }));
138 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot3, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F3") }));
139 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot4, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F4") }));
140 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot5, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F5") }));
141 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot6, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F6") }));
142 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateSlot7, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Shift"), Key2 = InteropEmu.GetKeyCode("F7") }));
143 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.SaveStateToFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("S") }));
144 
145 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot1, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F1") }));
146 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot2, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F2") }));
147 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot3, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F3") }));
148 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot4, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F4") }));
149 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot5, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F5") }));
150 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot6, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F6") }));
151 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlot7, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F7") }));
152 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateSlotAuto, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("F8") }));
153 				ShortcutKeys1.Add(new ShortcutKeyInfo(EmulatorShortcut.LoadStateFromFile, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Ctrl"), Key2 = InteropEmu.GetKeyCode("L") }));
154 
155 				ShortcutKeys2 = new List<ShortcutKeyInfo>();
156 				ShortcutKeys2.Add(new ShortcutKeyInfo(EmulatorShortcut.FastForward, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Pad1 R2") }));
157 				ShortcutKeys2.Add(new ShortcutKeyInfo(EmulatorShortcut.Rewind, new KeyCombination() { Key1 = InteropEmu.GetKeyCode("Pad1 L2") }));
158 			}
159 			DefaultsInitialized = true;
160 		}
161 
ApplyConfig()162 		static public void ApplyConfig()
163 		{
164 			PreferenceInfo preferenceInfo = ConfigManager.Config.PreferenceInfo;
165 
166 			if(Program.IsMono) {
167 				FileAssociationHelper.ConfigureLinuxMimeTypes();
168 			} else {
169 				FileAssociationHelper.UpdateFileAssociation("nes", preferenceInfo.AssociateNesFiles);
170 				FileAssociationHelper.UpdateFileAssociation("fds", preferenceInfo.AssociateFdsFiles);
171 				FileAssociationHelper.UpdateFileAssociation("mmo", preferenceInfo.AssociateMmoFiles);
172 				FileAssociationHelper.UpdateFileAssociation("mst", preferenceInfo.AssociateMstFiles);
173 				FileAssociationHelper.UpdateFileAssociation("nsf", preferenceInfo.AssociateNsfFiles);
174 				FileAssociationHelper.UpdateFileAssociation("nsfe", preferenceInfo.AssociateNsfFiles);
175 				FileAssociationHelper.UpdateFileAssociation("unf", preferenceInfo.AssociateUnfFiles);
176 			}
177 
178 			InteropEmu.SetOsdState(!preferenceInfo.DisableOsd);
179 			InteropEmu.SetGameDatabaseState(!preferenceInfo.DisableGameDatabase);
180 
181 			InteropEmu.SetFlag(EmulationFlags.DeveloperMode, preferenceInfo.DeveloperMode);
182 
183 			InteropEmu.SetFlag(EmulationFlags.FdsAutoLoadDisk, preferenceInfo.FdsAutoLoadDisk);
184 			InteropEmu.SetFlag(EmulationFlags.FdsFastForwardOnLoad, preferenceInfo.FdsFastForwardOnLoad);
185 			InteropEmu.SetFlag(EmulationFlags.FdsAutoInsertDisk, preferenceInfo.FdsAutoInsertDisk);
186 			InteropEmu.SetFlag(EmulationFlags.PauseOnMovieEnd, preferenceInfo.PauseOnMovieEnd);
187 			InteropEmu.SetFlag(EmulationFlags.AllowBackgroundInput, preferenceInfo.AllowBackgroundInput);
188 			InteropEmu.SetFlag(EmulationFlags.UseHighResolutionTimer, !preferenceInfo.DisableHighResolutionTimer);
189 			InteropEmu.SetFlag(EmulationFlags.AllowMismatchingSaveStates, preferenceInfo.AllowMismatchingSaveStates);
190 
191 			InteropEmu.SetFlag(EmulationFlags.ShowFrameCounter, preferenceInfo.ShowFrameCounter);
192 			InteropEmu.SetFlag(EmulationFlags.ShowGameTimer, preferenceInfo.ShowGameTimer);
193 
194 			InteropEmu.SetFlag(EmulationFlags.HidePauseOverlay, preferenceInfo.HidePauseOverlay);
195 			InteropEmu.SetFlag(EmulationFlags.DisplayMovieIcons, preferenceInfo.DisplayMovieIcons);
196 			InteropEmu.SetFlag(EmulationFlags.DisableGameSelectionScreen, preferenceInfo.DisableGameSelectionScreen);
197 			InteropEmu.SetFlag(EmulationFlags.ConfirmExitResetPower, preferenceInfo.ConfirmExitResetPower);
198 
199 			InteropEmu.NsfSetNsfConfig(preferenceInfo.NsfAutoDetectSilence ? preferenceInfo.NsfAutoDetectSilenceDelay : 0, preferenceInfo.NsfMoveToNextTrackAfterTime ? preferenceInfo.NsfMoveToNextTrackTime : -1, !preferenceInfo.NsfEnableApuIrqs);
200 			InteropEmu.SetFlag(EmulationFlags.NsfRepeat, preferenceInfo.NsfRepeat);
201 			InteropEmu.SetFlag(EmulationFlags.NsfShuffle, preferenceInfo.NsfShuffle);
202 
203 			InteropEmu.SetFlag(EmulationFlags.DisplayDebugInfo, preferenceInfo.DisplayDebugInfo);
204 
205 			InteropEmu.SetFlag(EmulationFlags.VsDualMuteMaster, preferenceInfo.VsDualAudioOutput == VsDualOutputOption.SlaveOnly);
206 			InteropEmu.SetFlag(EmulationFlags.VsDualMuteSlave, preferenceInfo.VsDualAudioOutput == VsDualOutputOption.MasterOnly);
207 
208 			InteropEmu.SetAutoSaveOptions(preferenceInfo.AutoSave ? (uint)preferenceInfo.AutoSaveDelay : 0, preferenceInfo.AutoSaveNotify);
209 
210 			InteropEmu.ClearShortcutKeys();
211 			foreach(ShortcutKeyInfo shortcutInfo in preferenceInfo.ShortcutKeys1) {
212 				InteropEmu.SetShortcutKey(shortcutInfo.Shortcut, shortcutInfo.KeyCombination, 0);
213 			}
214 			foreach(ShortcutKeyInfo shortcutInfo in preferenceInfo.ShortcutKeys2) {
215 				InteropEmu.SetShortcutKey(shortcutInfo.Shortcut, shortcutInfo.KeyCombination, 1);
216 			}
217 
218 			InteropEmu.SetRewindBufferSize(preferenceInfo.RewindBufferSize);
219 
220 			InteropEmu.SetFolderOverrides(ConfigManager.SaveFolder, ConfigManager.SaveStateFolder, ConfigManager.ScreenshotFolder);
221 		}
222 	}
223 
224 	public class ShortcutKeyInfo
225 	{
226 		public EmulatorShortcut Shortcut;
227 		public KeyCombination KeyCombination;
228 
ShortcutKeyInfo()229 		public ShortcutKeyInfo() { }
230 
ShortcutKeyInfo(EmulatorShortcut key, KeyCombination keyCombination)231 		public ShortcutKeyInfo(EmulatorShortcut key, KeyCombination keyCombination)
232 		{
233 			Shortcut = key;
234 			KeyCombination = keyCombination;
235 		}
236 	}
237 
238 	public enum VsDualOutputOption
239 	{
240 		Both = 0,
241 		MasterOnly = 1,
242 		SlaveOnly = 2
243 	}
244 }
245