Skip to content

Commit f734b21

Browse files
zlonastMistuke
authored andcommitted
Add ReplaceFileW
1 parent f340d2c commit f734b21

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

System/Win32/File.hsc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ module System.Win32.File
190190
, removeDirectory
191191
, getBinaryType
192192
, getTempFileName
193+
, replaceFile
193194

194195
-- * HANDLE operations
195196
, createFile
@@ -419,6 +420,10 @@ getFileInformationByHandle h = alloca $ \res -> do
419420
failIfFalseWithRetry_ "GetFileInformationByHandle" $ c_GetFileInformationByHandle h res
420421
peek res
421422

423+
replaceFile :: LPCWSTR -> LPCWSTR -> LPCWSTR -> DWORD -> IO ()
424+
replaceFile replacedFile replacementFile backupFile replaceFlags =
425+
failIfFalse_ "ReplaceFile" $ c_ReplaceFile replacedFile replacementFile backupFile replaceFlags nullPtr nullPtr
426+
422427
----------------------------------------------------------------
423428
-- Read/write files
424429
----------------------------------------------------------------

System/Win32/File/Internal.hsc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ type BinaryType = DWORD
193193

194194
----------------------------------------------------------------
195195

196+
type ReplaceType = DWORD
197+
198+
#{enum ReplaceType,
199+
, rEPLACEFILE_WRITE_THROUGH = REPLACEFILE_WRITE_THROUGH
200+
, rEPLACEFILE_IGNORE_MERGE_ERRORS = REPLACEFILE_IGNORE_MERGE_ERRORS
201+
, rEPLACEFILE_IGNORE_ACL_ERRORS = REPLACEFILE_IGNORE_ACL_ERRORS
202+
}
203+
204+
----------------------------------------------------------------
205+
196206
type FileNotificationFlag = DWORD
197207

198208
#{enum FileNotificationFlag,
@@ -367,6 +377,9 @@ foreign import WINDOWS_CCONV unsafe "windows.h RemoveDirectoryW"
367377
foreign import WINDOWS_CCONV unsafe "windows.h GetBinaryTypeW"
368378
c_GetBinaryType :: LPCTSTR -> Ptr DWORD -> IO Bool
369379

380+
foreign import WINDOWS_CCONV unsafe "windows.h ReplaceFileW"
381+
c_ReplaceFile :: LPCWSTR -> LPCWSTR -> LPCWSTR -> DWORD -> LPVOID -> LPVOID -> IO Bool
382+
370383
----------------------------------------------------------------
371384
-- HANDLE operations
372385
----------------------------------------------------------------

System/Win32/WindowsString/File.hsc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module System.Win32.WindowsString.File
3535
, setVolumeLabel
3636
, getFileExInfoStandard
3737
, getFileExMaxInfoLevel
38+
, replaceFile
3839
, module System.Win32.File
3940
) where
4041

@@ -62,6 +63,7 @@ import System.Win32.File hiding (
6263
, setVolumeLabel
6364
, getFileExInfoStandard
6465
, getFileExMaxInfoLevel
66+
, replaceFile
6567
)
6668
import System.Win32.WindowsString.Types
6769
import System.OsString.Windows
@@ -180,7 +182,16 @@ getTempFileName dir prefix unique = allocaBytes ((#const MAX_PATH) * sizeOf (und
180182
fname <- peekTString c_buf
181183
pure (fname, uid)
182184

183-
185+
replaceFile :: WindowsString -> WindowsString -> Maybe WindowsString -> DWORD -> IO ()
186+
replaceFile replacedFile replacementFile mBackupFile replaceFlags =
187+
withFilePath replacedFile $ \ c_replacedFile ->
188+
withFilePath replacementFile $ \ c_replacementFile ->
189+
let getResult f =
190+
case mBackupFile of
191+
Nothing -> f nullPtr
192+
Just backupFile -> withFilePath backupFile f
193+
in getResult $ \ c_backupFile ->
194+
failIfFalse_ "ReplaceFile" $ c_ReplaceFile c_replacedFile c_replacementFile c_backupFile replaceFlags nullPtr nullPtr
184195

185196
----------------------------------------------------------------
186197
-- File Notifications

Win32.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.0
22
name: Win32
3-
version: 2.14.1.0
3+
version: 2.14.2.0
44
license: BSD3
55
license-file: LICENSE
66
author: Alastair Reid, shelarcy, Tamar Christina

0 commit comments

Comments
 (0)