Improve output

This commit is contained in:
Sander Declerck 2026-01-19 14:30:09 +01:00
parent 2784dfd34e
commit 0e7cce750d
No known key found for this signature in database

View file

@ -36,29 +36,35 @@ async function installOnWindows() {
const downloadUrl = buildDownloadUrl(architecture); const downloadUrl = buildDownloadUrl(architecture);
const msiPath = join(tmpdir(), `SafeChainAgent-${Date.now()}.msi`); const msiPath = join(tmpdir(), `SafeChainAgent-${Date.now()}.msi`);
ui.emptyLine();
ui.writeInformation( ui.writeInformation(
`Downloading SafeChain Agent ${ULTIMATE_VERSION} for ${architecture}...`, `📥 Downloading SafeChain Agent ${ULTIMATE_VERSION} (${architecture})...`,
); );
ui.writeVerbose(`Download URL: ${downloadUrl}`); ui.writeVerbose(`Download URL: ${downloadUrl}`);
ui.writeVerbose(`Destination: ${msiPath}`); ui.writeVerbose(`Destination: ${msiPath}`);
await downloadFile(downloadUrl, msiPath); await downloadFile(downloadUrl, msiPath);
ui.emptyLine();
stopServiceIfRunning(); stopServiceIfRunning();
uninstallIfInstalled(); uninstallIfInstalled();
// Wait a moment for uninstall to complete // Wait a moment for uninstall to complete
await new Promise((resolve) => setTimeout(resolve, 2000)); await new Promise((resolve) => setTimeout(resolve, 2000));
ui.writeInformation("Installing SafeChain Agent..."); ui.writeInformation("⚙️ Installing SafeChain Agent...");
ui.writeVerbose(`Running: msiexec /i "${msiPath}" /qn /norestart`); ui.writeVerbose(`Running: msiexec /i "${msiPath}" /qn /norestart`);
runMsiInstaller(msiPath); runMsiInstaller(msiPath);
ui.writeInformation("Starting SafeChain Agent service..."); ui.emptyLine();
ui.writeInformation("🚀 Starting SafeChain Agent service...");
startService(); startService();
ui.writeVerbose(`Cleaning up temporary file: ${msiPath}`); ui.writeVerbose(`Cleaning up temporary file: ${msiPath}`);
cleanup(msiPath); cleanup(msiPath);
ui.writeInformation("SafeChain Agent installed and started successfully!");
ui.emptyLine();
ui.writeInformation("✅ SafeChain Agent installed and started successfully!");
ui.emptyLine();
} }
function isRunningAsAdmin() { function isRunningAsAdmin() {
@ -98,8 +104,6 @@ async function downloadFile(url, destPath) {
function uninstallIfInstalled() { function uninstallIfInstalled() {
try { try {
ui.writeInformation("Uninstalling existing SafeChain Agent...");
// Use PowerShell to find the product code, then use msiexec to uninstall // Use PowerShell to find the product code, then use msiexec to uninstall
// This is the modern alternative to wmic which is deprecated // This is the modern alternative to wmic which is deprecated
const findProductCodeCmd = `powershell -Command "$app = Get-WmiObject -Class Win32_Product -Filter \\"Name='SafeChain Agent'\\"; if ($app) { Write-Output $app.IdentifyingNumber }"`; const findProductCodeCmd = `powershell -Command "$app = Get-WmiObject -Class Win32_Product -Filter \\"Name='SafeChain Agent'\\"; if ($app) { Write-Output $app.IdentifyingNumber }"`;
@ -110,17 +114,18 @@ function uninstallIfInstalled() {
}).trim(); }).trim();
if (productCode) { if (productCode) {
ui.writeInformation("🗑️ Removing previous installation...");
ui.writeVerbose(`Found product code: ${productCode}`); ui.writeVerbose(`Found product code: ${productCode}`);
ui.writeVerbose(`Running: msiexec /x ${productCode} /qn /norestart`); ui.writeVerbose(`Running: msiexec /x ${productCode} /qn /norestart`);
execSync(`msiexec /x ${productCode} /qn /norestart`, { execSync(`msiexec /x ${productCode} /qn /norestart`, {
stdio: "inherit", stdio: "inherit",
}); });
} else { } else {
ui.writeVerbose("No existing SafeChain Agent installation found."); ui.writeVerbose("No existing installation found (fresh install).");
} }
} catch { } catch {
// Not installed or uninstall failed, which is fine for a fresh install // Not installed or uninstall failed, which is fine for a fresh install
ui.writeVerbose("No existing SafeChain Agent installation found."); ui.writeVerbose("No existing installation found (fresh install).");
} }
} }
@ -136,12 +141,12 @@ function runMsiInstaller(msiPath) {
function stopServiceIfRunning() { function stopServiceIfRunning() {
try { try {
ui.writeInformation("Stopping existing SafeChain Agent service..."); ui.writeInformation("⏹️ Stopping running service...");
ui.writeVerbose('Running: net stop "SafeChainAgent"'); ui.writeVerbose('Running: net stop "SafeChainAgent"');
execSync('net stop "SafeChainAgent"', { stdio: "inherit" }); execSync('net stop "SafeChainAgent"', { stdio: "inherit" });
} catch { } catch {
// Service is not running or doesn't exist, which is fine // Service is not running or doesn't exist, which is fine
ui.writeVerbose("SafeChain Agent service not running or not installed."); ui.writeVerbose("Service not running (will start after installation).");
} }
} }