From 60aa29f70b6923775d614eba7968481a873e3c7f Mon Sep 17 00:00:00 2001 From: valnoxy Date: Tue, 11 Jul 2023 23:23:14 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8C=8E=20Add=20Localization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Initial languages: English, German --- GoAwayEdge/App.xaml | 2 + GoAwayEdge/App.xaml.cs | 38 ++++++++-------- GoAwayEdge/Common/Updater.cs | 35 +++++++-------- GoAwayEdge/GoAwayEdge.csproj | 12 +++++- GoAwayEdge/GoAwayEdge.csproj.user | 6 +++ GoAwayEdge/Installer.xaml | 37 ++++++---------- GoAwayEdge/Installer.xaml.cs | 43 ++++++++++--------- .../ResourceDictionary.de-DE.xaml | 31 +++++++++++++ .../Localization/ResourceDictionary.xaml | 31 +++++++++++++ GoAwayEdge/Pages/Installation.xaml | 4 +- GoAwayEdge/Pages/Installation.xaml.cs | 2 +- GoAwayEdge/Pages/InstallationSuccess.xaml | 6 +-- GoAwayEdge/Pages/License.xaml | 12 +++--- GoAwayEdge/Pages/License.xaml.cs | 9 ++-- GoAwayEdge/Pages/Settings.xaml | 15 +++---- GoAwayEdge/Pages/Settings.xaml.cs | 6 +-- 16 files changed, 177 insertions(+), 112 deletions(-) create mode 100644 GoAwayEdge/Localization/ResourceDictionary.de-DE.xaml create mode 100644 GoAwayEdge/Localization/ResourceDictionary.xaml diff --git a/GoAwayEdge/App.xaml b/GoAwayEdge/App.xaml index f1580f8..b3f84da 100644 --- a/GoAwayEdge/App.xaml +++ b/GoAwayEdge/App.xaml @@ -9,6 +9,8 @@ + + diff --git a/GoAwayEdge/App.xaml.cs b/GoAwayEdge/App.xaml.cs index 7b3948f..240d584 100644 --- a/GoAwayEdge/App.xaml.cs +++ b/GoAwayEdge/App.xaml.cs @@ -22,7 +22,7 @@ namespace GoAwayEdge /// /// Interaktionslogik für App.xaml /// - public partial class App : Application + public partial class App { private static string? _url; private static SearchEngine _engine = SearchEngine.Google; // Fallback @@ -34,7 +34,7 @@ public void Application_Startup(object sender, StartupEventArgs e) if (IsAdministrator() == false) { // Restart program and run as admin - var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName; + var exeName = Process.GetCurrentProcess().MainModule?.FileName; if (exeName != null) { var startInfo = new ProcessStartInfo(exeName) @@ -42,7 +42,7 @@ public void Application_Startup(object sender, StartupEventArgs e) Verb = "runas", UseShellExecute = true }; - System.Diagnostics.Process.Start(startInfo); + Process.Start(startInfo); } Application.Current.Shutdown(); return; @@ -60,7 +60,7 @@ public void Application_Startup(object sender, StartupEventArgs e) #if DEBUG Clipboard.SetText(argumentJoin); - MessageBox.Show("The following args was redirected (copied to clipboard):\n\n" + argumentJoin, "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information); + MessageBox.Show("The following args are redirected (copied to the clipboard):\n\n" + argumentJoin, "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Information); #endif Output.WriteLine("Command line args:\n\n" + argumentJoin + "\n", ConsoleColor.Gray); @@ -74,11 +74,11 @@ public void Application_Startup(object sender, StartupEventArgs e) } if (arg.Contains("--update")) { - var statusEnv = Common.Updater.InitEnv(); + var statusEnv = Updater.InitEnv(); if (statusEnv == false) Environment.Exit(1); // Validate IFEO bínary - var binaryStatus = Common.Updater.ValidateIfeoBinary(); + var binaryStatus = Updater.ValidateIfeoBinary(); switch (binaryStatus) { case 0: // validated @@ -90,7 +90,7 @@ public void Application_Startup(object sender, StartupEventArgs e) if (result == MessageBoxResult.Yes) { // Restart program and run as admin - var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName; + var exeName = Process.GetCurrentProcess().MainModule?.FileName; if (exeName != null) { var startInfo = new ProcessStartInfo(exeName) @@ -99,7 +99,7 @@ public void Application_Startup(object sender, StartupEventArgs e) UseShellExecute = true, Arguments = "--update" }; - System.Diagnostics.Process.Start(startInfo); + Process.Start(startInfo); } Application.Current.Shutdown(); return; @@ -115,7 +115,7 @@ public void Application_Startup(object sender, StartupEventArgs e) if (result == MessageBoxResult.Yes) { // Restart program and run as admin - var exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName; + var exeName = Process.GetCurrentProcess().MainModule?.FileName; if (exeName != null) { var startInfo = new ProcessStartInfo(exeName) @@ -124,7 +124,7 @@ public void Application_Startup(object sender, StartupEventArgs e) UseShellExecute = true, Arguments = "--update" }; - System.Diagnostics.Process.Start(startInfo); + Process.Start(startInfo); } Application.Current.Shutdown(); return; @@ -171,7 +171,7 @@ public void Application_Startup(object sender, StartupEventArgs e) // Open URL in default browser if (_url != null) { - var parsed = ParsingUrl(_url); + var parsed = ParseUrl(_url); Output.WriteLine("Opening URL in default browser:\n\n" + parsed + "\n", ConsoleColor.Gray); var p = new Process(); @@ -185,7 +185,7 @@ public void Application_Startup(object sender, StartupEventArgs e) Environment.Exit(0); } - private static string ParsingUrl(string encodedUrl) + private static string ParseUrl(string encodedUrl) { // Remove URI handler with url argument prefix encodedUrl = encodedUrl[encodedUrl.IndexOf("http", StringComparison.Ordinal)..]; @@ -207,7 +207,7 @@ private static string ParsingUrl(string encodedUrl) // Replace Search Engine encodedUrl = encodedUrl.Replace("https://www.bing.com/search?q=", DefineEngine(_engine)); - Uri uri = new(encodedUrl.ToString()); + var uri = new Uri(encodedUrl); return uri.ToString(); } @@ -236,9 +236,6 @@ private static string DecodeUrlString(string url) private static string DotSlash(string url) { - //url = url.Replace("%3A", ":"); - //url = url.Replace("%2F", "/"); - string newUrl; while ((newUrl = Uri.UnescapeDataString(url)) != url) url = newUrl; @@ -247,13 +244,16 @@ private static string DotSlash(string url) { var uri = new Uri(url); var query = HttpUtility.ParseQueryString(uri.Query).Get("url"); - var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(query)); - if (decoded != null) + if (query != null) { + var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(query)); return decoded; } } - catch {;} + catch + { + // ignored + } return url; } diff --git a/GoAwayEdge/Common/Updater.cs b/GoAwayEdge/Common/Updater.cs index e94c4cc..69479cf 100644 --- a/GoAwayEdge/Common/Updater.cs +++ b/GoAwayEdge/Common/Updater.cs @@ -1,9 +1,8 @@ -using Microsoft.Win32; -using System; +using Microsoft.Toolkit.Uwp.Notifications; +using Microsoft.Win32; using System.IO; -using System.Windows; -using Microsoft.Toolkit.Uwp.Notifications; using System.Security.Cryptography; +using System.Windows; namespace GoAwayEdge.Common { @@ -65,20 +64,20 @@ public static int ValidateIfeoBinary() return 2; } - var IfeoBinaryPath = (string)key.GetValue("FilterFullPath"); - if (IfeoBinaryPath == null) + var ifeoBinaryPath = (string)key.GetValue("FilterFullPath"); + if (ifeoBinaryPath == null) { Console.WriteLine("FilterFullPath value not found."); return 2; } - if (File.Exists(IfeoBinaryPath)) + if (File.Exists(ifeoBinaryPath)) { - var EdgeBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge.exe"; - IfeoBinaryPath = Path.GetDirectoryName(IfeoBinaryPath) + "\\msedge_ifeo.exe"; + var edgeBinaryPath = Path.GetDirectoryName(ifeoBinaryPath) + "\\msedge.exe"; + ifeoBinaryPath = Path.GetDirectoryName(ifeoBinaryPath) + "\\msedge_ifeo.exe"; - var edgeHash = CalculateMD5(EdgeBinaryPath); - var ifeoHash = CalculateMD5(IfeoBinaryPath); + var edgeHash = CalculateMD5(edgeBinaryPath); + var ifeoHash = CalculateMD5(ifeoBinaryPath); #if DEBUG if (edgeHash != ifeoHash) MessageBox.Show($"The Edge Hash ({edgeHash}) and Ifeo Hash ({ifeoHash}) are not identical. Validation failed!", "GoAwayEdge", MessageBoxButton.OK, MessageBoxImage.Warning); @@ -88,7 +87,7 @@ public static int ValidateIfeoBinary() } else { - Console.WriteLine($"FilterFullPath does not exist: {IfeoBinaryPath}"); + Console.WriteLine($"FilterFullPath does not exist: {ifeoBinaryPath}"); return 2; } } @@ -123,14 +122,10 @@ public static void ModifyIfeoBinary(ModifyAction action) private static string CalculateMD5(string filename) { - using (var md5 = MD5.Create()) - { - using (var stream = File.OpenRead(filename)) - { - var hash = md5.ComputeHash(stream); - return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); - } - } + using var md5 = MD5.Create(); + using var stream = File.OpenRead(filename); + var hash = md5.ComputeHash(stream); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } } diff --git a/GoAwayEdge/GoAwayEdge.csproj b/GoAwayEdge/GoAwayEdge.csproj index de2a8f3..e4469fe 100644 --- a/GoAwayEdge/GoAwayEdge.csproj +++ b/GoAwayEdge/GoAwayEdge.csproj @@ -13,7 +13,7 @@ GoAwayEdge Exploitox valnoxy - 1.0.2.26 + 1.1.0.31 Copyright (c) 2018 - 2023 Exploitox. All rights reserved. https://github.com/valnoxy/GoAwayEdge https://github.com/valnoxy/GoAwayEdge @@ -21,10 +21,20 @@ GoAwayEdge.ico + + + + + + + + + + diff --git a/GoAwayEdge/GoAwayEdge.csproj.user b/GoAwayEdge/GoAwayEdge.csproj.user index 4b8db3e..c7adc9c 100644 --- a/GoAwayEdge/GoAwayEdge.csproj.user +++ b/GoAwayEdge/GoAwayEdge.csproj.user @@ -27,6 +27,12 @@ Designer + + Designer + + + Designer + Designer diff --git a/GoAwayEdge/Installer.xaml b/GoAwayEdge/Installer.xaml index 0849e68..0d07ecd 100644 --- a/GoAwayEdge/Installer.xaml +++ b/GoAwayEdge/Installer.xaml @@ -6,13 +6,14 @@ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:local="clr-namespace:GoAwayEdge" mc:Ignorable="d" - Title="GoAwayEdge Installer" MaxHeight="500" MaxWidth="800" + Title="{StaticResource Title}" MaxHeight="500" MaxWidth="800" MinHeight="500" MinWidth="800" Height="500" Width="800" WindowStartupLocation="CenterScreen" ExtendsContentIntoTitleBar="True" WindowBackdropType="Mica" WindowCornerPreference="Round" ResizeMode="NoResize"> + @@ -20,31 +21,21 @@ - - + - - - - - - - -