Skip to content

Commit

Permalink
Updated silent switch
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoxy committed Dec 26, 2024
1 parent cd3d64f commit 4aac961
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 40 deletions.
48 changes: 35 additions & 13 deletions GoAwayEdge/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
IsDebug = true;
if (IsAdministrator() == false)
{
ElevateAsAdmin();
ElevateAsAdmin();
Environment.Exit(0);
return;
}
Expand All @@ -70,7 +70,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
{
if (IsAdministrator() == false)
{
ElevateAsAdmin(string.Join(" ", args));
ElevateAsAdmin(string.Join(" ", args));
Environment.Exit(0);
return;
}
Expand Down Expand Up @@ -113,25 +113,47 @@ public void Application_Startup(object sender, StartupEventArgs e)
{
foreach (var arg in args)
{
if (arg.StartsWith("-se:"))
if (arg.StartsWith("-e:"))
Configuration.Search = ArgumentParse.ParseSearchEngine(arg);
if (arg.Contains("--url:"))
if (arg.Contains("--search-url:"))
{
Configuration.CustomQueryUrl = ParseCustomSearchEngine(arg);
Configuration.Search = !string.IsNullOrEmpty(Configuration.CustomQueryUrl) ? SearchEngine.Custom : SearchEngine.Google;
Configuration.CustomQueryUrl = ParseCustomUrl(arg, 13);
Configuration.Search = !string.IsNullOrEmpty(Configuration.CustomQueryUrl)
? SearchEngine.Custom
: SearchEngine.Google;
}

if (arg.Contains("-a:"))
Configuration.AiProvider = ArgumentParse.ParseAiProvider(arg);
if (arg.Contains("--ai-url:"))
{
Configuration.CustomAiProviderUrl = ParseCustomUrl(arg, 9);
Configuration.AiProvider = !string.IsNullOrEmpty(Configuration.CustomAiProviderUrl)
? AiProvider.Custom
: AiProvider.Default;
}

if (arg.Contains("-w:"))
Configuration.WeatherProvider = ArgumentParse.ParseWeatherProvider(arg);
if (arg.Contains("--weather-url:"))
{
Configuration.CustomWeatherProviderUrl = ParseCustomUrl(arg, 14);
Configuration.WeatherProvider = !string.IsNullOrEmpty(Configuration.CustomWeatherProviderUrl)
? WeatherProvider.Custom
: WeatherProvider.Default;
}
}

if (IsAdministrator() == false)
{
ElevateAsAdmin(string.Join(" ", args));
ElevateAsAdmin(string.Join(" ", args));
Environment.Exit(0);
return;
}

Configuration.InitialEnvironment();
InstallRoutine.Install(null);
Environment.Exit(0);
var result = InstallRoutine.Install(null);
Environment.Exit(result);
}
if (args.Contains("-u"))
{
Expand Down Expand Up @@ -191,7 +213,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
ifeoMessageUi.ShowDialog();

if (ifeoMessageUi.Summary == "Btn1")
ElevateAsAdmin("--update");
ElevateAsAdmin("--update");

Environment.Exit(0);
}
Expand All @@ -207,7 +229,7 @@ public void Application_Startup(object sender, StartupEventArgs e)
ifeoMessageUi.ShowDialog();

if (ifeoMessageUi.Summary == "Btn1")
ElevateAsAdmin("--update");
ElevateAsAdmin("--update");

Environment.Exit(0);
}
Expand Down Expand Up @@ -240,9 +262,9 @@ private static void ElevateAsAdmin(string? arguments = null)
Process.Start(startInfo);
}

private static string? ParseCustomSearchEngine(string argument)
private static string? ParseCustomUrl(string argument, int count)
{
var argParsed = argument.Remove(0, 6);
var argParsed = argument.Remove(0, count);
var result = Uri.TryCreate(argParsed, UriKind.Absolute, out var uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
return result ? argParsed : null;
Expand Down
27 changes: 17 additions & 10 deletions GoAwayEdge/Common/Installation/InstallRoutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class Shell32
public static partial void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
}

public static void Install(object? sender, DoWorkEventArgs? e = null)
public static int Install(object? sender, DoWorkEventArgs? e = null)
{
var worker = sender as BackgroundWorker;

Expand All @@ -40,7 +40,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}

// Apply registry key
Expand Down Expand Up @@ -108,7 +108,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}
}
catch (Exception ex)
Expand All @@ -121,7 +121,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}

// Kill Microsoft Edge processes
Expand All @@ -142,7 +142,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}
}
else if (!Configuration.NoEdgeInstalled)
Expand All @@ -163,7 +163,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}
}

Expand Down Expand Up @@ -201,7 +201,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}

// Register Uninstall data
Expand All @@ -216,7 +216,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
messageUi.ShowDialog();
});
Environment.Exit(1);
return;
return 1;
}

// Create Shortcut for Control Panel
Expand All @@ -235,6 +235,7 @@ public static void Install(object? sender, DoWorkEventArgs? e = null)
worker?.ReportProgress(100, "");
Logging.Log("Installation finished.");
Console.WriteLine("Installation finished.");
return 0;
}

public static void Uninstall(object? sender, DoWorkEventArgs? e = null)
Expand Down Expand Up @@ -417,9 +418,15 @@ internal static bool CopyItself(string pathTo, bool overwrite = false)
}
}

catch (Exception e)
catch (Exception ex)
{
MessageBox.Show(e.ToString());
Logging.Log("Failed to copy itself: " + ex, Logging.LogLevel.ERROR);
Application.Current.Dispatcher.Invoke(() =>
{
var errorMessage = LocalizationManager.LocalizeValue("FailedInstallation", ex.Message);
var messageUi = new MessageUi("GoAwayEdge", errorMessage, "OK");
messageUi.ShowDialog();
});
return false;
}

Expand Down
16 changes: 12 additions & 4 deletions GoAwayEdge/Common/Runtime/ArgumentParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public static EdgeChannel ParseEdgeChannel(string argument)

public static AiProvider ParseAiProvider(string argument)
{
return argument.ToLower() switch
var arg = argument;
if (argument.StartsWith("-a:"))
arg = argument.Remove(0, 3);

return arg.ToLower() switch
{
"default" => AiProvider.Default,
"copilot" => AiProvider.Copilot,
Expand All @@ -227,8 +231,8 @@ public static AiProvider ParseAiProvider(string argument)
public static SearchEngine ParseSearchEngine(string argument)
{
var arg = argument;
if (argument.StartsWith("-se:"))
arg = argument.Remove(0, 4);
if (argument.StartsWith("-e:"))
arg = argument.Remove(0, 3);

return arg.ToLower() switch
{
Expand All @@ -248,7 +252,11 @@ public static SearchEngine ParseSearchEngine(string argument)

public static WeatherProvider ParseWeatherProvider(string argument)
{
return argument.ToLower() switch
var arg = argument;
if (argument.StartsWith("-w:"))
arg = argument.Remove(0, 3);

return arg.ToLower() switch
{
"default" => WeatherProvider.Default,
"weathercom" => WeatherProvider.WeatherCom,
Expand Down
1 change: 1 addition & 0 deletions GoAwayEdge/Localization/ResourceDictionary.de-DE.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<!-- Setup finished -->
<system:String x:Key="SetupFinishedTitle">Installation abgeschlossen!</system:String>
<system:String x:Key="SetupFinishedDescription">Öffnen Sie das Installationsprogramm, wenn Sie GoAwayEdge erneut anpassen möchten.</system:String>
<system:String x:Key="SetupFinishedDescriptionWithControlPanel">Öffnen Sie das Installationsprogramm oder das Kontrollpanel, wenn Sie GoAwayEdge erneut anpassen möchten.</system:String>
<system:String x:Key="UninstallFinishedTitle">Deinstallation abgeschlossen!</system:String>
<system:String x:Key="UninstallFinishedDescription">GoAwayEdge wurde erfolgreich vom System entfernt.</system:String>
<system:String x:Key="DonateButton">Über PayPal spenden</system:String>
Expand Down
1 change: 1 addition & 0 deletions GoAwayEdge/Localization/ResourceDictionary.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<!-- Setup finished -->
<system:String x:Key="SetupFinishedTitle">Installation completed!</system:String>
<system:String x:Key="SetupFinishedDescription">Simply open this Installer, if you want to customize GoAwayEdge again.</system:String>
<system:String x:Key="SetupFinishedDescriptionWithControlPanel">Simply open this installer or the Control Panel if you want to customize GoAwayEdge again.</system:String>
<system:String x:Key="UninstallFinishedTitle">Uninstallation completed!</system:String>
<system:String x:Key="UninstallFinishedDescription">GoAwayEdge has been successfully removed from the system.</system:String>
<system:String x:Key="DonateButton">Donate via PayPal</system:String>
Expand Down
3 changes: 1 addition & 2 deletions GoAwayEdge/UserInterface/Setup/Installer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ internal void NextBtn_OnClick(object sender, RoutedEventArgs e)
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = true;
FrameWindow.Content = _redirectOrRemovePage;
SettingPage = new Settings();
break;
}
}
Expand All @@ -81,7 +80,7 @@ private void BackBtn_OnClick(object sender, RoutedEventArgs e)
FrameWindow.Content = LicensePage;
break;
case Settings:
NextBtn.IsEnabled = true;
NextBtn.IsEnabled = false;
BackBtn.IsEnabled = true;
FrameWindow.Content = _redirectOrRemovePage;
break;
Expand Down
7 changes: 6 additions & 1 deletion GoAwayEdge/UserInterface/Setup/Pages/Installation.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Installation()
}
else
{
applyBackgroundWorker.DoWork += InstallRoutine.Install;
applyBackgroundWorker.DoWork += InstallRoutine_Install;
}
applyBackgroundWorker.ProgressChanged += ApplyBackgroundWorker_ProgressChanged;
applyBackgroundWorker.RunWorkerAsync();
Expand All @@ -36,5 +36,10 @@ private static void ApplyBackgroundWorker_ProgressChanged(object? sender, Progre
Installer.ContentWindow?.FrameWindow.NavigationService.Navigate(new InstallationSuccess());
}
}

private static void InstallRoutine_Install(object? sender, DoWorkEventArgs e)
{
e.Result = InstallRoutine.Install(sender, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public InstallationSuccess()
Installer.ContentWindow!.NextBtn.Content = !string.IsNullOrEmpty(exitResource)
? exitResource : "Exit";

var setupDescriptionResource = Configuration.InstallControlPanel ?
(string)Application.Current.MainWindow!.FindResource("SetupFinishedDescriptionWithControlPanel") : (string)Application.Current.MainWindow!.FindResource("SetupFinishedDescription");
SetupDescription.Text = setupDescriptionResource;

if (Configuration.Uninstall)
{
Dispatcher.Invoke(() =>
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<a href="https://translate.valnoxy.dev/engage/goawayedge/">Help me translate</a>
<br />
<br />
🎉 Version 1.3.4 is out. Check out the release notes
🎉 Version 2.0.0 is out. Check out the release notes
<a href="https://github.com/valnoxy/GoAwayEdge/releases">here</a>.
<br />
<br />
Expand Down Expand Up @@ -72,17 +72,21 @@ Feel free to explore the code, contribute, or simply enjoy a browser experience
## 🤫 2. Silent Installation
You can install GoAwayEdge silently by parsing the following arguments:

| Switch | Description |
| ----------------- | ------------------------------------------------------------------------- |
| `-s` | Silent installation |
| `-se:<Engine>` | Specify the Search Engine: `Google` (default), `Bing`, `DuckDuckGo`, `Yahoo`, `Yandex`, `Ecisua`, `Ask`, `Quant`, `Perplexity` |
| `--url:<Url>` | Custom search query url (ex: `https://google.com/search?q=`) |
| Switch | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| `-s` | Silent installation |
| `-e:<Engine>` | Specify the Search Engine: `Google` (default), `Bing`, `DuckDuckGo`, `Yahoo`, `Yandex`, `Ecisua`, `Ask`, `Quant`, `Perplexity` |
| `-a:<AI Service>` | Specify the AI Service: `Default`, `Copilot`, `ChatGPT`, `Gemini`, `GitHub_Copilot`, `Grok`, |
| `-w:<Weather Service>` | Specify the Weather Service: `Default`, `WeatherCom`, `AccuWeather` |
| `--search-url:<Url>` | Custom search query url (ex: `https://google.com/search?q=`) |
| `--ai-url:<Url>` | Custom AI website (ex: `https://chatgpt.com`) |
| `--weather-url:<Url>` | Custom weather query url (ex: `https://my-weather.com/{country-code}/{latitude},{longitude}`) |

<b>Example</b>:

```bat
GoAwayEdge.exe -s -se:DuckDuckGo
```
GoAwayEdge.exe -s -e:DuckDuckGo
```

# 🗑️ Remove GoAwayEdge
You can uninstall GoAwayEdge just like any other application. Alternatively, you can also take this way:
Expand All @@ -91,7 +95,7 @@ You can uninstall GoAwayEdge just like any other application. Alternatively, you
3. Click on ```Uninstall```.
4. Done!

You can also uninstall GoAwayEdge by parsing the following argument:
You can also silently uninstall GoAwayEdge by parsing the following argument:
```bat
GoAwayEdge.exe -u
```
Expand All @@ -110,7 +114,7 @@ This project uses the following libraries:
GoAwayEdge is licensed under [MIT](https://github.com/valnoxy/GoAwayEdge/blob/main/LICENSE). So you are allowed to use freely and modify the application. I will not be responsible for any outcome. Proceed with any action at your own risk.

<hr>
<h6 align="center">© 2018 - 2024 valnoxy. All Rights Reserved.
<h6 align="center">© 2018 - 2025 valnoxy. All Rights Reserved.
<br>
By Jonas Günner &lt;[email protected]&gt;</h6>
<p align="center">
Expand Down

0 comments on commit 4aac961

Please sign in to comment.