diff --git a/src/UniversalValveToolbox/Base/DtoModel.cs b/src/UniversalValveToolbox/Base/DtoModel.cs index 1ee0993..5db0196 100644 --- a/src/UniversalValveToolbox/Base/DtoModel.cs +++ b/src/UniversalValveToolbox/Base/DtoModel.cs @@ -8,6 +8,13 @@ using Newtonsoft.Json; namespace UniversalValveToolbox.Base { public abstract class DtoModel : INotifyPropertyChanged { + protected bool ForceUpdateField(T value, ref T field, [CallerMemberName]string name = null) { + field = value; + OnPropertyChanged(name); + + return true; + } + protected bool UpdateField(T value, ref T field, [CallerMemberName]string name = null) { var updated = !EqualityComparer.Default.Equals(value, field); if (updated) { diff --git a/src/UniversalValveToolbox/Model/Dto/AddonDtoModel.cs b/src/UniversalValveToolbox/Model/Dto/AddonDtoModel.cs index 4a285a5..2fb68a7 100644 --- a/src/UniversalValveToolbox/Model/Dto/AddonDtoModel.cs +++ b/src/UniversalValveToolbox/Model/Dto/AddonDtoModel.cs @@ -32,6 +32,8 @@ namespace UniversalValveToolbox.Model.Dto { get => args; set => UpdateField(value, ref args); } + + public override string ToString() => name ?? ""; } } diff --git a/src/UniversalValveToolbox/Model/Dto/EngineDtoModel.cs b/src/UniversalValveToolbox/Model/Dto/EngineDtoModel.cs index 51441d3..c21d20c 100644 --- a/src/UniversalValveToolbox/Model/Dto/EngineDtoModel.cs +++ b/src/UniversalValveToolbox/Model/Dto/EngineDtoModel.cs @@ -26,5 +26,7 @@ namespace UniversalValveToolbox.Model.Dto { get => tools; set => UpdateField(value, ref tools); } + + public override string ToString() => name; } } diff --git a/src/UniversalValveToolbox/Model/Dto/ProjectDtoModel.cs b/src/UniversalValveToolbox/Model/Dto/ProjectDtoModel.cs index cc28d28..d77e4dc 100644 --- a/src/UniversalValveToolbox/Model/Dto/ProjectDtoModel.cs +++ b/src/UniversalValveToolbox/Model/Dto/ProjectDtoModel.cs @@ -7,6 +7,13 @@ namespace UniversalValveToolbox.Model.Dto { private string name; private string args; + public ProjectDtoModel() { + this.engine = 0; + this.path = ""; + this.name = ""; + this.args = ""; + } + public int Engine { get => engine; set => UpdateField(value, ref engine); @@ -27,6 +34,6 @@ namespace UniversalValveToolbox.Model.Dto { set => UpdateField(value, ref args); } - public override string ToString() => name; + public override string ToString() => name ?? ""; } } diff --git a/src/UniversalValveToolbox/Model/Provider/DataProvider.cs b/src/UniversalValveToolbox/Model/Provider/DataProvider.cs index 91180c4..47ef6ee 100644 --- a/src/UniversalValveToolbox/Model/Provider/DataProvider.cs +++ b/src/UniversalValveToolbox/Model/Provider/DataProvider.cs @@ -11,10 +11,10 @@ using UniversalValveToolbox.Utils; namespace UniversalValveToolbox.Model.Provider { class DataProvider { - private readonly string SettingsPath = Path.Combine(Application.StartupPath, "json", "settings.json"); - private readonly string EnginesPath = Path.Combine(Application.StartupPath, "json", "engines"); - private readonly string ProjectsPath = Path.Combine(Application.StartupPath, "json", "projects"); - private readonly string AddonsPath = Path.Combine(Application.StartupPath, "json", "addons"); + public static readonly string SettingsPath = Path.Combine(Application.StartupPath, "json", "settings.json"); + public static readonly string EnginesPath = Path.Combine(Application.StartupPath, "json", "engines"); + public static readonly string ProjectsPath = Path.Combine(Application.StartupPath, "json", "projects"); + public static readonly string AddonsPath = Path.Combine(Application.StartupPath, "json", "addons"); public SettingsDtoModel Settings { diff --git a/src/UniversalValveToolbox/Model/VIewModel/FormAddonViewModel.cs b/src/UniversalValveToolbox/Model/VIewModel/FormAddonViewModel.cs new file mode 100644 index 0000000..cd09d37 --- /dev/null +++ b/src/UniversalValveToolbox/Model/VIewModel/FormAddonViewModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversalValveToolbox.Base; +using UniversalValveToolbox.Model.Dto; + +namespace UniversalValveToolbox.Model.ViewModel { + class FormAddonViewModel: DtoModel { + private AddonDtoModel selectAddon; + + public AddonDtoModel SelectAddon { + get => selectAddon; + set => UpdateField(value, ref selectAddon); + } + + } +} diff --git a/src/UniversalValveToolbox/Model/ViewModel/FormProjectViewModel.cs b/src/UniversalValveToolbox/Model/ViewModel/FormProjectViewModel.cs index 71f674f..31b18fb 100644 --- a/src/UniversalValveToolbox/Model/ViewModel/FormProjectViewModel.cs +++ b/src/UniversalValveToolbox/Model/ViewModel/FormProjectViewModel.cs @@ -8,11 +8,57 @@ using UniversalValveToolbox.Model.Dto; namespace UniversalValveToolbox.Model.ViewModel { class FormProjectViewModel: DtoModel { - private ProjectDtoModel selectProject; + private ProjectDtoModel[] projects; + private int selectProjectIndex = 0; - public ProjectDtoModel SelectProject { - get => selectProject; - set => UpdateField(value, ref selectProject); + private EngineDtoModel[] engines; + private int selectEngineIndex = 0; + + public FormProjectViewModel(ProjectDtoModel[] projects, EngineDtoModel[] engines) { + this.projects = projects; + this.engines = engines; } + + public ProjectDtoModel[] Projects { + get => projects; + set { + UpdateField(value, ref projects); + + SelectProjectIndex = 0; + } + } + + public int SelectProjectIndex { + get => selectProjectIndex; + set { + ForceUpdateField(value, ref selectProjectIndex); + OnPropertyChanged(nameof(SelectProject)); + + var index = Math.Max(engines.ToList().FindIndex(engine => engine.Appid == SelectProject.Engine), 0); + + SelectEngineIndex = index; + } + } + + public ProjectDtoModel SelectProject => projects[selectProjectIndex]; + + public EngineDtoModel[] Engines { + get => engines; + set { + UpdateField(value, ref engines); + + SelectEngineIndex = 0; + } + } + + public int SelectEngineIndex { + get => selectEngineIndex; + set { + ForceUpdateField(value, ref selectEngineIndex); + OnPropertyChanged(nameof(SelectEngine)); + } + } + + public EngineDtoModel SelectEngine => engines[selectEngineIndex]; } } diff --git a/src/UniversalValveToolbox/UI/FormAddons.Designer.cs b/src/UniversalValveToolbox/UI/FormAddons.Designer.cs index cb7dd4a..86810cf 100644 --- a/src/UniversalValveToolbox/UI/FormAddons.Designer.cs +++ b/src/UniversalValveToolbox/UI/FormAddons.Designer.cs @@ -36,9 +36,6 @@ this.buttonNew = new System.Windows.Forms.Button(); this.labelAddon = new System.Windows.Forms.Label(); this.labelLinkedEngine = new System.Windows.Forms.Label(); - this.dataGridViewEngines = new System.Windows.Forms.DataGridView(); - this.ColumnEngineName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnAppID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.labelName = new System.Windows.Forms.Label(); this.textBoxName = new System.Windows.Forms.TextBox(); this.textBoxPath = new System.Windows.Forms.TextBox(); @@ -50,7 +47,7 @@ this.comboBoxCategory = new System.Windows.Forms.ComboBox(); this.labelCategory = new System.Windows.Forms.Label(); this.buttonApply = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridViewEngines)).BeginInit(); + this.engineListView = new System.Windows.Forms.ListView(); this.SuspendLayout(); // // buttonCancel @@ -84,6 +81,7 @@ this.comboBox_Addon.Name = "comboBox_Addon"; this.comboBox_Addon.Size = new System.Drawing.Size(390, 21); this.comboBox_Addon.TabIndex = 6; + this.comboBox_Addon.SelectedIndexChanged += new System.EventHandler(this.comboBox_Addon_SelectedIndexChanged); // // buttonRemove // @@ -123,42 +121,6 @@ this.labelLinkedEngine.TabIndex = 12; this.labelLinkedEngine.Text = "Linked Engine:"; // - // dataGridViewEngines - // - this.dataGridViewEngines.AllowUserToAddRows = false; - this.dataGridViewEngines.AllowUserToDeleteRows = false; - this.dataGridViewEngines.AllowUserToOrderColumns = true; - this.dataGridViewEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridViewEngines.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; - this.dataGridViewEngines.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridViewEngines.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.ColumnEngineName, - this.ColumnAppID}); - this.dataGridViewEngines.Location = new System.Drawing.Point(12, 182); - this.dataGridViewEngines.Name = "dataGridViewEngines"; - this.dataGridViewEngines.ReadOnly = true; - this.dataGridViewEngines.Size = new System.Drawing.Size(471, 180); - this.dataGridViewEngines.TabIndex = 13; - // - // ColumnEngineName - // - this.ColumnEngineName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ColumnEngineName.HeaderText = "Engine"; - this.ColumnEngineName.Name = "ColumnEngineName"; - this.ColumnEngineName.ReadOnly = true; - this.ColumnEngineName.Resizable = System.Windows.Forms.DataGridViewTriState.False; - // - // ColumnAppID - // - this.ColumnAppID.FillWeight = 256F; - this.ColumnAppID.HeaderText = "AppID"; - this.ColumnAppID.Name = "ColumnAppID"; - this.ColumnAppID.ReadOnly = true; - this.ColumnAppID.Resizable = System.Windows.Forms.DataGridViewTriState.False; - this.ColumnAppID.Width = 62; - // // labelName // this.labelName.AutoSize = true; @@ -262,11 +224,25 @@ this.buttonApply.Text = "Apply"; this.buttonApply.UseVisualStyleBackColor = true; // + // engineListView + // + this.engineListView.CheckBoxes = true; + this.engineListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; + this.engineListView.HideSelection = false; + this.engineListView.Location = new System.Drawing.Point(15, 182); + this.engineListView.Name = "engineListView"; + this.engineListView.Size = new System.Drawing.Size(387, 188); + this.engineListView.TabIndex = 28; + this.engineListView.UseCompatibleStateImageBehavior = false; + this.engineListView.View = System.Windows.Forms.View.List; + this.engineListView.SelectedIndexChanged += new System.EventHandler(this.engineListView_SelectedIndexChanged); + // // FormAddons // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(495, 417); + this.Controls.Add(this.engineListView); this.Controls.Add(this.buttonApply); this.Controls.Add(this.labelCategory); this.Controls.Add(this.comboBoxCategory); @@ -278,7 +254,6 @@ this.Controls.Add(this.labelPath); this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelName); - this.Controls.Add(this.dataGridViewEngines); this.Controls.Add(this.labelLinkedEngine); this.Controls.Add(this.labelAddon); this.Controls.Add(this.buttonRemove); @@ -293,7 +268,6 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Edit Addons"; this.Load += new System.EventHandler(this.FormAddons_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridViewEngines)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -308,9 +282,6 @@ private System.Windows.Forms.Button buttonNew; private System.Windows.Forms.Label labelAddon; private System.Windows.Forms.Label labelLinkedEngine; - private System.Windows.Forms.DataGridView dataGridViewEngines; - private System.Windows.Forms.DataGridViewTextBoxColumn ColumnEngineName; - private System.Windows.Forms.DataGridViewTextBoxColumn ColumnAppID; private System.Windows.Forms.Label labelName; private System.Windows.Forms.TextBox textBoxName; private System.Windows.Forms.TextBox textBoxPath; @@ -322,5 +293,6 @@ private System.Windows.Forms.ComboBox comboBoxCategory; private System.Windows.Forms.Label labelCategory; private System.Windows.Forms.Button buttonApply; + private System.Windows.Forms.ListView engineListView; } } \ No newline at end of file diff --git a/src/UniversalValveToolbox/UI/FormAddons.cs b/src/UniversalValveToolbox/UI/FormAddons.cs index 6eb88fa..63ede46 100644 --- a/src/UniversalValveToolbox/UI/FormAddons.cs +++ b/src/UniversalValveToolbox/UI/FormAddons.cs @@ -1,10 +1,61 @@ using System; using System.Windows.Forms; +using UniversalValveToolbox.Model.Provider; +using UniversalValveToolbox.Model.ViewModel; +using UniversalValveToolbox.Model.Dto; +using kasthack.binding.wf; +using System.Linq; namespace UniversalValveToolbox { public partial class FormAddons : Form { + private DataProvider dataProvider = new DataProvider(); + + private FormAddonViewModel model; + + private AddonDtoModel[] arrayAddon; + public FormAddons() { InitializeComponent(); + + model = new FormAddonViewModel(); + model.SelectAddon = new AddonDtoModel(); + + var addons = dataProvider.Addons; + arrayAddon = new AddonDtoModel[addons.Length + 1]; + arrayAddon[0] = model.SelectAddon; + Array.Copy(addons, 0, arrayAddon, 1, addons.Length); + + comboBox_Addon.Items.Clear(); + comboBox_Addon.Items.AddRange(arrayAddon); + comboBox_Addon.SelectedIndex = 0; + + textBoxName.Bind(a => a.Text, model, a => a.SelectAddon.Name); + textBoxPath.Bind(a => a.Text, model, a => a.SelectAddon.Bin); + textBoxArgs.Bind(a => a.Text, model, a => a.SelectAddon.Args); + + model.PropertyChanged += Model_PropertyChanged; + } + + private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { + var availableEngines = dataProvider.Engines.Select(engine => { + var item = new ListViewItem(engine.Name); + item.Checked = model.SelectAddon.Engines.Contains(engine.Appid); + return item; + }).ToArray(); + + + engineListView.Items.Clear(); + engineListView.Items.AddRange(availableEngines); + + + + //dataGridViewEngines.Rows.add + //var index = availableEngines.ToList().FindIndex(engine => engine.Appid == model.SelectProject.Engine); + + //comboBoxEngine.Items.Clear(); + //comboBoxEngine.Items.AddRange(availableEngines); + + //comboBoxEngine.SelectedIndex = index; } private void buttonCancel_Click(object sender, EventArgs e) { @@ -32,5 +83,14 @@ namespace UniversalValveToolbox { { } + + private void comboBox_Addon_SelectedIndexChanged(object sender, EventArgs e) { + var selectAddon = arrayAddon.First(addon => addon.Name == ((AddonDtoModel)comboBox_Addon.SelectedItem).Name); + model.SelectAddon = selectAddon; + } + + private void engineListView_SelectedIndexChanged(object sender, EventArgs e) { + + } } } diff --git a/src/UniversalValveToolbox/UI/FormAddons.resx b/src/UniversalValveToolbox/UI/FormAddons.resx index cea1d21..f501c14 100644 --- a/src/UniversalValveToolbox/UI/FormAddons.resx +++ b/src/UniversalValveToolbox/UI/FormAddons.resx @@ -117,12 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - diff --git a/src/UniversalValveToolbox/UI/FormMain.cs b/src/UniversalValveToolbox/UI/FormMain.cs index 3300fb8..9840d37 100644 --- a/src/UniversalValveToolbox/UI/FormMain.cs +++ b/src/UniversalValveToolbox/UI/FormMain.cs @@ -36,7 +36,8 @@ namespace UniversalValveToolbox { UpdateAddonsList(); Text = VersionHelper.AssemblyTitle + VersionHelper.AssemblyVersion; - comboBoxGameConfig.SelectedIndex = 0; + + comboBoxEngine.SelectedIndexChanged += (s, e) => { UpdateProjectList(); diff --git a/src/UniversalValveToolbox/UI/FormProfiles.Designer.cs b/src/UniversalValveToolbox/UI/FormProfiles.Designer.cs index 085a68f..cb7645a 100644 --- a/src/UniversalValveToolbox/UI/FormProfiles.Designer.cs +++ b/src/UniversalValveToolbox/UI/FormProfiles.Designer.cs @@ -1,4 +1,6 @@ -namespace UniversalValveToolbox { +using System; + +namespace UniversalValveToolbox { partial class FormProfiles { /// /// Required designer variable. @@ -53,6 +55,7 @@ this.comboBox_Mod.Name = "comboBox_Mod"; this.comboBox_Mod.Size = new System.Drawing.Size(395, 21); this.comboBox_Mod.TabIndex = 3; + this.comboBox_Mod.SelectedIndexChanged += new System.EventHandler(this.comboBox_Mod_SelectedIndexChanged); // // buttonOK // @@ -63,6 +66,7 @@ this.buttonOK.TabIndex = 4; this.buttonOK.Text = "OK"; this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); // // buttonCancel // @@ -84,6 +88,7 @@ this.buttonNew.TabIndex = 7; this.buttonNew.Text = "New"; this.buttonNew.UseVisualStyleBackColor = true; + this.buttonNew.Click += new System.EventHandler(this.buttonNew_Click); // // buttonRemove // @@ -94,6 +99,7 @@ this.buttonRemove.TabIndex = 8; this.buttonRemove.Text = "Remove"; this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click); // // buttonBrowse // @@ -134,6 +140,7 @@ this.comboBoxEngine.Name = "comboBoxEngine"; this.comboBoxEngine.Size = new System.Drawing.Size(395, 21); this.comboBoxEngine.TabIndex = 15; + this.comboBoxEngine.SelectedIndexChanged += new System.EventHandler(this.comboBoxEngine_SelectedIndexChanged); // // label2 // @@ -190,6 +197,7 @@ this.buttonApply.TabIndex = 28; this.buttonApply.Text = "Apply"; this.buttonApply.UseVisualStyleBackColor = true; + this.buttonApply.Click += new System.EventHandler(this.buttonApply_Click); // // textBoxArgs // @@ -243,6 +251,7 @@ } + #endregion private System.Windows.Forms.ComboBox comboBox_Mod; diff --git a/src/UniversalValveToolbox/UI/FormProfiles.cs b/src/UniversalValveToolbox/UI/FormProfiles.cs index 935a672..aa5c03c 100644 --- a/src/UniversalValveToolbox/UI/FormProfiles.cs +++ b/src/UniversalValveToolbox/UI/FormProfiles.cs @@ -1,23 +1,59 @@ using kasthack.binding.wf; using System; +using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; +using UniversalValveToolbox.Model.Dto; using UniversalValveToolbox.Model.Provider; using UniversalValveToolbox.Model.ViewModel; +using UniversalValveToolbox.Utils; namespace UniversalValveToolbox { public partial class FormProfiles : Form { private DataProvider dataProvider = new DataProvider(); - private FormProjectViewModel model = new FormProjectViewModel(); + private FormProjectViewModel model; + public FormProfiles() { InitializeComponent(); - comboBox_Mod.Items.Clear(); - comboBox_Mod.Items.AddRange(dataProvider.Projects); - //textBox1.Text = "1"; + model = new FormProjectViewModel(dataProvider.Projects, dataProvider.Engines); - //textBox1.Bind(a => a.Name, model, a => a.SelectProject.Name); + UpdateComboBoxProject(); + UpdateComboBoxEngine(); + + textBox1.Bind(a => a.Text, model, a => a.SelectProject.Name); + textBoxPath.Bind(a => a.Text, model, a => a.SelectProject.Path); + textBoxArgs.Bind(a => a.Text, model, a => a.SelectProject.Args); + + comboBox_Mod.Bind(a => a.SelectedIndex, model, a => a.SelectProjectIndex); + comboBoxEngine.Bind(a => a.SelectedIndex, model, a => a.SelectEngineIndex); + + //model.PropertyChanged += Model_PropertyChanged; + + UpdateComboBoxEngine(); + + //comboBox_Mod.SelectedIndex = 0; + } + + private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { + + UpdateComboBoxEngine(); + } + + private void UpdateComboBoxProject() { + comboBox_Mod.Items.Clear(); + comboBox_Mod.Items.AddRange(model.Projects); + + comboBox_Mod.SelectedIndex = model.SelectProjectIndex; + } + + private void UpdateComboBoxEngine() { + comboBoxEngine.Items.Clear(); + comboBoxEngine.Items.AddRange(model.Engines); + + comboBox_Mod.SelectedIndex = model.SelectEngineIndex; } private void FormEditProfile_Load(object sender, EventArgs e) { @@ -44,5 +80,58 @@ namespace UniversalValveToolbox { textBoxPath.Text = folderpath; } } + + private void comboBoxEngine_SelectedIndexChanged(object sender, EventArgs e) { + model.SelectProject.Engine = ((EngineDtoModel)comboBoxEngine.SelectedItem).Appid; + } + + private void comboBox_Mod_SelectedIndexChanged(object sender, EventArgs e) { + model.SelectProjectIndex = comboBox_Mod.SelectedIndex; + } + + private void Remove() { + var newProjectList = new List(model.Projects); + newProjectList.RemoveAt(model.SelectProjectIndex); + + model.Projects = newProjectList.ToArray(); + + UpdateComboBoxProject(); + } + + private void New() { + var newProject = new ProjectDtoModel(); + newProject.Name = ""; + + var newProjectList = new List(model.Projects); + newProjectList.Insert(0, newProject); + + model.Projects = newProjectList.ToArray(); + + UpdateComboBoxProject(); + } + + private void Save() { + var selectProject = model.SelectProject; + + JsonFileUtil.SaveValues(DataProvider.ProjectsPath, "json", model.Projects.ToList()); + } + + private void buttonOK_Click(object sender, EventArgs e) { + Save(); + + Close(); + } + + private void buttonApply_Click(object sender, EventArgs e) { + Save(); + } + + private void buttonNew_Click(object sender, EventArgs e) { + New(); + } + + private void buttonRemove_Click(object sender, EventArgs e) { + Remove(); + } } } diff --git a/src/UniversalValveToolbox/UniversalValveToolbox.csproj b/src/UniversalValveToolbox/UniversalValveToolbox.csproj index e42d631..e9ff40c 100644 --- a/src/UniversalValveToolbox/UniversalValveToolbox.csproj +++ b/src/UniversalValveToolbox/UniversalValveToolbox.csproj @@ -61,6 +61,7 @@ + diff --git a/src/UniversalValveToolbox/Utils/JsonFileUtil.cs b/src/UniversalValveToolbox/Utils/JsonFileUtil.cs index 6286a05..46837ee 100644 --- a/src/UniversalValveToolbox/Utils/JsonFileUtil.cs +++ b/src/UniversalValveToolbox/Utils/JsonFileUtil.cs @@ -12,6 +12,30 @@ namespace UniversalValveToolbox.Utils { public static T[] ReadValues(string directoryPath) => Directory.GetFiles(directoryPath, "*").Select(path => ReadValue(path)).ToArray(); + public static List ReadListValues(string directoryPath) => new List(ReadValues(directoryPath)); + public static void WriteValue(string path, T value) => File.WriteAllText(path, JsonConvert.SerializeObject(value, Formatting.Indented)); + + public static void SaveValues(string folderPath, string fileExtension, List values) { + DirectoryInfo di = new DirectoryInfo(folderPath); + + foreach (FileInfo file in di.GetFiles()) { + file.Delete(); + } + foreach (DirectoryInfo dir in di.GetDirectories()) { + dir.Delete(true); + } + + foreach (var item in values) { + StringBuilder fileName = new StringBuilder(item.ToString().ToLower()); + foreach (char c in System.IO.Path.GetInvalidFileNameChars()) { + fileName = fileName.Replace(c, '_'); + } + + var path = Path.Combine(folderPath, $"{fileName}.{fileExtension}"); + + File.WriteAllText(path, JsonConvert.SerializeObject(item, Formatting.Indented)); + } + } } } diff --git a/src/UniversalValveToolbox/json/projects/test project.json b/src/UniversalValveToolbox/json/projects/test project.json index 4ab206d..5fe485f 100644 --- a/src/UniversalValveToolbox/json/projects/test project.json +++ b/src/UniversalValveToolbox/json/projects/test project.json @@ -2,5 +2,5 @@ "engine": 243730, //linked avalible engine by id "path": "C:\\Test", //path for export to users's env "name": "Test Project", //name for launcher - "args": "" //run args + "args": "-test" //run args }