This repository has been archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpub.rs
114 lines (92 loc) · 3.09 KB
/
pub.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use std::{
env,
fs,
path::{Path, PathBuf},
process::{self, Command},
};
fn main() {
let symb = Path::new("./pub.pdb");
if symb.exists() {
fs::remove_file(symb).unwrap();
}
let version = env::args().nth(1).unwrap_or_else(|| {
eprintln!("Please provide a version, e.g., ./pub.exe 3.0.0");
process::exit(1);
});
let bins = ["game-server", "sdk-server", "cfg-manager"];
for bin in &bins {
println!("Building {}.", bin);
let status = Command::new("cargo")
.args(["build", "--release", "--bin", bin])
.status()
.expect("Failed to start cargo build");
if !status.success() {
eprintln!("Failed to build {}", bin);
process::exit(1);
}
}
let target_dir = Path::new("target").join("release");
if !target_dir.exists() {
eprintln!("Target directory not found. Was the build successful?");
process::exit(1);
}
let exe_files: Vec<PathBuf> = bins
.iter()
.map(|bin| target_dir.join(format!("{}.exe", bin)))
.collect();
for exe in &exe_files {
if !exe.exists() {
eprintln!("{} not found.", exe.display());
process::exit(1);
}
}
let release_dir = Path::new("release");
if !release_dir.exists() {
println!("Release directory not found. Creating it.");
fs::create_dir(release_dir).expect("Failed to create release directory");
}
let new_dir = release_dir.join(format!("{}-Windows-X86_64", version));
if !new_dir.exists() {
println!("Creating directory: {}", new_dir.display());
fs::create_dir(&new_dir).expect("Failed to create new release directory");
}
println!("Copying .exe files.");
for exe in &exe_files {
let dest = new_dir.join(exe.file_name().unwrap());
fs::copy(exe, &dest).unwrap_or_else(|e| {
eprintln!("Failed to copy {}: {}", exe.display(), e);
process::exit(1);
});
}
let license_file = Path::new("LICENSE");
if license_file.exists() {
println!("Copying LICENSE file.");
fs::copy(license_file, new_dir.join("LICENSE")).expect("Failed to copy LICENSE file");
} else {
println!("LICENSE file not found.");
}
let cfg_dir = Path::new("_cfg");
if cfg_dir.exists() {
println!("Copying _cfg directory.");
copy_dir_recursive(cfg_dir, &new_dir.join("_cfg")).expect("Failed to copy _cfg directory");
} else {
println!("_cfg directory not found.");
}
println!("All files have been copied to {}", new_dir.display());
}
fn copy_dir_recursive(src: &Path, dest: &Path) -> std::io::Result<()> {
if !dest.exists() {
fs::create_dir(dest)?;
}
for entry in fs::read_dir(src)? {
let entry = entry?;
let entry_path = entry.path();
let dest_path = dest.join(entry.file_name());
if entry_path.is_dir() {
copy_dir_recursive(&entry_path, &dest_path)?;
} else {
fs::copy(&entry_path, &dest_path)?;
}
}
Ok(())
}