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 installat
ion 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 boxe
s 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/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) |
| 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 MsiProc
essMessage 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 acti
on. |
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 ref
erence. |
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 th
em; 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 asynchro
nously; 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 a
ction 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. |
| 80 */ |
| 81 void log( std::string message ) ; |
| 82 |
| 83 /** |
| 84 * Write a message to the installation log, wide string version. |
43 */ | 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
be caught by an entry point catch-all. |
| 92 * First and second, there's the constructor and destructor of a Session insta
nce. |
| 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 mess
ages. |
| 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 subclasse
s. |
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 ha
ndle 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 cu
stom 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. |
| 115 * This string must be ASCII characters only, so that its wide-character ve
rsion displays identically. |
55 */ | 116 */ |
56 Session( MSIHANDLE handle, std::wstring name ) ; | 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. |
| 121 * |
| 122 * The life cycle of the session handle is not the responsibility of the base
class. |
| 123 * In an interactive session, the handle is provided as an argument to the cus
tom action entry point, and we do not manage its life cycle. |
| 124 * In an offline session, the handle is created in the (subclass) constructor. |
61 */ | 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 ac
tion. |
67 */ | 131 */ |
68 std::wstring log_prefix ; | 132 std::string log_prefix ; |
| 133 |
| 134 /** |
| 135 * Prefix for log messages, wide string. Contains the name of the custom actio
n. |
| 136 */ |
| 137 std::wstring log_prefix_w ; |
69 | 138 |
70 /** | 139 /** |
71 * Private copy constructor is declared but not defined. | 140 * Private copy constructor is declared but not defined. |
| 141 * |
| 142 * C++11: declare with <b>= delete</b>. |
72 */ | 143 */ |
73 Session( const Session & ) ; | 144 Session( const Session & ) ; |
74 | 145 |
75 /** | 146 /** |
| 147 * Write a message with MsiProcessMessage and throw no exceptions. |
| 148 * |
| 149 * This is declared private because there are very few cases in which no-excep
tion behavior is required. |
| 150 * |
| 151 * C++11: declare with **noexcept**. |
| 152 */ |
| 153 int write_message_noexcept( Message & m ) ; |
| 154 |
| 155 /** |
76 * Private assignment operator is declared but not defined. | 156 * Private assignment operator is declared but not defined. |
| 157 * |
| 158 * C++11: declare with <b>= delete</b>. |
77 */ | 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 cu
stom 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. |
| 186 * |
| 187 * **noexcept** declaration to be added for C++11. |
104 */ | 188 */ |
105 Immediate_Session( MSIHANDLE handle, std::wstring name ) ; | 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
to 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. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/wi
ndows/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 |