Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user settings to the GUI #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions SharpMonoInjector.Gui/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SharpMonoInjector.Gui.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<userSettings>
<SharpMonoInjector.Gui.Properties.Settings>
<setting name="AssemblyPath" serializeAs="String">
<value />
</setting>
<setting name="InjectNamespace" serializeAs="String">
<value />
</setting>
<setting name="InjectClassName" serializeAs="String">
<value />
</setting>
<setting name="InjectMethodName" serializeAs="String">
<value>Load</value>
</setting>
</SharpMonoInjector.Gui.Properties.Settings>
</userSettings>
</configuration>
48 changes: 48 additions & 0 deletions SharpMonoInjector.Gui/Properties/Settings.Designer.cs

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

21 changes: 16 additions & 5 deletions SharpMonoInjector.Gui/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="SharpMonoInjector.Gui.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="AssemblyPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="InjectNamespace" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="InjectClassName" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="InjectMethodName" Type="System.String" Scope="User">
<Value Profile="(Default)">Load</Value>
</Setting>
</Settings>
</SettingsFile>
40 changes: 40 additions & 0 deletions SharpMonoInjector.Gui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SharpMonoInjector.Gui.Models;
using System.Collections.Generic;
using System.Linq;
using System.Timers;

namespace SharpMonoInjector.Gui.ViewModels
{
Expand All @@ -26,6 +27,13 @@ public MainWindowViewModel()
InjectCommand = new RelayCommand(ExecuteInjectCommand, CanExecuteInjectCommand);
EjectCommand = new RelayCommand(ExecuteEjectCommand, CanExecuteEjectCommand);
CopyStatusCommand = new RelayCommand(ExecuteCopyStatusCommand);

AssemblyPath = Properties.Settings.Default.AssemblyPath;
InjectNamespace = Properties.Settings.Default.InjectNamespace;
InjectClassName = Properties.Settings.Default.InjectClassName;
InjectMethodName = Properties.Settings.Default.InjectMethodName;

InitSettingsTimer();
}

#region[Commands]
Expand Down Expand Up @@ -322,6 +330,8 @@ public string AssemblyPath
Set(ref _assemblyPath, value);
if (File.Exists(_assemblyPath))
InjectNamespace = Path.GetFileNameWithoutExtension(_assemblyPath);
Properties.Settings.Default.AssemblyPath = _assemblyPath;
NotifySaveSettings();
InjectCommand.RaiseCanExecuteChanged();
}
}
Expand All @@ -334,6 +344,8 @@ public string InjectNamespace
{
Set(ref _injectNamespace, value);
EjectNamespace = value;
Properties.Settings.Default.InjectNamespace = _injectNamespace;
NotifySaveSettings();
}
}

Expand All @@ -345,6 +357,8 @@ public string InjectClassName
{
Set(ref _injectClassName, value);
EjectClassName = value;
Properties.Settings.Default.InjectClassName = _injectClassName;
NotifySaveSettings();
InjectCommand.RaiseCanExecuteChanged();
}
}
Expand All @@ -358,6 +372,8 @@ public string InjectMethodName
Set(ref _injectMethodName, value);
if (_injectMethodName == "Load")
EjectMethodName = "Unload";
Properties.Settings.Default.InjectMethodName = _injectMethodName;
NotifySaveSettings();
InjectCommand.RaiseCanExecuteChanged();
}
}
Expand Down Expand Up @@ -549,6 +565,30 @@ public static bool AntivirusInstalled()

#endregion

#region [Save Settings Timer]

private Timer _settingsTimer;
private void InitSettingsTimer()
{
// 0.62 seconds should be enough time to finish typing.
_settingsTimer = new Timer(700);
_settingsTimer.AutoReset = false;
_settingsTimer.Elapsed += OnSettingsTimerComplete;
}
private void NotifySaveSettings()
{
if (_settingsTimer == null)
return;
// Restart
_settingsTimer.Stop();
_settingsTimer.Start();
}
private void OnSettingsTimerComplete(Object source, ElapsedEventArgs e)
{
Properties.Settings.Default.Save();
}

#endregion
}
}