Partially untested code for Linux support without Wine

This commit is contained in:
CreepyCrafter24 2020-04-08 16:05:09 +02:00
parent f931169ebe
commit 5cae428440
31 changed files with 350 additions and 426 deletions

2
CLI.md
View File

@ -1,7 +1,7 @@
# CLI
Updating the cache: uptool update
Installing a package: uptool install \<package>
Installing a package (set \<package> to a file for local): uptool install \<package>
Upgrading a package: uptool upgrade \<package>

View File

@ -14,13 +14,13 @@ namespace Installer
{
public partial class InstallerForm : Form
{
private string Log = "";
private string _log = "";
public InstallerForm()
{
InitializeComponent();
Step(0, "Initialized");
Log.TrimStart(Environment.NewLine.ToCharArray());
_log.TrimStart(Environment.NewLine.ToCharArray());
}
private void install_Click(object sender, EventArgs e)
@ -54,10 +54,10 @@ namespace Installer
}
Step(5, "Creating shortcut");
Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
Step(6, "Creating PATH entry");
if (!PATH.Content.Contains(PATH.GetName(PathTool.GetRelative("Install"))))
PATH.Append(PathTool.GetRelative("Install"));
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
Path.Append(PathTool.GetRelative("Install"));
Step(7, "Done!");
}
catch (Exception ex)
@ -85,9 +85,9 @@ namespace Installer
{
progress.Value = p;
processLabel.Text = text;
Log += $"{Environment.NewLine}[{DateTime.Now.ToString(CultureInfo.InvariantCulture).Split(' ')[1]}] {text}";
_log += $"{Environment.NewLine}[{DateTime.Now.ToString(CultureInfo.InvariantCulture).Split(' ')[1]}] {text}";
}
private void log_Click(object sender, EventArgs e) => new Thread(() => MessageBox.Show(Log)).Start();
private void log_Click(object sender, EventArgs e) => new Thread(() => MessageBox.Show(_log)).Start();
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
namespace Installer
{
public static class PATH
public static class Path
{
public static string[] Content
{
@ -15,6 +15,6 @@ namespace Installer
public static void Append(string path, bool escape = true) =>
Content = Content.Append(escape ? GetName(path) : path).ToArray();
public static string GetName(string path) => Path.GetFullPath(path);
public static string GetName(string path) => System.IO.Path.GetFullPath(path);
}
}

View File

@ -6,14 +6,14 @@ namespace Installer
{
internal static class PathTool
{
public static string dir =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
public static string Dir =>
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
public static string tempPath => GetRelative("tmp");
public static string appsPath => GetRelative("Apps");
public static string TempPath => GetRelative("tmp");
public static string AppsPath => GetRelative("Apps");
public static string InfoXml => GetRelative("info.xml");
public static string GetRelative(params string[] segments) =>
Path.Combine(new[] {dir}.Concat(segments).ToArray());
System.IO.Path.Combine(new[] {Dir}.Concat(segments).ToArray());
}
}

View File

@ -54,10 +54,10 @@ namespace Installer
}
Console.WriteLine("Creating shortcut");
Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "UpTool2.lnk"));
Console.WriteLine("Creating PATH entry");
if (!PATH.Content.Contains(PATH.GetName(PathTool.GetRelative("Install"))))
PATH.Append(PathTool.GetRelative("Install"));
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
Path.Append(PathTool.GetRelative("Install"));
}
}
finally

View File

@ -0,0 +1,30 @@
using System;
using System.IO;
namespace UpTool_build_tool
{
internal static class BatchScripts
{
public static Tuple<string, string> Create(bool shortcuts, string? mainBin, string programName, string? postInstall, string? postRemove)
{
string installBat = "@echo off\r\necho INSTALL";
string removeBat = "@echo off\r\necho REMOVE";
if (shortcuts)
{
installBat += "\r\n";
installBat +=
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}';$s.Save()""";
removeBat += "\r\n";
removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk""";
}
if (!string.IsNullOrWhiteSpace(mainBin))
{
removeBat += "\r\n";
removeBat += $@"taskkill /f /im ""{Path.GetFileName(mainBin)}""";
}
installBat += $"\r\n{postInstall}";
removeBat += $"\r\n{postRemove}";
return new Tuple<string, string>(installBat, removeBat);
}
}
}

View File

@ -14,24 +14,26 @@ namespace UpTool_build_tool
public static int Main(string[] args)
{
RootCommand rootCommand = new RootCommand();
Command build = new Command("build", "Builds a generic package with or without shortcuts from a directory");
build.AddOption(new Option<string>("--binDir", "Directory to package"));
build.AddOption(new Option<string>("--mainBin", "The applications main binary"));
build.AddOption(new Option<string>("--packageFile", "Directory to package"));
build.AddOption(new Option<string>("--postInstall", () => "",
"Command(s) to run after installing the package"));
build.AddOption(
new Option<string>("--postRemove", () => "", "Command(s) to run after removing the package"));
build.AddOption(new Option<bool>("--noLogo", "Disables the logo"));
build.AddOption(new Option<bool>("--noShortcuts",
"When this is enabled the scripts will not generate a start-menu item"));
build.Handler = CommandHandler.Create<string, string, string, string, string, bool, bool>(Build);
Command build = new Command("build", "Builds a generic package with or without shortcuts from a directory")
{
new Option<string>("--binDir", "Directory to package"),
new Option<string>("--mainBin", () => "FIND_BIN", "The applications main binary"),
new Option<string>("--packageFile", "Directory to package"),
new Option<string>("--postInstall", () => "", "Command(s) to run after installing the package (This will be pasted into the .bat AND .sh file)"),
new Option<string>("--postRemove", () => "", "Command(s) to run after removing the package (This will be pasted into the .bat AND .sh file)"),
new Option<bool>("--noLogo", "Disables the logo"),
new Option<bool>("--noShortcuts",
"When this is enabled the scripts will not generate a start-menu item"),
new Option<bool>("--noWine",
"This indicates that your program supports multiple platforms natively and doesn't require WINE")
};
build.Handler = CommandHandler.Create((Action<string, string, string, string, string, bool, bool, bool>)Build);
rootCommand.AddCommand(build);
return rootCommand.InvokeAsync(args).Result;
}
private static void Build(string binDir, string mainBin, string packageFile, string postInstall,
string postRemove, bool noLogo, bool noShortcuts)
string postRemove, bool noLogo, bool noShortcuts, bool noWine)
{
Stopwatch watch = Stopwatch.StartNew();
if (!noLogo)
@ -55,9 +57,7 @@ namespace UpTool_build_tool
{
archive.AddDirectory(binDir, "Data", new[] {".xml", ".pdb"}, new[] {packageFile});
Console.WriteLine("Creating batch scripts...");
string installBat = "@echo off\r\necho INSTALL";
string removeBat = "@echo off\r\necho REMOVE";
if (string.IsNullOrWhiteSpace(mainBin))
if (mainBin == "FIND_BIN")
{
string[] tmp = Directory.GetFiles(binDir, "*.exe");
if (tmp.Length > 0)
@ -71,35 +71,22 @@ namespace UpTool_build_tool
}
}
string programName = Path.GetFileNameWithoutExtension(mainBin);
if (!noShortcuts)
{
installBat += "\r\n";
installBat +=
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}';$s.Save()""";
removeBat += "\r\n";
removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk""";
}
if (!string.IsNullOrWhiteSpace(mainBin))
{
removeBat += "\r\n";
removeBat += $@"taskkill /f /im ""{Path.GetFileName(mainBin)}""";
}
installBat += $"\r\n{postInstall}";
removeBat += $"\r\n{postRemove}";
using (Stream s = archive.CreateEntry("Install.bat").Open())
{
using StreamWriter writer = new StreamWriter(s);
writer.Write(installBat);
}
using (Stream s = archive.CreateEntry("Remove.bat").Open())
{
using StreamWriter writer = new StreamWriter(s);
writer.Write(removeBat);
}
(string installBat, string removeBat) = BatchScripts.Create(!noShortcuts, mainBin, programName, postInstall, postRemove);
archive.AddFile("Install.bat", installBat);
archive.AddFile("Remove.bat", removeBat);
ShScripts.Create(archive.AddFile, !noShortcuts, mainBin, programName, postInstall, postRemove, !noWine);
}
watch.Stop();
Console.WriteLine($"Completed package creation in {watch.Elapsed}");
Console.WriteLine($"Output file: {Path.GetFullPath(packageFile)}");
}
private static void AddFile(this ZipArchive archive, string fileName, string content)
{
using Stream s = archive.CreateEntry(fileName).Open();
using StreamWriter writer = new StreamWriter(s);
writer.Write(content);
}
}
}

View File

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UpTool_build_tool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UpTool_build_tool")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("AAB8D6BA-3A43-4DC4-95EE-6757482B77FD")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,39 @@
using System;
using System.Text.RegularExpressions;
namespace UpTool_build_tool
{
internal static class ShScripts
{
public static void Create(Action<string, string> fileSave, bool shortcuts, string? mainBin, string programName, string? postInstall, string? postRemove, bool wine)
{
Regex rgx = new Regex("[^a-z0-9]");
Regex upRgx = new Regex("[^a-zA-Z0-9 -]");
string lnkName = $"~/.local/share/applications/{rgx.Replace(programName.ToLower(), "")}.desktop";
string installSh = "#!/bin/bash\necho INSTALL";
string removeSh = "#!/bin/bash\necho REMOVE";
if (shortcuts)
{
installSh += $@"
echo ""[Desktop Entry]"" > {lnkName}
echo ""Exec={(wine ? "wine " : "")}{mainBin}"" >> {lnkName}
echo ""Icon=application/x-shellscript"" >> {lnkName}
echo ""Name={upRgx.Replace(programName, "")}"" >> {lnkName}
echo ""StartupNotify=false"" >> {lnkName}
echo ""Terminal=false"" >> {lnkName}
echo ""Type=Application"" >> {lnkName}";
removeSh += "\r\n";
removeSh += $@"rm {lnkName}";
}
if (!string.IsNullOrWhiteSpace(mainBin))
{
removeSh += "\r\n";
removeSh += $@"pkill -f ""{mainBin}""";
}
installSh += $"\r\n{postInstall}";
removeSh += $"\r\n{postRemove}";
fileSave("Install.sh", installSh);
fileSave("Remove.sh", removeSh);
}
}
}

View File

@ -7,10 +7,10 @@
<Deterministic>false</Deterministic>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AssemblyVersion>1.0.*</AssemblyVersion>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>.\pkgtool.exe build --noLogo --noShortcuts --binDir .</PostBuildEvent>
<PostBuildEvent>.\pkgtool build --noLogo --noShortcuts --binDir . --mainBin ""</PostBuildEvent>
<ApplicationIcon>..\UpTool2.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>

View File

@ -221,7 +221,7 @@
this.ResumeLayout(false);
}
#endregion
#endregion
private System.Windows.Forms.FlowLayoutPanel sidebarPanel;
private System.Windows.Forms.Panel infoPanel;

View File

@ -39,8 +39,8 @@ namespace UpTool2
}
Program.SetSplash(8, "Reloading data");
ReloadElements();
if (!Directory.Exists(PathTool.appsPath))
Directory.CreateDirectory(PathTool.appsPath);
if (!Directory.Exists(PathTool.AppsPath))
Directory.CreateDirectory(PathTool.AppsPath);
}
private void Action_install_Click(object sender, EventArgs e)
@ -91,7 +91,7 @@ namespace UpTool2
while (GlobalVariables.Apps.ContainsKey(id) || Directory.Exists(PathTool.GetAppPath(id)))
id = Guid.NewGuid();
App appI = new App(AppNameDialog.Show(), "Locally installed package, removal only",
GlobalVariables.minimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, "");
GlobalVariables.MinimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, "");
AppInstall.InstallZip(searchPackageDialog.FileName, appI, true);
#if !DEBUG
}
@ -109,8 +109,8 @@ namespace UpTool2
ClearSelection();
infoPanel_Title.Invalidate();
infoPanel_Description.Invalidate();
int F = sidebarPanel.Controls.Count;
for (int i = 0; i < F; i++) sidebarPanel.Controls[0].Dispose();
int f = sidebarPanel.Controls.Count;
for (int i = 0; i < f; i++) sidebarPanel.Controls[0].Dispose();
GlobalVariables.Apps.Clear();
//add
toolTip.SetToolTip(controls_settings, "Settings");
@ -133,21 +133,21 @@ namespace UpTool2
BackgroundImage = (Bitmap) app.Icon,
BackgroundImageLayout = ImageLayout.Stretch
};
bool updateable = !app.Local && (app.status & Status.Updatable) == Status.Updatable;
bool updateable = !app.Local && (app.Status & Status.Updatable) == Status.Updatable;
sidebarIcon.Click += (sender, e) =>
{
infoPanel_Title.Text = app.Name;
infoPanel_Title.ForeColor = app.Local ? Color.Red : Color.Black;
infoPanel_Description.Text = app.Description;
action_install.Tag = app;
action_install.Enabled = !(app.Local || Directory.Exists(app.appPath));
action_install.Enabled = !(app.Local || Directory.Exists(app.AppPath));
action_remove.Tag = app;
action_remove.Enabled = Directory.Exists(app.appPath);
action_remove.Enabled = Directory.Exists(app.AppPath);
action_update.Tag = app;
action_update.Enabled = updateable;
action_run.Tag = app;
action_run.Enabled = (app.status & Status.Installed) == Status.Installed && !app.Local &&
app.Runnable && Directory.Exists(app.appPath);
action_run.Enabled = (app.Status & Status.Installed) == Status.Installed && !app.Local &&
app.Runnable && Directory.Exists(app.AppPath);
};
if (updateable)
availableUpdates++;
@ -229,7 +229,7 @@ namespace UpTool2
Panel sidebarIcon = (Panel) sidebarPanel.Controls[i];
App app = (App) sidebarIcon.Tag;
sidebarIcon.Visible = apps.Contains(app) &&
((int) app.status & (int) (Program.Online ? status : Status.Installed)) != 0;
((int) app.Status & (int) (Program.Online ? status : Status.Installed)) != 0;
}
ClearSelection();
#if DEBUG

View File

@ -19,8 +19,8 @@ namespace UpTool2
internal static class Program
{
public static Form Splash;
private static int SplashProgress;
private static string SplashMessage;
private static int _splashProgress;
private static string _splashMessage;
public static bool Online;
[STAThread]
@ -47,10 +47,10 @@ namespace UpTool2
try
{
#endif
ExternalFunctionalityManager.Init(new UTLibFunctions());
ExternalFunctionalityManager.Init(new UtLibFunctions());
SetSplash(1, "Initializing paths");
if (!Directory.Exists(PathTool.dir))
Directory.CreateDirectory(PathTool.dir);
if (!Directory.Exists(PathTool.Dir))
Directory.CreateDirectory(PathTool.Dir);
FixXml();
SetSplash(2, "Performing checks");
string metaXml = XDocument.Load(PathTool.InfoXml).Element("meta").Element("UpdateSource").Value;
@ -135,10 +135,10 @@ namespace UpTool2
20);
g.FillRectangle(Brushes.Gray, bar);
g.FillRectangle(Brushes.Black,
new Rectangle(bar.X, bar.Y, (bar.Width * SplashProgress) / 10, bar.Height));
new Rectangle(bar.X, bar.Y, (bar.Width * _splashProgress) / 10, bar.Height));
g.DrawRectangle(Pens.DimGray, bar);
//g.DrawString(SplashMessage, smallFont, Brushes.White, new PointF(bar.Left, bar.Bottom));
g.DrawString(SplashMessage, smallFont, Brushes.White, bar,
g.DrawString(_splashMessage, smallFont, Brushes.White, bar,
new StringFormat {Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center});
};
int xOff = 0;
@ -163,9 +163,9 @@ namespace UpTool2
public static void SetSplash(int progress, string status) => Splash.Invoke(new Action(() =>
{
SplashProgress = progress;
_splashProgress = progress;
Console.WriteLine(status);
SplashMessage = status;
_splashMessage = status;
Splash.Invoke((Action) Splash.Invalidate);
}));

View File

@ -6,29 +6,29 @@ namespace UpTool2
{
public partial class SettingsForms : Form
{
private readonly XDocument doc;
private readonly XElement meta;
private readonly XElement repos;
private readonly XDocument _doc;
private readonly XElement _meta;
private readonly XElement _repos;
public SettingsForms()
{
InitializeComponent();
Program.FixXml();
doc = XDocument.Load(PathTool.InfoXml);
meta = doc.Element("meta");
repos = meta.Element("Repos");
foreach (XElement repo in repos.Elements("Repo"))
_doc = XDocument.Load(PathTool.InfoXml);
_meta = _doc.Element("meta");
_repos = _meta.Element("Repos");
foreach (XElement repo in _repos.Elements("Repo"))
sourceGrid.Rows.Add(repo.Element("Name").Value, repo.Element("Link").Value);
}
private void SettingsForms_FormClosing(object sender, FormClosingEventArgs e)
{
repos.RemoveNodes();
_repos.RemoveNodes();
for (int y = 0; y < sourceGrid.Rows.Count; y++)
if (y + 1 < sourceGrid.Rows.Count)
repos.Add(new XElement("Repo", new XElement("Name", (string) sourceGrid.Rows[y].Cells[0].Value),
_repos.Add(new XElement("Repo", new XElement("Name", (string) sourceGrid.Rows[y].Cells[0].Value),
new XElement("Link", (string) sourceGrid.Rows[y].Cells[1].Value)));
doc.Save(PathTool.InfoXml);
_doc.Save(PathTool.InfoXml);
}
}
}

View File

@ -11,7 +11,7 @@ using UpToolLib.DataStructures;
namespace UpTool2
{
internal class UTLibFunctions : IExternalFunctionality
internal class UtLibFunctions : IExternalFunctionality
{
public Tuple<bool, byte[]> Download(Uri link)
{
@ -47,7 +47,7 @@ namespace UpTool2
public bool YesNoDialog(string text, bool _) =>
MessageBox.Show(text, "", MessageBoxButtons.YesNo) == DialogResult.Yes;
public void OKDialog(string text) => MessageBox.Show(text);
public void OkDialog(string text) => MessageBox.Show(text);
public object GetDefaultIcon() => Resources.C_64.ToBitmap();
public object ImageFromB64(string b64) =>

View File

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Drawing;
using System.IO;
using System.Linq;
using UpToolLib;
using UpToolLib.DataStructures;
@ -9,14 +11,15 @@ using UpToolLib.Tool;
namespace UpToolCLI
{
public class Program
public static class Program
{
public static int Main(string[] args)
{
MutexLock.Lock();
try
{
ExternalFunctionalityManager.Init(new UTLibFunctions());
XmlTool.FixXml();
ExternalFunctionalityManager.Init(new UtLibFunctions());
RootCommand rootCommand = new RootCommand();
rootCommand.AddCommand(new Command("update", "Updates the cache")
{
@ -25,40 +28,40 @@ namespace UpToolCLI
Command install = new Command("install", "Install a package")
{
Handler = CommandHandler.Create<string, bool>(Install)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app or the file name"),
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
};
install.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
install.AddOption(new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files"));
install.Handler = CommandHandler.Create<string, bool>(Install);
rootCommand.AddCommand(install);
Command upgrade = new Command("upgrade", "Upgrade a package")
{
Handler = CommandHandler.Create<string, bool>(Upgrade)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
};
upgrade.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
upgrade.AddOption(new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files"));
upgrade.Handler = CommandHandler.Create<string, bool>(Upgrade);
rootCommand.AddCommand(upgrade);
Command reinstall = new Command("reinstall", "Reinstall a package")
{
Handler = CommandHandler.Create<string, bool>(Reinstall)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
};
reinstall.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
reinstall.AddOption(new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files"));
reinstall.Handler = CommandHandler.Create<string, bool>(Reinstall);
rootCommand.AddCommand(reinstall);
Command remove = new Command("remove", "Remove a package")
{
Handler = CommandHandler.Create<string>(Remove)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
};
remove.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
remove.Handler = CommandHandler.Create<string>(Remove);
rootCommand.AddCommand(remove);
Command purge = new Command("purge", "Completely remove a package")
{
Handler = CommandHandler.Create<string>(Purge)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
};
purge.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
purge.Handler = CommandHandler.Create<string>(Purge);
rootCommand.AddCommand(purge);
rootCommand.AddCommand(new Command("list", "Lists installed packages")
@ -73,25 +76,25 @@ namespace UpToolCLI
Command search = new Command("search", "Search for packages")
{
Handler = CommandHandler.Create<string>(Search)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
};
search.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
search.Handler = CommandHandler.Create<string>(Search);
rootCommand.AddCommand(search);
Command show = new Command("show", "Shows package info")
{
Handler = CommandHandler.Create<string>(Show)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
};
show.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
show.Handler = CommandHandler.Create<string>(Show);
rootCommand.AddCommand(show);
Command start = new Command("start", "Starts an app")
{
Handler = CommandHandler.Create<string>(Show)
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
new Option<string>(new[] {"--waitForExit", "-wait"}, "Waits until the program quits")
};
start.AddOption(new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"));
start.Handler = CommandHandler.Create<string, bool>(Start);
rootCommand.AddCommand(start);
return rootCommand.InvokeAsync(args).Result;
}
finally
@ -107,7 +110,7 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
Console.WriteLine();
IEnumerable<App> tmp = GlobalVariables.Apps.Where(s =>
(s.Value.status & Status.Updatable) == Status.Updatable).Select(s => s.Value);
(s.Value.Status & Status.Updatable) == Status.Updatable).Select(s => s.Value);
IEnumerable<App> apps = tmp as App[] ?? tmp.ToArray();
int updatableCount = apps.Count();
Console.WriteLine(updatableCount == 0
@ -120,10 +123,10 @@ namespace UpToolCLI
{
RepoManagement.GetReposFromDisk();
foreach (KeyValuePair<Guid, App> app in GlobalVariables.Apps.Where(s =>
(s.Value.status & Status.Installed) == Status.Installed))
(s.Value.Status & Status.Installed) == Status.Installed))
{
Console.BackgroundColor = (app.Value.status & Status.Local) == Status.Local ? ConsoleColor.DarkRed :
(app.Value.status & Status.Updatable) == Status.Updatable ? ConsoleColor.DarkGreen :
Console.BackgroundColor = (app.Value.Status & Status.Local) == Status.Local ? ConsoleColor.DarkRed :
(app.Value.Status & Status.Updatable) == Status.Updatable ? ConsoleColor.DarkGreen :
ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"{app.Value.Name} ({app.Key})");
@ -135,7 +138,7 @@ namespace UpToolCLI
{
RepoManagement.GetReposFromDisk();
foreach (KeyValuePair<Guid, App> app in GlobalVariables.Apps.Where(s =>
(s.Value.status & Status.Updatable) == Status.Updatable))
(s.Value.Status & Status.Updatable) == Status.Updatable))
{
Console.WriteLine($"Updating {app.Value.Name}");
AppExtras.Update(app.Value, false);
@ -167,21 +170,17 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
if ((tmp.status & Status.Updatable) == Status.Updatable)
if ((tmp.Status & Status.Updatable) == Status.Updatable)
{
Console.WriteLine($"Upgrading {tmp.Name}");
AppExtras.Update(tmp, force);
}
else
{
Console.WriteLine("Package is up-to-date");
}
}
Console.WriteLine("Done!");
}
@ -191,9 +190,7 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
@ -208,21 +205,17 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
if ((tmp.status & Status.Installed) == Status.Installed)
if ((tmp.Status & Status.Installed) == Status.Installed)
{
Console.WriteLine($"Removing {tmp.Name}");
AppExtras.Remove(tmp, false);
}
else
{
Console.WriteLine("Package is not installed");
}
}
Console.WriteLine("Done!");
}
@ -232,21 +225,17 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
if ((tmp.status & Status.Installed) == Status.Installed)
if ((tmp.Status & Status.Installed) == Status.Installed)
{
Console.WriteLine($"Purgeing {tmp.Name}");
AppExtras.Remove(tmp, true);
}
else
{
Console.WriteLine("Package is not installed");
}
}
Console.WriteLine("Done!");
}
@ -257,15 +246,25 @@ namespace UpToolCLI
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
if (File.Exists(identifier))
{
Console.WriteLine("Name:");
string name = Console.ReadLine();
AppInstall.InstallZip(identifier, new App(name, "Locally installed package, removal only", GlobalVariables.MinimumVer, "", true, "",
Guid.NewGuid(), Color.Red, "", false, ""), force);
Console.WriteLine($"Successfully installed \"{name}\"");
}
else
{
Console.WriteLine("Package not found.");
Console.WriteLine(identifier);
}
}
else
{
App tmp = apps.First();
if ((tmp.status & Status.Installed) == Status.Installed)
{
if ((tmp.Status & Status.Installed) == Status.Installed)
Console.WriteLine("Package is already installed");
}
else
{
Console.WriteLine($"Installing {tmp.Name}");
@ -280,16 +279,19 @@ namespace UpToolCLI
RepoManagement.GetReposFromDisk();
App[] apps = AppExtras.FindApps(identifier);
if (apps.Length == 0)
{
Console.WriteLine("Package not found.");
}
else
{
App tmp = apps.First();
Console.WriteLine($"Starting {tmp.Name}");
System.Diagnostics.Process tmp1 = AppExtras.RunApp(tmp);
if (waitForExit)
tmp1.WaitForExit();
if (tmp.Runnable)
{
Console.WriteLine($"Starting {tmp.Name}");
System.Diagnostics.Process tmp1 = AppExtras.RunApp(tmp);
if (waitForExit)
tmp1.WaitForExit();
}
else
Console.WriteLine($"{tmp.Name} is not runnable");
}
Console.WriteLine("Done!");
}

View File

@ -8,7 +8,7 @@ using UpToolLib.DataStructures;
namespace UpToolCLI
{
public class UTLibFunctions : IExternalFunctionality
public class UtLibFunctions : IExternalFunctionality
{
public Tuple<bool, byte[]> Download(Uri link)
{
@ -82,7 +82,7 @@ namespace UpToolCLI
return current;
}
public void OKDialog(string text)
public void OkDialog(string text)
{
Console.WriteLine(text);
Console.BackgroundColor = ConsoleColor.White;

View File

@ -38,13 +38,13 @@ namespace UpToolLib.DataStructures
MainFile = mainFile ?? throw new ArgumentNullException(nameof(mainFile));
}
public Status status
public Status Status
{
get
{
if (!System.IO.File.Exists(infoPath))
return Status.Not_Installed;
if (Version.TryParse(XDocument.Load(infoPath).Element("app").Element("Version").Value,
if (!System.IO.File.Exists(InfoPath))
return Status.NotInstalled;
if (Version.TryParse(XDocument.Load(InfoPath).Element("app").Element("Version").Value,
out Version ver) && ver >= Version)
return Local ? Status.Installed | Status.Local : Status.Installed;
return Status.Installed | Status.Updatable;
@ -68,15 +68,15 @@ ID: {Id}
Color: {Color.ToKnownColor()}
Runnable: {Runnable}
MainFile: {MainFile}
Status: {status}
Status: {Status}
Object Hash Code: {GetHashCode()}";
public static bool operator ==(App left, App right) => left.Equals(right);
public static bool operator !=(App left, App right) => !(left == right);
public string appPath => PathTool.GetAppPath(Id);
public string dataPath => PathTool.GetDataPath(Id);
public string infoPath => PathTool.GetInfoPath(Id);
public string AppPath => PathTool.GetAppPath(Id);
public string DataPath => PathTool.GetDataPath(Id);
public string InfoPath => PathTool.GetInfoPath(Id);
}
}

View File

@ -7,7 +7,7 @@ namespace UpToolLib.DataStructures
public Tuple<bool, byte[]> Download(Uri link);
public string FetchImageB64(Uri link);
public bool YesNoDialog(string text, bool defaultVal);
public void OKDialog(string text);
public void OkDialog(string text);
public object GetDefaultIcon();
public object ImageFromB64(string b64);
public void Log(string text);

View File

@ -5,7 +5,7 @@ namespace UpToolLib.DataStructures
[Flags]
public enum Status
{
Not_Installed = 1,
NotInstalled = 1,
Updatable = 2,
Installed = 4,
Local = 8,

View File

@ -4,11 +4,11 @@ namespace UpToolLib
{
public static class ExternalFunctionalityManager
{
internal static IExternalFunctionality instance;
internal static IExternalFunctionality Instance;
public static void Init(IExternalFunctionality externalFunctionality)
{
instance = externalFunctionality;
Instance = externalFunctionality;
}
}
}

View File

@ -7,6 +7,6 @@ namespace UpToolLib
public static class GlobalVariables
{
public static readonly Dictionary<Guid, App> Apps = new Dictionary<Guid, App>();
public static Version minimumVer => Version.Parse("0.0.0.0");
public static Version MinimumVer => Version.Parse("0.0.0.0");
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Threading;
namespace UpToolLib

View File

@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace UpToolLib.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("UpToolLib.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -1,101 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -14,8 +14,8 @@ namespace UpToolLib.Tool
Process.Start(
new ProcessStartInfo
{
FileName = Path.Combine(app.dataPath, app.MainFile),
WorkingDirectory = app.dataPath
FileName = Path.Combine(app.DataPath, app.MainFile),
WorkingDirectory = app.DataPath
});
public static void Update(App app, bool overwrite)
@ -26,32 +26,61 @@ namespace UpToolLib.Tool
public static void Remove(App app, bool deleteAll)
{
string tmp = PathTool.tempPath;
string tmp = PathTool.TempPath;
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
if (File.Exists(Path.Combine(app.appPath, "package.zip")))
if (File.Exists(Path.Combine(app.AppPath, "package.zip")))
{
ZipFile.ExtractToDirectory(Path.Combine(app.appPath, "package.zip"), tmp);
Process.Start(new ProcessStartInfo
ZipFile.ExtractToDirectory(Path.Combine(app.AppPath, "package.zip"), tmp);
/*Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C \"{Path.Combine(tmp, "Remove.bat")}\"",
WorkingDirectory = Path.Combine(app.appPath, "app"),
WorkingDirectory = Path.Combine(app.AppPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
if (!deleteAll) CheckDirecory(Path.Combine(tmp, "Data"), app.dataPath);
}).WaitForExit();*/
int key = new[]
{
PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT,
PlatformID.WinCE
}
.Contains(Environment.OSVersion.Platform) ? 0 :
File.Exists(Path.Combine(tmp, "Remove.sh")) ? 1 : 2;
ProcessStartInfo prc = new ProcessStartInfo
{
FileName = key switch
{
0 => "cmd.exe",
1 => "bash",
2 => "wine",
_ => throw new Exception()
},
WorkingDirectory = Path.Combine(app.AppPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
foreach (string s in key switch
{
0 => new[] {"/C", $"{Path.Combine(tmp, "Remove.bat")}"},
1 => new[] {Path.Combine(tmp, "Remove.sh")},
2 => new[] {"cmd", "/C", $"{Path.Combine(tmp, "Remove.bat")}"},
_ => throw new Exception()
})
prc.ArgumentList.Add(s);
Process.Start(prc)?.WaitForExit();
if (!deleteAll) CheckDirecory(Path.Combine(tmp, "Data"), app.DataPath);
Directory.Delete(tmp, true);
}
if (File.Exists(app.infoPath))
File.Delete(app.infoPath);
if (File.Exists(Path.Combine(app.appPath, "package.zip")))
File.Delete(Path.Combine(app.appPath, "package.zip"));
if (deleteAll || (Directory.Exists(app.dataPath) &&
Directory.GetFiles(app.dataPath).Length + Directory.GetDirectories(app.dataPath).Length ==
if (File.Exists(app.InfoPath))
File.Delete(app.InfoPath);
if (File.Exists(Path.Combine(app.AppPath, "package.zip")))
File.Delete(Path.Combine(app.AppPath, "package.zip"));
if (deleteAll || (Directory.Exists(app.DataPath) &&
Directory.GetFiles(app.DataPath).Length + Directory.GetDirectories(app.DataPath).Length ==
0))
Directory.Delete(app.appPath, true);
Directory.Delete(app.AppPath, true);
}
private static void CheckDirecory(string tmp, string app)

View File

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
@ -23,8 +24,8 @@ namespace UpToolLib.Tool
try
{
#endif
app = appI.appPath;
tmp = PathTool.tempPath;
app = appI.AppPath;
tmp = PathTool.TempPath;
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
@ -39,7 +40,7 @@ namespace UpToolLib.Tool
if (!Directory.Exists(app))
Directory.CreateDirectory(app);
}
(bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.instance.Download(new Uri(appI.File));
(bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.Instance.Download(new Uri(appI.File));
if (!dlSuccess)
throw new Exception("Download failed");
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
@ -77,9 +78,9 @@ Online: {appI.Hash.ToUpper()}");
string tmp = "";
try
{
app = meta.appPath;
app = meta.AppPath;
Directory.CreateDirectory(app);
tmp = PathTool.tempPath;
tmp = PathTool.TempPath;
if (Directory.Exists(tmp))
Directory.Delete(tmp, true);
Directory.CreateDirectory(tmp);
@ -102,18 +103,16 @@ Online: {appI.Hash.ToUpper()}");
//Use
//PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Hello World')"
//for message boxes
private static void CompleteInstall(App app, bool force) => CompleteInstall(app.appPath, app.Name,
private static void CompleteInstall(App app, bool force) => CompleteInstall(app.AppPath, app.Name,
app.Description, app.Version, app.MainFile, force);
private static void CompleteInstall(string appPath, string name, string description, Version version,
string mainFile, bool force)
{
string tmp = PathTool.tempPath;
string tmp = PathTool.TempPath;
ZipFile.ExtractToDirectory(Path.Combine(appPath, "package.zip"), tmp);
if (force)
{
Directory.Move(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
}
else
{
CopyAll(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
@ -124,14 +123,62 @@ Online: {appI.Hash.ToUpper()}");
if (mainFile != null)
el.Add(new XElement(new XElement("MainFile", mainFile)));
el.Save(Path.Combine(appPath, "info.xml"));
Process.Start(new ProcessStartInfo
/*if (new[] { PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT, PlatformID.WinCE }.Contains(Environment.OSVersion.Platform))
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
ArgumentList = {"/C", $"{Path.Combine(tmp, "Install.bat")}"},
WorkingDirectory = Path.Combine(appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
else if (File.Exists(Path.Combine(tmp, "Install.sh")))
Process.Start(new ProcessStartInfo
{
FileName = "bash",
ArgumentList = {Path.Combine(tmp, "Install.sh")},
WorkingDirectory = Path.Combine(appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
else
Process.Start(new ProcessStartInfo
{
FileName = "wine",
ArgumentList = {"cmd", "/C", $"{Path.Combine(tmp, "Install.bat")}"},
WorkingDirectory = Path.Combine(appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();*/
int key = new[]
{
PlatformID.Xbox, PlatformID.Win32S, PlatformID.Win32Windows, PlatformID.Win32NT,
PlatformID.WinCE
}
.Contains(Environment.OSVersion.Platform) ? 0 :
File.Exists(Path.Combine(tmp, "Install.sh")) ? 1 : 2;
ProcessStartInfo prc = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/C \"{Path.Combine(tmp, "Install.bat")}\"",
FileName = key switch
{
0 => "cmd.exe",
1 => "bash",
2 => "wine",
_ => throw new Exception()
},
WorkingDirectory = Path.Combine(appPath, "app"),
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
}).WaitForExit();
};
foreach (string s in key switch
{
0 => new[] {"/C", $"{Path.Combine(tmp, "Install.bat")}"},
1 => new[] {Path.Combine(tmp, "Install.sh")},
2 => new[] {"cmd", "/C", $"{Path.Combine(tmp, "Install.bat")}"},
_ => throw new Exception()
})
prc.ArgumentList.Add(s);
Process.Start(prc)?.WaitForExit();
}
private static void CopyAll(string source, string target)

View File

@ -6,17 +6,17 @@ namespace UpToolLib.Tool
{
public static class PathTool
{
public static string dir =>
public static string Dir =>
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
public static string tempPath => GetRelative("tmp");
public static string appsPath => GetRelative("Apps");
public static string TempPath => GetRelative("tmp");
public static string AppsPath => GetRelative("Apps");
public static string InfoXml => GetRelative("info.xml");
public static string GetRelative(params string[] segments) =>
Path.Combine(new[] {dir}.Concat(segments).ToArray());
Path.Combine(new[] {Dir}.Concat(segments).ToArray());
public static string GetAppPath(Guid app) => Path.Combine(appsPath, app.ToString());
public static string GetAppPath(Guid app) => Path.Combine(AppsPath, app.ToString());
public static string GetDataPath(Guid app) => Path.Combine(GetAppPath(app), "app");

View File

@ -25,11 +25,11 @@ namespace UpToolLib.Tool
try
{
#endif
ExternalFunctionalityManager.instance.Log($"[{i + 1}] Loading {repArr[i]}");
ExternalFunctionalityManager.Instance.Log($"[{i + 1}] Loading {repArr[i]}");
XDocument repo = XDocument.Load(new Uri(repArr[i]).Unshorten().AbsoluteUri);
repArr.AddRange(repo.Element("repo").Elements("repolink").Select(s => s.Value)
.Where(s => !repArr.Contains(s)));
XElement[] tmp_apparray = repo.Element("repo").Elements("app").Where(app =>
XElement[] tmpApparray = repo.Element("repo").Elements("app").Where(app =>
!tmpAppsList.Any(a => a.Element("ID").Value == app.Element("ID").Value) ||
!tmpAppsList
.Where(a => a.Element("ID").Value == app.Element("ID").Value).Any(a =>
@ -37,13 +37,12 @@ namespace UpToolLib.Tool
.Concat(repo.Element("repo").Elements("applink")
.Select(s =>
{
ExternalFunctionalityManager.instance.Log($"- Loading {s.Value}");
ExternalFunctionalityManager.Instance.Log($"- Loading {s.Value}");
return XDocument.Load(new Uri(s.Value).Unshorten().AbsoluteUri).Element("app");
}))
.ToArray();
for (int i1 = 0; i1 < tmp_apparray.Length; i1++)
foreach (XElement app in tmpApparray)
{
XElement app = tmp_apparray[i1];
//"Sanity check"
Version.Parse(app.Element("Version").Value);
Guid.Parse(app.Element("ID").Value);
@ -63,14 +62,16 @@ namespace UpToolLib.Tool
{
tmpAppsList.Last()
.Add(new XElement("Icon",
ExternalFunctionalityManager.instance.FetchImageB64(
ExternalFunctionalityManager.Instance.FetchImageB64(
new Uri(app.Element("Icon").Value).Unshorten())));
}
catch
{
// ignored
}
if (tmpAppsList.Count(a => a.Element("ID").Value == app.Element("ID").Value) > 1)
XElement app1 = app;
if (tmpAppsList.Count(a => a.Element("ID").Value == app1.Element("ID").Value) > 1)
tmpAppsList.Where(a => a.Element("ID").Value == app.Element("ID").Value).Reverse()
.Skip(1)
.ToList().ForEach(a => tmpAppsList.Remove(a));
@ -79,7 +80,7 @@ namespace UpToolLib.Tool
}
catch (Exception e)
{
ExternalFunctionalityManager.instance.OKDialog(
ExternalFunctionalityManager.Instance.OkDialog(
$"Failed to load repo: {repArr[i]}{Environment.NewLine}{e}");
}
#endif
@ -112,7 +113,7 @@ namespace UpToolLib.Tool
string locInPath = PathTool.GetInfoPath(id);
XElement locIn = File.Exists(locInPath) ? XDocument.Load(locInPath).Element("app") : app;
if (int.TryParse(app.Element("Version").Value, out _))
app.Element("Version").Value = GlobalVariables.minimumVer.ToString();
app.Element("Version").Value = GlobalVariables.MinimumVer.ToString();
GlobalVariables.Apps.Add(id, new App(
locIn.Element("Name").Value,
locIn.Element("Description").Value,
@ -123,15 +124,15 @@ namespace UpToolLib.Tool
id,
Color.White,
app.Element("Icon") == null
? ExternalFunctionalityManager.instance.GetDefaultIcon()
: ExternalFunctionalityManager.instance.ImageFromB64(app.Element("Icon").Value),
? ExternalFunctionalityManager.Instance.GetDefaultIcon()
: ExternalFunctionalityManager.Instance.ImageFromB64(app.Element("Icon").Value),
locIn.Element("MainFile") != null || app.Element("MainFile") != null,
locIn.Element("MainFile") == null
? app.Element("MainFile") == null ? "" : app.Element("MainFile").Value
: locIn.Element("MainFile").Value
));
});
Directory.GetDirectories(PathTool.appsPath)
Directory.GetDirectories(PathTool.AppsPath)
.Where(s => Guid.TryParse(Path.GetFileName(s), out Guid guid) &&
!GlobalVariables.Apps.ContainsKey(guid)).ToList().ForEach(s =>
{
@ -141,14 +142,14 @@ namespace UpToolLib.Tool
XElement data = XDocument.Load(PathTool.GetInfoPath(tmp)).Element("app");
GlobalVariables.Apps.Add(tmp,
new App("(local) " + data.Element("Name").Value, data.Element("Description").Value,
GlobalVariables.minimumVer, "", true, "", tmp, Color.Red,
ExternalFunctionalityManager.instance.GetDefaultIcon(),
GlobalVariables.MinimumVer, "", true, "", tmp, Color.Red,
ExternalFunctionalityManager.Instance.GetDefaultIcon(),
data.Element("MainFile") != null,
data.Element("MainFile") == null ? "" : data.Element("MainFile").Value));
}
catch (Exception e)
{
if (ExternalFunctionalityManager.instance.YesNoDialog(
if (ExternalFunctionalityManager.Instance.YesNoDialog(
$@"An error occured while loading this local repo:
{e.Message}
Do you want to exit? Otherwise the folder will be deleted, possibly causeing problems later.", false))

View File

@ -8,6 +8,8 @@ namespace UpToolLib.Tool
{
public static void FixXml()
{
if (!Directory.Exists(PathTool.AppsPath))
Directory.CreateDirectory(PathTool.AppsPath);
if (!File.Exists(PathTool.InfoXml) || XDocument.Load(PathTool.InfoXml).Element("meta") == null)
new XElement("meta").Save(PathTool.InfoXml);
XDocument x = XDocument.Load(PathTool.InfoXml);

View File

@ -8,19 +8,4 @@
<PackageReference Include="CC-Functions.Misc" Version="1.1.7399.26972" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>