fix_virtual_display_path: fix wchar* path
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
c269d1c831
commit
e1bb25c70e
@ -2,7 +2,7 @@
|
|||||||
use virtual_display::win10::{idd, DRIVER_INSTALL_PATH};
|
use virtual_display::win10::{idd, DRIVER_INSTALL_PATH};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
ffi::{CStr, CString},
|
ffi::CStr,
|
||||||
io::{self, Read},
|
io::{self, Read},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
@ -59,19 +59,27 @@ unsafe fn plug_out(index: idd::UINT) {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let abs_path = Path::new(DRIVER_INSTALL_PATH).canonicalize().unwrap();
|
let abs_path = Path::new(DRIVER_INSTALL_PATH).canonicalize().unwrap();
|
||||||
let full_inf_path = abs_path.to_str().unwrap();
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let invalid_device = 0 as idd::HSWDEVICE;
|
let invalid_device = 0 as idd::HSWDEVICE;
|
||||||
let mut h_sw_device = invalid_device;
|
let mut h_sw_device = invalid_device;
|
||||||
let full_inf_path = CString::new(full_inf_path).unwrap().into_raw();
|
|
||||||
|
let full_inf_path: Vec<u16> = abs_path
|
||||||
|
.to_string_lossy()
|
||||||
|
.as_ref()
|
||||||
|
.encode_utf16()
|
||||||
|
.chain(Some(0).into_iter())
|
||||||
|
.collect();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match prompt_input() as char {
|
match prompt_input() as char {
|
||||||
'x' => break,
|
'x' => break,
|
||||||
'i' => {
|
'i' => {
|
||||||
println!("Install or update driver begin");
|
println!("Install or update driver begin, {}", abs_path.display());
|
||||||
let mut reboot_required = idd::FALSE;
|
let mut reboot_required = idd::FALSE;
|
||||||
if idd::InstallUpdate(full_inf_path, &mut reboot_required) == idd::FALSE {
|
if idd::InstallUpdate(full_inf_path.as_ptr() as _, &mut reboot_required)
|
||||||
|
== idd::FALSE
|
||||||
|
{
|
||||||
println!("{}", CStr::from_ptr(idd::GetLastMsg()).to_str().unwrap());
|
println!("{}", CStr::from_ptr(idd::GetLastMsg()).to_str().unwrap());
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
@ -85,9 +93,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
'u' => {
|
'u' => {
|
||||||
println!("Uninstall driver begin");
|
println!("Uninstall driver begin {}", abs_path.display());
|
||||||
let mut reboot_required = idd::FALSE;
|
let mut reboot_required = idd::FALSE;
|
||||||
if idd::Uninstall(full_inf_path, &mut reboot_required) == idd::FALSE {
|
if idd::Uninstall(full_inf_path.as_ptr() as _, &mut reboot_required)
|
||||||
|
== idd::FALSE
|
||||||
|
{
|
||||||
println!("{}", CStr::from_ptr(idd::GetLastMsg()).to_str().unwrap());
|
println!("{}", CStr::from_ptr(idd::GetLastMsg()).to_str().unwrap());
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
@ -129,9 +139,6 @@ fn main() {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !full_inf_path.is_null() {
|
|
||||||
let _ = CString::from_raw(full_inf_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
idd::DeviceClose(h_sw_device);
|
idd::DeviceClose(h_sw_device);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
pub mod win10;
|
pub mod win10;
|
||||||
|
|
||||||
use hbb_common::{bail, lazy_static, ResultType};
|
use hbb_common::{bail, lazy_static, ResultType};
|
||||||
use std::{ffi::CString, path::Path, sync::Mutex};
|
use std::{path::Path, sync::Mutex};
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
// If device is uninstalled though "Device Manager" Window.
|
// If device is uninstalled though "Device Manager" Window.
|
||||||
@ -33,16 +33,24 @@ pub fn install_update_driver(_reboot_required: &mut bool) -> ResultType<()> {
|
|||||||
bail!("{} not exists", install_path)
|
bail!("{} not exists", install_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
let _full_install_path = match abs_path.to_str() {
|
|
||||||
Some(p) => CString::new(p)?.into_raw(),
|
|
||||||
None => bail!("{} not exists", install_path),
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
{
|
{
|
||||||
|
// Device must be created before install driver.
|
||||||
|
// https://github.com/fufesou/RustDeskIddDriver/issues/1
|
||||||
|
if let Err(e) = create_device() {
|
||||||
|
bail!("{}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
let full_install_path: Vec<u16> = abs_path
|
||||||
|
.to_string_lossy()
|
||||||
|
.as_ref()
|
||||||
|
.encode_utf16()
|
||||||
|
.chain(Some(0).into_iter())
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut reboot_required_tmp = win10::idd::FALSE;
|
let mut reboot_required_tmp = win10::idd::FALSE;
|
||||||
if win10::idd::InstallUpdate(_full_install_path, &mut reboot_required_tmp)
|
if win10::idd::InstallUpdate(full_install_path.as_ptr() as _, &mut reboot_required_tmp)
|
||||||
== win10::idd::FALSE
|
== win10::idd::FALSE
|
||||||
{
|
{
|
||||||
bail!("{}", win10::get_last_msg()?);
|
bail!("{}", win10::get_last_msg()?);
|
||||||
@ -65,16 +73,18 @@ pub fn uninstall_driver(_reboot_required: &mut bool) -> ResultType<()> {
|
|||||||
bail!("{} not exists", install_path)
|
bail!("{} not exists", install_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
let _full_install_path = match abs_path.to_str() {
|
|
||||||
Some(p) => CString::new(p)?.into_raw(),
|
|
||||||
None => bail!("{} not exists", install_path),
|
|
||||||
};
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
{
|
{
|
||||||
|
let full_install_path: Vec<u16> = abs_path
|
||||||
|
.to_string_lossy()
|
||||||
|
.as_ref()
|
||||||
|
.encode_utf16()
|
||||||
|
.chain(Some(0).into_iter())
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut reboot_required_tmp = win10::idd::FALSE;
|
let mut reboot_required_tmp = win10::idd::FALSE;
|
||||||
if win10::idd::Uninstall(_full_install_path, &mut reboot_required_tmp)
|
if win10::idd::Uninstall(full_install_path.as_ptr() as _, &mut reboot_required_tmp)
|
||||||
== win10::idd::FALSE
|
== win10::idd::FALSE
|
||||||
{
|
{
|
||||||
bail!("{}", win10::get_last_msg()?);
|
bail!("{}", win10::get_last_msg()?);
|
||||||
|
@ -64,14 +64,14 @@ const char* GetLastMsg()
|
|||||||
return g_lastMsg;
|
return g_lastMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL InstallUpdate(LPCTSTR fullInfPath, PBOOL rebootRequired)
|
BOOL InstallUpdate(LPCWSTR fullInfPath, PBOOL rebootRequired)
|
||||||
{
|
{
|
||||||
SetLastMsg("Sucess");
|
SetLastMsg("Sucess");
|
||||||
|
|
||||||
// UpdateDriverForPlugAndPlayDevices may return FALSE while driver was successfully installed...
|
// UpdateDriverForPlugAndPlayDevicesW may return FALSE while driver was successfully installed...
|
||||||
if (FALSE == UpdateDriverForPlugAndPlayDevices(
|
if (FALSE == UpdateDriverForPlugAndPlayDevicesW(
|
||||||
NULL,
|
NULL,
|
||||||
_T("RustDeskIddDriver"), // match hardware id in the inf file
|
L"RustDeskIddDriver", // match hardware id in the inf file
|
||||||
fullInfPath,
|
fullInfPath,
|
||||||
INSTALLFLAG_FORCE
|
INSTALLFLAG_FORCE
|
||||||
// | INSTALLFLAG_NONINTERACTIVE // INSTALLFLAG_NONINTERACTIVE may cause error 0xe0000247
|
// | INSTALLFLAG_NONINTERACTIVE // INSTALLFLAG_NONINTERACTIVE may cause error 0xe0000247
|
||||||
@ -82,7 +82,7 @@ BOOL InstallUpdate(LPCTSTR fullInfPath, PBOOL rebootRequired)
|
|||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
SetLastMsg("UpdateDriverForPlugAndPlayDevices failed, last error 0x%x\n", error);
|
SetLastMsg("UpdateDriverForPlugAndPlayDevicesW failed, last error 0x%x\n", error);
|
||||||
if (g_printMsg)
|
if (g_printMsg)
|
||||||
{
|
{
|
||||||
printf(g_lastMsg);
|
printf(g_lastMsg);
|
||||||
@ -94,11 +94,11 @@ BOOL InstallUpdate(LPCTSTR fullInfPath, PBOOL rebootRequired)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL Uninstall(LPCTSTR fullInfPath, PBOOL rebootRequired)
|
BOOL Uninstall(LPCWSTR fullInfPath, PBOOL rebootRequired)
|
||||||
{
|
{
|
||||||
SetLastMsg("Sucess");
|
SetLastMsg("Sucess");
|
||||||
|
|
||||||
if (FALSE == DiUninstallDriver(
|
if (FALSE == DiUninstallDriverW(
|
||||||
NULL,
|
NULL,
|
||||||
fullInfPath,
|
fullInfPath,
|
||||||
0,
|
0,
|
||||||
@ -108,7 +108,7 @@ BOOL Uninstall(LPCTSTR fullInfPath, PBOOL rebootRequired)
|
|||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
SetLastMsg("DiUninstallDriver failed, last error 0x%x\n", error);
|
SetLastMsg("DiUninstallDriverW failed, last error 0x%x\n", error);
|
||||||
if (g_printMsg)
|
if (g_printMsg)
|
||||||
{
|
{
|
||||||
printf(g_lastMsg);
|
printf(g_lastMsg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user