Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Knossos.NET/AppStyles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
<!--https://avaloniaui.github.io/icons.html-->
<Styles.Resources>
<StreamGeometry x:Key="3LinesRegular">M2 4.5C2 4.22386 2.22386 4 2.5 4H17.5C17.7761 4 18 4.22386 18 4.5C18 4.77614 17.7761 5 17.5 5H2.5C2.22386 5 2 4.77614 2 4.5Z M2 9.5C2 9.22386 2.22386 9 2.5 9H17.5C17.7761 9 18 9.22386 18 9.5C18 9.77614 17.7761 10 17.5 10H2.5C2.22386 10 2 9.77614 2 9.5Z M2.5 14C2.22386 14 2 14.2239 2 14.5C2 14.7761 2.22386 15 2.5 15H17.5C17.7761 15 18 14.7761 18 14.5C18 14.2239 17.7761 14 17.5 14H2.5Z</StreamGeometry>
<StreamGeometry x:Key="StarRegular">M14.4373398,3.10348696 C14.6345524,3.20081719 14.7941799,3.36044472 14.8915102,3.55765732 L17.8153782,9.48206111 L24.353346,10.4320834 C24.8998908,10.511501 25.2785723,11.0189439 25.1991547,11.5654888 C25.1675302,11.7831258 25.065043,11.9842682 24.9075593,12.1377768 L20.1766414,16.749282 L21.2934597,23.2608319 C21.3868207,23.8051684 21.0212328,24.3221243 20.4768964,24.4154853 C20.2601388,24.4526621 20.0371707,24.4173475 19.8425102,24.3150084 L13.9947741,21.2406716 L8.14703796,24.3150084 C7.65819337,24.5720092 7.05356621,24.3840627 6.79656541,23.8952181 C6.69422634,23.7005576 6.65891166,23.4775895 6.69608851,23.2608319 L7.81290673,16.749282 L3.08198882,12.1377768 C2.68650524,11.7522756 2.67841294,11.1191623 3.06391415,10.7236788 C3.21742275,10.5661951 3.41856517,10.4637079 3.6362022,10.4320834 L10.1741699,9.48206111 L13.098038,3.55765732 C13.3424603,3.06240366 13.9420861,2.85906466 14.4373398,3.10348696 Z M11.1702682,10.8530728 L4.85448108,11.7708103 L9.42462758,16.2256022 L8.34576234,22.5158692 L13.9947741,19.546008 L19.6437858,22.5158692 L18.5649206,16.2256022 L23.1350671,11.7708103 L16.81928,10.8530728 L13.9947741,5.12999876 L11.1702682,10.8530728 Z</StreamGeometry>
<StreamGeometry x:Key="OpenRegular">M7.25008054,4.49999913 L10.7494682,4.49999913 C11.1636818,4.49999913 11.4994682,4.83578644 11.4994682,5.25 C11.4994682,5.62969577 11.2173143,5.94349023 10.8512388,5.99315253 L10.7494682,5.99999913 L7.24972349,5.99999913 C6.07077742,5.99943864 5.10347879,6.90639393 5.00784424,8.06094921 L5.00026803,8.21986131 L5.00310465,16.7504962 C5.00341779,17.9413602 5.92883567,18.9158978 7.09964605,18.9947542 L7.25369622,18.9999045 L15.751762,18.9882338 C16.9414684,18.9865998 17.9144722,18.0618298 17.9934904,16.8921377 L17.9986716,16.738236 L17.9986716,13.2319436 C17.9986716,12.81773 18.334458,12.4819436 18.7486716,12.4819436 C19.1283674,12.4819436 19.4421626,12.7640975 19.491825,13.130173 L19.4986716,13.2319436 L19.4986716,16.738236 C19.4986716,18.7405488 17.9292489,20.3767194 15.9527826,20.4827708 L15.7538222,20.4882324 L7.25825518,20.499901 L7.05493071,20.4947588 C5.14237343,20.3951844 3.60893529,18.8625525 3.50835508,16.9500479 L3.5031047,16.7508907 L3.50087004,8.2525319 L3.50527942,8.05003289 C3.60537339,6.13731798 5.13865446,4.60431851 7.05094826,4.50510482 L7.25008054,4.49999913 L10.7494682,4.49999913 L7.25008054,4.49999913 Z M13.748109,3.00129623 L20.3017795,3.0018036 L20.4013609,3.01557712 L20.4013609,3.01557712 L20.5021655,3.04376069 L20.5021655,3.04376069 L20.5589882,3.06786568 L20.5589882,3.06786568 C20.6122302,3.09104804 20.6633548,3.12146211 20.7110467,3.15867802 L20.7803898,3.22139044 L20.7803898,3.22139044 L20.8641342,3.31997258 L20.8641342,3.31997258 L20.9183108,3.41008637 L20.9183108,3.41008637 L20.9570021,3.50039784 L20.9570021,3.50039784 L20.9762122,3.56459327 L20.9762122,3.56459327 L20.9897783,3.62845344 L20.9897783,3.62845344 L20.9991402,3.72265407 L20.9991402,3.72265407 L20.9996358,10.2551867 C20.9996358,10.6694002 20.6638494,11.0051867 20.2496358,11.0051867 C19.86994,11.0051867 19.5561448,10.7230328 19.5064824,10.3569572 L19.4996358,10.2551867 L19.49887,5.56129623 L12.2796385,12.7845179 C12.0134324,13.0508449 11.5967743,13.0751456 11.3031133,12.8573578 L11.2189784,12.7847587 C10.9526514,12.5185526 10.9283507,12.1018944 11.1461385,11.8082335 L11.2187376,11.7240986 L18.43687,4.50129623 L13.748109,4.50129623 C13.3684132,4.50129623 13.054618,4.21914235 13.0049556,3.85306678 L12.998109,3.75129623 C12.998109,3.37160046 13.2802629,3.05780527 13.6463384,3.00814284 L13.748109,3.00129623 Z</StreamGeometry>
<StreamGeometry x:Key="DeleteRegular">M24,7.25 C27.1017853,7.25 29.629937,9.70601719 29.7458479,12.7794443 L29.75,13 L37,13 C37.6903559,13 38.25,13.5596441 38.25,14.25 C38.25,14.8972087 37.7581253,15.4295339 37.1278052,15.4935464 L37,15.5 L35.909,15.5 L34.2058308,38.0698451 C34.0385226,40.2866784 32.1910211,42 29.9678833,42 L18.0321167,42 C15.8089789,42 13.9614774,40.2866784 13.7941692,38.0698451 L12.09,15.5 L11,15.5 C10.3527913,15.5 9.8204661,15.0081253 9.75645361,14.3778052 L9.75,14.25 C9.75,13.6027913 10.2418747,13.0704661 10.8721948,13.0064536 L11,13 L18.25,13 C18.25,9.82436269 20.8243627,7.25 24,7.25 Z M33.4021054,15.5 L14.5978946,15.5 L16.2870795,37.8817009 C16.3559711,38.7945146 17.116707,39.5 18.0321167,39.5 L29.9678833,39.5 C30.883293,39.5 31.6440289,38.7945146 31.7129205,37.8817009 L33.4021054,15.5 Z M27.25,20.75 C27.8972087,20.75 28.4295339,21.2418747 28.4935464,21.8721948 L28.5,22 L28.5,33 C28.5,33.6903559 27.9403559,34.25 27.25,34.25 C26.6027913,34.25 26.0704661,33.7581253 26.0064536,33.1278052 L26,33 L26,22 C26,21.3096441 26.5596441,20.75 27.25,20.75 Z M20.75,20.75 C21.3972087,20.75 21.9295339,21.2418747 21.9935464,21.8721948 L22,22 L22,33 C22,33.6903559 21.4403559,34.25 20.75,34.25 C20.1027913,34.25 19.5704661,33.7581253 19.5064536,33.1278052 L19.5,33 L19.5,22 C19.5,21.3096441 20.0596441,20.75 20.75,20.75 Z M24,9.75 C22.2669685,9.75 20.8507541,11.1064548 20.7551448,12.8155761 L20.75,13 L27.25,13 C27.25,11.2050746 25.7949254,9.75 24,9.75 Z</StreamGeometry>
<StreamGeometry x:Key="ArrowDownloadRegular">M12.25,39.5 L35.75,39.5 C36.4403559,39.5 37,40.0596441 37,40.75 C37,41.3972087 36.5081253,41.9295339 35.8778052,41.9935464 L35.75,42 L12.25,42 C11.5596441,42 11,41.4403559 11,40.75 C11,40.1027913 11.4918747,39.5704661 12.1221948,39.5064536 L12.25,39.5 L35.75,39.5 L12.25,39.5 Z M23.6221948,6.00645361 L23.75,6 C24.3972087,6 24.9295339,6.49187466 24.9935464,7.12219476 L25,7.25 L25,31.54 L30.6466793,25.8942911 C31.1348346,25.4061358 31.9262909,25.4061358 32.4144462,25.8942911 C32.9026016,26.3824465 32.9026016,27.1739027 32.4144462,27.6620581 L24.6362716,35.4402327 C24.1481163,35.928388 23.35666,35.928388 22.8685047,35.4402327 L15.0903301,27.6620581 C14.6021747,27.1739027 14.6021747,26.3824465 15.0903301,25.8942911 C15.5784855,25.4061358 16.3699417,25.4061358 16.858097,25.8942911 L22.5,31.536 L22.5,7.25 C22.5,6.60279131 22.9918747,6.0704661 23.6221948,6.00645361 L23.75,6 L23.6221948,6.00645361 Z</StreamGeometry>
<StreamGeometry x:Key="ArrowUpRegular">M4.21157,12.7326 C3.9244,13.0312 3.93361,13.5059 4.23213,13.7931 C4.53064,14.0803 5.00543,14.0711 5.29259,13.7725 L13.2521,5.49831 L13.2521,24.2511 C13.2521,24.6653 13.5879,25.0011 14.0021,25.0011 C14.4163,25.0011 14.7521,24.6653 14.7521,24.2511 L14.7521,5.4993 L22.7106,13.7725 C22.9978,14.0711 23.4726,14.0803 23.7711,13.7931 C24.0696,13.5059 24.0788,13.0312 23.7916,12.7326 L14.7223,3.30466 C14.3289,2.89568 13.6743,2.89568 13.2809,3.30466 L4.21157,12.7326 Z</StreamGeometry>
<StreamGeometry x:Key="DocumentArrowLeftRegular">M10.5 8.25C10.5 7.2835 11.2835 6.5 12.25 6.5H24V15.25C24 17.3211 25.6789 19 27.75 19H37.5V39.75C37.5 40.7165 36.7165 41.5 35.75 41.5H24.2608C23.7353 42.4086 23.1029 43.2476 22.3809 44H35.75C38.0972 44 40 42.0972 40 39.75V18.4142C40 17.8175 39.7629 17.2452 39.341 16.8232L27.1768 4.65901C26.7548 4.23705 26.1825 4 25.5858 4H12.25C9.90279 4 8 5.90279 8 8.25V22.9963C8.79632 22.6642 9.63275 22.4091 10.5 22.2402V8.25ZM35.4822 16.5H27.75C27.0596 16.5 26.5 15.9404 26.5 15.25V7.51777L35.4822 16.5Z M24 35C24 41.0751 19.0751 46 13 46C6.92487 46 2 41.0751 2 35C2 28.9249 6.92487 24 13 24C19.0751 24 24 28.9249 24 35ZM11.7071 29.2929C11.3166 28.9024 10.6834 28.9024 10.2929 29.2929L5.29289 34.2929C4.90237 34.6834 4.90237 35.3166 5.29289 35.7071L10.2929 40.7071C10.6834 41.0976 11.3166 41.0976 11.7071 40.7071C12.0976 40.3166 12.0976 39.6834 11.7071 39.2929L8.41421 36H20C20.5523 36 21 35.5523 21 35C21 34.4477 20.5523 34 20 34H8.41421L11.7071 30.7071C12.0976 30.3166 12.0976 29.6834 11.7071 29.2929Z</StreamGeometry>
<StreamGeometry x:Key="ChevronLeftRegular">M31.8839 8.36612C32.372 8.85427 32.372 9.64573 31.8839 10.1339L18.0178 24L31.8839 37.8661C32.372 38.3543 32.372 39.1457 31.8839 39.6339C31.3957 40.122 30.6043 40.122 30.1161 39.6339L15.3661 24.8839C14.878 24.3957 14.878 23.6043 15.3661 23.1161L30.1161 8.36612C30.6043 7.87796 31.3957 7.87796 31.8839 8.36612Z</StreamGeometry>
</Styles.Resources>

Expand Down
31 changes: 31 additions & 0 deletions Knossos.NET/Classes/KnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Avalonia.Media;
using Avalonia.Threading;
using Microsoft.Win32;
using WindowsShortcutFactory;

namespace Knossos.NET
{
Expand Down Expand Up @@ -1190,5 +1191,35 @@ public static void DeleteFileSafe(string filePath)
Log.Add(Log.LogSeverity.Error, "KnUtils.DeleteFileSafe()", ex);
}
}

/// <summary>
/// Creates a shortcut into the user desktop
/// optional diferent icon path, if null is passed the destfilepath icon will be used
/// Only Windows
/// </summary>
/// <param name="shortcutName"></param>
/// <param name="destFileFullPath"></param>
/// <param name="iconFilePath"></param>
public static void CreateDesktopShortcut(string shortcutName, string destFileFullPath, string arguments = "", string? iconFilePath = null)
{
try
{
if (IsWindows)
{
using var shortcut = new WindowsShortcut
{
Path = @destFileFullPath,
Description = "KnossosNET quicklaunch to " + shortcutName,
IconLocation = iconFilePath == null ? destFileFullPath : iconFilePath,
Arguments = arguments
};

shortcut.Save(@Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + shortcutName + ".lnk");
}
}catch(Exception ex)
{
Log.Add(Log.LogSeverity.Error, "KnUtils.CreateDesktopShortcut()", ex);
}
}
}
}
31 changes: 31 additions & 0 deletions Knossos.NET/Classes/Knossos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,20 @@ private static async Task QuickLaunch()
string modid = string.Empty;
string modver = string.Empty;
string modExecType = string.Empty;
string toolName = string.Empty;
bool saveID = false;
bool saveVer = false;
bool saveExecType = false;
bool toolID = false;

foreach (var arg in args)
{
Log.Add(Log.LogSeverity.Information, "Knossos.StartUp", "Knet Cmdline Arg: " + arg);
if (toolID)
{
toolID = false;
toolName = arg;
}
if (saveID)
{
saveID = false;
Expand All @@ -235,6 +242,10 @@ private static async Task QuickLaunch()
{
saveID = true;
}
if (arg.ToLower() == "-tool")
{
toolID = true;
}
if (arg.ToLower() == "-version")
{
saveVer = true;
Expand All @@ -245,6 +256,26 @@ private static async Task QuickLaunch()
}
}

if (toolName != string.Empty)
{
var tool = GetTools().FirstOrDefault(x=> x.name.ToLower() == toolName.ToLower());
try
{
if (tool != null)
{
_ = tool.Open();
}
else
{
Log.Add(Log.LogSeverity.Error, "Knossos.QuickLaunch", "Quick launch was used but the tool was not found. Used tool name: " + toolName);
}
}
catch(Exception ex)
{
Log.Add(Log.LogSeverity.Error, "Knossos.QuickLaunch", ex);
}
}

if(modid != string.Empty)
{
var execType = FsoExecType.Release;
Expand Down
81 changes: 66 additions & 15 deletions Knossos.NET/Classes/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.IO;
using System.Threading.Tasks;

namespace Knossos.NET.Classes
{
Expand Down Expand Up @@ -70,37 +71,65 @@ public Tool(string folderpath)
/// </summary>
/// <param name="workingFolder"></param>
/// <returns>true or false depending if the process start was successfull</returns>
public bool Open(string? workingFolder = null)
public async Task<bool> Open(string? workingFolder = null)
{
var best = GetBestPackage();
if (folderpath != string.Empty && best != null)
var bestPkg = GetBestPackage();
var path = GetExecutableFullPath(bestPkg);
if (path != null)
{
try
{
if (!KnUtils.IsWindows)
KnUtils.Chmod(Path.Combine(folderpath, best.executablePath));
using (var process = new Process())
KnUtils.Chmod(path);

if(bestPkg != null && bestPkg.wineSupport && bestPkg.os.ToLower() == "windows" && KnUtils.IsLinux)
{
process.StartInfo.FileName = Path.Combine(folderpath, best.executablePath);
if(cmdline != string.Empty)
process.StartInfo.Arguments = cmdline;
if(workingFolder != null)
process.StartInfo.WorkingDirectory = workingFolder;
process.StartInfo.UseShellExecute = true;
process.Start();
return true;
Log.Add(Log.LogSeverity.Information, "Tool.Open()", "Executing Wine to run this tool: " + path);
//Wine
var res = await Wine.RunTool(path,cmdline, workingFolder, bestPkg.cpuArch);
return res.IsSuccess;
}
else
{
Log.Add(Log.LogSeverity.Information, "Tool.Open()", "Running tool: " + path);
//Normal
using (var process = new Process())
{
process.StartInfo.FileName = path;
if (cmdline != string.Empty)
process.StartInfo.Arguments = cmdline;
if (workingFolder != null)
process.StartInfo.WorkingDirectory = workingFolder;
process.StartInfo.UseShellExecute = true;
process.Start();
return true;
}
}
}
catch (Exception ex)
{
Log.Add(Log.LogSeverity.Error, "Tool.Open()", ex);
}
}
return false;
}

/// <summary>
/// Gets full path to the best executable for this tool on this platform
/// </summary>
/// <returns>fullpath string or null</returns>
public string? GetExecutableFullPath(ToolPackage? toolPackage = null)
{
var best = toolPackage == null ? GetBestPackage() : toolPackage;
if (folderpath != string.Empty && best != null)
{
return Path.Combine(folderpath, best.executablePath);
}
else
{
Log.Add(Log.LogSeverity.Error, "Tool.Open()", "Invalid platform or folderpath is empty. Tool: " + name);
Log.Add(Log.LogSeverity.Error, "Tool.GetExecutableFullPath()", "Invalid platform or folderpath is empty. Tool: " + name);
}
return false;
return null;
}

/// <summary>
Expand Down Expand Up @@ -257,6 +286,26 @@ private void SetPkgScores()
}
}
}
else
{
//Wine
if(pkg.wineSupport && pkg.os.ToLower() == "windows" && KnUtils.IsLinux)
{
foreach (var arch in archs)
{
if (arch == "x64" && KnUtils.CpuArch == "X64" ||
arch == "x86" && KnUtils.CpuArch == "X86" ||
arch == "arm64" && KnUtils.CpuArch == "Arm64" ||
arch == "arm32" && KnUtils.CpuArch != "Arm64" && (KnUtils.CpuArch == "Arm" || KnUtils.CpuArch == "Armv6") ||
arch == "riscv64" && KnUtils.CpuArch == "RiscV64" ||
arch == "riscv32" && KnUtils.CpuArch == "RiscV32")
{
pkg.score = 5;
continue;
}
}
}
}
}
scoresSet = true;
}
Expand All @@ -276,5 +325,7 @@ public class ToolPackage
public string executablePath { get; set; } = string.Empty;
[JsonIgnore]
public int score { get; set; } = 0;
[JsonPropertyName("wine_support")]
public bool wineSupport { get; set; } = false;
}
}
Loading