mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-26 03:05:42 +01:00
fix(tasks): fix multiple logic issues under Windows
This commit is contained in:
parent
d6cb916a9c
commit
3727e4185b
@ -168,3 +168,15 @@ extern "C" HRESULT getSystemFolder(wchar_t *out_path)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" HRESULT getDesktopFolder(wchar_t *out_path)
|
||||
{
|
||||
PWSTR path = NULL;
|
||||
HRESULT result = SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &path);
|
||||
if (result == S_OK)
|
||||
{
|
||||
wcscpy_s(out_path, MAX_PATH + 1, path);
|
||||
CoTaskMemFree(path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -60,6 +60,8 @@ mod natives {
|
||||
) -> ::std::os::raw::c_int;
|
||||
|
||||
pub fn getSystemFolder(out_path: *mut ::std::os::raw::c_ushort) -> HRESULT;
|
||||
|
||||
pub fn getDesktopFolder(out_path: *mut ::std::os::raw::c_ushort) -> HRESULT;
|
||||
}
|
||||
|
||||
pub fn prepare_install_webview2(name: &str) -> Result<(), String> {
|
||||
@ -116,6 +118,34 @@ mod natives {
|
||||
)
|
||||
}
|
||||
|
||||
// Needed here for Windows interop
|
||||
#[allow(unsafe_code)]
|
||||
pub fn create_desktop_shortcut(
|
||||
name: &str,
|
||||
description: &str,
|
||||
target: &str,
|
||||
args: &str,
|
||||
working_dir: &str,
|
||||
exe_path: &str,
|
||||
) -> Result<String, String> {
|
||||
let mut cmd_path = [0u16; MAX_PATH + 1];
|
||||
let _result = unsafe { getDesktopFolder(cmd_path.as_mut_ptr()) };
|
||||
let source_path = format!(
|
||||
"{}\\{}.lnk",
|
||||
String::from_utf16_lossy(&cmd_path[..count_u16(&cmd_path)]).as_str(),
|
||||
name
|
||||
);
|
||||
create_shortcut_inner(
|
||||
source_path,
|
||||
name,
|
||||
description,
|
||||
target,
|
||||
args,
|
||||
working_dir,
|
||||
exe_path,
|
||||
)
|
||||
}
|
||||
|
||||
// Needed here for Windows interop
|
||||
#[allow(unsafe_code)]
|
||||
fn create_shortcut_inner(
|
||||
@ -181,6 +211,18 @@ mod natives {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn count_u16(u16str: &[u16]) -> usize {
|
||||
let mut pos = 0;
|
||||
for x in u16str.iter() {
|
||||
if *x == 0 {
|
||||
break;
|
||||
}
|
||||
pos += 1;
|
||||
}
|
||||
pos
|
||||
}
|
||||
|
||||
/// Cleans up the installer
|
||||
pub fn burn_on_exit(app_name: &str) {
|
||||
let current_exe = env::current_exe().log_expect("Current executable could not be found");
|
||||
@ -194,6 +236,7 @@ mod natives {
|
||||
.to_str()
|
||||
.log_expect("Unable to convert tool path to string")
|
||||
.replace(" ", "\\ ");
|
||||
let tool_wv = format!("{}.WebView2", tool);
|
||||
|
||||
let log = path.join(format!("{}_installer.log", app_name));
|
||||
let log = log
|
||||
@ -207,8 +250,8 @@ mod natives {
|
||||
.replace(" ", "\\ ");
|
||||
|
||||
let target_arguments = format!(
|
||||
"/C choice /C Y /N /D Y /T 2 & del {} {} & rmdir {}",
|
||||
tool, log, install_path
|
||||
"/C choice /C Y /N /D Y /T 2 & del {} {} & rmdir /Q /S {} & rmdir {}",
|
||||
tool, log, tool_wv, install_path
|
||||
);
|
||||
|
||||
info!("Launching cmd with {:?}", target_arguments);
|
||||
|
@ -11,7 +11,7 @@ use crate::config::PackageDescription;
|
||||
|
||||
use crate::logging::LoggingErrors;
|
||||
|
||||
use crate::native::create_shortcut;
|
||||
use crate::native::create_desktop_shortcut;
|
||||
|
||||
pub struct InstallDesktopShortcutTask {
|
||||
pub name: String,
|
||||
@ -84,7 +84,7 @@ impl Task for InstallDesktopShortcutTask {
|
||||
.to_str()
|
||||
.log_expect("Unable to build shortcut metadata (exe)");
|
||||
|
||||
installed_files.push(create_shortcut(
|
||||
installed_files.push(create_desktop_shortcut(
|
||||
&shortcut.name,
|
||||
&shortcut.description,
|
||||
tool_path,
|
||||
|
@ -61,7 +61,7 @@ impl Task for InstallGlobalShortcutsTask {
|
||||
"",
|
||||
)?;
|
||||
|
||||
if !shortcut_file.is_empty() {
|
||||
if !shortcut_file.is_empty() && !context.database.shortcuts.contains(&shortcut_file) {
|
||||
context.database.shortcuts.push(shortcut_file);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
use crate::installer::InstallerFramework;
|
||||
|
||||
use crate::tasks::download_pkg::DownloadPackageTask;
|
||||
use crate::tasks::install_global_shortcut::InstallGlobalShortcutsTask;
|
||||
use crate::tasks::install_shortcuts::InstallShortcutsTask;
|
||||
use crate::tasks::save_database::SaveDatabaseTask;
|
||||
use crate::tasks::uninstall_pkg::UninstallPackageTask;
|
||||
use crate::tasks::Task;
|
||||
@ -196,7 +196,12 @@ impl Task for InstallPackageTask {
|
||||
optional: true,
|
||||
}),
|
||||
),
|
||||
TaskDependency::build(TaskOrdering::Post, Box::new(InstallGlobalShortcutsTask {})),
|
||||
TaskDependency::build(
|
||||
TaskOrdering::Post,
|
||||
Box::new(InstallShortcutsTask {
|
||||
name: self.name.clone(),
|
||||
}),
|
||||
),
|
||||
TaskDependency::build(
|
||||
TaskOrdering::Post,
|
||||
Box::new(InstallDesktopShortcutTask {
|
||||
|
Loading…
Reference in New Issue
Block a user