[SETUPLIB][REACTOS][USETUP] Further improve the interfacing with INF and File-Queue...
[reactos.git] / base / setup / reactos / spapisup / fileqsup.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS GUI first stage setup application
4 * FILE: base/setup/lib/fileqsup.c
5 * PURPOSE: Interfacing with Setup* API File Queue support functions
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include "precomp.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* SETUP* API COMPATIBILITY FUNCTIONS ****************************************/
17
18 /* A simplified version of SetupQueueCopyW that wraps Cabinet support around */
19 BOOL
20 WINAPI
21 SpFileQueueCopy_NtToWin32(
22 IN HSPFILEQ QueueHandle,
23 IN PCWSTR SourceRootPath,
24 IN PCWSTR SourcePath OPTIONAL,
25 IN PCWSTR SourceFileName,
26 IN PCWSTR SourceDescription OPTIONAL,
27 IN PCWSTR SourceCabinet OPTIONAL,
28 IN PCWSTR SourceTagFile OPTIONAL,
29 IN PCWSTR TargetDirectory,
30 IN PCWSTR TargetFileName OPTIONAL,
31 IN ULONG CopyStyle)
32 {
33 WCHAR Win32SourceRootPath[MAX_PATH];
34 WCHAR Win32TargetDirectory[MAX_PATH];
35
36 /*
37 * SpFileQueueCopy is called within setuplib with NT paths, however
38 * the Win32 SetupQueueCopyW API only takes Win32 paths. We therefore
39 * map the NT path to Win32 path and then call the Win32 API.
40 */
41 if (!ConvertNtPathToWin32Path(Win32SourceRootPath,
42 _countof(Win32SourceRootPath),
43 SourceRootPath))
44 {
45 return FALSE;
46 }
47 /* SourcePath, SourceFileName and SourceCabinet are appended to SourceRootPath by the SetupApi function */
48
49 if (!ConvertNtPathToWin32Path(Win32TargetDirectory,
50 _countof(Win32TargetDirectory),
51 TargetDirectory))
52 {
53 return FALSE;
54 }
55 /* TargetFileName is appended to TargetDirectory by the SetupApi function */
56
57 /*
58 * Use the undocumented way of copying files from within a given cabinet file
59 * *ONLY IF* the files do not already exist in the same directory where
60 * the cabinet file resides!!
61 */
62 return SetupQueueCopyW(QueueHandle,
63 Win32SourceRootPath,
64 SourcePath,
65 SourceFileName,
66 // Undocumented on MSDN is the fact that this parameter is mandatory *IF* one wants to take the TagFile into account!
67 L"foobar",
68 // SourceTagFile -- Special behaviour: use cabinet file present in ArchiveDir path! The API does not check for a ".cab" extension.
69 SourceCabinet,
70 Win32TargetDirectory,
71 TargetFileName,
72 // We choose to decompress the archive, so do NOT specify SP_COPY_NODECOMP !
73 SP_COPY_NOOVERWRITE /* | SP_COPY_SOURCE_ABSOLUTE | SP_COPY_SOURCEPATH_ABSOLUTE */
74 );
75 }
76
77 BOOL
78 WINAPI
79 SpFileQueueDelete_NtToWin32(
80 IN HSPFILEQ QueueHandle,
81 IN PCWSTR PathPart1,
82 IN PCWSTR PathPart2 OPTIONAL)
83 {
84 WCHAR Win32PathPart1[MAX_PATH];
85
86 /*
87 * SpFileQueueDelete is called within setuplib with NT paths, however
88 * the Win32 SetupQueueDeleteW API only takes Win32 paths. We therefore
89 * map the NT path to Win32 path and then call the Win32 API.
90 */
91 if (!ConvertNtPathToWin32Path(Win32PathPart1,
92 _countof(Win32PathPart1),
93 PathPart1))
94 {
95 return FALSE;
96 }
97 /* PathPart2 is appended to PathPart1 by the SetupApi function */
98
99 return SetupQueueDeleteW(QueueHandle, Win32PathPart1, PathPart2);
100 }
101
102 BOOL
103 WINAPI
104 SpFileQueueRename_NtToWin32(
105 IN HSPFILEQ QueueHandle,
106 IN PCWSTR SourcePath,
107 IN PCWSTR SourceFileName OPTIONAL,
108 IN PCWSTR TargetPath OPTIONAL,
109 IN PCWSTR TargetFileName)
110 {
111 WCHAR Win32SourcePath[MAX_PATH];
112 WCHAR Win32TargetPath[MAX_PATH];
113
114 /*
115 * SpFileQueueRename is called within setuplib with NT paths, however
116 * the Win32 SetupQueueRenameW API only takes Win32 paths. We therefore
117 * map the NT path to Win32 path and then call the Win32 API.
118 */
119 if (!ConvertNtPathToWin32Path(Win32SourcePath,
120 _countof(Win32SourcePath),
121 SourcePath))
122 {
123 return FALSE;
124 }
125 /* SourceFileName is appended to SourcePath by the SetupApi function */
126
127 if (TargetPath)
128 {
129 if (!ConvertNtPathToWin32Path(Win32TargetPath,
130 _countof(Win32TargetPath),
131 TargetPath))
132 {
133 return FALSE;
134 }
135 }
136 /* TargetFileName is appended to TargetPath by the SetupApi function */
137
138 return SetupQueueRenameW(QueueHandle,
139 Win32SourcePath,
140 SourceFileName,
141 TargetPath ? Win32TargetPath : NULL,
142 TargetFileName);
143 }
144
145
146 /* GLOBALS *******************************************************************/
147
148 pSpFileQueueOpen SpFileQueueOpen = SetupOpenFileQueue;
149 pSpFileQueueClose SpFileQueueClose = SetupCloseFileQueue;
150 pSpFileQueueCopy SpFileQueueCopy = SpFileQueueCopy_NtToWin32;
151 pSpFileQueueDelete SpFileQueueDelete = SpFileQueueDelete_NtToWin32;
152 pSpFileQueueRename SpFileQueueRename = SpFileQueueRename_NtToWin32;
153 pSpFileQueueCommit SpFileQueueCommit = SetupCommitFileQueueW;
154
155 /* EOF */