Skip to content

Commit

Permalink
added forge installer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nacrt committed Dec 29, 2020
1 parent 5adaa94 commit 00fce63
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 61 deletions.
110 changes: 59 additions & 51 deletions SkyblockClient/Forge/ForgeInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,52 @@ public async static Task Work()
return;
}

try
{
const string JAVA_LINK = "https://www.java.com/en/download/manual.jsp";
bool correctJavaVersion = false;
if (Globals.Settings.checkJavaVersion)
{
try
{
const string JAVA_LINK = "https://www.java.com/en/download/manual.jsp";
bool correctJavaVersion = false;

var javaProcess = Process.Start(Utils.CreateProcessStartInfo("java.exe", "-version"));
var javaProcess = Process.Start(Utils.CreateProcessStartInfo("java.exe", "-version"));

List<string> jLines = new List<string>();
List<string> jLines = new List<string>();

while (!javaProcess.StandardError.EndOfStream)
{
jLines.Add(javaProcess.StandardError.ReadLine());
}
while (!javaProcess.StandardError.EndOfStream)
{
jLines.Add(javaProcess.StandardError.ReadLine());
}

if (jLines.Count == 3 && jLines[0].Split('"')[1].StartsWith("1.8."))
{
correctJavaVersion = true;
if (jLines.Count == 3 && jLines[0].Split('"')[1].StartsWith("1.8."))
{
correctJavaVersion = true;
}
else
{
correctJavaVersion = false;
}


if (!correctJavaVersion)
{
Utils.Error("You are Using the wrong version of Java.");
Utils.Error("Download the newest version here:");
Utils.Error(JAVA_LINK);
Utils.Error("Select \"Windows Offline (64-Bit)\"");
Process.Start(Utils.CreateProcessStartInfo("cmd.exe", $"/c start {JAVA_LINK}"));
}
}
else
catch (System.ComponentModel.Win32Exception e)
{
correctJavaVersion = false;
Utils.Error(e.Message, "Win32Exception in ForgeInstaller.Work");
Utils.Log(e, "Win32Exception in ForgeInstaller.Work");
}


if (!correctJavaVersion)
catch (Exception e)
{
Utils.Error("You are Using the wrong version of Java.");
Utils.Error("Download the newest version here:");
Utils.Error(JAVA_LINK);
Utils.Error("Select \"Windows Offline (64-Bit)\"");
Process.Start(Utils.CreateProcessStartInfo("cmd.exe", $"/c start {JAVA_LINK}"));
Utils.Error(e.Message, "Unknown Exception in ForgeInstaller.Work - please publish the log file to the author");
Utils.Log(e, "Win32Exception in ForgeInstaller.Work");
}
}
catch (System.ComponentModel.Win32Exception e)
{
Utils.Error(e.Message, "Win32Exception in ForgeInstaller.Work");
Utils.Log(e, "Win32Exception in ForgeInstaller.Work");
}
catch (Exception e)
{
Utils.Error(e.Message, "Unknown Exception in ForgeInstaller.Work - please publish the log file to the author");
Utils.Log(e, "Win32Exception in ForgeInstaller.Work");
}

List<Task> tasks = new List<Task>();
tasks.Add(Task.Run(() => Profile()));
Expand All @@ -72,6 +75,8 @@ public async static Task Work()

private static async Task Profile()
{
if (!Globals.Settings.installProfileToLauncher)
return;
SkyClientJson skyClientJson = null;

try
Expand Down Expand Up @@ -139,87 +144,90 @@ private static async Task Profile()

private static async Task Libraries()
{
if (!Globals.Settings.installForgeLibaries)
return;

string fileForge = @"forge-1.8.9-11.15.1.2318-1.8.9.jar";
string libraryDirectory = Path.Combine(Globals.minecraftLibrariesLocation, "net", "minecraftforge", "forge", "1.8.9-11.15.1.2318-1.8.9");

string nextCommand = string.Empty;
string crashAt = string.Empty;

try
{
nextCommand = "if (!File.Exists(Path.Combine(libraryDirectory, fileForge)))";
{
crashAt = "if (!File.Exists(Path.Combine(libraryDirectory, fileForge)))";
if (!File.Exists(Path.Combine(libraryDirectory, fileForge)))
{
nextCommand = "if (!Directory.Exists(libraryDirectory))";
crashAt = "if (!Directory.Exists(libraryDirectory))";
if (!Directory.Exists(libraryDirectory))
{
nextCommand = "Directory.CreateDirectory(libraryDirectory);";
crashAt = "Directory.CreateDirectory(libraryDirectory);";
Directory.CreateDirectory(libraryDirectory);
}

nextCommand = "await Globals.DownloadFileByte(\"forge/\" + fileForge, Path.Combine(Globals.tempFolderLocation, fileForge));";
crashAt = "await Globals.DownloadFileByte(\"forge/\" + fileForge, Path.Combine(Globals.tempFolderLocation, fileForge));";
await Globals.DownloadFileByte("forge/" + fileForge, Path.Combine(Globals.tempFolderLocation, fileForge));

nextCommand = "File.Move(Path.Combine(Globals.tempFolderLocation, fileForge), Path.Combine(libraryDirectory, fileForge));";
crashAt = "File.Move(Path.Combine(Globals.tempFolderLocation, fileForge), Path.Combine(libraryDirectory, fileForge));";
File.Move(Path.Combine(Globals.tempFolderLocation, fileForge), Path.Combine(libraryDirectory, fileForge));
}
else
{
nextCommand = "Utils.Debug(Path.Combine(libraryDirectory, fileForge) + \" exists\");";
crashAt = "Utils.Debug(Path.Combine(libraryDirectory, fileForge) + \" exists\");";
Utils.Debug(Path.Combine(libraryDirectory, fileForge) + " exists");
}
}
catch (System.ComponentModel.Win32Exception win32Exception)
{
const string CRASH_MESSAGE = "A Win32Exception occured while installing the Forge to your .minecraft";
Utils.Error(CRASH_MESSAGE);
Utils.Log(win32Exception, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Forge", $"nextCommand:'{nextCommand}'");
Utils.Log(win32Exception, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Forge", $"nextCommand:'{crashAt}'");
}
catch (Exception e)
{
const string CRASH_MESSAGE = "An unkown Exception occured while installing the Forge to your .minecraft";
Utils.Error(CRASH_MESSAGE);
Utils.Log(e, CRASH_MESSAGE, "ForgeInstaller.Profile().Part:Forge", $"nextCommand:'{nextCommand}'");
Utils.Log(e, CRASH_MESSAGE, "ForgeInstaller.Profile().Part:Forge", $"crashAt:'{crashAt}'");
}

string fileJson = "1.8.9-forge1.8.9-11.15.1.2318-1.8.9.json";
string versionDirectory = Path.Combine(Globals.minecraftVersionsLocation, "1.8.9-forge1.8.9-11.15.1.2318-1.8.9");

try
{
nextCommand = "if (!File.Exists(Path.Combine(versionDirectory, fileJson)))";
crashAt = "if (!File.Exists(Path.Combine(versionDirectory, fileJson)))";
if (!File.Exists(Path.Combine(versionDirectory, fileJson)))
{
nextCommand = "if (!Directory.Exists(versionDirectory))";
crashAt = "if (!Directory.Exists(versionDirectory))";
if (!Directory.Exists(versionDirectory))
{
nextCommand = "Directory.CreateDirectory(versionDirectory);";
crashAt = "Directory.CreateDirectory(versionDirectory);";
Directory.CreateDirectory(versionDirectory);
}

nextCommand = "await Globals.DownloadFileByte(\"forge/\" + fileJson, Path.Combine(Globals.tempFolderLocation, fileJson));";
crashAt = "await Globals.DownloadFileByte(\"forge/\" + fileJson, Path.Combine(Globals.tempFolderLocation, fileJson));";
await Globals.DownloadFileByte("forge/" + fileJson, Path.Combine(Globals.tempFolderLocation, fileJson));

nextCommand = "File.Move(Path.Combine(Globals.tempFolderLocation, fileJson), Path.Combine(versionDirectory, fileJson));";
crashAt = "File.Move(Path.Combine(Globals.tempFolderLocation, fileJson), Path.Combine(versionDirectory, fileJson));";
File.Move(Path.Combine(Globals.tempFolderLocation, fileJson), Path.Combine(versionDirectory, fileJson));
}
else
{
nextCommand = "Utils.Debug(Path.Combine(versionDirectory, fileJson) + \" exists\");";
crashAt = "Utils.Debug(Path.Combine(versionDirectory, fileJson) + \" exists\");";
Utils.Debug(Path.Combine(versionDirectory, fileJson) + " exists");
}
}
catch (System.ComponentModel.Win32Exception win32Exception)
{
const string CRASH_MESSAGE = "A Win32Exception occured while installing the Forge to your .minecraft";
Utils.Error(CRASH_MESSAGE);
Utils.Log(win32Exception, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Json", $"nextCommand:'{nextCommand}'");
Utils.Log(win32Exception, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Json", $"nextCommand:'{crashAt}'");
}
catch (Exception e)
{
const string CRASH_MESSAGE = "An unkown Exception occured while installing the Forge to your .minecraft";

Utils.Error(CRASH_MESSAGE);
Utils.Log(e, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Json", $"nextCommand:'{nextCommand}'");
Utils.Log(e, CRASH_MESSAGE, "ForgeInstaller.Libraries().Part:Json", $"nextCommand:'{crashAt}'");
}
}

Expand Down
12 changes: 12 additions & 0 deletions SkyblockClient/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class GlobalSettings
const bool UPDATE_PROFILE_ON_DEBUG_DEFAULT = false;
const bool COPY_ENDPOINT_TO_CLIPBOARD_ON_DEBUG_ON_ERROR_DEFAULT = true;
const bool ENABLE_MOD_DEPENDENT_PACKS_ON_ENABLE_DEFAULT = true;
const bool INSTALL_FORGE_LIBRARIES_DEFAULT = true;
const bool INSTALL_PROFILE_TO_LAUNCHER = true;
const bool CHECK_JAVA_VERSION_DEFAULT = false;

[DefaultValue(APPEND_MISSING_OPTION_ICON_DEFAULT)]
public bool appendMissingOptionIcon = APPEND_MISSING_OPTION_ICON_DEFAULT;
Expand All @@ -28,5 +31,14 @@ public class GlobalSettings

[DefaultValue(ENABLE_MOD_DEPENDENT_PACKS_ON_ENABLE_DEFAULT)]
public bool enableModDependentPacksOnEnable = ENABLE_MOD_DEPENDENT_PACKS_ON_ENABLE_DEFAULT;

[DefaultValue(INSTALL_FORGE_LIBRARIES_DEFAULT)]
public bool installForgeLibaries = INSTALL_FORGE_LIBRARIES_DEFAULT;

[DefaultValue(INSTALL_PROFILE_TO_LAUNCHER)]
public bool installProfileToLauncher = INSTALL_PROFILE_TO_LAUNCHER;

[DefaultValue(CHECK_JAVA_VERSION_DEFAULT)]
public bool checkJavaVersion = CHECK_JAVA_VERSION_DEFAULT;
}
}
2 changes: 1 addition & 1 deletion SkyblockClient/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static List<ModOption> neededMods

foreach (var mod in enabled)
{
if (mod.dispersed)
if (mod.Dispersed)
{
foreach (var library in modOptions)
{
Expand Down
13 changes: 7 additions & 6 deletions SkyblockClient/Options/ModOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ public class ModOption : Option, IEquatable<ModOption>, IEquatable<string>
public override IDownloadUrl downloadUrl => remote ? (IDownloadUrl)new RemoteDownloadUrl(url) : new InternalDownloadUrl("mods/" + file);

[JsonIgnore]
public bool caution => IsSet(warning.Trim());
public bool Caution => IsSet(warning.Trim());

[DefaultValue("")]
public string warning { get; set; }
[JsonIgnore]
public bool dispersed => IsSet(dependency.Trim());
public bool Dispersed => IsSet(dependency.Trim());
[DefaultValue("")]
public string dependency { get; set; }

public bool config { get; set; }

[JsonIgnore]
public bool HasPacks => IsSet<string>(packs);
public List<string> packs { get; set; }


public override string ToString()
{
string result = $"{id}-{display}\n";
Expand Down Expand Up @@ -53,7 +54,7 @@ public override void ComboBoxChecked(object sender, RoutedEventArgs e)
var checkBox = sender as CheckBoxMod;
var isChecked = checkBox.IsChecked;

if (caution && isChecked)
if (Caution && isChecked)
{
MessageBoxResult result = MessageBox.Show(warning + "\n\nUse anyway?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
switch (result)
Expand All @@ -73,11 +74,11 @@ public override void ComboBoxChecked(object sender, RoutedEventArgs e)
}
}
else
{
{
this.enabled = isChecked;
}

if (!(packs is null) && Globals.Settings.enableModDependentPacksOnEnable)
if (HasPacks && Globals.Settings.enableModDependentPacksOnEnable)
{
foreach (var pack in packs)
{
Expand Down
1 change: 1 addition & 0 deletions SkyblockClient/Options/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ public void OpenGuide()
}

protected bool IsSet(string value) => !(value == null || value == "" || value == "None" || value == "none");
protected bool IsSet<T>(List<T> value) => !(value == null || value.Count == 0);
}
}
4 changes: 2 additions & 2 deletions SkyblockClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.8.14")]
[assembly: AssemblyFileVersion("0.8.14")]
[assembly: AssemblyVersion("0.8.15")]
[assembly: AssemblyFileVersion("0.8.15")]
2 changes: 1 addition & 1 deletion SkyblockClient/SkyblockClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ProjectGuid>{2DEA9CD8-419E-4F59-82D9-D089DC282BB7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SkyblockClient</RootNamespace>
<AssemblyName>SkyblockClient-0.8.14</AssemblyName>
<AssemblyName>SkyblockClient-0.8.15</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down

0 comments on commit 00fce63

Please sign in to comment.