OLD | NEW |
1 /** | 1 /** |
2 * \file session.cpp Implementation of Session class. | 2 * \file session.cpp Implementation of Session class. |
3 */ | 3 */ |
4 | 4 |
5 #include "installer-lib.h" | 5 #include "installer-lib.h" |
6 #include "session.h" | 6 #include "session.h" |
7 #include "property.h" | 7 #include "property.h" |
8 #include "msiquery.h" | 8 #include "msiquery.h" |
9 | 9 |
10 //------------------------------------------------------------------------------
----------- | 10 //------------------------------------------------------------------------------
----------- |
11 // Message | 11 // Message |
12 //------------------------------------------------------------------------------
----------- | 12 //------------------------------------------------------------------------------
----------- |
13 Message::Message( std::string message, INSTALLMESSAGE messageType ) | 13 Message::Message(std::string message, INSTALLMESSAGE messageType) |
14 : r( 1 ), MessageTypeCode( messageType ) | 14 : r(1), MessageTypeCode(messageType) |
15 { | 15 { |
16 r.AssignString( 0, message ) ; | 16 r.AssignString(0, message); |
17 } | 17 } |
18 | 18 |
19 Message::Message( std::wstring message, INSTALLMESSAGE messageType ) | 19 Message::Message(std::wstring message, INSTALLMESSAGE messageType) |
20 : r( 1 ), MessageTypeCode( messageType ) | 20 : r(1), MessageTypeCode(messageType) |
21 { | 21 { |
22 r.AssignString( 0, message ) ; | 22 r.AssignString(0, message); |
23 } | 23 } |
24 | 24 |
25 //------------------------------------------------------------------------------
----------- | 25 //------------------------------------------------------------------------------
----------- |
26 // Session | 26 // Session |
27 //------------------------------------------------------------------------------
----------- | 27 //------------------------------------------------------------------------------
----------- |
28 Session::Session( MSIHANDLE handle, std::string name ) | 28 Session::Session(MSIHANDLE handle, std::string name) |
29 : handle( handle ), | 29 : handle(handle), |
30 logPrefix( name + ": " ) | 30 logPrefix(name + ": ") |
31 { | 31 { |
32 logPrefixW.assign( name.begin(), name.end() ) ; | 32 logPrefixW.assign(name.begin(), name.end()); |
33 logPrefixW += L": " ; | 33 logPrefixW += L": "; |
34 LogNoexcept( "Entering custom action" ) ; | 34 LogNoexcept("Entering custom action"); |
35 } | 35 } |
36 | 36 |
37 Session::~Session() | 37 Session::~Session() |
38 { | 38 { |
39 LogNoexcept( "Exiting custom action" ) ; | 39 LogNoexcept("Exiting custom action"); |
40 } | 40 } |
41 | 41 |
42 /** | 42 /** |
43 * A message for the installation log. | 43 * A message for the installation log. |
44 * | 44 * |
45 * Writing to the installation log uses MsiProcessMessage just like interactive d
ialog boxes do. | 45 * Writing to the installation log uses MsiProcessMessage just like interactive d
ialog boxes do. |
46 * | 46 * |
47 * This class is not exposed outside this compilation unit because everything it
can do is already exposed by the log functions. | 47 * This class is not exposed outside this compilation unit because everything it
can do is already exposed by the log functions. |
48 */ | 48 */ |
49 struct LogMessage | 49 struct LogMessage |
50 : public Message | 50 : public Message |
51 { | 51 { |
52 LogMessage ( std::wstring message ) | 52 LogMessage(std::wstring message) |
53 : Message( message, INSTALLMESSAGE_INFO ) | 53 : Message(message, INSTALLMESSAGE_INFO) |
54 {} | 54 {} |
55 | 55 |
56 LogMessage ( std::string message ) | 56 LogMessage(std::string message) |
57 : Message( message, INSTALLMESSAGE_INFO ) | 57 : Message(message, INSTALLMESSAGE_INFO) |
58 {} | 58 {} |
59 } ; | 59 }; |
60 | 60 |
61 void Session::Log( std::string message ) | 61 void Session::Log(std::string message) |
62 { | 62 { |
63 WriteMessage( LogMessage( logPrefix + message ) ) ; | 63 WriteMessage(LogMessage(logPrefix + message)); |
64 } | 64 } |
65 | 65 |
66 void Session::Log( std::wstring message ) | 66 void Session::Log(std::wstring message) |
67 { | 67 { |
68 WriteMessage( LogMessage( logPrefixW + message ) ) ; | 68 WriteMessage(LogMessage(logPrefixW + message)); |
69 } | 69 } |
70 | 70 |
71 void Session::LogNoexcept( std::string message ) | 71 void Session::LogNoexcept(std::string message) |
72 { | 72 { |
73 WriteMessageNoexcept( LogMessage( logPrefix + message ) ) ; | 73 WriteMessageNoexcept(LogMessage(logPrefix + message)); |
74 } | 74 } |
75 | 75 |
76 int Session::WriteMessage( Message & m ) | 76 int Session::WriteMessage(Message& m) |
77 { | 77 { |
78 int x = WriteMessageNoexcept( m ) ; | 78 int x = WriteMessageNoexcept(m); |
79 if ( x == -1 ) | 79 if (x == -1) |
80 { | 80 { |
81 throw WindowsApiError( "MsiProcessMessage", x, "attempt to write to log file
" ) ; | 81 throw WindowsApiError("MsiProcessMessage", x, "attempt to write to log file"
); |
82 } | 82 } |
83 return x ; | 83 return x; |
84 } | 84 } |
85 | 85 |
86 int Session::WriteMessageNoexcept( Message & m ) | 86 int Session::WriteMessageNoexcept(Message& m) |
87 { | 87 { |
88 return MsiProcessMessage( handle, m.MessageTypeCode, m.r.Handle() ) ; | 88 return MsiProcessMessage(handle, m.MessageTypeCode, m.r.Handle()); |
89 } | 89 } |
90 | 90 |
91 //------------------------------------------------------------------------------
----------- | 91 //------------------------------------------------------------------------------
----------- |
92 // ImmediateSession | 92 // ImmediateSession |
93 //------------------------------------------------------------------------------
----------- | 93 //------------------------------------------------------------------------------
----------- |
94 ImmediateSession::ImmediateSession( MSIHANDLE handle, std::string name ) | 94 ImmediateSession::ImmediateSession(MSIHANDLE handle, std::string name) |
95 : Session( handle, name ) | 95 : Session(handle, name) |
96 {} | 96 {} |
OLD | NEW |