Browse Source

libobs/util: Use MoveFileEx with MOVEFILE_REPLACE_EXISTING

Ensures that it will replace an old file if it exists.
jp9000 8 years ago
parent
commit
2537f9a5e2
1 changed files with 4 additions and 2 deletions
  1. 4 2
      libobs/util/platform-windows.c

+ 4 - 2
libobs/util/platform-windows.c

@@ -549,7 +549,8 @@ int os_rename(const char *old_path, const char *new_path)
 		goto error;
 	}
 
-	code = MoveFileW(old_path_utf16, new_path_utf16) ? 0 : -1;
+	code = MoveFileExW(old_path_utf16, new_path_utf16,
+			MOVEFILE_REPLACE_EXISTING) ? 0 : -1;
 
 error:
 	bfree(old_path_utf16);
@@ -576,7 +577,8 @@ int os_safe_replace(const char *target, const char *from, const char *backup)
 	if (ReplaceFileW(wtarget, wfrom, wbackup, 0, NULL, NULL)) {
 		code = 0;
 	} else if (GetLastError() == ERROR_FILE_NOT_FOUND) {
-		code = MoveFile(wfrom, wtarget) ? 0 : -1;
+		code = MoveFileExW(wfrom, wtarget, MOVEFILE_REPLACE_EXISTING)
+			? 0 : -1;
 	}
 
 fail: