22// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
33
44use super :: ffi;
5- use super :: { MessageType , Record , RunMode , MSIHANDLE } ;
5+ use super :: { Database , MessageType , Record , RunMode , MSIHANDLE } ;
66use std:: ffi:: CString ;
77use std:: ops:: Deref ;
88
@@ -27,10 +27,16 @@ use std::ops::Deref;
2727/// ```
2828pub struct Session {
2929 h : MSIHANDLE ,
30- owned : bool ,
3130}
3231
3332impl Session {
33+ /// Returns the active database for the installation. This function returns a read-only [`Database`].
34+ pub fn database ( & self ) -> Database {
35+ unsafe {
36+ let h = ffi:: MsiGetActiveDatabase ( self . h ) ;
37+ Database :: from ( h)
38+ }
39+ }
3440 /// Runs the specified immediate custom action, or schedules a deferred custom action.
3541 /// If `None` the default action is run e.g., `INSTALL`.
3642 ///
@@ -77,6 +83,11 @@ impl Session {
7783 self . do_action ( Some ( action) ) ;
7884 }
7985
86+ /// The numeric language ID used by the current install session.
87+ pub fn language ( & self ) -> u16 {
88+ unsafe { ffi:: MsiGetLanguage ( self . h ) }
89+ }
90+
8091 /// Processes a [`Record`] within the [`Session`].
8192 pub fn message ( & self , kind : MessageType , record : & Record ) -> i32 {
8293 unsafe { ffi:: MsiProcessMessage ( self . h , kind, * * record) }
@@ -168,20 +179,8 @@ impl Deref for Session {
168179 }
169180}
170181
171- impl Drop for Session {
172- fn drop ( & mut self ) {
173- // An MSIHANDLE must be closed when it was created by opening a package,
174- // but not closed when it was passed to a custom action.
175- if self . owned {
176- unsafe {
177- ffi:: MsiCloseHandle ( self . h ) ;
178- }
179- }
180- }
181- }
182-
183182impl From < MSIHANDLE > for Session {
184183 fn from ( h : MSIHANDLE ) -> Self {
185- Session { h, owned : false }
184+ Session { h }
186185 }
187186}
0 commit comments