Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 139 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions framework_tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ path = "../framework_lib"
[build-dependencies]
# Note: Only takes effect in release builds
static_vcruntime = "2.0"
embed-resource = "3.0"
winresource = "0.1.17"

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.9"
features = [
"wincon"
]
18 changes: 17 additions & 1 deletion framework_tool/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
fn main() {
static_vcruntime::metabuild();
// Add app icon
if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
winresource::WindowsResource::new()
.set_icon("..\\res\\framework_startmenuicon.ico")
.compile()
.unwrap();
}

if !cfg!(debug_assertions) {
// Statically link vcruntime to allow running on clean install
static_vcruntime::metabuild();

// Embed resources file to force running as admin
embed_resource::compile("framework_tool-manifest.rc", embed_resource::NONE)
.manifest_optional()
.unwrap();
}
}
2 changes: 2 additions & 0 deletions framework_tool/framework_tool-manifest.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define RT_MANIFEST 24
1 RT_MANIFEST "framework_tool.exe.manifest"
10 changes: 10 additions & 0 deletions framework_tool/framework_tool.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
42 changes: 41 additions & 1 deletion framework_tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,49 @@ fn get_args() -> Vec<String> {
}

fn main() -> Result<(), &'static str> {
let args = commandline::parse(&get_args());
let args = get_args();

// If the user double-clicks (opens from explorer/desktop),
// then we want to have the default behavior of showing a report of
// all firmware versions.
#[cfg(windows)]
let (args, double_clicked) = {
let double_clicked = unsafe {
// See https://devblogs.microsoft.com/oldnewthing/20160125-00/?p=92922
let mut plist: winapi::shared::minwindef::DWORD = 0;
let processes = winapi::um::wincon::GetConsoleProcessList(&mut plist, 1);

// If we're the only process that means we're in a fresh terminal
// without CMD or powershell. This happens in some cases, for example
// if the user double-clicks the app from Explorer.
processes == 1
};
// But it also happens if launched from the commandline and a UAC prompt is necessary,
// for example with sudo set to open "In a new windows", therefore we also have to
// check that no commandline arguments were provided.
if double_clicked && args.len() == 1 {
(
vec![args[0].clone(), "--versions".to_string()],
double_clicked,
)
} else {
(args, double_clicked)
}
};

let args = commandline::parse(&args);
if (commandline::run_with_args(&args, false)) != 0 {
return Err("Fail");
}

// Prevent command prompt from auto closing
#[cfg(windows)]
if double_clicked {
println!();
println!("Press ENTER to exit...");
let mut line = String::new();
let _ = std::io::stdin().read_line(&mut line).unwrap();
}

Ok(())
}
Binary file added res/framework_startmenuicon.ico
Binary file not shown.
Loading