Added Configuration and post install

This commit is contained in:
Gilles Lazures 2026-02-11 02:31:30 +01:00
parent f1511f1d3d
commit 7b133c1ea5
5 changed files with 66 additions and 20 deletions

View File

@ -4,15 +4,22 @@ using BrikInstaller.Utils;
namespace BrikInstaller; namespace BrikInstaller;
public static class Constants { public class Constants {
public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; public static readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
public static readonly string Os = OsHelper.getOperatingSystem(); public static readonly string Os = OsHelper.getOperatingSystem();
public static readonly string Arch = OsHelper.getArchitecture(); public static readonly string Arch = OsHelper.getArchitecture();
public static readonly string Env = "DEV"; public static readonly string Env = "DEV";
public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory; public static readonly string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string CurrentWorkingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; 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 class URLs {
public static readonly string ApiPoint = "https://brik.azures.fr"; public static readonly string ApiPoint = "https://brik.azures.fr";
public static class Endpoints { public static class Endpoints {
@ -24,6 +31,9 @@ public static class Constants {
public static string Metadata() public static string Metadata()
=> $"{ApiPoint}/metadata"; => $"{ApiPoint}/metadata";
public static string Configuration(string softName, string os, string arch)
=> $"{ApiPoint}/products/{softName}/{os}-{arch}/configuration";
} }
} }
} }

View File

@ -4,6 +4,9 @@ using System.Text.Json;
using BrikInstaller.Utils; using BrikInstaller.Utils;
using BrikInstaller.Schemas; using BrikInstaller.Schemas;
using BrikInstaller.Services; using BrikInstaller.Services;
using System.Security.Cryptography.X509Certificates;
using System.Net.Http.Json;
using System.Reflection.Metadata;
namespace BrikInstaller; namespace BrikInstaller;
@ -58,7 +61,7 @@ class Program{
string requestId = json.RootElement.GetProperty("requestId").GetString()!; string requestId = json.RootElement.GetProperty("requestId").GetString()!;
string method = json.RootElement.GetProperty("functionName").GetString()!; string method = json.RootElement.GetProperty("functionName").GetString()!;
var jsonPayload = json.RootElement.GetProperty("payload"); var jsonPayload = json.RootElement.GetProperty("payload");
object? responsePayload = null; object? responsePayload = null;
var pw = (PhotinoWindow)sender!; var pw = (PhotinoWindow)sender!;
@ -122,7 +125,9 @@ class Program{
case "installer::install": case "installer::install":
if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) { if (jsonPayload.TryGetProperty("soft", out var softName) && jsonPayload.TryGetProperty("path", out var softInstallPath)) {
try { 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 }; responsePayload = new { success = true };
} catch (Exception) { } catch (Exception) {
responsePayload = new { success = false }; responsePayload = new { success = false };
@ -132,10 +137,13 @@ class Program{
case "installer::quit": case "installer::quit":
if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) { if (jsonPayload.TryGetProperty("createShortcut", out var createShortcut) && jsonPayload.TryGetProperty("launchAfterExit", out var launchAfterExit)) {
try { 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)!; InstallationFinish installationFinish = jsonPayload.Deserialize<InstallationFinish>(Constants._jsonOptions)!;
if (installationFinish.CreateShortcut) { if (installationFinish.CreateShortcut) {
//TO-DO : Fetch executable path from remote ShortcutService.CreateShortcut(Constants.ProductMetadata.Name, Path.Combine(Constants.ProductMetadata.InstallPath, productConfig.Executable!));
// Create a shortcut with it
} }
if (installationFinish.LaunchAfterExit) { if (installationFinish.LaunchAfterExit) {
//TO-DO : Fetch executable path from remote //TO-DO : Fetch executable path from remote

View File

@ -7,4 +7,8 @@ public class ProductRequirement {
public string? ExpectedOutputPattern { get; set; } public string? ExpectedOutputPattern { get; set; }
public string? InstallationMode { get; set; } public string? InstallationMode { get; set; }
public string? InstallationUrl { get; set; } public string? InstallationUrl { get; set; }
}
public class ProductConfig {
public string? Executable { get; set; }
} }

View File

@ -8,6 +8,7 @@ public static class GenericFilesService {
private static readonly HttpClient _httpClient = new(); private static readonly HttpClient _httpClient = new();
public static async Task SyncFilesAsync(string rootEndpoint, string apiUrl, string destinationDir) { public static async Task SyncFilesAsync(string rootEndpoint, string apiUrl, string destinationDir) {
Console.WriteLine(rootEndpoint);
try { try {
var index = await _httpClient.GetFromJsonAsync<BrikFilesIndex>(apiUrl); var index = await _httpClient.GetFromJsonAsync<BrikFilesIndex>(apiUrl);
if (index?.Root == null) return; if (index?.Root == null) return;

View File

@ -75,32 +75,47 @@ public static class InstallationService {
return final; 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 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)) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
CreateWindowsShortcut(appName, targetExePath); CreateWindowsShortcut(appName, targetExePath);
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
CreateMacShortcut(appName, targetExePath);
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
CreateLinuxShortcut(appName, targetExePath); 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) { private static void CreateWindowsShortcut(string appName, string targetExePath) {
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk"); string shortcutLocation = Path.Combine(desktopPath, $"{appName}.lnk");
string cmd = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()";
string script = $"$s=(New-Object -ComObject WScript.Shell).CreateShortcut('{shortcutLocation}');$s.TargetPath='{targetExePath}';$s.Save()"; BashUtils.GetCommandOutput($"powershell -Command \"{cmd}\"");
Process.Start(new ProcessStartInfo("powershell", $"-Command \"{script}\"") { CreateNoWindow = true });
} }
private static void CreateLinuxShortcut(string appName, string targetExePath) { private static void CreateLinuxShortcut(string appName, string targetExePath) {
@ -111,8 +126,16 @@ Name={appName}
Exec=""{targetExePath}"" Exec=""{targetExePath}""
Terminal=false Terminal=false
"; ";
string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop"); string desktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Desktop");
File.WriteAllText(Path.Combine(desktopPath, $"{appName}.desktop"), desktopEntry); string filePath = Path.Combine(desktopPath, $"{appName}.desktop");
Process.Start("chmod", $"+x \"{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}\"");
} }
} }