From 61ccb4f1a11d9ced3473e52cffb021cb0efe5201 Mon Sep 17 00:00:00 2001
From: Miepee <38186597+Miepee@users.noreply.github.com>
Date: Sun, 25 Jul 2021 12:29:36 +0200
Subject: [PATCH] Linux - Show visible error, if xdelta3/ java doesn't exist,
Fixes #18
---
.../AM2RLauncher/CrossPlatformOperations.cs | 85 ++++++++++++++-----
.../AM2RLauncher/MainForm/MainForm.Methods.cs | 34 +++++++-
2 files changed, 95 insertions(+), 24 deletions(-)
diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
index 2d47d4e..29b7255 100644
--- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
+++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs
@@ -215,40 +215,79 @@ namespace AM2RLauncher
/// if it is installed, if not.
public static bool IsJavaInstalled()
{
+ string process = null;
+ string arguments = null;
+
if (currentPlatform.IsWinForms)
{
- string process = "cmd.exe",
- arguments = "/C java -version";
- ProcessStartInfo javaStart = new ProcessStartInfo();
- javaStart.FileName = process;
- javaStart.Arguments = arguments;
- javaStart.UseShellExecute = false;
- javaStart.CreateNoWindow = true;
+ process = "cmd.exe";
+ arguments = "/C java -version";
+ }
+ else if (currentPlatform.IsGtk)
+ {
+ process = "java";
+ arguments = "-version";
+ }
+ ProcessStartInfo javaStart = new ProcessStartInfo();
+ javaStart.FileName = process;
+ javaStart.Arguments = arguments;
+ javaStart.UseShellExecute = false;
+ javaStart.CreateNoWindow = true;
- Process java = new Process();
- java.StartInfo = javaStart;
+ Process java = new Process();
- //this is primarily for linux, but could be happening on windows as well
- try
- {
- java.Start();
+ java.StartInfo = javaStart;
- java.WaitForExit();
- }
- catch (System.ComponentModel.Win32Exception)
- {
- return false;
- }
+ //this is primarily for linux, but could be happening on windows as well
+ try
+ {
+ java.Start();
- return java.ExitCode == 0;
+ java.WaitForExit();
}
- else if (currentPlatform.IsGtk)
+ catch (System.ComponentModel.Win32Exception)
{
- return true; // sorry linux users, either Eto, .net or GTK is dumb.
+ return false;
}
- return false;
+
+ return java.ExitCode == 0;
+
+ }
+
+ ///
+ /// Checks if command-line xdelta is installed on non-Windows systems.
+ ///
+ /// if it is installed, if not.
+ public static bool CheckIfXdeltaIsInstalled()
+ {
+ string process = "xdelta3";
+ string arguments = "-V";
+
+ ProcessStartInfo xdeltaStart = new ProcessStartInfo();
+ xdeltaStart.FileName = process;
+ xdeltaStart.Arguments = arguments;
+ xdeltaStart.UseShellExecute = false;
+ xdeltaStart.CreateNoWindow = true;
+
+
+ Process xdelta = new Process();
+
+ xdelta.StartInfo = xdeltaStart;
+
+ try
+ {
+ xdelta.Start();
+
+ xdelta.WaitForExit();
+ }
+ catch (System.ComponentModel.Win32Exception)
+ {
+ return false;
+ }
+
+ return xdelta.ExitCode == 0;
}
///
diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
index 8e1e885..911bad2 100644
--- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
+++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs
@@ -251,6 +251,19 @@ namespace AM2RLauncher
{
log.Info("Installing profile " + profile.Name + "...");
+ // check if xdelta is installed on linux, by searching all folders in PATH
+ if (Platform.IsGtk && !CrossPlatformOperations.CheckIfXdeltaIsInstalled())
+ {
+ Application.Instance.Invoke(new Action(() =>
+ {
+ MessageBox.Show(Language.Text.XdeltaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK);
+ }));
+ SetPlayButtonState(UpdateState.Install);
+ UpdateStateMachine();
+ log.Error("Xdelta not found. Aborting installing a profile...");
+ return;
+ }
+
string profilesHomePath = CrossPlatformOperations.CURRENTPATH + "/Profiles";
string profilePath = profilesHomePath + "/" + profile.Name;
@@ -420,13 +433,32 @@ namespace AM2RLauncher
// Check for java, exit safely with a warning if not found!
if (!CrossPlatformOperations.IsJavaInstalled())
{
- MessageBox.Show(Language.Text.JavaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK);
+ //message box show needs to be done on main thread
+ Application.Instance.Invoke(new Action(() =>
+ {
+ MessageBox.Show(Language.Text.JavaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK);
+ }));
SetApkButtonState(ApkButtonState.Create);
UpdateStateMachine();
log.Error("Java not found! Aborting Android APK creation.");
return;
}
+ // check if xdelta is installed on linux, by searching all folders in PATH
+ if (Platform.IsGtk && !CrossPlatformOperations.CheckIfXdeltaIsInstalled())
+ {
+ //message box show needs to be done on main thread
+ Application.Instance.Invoke(new Action(() =>
+ {
+ MessageBox.Show(Language.Text.XdeltaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK);
+ }));
+ SetApkButtonState(ApkButtonState.Create);
+ UpdateStateMachine();
+ log.Error("Xdelta not found. Aborting Android APK creation...");
+ return;
+
+ }
+
log.Debug("java installed!");
string proc = "",