Skip to content

Commit

Permalink
Added empty string validation
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoxy committed Oct 18, 2023
1 parent 166ae9c commit 2785fb1
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 48 deletions.
14 changes: 7 additions & 7 deletions GoAwayEdge/App.xaml.cs
Expand Up @@ -62,7 +62,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
Updater.InitialEnvironment();

#if DEBUG
var w = new MessageUI("GoAwayEdge",
var w = new MessageUi("GoAwayEdge",
$"The following args are redirected (CTRL+C to copy):\n\n{argumentJoin}", "OK", null, true);
w.ShowDialog();
#endif
Expand Down Expand Up @@ -90,7 +90,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
case 1: // failed validation
if (IsAdministrator() == false)
{
var ifeoMessageUi = new MessageUI("GoAwayEdge",
var ifeoMessageUi = new MessageUi("GoAwayEdge",
"The IFEO exclusion file needs to be updated. Update now?", "No", "Yes");
ifeoMessageUi.ShowDialog();

Expand Down Expand Up @@ -118,7 +118,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
case 2: // missing
if (IsAdministrator() == false)
{
var ifeoMessageUi = new MessageUI("GoAwayEdge",
var ifeoMessageUi = new MessageUi("GoAwayEdge",
"The IFEO exclusion file is missing and need to be copied. Copy now?", "No", "Yes");
ifeoMessageUi.ShowDialog();

Expand Down Expand Up @@ -170,7 +170,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
if (!args.Contains("--profile-directory") && !ContainsParsedData(args) && args.Length != 2) continue; // Start Edge (default browser on this system)

#if DEBUG
var messageUi = new MessageUI("GoAwayEdge",
var messageUi = new MessageUi("GoAwayEdge",
$"Microsoft Edge will now start normally via IFEO application.", "OK", null, true);
messageUi.ShowDialog();
#endif
Expand Down Expand Up @@ -198,7 +198,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
p.StartInfo.Arguments = "microsoft-edge://?ux=copilot&tcp=1&source=taskbar";
Output.WriteLine("Opening Windows Copilot", ConsoleColor.Gray);
#if DEBUG
var copilotMessageUi = new MessageUI("GoAwayEdge",
var copilotMessageUi = new MessageUi("GoAwayEdge",
"Opening Windows Copilot ...", "OK", null, true);
copilotMessageUi.ShowDialog();
#endif
Expand All @@ -208,7 +208,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
var parsed = ParseUrl(_url);
Output.WriteLine("Opening URL in default browser:\n\n" + parsed + "\n", ConsoleColor.Gray);
#if DEBUG
var defaultUrlMessageUi = new MessageUI("GoAwayEdge",
var defaultUrlMessageUi = new MessageUi("GoAwayEdge",
"Opening URL in default browser:\n\n" + parsed + "\n", "OK", null, true);
defaultUrlMessageUi.ShowDialog();
#endif
Expand Down Expand Up @@ -259,7 +259,7 @@ private static string ParseUrl(string encodedUrl)
encodedUrl = encodedUrl.Replace("https://www.bing.com/search?q=", DefineEngine(_engine));

#if DEBUG
var uriMessageUi = new MessageUI("GoAwayEdge",
var uriMessageUi = new MessageUi("GoAwayEdge",
"New Uri: " + encodedUrl, "OK", null, true);
uriMessageUi.ShowDialog();
#endif
Expand Down
6 changes: 3 additions & 3 deletions GoAwayEdge/Common/Updater.cs
Expand Up @@ -39,7 +39,7 @@ public static bool InitialEnvironment()
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
var messageUi = new MessageUi("GoAwayEdge",
$"Initialization failed!\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
return false;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static int ValidateIfeoBinary()
var ifeoHash = CalculateMd5(ifeoBinaryPath);
#if DEBUG
if (edgeHash != ifeoHash) {
var messageUi = new MessageUI("GoAwayEdge",
var messageUi = new MessageUi("GoAwayEdge",
$"The Edge Hash ({edgeHash}) and Ifeo Hash ({ifeoHash}) are not identical. Validation failed!", "OK", null,true);
messageUi.ShowDialog();
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public static void ModifyIfeoBinary(ModifyAction action)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
var messageUi = new MessageUi("GoAwayEdge",
$"Update failed!\n{ex.Message}!", "OK", null, true);
messageUi.ShowDialog();
}
Expand Down
2 changes: 1 addition & 1 deletion GoAwayEdge/GoAwayEdge.csproj
Expand Up @@ -13,7 +13,7 @@
<AssemblyName>GoAwayEdge</AssemblyName>
<Company>Exploitox</Company>
<Authors>valnoxy</Authors>
<Version>1.1.1.42</Version>
<Version>1.2.0.62</Version>
<Copyright>Copyright (c) 2018 - 2023 Exploitox. All rights reserved.</Copyright>
<PackageProjectUrl>https://github.com/valnoxy/GoAwayEdge</PackageProjectUrl>
<RepositoryUrl>https://github.com/valnoxy/GoAwayEdge</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion GoAwayEdge/GoAwayEdge.csproj.user
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\jonas\source\repos\GoAwayEdge\GoAwayEdge\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
<_LastSelectedProfileId>C:\Users\jonas\Documents\Git\GoAwayEdge\GoAwayEdge\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
<ItemGroup>
<Compile Update="App.xaml.cs">
Expand Down
10 changes: 6 additions & 4 deletions GoAwayEdge/Installer.xaml.cs
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using GoAwayEdge.Common;
using GoAwayEdge.Pages;

namespace GoAwayEdge
Expand All @@ -13,7 +14,7 @@ public partial class Installer
internal static Installer? ContentWindow;
private static License? _licensePage;
private static Settings? _settingPage;

public Installer()
{
InitializeComponent();
Expand All @@ -39,9 +40,10 @@ public Installer()
}
catch (Exception ex)
{
// TODO: Implement message box
// Failed to load language: {ex.Message}
return;
var messageUi = new MessageUi("GoAwayEdge",
$"Failed to load language: {ex.Message}", "OK", null, true);
messageUi.ShowDialog();
Environment.Exit(1);
}

_licensePage = new License();
Expand Down
2 changes: 1 addition & 1 deletion GoAwayEdge/MessageUI.xaml
@@ -1,4 +1,4 @@
<ui:UiWindow x:Class="GoAwayEdge.MessageUI"
<ui:UiWindow x:Class="GoAwayEdge.MessageUi"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down
13 changes: 5 additions & 8 deletions GoAwayEdge/MessageUI.xaml.cs
@@ -1,9 +1,6 @@
// Copyright (c) 2023 valnoxy
// Copied from Dive: https://github.com/valnoxy/Dive/blob/main/Dive/Dive.UI/MessageUI.xaml.cs

using System;
using System.Threading;
using System.Timers;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
Expand All @@ -13,15 +10,15 @@ namespace GoAwayEdge
/// <summary>
/// Interaktionslogik für MessageUI.xaml
/// </summary>
public partial class MessageUI
public partial class MessageUi
{
public virtual string? Summary => _buttonPressed;

private static string? _buttonPressed;
private static bool _mainThread;
private readonly DispatcherTimer _timer;
private readonly DispatcherTimer _timer = null!;

public MessageUI(string title, string message, string? btn1 = null, string? btn2 = null, bool isMainThread = false, int timer = 0)
public MessageUi(string title, string message, string? btn1 = null, string? btn2 = null, bool isMainThread = false, int timer = 0)
{
InitializeComponent();

Expand All @@ -41,10 +38,10 @@ public MessageUI(string title, string message, string? btn1 = null, string? btn2

_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
LbTimer.Text = $"{time.ToString("%s")}s before auto-selecting '{this.Btn2.Content}'.";
LbTimer.Text = $"{time:%s}s before auto-selecting '{this.Btn2.Content}'.";
if (time == TimeSpan.Zero)
{
_timer?.Stop();
_timer.Stop();
_buttonPressed = "Btn2";
if (_mainThread) this.Hide();
else this.Close();
Expand Down
30 changes: 8 additions & 22 deletions GoAwayEdge/Pages/Installation.xaml.cs
Expand Up @@ -49,9 +49,7 @@ private static void Install(object? sender, DoWorkEventArgs e)
var status = CopyItself(Path.Combine(instDir, "GoAwayEdge.exe"), Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName) != instDir);
if (status == false)
{
var messageUi = new MessageUI("GoAwayEdge",
"Installation failed! Please try again.", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show("Installation failed! Please try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand Down Expand Up @@ -104,9 +102,7 @@ private static void Install(object? sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Installation failed!\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show($"Installation failed!\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand All @@ -118,9 +114,7 @@ private static void Install(object? sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Installation failed!\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show($"Installation failed!\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand All @@ -137,9 +131,7 @@ private static void Install(object? sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Installation failed!\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show($"Installation failed!\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand All @@ -166,9 +158,7 @@ private static void Uninstall(object? sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Uninstallation failed! Please try again.\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show($"Uninstallation failed! Please try again.\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand All @@ -182,9 +172,7 @@ private static void Uninstall(object? sender, DoWorkEventArgs e)
}
catch (Exception ex)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Uninstallation failed! Please try again.\n{ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show($"Uninstallation failed! Please try again.\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
return;
}
Expand Down Expand Up @@ -225,11 +213,9 @@ public static bool CopyItself(string pathTo, bool overwrite = false)
}
}

catch (Exception ex)
catch (Exception e)
{
var messageUi = new MessageUI("GoAwayEdge",
$"Copy failed: {ex.Message}", "OK", null, true);
messageUi.ShowDialog();
MessageBox.Show(e.ToString());
return false;
}

Expand Down
12 changes: 12 additions & 0 deletions GoAwayEdge/Pages/Settings.xaml.cs
Expand Up @@ -83,38 +83,48 @@ private void SearchEngineBox_OnSelectionChanged(object sender, SelectionChangedE
case 0:
Configuration.Search = SearchEngine.Google;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 1:
Configuration.Search = SearchEngine.Bing;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 2:
Configuration.Search = SearchEngine.DuckDuckGo;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 3:
Configuration.Search = SearchEngine.Yahoo;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 4:
Configuration.Search = SearchEngine.Yandex;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 5:
Configuration.Search = SearchEngine.Ecosia;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 6:
Configuration.Search = SearchEngine.Ask;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 7:
Configuration.Search = SearchEngine.Qwant;
CustomSearchPanel.Visibility = Visibility.Collapsed;
Installer.ContentWindow!.NextBtn.IsEnabled = true;
break;
case 8:
Configuration.Search = SearchEngine.Custom;
CustomSearchPanel.Visibility = Visibility.Visible;
if (string.IsNullOrEmpty(Configuration.CustomQueryUrl))
Installer.ContentWindow!.NextBtn.IsEnabled = false;
break;
}
}
Expand All @@ -137,6 +147,8 @@ private void UninstallSwitch_OnClick(object sender, RoutedEventArgs e)
private void QueryUrlTextBox_OnTextChanged(object sender, TextChangedEventArgs e)
{
Configuration.CustomQueryUrl = QueryUrlTextBox.Text;
Installer.ContentWindow!.NextBtn.IsEnabled = Uri.TryCreate(QueryUrlTextBox.Text, UriKind.Absolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
}
}
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2022-11-13T01:33:03.7406004Z;True|2022-11-13T02:19:07.9073988+01:00;True|2022-11-13T02:18:35.3043045+01:00;True|2022-11-12T20:05:07.6366825+01:00;False|2022-11-12T20:04:52.3576134+01:00;True|2022-11-12T19:36:12.8480978+01:00;</History>
<History>True|2023-10-18T22:00:28.0962969Z;True|2022-11-13T02:33:03.7406004+01:00;True|2022-11-13T02:19:07.9073988+01:00;True|2022-11-13T02:18:35.3043045+01:00;True|2022-11-12T20:05:07.6366825+01:00;False|2022-11-12T20:04:52.3576134+01:00;True|2022-11-12T19:36:12.8480978+01:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

0 comments on commit 2785fb1

Please sign in to comment.