Skip to content

Commit

Permalink
Close #40, Close 39, dialogs improved, somen changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot committed Aug 23, 2017
1 parent bdf1e43 commit 48576f6
Show file tree
Hide file tree
Showing 35 changed files with 686 additions and 433 deletions.
22 changes: 15 additions & 7 deletions Source/NETworkManager/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ private void Application_Startup(object sender, StartupEventArgs e)
// Parse the command line arguments and store them in the current configuration
CommandLineManager.Parse();

if (CommandLineManager.Current.Help)
{
StartupUri = new Uri("/Views/Help/HelpCommandLineWindow.xaml", UriKind.Relative);
return;
}

// If we have restart our application... wait until it has finished
if (CommandLineManager.Current.RestartPid != 0)
{
Expand All @@ -37,12 +31,26 @@ private void Application_Startup(object sender, StartupEventArgs e)
if (process != null)
process.WaitForExit();
}

// Detect the current configuration
ConfigurationManager.Detect();

// Get assembly informations
AssemblyManager.Load();

// Load settings
SettingsManager.Load();

// Load localization (requires settings to be loaded first)
LocalizationManager.Load();

if (CommandLineManager.Current.Help)
{
StartupUri = new Uri("/Views/Help/HelpCommandLineWindow.xaml", UriKind.Relative);
return;
}

// Load templates
TemplateManager.LoadNetworkInterfaceConfigTemplates();
TemplateManager.LoadWakeOnLANTemplates();

Expand Down
16 changes: 3 additions & 13 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void OnPropertyChanged(string propertyName)
#endregion

#region Variables
MetroDialogSettings dialogSettings = new MetroDialogSettings();


NotifyIcon notifyIcon;

Expand Down Expand Up @@ -218,12 +218,8 @@ public MainWindow()
InitializeComponent();
DataContext = this;

// Get assembly informations
AssemblyManager.Load();
Version = AssemblyManager.Current.AssemblyVersion.ToString();

// Load localization
LocalizationManager.Load();
LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(LocalizationManager.Culture.IetfLanguageTag)));

// Load appearance
Expand All @@ -235,12 +231,6 @@ public MainWindow()
Opacity = SettingsManager.Current.Appearance_Opacity;
}

// Dialog
dialogSettings.CustomResourceDictionary = new ResourceDictionary
{
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
};

// Autostart & Window start
if (CommandLineManager.Current.Autostart && SettingsManager.Current.Autostart_StartMinimizedInTray || SettingsManager.Current.TrayIcon_AlwaysShowIcon)
InitNotifyIcon();
Expand Down Expand Up @@ -291,7 +281,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;

MetroDialogSettings settings = dialogSettings;
MetroDialogSettings settings = AppearanceManager.MetroDialog;

settings.AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_Close"] as string;
settings.NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_Cancel"] as string;
Expand Down Expand Up @@ -645,7 +635,7 @@ private async void OpenSettingsAction()
{
ShowWindowAction();

MetroDialogSettings settings = dialogSettings;
MetroDialogSettings settings = AppearanceManager.MetroDialog;

settings.AffirmativeButtonText = System.Windows.Application.Current.Resources["String_Button_RestartNow"] as string;
settings.NegativeButtonText = System.Windows.Application.Current.Resources["String_Button_OK"] as string;
Expand Down
2 changes: 0 additions & 2 deletions Source/NETworkManager/Models/Network/DNSLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class DNSLookup
{
#region Variables
Resolver dnsResolver = new Resolver();

int resourceRecordsCount;
#endregion

#region Events
Expand Down
8 changes: 8 additions & 0 deletions Source/NETworkManager/Models/Settings/AppearanceManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using MahApps.Metro;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Windows;

namespace NETworkManager.Models.Settings
{
public static class AppearanceManager
{
public static MetroDialogSettings MetroDialog = new MetroDialogSettings();

/// <summary>
/// Load Appearance (AppTheme and Accent) from the user settings.
/// </summary>
Expand All @@ -22,6 +25,11 @@ public static void Load()

if (!string.IsNullOrEmpty(accentName) && accentName != ThemeManager.DetectAppStyle().Item2.Name)
ChangeAccent(accentName);

MetroDialog.CustomResourceDictionary = new ResourceDictionary
{
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml", UriKind.RelativeOrAbsolute)
};
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/Models/Settings/AutostartManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static void Enable()
{
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(RunKeyCurrentUser, true);

string command = string.Format("{0} {1}", ConfigurationManager.Current.ApplicationFullName, CommandLineManager.GetCommandLineParameter(CommandLineManager.ParameterAutostart));
string command = string.Format("{0} {1}", ConfigurationManager.Current.ApplicationFullName, CommandLineManager.ParameterAutostart);

registryKey.SetValue(ConfigurationManager.Current.ApplicationName, command);
registryKey.Close();
Expand Down
1 change: 1 addition & 0 deletions Source/NETworkManager/Models/Settings/CommandLineInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class CommandLineInfo
public bool Autostart { get; set; }
public bool ResetSettings { get; set; }
public int RestartPid { get; set; }
public string WrongParameter { get; set; }

public CommandLineInfo()
{
Expand Down
57 changes: 36 additions & 21 deletions Source/NETworkManager/Models/Settings/CommandLineManager.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using NETworkManager.Views.Settings;
using System;
using System.Windows;
using System;

namespace NETworkManager.Models.Settings
{
public static class CommandLineManager
{
public const string ParameterIdentifier = "--";
public const string ParameterHelp = "help";
public const string ParameterAutostart = "autostart";
public const string ParameterResetSettings = "reset-settings";
public const string ParameterRestartPid = "restart-pid:";
public const char ParameterSplit = ':';

// Public + Help
public const string ParameterHelp = ParameterIdentifier + "help";
public const string ParameterResetSettings = ParameterIdentifier + "reset-settings";

// Internal use only
public const string ParameterAutostart = ParameterIdentifier + "autostart";
public const string ParameterRestartPid = ParameterIdentifier + "restart-pid";

public static CommandLineInfo Current { get; set; }

Expand All @@ -22,46 +25,58 @@ public static void Parse()
{
Current = new CommandLineInfo();

// Get the command line args
// Detect start parameters
string[] parameters = Environment.GetCommandLineArgs();

char[] trimChars = ParameterIdentifier.ToCharArray();

// Detect start parameters
foreach (string parameter in parameters)
for (int i = 0; i < parameters.Length; i++)
{
if (parameter.StartsWith(ParameterIdentifier))
string[] param = parameters[i].Split(ParameterSplit);

if (param[0].StartsWith(ParameterIdentifier))
{
string param = parameter.TrimStart(trimChars);
if (param.Equals(ParameterHelp, StringComparison.InvariantCultureIgnoreCase))
if (param[0].Equals(ParameterHelp, StringComparison.InvariantCultureIgnoreCase))
{
Current.Help = true;
}// Autostart
else if(param.Equals(ParameterAutostart, StringComparison.InvariantCultureIgnoreCase))
else if (param[0].Equals(ParameterAutostart, StringComparison.InvariantCultureIgnoreCase))
{
Current.Autostart = true;
} // Reset Settings
else if (param.Equals(ParameterResetSettings, StringComparison.InvariantCultureIgnoreCase))
else if (param[0].Equals(ParameterResetSettings, StringComparison.InvariantCultureIgnoreCase))
{
Current.ResetSettings = true;
} // Restart
else if (param.StartsWith(ParameterRestartPid, StringComparison.InvariantCultureIgnoreCase))
else if (param[0].Equals(ParameterRestartPid, StringComparison.InvariantCultureIgnoreCase))
{
int.TryParse(param.Split(':')[1], out int restartPid);
int.TryParse(param[1], out int restartPid);

Current.RestartPid = restartPid;
}
else
{
AddToWrongParameter(parameters[i]);

Current.Help = true;
}
}
else
{
// Ignore the first parameter because it's the path of the .exe
if (i != 0)
{
AddToWrongParameter(parameters[i]);
Current.Help = true;
}
}
}
}

public static string GetCommandLineParameter(string parameter)
private static void AddToWrongParameter(string parameter)
{
return string.Format("{0}{1}", ParameterIdentifier, parameter);
if (!string.IsNullOrEmpty(Current.WrongParameter))
Current.WrongParameter += Environment.NewLine;

Current.WrongParameter += parameter;
}
}
}
13 changes: 7 additions & 6 deletions Source/NETworkManager/NETworkManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<Compile Include="Validators\IPAddressValidator.cs" />
<Compile Include="Validators\OpacityTextboxValidator.cs" />
<Compile Include="ViewModels\Applications\DNSLookupViewModel.cs" />
<Compile Include="ViewModels\Help\HelpCommandLineViewModel.cs" />
<Compile Include="ViewModels\Settings\SettingsApplicationDNSLookupViewModel.cs" />
<Compile Include="ViewModels\Settings\SettingsApplicationWakeOnLANViewModel.cs" />
<Compile Include="Views\Settings\SettingsApplicationDNSLookupView.xaml.cs">
Expand Down Expand Up @@ -644,9 +645,6 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\WindowsIcons-license.txt" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Entypo.ttf" />
<None Include="Resources\oui.txt">
Expand All @@ -658,13 +656,16 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Entypo-license.txt" />
</ItemGroup>
<ItemGroup>
<Resource Include="3rdParty\Heijden.DNS\Records\totla.txt" />
<Resource Include="3rdParty\Heijden.DNS\Root\named_root.txt" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\WindowsIcons-license.txt" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Entypo-license.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
19 changes: 13 additions & 6 deletions Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<system:String x:Key="String_Header_HotKeys">HotKeys</system:String>
<system:String x:Key="String_Header_DNSLookup">DNS Lookup</system:String>
<system:String x:Key="String_Header_Route">Route</system:String>
<system:String x:Key="String_Header_MaximumHopsReached">Maximale Hops erreicht</system:String>
<system:String x:Key="String_Header_CanceledByUser">Vom Benutzer abgebrochen</system:String>
<system:String x:Key="String_Header_DontFragment">Nicht fragmentieren</system:String>
<system:String x:Key="String_Header_Import">Importieren</system:String>
Expand All @@ -64,8 +63,9 @@
<system:String x:Key="String_Header_Update">Update</system:String>
<system:String x:Key="String_Header_Transparency">Transparenz</system:String>
<system:String x:Key="String_Header_WakeOnLAN">Wake on LAN</system:String>
<system:String x:Key="String_Header_HelpCommandLine">Hilfe - Kommandozeile</system:String>

<system:String x:Key="String_Header_CommandLineArguments">Befehlszeilenargumente</system:String>
<system:String x:Key="String_Header_WrongParameter">Falscher Parameter</system:String>

<!-- Normal strings -->
<system:String x:Key="String_ProductName">NETworkManager</system:String>
<system:String x:Key="String_ShowWindow">Fenster anzeigen</system:String>
Expand Down Expand Up @@ -174,8 +174,8 @@
<system:String x:Key="String_ConfirmClose">Schließen bestätigen</system:String>
<system:String x:Key="String_ConfirmCloseQuesiton">Sind Sie sicher, dass Sie die Anwendung beenden möchten?</system:String>
<system:String x:Key="String_UntrayBringWindowToFront">Untray / Fenster in den Vordergrund bringen</system:String>
<system:String x:Key="String_MaximumHopsReachedMessage">Traceroute wurde nach {0} Hops abgebrochen.</system:String>
<system:String x:Key="String_CanceledByUserMessage">Der Vorgang wurde vom Benutzer abgebrochen!</system:String>
<system:String x:Key="String_MaximumNumberOfHopsReached">Maximale Anzahl ({0}) an Hops/Router erreicht! </system:String>
<system:String x:Key="String_CanceledByUser">Der Vorgang wurde vom Benutzer abgebrochen!</system:String>
<system:String x:Key="String_NetworkInterfaceConfigTemplates">Netzwerkinterface Konfigurations Templates</system:String>
<system:String x:Key="String_WakeOnLANTemplates">Wake on LAN Templates</system:String>
<system:String x:Key="String_SelectedSettingsAreReset">Die ausgewählten Einstellungen werden zurückgesetzt. (Der Speicherpfad ist hiervon nicht betroffen.)</system:String>
Expand Down Expand Up @@ -221,7 +221,10 @@
<system:String x:Key="String_NothingToDoCheckYourInput">Nichts zu tun. Überprüfen Sie Ihre Eingabe!</system:String>
<system:String x:Key="String_Scanned">Gescannt</system:String>
<system:String x:Key="String_Found">Found</system:String>

<system:String x:Key="String_TheApplicationCanBeStartedWithoutParameters">Die Anwendung kann ohne Parameter gestartet werden!</system:String>
<system:String x:Key="String_TheFollwingParametersCanNotBeProcesses">Die folgenden Parameter können nicht verarbeitet werden:</system:String>
<system:String x:Key="String_TheFollowingParametersAreAvailable">Folgende Parameter stehen zur Verfügung:</system:String>

<!-- Buttons -->
<system:String x:Key="String_Button_Change">Wechseln</system:String>
<system:String x:Key="String_Button_Default">Standard</system:String>
Expand All @@ -247,6 +250,10 @@
<system:String x:Key="String_Button_Reset">Zurücksetzen</system:String>
<system:String x:Key="String_Button_Continue">Weiter</system:String>
<system:String x:Key="String_Button_Validate">Validieren</system:String>

<!-- Help -->
<system:String x:Key="String_Help_ParameterHelp">Zeigt diesen Dialog an.</system:String>
<system:String x:Key="String_Help_ParameterResetSettings">Setzt alle Einstellungen zurück.</system:String>

<!-- ContextMenuItem.Header -->
<system:String x:Key="String_ContextMenu_Cut">Ausschneiden</system:String>
Expand Down
21 changes: 14 additions & 7 deletions Source/NETworkManager/Resources/Localization/Resources.en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<system:String x:Key="String_Header_HotKeys">HotKeys</system:String>
<system:String x:Key="String_Header_DNSLookup">DNS Lookup</system:String>
<system:String x:Key="String_Header_Route">Route</system:String>
<system:String x:Key="String_Header_MaximumHopsReached">Maximum hops reached</system:String>
<system:String x:Key="String_Header_CanceledByUser">Canceled by user</system:String>
<system:String x:Key="String_Header_DontFragment">Don't fragment</system:String>
<system:String x:Key="String_Header_Import">Import</system:String>
Expand All @@ -65,8 +64,9 @@
<system:String x:Key="String_Header_Update">Update</system:String>
<system:String x:Key="String_Header_Transparency">Transparency</system:String>
<system:String x:Key="String_Header_WakeOnLAN">Wake on LAN</system:String>
<system:String x:Key="String_Header_HelpCommandLine">Help - Command Line</system:String>

<system:String x:Key="String_Header_CommandLineArguments">Command Line Arguments</system:String>
<system:String x:Key="String_Header_WrongParameter">Wrong parameter</system:String>

<!-- Normal strings -->
<system:String x:Key="String_ProductName">NETworkManager</system:String>
<system:String x:Key="String_ShowWindow">Show window</system:String>
Expand Down Expand Up @@ -175,8 +175,8 @@
<system:String x:Key="String_ConfirmClose">Confirm close</system:String>
<system:String x:Key="String_ConfirmCloseQuesiton">Are you sure you want to close the application?</system:String>
<system:String x:Key="String_UntrayBringWindowToFront">Untray / Bring window to front</system:String>
<system:String x:Key="String_MaximumHopsReachedMessage">Traceroute was canceled after {0} hops.</system:String>
<system:String x:Key="String_CanceledByUserMessage">The operation has been canceled by the user!</system:String>
<system:String x:Key="String_MaximumNumberOfHopsReached">Maximum number ({0}) of hops/router reached!</system:String>
<system:String x:Key="String_CanceledByUser">The operation has been canceled by the user!</system:String>
<system:String x:Key="String_ApplicationSettings">Application settings</system:String>
<system:String x:Key="String_NetworkInterfaceConfigTemplates">Network Interface config templates</system:String>
<system:String x:Key="String_WakeOnLANTemplates">Wake on LAN templates</system:String>
Expand Down Expand Up @@ -223,7 +223,10 @@
<system:String x:Key="String_NothingToDoCheckYourInput">Nothing to do. Check your input!</system:String>
<system:String x:Key="String_Scanned">Scanned</system:String>
<system:String x:Key="String_Found">Found</system:String>

<system:String x:Key="String_TheApplicationCanBeStartedWithoutParameters">The application can be started without parameters!</system:String>
<system:String x:Key="String_TheFollwingParametersCanNotBeProcesses">The following parameters can not be processed:</system:String>
<system:String x:Key="String_TheFollowingParametersAreAvailable">The following parameters are available:</system:String>

<!-- Buttons -->
<system:String x:Key="String_Button_Change">Change</system:String>
<system:String x:Key="String_Button_Default">Default</system:String>
Expand All @@ -249,7 +252,11 @@
<system:String x:Key="String_Button_Continue">Continue</system:String>
<system:String x:Key="String_Button_Validate">Validate</system:String>
<system:String x:Key="String_Button_Lookup">Lookup</system:String>


<!-- Help -->
<system:String x:Key="String_Help_ParameterHelp">Displays this dialog.</system:String>
<system:String x:Key="String_Help_ParameterResetSettings">Reset all settings.</system:String>

<!-- ContextMenuItem.Header -->
<system:String x:Key="String_ContextMenu_Cut">Cut</system:String>
<system:String x:Key="String_ContextMenu_Copy">Copy</system:String>
Expand Down

0 comments on commit 48576f6

Please sign in to comment.