From 5580a8a7a8bfe91f88a9d38d4c6e9289cf43e2d7 Mon Sep 17 00:00:00 2001 From: JoshD Date: Mon, 18 Jul 2016 17:28:10 -0700 Subject: [PATCH] Changed settings storage to use the settings framework rather than rolling my own; this makes per-user settings work and fixes permission issues for non-admin users. Also made a small tweak to make the mouse work properly in high-dpi scenarios. --- Contralto/App.config | 51 ++++++- Contralto/Configuration.cs | 160 ++++---------------- Contralto/Contralto.csproj | 16 +- Contralto/Properties/AssemblyInfo.cs | 8 +- Contralto/Properties/Settings.Designer.cs | 170 ++++++++++++++++++++++ Contralto/Properties/Settings.settings | 42 ++++++ Contralto/UI/AltoWindow.cs | 3 +- Contralto/UI/SystemOptions.cs | 5 +- Contralto/app.manifest | 75 ++++++++++ 9 files changed, 384 insertions(+), 146 deletions(-) create mode 100644 Contralto/Properties/Settings.Designer.cs create mode 100644 Contralto/Properties/Settings.settings create mode 100644 Contralto/app.manifest diff --git a/Contralto/App.config b/Contralto/App.config index 8e15646..d226eef 100644 --- a/Contralto/App.config +++ b/Contralto/App.config @@ -1,6 +1,51 @@ - + + + +
+ + - + - \ No newline at end of file + + + + + + + 2 + + + + + + + + + 34 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + False + + + True + + + + diff --git a/Contralto/Configuration.cs b/Contralto/Configuration.cs index 14d622f..a8490da 100644 --- a/Contralto/Configuration.cs +++ b/Contralto/Configuration.cs @@ -192,154 +192,46 @@ namespace Contralto public static string GetRomPath(string romFileName) { return Path.Combine("ROM", romFileName); - } + } /// - /// Reads the current configuration file from disk. + /// Reads the current configuration file from the app's configuration. /// /// TODO: use reflection to do this. /// public static void ReadConfiguration() { - try - { - using (StreamReader configStream = new StreamReader("contralto.cfg")) - { - // - // Config file consists of text lines containing name / value pairs: - // - // Whitespace is ignored - // - int lineNumber = 0; - while (!configStream.EndOfStream) - { - lineNumber++; - string line = configStream.ReadLine().Trim(); - - if (string.IsNullOrEmpty(line)) - { - continue; - } - - // Find whitespace separating tokens - int ws = line.IndexOfAny(new char[] { ' ', '\t' }); - - if (ws < 1) - { - Log.Write(LogType.Warning, LogComponent.Configuration, "Syntax error on line {0}. Ignoring.", lineNumber); - continue; - } - - string parameter = line.Substring(0, ws); - string value = line.Substring(ws + 1, line.Length - ws - 1); - - try - { - switch (parameter.ToLowerInvariant()) - { - case "drive0image": - Drive0Image = value; - break; - - case "drive1image": - Drive1Image = value; - break; - - case "systemtype": - SystemType = (SystemType)Enum.Parse(typeof(SystemType), value, true); - break; - - case "hostaddress": - HostAddress = Convert.ToByte(value, 8); - break; - - case "hostpacketinterfacename": - HostPacketInterfaceName = value; - break; - - case "hostpacketinterfacetype": - HostPacketInterfaceType = (PacketInterfaceType)Enum.Parse(typeof(PacketInterfaceType), value, true); - break; - - case "alternateboottype": - AlternateBootType = (AlternateBootType)Enum.Parse(typeof(AlternateBootType), value, true); - break; - - case "bootaddress": - BootAddress = Convert.ToUInt16(value, 8); - break; - - case "bootfile": - BootFile = Convert.ToUInt16(value, 8); - break; - - case "interlacedisplay": - InterlaceDisplay = bool.Parse(value); - break; - - case "throttlespeed": - ThrottleSpeed = bool.Parse(value); - break; - - default: - Log.Write(LogType.Warning, LogComponent.Configuration, "Invalid parameter on line {0}. Ignoring.", lineNumber); - break; - } - } - catch - { - Log.Write(LogType.Warning, LogComponent.Configuration, "Invalid value on line {0}. Ignoring.", lineNumber); - continue; - } - } - } - } - catch (Exception) - { - Log.Write(LogType.Warning, LogComponent.Configuration, "Configuration file 'contralto.cfg' could not be read; assuming default settings."); - WriteConfiguration(); - } + Drive0Image = (string)Properties.Settings.Default["Drive0Image"]; + Drive1Image = (string)Properties.Settings.Default["Drive1Image"]; + SystemType = (SystemType)Properties.Settings.Default["SystemType"]; + HostAddress = (byte)Properties.Settings.Default["HostAddress"]; + HostPacketInterfaceName = (string)Properties.Settings.Default["HostPacketInterfaceName"]; + HostPacketInterfaceType = (PacketInterfaceType)Properties.Settings.Default["HostPacketInterfaceType"]; + AlternateBootType = (AlternateBootType)Properties.Settings.Default["AlternateBootType"]; + BootAddress = (ushort)Properties.Settings.Default["BootAddress"]; + BootFile = (ushort)Properties.Settings.Default["BootFile"]; + InterlaceDisplay = (bool)Properties.Settings.Default["InterlaceDisplay"]; + ThrottleSpeed = (bool)Properties.Settings.Default["ThrottleSpeed"]; } /// - /// Commits the current configuration to disk. + /// Commits the current configuration to the app's settings. /// public static void WriteConfiguration() { - try - { - using (StreamWriter configStream = new StreamWriter("contralto.cfg")) - { - if (!string.IsNullOrEmpty(Drive0Image)) - { - configStream.WriteLine("Drive0Image {0}", Drive0Image); - } + Properties.Settings.Default["Drive0Image"] = Drive0Image; + Properties.Settings.Default["Drive1Image"] = Drive1Image; + Properties.Settings.Default["SystemType"] = (int)SystemType; + Properties.Settings.Default["HostAddress"] = HostAddress; + Properties.Settings.Default["HostPacketInterfaceName"] = HostPacketInterfaceName; + Properties.Settings.Default["HostPacketInterfaceType"] = (int)HostPacketInterfaceType; + Properties.Settings.Default["AlternateBootType"] = (int)AlternateBootType; + Properties.Settings.Default["BootAddress"] = BootAddress; + Properties.Settings.Default["BootFile"] = BootFile; + Properties.Settings.Default["InterlaceDisplay"] = InterlaceDisplay; + Properties.Settings.Default["ThrottleSpeed"] = ThrottleSpeed; - if (!string.IsNullOrEmpty(Drive1Image)) - { - configStream.WriteLine("Drive1Image {0}", Drive1Image); - } - - configStream.WriteLine("SystemType {0}", SystemType); - configStream.WriteLine("HostAddress {0}", Conversion.ToOctal(HostAddress)); - - if (!string.IsNullOrEmpty(HostPacketInterfaceName)) - { - configStream.WriteLine("HostPacketInterfaceName {0}", HostPacketInterfaceName); - } - - configStream.WriteLine("HostPacketInterfaceType {0}", HostPacketInterfaceType); - configStream.WriteLine("AlternateBootType {0}", AlternateBootType); - configStream.WriteLine("BootAddress {0}", Conversion.ToOctal(BootAddress)); - configStream.WriteLine("BootFile {0}", Conversion.ToOctal(BootFile)); - configStream.WriteLine("InterlaceDisplay {0}", InterlaceDisplay); - configStream.WriteLine("ThrottleSpeed {0}", ThrottleSpeed); - } - } - catch (Exception) - { - Log.Write(LogType.Warning, LogComponent.Configuration, "Configuration file 'contralto.cfg' could not be opened for writing."); - } + Properties.Settings.Default.Save(); } } diff --git a/Contralto/Contralto.csproj b/Contralto/Contralto.csproj index 885427a..cbd55aa 100644 --- a/Contralto/Contralto.csproj +++ b/Contralto/Contralto.csproj @@ -9,7 +9,7 @@ Properties Contralto Contralto - v4.5 + v4.6 512 publish\ true @@ -26,6 +26,7 @@ false false true + AnyCPU @@ -89,6 +90,9 @@ Alto.ico + + app.manifest + False @@ -126,6 +130,11 @@ True Resources.resx + + True + True + Settings.settings + Form @@ -197,6 +206,7 @@ + @@ -259,6 +269,10 @@ PreserveNewest + + SettingsSingleFileGenerator + Settings.Designer.cs + PreserveNewest diff --git a/Contralto/Properties/AssemblyInfo.cs b/Contralto/Properties/AssemblyInfo.cs index d937755..0066d30 100644 --- a/Contralto/Properties/AssemblyInfo.cs +++ b/Contralto/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Contralto")] +[assembly: AssemblyTitle("ContrAlto")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Vulcan Inc.")] -[assembly: AssemblyProduct("Contralto")] -[assembly: AssemblyCopyright("Copyright © Vulcan Inc. 2015")] +[assembly: AssemblyCompany("Living Computer Museum")] +[assembly: AssemblyProduct("ContrAlto")] +[assembly: AssemblyCopyright("Copyright © Living Computer Museum 2016")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Contralto/Properties/Settings.Designer.cs b/Contralto/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c6bebc4 --- /dev/null +++ b/Contralto/Properties/Settings.Designer.cs @@ -0,0 +1,170 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Contralto.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("2")] + public int SystemType { + get { + return ((int)(this["SystemType"])); + } + set { + this["SystemType"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Drive0Image { + get { + return ((string)(this["Drive0Image"])); + } + set { + this["Drive0Image"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Drive1Image { + get { + return ((string)(this["Drive1Image"])); + } + set { + this["Drive1Image"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("34")] + public byte HostAddress { + get { + return ((byte)(this["HostAddress"])); + } + set { + this["HostAddress"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string HostPacketInterfaceName { + get { + return ((string)(this["HostPacketInterfaceName"])); + } + set { + this["HostPacketInterfaceName"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int HostPacketInterfaceType { + get { + return ((int)(this["HostPacketInterfaceType"])); + } + set { + this["HostPacketInterfaceType"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int AlternateBootType { + get { + return ((int)(this["AlternateBootType"])); + } + set { + this["AlternateBootType"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public ushort BootAddress { + get { + return ((ushort)(this["BootAddress"])); + } + set { + this["BootAddress"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public ushort BootFile { + get { + return ((ushort)(this["BootFile"])); + } + set { + this["BootFile"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool InterlaceDisplay { + get { + return ((bool)(this["InterlaceDisplay"])); + } + set { + this["InterlaceDisplay"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ThrottleSpeed { + get { + return ((bool)(this["ThrottleSpeed"])); + } + set { + this["ThrottleSpeed"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public string EnableWindowsFormsHighDpiAutoResizing { + get { + return ((string)(this["EnableWindowsFormsHighDpiAutoResizing"])); + } + set { + this["EnableWindowsFormsHighDpiAutoResizing"] = value; + } + } + } +} diff --git a/Contralto/Properties/Settings.settings b/Contralto/Properties/Settings.settings new file mode 100644 index 0000000..bf5102b --- /dev/null +++ b/Contralto/Properties/Settings.settings @@ -0,0 +1,42 @@ + + + + + + 2 + + + + + + + + + 34 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + False + + + True + + + True + + + \ No newline at end of file diff --git a/Contralto/UI/AltoWindow.cs b/Contralto/UI/AltoWindow.cs index 4cdb84c..45ce748 100644 --- a/Contralto/UI/AltoWindow.cs +++ b/Contralto/UI/AltoWindow.cs @@ -645,7 +645,6 @@ namespace Contralto return; } - // We implement a crude "mouse capture" behavior by forcing the mouse cursor to the // center of the display window and taking the delta of the last movement and using it // to move the Alto's mouse. @@ -663,7 +662,7 @@ namespace Contralto // Don't handle the very next Mouse Move event (which will just be the motion we caused in the // below line...) - //_skipNextMouseMove = true; + _skipNextMouseMove = true; Cursor.Position = DisplayBox.PointToScreen(middle); } diff --git a/Contralto/UI/SystemOptions.cs b/Contralto/UI/SystemOptions.cs index 10b0daf..055aab9 100644 --- a/Contralto/UI/SystemOptions.cs +++ b/Contralto/UI/SystemOptions.cs @@ -230,8 +230,9 @@ namespace Contralto.UI // // First warn the user of changes that require a restart. // - if (Configuration.HostPacketInterfaceName != iface.Description || - Configuration.HostPacketInterfaceType != _selectedInterfaceType || + if ((!(String.IsNullOrEmpty(Configuration.HostPacketInterfaceName) && EthernetInterfaceListBox.SelectedIndex == 0) && + (Configuration.HostPacketInterfaceName != iface.Description || + Configuration.HostPacketInterfaceType != _selectedInterfaceType)) || Configuration.SystemType != _selectedSystemType) { MessageBox.Show("Changes to CPU or host Ethernet configuration will not take effect until ContrAlto is restarted."); diff --git a/Contralto/app.manifest b/Contralto/app.manifest new file mode 100644 index 0000000..ef8ac3a --- /dev/null +++ b/Contralto/app.manifest @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + +