-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbuild.rs
More file actions
105 lines (93 loc) · 3.18 KB
/
build.rs
File metadata and controls
105 lines (93 loc) · 3.18 KB
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
use devolutions_pedm_shared::build::target_dir;
use fs_extra::dir::CopyOptions;
use std::error::Error;
use std::path::PathBuf;
use std::{env, fs};
#[cfg(target_os = "windows")]
fn generate_version_rc() -> String {
let output_name = "DevolutionsPedmShellExt";
let filename = format!("{}.dll", output_name);
let company_name = "Devolutions Inc.";
let legal_copyright = format!("Copyright 2020-2024 {}", company_name);
let version_number = env::var("CARGO_PKG_VERSION").unwrap() + ".0";
let version_commas = version_number.replace('.', ",");
let file_description = output_name;
let file_version = version_number.clone();
let internal_name = filename.clone();
let original_filename = filename;
let product_name = output_name;
let product_version = version_number;
let vs_file_version = version_commas.clone();
let vs_product_version = version_commas;
let version_rc = format!(
r#"#include <winresrc.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION {vs_file_version}
PRODUCTVERSION {vs_product_version}
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "{company_name}"
VALUE "FileDescription", "{file_description}"
VALUE "FileVersion", "{file_version}"
VALUE "InternalName", "{internal_name}"
VALUE "LegalCopyright", "{legal_copyright}"
VALUE "OriginalFilename", "{original_filename}"
VALUE "ProductName", "{product_name}"
VALUE "ProductVersion", "{product_version}"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END"#,
vs_file_version = vs_file_version,
vs_product_version = vs_product_version,
company_name = company_name,
file_description = file_description,
file_version = file_version,
internal_name = internal_name,
legal_copyright = legal_copyright,
original_filename = original_filename,
product_name = product_name,
product_version = product_version
);
version_rc
}
#[cfg(target_os = "windows")]
fn main() -> Result<(), Box<dyn Error>> {
let target = target_dir()?;
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let options = CopyOptions {
overwrite: true,
copy_inside: true,
..Default::default()
};
fs_extra::dir::copy(crate_dir.join("Assets"), &target, &options)?;
fs::copy(crate_dir.join("AppxManifest.xml"), target.join("AppxManifest.xml"))?;
let out_dir = env::var("OUT_DIR").unwrap();
let version_rc_file = format!("{}/version.rc", out_dir);
let version_rc_data = generate_version_rc();
fs::write(&version_rc_file, version_rc_data).unwrap();
embed_resource::compile(&version_rc_file, embed_resource::NONE)
.manifest_required()
.unwrap();
embed_resource::compile("resources.rc", embed_resource::NONE)
.manifest_required()
.unwrap();
Ok(())
}
#[cfg(not(target_os = "windows"))]
fn main() {}