Refactor some more

- use common method for newswebview and changelogwebview- loaded
- create method to get an openfiledialog with our common parameters.
- change messageboxes to be bound to the parent form
- fix downloaidng being accidentally cancelled
- and more
pull/32/head
Miepee 4 years ago
parent a41d8d6312
commit 428387256f

@ -14,6 +14,8 @@ using System.Threading.Tasks;
namespace AM2RLauncher namespace AM2RLauncher
{ {
//TODO: comment a bunch of this stuf for readability
/// <summary> /// <summary>
/// Methods for UI Events that get triggered go in here /// Methods for UI Events that get triggered go in here
/// </summary> /// </summary>
@ -54,7 +56,7 @@ namespace AM2RLauncher
log.Error("Druid PatchData corruption occurred!"); log.Error("Druid PatchData corruption occurred!");
await Application.Instance.InvokeAsync(() => await Application.Instance.InvokeAsync(() =>
{ {
MessageBox.Show(Text.CorruptPatchData, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, Text.CorruptPatchData, Text.ErrorWindowTitle, MessageBoxType.Error);
}); });
HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData"); HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData");
return; return;
@ -63,7 +65,7 @@ namespace AM2RLauncher
catch (UserCancelledException ex) catch (UserCancelledException ex)
{ {
log.Info(ex.Message); log.Info(ex.Message);
MessageBox.Show(Text.CorruptPatchData, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, Text.CorruptPatchData, Text.ErrorWindowTitle, MessageBoxType.Error);
HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData"); HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData");
} }
catch (LibGit2SharpException ex) // This is for any exceptions from libgit catch (LibGit2SharpException ex) // This is for any exceptions from libgit
@ -75,19 +77,19 @@ namespace AM2RLauncher
if (!(bool)autoUpdateAM2RCheck.Checked) if (!(bool)autoUpdateAM2RCheck.Checked)
{ {
log.Error("Internet connection failed while attempting to pull repository" + currentMirror + "!"); log.Error("Internet connection failed while attempting to pull repository" + currentMirror + "!");
MessageBox.Show(Text.InternetConnectionDrop, Text.WarningWindowTitle, MessageBoxType.Warning); MessageBox.Show(this, Text.InternetConnectionDrop, Text.WarningWindowTitle, MessageBoxType.Warning);
} }
} }
else else
{ {
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error);
} }
} }
catch (Exception ex) // This is if somehow any other exception might get thrown as well. catch (Exception ex) // This is if somehow any other exception might get thrown as well.
{ {
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error);
} }
finally finally
{ {
@ -171,12 +173,12 @@ namespace AM2RLauncher
ex.Message.ToLower().Contains("failed to resolve address")) ex.Message.ToLower().Contains("failed to resolve address"))
{ {
log.Error("Internet connection dropped while attempting to clone repository" + currentMirror + "!"); log.Error("Internet connection dropped while attempting to clone repository" + currentMirror + "!");
MessageBox.Show(Text.InternetConnectionDrop, Text.WarningWindowTitle, MessageBoxType.Warning); MessageBox.Show(this, Text.InternetConnectionDrop, Text.WarningWindowTitle, MessageBoxType.Warning);
} }
else else
{ {
log.Error("LibGit2SharpException: " + ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); log.Error("LibGit2SharpException: " + ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error);
if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData")) if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData"))
HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData"); HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData");
} }
@ -185,7 +187,7 @@ namespace AM2RLauncher
catch (Exception ex) // This is if somehow any other exception might get thrown as well. catch (Exception ex) // This is if somehow any other exception might get thrown as well.
{ {
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error);
if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + " / PatchData")) if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + " / PatchData"))
HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData"); HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData");
@ -217,14 +219,13 @@ namespace AM2RLauncher
#region Downloading #region Downloading
case UpdateState.Downloading: case UpdateState.Downloading:
var result = MessageBox.Show(Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No); var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No);
if (result == DialogResult.No) if (result != DialogResult.Yes)
return; return;
else
{
log.Info("User cancelled download!"); log.Info("User cancelled download!");
isGitProcessGettingCancelled = true; isGitProcessGettingCancelled = true;
}
// We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :)
// But we should probably wait a bit before proceeding, since cleanup can take a while // But we should probably wait a bit before proceeding, since cleanup can take a while
Thread.Sleep(1000); Thread.Sleep(1000);
@ -238,14 +239,7 @@ namespace AM2RLauncher
log.Info("Requesting user input for AM2R_11.zip..."); log.Info("Requesting user input for AM2R_11.zip...");
OpenFileDialog fileFinder = new OpenFileDialog OpenFileDialog fileFinder = GetSingleZipDialog(Text.Select11FileDialog);
{
Directory = new Uri(CrossPlatformOperations.CURRENTPATH),
MultiSelect = false,
Title = Text.Select11FileDialog
};
fileFinder.Filters.Add(new FileFilter(Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok) if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{ {
@ -253,20 +247,10 @@ namespace AM2RLauncher
return; return;
} }
if (!String.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default // Default filename is whitespace
{ if (String.IsNullOrWhiteSpace(fileFinder.FileName))
if (Directory.Exists(fileFinder.FileName))
{
// This can happen on linux, and maybe windows as well
log.Error("User selected a Directory. Cancelling import.");
return;
}
IsZipAM2R11ReturnCodes errorCode = Profile.CheckIfZipIsAM2R11(fileFinder.FileName);
if (errorCode != IsZipAM2R11ReturnCodes.Successful)
{ {
log.Error("User tried to input invalid AM2R_11.zip file (" + errorCode + "). Cancelling import."); log.Error("User did not supply valid input. Cancelling import.");
MessageBox.Show(Text.ZipIsNotAM2R11 + "\n\nError Code: " + errorCode, Text.ErrorWindowTitle, MessageBoxType.Error);
return; return;
} }
@ -277,16 +261,19 @@ namespace AM2RLauncher
break; break;
} }
IsZipAM2R11ReturnCodes errorCode = Profile.CheckIfZipIsAM2R11(fileFinder.FileName);
if (errorCode != IsZipAM2R11ReturnCodes.Successful)
{
log.Error("User tried to input invalid AM2R_11.zip file (" + errorCode + "). Cancelling import.");
MessageBox.Show(this, Text.ZipIsNotAM2R11 + "\n\nError Code: " + errorCode, Text.ErrorWindowTitle, MessageBoxType.Error);
return;
}
// We check if it exists first, because someone coughDRUIDcough might've copied it into here while on the showDialog // We check if it exists first, because someone coughDRUIDcough might've copied it into here while on the showDialog
if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")) if (fileFinder.FileName != CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")
File.Copy(fileFinder.FileName, CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip"); File.Copy(fileFinder.FileName, CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip");
log.Info("AM2R_11.zip successfully imported."); log.Info("AM2R_11.zip successfully imported.");
}
else
{
log.Error("User did not supply valid input. Cancelling import.");
}
UpdateStateMachine(); UpdateStateMachine();
break; break;
@ -305,36 +292,34 @@ namespace AM2RLauncher
// If the file cannot be launched due to anti-virus shenanigans or any other reason, we try catch here // If the file cannot be launched due to anti-virus shenanigans or any other reason, we try catch here
try try
{ {
// Check if xdelta is installed on linux´and exit if not // Check if xdelta is installed on unix and exit if not
if ((OS.IsUnix) && !CrossPlatformOperations.CheckIfXdeltaIsInstalled()) if (OS.IsUnix && !CrossPlatformOperations.CheckIfXdeltaIsInstalled())
{ {
MessageBox.Show(Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK); MessageBox.Show(this, Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK);
SetPlayButtonState(UpdateState.Install); SetPlayButtonState(UpdateState.Install);
UpdateStateMachine(); UpdateStateMachine();
log.Error("Xdelta not found. Aborting installing a profile..."); log.Error("Xdelta not found. Aborting installing a profile...");
break; return;
} }
var progressIndicator = new Progress<int>(UpdateProgressBar); var progressIndicator = new Progress<int>(UpdateProgressBar);
bool useHqMusic = hqMusicPCCheck.Checked.Value; bool useHqMusic = hqMusicPCCheck.Checked.Value;
await Task.Run(() => Profile.InstallProfile(profileList[profileIndex.Value], useHqMusic, progressIndicator)); await Task.Run(() => Profile.InstallProfile(profileList[profileIndex.Value], useHqMusic, progressIndicator));
// This is just for visuals because the average windows end user will ask why it doesn't go to the end otherwise. // This is just for visuals because the average windows end user will ask why it doesn't go to the end otherwise.
if (OS.IsWindows) if (OS.IsWindows)
Thread.Sleep(1000); Thread.Sleep(500);
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace);
MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Text.ErrorWindowTitle, MessageBoxType.Error);
} }
progressBar.Visible = false; progressBar.Visible = false;
progressBar.Value = 0; progressBar.Value = 0;
// Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something // Just need to switch this to anything that isn't an "active" state so SetUpdateState() actually does something
SetPlayButtonState(UpdateState.Play); SetPlayButtonState(UpdateState.Play);
UpdateStateMachine(); UpdateStateMachine();
break; break;
#endregion #endregion
@ -345,9 +330,7 @@ namespace AM2RLauncher
return; return;
ProfileXML profile = profileList[profileIndex.Value]; ProfileXML profile = profileList[profileIndex.Value];
Visible = false; Visible = false;
SetPlayButtonState(UpdateState.Playing); SetPlayButtonState(UpdateState.Playing);
// Make sure the main interface state machines properly // Make sure the main interface state machines properly
@ -357,8 +340,6 @@ namespace AM2RLauncher
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
trayIndicator.Visible = true; trayIndicator.Visible = true;
WindowState windowStateBeforeLaunching = this.WindowState; WindowState windowStateBeforeLaunching = this.WindowState;
if (windowStateBeforeLaunching == WindowState.Maximized)
this.WindowState = WindowState.Normal;
Minimize(); Minimize();
string envVarText = customEnvVarTextBox?.Text; string envVarText = customEnvVarTextBox?.Text;
@ -370,66 +351,41 @@ namespace AM2RLauncher
trayIndicator.Visible = false; trayIndicator.Visible = false;
Show(); Show();
BringToFront(); BringToFront();
if (windowStateBeforeLaunching == WindowState.Maximized) Visible = true;
Maximize(); WindowState = windowStateBeforeLaunching;
SetPlayButtonState(UpdateState.Play); SetPlayButtonState(UpdateState.Play);
UpdateStateMachine(); UpdateStateMachine();
Visible = true;
break; break;
#endregion #endregion
default: break; default: throw new NotImplementedException("Encountered invalid update state: " + updateState + "!");
} }
} }
/// <summary>
/// This is just a helper method for the git commands in order to have a progress bar display for them.
/// </summary>
private bool TransferProgressHandlerMethod(TransferProgress transferProgress)
{
// Thank you random issue on the gitlib2sharp repo!!!!
// Also tldr; rtfm
if (isGitProcessGettingCancelled) return false;
// This needs to be in an Invoke, in order to access the variables from the main thread
// Otherwise this will throw a runtime exception
Application.Instance.Invoke(() =>
{
progressBar.MinValue = 0;
progressBar.MaxValue = transferProgress.TotalObjects;
if (currentGitObject >= transferProgress.ReceivedObjects)
return;
progressLabel.Text = Text.ProgressbarProgress + " " + transferProgress.ReceivedObjects + " (" + ((int)transferProgress.ReceivedBytes / 1000000) + "MB) / " + transferProgress.TotalObjects + " objects";
currentGitObject = transferProgress.ReceivedObjects;
progressBar.Value = transferProgress.ReceivedObjects;
});
return true;
}
/// <summary> /// <summary>
/// Does stuff, depending on the current state of <see cref="apkButtonState"/>. /// Does stuff, depending on the current state of <see cref="apkButtonState"/>.
/// </summary> /// </summary>
private async void ApkButtonClickEvent(object sender, EventArgs e) private async void ApkButtonClickEvent(object sender, EventArgs e)
{ {
// If we're currently creating something, exit
if (apkButtonState == ApkButtonState.Creating) return;
// Check for java, exit safely with a warning if not found! // Check for java, exit safely with a warning if not found!
if (!CrossPlatformOperations.IsJavaInstalled()) if (!CrossPlatformOperations.IsJavaInstalled())
{ {
MessageBox.Show(Text.JavaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK); MessageBox.Show(this, Text.JavaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK);
SetApkButtonState(ApkButtonState.Create); SetApkButtonState(ApkButtonState.Create);
UpdateStateMachine(); UpdateStateMachine();
log.Error("Java not found! Aborting Android APK creation."); log.Error("Java not found! Aborting Android APK creation.");
return; return;
} }
// Check if xdelta is installed on linux
// Check if xdelta is installed on unix, exit with a warning if not.
if (OS.IsUnix && !CrossPlatformOperations.CheckIfXdeltaIsInstalled()) if (OS.IsUnix && !CrossPlatformOperations.CheckIfXdeltaIsInstalled())
{ {
MessageBox.Show(Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK); MessageBox.Show(this, Text.XdeltaNotFound, Text.WarningWindowTitle, MessageBoxButtons.OK);
SetApkButtonState(ApkButtonState.Create); SetApkButtonState(ApkButtonState.Create);
UpdateStateMachine(); UpdateStateMachine();
log.Error("Xdelta not found. Aborting Android APK creation..."); log.Error("Xdelta not found. Aborting Android APK creation...");
@ -441,7 +397,6 @@ namespace AM2RLauncher
if (apkButtonState == ApkButtonState.Create) if (apkButtonState == ApkButtonState.Create)
{ {
SetApkButtonState(ApkButtonState.Creating); SetApkButtonState(ApkButtonState.Creating);
UpdateStateMachine(); UpdateStateMachine();
progressBar.Visible = true; progressBar.Visible = true;
@ -451,50 +406,31 @@ namespace AM2RLauncher
await Task.Run(() => Profile.CreateAPK(profileList[profileIndex.Value], useHqMusic, progressIndicator)); await Task.Run(() => Profile.CreateAPK(profileList[profileIndex.Value], useHqMusic, progressIndicator));
SetApkButtonState(ApkButtonState.Create); SetApkButtonState(ApkButtonState.Create);
progressBar.Visible = false; progressBar.Visible = false;
}
UpdateStateMachine(); UpdateStateMachine();
} }
/// <summary>
/// Runs on <see cref="newsWebView"/>'s DocumentLoaded event. Manages the warning for no internet connection.
/// </summary>
private void NewsWebViewDocumentLoaded(object sender, WebViewLoadedEventArgs e)
{
if (!isInternetThere)
{
newsPage.Content = new TableLayout
{
Rows =
{
null,
newsNoConnectionLabel,
null
}
};
}
} }
/// <summary> /// <summary>
/// Runs on <see cref="changelogWebView"/>'s DocumentLoaded event. Manages the warning for no internet connection. /// If no internet access is available, this changes the content of <paramref name="tabPage"/> to an empty page only displaying <paramref name="errorLabel"/>.
/// </summary> /// </summary>
private void ChangelogWebViewDocumentLoaded(object sender, WebViewLoadedEventArgs e) /// <param name="tabPage">The <see cref="TabPage"/> to change the contents of.</param>
/// <param name="errorLabel">The <see cref="Label"/> that should be displayed.</param>
private void ChangeToEmptyPageOnNoInternet(TabPage tabPage, Label errorLabel)
{ {
if (!isInternetThere) if (isInternetThere)
{ return;
changelogPage.Content = new TableLayout
tabPage.Content = new TableLayout
{ {
Rows = Rows =
{ {
null, null,
changelogNoConnectionLabel, errorLabel,
null null
} }
}; };
} }
}
/// <summary> /// <summary>
/// Runs when <see cref="addModButton"/> is clicked. Brings up a file select to select a mod, and adds that to the mod directory. /// Runs when <see cref="addModButton"/> is clicked. Brings up a file select to select a mod, and adds that to the mod directory.
@ -503,14 +439,7 @@ namespace AM2RLauncher
{ {
log.Info("User requested to add mod. Requesting user input for new mod .zip..."); log.Info("User requested to add mod. Requesting user input for new mod .zip...");
OpenFileDialog fileFinder = new OpenFileDialog OpenFileDialog fileFinder = GetSingleZipDialog(Text.SelectModFileDialog);
{
Directory = new Uri(CrossPlatformOperations.CURRENTPATH),
MultiSelect = false,
Title = Text.SelectModFileDialog
};
fileFinder.Filters.Add(new FileFilter(Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok) if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{ {
@ -547,7 +476,7 @@ namespace AM2RLauncher
ProfileXML profile2 = Serializer.Deserialize<ProfileXML>(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml")); ProfileXML profile2 = Serializer.Deserialize<ProfileXML>(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml"));
log.Error("Mod is already imported as " + extractedName + "! Cancelling mod import."); log.Error("Mod is already imported as " + extractedName + "! Cancelling mod import.");
MessageBox.Show(HelperMethods.GetText(Text.ModIsAlreadyInstalledMessage, profile2.Name), Text.WarningWindowTitle, MessageBoxType.Warning); MessageBox.Show(this, HelperMethods.GetText(Text.ModIsAlreadyInstalledMessage, profile2.Name), Text.WarningWindowTitle, MessageBoxType.Warning);
return; return;
} }
// Directory doesn't exist -> extract! // Directory doesn't exist -> extract!
@ -559,7 +488,7 @@ namespace AM2RLauncher
{ {
log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod import."); log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod import.");
MessageBox.Show(HelperMethods.GetText(Text.ModIsInvalidMessage, extractedName), Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, HelperMethods.GetText(Text.ModIsInvalidMessage, extractedName), Text.ErrorWindowTitle, MessageBoxType.Error);
Directory.Delete(modsDir + "/" + extractedName, true); Directory.Delete(modsDir + "/" + extractedName, true);
File.Delete(CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name); File.Delete(CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name);
return; return;
@ -572,7 +501,7 @@ namespace AM2RLauncher
{ {
log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + OS.Name + ". Cancelling mod import."); log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + OS.Name + ". Cancelling mod import.");
MessageBox.Show(HelperMethods.GetText(Text.ModIsForWrongOS, profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", OS.Name), MessageBox.Show(this, HelperMethods.GetText(Text.ModIsForWrongOS, profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", OS.Name),
Text.ErrorWindowTitle, MessageBoxType.Error); Text.ErrorWindowTitle, MessageBoxType.Error);
HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); HelperMethods.DeleteDirectory(modsDir + "/" + extractedName);
return; return;
@ -582,13 +511,13 @@ namespace AM2RLauncher
if (profileList.FirstOrDefault(p => p.Name == profile.Name) != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name)) if (profileList.FirstOrDefault(p => p.Name == profile.Name) != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name))
{ {
log.Error(profile.Name + " is already installed."); log.Error(profile.Name + " is already installed.");
MessageBox.Show(HelperMethods.GetText(Text.ModIsAlreadyInstalledMessage, profile.Name), Text.WarningWindowTitle, MessageBoxType.Warning); MessageBox.Show(this, HelperMethods.GetText(Text.ModIsAlreadyInstalledMessage, profile.Name), Text.WarningWindowTitle, MessageBoxType.Warning);
HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); HelperMethods.DeleteDirectory(modsDir + "/" + extractedName);
return; return;
} }
log.Info(profile.Name + " successfully installed."); log.Info(profile.Name + " successfully installed.");
MessageBox.Show(HelperMethods.GetText(Text.ModSuccessfullyInstalledMessage, profile.Name), Text.SuccessWindowTitle); MessageBox.Show(this, HelperMethods.GetText(Text.ModSuccessfullyInstalledMessage, profile.Name), Text.SuccessWindowTitle);
LoadProfilesAndAdjustLists(); LoadProfilesAndAdjustLists();
// Adjust profileIndex to point to newly added mod. if its not found for whatever reason, we default to first community updates // Adjust profileIndex to point to newly added mod. if its not found for whatever reason, we default to first community updates
@ -779,7 +708,7 @@ namespace AM2RLauncher
// Create warning dialog when enabling // Create warning dialog when enabling
if (enabled) if (enabled)
{ {
MessageBox.Show(Text.WarningWindowText, Text.WarningWindowTitle, MessageBoxType.Warning); MessageBox.Show(this, Text.WarningWindowText, Text.WarningWindowTitle, MessageBoxType.Warning);
currentMirror = customMirrorTextBox.Text; currentMirror = customMirrorTextBox.Text;
} }
else else
@ -835,7 +764,7 @@ namespace AM2RLauncher
if (!gitURLRegex.IsMatch(mirrorText)) if (!gitURLRegex.IsMatch(mirrorText))
{ {
log.Info("User used " + mirrorText + " as a custom Mirror, didn't pass git validation test."); log.Info("User used " + mirrorText + " as a custom Mirror, didn't pass git validation test.");
MessageBox.Show(HelperMethods.GetText(Text.InvalidGitURL, mirrorText), Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, HelperMethods.GetText(Text.InvalidGitURL, mirrorText), Text.ErrorWindowTitle, MessageBoxType.Error);
return; return;
} }
@ -883,7 +812,7 @@ namespace AM2RLauncher
ProfileXML profile = profileList[modSettingsProfileDropDown.SelectedIndex]; ProfileXML profile = profileList[modSettingsProfileDropDown.SelectedIndex];
log.Info("User is attempting to delete profile " + profile.Name + "."); log.Info("User is attempting to delete profile " + profile.Name + ".");
DialogResult result = MessageBox.Show(HelperMethods.GetText(Text.DeleteModWarning, profile.Name), Text.WarningWindowTitle, DialogResult result = MessageBox.Show(this, HelperMethods.GetText(Text.DeleteModWarning, profile.Name), Text.WarningWindowTitle,
MessageBoxButtons.OKCancel, MessageBoxType.Warning, MessageBoxDefaultButton.Cancel); MessageBoxButtons.OKCancel, MessageBoxType.Warning, MessageBoxDefaultButton.Cancel);
if (result == DialogResult.Ok) if (result == DialogResult.Ok)
@ -891,7 +820,7 @@ namespace AM2RLauncher
log.Info("User did not cancel. Proceeding to delete " + profile); log.Info("User did not cancel. Proceeding to delete " + profile);
DeleteProfileAndAdjustLists(profile); DeleteProfileAndAdjustLists(profile);
log.Info(profile + " has been deleted"); log.Info(profile + " has been deleted");
MessageBox.Show(HelperMethods.GetText(Text.DeleteModButtonSuccess, profile.Name), Text.SuccessWindowTitle); MessageBox.Show(this, HelperMethods.GetText(Text.DeleteModButtonSuccess, profile.Name), Text.SuccessWindowTitle);
} }
else else
{ {
@ -911,14 +840,7 @@ namespace AM2RLauncher
ProfileXML currentProfile = profileList[modSettingsProfileDropDown.SelectedIndex]; ProfileXML currentProfile = profileList[modSettingsProfileDropDown.SelectedIndex];
OpenFileDialog fileFinder = new OpenFileDialog OpenFileDialog fileFinder = GetSingleZipDialog(Text.SelectModFileDialog);
{
Directory = new Uri(CrossPlatformOperations.CURRENTPATH),
MultiSelect = false,
Title = Text.SelectModFileDialog
};
fileFinder.Filters.Add(new FileFilter(Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok) if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{ {
@ -962,7 +884,7 @@ namespace AM2RLauncher
if (!File.Exists(extractedFolder + "/profile.xml")) if (!File.Exists(extractedFolder + "/profile.xml"))
{ {
log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod update."); log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod update.");
MessageBox.Show(HelperMethods.GetText(Text.ModIsInvalidMessage, extractedName), Text.ErrorWindowTitle, MessageBoxType.Error); MessageBox.Show(this, HelperMethods.GetText(Text.ModIsInvalidMessage, extractedName), Text.ErrorWindowTitle, MessageBoxType.Error);
Directory.Delete(extractedFolder, true); Directory.Delete(extractedFolder, true);
File.Delete(CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name); File.Delete(CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name);
return; return;
@ -974,7 +896,7 @@ namespace AM2RLauncher
if (profileList.FirstOrDefault(p => p.Name == profile.Name) != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name)) if (profileList.FirstOrDefault(p => p.Name == profile.Name) != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name))
{ {
// Mod is already installed, so we can update! // Mod is already installed, so we can update!
DialogResult updateResult = MessageBox.Show(HelperMethods.GetText(Text.UpdateModWarning, currentProfile.Name), Text.WarningWindowTitle, DialogResult updateResult = MessageBox.Show(this, HelperMethods.GetText(Text.UpdateModWarning, currentProfile.Name), Text.WarningWindowTitle,
MessageBoxButtons.OKCancel, MessageBoxType.Warning, MessageBoxDefaultButton.Cancel); MessageBoxButtons.OKCancel, MessageBoxType.Warning, MessageBoxDefaultButton.Cancel);
if (updateResult == DialogResult.Ok) if (updateResult == DialogResult.Ok)
@ -982,7 +904,7 @@ namespace AM2RLauncher
// If the profile isn't installed, don't ask about archiving it // If the profile isn't installed, don't ask about archiving it
if (Profile.IsProfileInstalled(currentProfile)) if (Profile.IsProfileInstalled(currentProfile))
{ {
DialogResult archiveResult = MessageBox.Show(HelperMethods.GetText(Text.ArchiveMod, currentProfile.Name + " " + Text.VersionLabel + currentProfile.Version), Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No); DialogResult archiveResult = MessageBox.Show(this, HelperMethods.GetText(Text.ArchiveMod, currentProfile.Name + " " + Text.VersionLabel + currentProfile.Version), Text.WarningWindowTitle, MessageBoxButtons.YesNo, MessageBoxType.Warning, MessageBoxDefaultButton.No);
// User wants to archive profile // User wants to archive profile
if (archiveResult == DialogResult.Yes) if (archiveResult == DialogResult.Yes)
@ -1006,7 +928,7 @@ namespace AM2RLauncher
// Cancel the operation! // Cancel the operation!
// Show message to tell user that mod could not be found, install this separately // Show message to tell user that mod could not be found, install this separately
log.Error("Mod is not installed! Cancelling mod update."); log.Error("Mod is not installed! Cancelling mod update.");
MessageBox.Show(HelperMethods.GetText(Text.UpdateModButtonWrongMod, currentProfile.Name).Replace("$SELECT", profile.Name), MessageBox.Show(this, HelperMethods.GetText(Text.UpdateModButtonWrongMod, currentProfile.Name).Replace("$SELECT", profile.Name),
Text.WarningWindowTitle, MessageBoxButtons.OK); Text.WarningWindowTitle, MessageBoxButtons.OK);
abort = true; abort = true;
} }
@ -1020,7 +942,7 @@ namespace AM2RLauncher
} }
log.Info("Successfully updated mod profile " + profile.Name + "."); log.Info("Successfully updated mod profile " + profile.Name + ".");
MessageBox.Show(HelperMethods.GetText(Text.ModSuccessfullyInstalledMessage, currentProfile.Name), Text.SuccessWindowTitle); MessageBox.Show(this, HelperMethods.GetText(Text.ModSuccessfullyInstalledMessage, currentProfile.Name), Text.SuccessWindowTitle);
UpdateStateMachine(); UpdateStateMachine();
LoadProfilesAndAdjustLists(); LoadProfilesAndAdjustLists();
@ -1048,7 +970,7 @@ namespace AM2RLauncher
{ {
case UpdateState.Downloading: case UpdateState.Downloading:
{ {
var result = MessageBox.Show(Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo, var result = MessageBox.Show(this, Text.CloseOnCloningText, Text.WarningWindowTitle, MessageBoxButtons.YesNo,
MessageBoxType.Warning, MessageBoxDefaultButton.No); MessageBoxType.Warning, MessageBoxDefaultButton.No);
if (result == DialogResult.No) if (result == DialogResult.No)
{ {
@ -1060,7 +982,7 @@ namespace AM2RLauncher
break; break;
} }
case UpdateState.Installing: case UpdateState.Installing:
MessageBox.Show(Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning); MessageBox.Show(this, Text.CloseOnInstallingText, Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning);
e.Cancel = true; e.Cancel = true;
break; break;
} }

@ -1,4 +1,7 @@
using Eto.Forms; using AM2RLauncher.Core;
using AM2RLauncher.Language;
using Eto.Forms;
using LibGit2Sharp;
using System; using System;
namespace AM2RLauncher namespace AM2RLauncher
@ -40,5 +43,47 @@ namespace AM2RLauncher
{ {
return profileIndex != null; return profileIndex != null;
} }
/// <summary>
/// This is just a helper method for the git commands in order to have a progress bar display for them.
/// </summary>
private bool TransferProgressHandlerMethod(TransferProgress transferProgress)
{
// Thank you random issue on the gitlib2sharp repo!!!!
// Also tldr; rtfm
if (isGitProcessGettingCancelled) return false;
// This needs to be in an Invoke, in order to access the variables from the main thread
// Otherwise this will throw a runtime exception
Application.Instance.Invoke(() =>
{
progressBar.MinValue = 0;
progressBar.MaxValue = transferProgress.TotalObjects;
if (currentGitObject >= transferProgress.ReceivedObjects)
return;
progressLabel.Text = Text.ProgressbarProgress + " " + transferProgress.ReceivedObjects + " (" + ((int)transferProgress.ReceivedBytes / 1000000) + "MB) / " + transferProgress.TotalObjects + " objects";
currentGitObject = transferProgress.ReceivedObjects;
progressBar.Value = transferProgress.ReceivedObjects;
});
return true;
}
/// <summary>
/// Creates a single-file, zip-filtered file dialog.
/// </summary>
/// <param name="title">The title of the file dialog.</param>
/// <returns>The created file dialog.</returns>
private OpenFileDialog GetSingleZipDialog(string title = "")
{
OpenFileDialog fileDialog = new OpenFileDialog
{
Directory = new Uri(CrossPlatformOperations.CURRENTPATH),
MultiSelect = false,
Title = title
};
fileDialog.Filters.Add(new FileFilter(Text.ZipArchiveText, ".zip"));
return fileDialog;
}
} }
} }

@ -818,8 +818,8 @@ namespace AM2RLauncher
customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus; customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus;
//TODO: Retest if these now work on mac //TODO: Retest if these now work on mac
newsWebView.DocumentLoaded += NewsWebViewDocumentLoaded; newsWebView.DocumentLoaded += (sender, e) => ChangeToEmptyPageOnNoInternet(newsPage, newsNoConnectionLabel);
changelogWebView.DocumentLoaded += ChangelogWebViewDocumentLoaded; changelogWebView.DocumentLoaded += (sender, e) => ChangeToEmptyPageOnNoInternet(changelogPage, changelogNoConnectionLabel);
log.Info("Events linked successfully."); log.Info("Events linked successfully.");

@ -353,7 +353,6 @@ public static class CrossPlatformOperations
try try
{ {
xdelta.Start(); xdelta.Start();
xdelta.WaitForExit(); xdelta.WaitForExit();
} }
catch (System.ComponentModel.Win32Exception) catch (System.ComponentModel.Win32Exception)

Loading…
Cancel
Save