1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 
27 #include "checkinstall.hxx"
28 #include <com/sun/star/beans/XExactName.hpp>
29 #include <com/sun/star/beans/XMaterialHolder.hpp>
30 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
31 #include <com/sun/star/util/Date.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <comphelper/processfactory.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <tools/date.hxx>
36 
37 using namespace rtl;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::beans;
41 
42 namespace desktop
43 {
44 
CheckInstallation(OUString & rTitle)45 sal_Bool CheckInstallation( OUString& rTitle )
46 {
47     try
48     {
49 	    Reference< XMultiServiceFactory > xSMgr = ::comphelper::getProcessServiceFactory();
50 	    Reference< XExactName > xExactName( xSMgr->createInstance(
51 								    ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
52 									    "com.sun.star.comp.desktop.Evaluation" ))),
53 								    UNO_QUERY );
54 	    if ( xExactName.is() )
55 	    {
56 		    try
57 		    {
58 			    rTitle = xExactName->getExactName( rTitle );
59 			    Reference< XMaterialHolder > xMaterialHolder( xExactName, UNO_QUERY );
60 			    if ( xMaterialHolder.is() )
61 			    {
62 				    com::sun::star::util::Date aExpirationDate;
63 				    Any a = xMaterialHolder->getMaterial();
64 				    if ( a >>= aExpirationDate )
65 				    {
66 					    Date aToday;
67 					    Date aTimeBombDate( aExpirationDate.Day, aExpirationDate.Month, aExpirationDate.Year );
68 					    if ( aToday > aTimeBombDate )
69 					    {
70 						    InfoBox aInfoBox( NULL, String::CreateFromAscii( "This version has expired" ) );
71 						    aInfoBox.Execute();
72 						    return sal_False;
73 					    }
74 				    }
75 
76 				    return sal_True;
77 			    }
78 			    else
79 			    {
80 				    InfoBox aInfoBox( NULL, rTitle );
81 				    aInfoBox.Execute();
82 				    return sal_False;
83 			    }
84 		    }
85 		    catch ( RuntimeException& )
86 		    {
87 			    // Evaluation version expired!
88 			    return sal_False;
89 		    }
90 	    }
91 	    else
92 	    {
93 		    Reference< com::sun::star::container::XContentEnumerationAccess > rContent( xSMgr , UNO_QUERY );
94 		    if( rContent.is() )
95 		    {
96 			    OUString sEvalService = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.Evaluation" ) );
97 			    Reference < com::sun::star::container::XEnumeration > rEnum = rContent->createContentEnumeration( sEvalService );
98 			    if ( rEnum.is() )
99 			    {
100 				    InfoBox aInfoBox( NULL, rTitle );
101 				    aInfoBox.Execute();
102 				    return sal_False;
103 			    }
104 		    }
105 	    }
106     }
107     catch(Exception)
108     {
109     }
110 
111 	return sal_True;
112 }
113 
114 } // namespace desktop
115