Skip to content

Commit 8d9a52a

Browse files
committed
Added check for Java and arctool
Because we're sick of having to deal with errors regarding them.
1 parent 7ddb70e commit 8d9a52a

6 files changed

Lines changed: 125 additions & 49 deletions

File tree

Sonic-06-Mod-Manager/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
[assembly: ComVisible(false)]
1313
[assembly: Guid("277111e3-79d8-41b5-b0d7-7609dff6e36f")]
1414
[assembly: AssemblyVersion("2.0.0.6")]
15-
[assembly: AssemblyFileVersion("3.2.9.0")]
15+
[assembly: AssemblyFileVersion("3.3.0.0")]

Sonic-06-Mod-Manager/Properties/Resources.Designer.cs

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sonic-06-Mod-Manager/Properties/Resources.resx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@
166166
<data name="error" type="System.Resources.ResXFileRef, System.Windows.Forms">
167167
<value>..\res\icons\error.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
168168
</data>
169+
<data name="Exception_ArctoolMissing" xml:space="preserve">
170+
<value>Arctool is missing, therefore mod installation has failed.
171+
Please whitelist the following directory in your antivirus software and restart Sonic '06 Mod Manager...
172+
</value>
173+
</data>
169174
<data name="Exception_Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
170175
<value>..\res\images\exception_logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
171176
</data>

Sonic-06-Mod-Manager/src/Environment3/UnifySetup.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ private void Button_Continue_Click(object sender, EventArgs e) {
9292
Properties.Settings.Default.General_FirstLaunch = false;
9393
Properties.Settings.Default.Save();
9494
FormClosing -= UnifySetup_FormClosing;
95-
}
95+
}
96+
97+
if (!Program.CheckJava())
98+
{
99+
DialogResult javaWarning = UnifyMessenger.UnifyMessage.ShowDialog("No Java installation was found.\n" +
100+
"Some patch scripts require Java to alter game logic in Lua scripts.\n" +
101+
"Please install Java and restart your computer...",
102+
"Java Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
103+
}
96104

97105
Close(); // Close the form
98106
}

Sonic-06-Mod-Manager/src/UnifyPatcher.cs

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,36 @@ public static string UnpackARC(string arc, string tempPath)
306306
if (drive.IsReady && drive.Name == Path.GetPathRoot(Environment.SystemDirectory))
307307
if (drive.AvailableFreeSpace > new FileInfo(arc).Length)
308308
{
309-
Directory.CreateDirectory(tempPath); // Create temporary location
310-
File.Copy(arc, Path.Combine(tempPath, Path.GetFileName(arc))); // Copy archive to temporary location
311-
312-
// Extracts the archive in the temporary location
313-
var unpack = new ProcessStartInfo()
309+
try
314310
{
315-
FileName = Program.Arctool,
316-
Arguments = $"-d \"{Path.Combine(tempPath, Path.GetFileName(arc))}\"",
317-
WorkingDirectory = Path.GetDirectoryName(Program.Arctool),
318-
WindowStyle = ProcessWindowStyle.Hidden
319-
};
311+
Directory.CreateDirectory(tempPath); // Create temporary location
312+
File.Copy(arc, Path.Combine(tempPath, Path.GetFileName(arc))); // Copy archive to temporary location
313+
314+
// Extracts the archive in the temporary location
315+
var unpack = new ProcessStartInfo()
316+
{
317+
FileName = Program.Arctool,
318+
Arguments = $"-d \"{Path.Combine(tempPath, Path.GetFileName(arc))}\"",
319+
WorkingDirectory = Path.GetDirectoryName(Program.Arctool),
320+
WindowStyle = ProcessWindowStyle.Hidden
321+
};
320322

321-
var Unpack = Process.Start(unpack);
322-
Unpack.WaitForExit();
323-
Unpack.Close();
323+
var Unpack = Process.Start(unpack);
324+
Unpack.WaitForExit();
325+
Unpack.Close();
324326

325-
return tempPath;
327+
return tempPath;
328+
}
329+
catch (System.ComponentModel.Win32Exception ex)
330+
{
331+
if (!File.Exists(Program.Arctool))
332+
{
333+
skipped.Add($"► {Path.GetFileName(arc)} (a required pre-requisite is missing - check the debug log for more information)");
334+
Console.WriteLine($"[{DateTime.Now:HH:mm:ss tt}] [Error] {Properties.Resources.Exception_ArctoolMissing + Program.Arctool}\n{ex}");
335+
}
336+
337+
return string.Empty;
338+
}
326339
}
327340
else
328341
throw new InsufficientMemoryException($"Unable to extract '{Path.GetFileName(arc)}' due to insufficient drive space...");
@@ -333,46 +346,62 @@ public static string UnpackARC(string arc, string tempPath)
333346
/// <summary>
334347
/// Repacks an archive from a temporary location.
335348
/// </summary>
336-
public static void RepackARC(string arc, string output) {
337-
ArcPacker repack = new ArcPacker();
338-
repack.WriteArc(output, Path.Combine(arc, Path.GetFileNameWithoutExtension(output)));
339-
340-
// Erases temporary repack data
341-
try {
342-
DirectoryInfo tempData = new DirectoryInfo(arc);
343-
if (Directory.Exists(arc)) {
344-
foreach (FileInfo file in tempData.GetFiles()) file.Delete();
345-
foreach (DirectoryInfo directory in tempData.GetDirectories()) directory.Delete(true);
346-
Directory.Delete(arc);
347-
}
348-
} catch { }
349+
public static void RepackARC(string arc, string output)
350+
{
351+
if (arc != string.Empty)
352+
{
353+
ArcPacker repack = new ArcPacker();
354+
repack.WriteArc(output, Path.Combine(arc, Path.GetFileNameWithoutExtension(output)));
355+
356+
// Erases temporary repack data
357+
try {
358+
DirectoryInfo tempData = new DirectoryInfo(arc);
359+
if (Directory.Exists(arc)) {
360+
foreach (FileInfo file in tempData.GetFiles()) file.Delete();
361+
foreach (DirectoryInfo directory in tempData.GetDirectories()) directory.Delete(true);
362+
Directory.Delete(arc);
363+
}
364+
} catch { }
365+
}
349366
}
350367

351368
/// <summary>
352369
/// Merges two archives into a single archive.
353370
/// </summary>
354-
public static void Merge(string arc1, string arc2) {
355-
string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Defines the temporary path.
356-
Directory.CreateDirectory(tempPath);
357-
string unpack1 = UnpackARC(arc1, tempPath);
358-
ProcessStartInfo arctool;
359-
360-
File.Copy(arc2, Path.Combine(tempPath, Path.GetFileName(arc2)), true); // Copies the input ARC to the temporary path.
361-
362-
// Defines the arctool process.
363-
arctool = new ProcessStartInfo() {
364-
FileName = Program.Arctool,
365-
Arguments = $"-d \"{Path.Combine(tempPath, Path.GetFileName(arc2))}\"",
366-
WorkingDirectory = Path.GetDirectoryName(Program.Arctool),
367-
WindowStyle = ProcessWindowStyle.Hidden
368-
};
371+
public static void Merge(string arc1, string arc2)
372+
{
373+
try
374+
{
375+
string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Defines the temporary path.
376+
Directory.CreateDirectory(tempPath);
377+
string unpack1 = UnpackARC(arc1, tempPath);
378+
ProcessStartInfo arctool;
379+
380+
File.Copy(arc2, Path.Combine(tempPath, Path.GetFileName(arc2)), true); // Copies the input ARC to the temporary path.
381+
382+
// Defines the arctool process.
383+
arctool = new ProcessStartInfo() {
384+
FileName = Program.Arctool,
385+
Arguments = $"-d \"{Path.Combine(tempPath, Path.GetFileName(arc2))}\"",
386+
WorkingDirectory = Path.GetDirectoryName(Program.Arctool),
387+
WindowStyle = ProcessWindowStyle.Hidden
388+
};
369389

370-
var Unpack2 = Process.Start(arctool); // Unpacks the merge ARC.
371-
Unpack2.WaitForExit();
390+
var Unpack2 = Process.Start(arctool); // Unpacks the merge ARC.
391+
Unpack2.WaitForExit();
372392

373-
File.Delete(Path.Combine(tempPath, Path.GetFileName(arc2))); // Deletes the temporary merge ARC.
393+
File.Delete(Path.Combine(tempPath, Path.GetFileName(arc2))); // Deletes the temporary merge ARC.
374394

375-
RepackARC(unpack1, arc1);
395+
RepackARC(unpack1, arc1);
396+
}
397+
catch (System.ComponentModel.Win32Exception ex)
398+
{
399+
if (!File.Exists(Program.Arctool))
400+
{
401+
skipped.Add($"► {Path.GetFileName(arc1)} (a required pre-requisite is missing - check the debug log for more information)");
402+
Console.WriteLine($"[{DateTime.Now:HH:mm:ss tt}] [Error] {Properties.Resources.Exception_ArctoolMissing + Program.Arctool}\n{ex}");
403+
}
404+
}
376405
}
377406
}
378407

Sonic-06-Mod-Manager/src/UnifyProgram.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Diagnostics;
77
using System.Windows.Forms;
88
using System.Globalization;
9+
using System.Collections.Generic;
910
using Unify.Networking.GameBanana;
1011

1112
// Sonic '06 Mod Manager is licensed under the MIT License:
@@ -38,7 +39,7 @@ namespace Unify.Environment3
3839
{
3940
static class Program
4041
{
41-
public static readonly string GlobalVersionNumber = $"Version 3.29";
42+
public static readonly string GlobalVersionNumber = $"Version 3.3";
4243

4344
#if !DEBUG
4445
public static readonly string VersionNumber = GlobalVersionNumber;
@@ -183,5 +184,27 @@ public static void Reset() {
183184
}
184185
} catch { }
185186
}
187+
188+
public static bool CheckJava()
189+
{
190+
try
191+
{
192+
ProcessStartInfo procStartInfo = new ProcessStartInfo("java", "-version ") {
193+
RedirectStandardOutput = true,
194+
RedirectStandardError = true,
195+
UseShellExecute = false,
196+
CreateNoWindow = true
197+
};
198+
199+
Process proc = new Process() { StartInfo = procStartInfo };
200+
proc.Start();
201+
202+
return true;
203+
}
204+
catch
205+
{
206+
return false;
207+
}
208+
}
186209
}
187210
}

0 commit comments

Comments
 (0)