generated from azures04/Photino-Boilerplate
Added Configuration and post install
This commit is contained in:
parent
f1511f1d3d
commit
7b133c1ea5
@ -4,15 +4,22 @@ using BrikInstaller.Utils;
|
||||
|
||||
namespace BrikInstaller;
|
||||
|
||||
public static class Constants {
|
||||
public class Constants {
|
||||
public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
|
||||
public static readonly string Os = OsHelper.getOperatingSystem();
|
||||
public static readonly string Arch = OsHelper.getArchitecture();
|
||||
|
||||
public static readonly string Env = "DEV";
|
||||
|
||||
public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
public static readonly string CurrentWorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
|
||||
public static class ProductMetadata {
|
||||
public static string Name = "";
|
||||
public static string InstallPath = "";
|
||||
}
|
||||
|
||||
public static class URLs {
|
||||
public static readonly string ApiPoint = "https://brik.azures.fr";
|
||||
public static class Endpoints {
|
||||
@ -24,6 +31,9 @@ public static class Constants {
|
||||
|
||||
public static string Metadata()
|
||||
=> $"{ApiPoint}/metadata";
|
||||
|
||||
public static string Configuration(string softName, string os, string arch)
|
||||
=> $"{ApiPoint}/products/{softName}/{os}-{arch}/configuration";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,9 @@ using System.Text.Json;
|
||||
using BrikInstaller.Utils;
|
||||
using BrikInstaller.Schemas;
|
||||
using BrikInstaller.Services;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace BrikInstaller;
|
||||
|
||||
@ -58,7 +61,7 @@ class Program{
|
||||
string requestId = json.RootElement.GetProperty("requestId").GetString()!;
|
||||
string method = json.RootElement.GetProperty("functionName").GetString()!;
|
||||
var jsonPayload = json.RootElement.GetProperty("payload");
|
||||
|
||||
|
||||
object? responsePayload = null;
|
||||
var pw = (PhotinoWindow)sender!;
|
||||
|
||||
@ -122,7 +125,9 @@ class Program{
|
||||
case "installer::install":
|
||||
if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) {
|
||||
try {
|
||||
await GenericFilesService.SyncFilesAsync(Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), softInstallPath.ToString());
|
||||
Constants.ProductMetadata.Name = softName.ToString();
|
||||
Constants.ProductMetadata.InstallPath = softInstallPath.ToString();
|
||||
await GenericFilesService.SyncFilesAsync(Constants.URLs.Endpoints.Download(softName.ToString(), Constants.Os, Constants.Arch), Constants.URLs.Endpoints.Manifest(softName.ToString(), Constants.Os, Constants.Arch), softInstallPath.ToString());
|
||||
responsePayload = new { success = true };
|
||||
} catch (Exception) {
|
||||
responsePayload = new { success = false };
|
||||
@ -132,10 +137,13 @@ class Program{
|
||||
case "installer::quit":
|
||||
if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) {
|
||||
try {
|
||||
HttpMethod httpMethod = HttpMethod.Get;
|
||||
var response = await HttpHelper.FetchAsync(Constants.URLs.Endpoints.Configuration(Constants.ProductMetadata.Name, Constants.Os, Constants.Arch), httpMethod);
|
||||
var productConfig = await response.Content.ReadFromJsonAsync<ProductConfig>(Constants._jsonOptions);
|
||||
Console.WriteLine(productConfig!.Executable);
|
||||
InstallationFinish installationFinish = jsonPayload.Deserialize<InstallationFinish>(Constants._jsonOptions)!;
|
||||
if (installationFinish.CreateShortcut) {
|
||||
//TO-DO : Fetch executable path from remote
|
||||
// Create a shortcut with it
|
||||
ShortcutService.CreateShortcut(Constants.ProductMetadata.Name, Path.Combine(Constants.ProductMetadata.InstallPath, productConfig.Executable!));
|
||||
}
|
||||
if (installationFinish.LaunchAfterExit) {
|
||||
//TO-DO : Fetch executable path from remote
|
||||
|
||||
@ -7,4 +7,8 @@ public class ProductRequirement {
|
||||
public string? ExpectedOutputPattern { get; set; }
|
||||
public string? InstallationMode { get; set; }
|
||||
public string? InstallationUrl { get; set; }
|
||||
}
|
||||
|
||||
public class ProductConfig {
|
||||
public string? Executable { get; set; }
|
||||
}
|
||||
@ -8,6 +8,7 @@ public static class GenericFilesService {
|
||||
private static readonly HttpClient _httpClient = new();
|
||||
|
||||
public static async Task SyncFilesAsync(string rootEndpoint, string apiUrl, string destinationDir) {
|
||||
Console.WriteLine(rootEndpoint);
|
||||
try {
|
||||
var index = await _httpClient.GetFromJsonAsync<BrikFilesIndex>(apiUrl);
|
||||
if (index?.Root == null) return;
|
||||
|
||||
@ -75,32 +75,47 @@ public static class InstallationService {
|
||||
return final;
|
||||
}
|
||||
|
||||
public static void LaunchApplication(string executablePath) {
|
||||
try {
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo();
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
startInfo.FileName = executablePath;
|
||||
startInfo.UseShellExecute = true;
|
||||
}
|
||||
else {
|
||||
BashUtils.GetCommandOutput($"chmod +x \"{executablePath}\"");
|
||||
|
||||
startInfo.FileName = executablePath;
|
||||
startInfo.UseShellExecute = false;
|
||||
}
|
||||
|
||||
startInfo.WorkingDirectory = Path.GetDirectoryName(executablePath);
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine($"[Launch Error] Unable to start : {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ShortcutService {
|
||||
public static void CreateShortcut(string appName, string targetExePath, bool createDesktop, bool autoStart) {
|
||||
public static void CreateShortcut(string appName, string targetExePath) {
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||
CreateWindowsShortcut(appName, targetExePath);
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
|
||||
CreateMacShortcut(appName, targetExePath);
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
|
||||
CreateLinuxShortcut(appName, targetExePath);
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
|
||||
CreateMacShortcut(appName, targetExePath);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateMacShortcut(string appName, string targetExePath) {
|
||||
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
||||
string shortcutPath = Path.Combine(desktopPath, appName);
|
||||
|
||||
BashUtils.GetCommandOutput($"ln -sf \"{targetExePath}\" \"{shortcutPath}\"");
|
||||
}
|
||||
|
||||
private static void CreateWindowsShortcut(string appName, string targetExePath) {
|
||||
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||
string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk");
|
||||
|
||||
string script = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()";
|
||||
Process.Start(new ProcessStartInfo("powershell", $"-Command \"{script}\"") { CreateNoWindow = true });
|
||||
string cmd = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()";
|
||||
BashUtils.GetCommandOutput($"powershell -Command \"{cmd}\"");
|
||||
}
|
||||
|
||||
private static void CreateLinuxShortcut(string appName, string targetExePath) {
|
||||
@ -111,8 +126,16 @@ Name={appName}
|
||||
Exec=""{targetExePath}""
|
||||
Terminal=false
|
||||
";
|
||||
|
||||
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
||||
File.WriteAllText(Path.Combine(desktopPath, $"{appName}.desktop"), desktopEntry);
|
||||
Process.Start("chmod", $"+x \"{Path.Combine(desktopPath, $"{appName}.desktop")}\"");
|
||||
string filePath = Path.Combine(desktopPath, $"{appName}.desktop");
|
||||
File.WriteAllText(filePath, desktopEntry);
|
||||
BashUtils.GetCommandOutput($"chmod +x \"{filePath}\"");
|
||||
}
|
||||
|
||||
private static void CreateMacShortcut(string appName, string targetExePath) {
|
||||
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
|
||||
string shortcutPath = Path.Combine(desktopPath, appName);
|
||||
BashUtils.GetCommandOutput($"ln -sf \"{targetExePath}\" \"{shortcutPath}\"");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user