|
| 1 | +// Copyright 2019-2024 Tauri Programme within The Commons Conservancy |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +use anyhow::Result; |
| 6 | +use clap::{Parser, Subcommand}; |
| 7 | + |
| 8 | +use crate::interface::{AppInterface, AppSettings, Interface}; |
| 9 | + |
| 10 | +#[derive(Debug, Parser)] |
| 11 | +#[clap(about = "Manage or create permissions for your app or plugin")] |
| 12 | +pub struct Cli { |
| 13 | + #[clap(subcommand)] |
| 14 | + command: Commands, |
| 15 | +} |
| 16 | + |
| 17 | +#[derive(Subcommand, Debug)] |
| 18 | +enum Commands { |
| 19 | + /// Print the default Upgrade Code used by MSI installer derived from productName. |
| 20 | + WixUpgradeCode, |
| 21 | +} |
| 22 | + |
| 23 | +pub fn command(cli: Cli) -> Result<()> { |
| 24 | + match cli.command { |
| 25 | + Commands::WixUpgradeCode => wix_upgrade_code(), |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +// NOTE: if this is ever changed, make sure to also update Wix upgrade code generation in tauri-bundler |
| 30 | +fn wix_upgrade_code() -> Result<()> { |
| 31 | + crate::helpers::app_paths::resolve(); |
| 32 | + |
| 33 | + let target = tauri_utils::platform::Target::Windows; |
| 34 | + let config = crate::helpers::config::get(target, None)?; |
| 35 | + |
| 36 | + let interface = AppInterface::new(config.lock().unwrap().as_ref().unwrap(), None)?; |
| 37 | + |
| 38 | + let product_name = interface.app_settings().get_package_settings().product_name; |
| 39 | + |
| 40 | + let upgrade_code = uuid::Uuid::new_v5( |
| 41 | + &uuid::Uuid::NAMESPACE_DNS, |
| 42 | + format!("{product_name}.exe.app.x64").as_bytes(), |
| 43 | + ) |
| 44 | + .to_string(); |
| 45 | + |
| 46 | + log::info!("Default WiX Upgrade Code, derived from {product_name}: {upgrade_code}"); |
| 47 | + if let Some(code) = config.lock().unwrap().as_ref().and_then(|c| { |
| 48 | + c.bundle |
| 49 | + .windows |
| 50 | + .wix |
| 51 | + .as_ref() |
| 52 | + .and_then(|wix| wix.upgrade_code) |
| 53 | + }) { |
| 54 | + log::info!("Application Upgrade Code override: {code}"); |
| 55 | + } |
| 56 | + |
| 57 | + Ok(()) |
| 58 | +} |
0 commit comments