TC2 settings can now be restored
This commit is contained in:
1 parent
4c507aae4e
commit
32b769bdaa
5 files changed
+45
-9
No files matched your search
@@ -1,4 +1,6 @@
|
||||
namespace mbts.spark {
|
||||
using BCG;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
@@ -15,11 +17,11 @@ namespace mbts.spark {
|
||||
public BCG.NMSheetSettings value { get; set; }
|
||||
|
||||
// TODO: Convert NMSheetSettings to a normal protobuf settings type (then remove json prop)
|
||||
[Obsolete]
|
||||
//[Obsolete]
|
||||
[ProtoMember(1)]
|
||||
public string value_json {
|
||||
get => JsonSerializer.Serialize(value);
|
||||
set => this.value = JsonSerializer.Deserialize<BCG.NMSheetSettings>(value);
|
||||
get => BCG.CommonGUIUtilities.bin_serialize_str(value);
|
||||
set => this.value = BCG.CommonGUIUtilities.bin_deserialize_str<BCG.NMSheetSettings>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace mbts.spark {
|
||||
using BCG;
|
||||
|
||||
using bts.api;
|
||||
|
||||
using mbts;
|
||||
@@ -13,7 +15,7 @@
|
||||
readonly OptionsViewSettings _settings;
|
||||
readonly IBus _bus;
|
||||
|
||||
System.Windows.Forms.Control _view;
|
||||
NMSheetControl _view;
|
||||
|
||||
public OptionsViewWindow(
|
||||
OptionsViewWindowFactory factory, IBus bus, OptionsViewSettings settings) :
|
||||
@@ -34,6 +36,8 @@
|
||||
Disposable.dispose(ref _view);
|
||||
|
||||
protected override OptionsViewSettings _get_state() =>
|
||||
_settings;
|
||||
new OptionsViewSettings() {
|
||||
value = _view.get_setting()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
using Microsoft.Scripting.Utils;
|
||||
using System.Linq;
|
||||
using bts.api;
|
||||
using System.Text;
|
||||
|
||||
namespace BCG {
|
||||
public class CommonGUIUtilities {
|
||||
@@ -164,6 +167,19 @@ namespace BCG {
|
||||
#pragma warning restore SYSLIB0011
|
||||
}
|
||||
|
||||
public static byte[] bin_serialize<T>(T t) {
|
||||
MemoryStream str = new MemoryStream();
|
||||
bin_serialize(t, str);
|
||||
str.Position = 0;
|
||||
return str.ToArray();
|
||||
}
|
||||
|
||||
public static string bin_serialize_str<T>(T t) {
|
||||
byte[] data = bin_serialize<T>(t);
|
||||
return new string(data.Select(b => (char)b).ToArray());
|
||||
//return System.Text.Encoding.ASCII.GetString(data);
|
||||
}
|
||||
|
||||
public static T bin_deserialize<T>(Stream str) {
|
||||
#pragma warning disable SYSLIB0011
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
@@ -172,6 +188,18 @@ namespace BCG {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static T bin_deserialize<T>(byte[] b) {
|
||||
MemoryStream str = new MemoryStream(b);
|
||||
return bin_deserialize<T>(str);
|
||||
}
|
||||
|
||||
public static T bin_deserialize_str<T>(string str) {
|
||||
byte[] data = str.ToCharArray().Select(c => (byte)c).ToArray();
|
||||
return bin_deserialize<T>(data);
|
||||
// byte[] data = System.Text.Encoding.ASCII.GetBytes(str);
|
||||
// return bin_deserialize<T>(data);
|
||||
}
|
||||
|
||||
public static T basic_deep_clone<T>(T t) {
|
||||
try {
|
||||
MemoryStream str = new MemoryStream();
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace BCG {
|
||||
// System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
// formatter.Serialize(str, _settings);
|
||||
// str.Close();
|
||||
string json_txt = JsonSerializer.Serialize(_settings);
|
||||
string json_txt = CommonGUIUtilities.bin_serialize_str(_settings);
|
||||
System.IO.File.WriteAllText(diag.FileName, json_txt);
|
||||
}
|
||||
} catch (Exception ex) { MessageBox.Show(String.Format("Could not save settings\n{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
|
||||
@@ -111,7 +111,7 @@ namespace BCG {
|
||||
// System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
// NMSheetSettings new_settings = formatter.Deserialize(str) as NMSheetSettings;
|
||||
string json_txt = System.IO.File.ReadAllText(diag.FileName);
|
||||
NMSheetSettings new_settings = JsonSerializer.Deserialize<NMSheetSettings>(json_txt);
|
||||
NMSheetSettings new_settings = CommonGUIUtilities.bin_deserialize_str<NMSheetSettings>(json_txt);
|
||||
NMSheetSettings.handle_bad_data(new_settings);
|
||||
new_settings.setting_option_list = _settings.setting_option_list;
|
||||
new_settings.setting_quoter = _settings.setting_quoter;
|
||||
|
||||
@@ -61,7 +61,9 @@ namespace BCG {
|
||||
private NMSheetControl() { InitializeComponent(); }
|
||||
|
||||
private void _insert_symbol(NMSheetSettings settings) {
|
||||
settings.setting_option_list.Add(new NMSheetSymbol(Venue.Sim, "BTC"));
|
||||
// temporary
|
||||
if (settings.setting_option_list.Count == 0)
|
||||
settings.setting_option_list.Add(new NMSheetSymbol(Venue.Sim, "BTC"));
|
||||
}
|
||||
|
||||
public NMSheetControl(IBus bus, IShellWindow parent_window, NMSheetSettings settings)
|
||||
|
||||
Reference in new issue
Block a user