Implement Linux locator

This commit is contained in:
Caelan
2024-01-10 09:25:45 +00:00
parent 9ee435cfba
commit a72c313405
5 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
using System;
using Microsoft.Extensions.Logging;
namespace AvaloniaCrossPlat;
public class ConsoleLogger : ILogger
{
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Console.WriteLine(formatter(state, exception));
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public IDisposable BeginScope<TState>(TState state)
{
return null;
}
}

View File

@@ -13,7 +13,7 @@ class Program
public static void Main(string[] args)
{
VelopackApp.Build()
.Run();
.Run(new ConsoleLogger());
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

View File

@@ -49,10 +49,12 @@ Categories=Development;
""");
File.Copy(Options.Icon, Path.Combine(dir.FullName, Options.PackId + Path.GetExtension(Options.Icon)), true);
var helper = new HelperExe(Log);
var bin = dir.CreateSubdirectory("usr").CreateSubdirectory("bin");
CopyFiles(new DirectoryInfo(packDir), bin, progress, true);
File.WriteAllText(Path.Combine(bin.FullName, "sq.version"), nuspecText);
File.Copy(helper.UpdateNixPath, Path.Combine(bin.FullName, "UpdateNix"), true);
progress(100);
return Task.FromResult(dir.FullName);
}

View File

@@ -24,6 +24,7 @@ public class HelperExe : HelperFile
var tool = AppImageTool;
Chmod.ChmodFileAsExecutable(tool);
InvokeAndThrowIfNonZero(tool, new[] { appDir, outputFile }, null);
Chmod.ChmodFileAsExecutable(outputFile);
}
[SupportedOSPlatform("osx")]

View File

@@ -1,11 +1,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NuGet.Versioning;
using Velopack.NuGet;
namespace Velopack.Locators
{
@@ -43,6 +46,9 @@ namespace Velopack.Locators
/// <summary> A pointer to /var/tmp/{velopack}, a location on linux which is semi-persistent. </summary>
public string PersistentVelopackDir => CreateSubDirIfDoesNotExist("/var/tmp", "velopack");
/// <summary> File path of the .AppImage which mounted and ran this application. </summary>
public string AppImagePath => Environment.GetEnvironmentVariable("APPIMAGE");
/// <summary>
/// Creates a new <see cref="OsxVelopackLocator"/> and auto-detects the
/// app information from metadata embedded in the .app.
@@ -54,8 +60,34 @@ namespace Velopack.Locators
throw new NotSupportedException("Cannot instantiate LinuxVelopackLocator on a non-linux system.");
Log.Info($"Initialising {nameof(LinuxVelopackLocator)}");
// are we inside a mounted .AppImage?
var ourPath = VelopackRuntimeInfo.EntryExePath;
var ix = ourPath.IndexOf("/usr/bin/", StringComparison.InvariantCultureIgnoreCase);
if (ix <= 0) {
Log.Warn($"Unable to locate .AppImage root from '{ourPath}'");
return;
}
throw new NotImplementedException();
var rootDir = ourPath.Substring(0, ix);
var contentsDir = Path.Combine(rootDir, "usr", "bin");
var updateExe = Path.Combine(contentsDir, "UpdateNix");
var metadataPath = Path.Combine(contentsDir, Utility.SpecVersionFileName);
if (!String.IsNullOrEmpty(AppImagePath) && File.Exists(AppImagePath)) {
if (File.Exists(updateExe) && NuspecManifest.TryParseFromFile(metadataPath, out var manifest)) {
Log.Info("Located valid manifest file at: " + metadataPath);
AppId = manifest.Id;
RootAppDir = rootDir;
AppContentDir = contentsDir;
UpdateExePath = updateExe;
CurrentlyInstalledVersion = manifest.Version;
} else {
logger.Error("Unable to locate UpdateNix in " + contentsDir);
}
} else {
logger.Error("Unable to locate .AppImage ($APPIMAGE)");
}
}
}
}