This commit is contained in:
Alex Z 2020-01-19 19:12:32 +03:00
parent fbec876475
commit 429c8da82f
16 changed files with 386 additions and 38 deletions

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29521.150
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalValveToolbox", "UniversalValveToolbox\UniversalValveToolbox.csproj", "{DE66895F-7317-45D3-B5CA-292253CE086A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wpfExample", "wpfExample\wpfExample.csproj", "{8532F273-FDBB-462A-9276-85641A9B059B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{DE66895F-7317-45D3-B5CA-292253CE086A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE66895F-7317-45D3-B5CA-292253CE086A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE66895F-7317-45D3-B5CA-292253CE086A}.Release|Any CPU.Build.0 = Release|Any CPU
{8532F273-FDBB-462A-9276-85641A9B059B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8532F273-FDBB-462A-9276-85641A9B059B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8532F273-FDBB-462A-9276-85641A9B059B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8532F273-FDBB-462A-9276-85641A9B059B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>

View File

@ -1,6 +1,9 @@
using System;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using UniversalValveToolbox.Util;
using UniversalValveToolbox.Util.Dto;
namespace UniversalValveToolbox {
public partial class FormMain : Form {
@ -77,16 +80,14 @@ namespace UniversalValveToolbox {
}
private void button_Launch_Click(object sender, EventArgs e) {
var frmSettings = new FormSettings();
frmSettings.ShowDialog();
this.OpenSettings();
}
private void listView_MouseDoubleClick(object sender, MouseEventArgs e) {
var selectItemText = listView.SelectedItems[0].Text;
if (selectItemText == Properties.translations.MenuItems.itmOpenSettings) {
var frmSettings = new FormSettings();
frmSettings.ShowDialog();
this.OpenSettings();
}
else if (selectItemText == Properties.translations.MenuItems.itmEditConfigurations) {
var frmProfiles = new FormProfiles();
@ -104,5 +105,19 @@ namespace UniversalValveToolbox {
Process.Start("https://github.com/EpicMorg/UniversalValveToolbox");
}
}
private void OpenSettings() {
var dataManager = new DataManager();
var settingsDto = dataManager.ReadSettings();
var languageProvider = new LanguageProvider();
var settingsModel = new SettingsViewModel(settingsDto, languageProvider);
var frmSettings = new FormSettings(settingsModel);
if (frmSettings.ShowDialog() == DialogResult.OK) {
dataManager.SaveSettings(settingsDto);
}
}
}
}

View File

@ -31,6 +31,7 @@
this.comboBoxLang = new System.Windows.Forms.ComboBox();
this.comboBoxTheme = new System.Windows.Forms.ComboBox();
this.label6 = new System.Windows.Forms.Label();
this.elementHost1 = new System.Windows.Forms.Integration.ElementHost();
this.SuspendLayout();
//
// labelDivider
@ -38,7 +39,7 @@
this.labelDivider.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.labelDivider.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.labelDivider.Location = new System.Drawing.Point(-21, 101);
this.labelDivider.Location = new System.Drawing.Point(-21, 272);
this.labelDivider.Name = "labelDivider";
this.labelDivider.Size = new System.Drawing.Size(385, 2);
this.labelDivider.TabIndex = 26;
@ -46,7 +47,7 @@
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(224, 113);
this.buttonCancel.Location = new System.Drawing.Point(224, 284);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 25;
@ -57,7 +58,8 @@
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.Location = new System.Drawing.Point(143, 113);
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(143, 284);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 24;
@ -108,11 +110,21 @@
this.label6.TabIndex = 31;
this.label6.Text = "Theme:";
//
// elementHost1
//
this.elementHost1.Location = new System.Drawing.Point(12, 93);
this.elementHost1.Name = "elementHost1";
this.elementHost1.Size = new System.Drawing.Size(287, 176);
this.elementHost1.TabIndex = 33;
this.elementHost1.Text = "elementHost1";
this.elementHost1.Child = null;
//
// FormSettings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(311, 148);
this.ClientSize = new System.Drawing.Size(311, 319);
this.Controls.Add(this.elementHost1);
this.Controls.Add(this.comboBoxTheme);
this.Controls.Add(this.label6);
this.Controls.Add(this.comboBoxLang);
@ -142,5 +154,6 @@
private System.Windows.Forms.ComboBox comboBoxLang;
private System.Windows.Forms.ComboBox comboBoxTheme;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Integration.ElementHost elementHost1;
}
}

View File

@ -1,12 +1,24 @@
using System;
using kasthack.binding.wf;
using System;
using System.Windows.Forms;
using UniversalValveToolbox.Util.Dto;
namespace UniversalValveToolbox {
public partial class FormSettings : Form {
public FormSettings() {
public FormSettings(SettingsViewModel settings) {
InitializeComponent();
comboBoxLang.SelectedIndex = 0;
comboBoxTheme.SelectedIndex = 0;
comboBoxLang.Bind(a => a.DataSource, settings, a => a.Languages);
comboBoxLang.Bind(a => a.SelectedIndex, settings, a => a.SelectedLanguageIndex);
//this.Bind(a => a.Text, settings, a => a.Language);
//^
//this.DataBindings.Add(new Binding(nameof(this.Text), settings, nameof(settings.Language), false, DataSourceUpdateMode.OnPropertyChanged));
}
private void buttonCancel_Click(object sender, EventArgs e) {

View File

@ -36,14 +36,11 @@
<ApplicationIcon>valve.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="EpicMorg.SteamPathsLib, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EpicMorg.SteamPathsLib.1.1.0\lib\net48\EpicMorg.SteamPathsLib.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -53,6 +50,14 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<PackageReference Include="EpicMorg.SteamPathsLib" Version="1.1.0" />
<PackageReference Include="kasthack.binding.wf">
<Version>1.2.26</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<Reference Include="UIAutomationProvider" />
<Reference Include="WindowsBase" />
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form\FormAbout.cs">
@ -112,6 +117,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>MessageBoxes.resx</DependentUpon>
</Compile>
<Compile Include="Util\JsonReader.cs" />
<Compile Include="Util\VersionHelper.cs" />
<EmbeddedResource Include="Form\FormAbout.resx">
<DependentUpon>FormAbout.cs</DependentUpon>
@ -183,7 +189,6 @@
<None Include="json\settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -194,9 +199,6 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\cancel_16.png" />
<None Include="Resources\checked_16.png" />

View File

@ -0,0 +1,221 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using UniversalValveToolbox.Util.Dto;
namespace UniversalValveToolbox.Util {
class DataManager {
private const string SettingsPath = "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.Util.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

@ -2,7 +2,7 @@
"vproject": {
"engine": 243730, //linked avalible engine by id
"path": "C:\\Test", //path for export to users's env
"name": "Test Project" //name for launcher
"name": "Test Project", //name for launcher
"args": "" //run args
}
}

View File

@ -1,6 +1,6 @@
{
"default-project": "projects//test project.json",
"avalible-enginies": [ 243730 ],
"language": null,
"theme": null
"DefaultProject": null,
"AvalibleEnginies": null,
"Language": "Россиян",
"Theme": null
}

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EpicMorg.SteamPathsLib" version="1.1.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
</packages>

9
src/wpfExample/App.xaml Normal file
View File

@ -0,0 +1,9 @@
<Application x:Class="wpfExample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:wpfExample"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace wpfExample {
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application {
}
}

View File

@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

View File

@ -0,0 +1,22 @@
<Window x:Class="wpfExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpfExample"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBox HorizontalAlignment="Left" Margin="73,123,0,0" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.5,0.5">
<TextBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="719.385"/>
<TranslateTransform/>
</TransformGroup>
</TextBox.RenderTransform>
</TextBox>
</Grid>
</Window>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wpfExample {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>