Move static keyword to the right place
[reactos.git] / reactos / lib / setupapi / queue.c
index d757868..6a66aa2 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "config.h"
-#include "wine/port.h"
-
-#include <stdarg.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "winreg.h"
-#include "winternl.h"
-#include "winerror.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winnls.h"
-#include "setupapi.h"
-#include "wine/unicode.h"
 #include "setupapi_private.h"
-#include "winver.h"
-#include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
 
@@ -176,7 +159,7 @@ static void concat_W( WCHAR *buffer, const WCHAR *src1, const WCHAR *src2, const
  */
 static BOOL build_filepathsW( const struct file_op *op, FILEPATHS_W *paths )
 {
-    int src_len = 1, dst_len = 1;
+    unsigned int src_len = 1, dst_len = 1;
     WCHAR *source = (PWSTR)paths->Source, *target = (PWSTR)paths->Target;
 
     if (op->src_root) src_len += strlenW(op->src_root) + 1;
@@ -249,6 +232,22 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification,
             MultiByteToWideChar( CP_ACP, 0, buffer, -1, (WCHAR *)old_param2, MAX_PATH );
         break;
 
+    case SPFILENOTIFY_STARTREGISTRATION:
+    case SPFILENOTIFY_ENDREGISTRATION:
+        {
+            SP_REGISTER_CONTROL_STATUSW *statusW = (SP_REGISTER_CONTROL_STATUSW *)param1;
+            SP_REGISTER_CONTROL_STATUSA statusA;
+
+            statusA.cbSize = sizeof(statusA);
+            statusA.FileName = strdupWtoA( statusW->FileName );
+            statusA.Win32Error  = statusW->Win32Error;
+            statusA.FailureCode = statusW->FailureCode;
+            ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification,
+                                              (UINT_PTR)&statusA, param2 );
+            HeapFree( GetProcessHeap(), 0, (LPSTR)statusA.FileName );
+        }
+        break;
+
     case SPFILENOTIFY_NEEDMEDIA:
     case SPFILENOTIFY_QUEUESCAN:
         FIXME("mapping for %d not implemented\n",notification);
@@ -260,7 +259,7 @@ UINT CALLBACK QUEUE_callback_WtoA( void *context, UINT notification,
         ret = callback_ctx->orig_handler( callback_ctx->orig_context, notification, param1, param2 );
         break;
     }
-        return ret;
+    return ret;
 }
 
 
@@ -351,25 +350,11 @@ static WCHAR *get_destination_dir( HINF hinf, const WCHAR *section )
 {
     static const WCHAR Dest[] = {'D','e','s','t','i','n','a','t','i','o','n','D','i','r','s',0};
     static const WCHAR Def[]  = {'D','e','f','a','u','l','t','D','e','s','t','D','i','r',0};
-
-    const WCHAR *dir;
-    WCHAR *ptr, *ret;
     INFCONTEXT context;
-    INT dirid;
-    DWORD len1, len2;
 
     if (!SetupFindFirstLineW( hinf, Dest, section, &context ) &&
         !SetupFindFirstLineW( hinf, Dest, Def, &context )) return NULL;
-    if (!SetupGetIntField( &context, 1, &dirid )) return NULL;
-    if (!(dir = DIRID_get_string( hinf, dirid ))) return NULL;
-    len1 = strlenW(dir) + 1;
-    if (!SetupGetStringFieldW( &context, 2, NULL, 0, &len2 )) len2 = 0;
-    if (!(ret = HeapAlloc( GetProcessHeap(), 0, (len1+len2) * sizeof(WCHAR) ))) return NULL;
-    strcpyW( ret, dir );
-    ptr = ret + strlenW(ret);
-    if (len2 && ptr > ret && ptr[-1] != '\\') *ptr++ = '\\';
-    if (!SetupGetStringFieldW( &context, 2, ptr, len2, NULL )) *ptr = 0;
-    return ret;
+    return PARSER_get_dest_dir( &context );
 }
 
 
@@ -768,6 +753,7 @@ BOOL WINAPI SetupQueueCopySectionW( HSPFILEQ queue, PCWSTR src_root, HINF hinf,
     params.SecurityDescriptor = NULL;
 
     if (!hlist) hlist = hinf;
+    if (!hinf) hinf = hlist;
     if (!SetupFindFirstLineW( hlist, section, NULL, &context )) return FALSE;
     if (!(params.TargetDirectory = get_destination_dir( hinf, section ))) return FALSE;
     do
@@ -947,7 +933,7 @@ static BOOL create_full_pathW(const WCHAR *path)
     return ret;
 }
 
-BOOL static do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style)
+static BOOL do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style)
 {
     BOOL rc = FALSE;
     BOOL docopy = TRUE;
@@ -979,8 +965,8 @@ BOOL static do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style)
         if ((GetFileAttributesW(target) != INVALID_FILE_ATTRIBUTES) &&
             (GetFileAttributesW(source) != INVALID_FILE_ATTRIBUTES))
         {
-            VersionSizeSource = GetFileVersionInfoSizeW(source,&zero);
-            VersionSizeTarget = GetFileVersionInfoSizeW(target,&zero);
+            VersionSizeSource = GetFileVersionInfoSizeW((LPWSTR)source,&zero);
+            VersionSizeTarget = GetFileVersionInfoSizeW((LPWSTR)target,&zero);
         }
 
         TRACE("SizeTarget %li ... SizeSource %li\n",VersionSizeTarget,
@@ -992,16 +978,16 @@ BOOL static do_file_copyW( LPCWSTR source, LPCWSTR target, DWORD style)
             LPVOID VersionTarget;
             VS_FIXEDFILEINFO *TargetInfo;
             VS_FIXEDFILEINFO *SourceInfo;
-            INT length;
+            UINT length;
             WCHAR  SubBlock[2]={'\\',0};
             DWORD  ret;
 
             VersionSource = HeapAlloc(GetProcessHeap(),0,VersionSizeSource);
             VersionTarget = HeapAlloc(GetProcessHeap(),0,VersionSizeTarget);
 
-            ret = GetFileVersionInfoW(source,0,VersionSizeSource,VersionSource);
+            ret = GetFileVersionInfoW((LPWSTR)source,0,VersionSizeSource,VersionSource);
             if (ret)
-              ret = GetFileVersionInfoW(target, 0, VersionSizeTarget,
+              ret = GetFileVersionInfoW((LPWSTR)target, 0, VersionSizeTarget,
                     VersionTarget);
 
             if (ret)
@@ -1267,6 +1253,26 @@ BOOL WINAPI SetupSetFileQueueFlags( HSPFILEQ handle, DWORD mask, DWORD flags )
 }
 
 
+/***********************************************************************
+ *   SetupSetFileQueueAlternatePlatformA  (SETUPAPI.@)
+ */
+BOOL WINAPI SetupSetFileQueueAlternatePlatformA(HSPFILEQ handle, PSP_ALTPLATFORM_INFO platform, PCSTR catalogfile)
+{
+    FIXME("(%p, %p, %s) stub!\n", handle, platform, debugstr_a(catalogfile));
+    return FALSE;
+}
+
+
+/***********************************************************************
+ *   SetupSetFileQueueAlternatePlatformW  (SETUPAPI.@)
+ */
+BOOL WINAPI SetupSetFileQueueAlternatePlatformW(HSPFILEQ handle, PSP_ALTPLATFORM_INFO platform, PCWSTR catalogfile)
+{
+    FIXME("(%p, %p, %s) stub!\n", handle, platform, debugstr_w(catalogfile));
+    return FALSE;
+}
+
+
 /***********************************************************************
  *            SetupInitDefaultQueueCallback   (SETUPAPI.@)
  */
@@ -1310,6 +1316,7 @@ UINT WINAPI SetupDefaultQueueCallbackA( PVOID context, UINT notification,
                                         UINT_PTR param1, UINT_PTR param2 )
 {
     FILEPATHS_A *paths = (FILEPATHS_A *)param1;
+    struct default_callback_context *ctx = (struct default_callback_context *)context;
 
     switch(notification)
     {
@@ -1332,7 +1339,9 @@ UINT WINAPI SetupDefaultQueueCallbackA( PVOID context, UINT notification,
         TRACE( "end delete %s\n", debugstr_a(paths->Target) );
         return 0;
     case SPFILENOTIFY_DELETEERROR:
-        ERR( "delete error %d %s\n", paths->Win32Error, debugstr_a(paths->Target) );
+        /*Windows Ignores attempts to delete files / folders which do not exist*/
+        if ((paths->Win32Error != ERROR_FILE_NOT_FOUND) && (paths->Win32Error != ERROR_PATH_NOT_FOUND))
+        SetupDeleteErrorA(ctx->owner, NULL, paths->Target, paths->Win32Error, 0);
         return FILEOP_SKIP;
     case SPFILENOTIFY_STARTRENAME:
         TRACE( "start rename %s -> %s\n", debugstr_a(paths->Source), debugstr_a(paths->Target) );
@@ -1341,8 +1350,7 @@ UINT WINAPI SetupDefaultQueueCallbackA( PVOID context, UINT notification,
         TRACE( "end rename %s -> %s\n", debugstr_a(paths->Source), debugstr_a(paths->Target) );
         return 0;
     case SPFILENOTIFY_RENAMEERROR:
-        ERR( "rename error %d %s -> %s\n", paths->Win32Error,
-             debugstr_a(paths->Source), debugstr_a(paths->Target) );
+        SetupRenameErrorA(ctx->owner, NULL, paths->Source, paths->Target, paths->Win32Error, 0);
         return FILEOP_SKIP;
     case SPFILENOTIFY_STARTCOPY:
         TRACE( "start copy %s -> %s\n", debugstr_a(paths->Source), debugstr_a(paths->Target) );
@@ -1371,6 +1379,137 @@ UINT WINAPI SetupDefaultQueueCallbackA( PVOID context, UINT notification,
 UINT WINAPI SetupDefaultQueueCallbackW( PVOID context, UINT notification,
                                         UINT_PTR param1, UINT_PTR param2 )
 {
-    FIXME( "notification %d params %x,%x\n", notification, param1, param2 );
-    return FILEOP_SKIP;
+    FILEPATHS_W *paths = (FILEPATHS_W *)param1;
+    struct default_callback_context *ctx = (struct default_callback_context *)context;
+
+    switch(notification)
+    {
+    case SPFILENOTIFY_STARTQUEUE:
+        TRACE( "start queue\n" );
+        return TRUE;
+    case SPFILENOTIFY_ENDQUEUE:
+        TRACE( "end queue\n" );
+        return 0;
+    case SPFILENOTIFY_STARTSUBQUEUE:
+        TRACE( "start subqueue %d count %d\n", param1, param2 );
+        return TRUE;
+    case SPFILENOTIFY_ENDSUBQUEUE:
+        TRACE( "end subqueue %d\n", param1 );
+        return 0;
+    case SPFILENOTIFY_STARTDELETE:
+        TRACE( "start delete %s\n", debugstr_w(paths->Target) );
+        return FILEOP_DOIT;
+    case SPFILENOTIFY_ENDDELETE:
+        TRACE( "end delete %s\n", debugstr_w(paths->Target) );
+        return 0;
+    case SPFILENOTIFY_DELETEERROR:
+        /*Windows Ignores attempts to delete files / folders which do not exist*/
+        if ((paths->Win32Error != ERROR_FILE_NOT_FOUND) && (paths->Win32Error != ERROR_PATH_NOT_FOUND))
+            SetupDeleteErrorW(ctx->owner, NULL, paths->Target, paths->Win32Error, 0);
+        return FILEOP_SKIP;
+    case SPFILENOTIFY_STARTRENAME:
+        SetupRenameErrorW(ctx->owner, NULL, paths->Source, paths->Target, paths->Win32Error, 0);
+        return FILEOP_DOIT;
+    case SPFILENOTIFY_ENDRENAME:
+        TRACE( "end rename %s -> %s\n", debugstr_w(paths->Source), debugstr_w(paths->Target) );
+        return 0;
+    case SPFILENOTIFY_RENAMEERROR:
+        ERR( "rename error %d %s -> %s\n", paths->Win32Error,
+             debugstr_w(paths->Source), debugstr_w(paths->Target) );
+        return FILEOP_SKIP;
+    case SPFILENOTIFY_STARTCOPY:
+        TRACE( "start copy %s -> %s\n", debugstr_w(paths->Source), debugstr_w(paths->Target) );
+        return FILEOP_DOIT;
+    case SPFILENOTIFY_ENDCOPY:
+        TRACE( "end copy %s -> %s\n", debugstr_w(paths->Source), debugstr_w(paths->Target) );
+        return 0;
+    case SPFILENOTIFY_COPYERROR:
+        ERR( "copy error %d %s -> %s\n", paths->Win32Error,
+             debugstr_w(paths->Source), debugstr_w(paths->Target) );
+        return FILEOP_SKIP;
+    case SPFILENOTIFY_NEEDMEDIA:
+        TRACE( "need media\n" );
+        return FILEOP_SKIP;
+    default:
+        FIXME( "notification %d params %x,%x\n", notification, param1, param2 );
+        break;
+    }
+    return 0;
+}
+
+/***********************************************************************
+ *            SetupDeleteErrorA   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupDeleteErrorA( HWND parent, PCSTR dialogTitle, PCSTR file,
+                               UINT w32error, DWORD style)
+{
+    FIXME( "stub: (Error Number %d when attempting to delete %s)\n",
+           w32error, debugstr_a(file) );
+    return DPROMPT_SKIPFILE;
+}
+
+/***********************************************************************
+ *            SetupDeleteErrorW   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupDeleteErrorW( HWND parent, PCWSTR dialogTitle, PCWSTR file,
+                               UINT w32error, DWORD style)
+{
+    FIXME( "stub: (Error Number %d when attempting to delete %s)\n",
+           w32error, debugstr_w(file) );
+    return DPROMPT_SKIPFILE;
+}
+
+/***********************************************************************
+ *            SetupRenameErrorA   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupRenameErrorA( HWND parent, PCSTR dialogTitle, PCSTR source,
+                               PCSTR target, UINT w32error, DWORD style)
+{
+    FIXME( "stub: (Error Number %d when attempting to rename %s to %s)\n",
+           w32error, debugstr_a(source), debugstr_a(target));
+    return DPROMPT_SKIPFILE;
+}
+
+/***********************************************************************
+ *            SetupRenameErrorW   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupRenameErrorW( HWND parent, PCWSTR dialogTitle, PCWSTR source,
+                               PCWSTR target, UINT w32error, DWORD style)
+{
+    FIXME( "stub: (Error Number %d when attempting to rename %s to %s)\n",
+           w32error, debugstr_w(source), debugstr_w(target));
+    return DPROMPT_SKIPFILE;
+}
+
+
+/***********************************************************************
+ *            SetupCopyErrorA   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupCopyErrorA( HWND parent, PCSTR dialogTitle, PCSTR diskname, 
+                             PCSTR sourcepath, PCSTR sourcefile, PCSTR targetpath,
+                             UINT w32error, DWORD style, PSTR pathbuffer, 
+                            DWORD buffersize, PDWORD requiredsize)
+{
+    FIXME( "stub: (Error Number %d when attempting to copy file %s from %s to %s)\n",
+           w32error, debugstr_a(sourcefile), debugstr_a(sourcepath) ,debugstr_a(targetpath));
+    return DPROMPT_SKIPFILE;
+}
+
+/***********************************************************************
+ *            SetupCopyErrorW   (SETUPAPI.@)
+ */
+
+UINT WINAPI SetupCopyErrorW( HWND parent, PCWSTR dialogTitle, PCWSTR diskname, 
+                             PCWSTR sourcepath, PCWSTR sourcefile, PCWSTR targetpath,
+                             UINT w32error, DWORD style, PWSTR pathbuffer, 
+                            DWORD buffersize, PDWORD requiredsize)
+{
+    FIXME( "stub: (Error Number %d when attempting to copy file %s from %s to %s)\n",
+           w32error, debugstr_w(sourcefile), debugstr_w(sourcepath) ,debugstr_w(targetpath));
+    return DPROMPT_SKIPFILE;
 }