Code cleanup

This commit is contained in:
Kevin Bost
2025-03-27 00:18:48 -07:00
parent fcd07da715
commit 63637c63ea
11 changed files with 38 additions and 49 deletions

14
Cargo.lock generated
View File

@@ -1133,7 +1133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if 1.0.0",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]
[[package]]
@@ -2277,6 +2277,7 @@ dependencies = [
"tempfile",
"time 0.3.41",
"velopack",
"wait-timeout",
"waitpid-any",
"webview2-com-sys",
"windows",
@@ -2319,6 +2320,15 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wait-timeout"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
dependencies = [
"libc",
]
[[package]]
name = "waitpid-any"
version = "0.3.0"
@@ -2491,7 +2501,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.59.0",
]
[[package]]

View File

@@ -59,6 +59,7 @@ regex.workspace = true
normpath.workspace = true
simple-stopwatch.workspace = true
file-rotate.workspace = true
wait-timeout.workspace = true
pretty-bytes-rust.workspace = true
enum-flags.workspace = true
log-panics.workspace = true

View File

@@ -1,4 +1,4 @@
//#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![allow(dead_code)]
#[macro_use]
@@ -158,7 +158,6 @@ fn run_inner(arg_config: Command) -> Result<()> {
// try to load the bundle from embedded zip
if offset > 0 && length > 0 {
info!("Loading bundle from embedded zip...");
bundle = Some(velopack::bundle::load_bundle_from_memory(&mmap[offset as usize..(offset + length) as usize])?);
}

View File

@@ -1,4 +1,4 @@
// #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![allow(dead_code)]
#[macro_use]

View File

@@ -22,7 +22,7 @@ namespace Velopack
Installer = 4,
/// <summary> A Windows Installer package (.msi) for the deployment tool.</summary>
MsiDeploymentTool = 5,
/// <summary> A Windows Installer package (.msi) that bootstraps the installer.</summary>
/// <summary> A Windows Installer package (.msi).</summary>
Msi = 6,
}

View File

@@ -52,6 +52,7 @@ pub fn load_bundle_from_file<'a, P: AsRef<Path>>(file_name: P) -> Result<BundleZ
}
pub fn load_bundle_from_memory(zip_range: &[u8]) -> Result<BundleZip, Error> {
info!("Loading bundle from embedded zip...");
let cursor: Box<dyn ReadSeek> = Box::new(Cursor::new(zip_range));
let zip = ZipArchive::new(cursor)?;
Ok(BundleZip {

View File

@@ -1,9 +1,10 @@
use std::path::PathBuf;
use semver::Version;
use uuid::Uuid;
use crate::{
bundle::{self, Manifest}, lockfile::LockFile, util::{self}, Error
bundle::{self, Manifest},
util::{self}, Error,
lockfile::LockFile
};
/// Returns the default channel name for the current OS.
@@ -132,8 +133,11 @@ impl VelopackLocator {
pub fn get_packages_dir(&self) -> PathBuf {
let path = self.paths.PackagesDir.clone();
if self.is_local_machine_install() || !util::is_directory_writable(&path) {
//TODO Need to add in the app name here.
//util::get_local_app_data()
let velopack_dir = std::env::temp_dir().join(format!("velopack_{}", self.manifest.id));
if !velopack_dir.exists() {
std::fs::create_dir_all(&velopack_dir).unwrap();
}
return velopack_dir.join("packages");
}
path
}

View File

@@ -6,15 +6,6 @@ use std::path::Path;
use std::thread;
use std::time::Duration;
// #[cfg(target_os = "windows")]
// use windows::{
// core::{GUID, PWSTR},
// Win32::UI::Shell::{
// FOLDERID_LocalAppData,
// SHGetKnownFolderPath,
// },
// };
pub fn retry_io<F, T, E>(op: F) -> Result<T, E>
where
F: Fn() -> Result<T, E>,
@@ -84,26 +75,3 @@ pub fn is_directory_writable<P1: AsRef<Path>>(path: P1) -> bool {
result.is_ok()
}
// #[cfg(target_os = "windows")]
// fn get_known_folder(rfid: *const GUID) -> Result<String, Error> {
// unsafe {
// let flag = windows::Win32::UI::Shell::KNOWN_FOLDER_FLAG(0);
// let result = SHGetKnownFolderPath(rfid, flag, None)?;
// pwstr_to_string(result)
// }
// }
// #[cfg(target_os = "windows")]
// fn pwstr_to_string(input: PWSTR) -> Result<String, Error> {
// unsafe {
// let hstring = input.to_hstring();
// let string = hstring.to_string_lossy();
// Ok(string.trim_end_matches('\0').to_string())
// }
// }
// #[cfg(target_os = "windows")]
// pub fn get_local_app_data() -> Result<String, Error> {
// get_known_folder(&FOLDERID_LocalAppData)
// }

View File

@@ -25,7 +25,7 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
Regex fileExcludeRegex = Options.SignExclude != null ? new Regex(Options.SignExclude) : null;
var filesToSign = new DirectoryInfo(packDir).GetAllFilesRecursively()
.Where(x => PathUtil.FileIsLikelyPEImage(x.Name))
.Where(x => fileExcludeRegex != null ? !fileExcludeRegex.IsMatch(x.FullName) : true)
.Where(x => fileExcludeRegex == null || !fileExcludeRegex.IsMatch(x.FullName))
.Select(x => x.FullName)
.ToArray();
@@ -228,6 +228,8 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
var portablePackage = new DirectoryInfo(Path.Combine(TempDir.FullName, "CreatePortablePackage"));
if (portablePackage.Exists) {
CompileWixTemplateToMsi(msiProgress, portablePackage, msiPath);
} else {
Log.Warn("Portable package not found, skipping MSI creation.");
}
}
@@ -391,6 +393,8 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
string conclusionMessage = GetFileContent(Options.InstConclusion);
string license = GetFileContent(Options.InstLicense);
bool hasLicense = !string.IsNullOrWhiteSpace(license);
string bannerImage = string.IsNullOrWhiteSpace(Options.MsiBanner) ? HelperFile.WixAssetsTopBanner : Options.MsiBanner;
string dialogImage = string.IsNullOrWhiteSpace(Options.MsiLogo) ? HelperFile.WixAssetsDialogBackground : Options.MsiLogo;
//Scope can be perMachine or perUser or perUserOrMachine, https://docs.firegiant.com/wix/schema/wxs/packagescopetype/
//For now just hard coding to perMachine
@@ -452,12 +456,12 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
<WixVariable
Id="WixUIBannerBmp"
Value="{HelperFile.WixAssetsTopBanner}"
Value="{bannerImage}"
/>
<WixVariable
Id="WixUIDialogBmp"
Value="{HelperFile.WixAssetsDialogBackground}"
Value="{dialogImage}"
/>
<!-- Message on last screen after install -->

View File

@@ -32,6 +32,9 @@ public class WindowsPackOptions : WindowsReleasifyOptions, INugetPackCommand, IP
public string InstConclusion { get; set; }
public string MsiBanner { get; set; }
public string MsiLogo { get; set; }
public bool BuildMsi { get; set; }
public bool BuildMsiDeploymentTool { get; set; }

View File

@@ -89,17 +89,16 @@ public class WindowsPackCommand : PackCommand
AddOption<bool>((v) => BuildMsiDeploymentTool = v, "--msiDeploymentTool")
.SetDescription("Compile a .msi machine-wide deployment tool.")
;//.SetHidden();
.SetHidden();
AddOption<string>((v) => MsiVersionOverride = v, "--msiDeploymentToolVersion")
.SetDescription("Override the product version for the generated msi.")
.SetArgumentHelpName("VERSION")
//.SetHidden()
.SetHidden()
.MustBeValidMsiVersion();
AddOption<bool>((v) => BuildMsi = v, "--msi")
.SetDescription("Compile a .msi machine-wide bootstrap package.")
;//.SetHidden();
.SetDescription("Compile a .msi machine-wide bootstrap package.");
AddOption<FileInfo>((v) => InstWelcome = v.ToFullNameOrNull(), "--instWelcome")
.SetDescription("Set the installer package welcome content.")