aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/windows.rs')
-rw-r--r--src/platform/windows.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/platform/windows.rs b/src/platform/windows.rs
index 413119ed..e63b8920 100644
--- a/src/platform/windows.rs
+++ b/src/platform/windows.rs
@@ -15,6 +15,39 @@ use std::{
mod clipboard_image;
+pub(crate) fn replace_file(
+ source: &std::path::Path,
+ destination: &std::path::Path,
+) -> std::io::Result<()> {
+ use std::os::windows::ffi::OsStrExt;
+ use windows_sys::Win32::Storage::FileSystem::{
+ MoveFileExW, MOVEFILE_REPLACE_EXISTING, MOVEFILE_WRITE_THROUGH,
+ };
+
+ let source = source
+ .as_os_str()
+ .encode_wide()
+ .chain(std::iter::once(0))
+ .collect::<Vec<_>>();
+ let destination = destination
+ .as_os_str()
+ .encode_wide()
+ .chain(std::iter::once(0))
+ .collect::<Vec<_>>();
+ let moved = unsafe {
+ MoveFileExW(
+ source.as_ptr(),
+ destination.as_ptr(),
+ MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH,
+ )
+ };
+ if moved == 0 {
+ Err(std::io::Error::last_os_error())
+ } else {
+ Ok(())
+ }
+}
+
pub(crate) fn set_default_plugin_pane_pwd(
_env: &mut Vec<(String, String)>,
_cwd: &std::path::Path,