-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serial PortName now comes from the UARTReplacement.dll.config files i…
…n the CSpect directory.
- Loading branch information
1 parent
4a42f26
commit 1db8219
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace Plugins.UARTReplacement | ||
{ | ||
public class Settings | ||
{ | ||
public string PortName { get; set; } | ||
|
||
public Settings() | ||
{ | ||
PortName = "COM1"; | ||
} | ||
|
||
public string ToXML() | ||
{ | ||
string output = ""; | ||
var xmlSerializer = new XmlSerializer(GetType()); | ||
using (var memoryStream = new MemoryStream()) | ||
using (var xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8)) | ||
{ | ||
xmlTextWriter.Formatting = Formatting.Indented; | ||
xmlSerializer.Serialize(xmlTextWriter, this); | ||
output = Encoding.UTF8.GetString(memoryStream.ToArray()); | ||
string _byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); | ||
if (output.StartsWith(_byteOrderMarkUtf8)) | ||
output = output.Remove(0, _byteOrderMarkUtf8.Length); | ||
} | ||
return output; | ||
} | ||
|
||
public static Settings Load(string OptionalFileNameAndPath = null) | ||
{ | ||
Settings settings; | ||
try | ||
{ | ||
string fn = string.IsNullOrWhiteSpace(OptionalFileNameAndPath) ? GetFileName() : OptionalFileNameAndPath; | ||
string xml = File.ReadAllText(fn); | ||
var reader = new StringReader(xml); | ||
using (reader) | ||
{ | ||
var serializer = new XmlSerializer(typeof(Settings)); | ||
settings = (Settings)serializer.Deserialize(reader); | ||
reader.Close(); | ||
} | ||
} | ||
catch (Exception /*ex*/) | ||
{ | ||
settings = new Settings(); | ||
} | ||
return settings; | ||
} | ||
|
||
public bool Save(string OptionalFileNameAndPath = null) | ||
{ | ||
try | ||
{ | ||
string fn = string.IsNullOrWhiteSpace(OptionalFileNameAndPath) ? GetFileName() : OptionalFileNameAndPath; | ||
File.WriteAllText(fn, ToXML()); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static string GetFileName() | ||
{ | ||
string path = AppDomain.CurrentDomain.BaseDirectory; | ||
var dll = Assembly.GetAssembly(typeof(Settings)).ManifestModule.ScopeName + ".config"; | ||
return Path.Combine(path, dll); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<PortName>COM1</PortName> | ||
</Settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters