- add change language
- refract code
This commit is contained in:
Alex Z 2020-01-20 06:48:05 +03:00
parent 78d49fd579
commit 36c1339a93
21 changed files with 674 additions and 243 deletions

View File

@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace UniversalValveToolbox.Base {
public abstract class DtoModel : INotifyPropertyChanged {
protected bool UpdateField<T>(T value, ref T field, [CallerMemberName]string name = null) {
var updated = !EqualityComparer<T>.Default.Equals(value, field);
if (updated) {
field = value;
OnPropertyChanged(name);
}
return updated;
}
protected void OnPropertyChanged([CallerMemberName]string name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@ -0,0 +1,37 @@
using UniversalValveToolbox.Base;
namespace UniversalValveToolbox.Utils.Dto {
public class AddonDtoModel : DtoModel {
private int[] engine;
private string args;
private string bin;
private string name;
private string category;
public int[] Engine {
get => this.engine;
set => this.UpdateField(value, ref this.engine);
}
public string Name {
get => this.name;
set => this.UpdateField(value, ref this.name);
}
public string Category {
get => this.category;
set => this.UpdateField(value, ref this.category);
}
public string Bin {
get => this.bin;
set => this.UpdateField(value, ref this.bin);
}
public string Args {
get => this.args;
set => this.UpdateField(value, ref this.args);
}
}
}

View File

@ -0,0 +1,30 @@
using UniversalValveToolbox.Base;
namespace UniversalValveToolbox.Model.Dto {
public class EngineDtoModel : DtoModel {
private int appid;
private string name;
private string bin;
private ToolDtoModel[] tools;
public int Appid {
get => appid;
set => UpdateField(value, ref appid);
}
public string Name {
get => name;
set => UpdateField(value, ref name);
}
public string Bin {
get => bin;
set => UpdateField(value, ref bin);
}
public ToolDtoModel[] Tools {
get => tools;
set => UpdateField(value, ref tools);
}
}
}

View File

@ -0,0 +1,36 @@
using UniversalValveToolbox.Base;
namespace UniversalValveToolbox.Model.Dto {
public class SettingsDtoModel : DtoModel {
private string defaultProject;
private int[] availableEnginies;
private string[] availableLanguages;
private string language;
private string theme;
public string DefaultProject {
get => defaultProject;
set => UpdateField(value, ref defaultProject);
}
public int[] AvailableEnginies {
get => availableEnginies;
set => UpdateField(value, ref availableEnginies);
}
public string[] AvailableLanguages {
get => availableLanguages;
set => UpdateField(value, ref availableLanguages);
}
public string Language {
get => language;
set => UpdateField(value, ref language);
}
public string Theme {
get => theme;
set => UpdateField(value, ref theme);
}
}
}

View File

@ -0,0 +1,24 @@
using UniversalValveToolbox.Base;
namespace UniversalValveToolbox.Model.Dto {
public class ToolDtoModel : DtoModel {
private string args;
private string bin;
private string name;
public string Args {
get => args;
set => UpdateField(value, ref args);
}
public string Bin {
get => bin;
set => UpdateField(value, ref bin);
}
public string Name {
get => name;
set => UpdateField(value, ref name);
}
}
}

View File

@ -0,0 +1,30 @@
using UniversalValveToolbox.Base;
namespace UniversalValveToolbox.Model.Dto {
public class VProjectDtoModel : DtoModel {
private int engine;
private string path;
private string name;
private string args;
public int Engine {
get => engine;
set => UpdateField(value, ref engine);
}
public string Path {
get => path;
set => UpdateField(value, ref path);
}
public string Name {
get => name;
set => UpdateField(value, ref name);
}
public string Args {
get => args;
set => UpdateField(value, ref args);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Newtonsoft.Json;
using UniversalValveToolbox.Model.Dto;
using UniversalValveToolbox.Utils;
namespace UniversalValveToolbox.Model.Provider {
class DataProvider {
private readonly string SettingsPath = Path.Combine(Application.StartupPath, "json", "settings.json");
public SettingsDtoModel Settings {
get => JsonFileUtil.ReadValue<SettingsDtoModel>(SettingsPath);
set => JsonFileUtil.WriteValue(SettingsPath, value);
}
}
}

View File

@ -0,0 +1,7 @@
using UniversalValveToolbox.Properties.translations;
namespace UniversalValveToolbox.Model.Provider {
public class LanguageProvider {
public string[] Languages { get; } = { LangDict.en_US, LangDict.ru_RU };
}
}

View File

@ -0,0 +1,32 @@
using System;
using UniversalValveToolbox.Base;
using UniversalValveToolbox.Model.Dto;
using UniversalValveToolbox.Model.Provider;
namespace UniversalValveToolbox.Model.VIewModel {
public class SettingsViewModel : DtoModel {
private readonly SettingsDtoModel settings;
private readonly LanguageProvider languageProvider;
private int selectedLanguage;
public int SelectedLanguageIndex {
get => selectedLanguage;
set {
if (UpdateField(value, ref selectedLanguage)) {
settings.Language = settings.AvailableLanguages[selectedLanguage];
}
}
}
public string[] Languages => languageProvider.Languages;
private string SelectedLanguage => Languages[SelectedLanguageIndex];
public SettingsViewModel(SettingsDtoModel settings, LanguageProvider languageProvider) {
this.settings = settings;
this.languageProvider = languageProvider;
SelectedLanguageIndex = Math.Max(0, Array.IndexOf(settings.AvailableLanguages, settings.Language));
}
}
}

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using UniversalValveToolbox.Model.Provider;
using UniversalValveToolbox.Utils;
namespace UniversalValveToolbox { namespace UniversalValveToolbox {
static class Program { static class Program {
@ -8,6 +10,11 @@ namespace UniversalValveToolbox {
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() { static void Main() {
var dataProvide = new DataProvider();
var currSettings = dataProvide.Settings;
LanguageManager.UpdateLanguage(currSettings.Language);
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormMain()); Application.Run(new FormMain());

View File

@ -0,0 +1,81 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace UniversalValveToolbox.Properties.translations {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class LangDict {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal LangDict() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UniversalValveToolbox.Properties.translations.LangDict", typeof(LangDict).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to English.
/// </summary>
internal static string en_US {
get {
return ResourceManager.GetString("en-US", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Russian.
/// </summary>
internal static string ru_RU {
get {
return ResourceManager.GetString("ru-RU", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="en-US" xml:space="preserve">
<value>English</value>
</data>
<data name="ru-RU" xml:space="preserve">
<value>Russian</value>
</data>
</root>

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="en-US" xml:space="preserve">
<value>Английский</value>
</data>
<data name="ru-RU" xml:space="preserve">
<value>Русский</value>
</data>
</root>

View File

@ -2,8 +2,9 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Forms; using System.Windows.Forms;
using UniversalValveToolbox.Model.Provider;
using UniversalValveToolbox.Model.VIewModel;
using UniversalValveToolbox.Utils; using UniversalValveToolbox.Utils;
using UniversalValveToolbox.Utils.Dto;
namespace UniversalValveToolbox { namespace UniversalValveToolbox {
public partial class FormMain : Form { public partial class FormMain : Form {
@ -107,8 +108,8 @@ namespace UniversalValveToolbox {
} }
private void OpenSettings() { private void OpenSettings() {
var dataManager = new DataManager(); var dataManager = new DataProvider();
var settingsDto = dataManager.ReadSettings(); var settingsDto = dataManager.Settings;
var languageProvider = new LanguageProvider(); var languageProvider = new LanguageProvider();
var settingsModel = new SettingsViewModel(settingsDto, languageProvider); var settingsModel = new SettingsViewModel(settingsDto, languageProvider);
@ -116,7 +117,8 @@ namespace UniversalValveToolbox {
var frmSettings = new FormSettings(settingsModel); var frmSettings = new FormSettings(settingsModel);
if (frmSettings.ShowDialog() == DialogResult.OK) { if (frmSettings.ShowDialog() == DialogResult.OK) {
dataManager.SaveSettings(settingsDto); dataManager.Settings = settingsDto;
Application.Restart();
} }
} }
} }

View File

@ -1,18 +1,24 @@
using kasthack.binding.wf; using kasthack.binding.wf;
using System; using System;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using UniversalValveToolbox.Utils.Dto; using UniversalValveToolbox.Model.VIewModel;
namespace UniversalValveToolbox { namespace UniversalValveToolbox {
public partial class FormSettings : Form { public partial class FormSettings : Form {
public FormSettings(SettingsViewModel settings) { public FormSettings(SettingsViewModel settings) {
InitializeComponent(); InitializeComponent();
comboBoxLang.SelectedIndex = 0; comboBoxLang.Items.Clear();
comboBoxLang.Items.AddRange(settings.Languages);
comboBoxLang.Bind(a => a.SelectedIndex, settings, a => a.SelectedLanguageIndex);
comboBoxTheme.SelectedIndex = 0; comboBoxTheme.SelectedIndex = 0;
comboBoxLang.Bind(a => a.DataSource, settings, a => a.Languages);
comboBoxLang.Bind(a => a.SelectedIndex, settings, a => a.SelectedLanguageIndex); //comboBoxLang.Bind(a => a.DataSource, settings, a => a.Languages);
//comboBoxLang.SelectedIndex = settings.SelectedLanguageIndex;
//this.Bind(a => a.Text, settings, a => a.Language); //this.Bind(a => a.Text, settings, a => a.Language);

View File

@ -60,6 +60,16 @@
<Reference Include="WindowsFormsIntegration" /> <Reference Include="WindowsFormsIntegration" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\translations\LangDict.Designer.cs">
<DependentUpon>LangDict.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Properties\translations\LangDict.ru.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>LangDict.ru.resx</DependentUpon>
</Compile>
<Compile Include="UI\FormAbout.cs"> <Compile Include="UI\FormAbout.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -117,8 +127,26 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>MessageBoxes.resx</DependentUpon> <DependentUpon>MessageBoxes.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Utils\JsonReader.cs" /> <Compile Include="Model\Dto\AddonDtoModel.cs" />
<Compile Include="Model\Provider\DataProvider.cs" />
<Compile Include="Model\Dto\EngineDtoModel.cs" />
<Compile Include="Base\DtoModel.cs" />
<Compile Include="Utils\JsonFileUtil.cs" />
<Compile Include="Utils\LanguageManager.cs" />
<Compile Include="Model\Dto\ToolDtoModel.cs" />
<Compile Include="Model\VIewModel\SettingsViewModel.cs" />
<Compile Include="Model\Dto\SettingsDtoModel.cs" />
<Compile Include="Model\Provider\LanguageProvider.cs" />
<Compile Include="Utils\VersionHelper.cs" /> <Compile Include="Utils\VersionHelper.cs" />
<Compile Include="Model\Dto\VProjectDtoModel.cs" />
<EmbeddedResource Include="Properties\translations\LangDict.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>LangDict.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\translations\LangDict.ru.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>LangDict.ru.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UI\FormAbout.resx"> <EmbeddedResource Include="UI\FormAbout.resx">
<DependentUpon>FormAbout.cs</DependentUpon> <DependentUpon>FormAbout.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
@ -166,28 +194,28 @@
<LastGenOutput>MessageBoxes.Designer.cs</LastGenOutput> <LastGenOutput>MessageBoxes.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<None Include="json\addons\myOtherProgram.json"> <None Include="json\addons\myOtherProgram.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\addons\myProgram.json"> <None Include="json\addons\myProgram.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\engines\496450.json"> <None Include="json\engines\496450.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\engines\254430.json"> <None Include="json\engines\254430.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\engines\243750.json"> <None Include="json\engines\243750.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\engines\243730.json"> <None Include="json\engines\243730.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\projects\test project.json"> <None Include="json\projects\test project.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="json\settings.json"> <None Include="json\settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>

View File

@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UniversalValveToolbox.Utils {
static class JsonFileUtil {
public static T ReadValue<T>(string path) => JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
public static void WriteValue<T>(string path, T value) => File.WriteAllText(path, JsonConvert.SerializeObject(value, Formatting.Indented));
}
}

View File

@ -1,219 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using UniversalValveToolbox.Utils.Dto;
using Newtonsoft.Json;
namespace UniversalValveToolbox.Utils {
class DataManager {
private readonly string SettingsPath = Path.Combine(Application.StartupPath, "json", "settings.json");
public Settings ReadSettings() => this.ReadModel<Settings>(SettingsPath);
public void SaveSettings(Settings settingsDto) => this.WriteModel(SettingsPath, settingsDto);
private T ReadModel<T>(string path) => JsonConvert.DeserializeObject<T>(File.ReadAllText(path));
private void WriteModel<T>(string path, T value) => File.WriteAllText(path, JsonConvert.SerializeObject(value, Formatting.Indented));
}
}
namespace UniversalValveToolbox.Utils.Dto {
public class Addon : BaseModel {
private int[] engine;
private string args;
private string bin;
private string name;
public int[] Engine {
get => this.engine;
set => this.UpdateField(value, ref this.engine);
}
public string Name {
get => this.name;
set => this.UpdateField(value, ref this.name);
}
private string category;
public string Category {
get => this.category;
set => this.UpdateField(value, ref this.category);
}
public string Bin {
get => this.bin;
set => this.UpdateField(value, ref this.bin);
}
public string Args {
get => this.args;
set => this.UpdateField(value, ref this.args);
}
}
public class Engine : BaseModel {
private int appid;
public int Appid {
get => this.appid;
set => this.UpdateField(value, ref this.appid);
}
private string name;
public string Name {
get => this.name;
set => this.UpdateField(value, ref this.name);
}
private string bin;
public string Bin {
get => this.bin;
set => this.UpdateField(value, ref this.bin);
}
private Tool[] tools;
public Tool[] Tools {
get => this.tools;
set => this.UpdateField(value, ref this.tools);
}
}
public class Tool : BaseModel {
private string args;
public string Args {
get => this.args;
set => this.UpdateField(value, ref this.args);
}
private string bin;
public string Bin {
get => this.bin;
set => this.UpdateField(value, ref this.bin);
}
private string name;
public string Name {
get => this.name;
set => this.UpdateField(value, ref this.name);
}
}
public class VProject : BaseModel {
private int engine;
public int Engine {
get => this.engine;
set => this.UpdateField(value, ref this.engine);
}
private string path;
public string Path {
get => this.path;
set => this.UpdateField(value, ref this.path);
}
private string name;
public string Name {
get => this.name;
set => this.UpdateField(value, ref this.name);
}
private string args;
public string Args {
get => this.args;
set => this.UpdateField(value, ref this.args);
}
}
public class Project : Dictionary<string, VProject> { }
public class SettingsViewModel : BaseModel {
private readonly Settings settings;
private readonly LanguageProvider languageProvider;
private int selectedLanguage;
public int SelectedLanguageIndex {
get => this.selectedLanguage;
set {
if (this.UpdateField(value, ref selectedLanguage)) {
this.settings.Language = this.SelectedLanguage;
}
}
}
public string[] Languages => this.languageProvider.Languages;
private string SelectedLanguage => this.Languages[this.SelectedLanguageIndex];
public SettingsViewModel(Settings settings, LanguageProvider languageProvider) {
this.settings = settings;
this.languageProvider = languageProvider;
this.SelectedLanguageIndex = Math.Max(0, Array.IndexOf(this.Languages, settings.Language));
}
}
public class LanguageProvider {
public string[] Languages { get; } = { "English", "Россиян" };
}
public class Settings : BaseModel {
private string defaultProject;
private int[] avalibleEnginies;
private string language;
private string theme;
public string DefaultProject {
get => this.defaultProject;
set => this.UpdateField(value, ref this.defaultProject);
}
public int[] AvalibleEnginies {
get => this.avalibleEnginies;
set => this.UpdateField(value, ref this.avalibleEnginies);
}
public string Language {
get => this.language;
set => this.UpdateField(value, ref this.language);
}
public string Theme {
get => this.theme;
set => this.UpdateField(value, ref this.theme);
}
}
public abstract class BaseModel : INotifyPropertyChanged {
protected bool UpdateField<T>(T value, ref T field, [CallerMemberName]string name = null) {
var updated = !EqualityComparer<T>.Default.Equals(value, field);
if (updated) {
field = value;
OnPropertyChanged(name);
}
return updated;
}
protected void OnPropertyChanged([CallerMemberName]string name = null) => this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UniversalValveToolbox.Utils {
static class LanguageManager {
public static void UpdateLanguage(string newLanguage, bool restart = false) {
var currThread = Thread.CurrentThread;
var newCultureInfo = new CultureInfo(newLanguage);
currThread.CurrentCulture = currThread.CurrentUICulture = newCultureInfo;
if (restart) {
Application.Restart();
}
}
}
}

View File

@ -1,11 +1,7 @@
{ {
"DefaultProject": null, "DefaultProject": null,
"AvalibleEnginies": null, "AvailableEnginies": null,
"Language": [ "Language": "en-US",
{ "AvailableLanguages": [ "en-US", "ru-RU" ],
"selected": "en-US",
"available": [ "en-US", "ru-RU" ]
}
],
"Theme": null "Theme": null
} }