Files
JoyD/Windows/CS/Framework4.0/Updater/src/main.rs

64 lines
1.6 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use tokio::time;
#[derive(Debug, Serialize, Deserialize)]
struct Config {
debug_mode: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
debug_mode: false,
}
}
}
fn get_config_path() -> PathBuf {
let exe_path = std::env::current_exe().expect("Failed to get executable path");
let drive = exe_path.parent().unwrap().parent().unwrap();
let appdata = drive.join("AppData").join("Updater");
fs::create_dir_all(&appdata).expect("Failed to create config directory");
appdata.join("config.json")
}
fn load_config() -> Config {
let config_path = get_config_path();
if config_path.exists() {
let content = fs::read_to_string(&config_path).expect("Failed to read config file");
serde_json::from_str(&content).expect("Failed to parse config file")
} else {
let default_config = Config::default();
let content = serde_json::to_string_pretty(&default_config).expect("Failed to serialize config");
fs::write(&config_path, content).expect("Failed to write config file");
default_config
}
}
async fn upgrade() {
println!("开始升级");
}
#[tokio::main]
async fn main() {
let config = load_config();
if !config.debug_mode {
#[cfg(windows)]
{
use windows::Win32::System::Console;
unsafe {
let _ = Console::FreeConsole();
}
}
}
let mut interval = time::interval(time::Duration::from_secs(300));
loop {
interval.tick().await;
upgrade().await;
}
}