Commit 30b47825 authored by Accensus's avatar Accensus
Browse files

- Moved some methods to AceLib.

parent ec54a373
......@@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Authors>Accensus</Authors>
<Version>2.2.1</Version>
<Version>2.3.0</Version>
<Copyright>(c) 2019-2020 Accensus</Copyright>
</PropertyGroup>
......@@ -17,4 +17,8 @@
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AceLib\AceLib.csproj" />
</ItemGroup>
</Project>
......@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29920.165
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageCropper", "ImageCropper.csproj", "{BFAF65C9-1500-4050-8C5A-3311B9A28DFE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageCropper", "ImageCropper.csproj", "{BFAF65C9-1500-4050-8C5A-3311B9A28DFE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AceLib", "..\..\AceLib\AceLib.csproj", "{A74E8D38-2F65-4741-B8A2-48377C3FFA6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -15,6 +17,10 @@ Global
{BFAF65C9-1500-4050-8C5A-3311B9A28DFE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFAF65C9-1500-4050-8C5A-3311B9A28DFE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFAF65C9-1500-4050-8C5A-3311B9A28DFE}.Release|Any CPU.Build.0 = Release|Any CPU
{A74E8D38-2F65-4741-B8A2-48377C3FFA6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A74E8D38-2F65-4741-B8A2-48377C3FFA6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A74E8D38-2F65-4741-B8A2-48377C3FFA6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A74E8D38-2F65-4741-B8A2-48377C3FFA6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -5,6 +5,7 @@ using System.Drawing;
using System.IO;
using System.Numerics;
using System.Text.RegularExpressions;
using AceLib;
namespace ImageCropper
{
......@@ -49,10 +50,14 @@ namespace ImageCropper
dest.Create();
}
FileInfo OffsetTool = FindOffsetTool();
FileInfo OffsetTool = Helpers.LookForExecutable(Process.GetCurrentProcess().MainModule.FileName, new[]
{
"GrabPNG.exe",
"SetPNG.exe"
});
if (OffsetTool == null)
{
Console.WriteLine("WARNING! GrabPNG or SetPNG not detected. Sprites will not have their offsets adjusted.\nPress Y to continue, and anything else to cancel.\n");
Console.WriteLine("WARNING! GrabPNG or SetPNG not detected. Sprites will not have their offsets adjusted.\nPress Y to continue or anything else to cancel.\n");
switch (Console.ReadKey(true).Key)
{
default:
......@@ -133,45 +138,5 @@ namespace ImageCropper
Proc.Start();
}
}
// [Ace] Honestly I'm not too sure if this is *the* way to do this, but it works well so far.
private static FileInfo FindOffsetTool()
{
string[] OffsetPrograms = new[]
{
"GrabPNG.exe",
"SetPNG.exe"
};
switch (Environment.OSVersion.Platform)
{
// [Ace] No Linux/MacOS support yet.
case PlatformID.Win32NT:
foreach (string tool in OffsetPrograms)
{
// [Ace] Check if tool is in the same folder as the executable.
string WorkingDir = new FileInfo(Process.GetCurrentProcess().MainModule.FileName).DirectoryName;
if (File.Exists(Path.Combine(WorkingDir, tool)))
{
return new FileInfo(Path.Combine(WorkingDir, tool));
}
// [Ace] Maybe it's on system or user PATH?
for (var target = EnvironmentVariableTarget.User; target <= EnvironmentVariableTarget.Machine; ++target)
{
foreach (string pathVar in (Environment.GetEnvironmentVariable("PATH", target) ?? "").Split(';'))
{
string path = pathVar.Trim();
if (!string.IsNullOrEmpty(path) && File.Exists(path = Path.Combine(path, tool)))
{
return new FileInfo(path);
}
}
}
}
break;
}
return null;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment