OLD | NEW |
1 /** | 1 /** |
2 * \file session.h The "install session" is the context for all custom installat
ion 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 |
| 17 //------------------------------------------------------------------------------
----------- |
| 18 /** |
| 19 * Wrapper class for arguments to MsiProcessMessage. |
| 20 * |
| 21 * The "user interface" for custom actions includes both interactive dialog boxes
as well as the installation log. |
| 22 * All of them use the same call, MsiProcessMessage. |
| 23 * This class encapsulates its arguments. |
| 24 * |
| 25 * \sa |
| 26 * * MSDN [MsiProcessMessage function](http://msdn.microsoft.com/en-us/library
/windows/desktop/aa370354%28v=vs.85%29.aspx) |
| 27 * * MSDN [Sending Messages to Windows Installer Using MsiProcessMessage](http
://msdn.microsoft.com/en-us/library/windows/desktop/aa371614%28v=vs.85%29.aspx) |
| 28 */ |
| 29 class Message |
| 30 { |
| 31 protected: |
| 32 /** |
| 33 * The flags used by MsiProcessMessage as the box type. |
| 34 */ |
| 35 INSTALLMESSAGE message_type ; |
| 36 |
| 37 /** |
| 38 * The record argument to MsiProcessMessage |
| 39 */ |
| 40 Record r ; |
| 41 |
| 42 Message( std::string message, INSTALLMESSAGE message_type ) ; |
| 43 |
| 44 Message( std::wstring message, INSTALLMESSAGE message_type ) ; |
| 45 |
| 46 /** |
| 47 * This class is a helper for Session, mustering all the arguments for MsiProce
ssMessage except for the session handle. |
| 48 */ |
| 49 friend Session ; |
| 50 } ; |
| 51 |
| 52 //------------------------------------------------------------------------------
----------- |
16 // Session | 53 // Session |
17 //------------------------------------------------------------------------------
----------- | 54 //------------------------------------------------------------------------------
----------- |
18 /** | 55 /** |
19 * A Windows Installer session | 56 * A Windows Installer session |
20 * | 57 * |
21 * Always instantiate an instance of this class at the start of each custom acti
on. | 58 * Always instantiate an instance of this class at the start of each custom actio
n. |
22 * Copy and assignment are disabled, so session objects are always passed by ref
erence. | 59 * Copy and assignment are disabled, so session objects are always passed by refe
rence. |
23 * | 60 * |
24 * 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. |
25 * Immediate custom actions always have an installer database associated with th
em; deferred actions never do. | 62 * Immediate custom actions always have an installer database associated with the
m; deferred actions never do. |
26 * Both immediate and deferred actions may be executed synchronously or asynchro
nously; 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. |
27 * | 64 * |
28 * \par Notes | 65 * \par Notes |
29 * This class is patterned after WcaInitialize/WcaFinalize of the WiX custom a
ction library. | 66 * This class is patterned after WcaInitialize/WcaFinalize of the WiX custom ac
tion library. |
30 * 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. |
31 * - 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. |
32 * - 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. |
33 */ | 70 */ |
34 class Session { | 71 class Session { |
35 public: | 72 public: |
36 /** | 73 /** |
37 * Destructor. | 74 * Destructor. |
38 */ | 75 */ |
39 ~Session() ; | 76 ~Session() ; |
40 | 77 |
41 /** | 78 /** |
42 * Write a message to the installation log. | 79 * Write a message to the installation log, regular string version. |
43 */ | 80 */ |
| 81 void log( std::string message ) ; |
| 82 |
| 83 /** |
| 84 * Write a message to the installation log, wide string version. |
| 85 */ |
44 void log( std::wstring message ) ; | 86 void log( std::wstring message ) ; |
45 | 87 |
| 88 /** |
| 89 * Write a message to the installation log without raising an exception. |
| 90 * |
| 91 * 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 * These log entry into and exit from the custom action, respectively. |
| 94 * 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 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 */ |
| 99 void log_noexcept( std::string message ) ; |
| 100 |
| 101 /** |
| 102 * Write to a MessageBox dialog. |
| 103 */ |
| 104 int write_message( Message & ) ; |
| 105 |
46 protected: | 106 protected: |
47 /** | 107 /** |
48 * Ordinary constructor is protected; public constructors are all in subclasse
s. | 108 * Ordinary constructor is protected; public constructors are all in subclasses
. |
49 * The MSI system uses a single handle type for all types of sessions. This ha
ndle is here in this base class. | 109 * The MSI system uses a single handle type for all types of sessions. This han
dle is here in this base class. |
50 * | 110 * |
51 * \param[in] handle | 111 * \param[in] handle |
52 * Handle for the Windows Installer session provided as an argument to a cu
stom action. | 112 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
53 * \param[in] name | 113 * \param[in] name |
54 * The name of the custom action, used for logging. | 114 * The name of the custom action, used for logging. |
55 */ | 115 * This string must be ASCII characters only, so that its wide-character ver
sion displays identically. |
56 Session( MSIHANDLE handle, std::wstring name ) ; | 116 */ |
| 117 Session( MSIHANDLE handle, std::string name ) ; |
57 | 118 |
58 protected: | |
59 /** | 119 /** |
60 * Handle for the Windows Installer session. | 120 * Handle for the Windows Installer session. |
61 */ | 121 * |
| 122 * 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 offline session, the handle is created in the (subclass) constructor. |
| 125 */ |
62 MSIHANDLE handle ; | 126 MSIHANDLE handle ; |
63 | 127 |
64 private: | 128 private: |
65 /** | 129 /** |
66 * Prefix for log messages. Contains the name of the custom action. | 130 * Prefix for log messages, regular string. Contains the name of the custom act
ion. |
67 */ | 131 */ |
68 std::wstring log_prefix ; | 132 std::string log_prefix ; |
69 | 133 |
70 /** | 134 /** |
71 * Private copy constructor is declared but not defined. | 135 * Prefix for log messages, wide string. Contains the name of the custom action
. |
72 */ | 136 */ |
| 137 std::wstring log_prefix_w ; |
| 138 |
| 139 /** |
| 140 * Private copy constructor is declared but not defined. |
| 141 * |
| 142 * C++11: declare with <b>= delete</b>. |
| 143 */ |
73 Session( const Session & ) ; | 144 Session( const Session & ) ; |
74 | 145 |
75 /** | 146 /** |
76 * Private assignment operator is declared but not defined. | 147 * Write a message with MsiProcessMessage and throw no exceptions. |
77 */ | 148 * |
| 149 * This is declared private because there are very few cases in which no-except
ion behavior is required. |
| 150 * |
| 151 * C++11: declare with **noexcept**. |
| 152 */ |
| 153 int write_message_noexcept( Message & m ) ; |
| 154 |
| 155 /** |
| 156 * Private assignment operator is declared but not defined. |
| 157 * |
| 158 * C++11: declare with <b>= delete</b>. |
| 159 */ |
78 Session & operator=( const Session & ) ; | 160 Session & operator=( const Session & ) ; |
79 | 161 |
80 /** | 162 /** |
81 * The Property class requires access to the session handle. | 163 * The Property class requires access to the session handle. |
82 */ | 164 */ |
83 friend Property::Property( Session & session, std::wstring name ) ; | 165 friend Property::Property( Session & session, std::wstring name ) ; |
84 }; | 166 }; |
85 | 167 |
86 //------------------------------------------------------------------------------
----------- | 168 //------------------------------------------------------------------------------
----------- |
87 // Immediate_Session | 169 // Immediate_Session |
88 //------------------------------------------------------------------------------
----------- | 170 //------------------------------------------------------------------------------
----------- |
89 /** | 171 /** |
90 * Session for immediate custom actions. | 172 * Session for immediate custom actions. |
91 * | 173 * |
92 * Access to the installer database is by passing a reference to a class of this
subtype to a Database constructor. | 174 * Access to the installer database is by passing a reference to a class of this
subtype to a Database constructor. |
93 */ | 175 */ |
94 class Immediate_Session : public Session | 176 class Immediate_Session : public Session |
95 { | 177 { |
96 public: | 178 public: |
97 /** | 179 /** |
98 * Ordinary constructor. | 180 * Ordinary constructor. |
99 * | 181 * |
100 * \param[in] handle | 182 * \param[in] handle |
101 * Handle for the Windows Installer session provided as an argument to a cu
stom action. | 183 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
102 * \param[in] name | 184 * \param[in] name |
103 * The name of the custom action, used for logging. | 185 * The name of the custom action, used for logging. |
104 */ | 186 * |
105 Immediate_Session( MSIHANDLE handle, std::wstring name ) ; | 187 * **noexcept** declaration to be added for C++11. |
| 188 */ |
| 189 Immediate_Session( MSIHANDLE handle, std::string name ) ; |
106 | 190 |
107 private: | 191 private: |
108 /* | 192 /* |
109 * Allow helper function for Installation_Database constructor to have access
to the handle. | 193 * Allow helper function for Installation_Database constructor to have access t
o the handle. |
110 */ | 194 */ |
111 friend MSIHANDLE get_active_database( Immediate_Session & session ) ; | 195 friend msi_handle get_active_database( Immediate_Session & session ) ; |
112 }; | 196 }; |
113 | 197 |
114 | 198 |
115 //------------------------------------------------------------------------------
----------- | 199 //------------------------------------------------------------------------------
----------- |
116 // Deferred_Session | 200 // Deferred_Session |
117 //------------------------------------------------------------------------------
----------- | 201 //------------------------------------------------------------------------------
----------- |
118 /** | 202 /** |
119 * Session for deferred custom actions. | 203 * Session for deferred custom actions. |
120 * | 204 * |
121 * There's much less context information easily available from a deferred custom
action. | 205 * There's much less context information easily available from a deferred custom
action. |
122 * | 206 * |
123 * /sa MDSN "Deferred Execution Custom Actions" | 207 * /sa MDSN "Deferred Execution Custom Actions" |
124 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa368268%28v=vs.8
5%29.aspx | 208 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa368268%28v=vs.85
%29.aspx |
125 * for general information. | 209 * for general information. |
126 * | 210 * |
127 * /sa MSDN "Obtaining Context Information for Deferred Execution Custom Actions
" | 211 * /sa MSDN "Obtaining Context Information for Deferred Execution Custom Actions" |
128 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa370543%28v=vs.8
5%29.aspx | 212 * http://msdn.microsoft.com/en-us/library/windows/desktop/aa370543%28v=vs.85
%29.aspx |
129 * lists the API calls available. | 213 * lists the API calls available. |
130 */ | 214 */ |
131 class Deferred_Session : public Session | 215 class Deferred_Session : public Session |
132 { | 216 { |
133 public: | 217 public: |
134 /** | 218 /** |
135 * Ordinary constructor. | 219 * Ordinary constructor. |
136 * | 220 * |
137 * \param[in] handle | 221 * \param[in] handle |
138 * Handle for the Windows Installer session provided as an argument to a cu
stom action. | 222 * Handle for the Windows Installer session provided as an argument to a cus
tom action. |
139 * \param[in] name | 223 * \param[in] name |
140 * The name of the custom action, used for logging. | 224 * The name of the custom action, used for logging. |
141 */ | 225 */ |
142 Deferred_Session( MSIHANDLE handle, std::wstring name ) ; | 226 Deferred_Session( MSIHANDLE handle, std::wstring name ) ; |
143 }; | 227 }; |
144 | 228 |
145 | 229 |
146 //------------------------------------------------------------------------------
----------- | 230 //------------------------------------------------------------------------------
----------- |
147 // Commit_Session | 231 // Commit_Session |
148 //------------------------------------------------------------------------------
----------- | 232 //------------------------------------------------------------------------------
----------- |
149 /** | 233 /** |
150 * The session for a commit custom action. NOT IMPLEMENTED. | 234 * The session for a commit custom action. NOT IMPLEMENTED. |
151 * | 235 * |
152 * \sa MSDN "Commit Custom Actions" http://msdn.microsoft.com/en-us/library/wind
ows/desktop/aa367991%28v=vs.85%29.aspx | 236 * \sa MSDN "Commit Custom Actions" http://msdn.microsoft.com/en-us/library/windo
ws/desktop/aa367991%28v=vs.85%29.aspx |
153 */ | 237 */ |
154 class Commit_Session | 238 class Commit_Session |
155 { | 239 { |
156 }; | 240 }; |
157 | 241 |
158 //------------------------------------------------------------------------------
----------- | 242 //------------------------------------------------------------------------------
----------- |
159 // Rollback_Session | 243 // Rollback_Session |
160 //------------------------------------------------------------------------------
----------- | 244 //------------------------------------------------------------------------------
----------- |
161 /** | 245 /** |
162 * The session for a rollback custom action. NOT IMPLEMENTED. | 246 * The session for a rollback custom action. NOT IMPLEMENTED. |
163 * | 247 * |
164 * \sa MSDN "Rollback Custom Actions" http://msdn.microsoft.com/en-us/library/wi
ndows/desktop/aa371369%28v=vs.85%29.aspx | 248 * \sa MSDN "Rollback Custom Actions" http://msdn.microsoft.com/en-us/library/win
dows/desktop/aa371369%28v=vs.85%29.aspx |
165 */ | 249 */ |
166 class Rollback_Session | 250 class Rollback_Session |
167 { | 251 { |
168 }; | 252 }; |
169 | 253 |
170 #endif | 254 #endif |
OLD | NEW |