OLD | NEW |
1 /** | 1 /** |
2 * \file session.h The "install session" is the context for all custom installati
on behavior. | 2 * \file session.h The "install session" is the context for all custom installati
on behavior. |
3 */ | 3 */ |
4 | 4 |
5 #ifndef SESSION_H | 5 #ifndef SESSION_H |
6 #define SESSION_H | 6 #define SESSION_H |
7 | 7 |
8 #include "property.h" | 8 #include "property.h" |
9 #include "record.h" | 9 #include "record.h" |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include "windows.h" | 12 #include "windows.h" |
13 #include "msi.h" | 13 #include "msi.h" |
14 | 14 |
15 //------------------------------------------------------------------------------
----------- | 15 //------------------------------------------------------------------------------
----------- |
16 // Message | 16 // Message |
17 //------------------------------------------------------------------------------
----------- | 17 //------------------------------------------------------------------------------
----------- |
18 /** | 18 /** |
19 * Wrapper class for arguments to MsiProcessMessage. | 19 * Wrapper class for arguments to MsiProcessMessage. |
20 * | 20 * |
21 * The "user interface" for custom actions includes both interactive dialog boxe
s as well as the installation log. | 21 * The "user interface" for custom actions includes both interactive dialog boxe
s as well as the installation log. |
22 * All of them use the same call, MsiProcessMessage. | 22 * All of them use the same call, MsiProcessMessage. |
23 * This class encapsulates its arguments. | 23 * This class encapsulates its arguments. |
24 * | 24 * |
25 * \sa | 25 * \sa |
26 * * MSDN [MsiProcessMessage function](http://msdn.microsoft.com/en-us/librar
y/windows/desktop/aa370354%28v=vs.85%29.aspx) | 26 * * MSDN [MsiProcessMessage function](http://msdn.microsoft.com/en-us/librar
y/windows/desktop/aa370354%28v=vs.85%29.aspx) |
27 * * MSDN [Sending Messages to Windows Installer Using MsiProcessMessage](htt
p://msdn.microsoft.com/en-us/library/windows/desktop/aa371614%28v=vs.85%29.aspx) | 27 * * MSDN [Sending Messages to Windows Installer Using MsiProcessMessage](htt
p://msdn.microsoft.com/en-us/library/windows/desktop/aa371614%28v=vs.85%29.aspx) |
28 */ | 28 */ |
29 class Message | 29 class Message |
30 { | 30 { |
31 protected: | 31 protected: |
32 /** | 32 /** |
33 * The flags used by MsiProcessMessage as the box type. | 33 * The flags used by MsiProcessMessage as the box type. |
34 */ | 34 */ |
35 INSTALLMESSAGE MessageTypeCode ; | 35 INSTALLMESSAGE MessageTypeCode; |
36 | 36 |
37 /** | 37 /** |
38 * The record argument to MsiProcessMessage | 38 * The record argument to MsiProcessMessage |
39 */ | 39 */ |
40 Record r ; | 40 Record r; |
41 | 41 |
42 Message( std::string message, INSTALLMESSAGE MessageTypeCode ) ; | 42 Message(std::string message, INSTALLMESSAGE MessageTypeCode); |
43 | 43 |
44 Message( std::wstring message, INSTALLMESSAGE MessageTypeCode ) ; | 44 Message(std::wstring message, INSTALLMESSAGE MessageTypeCode); |
45 | 45 |
46 /** | 46 /** |
47 * This class is a helper for Session, mustering all the arguments for MsiProce
ssMessage except for the session handle. | 47 * This class is a helper for Session, mustering all the arguments for MsiProce
ssMessage except for the session handle. |
48 */ | 48 */ |
49 friend Session ; | 49 friend Session; |
50 } ; | 50 }; |
51 | 51 |
52 //------------------------------------------------------------------------------
----------- | 52 //------------------------------------------------------------------------------
----------- |
53 // Session | 53 // Session |
54 //------------------------------------------------------------------------------
----------- | 54 //------------------------------------------------------------------------------
----------- |
55 /** | 55 /** |
56 * A Windows Installer session | 56 * A Windows Installer session |
57 * | 57 * |
58 * Always instantiate an instance of this class at the start of each custom actio
n. | 58 * Always instantiate an instance of this class at the start of each custom actio
n. |
59 * Copy and assignment are disabled, so session objects are always passed by refe
rence. | 59 * Copy and assignment are disabled, so session objects are always passed by refe
rence. |
60 * | 60 * |
61 * This class is the base for both immediate and deferred custom actions. | 61 * This class is the base for both immediate and deferred custom actions. |
62 * Immediate custom actions always have an installer database associated with the
m; deferred actions never do. | 62 * Immediate custom actions always have an installer database associated with the
m; deferred actions never do. |
63 * Both immediate and deferred actions may be executed synchronously or asynchron
ously; this class is silent about any difference. | 63 * Both immediate and deferred actions may be executed synchronously or asynchron
ously; this class is silent about any difference. |
64 * | 64 * |
65 * \par Notes | 65 * \par Notes |
66 * This class is patterned after WcaInitialize/WcaFinalize of the WiX custom ac
tion library. | 66 * This class is patterned after WcaInitialize/WcaFinalize of the WiX custom ac
tion library. |
67 * There are two things that class does that this one does not. | 67 * There are two things that class does that this one does not. |
68 * - Extract the file version information from the DLL using GetModuleFileName*
and GetFileVersionInfo* system calls. | 68 * - Extract the file version information from the DLL using GetModuleFileName*
and GetFileVersionInfo* system calls. |
69 * - Set a "global atom" (a Windows system object) to store the logging state,
later to be accessed by deferred actions. | 69 * - Set a "global atom" (a Windows system object) to store the logging state,
later to be accessed by deferred actions. |
70 */ | 70 */ |
71 class Session { | 71 class Session |
| 72 { |
72 public: | 73 public: |
73 /** | 74 /** |
74 * Destructor. | 75 * Destructor. |
75 */ | 76 */ |
76 ~Session() ; | 77 ~Session(); |
77 | 78 |
78 /** | 79 /** |
79 * Write a message to the installation log, regular string version. | 80 * Write a message to the installation log, regular string version. |
80 */ | 81 */ |
81 void Log( std::string message ) ; | 82 void Log(std::string message); |
82 | 83 |
83 /** | 84 /** |
84 * Write a message to the installation log, wide string version. | 85 * Write a message to the installation log, wide string version. |
85 */ | 86 */ |
86 void Log( std::wstring message ) ; | 87 void Log(std::wstring message); |
87 | 88 |
88 /** | 89 /** |
89 * Write a message to the installation log without raising an exception. | 90 * Write a message to the installation log without raising an exception. |
90 * | 91 * |
91 * Use this function only in the three circumstances when an exception cannot b
e caught by an entry point catch-all. | 92 * Use this function only in the three circumstances when an exception cannot b
e caught by an entry point catch-all. |
92 * First and second, there's the constructor and destructor of a Session instan
ce. | 93 * First and second, there's the constructor and destructor of a Session instan
ce. |
93 * These log entry into and exit from the custom action, respectively. | 94 * These log entry into and exit from the custom action, respectively. |
94 * Third, there's the top level catch-blocks of the CA. | 95 * Third, there's the top level catch-blocks of the CA. |
95 * The scope of the Session object cannot be within the try-block in order for
it to be in scope for the catch-block. | 96 * The scope of the Session object cannot be within the try-block in order for
it to be in scope for the catch-block. |
96 * The session must be in scope in the catch-block to allow logging error messa
ges. | 97 * The session must be in scope in the catch-block to allow logging error messa
ges. |
97 * In all other cases, use the exception mechanism. | 98 * In all other cases, use the exception mechanism. |
98 */ | 99 */ |
99 void LogNoexcept( std::string message ) ; | 100 void LogNoexcept(std::string message); |
100 | 101 |
101 /** | 102 /** |
102 * Write to a MessageBox dialog. | 103 * Write to a MessageBox dialog. |
103 */ | 104 */ |
104 int WriteMessage( Message & ) ; | 105 int WriteMessage(Message&); |
105 | 106 |
106 protected: | 107 protected: |
107 /** | 108 /** |
108 * Ordinary constructor is protected; public constructors are all in subclasses
. | 109 * Ordinary constructor is protected; public constructors are all in subclasses
. |
109 * The MSI system uses a single handle type for all types of sessions. This han
dle is here in this base class. | 110 * The MSI system uses a single handle type for all types of sessions. This han
dle is here in this base class. |
110 * | 111 * |
111 * \param[in] handle | 112 * \param[in] handle |
112 * Handle for the Windows Installer session provided as an argument to a cus
tom action. | 113 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
113 * \param[in] name | 114 * \param[in] name |
114 * The name of the custom action, used for logging. | 115 * The name of the custom action, used for logging. |
115 * This string must be ASCII characters only, so that its wide-character ver
sion displays identically. | 116 * This string must be ASCII characters only, so that its wide-character ver
sion displays identically. |
116 */ | 117 */ |
117 Session( MSIHANDLE handle, std::string name ) ; | 118 Session(MSIHANDLE handle, std::string name); |
118 | 119 |
119 /** | 120 /** |
120 * Handle for the Windows Installer session. | 121 * Handle for the Windows Installer session. |
121 * | 122 * |
122 * The life cycle of the session handle is not the responsibility of the base c
lass. | 123 * The life cycle of the session handle is not the responsibility of the base c
lass. |
123 * In an interactive session, the handle is provided as an argument to the cust
om action entry point, and we do not manage its life cycle. | 124 * In an interactive session, the handle is provided as an argument to the cust
om action entry point, and we do not manage its life cycle. |
124 * In an offline session, the handle is created in the (subclass) constructor. | 125 * In an offline session, the handle is created in the (subclass) constructor. |
125 */ | 126 */ |
126 MSIHANDLE handle ; | 127 MSIHANDLE handle; |
127 | 128 |
128 private: | 129 private: |
129 /** | 130 /** |
130 * Prefix for log messages, regular string. Contains the name of the custom act
ion. | 131 * Prefix for log messages, regular string. Contains the name of the custom act
ion. |
131 */ | 132 */ |
132 std::string logPrefix ; | 133 std::string logPrefix; |
133 | 134 |
134 /** | 135 /** |
135 * Prefix for log messages, wide string. Contains the name of the custom action
. | 136 * Prefix for log messages, wide string. Contains the name of the custom action
. |
136 */ | 137 */ |
137 std::wstring logPrefixW ; | 138 std::wstring logPrefixW; |
138 | 139 |
139 /** | 140 /** |
140 * Private copy constructor is declared but not defined. | 141 * Private copy constructor is declared but not defined. |
141 * | 142 * |
142 * C++11: declare with <b>= delete</b>. | 143 * C++11: declare with <b>= delete</b>. |
143 */ | 144 */ |
144 Session( const Session & ) ; | 145 Session(const Session&); |
145 | 146 |
146 /** | 147 /** |
147 * Write a message with MsiProcessMessage and throw no exceptions. | 148 * Write a message with MsiProcessMessage and throw no exceptions. |
148 * | 149 * |
149 * This is declared private because there are very few cases in which no-except
ion behavior is required. | 150 * This is declared private because there are very few cases in which no-except
ion behavior is required. |
150 * | 151 * |
151 * C++11: declare with **noexcept**. | 152 * C++11: declare with **noexcept**. |
152 */ | 153 */ |
153 int WriteMessageNoexcept( Message & m ) ; | 154 int WriteMessageNoexcept(Message& m); |
154 | 155 |
155 /** | 156 /** |
156 * Private assignment operator is declared but not defined. | 157 * Private assignment operator is declared but not defined. |
157 * | 158 * |
158 * C++11: declare with <b>= delete</b>. | 159 * C++11: declare with <b>= delete</b>. |
159 */ | 160 */ |
160 Session & operator=( const Session & ) ; | 161 Session& operator=(const Session&); |
161 | 162 |
162 /** | 163 /** |
163 * The Property class requires access to the session handle. | 164 * The Property class requires access to the session handle. |
164 */ | 165 */ |
165 friend Property::Property( Session & session, std::wstring name ) ; | 166 friend Property::Property(Session& session, std::wstring name); |
166 }; | 167 }; |
167 | 168 |
168 //------------------------------------------------------------------------------
----------- | 169 //------------------------------------------------------------------------------
----------- |
169 // ImmediateSession | 170 // ImmediateSession |
170 //------------------------------------------------------------------------------
----------- | 171 //------------------------------------------------------------------------------
----------- |
171 /** | 172 /** |
172 * Session for immediate custom actions. | 173 * Session for immediate custom actions. |
173 * | 174 * |
174 * Access to the installer database is by passing a reference to a class of this
subtype to a Database constructor. | 175 * Access to the installer database is by passing a reference to a class of this
subtype to a Database constructor. |
175 */ | 176 */ |
176 class ImmediateSession : public Session | 177 class ImmediateSession : public Session |
177 { | 178 { |
178 public: | 179 public: |
179 /** | 180 /** |
180 * Ordinary constructor. | 181 * Ordinary constructor. |
181 * | 182 * |
182 * \param[in] handle | 183 * \param[in] handle |
183 * Handle for the Windows Installer session provided as an argument to a cus
tom action. | 184 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
184 * \param[in] name | 185 * \param[in] name |
185 * The name of the custom action, used for logging. | 186 * The name of the custom action, used for logging. |
186 * | 187 * |
187 * **noexcept** declaration to be added for C++11. | 188 * **noexcept** declaration to be added for C++11. |
188 */ | 189 */ |
189 ImmediateSession( MSIHANDLE handle, std::string name ) ; | 190 ImmediateSession(MSIHANDLE handle, std::string name); |
190 | 191 |
191 private: | 192 private: |
192 /* | 193 /* |
193 * Allow helper function for InstallationDatabase constructor to have access to
the handle. | 194 * Allow helper function for InstallationDatabase constructor to have access to
the handle. |
194 */ | 195 */ |
195 friend MsiHandle GetActiveDatabase( ImmediateSession & session ) ; | 196 friend MsiHandle GetActiveDatabase(ImmediateSession& session); |
196 }; | 197 }; |
197 | 198 |
198 | 199 |
199 //------------------------------------------------------------------------------
----------- | 200 //------------------------------------------------------------------------------
----------- |
200 // DeferredSession | 201 // DeferredSession |
201 //------------------------------------------------------------------------------
----------- | 202 //------------------------------------------------------------------------------
----------- |
202 /** | 203 /** |
203 * Session for deferred custom actions. | 204 * Session for deferred custom actions. |
204 * | 205 * |
205 * There's much less context information easily available from a deferred custom
action. | 206 * There's much less context information easily available from a deferred custom
action. |
(...skipping 10 matching lines...) Expand all Loading... |
216 { | 217 { |
217 public: | 218 public: |
218 /** | 219 /** |
219 * Ordinary constructor. | 220 * Ordinary constructor. |
220 * | 221 * |
221 * \param[in] handle | 222 * \param[in] handle |
222 * Handle for the Windows Installer session provided as an argument to a cus
tom action. | 223 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
223 * \param[in] name | 224 * \param[in] name |
224 * The name of the custom action, used for logging. | 225 * The name of the custom action, used for logging. |
225 */ | 226 */ |
226 DeferredSession( MSIHANDLE handle, std::wstring name ) ; | 227 DeferredSession(MSIHANDLE handle, std::wstring name); |
227 }; | 228 }; |
228 | 229 |
229 | 230 |
230 //------------------------------------------------------------------------------
----------- | 231 //------------------------------------------------------------------------------
----------- |
231 // CommitSession | 232 // CommitSession |
232 //------------------------------------------------------------------------------
----------- | 233 //------------------------------------------------------------------------------
----------- |
233 /** | 234 /** |
234 * The session for a commit custom action. NOT IMPLEMENTED. | 235 * The session for a commit custom action. NOT IMPLEMENTED. |
235 * | 236 * |
236 * \sa MSDN "Commit Custom Actions" http://msdn.microsoft.com/en-us/library/windo
ws/desktop/aa367991%28v=vs.85%29.aspx | 237 * \sa MSDN "Commit Custom Actions" http://msdn.microsoft.com/en-us/library/windo
ws/desktop/aa367991%28v=vs.85%29.aspx |
237 */ | 238 */ |
238 class CommitSession | 239 class CommitSession |
239 { | 240 { |
240 }; | 241 }; |
241 | 242 |
242 //------------------------------------------------------------------------------
----------- | 243 //------------------------------------------------------------------------------
----------- |
243 // RollbackSession | 244 // RollbackSession |
244 //------------------------------------------------------------------------------
----------- | 245 //------------------------------------------------------------------------------
----------- |
245 /** | 246 /** |
246 * The session for a rollback custom action. NOT IMPLEMENTED. | 247 * The session for a rollback custom action. NOT IMPLEMENTED. |
247 * | 248 * |
248 * \sa MSDN "Rollback Custom Actions" http://msdn.microsoft.com/en-us/library/win
dows/desktop/aa371369%28v=vs.85%29.aspx | 249 * \sa MSDN "Rollback Custom Actions" http://msdn.microsoft.com/en-us/library/win
dows/desktop/aa371369%28v=vs.85%29.aspx |
249 */ | 250 */ |
250 class RollbackSession | 251 class RollbackSession |
251 { | 252 { |
252 }; | 253 }; |
253 | 254 |
254 #endif | 255 #endif |
OLD | NEW |