修改版本号配置,默认不显示控制台

This commit is contained in:
zqm
2026-05-06 15:29:36 +08:00
parent d1fae575f3
commit 0ee65e58fb
2 changed files with 18 additions and 10 deletions

View File

@@ -3,13 +3,23 @@ use winresource::VersionInfo;
extern crate winresource;
fn main() {
let version_str = "1.0.0.2";
let mut res = winresource::WindowsResource::new();
// 字符串表(文件属性对话框显示的值)
res.set("FileVersion", "1.0.0.1");
res.set("ProductVersion", "1.0.0.1");
res.set("FileVersion", version_str);
res.set("ProductVersion", version_str);
// 从字符串自动解析版本号到二进制结构
let mut parts = version_str.split('.');
let major: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let minor: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let patch: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
let pre: u64 = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0);
// 二进制结构VERSIONINFO 的 FILEVERSION / PRODUCTVERSION
// 格式: Major<<48 | Minor<<32 | Patch<<16 | Pre
let ver: u64 = (1u64 << 48) | (0 << 32) | (0 << 16) | 1;
let ver: u64 = (major << 48) | (minor << 32) | (patch << 16) | pre;
res.set_version_info(VersionInfo::FILEVERSION, ver);
res.set_version_info(VersionInfo::PRODUCTVERSION, ver);
res.compile().unwrap();

View File

@@ -1,3 +1,5 @@
#![windows_subsystem = "windows"]
use rand::Rng;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};
@@ -2708,17 +2710,13 @@ async fn main() {
// 加载 Updater 自身配置debug_mode
let config = load_updater_config();
// debug 模式下释放控制台,后台静默运行
if !config.debug_mode {
// debug 模式下分配控制台窗口
if config.debug_mode {
#[cfg(windows)]
{
use windows::Win32::System::Console;
use windows::Win32::Foundation::HWND;
unsafe {
let console = Console::GetConsoleWindow();
if console != HWND::default() {
let _ = Console::FreeConsole();
}
let _ = Console::AllocConsole();
}
}
}