From be3b930fc9abcd8d1038542dc47a1d52bf8500dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sun, 18 Sep 2016 22:59:13 +0200
Subject: [PATCH] setupapi: Implement SP_COPY_IN_USE_NEEDS_REBOOT.

---
 dlls/setupapi/queue.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/dlls/setupapi/queue.c b/dlls/setupapi/queue.c
index 8dae62e..c82e4fa 100644
--- a/dlls/setupapi/queue.c
+++ b/dlls/setupapi/queue.c
@@ -1135,7 +1135,7 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style,
         }
     }
     if (style & (SP_COPY_NODECOMP | SP_COPY_LANGUAGEAWARE | SP_COPY_FORCE_IN_USE |
-                 SP_COPY_IN_USE_NEEDS_REBOOT | SP_COPY_NOSKIP | SP_COPY_WARNIFSKIP))
+                 SP_COPY_NOSKIP | SP_COPY_WARNIFSKIP))
     {
         ERR("Unsupported style(s) 0x%x\n",style);
     }
@@ -1144,6 +1144,24 @@ static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style,
     {
         rc = CopyFileW(source,target,FALSE);
         TRACE("Did copy... rc was %i\n",rc);
+
+        if (!rc && GetLastError() == ERROR_SHARING_VIOLATION &&
+            (style & SP_COPY_IN_USE_NEEDS_REBOOT))
+        {
+            static const WCHAR prefixW[] = {'S','E','T',0};
+            WCHAR temp_file[MAX_PATH];
+            WCHAR temp[MAX_PATH];
+
+            if (GetTempPathW(MAX_PATH, temp) &&
+                GetTempFileNameW(temp, prefixW, 0, temp_file))
+            {
+                rc = CopyFileW(source, temp_file, FALSE);
+                if (rc)
+                    rc = MoveFileExW(temp_file, target, MOVEFILE_DELAY_UNTIL_REBOOT);
+                else
+                    DeleteFileW(temp_file);
+            }
+        }
     }
     else
         SetLastError(ERROR_SUCCESS);
-- 
1.9.1

