Skip to content

Commit

Permalink
Added option for editing configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusvallejo committed Jun 10, 2021
1 parent 48767af commit 5900461
Show file tree
Hide file tree
Showing 10 changed files with 4,055 additions and 32 deletions.
27 changes: 27 additions & 0 deletions Midi2Vol/App.cs
@@ -0,0 +1,27 @@
using IWshRuntimeLibrary;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace Midi2Vol
{
public class App
{

public App() { }
public App(String name, String AppRaw, String ProcessName)
{
this.name = name;
this.AppRaw = AppRaw;
this.ProcessName = ProcessName;
}
public String name { get; set; }
public String AppRaw { get; set; }
public String ProcessName { get; set; }
}


}
26 changes: 26 additions & 0 deletions Midi2Vol/Config.cs
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;


namespace Midi2Vol
{
class Config
{
public String configFile = "config.json";
public Config() { }
public List<App> SourceConfig()
{
String jsonString = System.IO.File.ReadAllText(configFile);
List<App> apps = JsonConvert.DeserializeObject<List<App>>(jsonString);
return apps;
}
public void saveConfig(List<App> apps)
{
String objectJson = JsonConvert.SerializeObject(apps);
System.IO.File.WriteAllText(configFile, objectJson);


}
}
}
121 changes: 121 additions & 0 deletions Midi2Vol/Edit.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions Midi2Vol/Edit.cs
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Midi2Vol
{
public partial class Edit : Form
{
private List<App> apps;
App currentApp;
public Edit(List<App> apps)
{
this.apps = apps;
InitializeComponent();
foreach (App app in apps)
{
listBox1.Items.Add(app.name);
}
}

private void button1_Click(object sender, EventArgs e)
{

if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "")
{
foreach (App app in apps)
{
if (app.name == textBox1.Text)
{
app.name = textBox1.Text;
app.AppRaw = textBox2.Text;
app.ProcessName = textBox3.Text;
return;

}

}
}
// app not found save it

App newApp = new App(textBox1.Text, textBox2.Text, textBox3.Text);
apps.Add(newApp);
listBox1.Items.Add(textBox1.Text);

}
private void button2_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
{
String name = listBox1.SelectedItem.ToString();
listBox1.ClearSelected();
apps.Remove(currentApp);
listBox1.Items.Remove(currentApp.name);
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
{
foreach (App app in apps)
{
if (app.name == listBox1.SelectedItem.ToString())
{
currentApp = app;
textBox1.Text = app.name;
textBox2.Text = app.AppRaw;
textBox3.Text = app.ProcessName;
}
}
textBox1.Update();
textBox2.Update();
textBox3.Update();
}
}
}
}

0 comments on commit 5900461

Please sign in to comment.