12a97ec55SAndrew Rist /**************************************************************
2*329107e9Smseidel  *
32a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52a97ec55SAndrew Rist  * distributed with this work for additional information
62a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
92a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*329107e9Smseidel  *
112a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*329107e9Smseidel  *
132a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142a97ec55SAndrew Rist  * software distributed under the License is distributed on an
152a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
172a97ec55SAndrew Rist  * specific language governing permissions and limitations
182a97ec55SAndrew Rist  * under the License.
19*329107e9Smseidel  *
202a97ec55SAndrew Rist  *************************************************************/
212a97ec55SAndrew Rist 
222a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "updatecheckconfig.hxx"
29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <osl/security.hxx>
35cdf0e10cSrcweir #include <osl/time.h>
36cdf0e10cSrcweir #include <osl/file.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #ifdef WNT
39cdf0e10cSrcweir #ifdef _MSC_VER
40cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers
41cdf0e10cSrcweir #pragma warning(disable: 4917)
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <shlobj.h>
44cdf0e10cSrcweir #ifdef _MSC_VER
45cdf0e10cSrcweir #pragma warning(pop)
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace container = com::sun::star::container ;
50cdf0e10cSrcweir namespace beans = com::sun::star::beans ;
51cdf0e10cSrcweir namespace lang = com::sun::star::lang ;
52cdf0e10cSrcweir namespace util = com::sun::star::util ;
53cdf0e10cSrcweir namespace uno = com::sun::star::uno ;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #define LAST_CHECK              "LastCheck"
58cdf0e10cSrcweir #define VERSION_FOUND           "UpdateVersionFound"
59cdf0e10cSrcweir #define UPDATE_VERSION          "UpdateVersion"
60cdf0e10cSrcweir #define UPDATE_BUILDID          "UpdateBuildId"
61cdf0e10cSrcweir #define UPDATE_DESCRIPTION      "UpdateDescription"
62cdf0e10cSrcweir #define DOWNLOAD_URL            "DownloadURL"
63cdf0e10cSrcweir #define IS_DIRECT_DOWNLOAD      "IsDirectDownload"
64cdf0e10cSrcweir #define OLD_VERSION             "UpdateFoundFor"
65cdf0e10cSrcweir #define AUTOCHECK_ENABLED       "AutoCheckEnabled"
66cdf0e10cSrcweir #define AUTODOWNLOAD_ENABLED    "AutoDownloadEnabled"
67cdf0e10cSrcweir #define CHECK_INTERVAL          "CheckInterval"
68cdf0e10cSrcweir #define LOCAL_FILE              "LocalFile"
69cdf0e10cSrcweir #define DOWNLOAD_SIZE           "DownloadSize"
70cdf0e10cSrcweir #define DOWNLOAD_PAUSED         "DownloadPaused"
71cdf0e10cSrcweir #define DOWNLOAD_DESTINATION    "DownloadDestination"
72cdf0e10cSrcweir #define RELEASE_NOTE            "ReleaseNote"
73cdf0e10cSrcweir #define EXTENSION_PREFIX        "Extension_"
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #define PROPERTY_VERSION        UNISTRING("Version")
76cdf0e10cSrcweir 
77*329107e9Smseidel static const sal_Char * const aUpdateEntryProperties[] = {
78*329107e9Smseidel 	UPDATE_VERSION,
79*329107e9Smseidel 	UPDATE_BUILDID,
80*329107e9Smseidel 	UPDATE_DESCRIPTION,
81*329107e9Smseidel 	DOWNLOAD_URL,
82*329107e9Smseidel 	IS_DIRECT_DOWNLOAD,
83*329107e9Smseidel 	RELEASE_NOTE"1",
84*329107e9Smseidel 	RELEASE_NOTE"2",
85*329107e9Smseidel 	RELEASE_NOTE"3",
86*329107e9Smseidel 	RELEASE_NOTE"4",
87*329107e9Smseidel 	RELEASE_NOTE"5",
88*329107e9Smseidel 	OLD_VERSION
89cdf0e10cSrcweir };
90*329107e9Smseidel 
91cdf0e10cSrcweir static const sal_uInt32 nUpdateEntryProperties = sizeof(aUpdateEntryProperties) / sizeof(sal_Char *);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir //------------------------------------------------------------------------------
94cdf0e10cSrcweir 
~NamedValueByNameAccess()95cdf0e10cSrcweir NamedValueByNameAccess::~NamedValueByNameAccess()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //------------------------------------------------------------------------------
100cdf0e10cSrcweir 
101*329107e9Smseidel ::com::sun::star::uno::Any
getValue(const sal_Char * pName)102cdf0e10cSrcweir NamedValueByNameAccess::getValue(const sal_Char * pName)
103cdf0e10cSrcweir {
104*329107e9Smseidel 	const sal_Int32 nLen = m_rValues.getLength();
105*329107e9Smseidel 	for( sal_Int32 n=0; n < nLen; ++n )
106*329107e9Smseidel 	{
107*329107e9Smseidel 		if( m_rValues[n].Name.equalsAscii( pName ) )
108*329107e9Smseidel 			return m_rValues[n].Value;
109*329107e9Smseidel 	}
110*329107e9Smseidel 	return ::com::sun::star::uno::Any();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //------------------------------------------------------------------------------
115cdf0e10cSrcweir 
116cdf0e10cSrcweir bool
isAutoCheckEnabled() const117cdf0e10cSrcweir UpdateCheckROModel::isAutoCheckEnabled() const
118cdf0e10cSrcweir {
119*329107e9Smseidel 	return sal_True == m_aNameAccess.getValue(AUTOCHECK_ENABLED).get< sal_Bool >();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //------------------------------------------------------------------------------
123cdf0e10cSrcweir 
124*329107e9Smseidel bool
isDownloadPaused() const125cdf0e10cSrcweir UpdateCheckROModel::isDownloadPaused() const
126cdf0e10cSrcweir {
127*329107e9Smseidel 	return sal_True == m_aNameAccess.getValue(DOWNLOAD_PAUSED).get< sal_Bool >();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //------------------------------------------------------------------------------
131cdf0e10cSrcweir 
132*329107e9Smseidel rtl::OUString
getStringValue(const sal_Char * pStr) const133cdf0e10cSrcweir UpdateCheckROModel::getStringValue(const sal_Char * pStr) const
134cdf0e10cSrcweir {
135*329107e9Smseidel 	uno::Any aAny( m_aNameAccess.getValue(pStr) );
136*329107e9Smseidel 	rtl::OUString aRet;
137*329107e9Smseidel 
138*329107e9Smseidel 	aAny >>= aRet;
139*329107e9Smseidel 
140*329107e9Smseidel 	return aRet;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir //------------------------------------------------------------------------------
144cdf0e10cSrcweir 
getLocalFileName() const145*329107e9Smseidel rtl::OUString UpdateCheckROModel::getLocalFileName() const
146*329107e9Smseidel {
147*329107e9Smseidel 	return getStringValue(LOCAL_FILE);
148cdf0e10cSrcweir };
149cdf0e10cSrcweir 
150cdf0e10cSrcweir //------------------------------------------------------------------------------
151cdf0e10cSrcweir 
getDownloadSize() const152*329107e9Smseidel sal_Int64 UpdateCheckROModel::getDownloadSize() const
153*329107e9Smseidel {
154*329107e9Smseidel 	uno::Any aAny( m_aNameAccess.getValue(DOWNLOAD_SIZE) );
155*329107e9Smseidel 	sal_Int64 nRet = -1;
156*329107e9Smseidel 
157*329107e9Smseidel 	aAny >>= nRet;
158*329107e9Smseidel 	return nRet;
159cdf0e10cSrcweir };
160cdf0e10cSrcweir 
161cdf0e10cSrcweir //------------------------------------------------------------------------------
162cdf0e10cSrcweir 
163cdf0e10cSrcweir rtl::OUString
getUpdateEntryVersion() const164cdf0e10cSrcweir UpdateCheckROModel::getUpdateEntryVersion() const
165cdf0e10cSrcweir {
166*329107e9Smseidel 	return getStringValue(OLD_VERSION);
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir //------------------------------------------------------------------------------
170cdf0e10cSrcweir 
171*329107e9Smseidel void
getUpdateEntry(UpdateInfo & rInfo) const172cdf0e10cSrcweir UpdateCheckROModel::getUpdateEntry(UpdateInfo& rInfo) const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     rInfo.BuildId = getStringValue(UPDATE_BUILDID);
175cdf0e10cSrcweir     rInfo.Version = getStringValue(UPDATE_VERSION);
176cdf0e10cSrcweir     rInfo.Description = getStringValue(UPDATE_DESCRIPTION);
177*329107e9Smseidel 
178cdf0e10cSrcweir     sal_Bool isDirectDownload = sal_False;
179cdf0e10cSrcweir     m_aNameAccess.getValue(IS_DIRECT_DOWNLOAD) >>= isDirectDownload;
180*329107e9Smseidel 
181cdf0e10cSrcweir     rInfo.Sources.push_back( DownloadSource( isDirectDownload, getStringValue(DOWNLOAD_URL) ) );
182*329107e9Smseidel 
183cdf0e10cSrcweir     rtl::OString aStr(RELEASE_NOTE);
184cdf0e10cSrcweir     for(sal_Int32 n=1; n < 6; ++n )
185cdf0e10cSrcweir     {
18624c56ab9SHerbert Dürr         rtl::OUString aUStr = getStringValue( (aStr + rtl::OString::valueOf(n)).getStr());
187cdf0e10cSrcweir         if( aUStr.getLength() > 0 )
188cdf0e10cSrcweir             rInfo.ReleaseNotes.push_back(ReleaseNote((sal_Int8) n, aUStr));
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
193cdf0e10cSrcweir //------------------------------------------------------------------------------
194cdf0e10cSrcweir 
getDesktopDirectory()195cdf0e10cSrcweir rtl::OUString UpdateCheckConfig::getDesktopDirectory()
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     rtl::OUString aRet;
198*329107e9Smseidel 
199cdf0e10cSrcweir #ifdef WNT
200cdf0e10cSrcweir     WCHAR szPath[MAX_PATH];
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     if( ! FAILED( SHGetSpecialFolderPathW( NULL, szPath, CSIDL_DESKTOPDIRECTORY, true ) ) )
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         aRet = rtl::OUString( reinterpret_cast< sal_Unicode * >(szPath) );
205cdf0e10cSrcweir         osl::FileBase::getFileURLFromSystemPath( aRet, aRet );
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir #else
208*329107e9Smseidel     // This should become a desktop specific setting in some system backend...
209cdf0e10cSrcweir     rtl::OUString aHomeDir;
210cdf0e10cSrcweir     osl::Security().getHomeDir( aHomeDir );
211cdf0e10cSrcweir     aRet = aHomeDir + rtl::OUString::createFromAscii("/Desktop");
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     // Set path to home directory when there is no /Desktop directory
214cdf0e10cSrcweir     osl::Directory aDocumentsDir( aRet );
215cdf0e10cSrcweir     if( osl::FileBase::E_None != aDocumentsDir.open() )
216cdf0e10cSrcweir         aRet = aHomeDir;
217cdf0e10cSrcweir #endif
218*329107e9Smseidel 
219cdf0e10cSrcweir     return aRet;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //------------------------------------------------------------------------------
223cdf0e10cSrcweir 
getAllUsersDirectory()224cdf0e10cSrcweir rtl::OUString UpdateCheckConfig::getAllUsersDirectory()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     rtl::OUString aRet;
227*329107e9Smseidel 
228cdf0e10cSrcweir #ifdef WNT
229cdf0e10cSrcweir     WCHAR szPath[MAX_PATH];
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     if( ! FAILED( SHGetSpecialFolderPathW( NULL, szPath, CSIDL_COMMON_DOCUMENTS, true ) ) )
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         aRet = rtl::OUString( reinterpret_cast< sal_Unicode * >(szPath) );
234cdf0e10cSrcweir         osl::FileBase::RC rc;
235*329107e9Smseidel         rc = osl::FileBase::getFileURLFromSystemPath( aRet, aRet );
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir #else
238cdf0e10cSrcweir     osl::FileBase::getTempDirURL(aRet);
239cdf0e10cSrcweir #endif
240*329107e9Smseidel 
241cdf0e10cSrcweir     return aRet;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateCheckConfig(const uno::Reference<container::XNameContainer> & xContainer,const uno::Reference<container::XNameContainer> & xAvailableUpdates,const uno::Reference<container::XNameContainer> & xIgnoredUpdates,const::rtl::Reference<UpdateCheckConfigListener> & rListener)245cdf0e10cSrcweir UpdateCheckConfig::UpdateCheckConfig( const uno::Reference<container::XNameContainer>& xContainer,
246cdf0e10cSrcweir                                       const uno::Reference<container::XNameContainer>& xAvailableUpdates,
247cdf0e10cSrcweir                                       const uno::Reference<container::XNameContainer>& xIgnoredUpdates,
248cdf0e10cSrcweir                                       const ::rtl::Reference< UpdateCheckConfigListener >& rListener ) :
249cdf0e10cSrcweir     m_xContainer( xContainer ),
250cdf0e10cSrcweir     m_xAvailableUpdates( xAvailableUpdates ),
251cdf0e10cSrcweir     m_xIgnoredUpdates( xIgnoredUpdates ),
252cdf0e10cSrcweir     m_rListener( rListener )
253cdf0e10cSrcweir {}
254cdf0e10cSrcweir 
255cdf0e10cSrcweir //------------------------------------------------------------------------------
~UpdateCheckConfig()256cdf0e10cSrcweir UpdateCheckConfig::~UpdateCheckConfig()
257cdf0e10cSrcweir {}
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //------------------------------------------------------------------------------
260cdf0e10cSrcweir 
261cdf0e10cSrcweir ::rtl::Reference< UpdateCheckConfig >
get(const uno::Reference<uno::XComponentContext> & xContext,const::rtl::Reference<UpdateCheckConfigListener> & rListener)262*329107e9Smseidel UpdateCheckConfig::get(
263cdf0e10cSrcweir     const uno::Reference<uno::XComponentContext>& xContext,
264cdf0e10cSrcweir     const ::rtl::Reference< UpdateCheckConfigListener >& rListener)
265cdf0e10cSrcweir {
266cdf0e10cSrcweir     if( !xContext.is() )
267*329107e9Smseidel         throw uno::RuntimeException(
268*329107e9Smseidel             UNISTRING( "UpdateCheckConfig: empty component context" ),
269cdf0e10cSrcweir             uno::Reference< uno::XInterface >() );
270*329107e9Smseidel 
271cdf0e10cSrcweir     uno::Reference< lang::XMultiComponentFactory > xServiceManager(xContext->getServiceManager());
272*329107e9Smseidel 
273cdf0e10cSrcweir     if( !xServiceManager.is() )
274*329107e9Smseidel         throw uno::RuntimeException(
275*329107e9Smseidel             UNISTRING( "UpdateCheckConfig: unable to obtain service manager from component context" ),
276cdf0e10cSrcweir             uno::Reference< uno::XInterface >() );
277*329107e9Smseidel 
278*329107e9Smseidel     uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
279*329107e9Smseidel         xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.configuration.ConfigurationProvider" ), xContext ),
280*329107e9Smseidel         uno::UNO_QUERY_THROW);
281*329107e9Smseidel 
282cdf0e10cSrcweir     beans::PropertyValue aProperty;
283cdf0e10cSrcweir     aProperty.Name  = UNISTRING( "nodepath" );
284cdf0e10cSrcweir     aProperty.Value = uno::makeAny( UNISTRING("org.openoffice.Office.Jobs/Jobs/UpdateCheck/Arguments") );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgumentList( 1 );
287cdf0e10cSrcweir     aArgumentList[0] = uno::makeAny( aProperty );
288*329107e9Smseidel 
289*329107e9Smseidel     uno::Reference< container::XNameContainer > xContainer(
290*329107e9Smseidel         xConfigProvider->createInstanceWithArguments(
291cdf0e10cSrcweir             UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ),
292cdf0e10cSrcweir         uno::UNO_QUERY_THROW );
293*329107e9Smseidel 
294cdf0e10cSrcweir     aProperty.Value = uno::makeAny( UNISTRING("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/IgnoredUpdates") );
295cdf0e10cSrcweir     aArgumentList[0] = uno::makeAny( aProperty );
296cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xIgnoredExt( xConfigProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ), uno::UNO_QUERY_THROW );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     aProperty.Value = uno::makeAny( UNISTRING("/org.openoffice.Office.ExtensionManager/ExtensionUpdateData/AvailableUpdates") );
299cdf0e10cSrcweir     aArgumentList[0] = uno::makeAny( aProperty );
300cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xUpdateAvail( xConfigProvider->createInstanceWithArguments( UNISTRING("com.sun.star.configuration.ConfigurationUpdateAccess"), aArgumentList ), uno::UNO_QUERY_THROW );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     return new UpdateCheckConfig( xContainer, xUpdateAvail, xIgnoredExt, rListener );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir //------------------------------------------------------------------------------
306cdf0e10cSrcweir 
307*329107e9Smseidel bool
isAutoCheckEnabled() const308cdf0e10cSrcweir UpdateCheckConfig::isAutoCheckEnabled() const
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     sal_Bool nValue = sal_False;
311cdf0e10cSrcweir     const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( AUTOCHECK_ENABLED ) ) >>= nValue;
312cdf0e10cSrcweir     return nValue;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir //------------------------------------------------------------------------------
316cdf0e10cSrcweir 
317*329107e9Smseidel bool
isAutoDownloadEnabled() const318cdf0e10cSrcweir UpdateCheckConfig::isAutoDownloadEnabled() const
319cdf0e10cSrcweir {
320cdf0e10cSrcweir     sal_Bool nValue = sal_False;
321cdf0e10cSrcweir     const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( AUTODOWNLOAD_ENABLED ) ) >>= nValue;
322cdf0e10cSrcweir     return nValue;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir //------------------------------------------------------------------------------
326cdf0e10cSrcweir 
327*329107e9Smseidel rtl::OUString
getUpdateEntryVersion() const328cdf0e10cSrcweir UpdateCheckConfig::getUpdateEntryVersion() const
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     rtl::OUString aValue;
331*329107e9Smseidel 
332cdf0e10cSrcweir     // getByName is defined as non const in XNameAccess
333cdf0e10cSrcweir     const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( OLD_VERSION ) ) >>= aValue;
334*329107e9Smseidel 
335*329107e9Smseidel     return aValue;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir //------------------------------------------------------------------------------
339cdf0e10cSrcweir 
340cdf0e10cSrcweir sal_Int64
getLastChecked() const341cdf0e10cSrcweir UpdateCheckConfig::getLastChecked() const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     sal_Int64 nValue = 0;
344*329107e9Smseidel 
345cdf0e10cSrcweir     // getByName is defined as non const in XNameAccess
346cdf0e10cSrcweir     const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( LAST_CHECK ) ) >>= nValue;
347*329107e9Smseidel 
348cdf0e10cSrcweir     return nValue;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //------------------------------------------------------------------------------
352cdf0e10cSrcweir 
353cdf0e10cSrcweir sal_Int64
getCheckInterval() const354cdf0e10cSrcweir UpdateCheckConfig::getCheckInterval() const
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     sal_Int64 nValue = 0;
357*329107e9Smseidel 
358cdf0e10cSrcweir     // getByName is defined as non const in XNameAccess
359cdf0e10cSrcweir     const_cast < UpdateCheckConfig *> (this)->getByName( UNISTRING( CHECK_INTERVAL ) ) >>= nValue;
360*329107e9Smseidel 
361cdf0e10cSrcweir     return nValue;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir //------------------------------------------------------------------------------
365cdf0e10cSrcweir 
366*329107e9Smseidel rtl::OUString
getLocalFileName() const367cdf0e10cSrcweir UpdateCheckConfig::getLocalFileName() const
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     rtl::OUString aName = UNISTRING(LOCAL_FILE);
370cdf0e10cSrcweir     rtl::OUString aRet;
371*329107e9Smseidel 
372cdf0e10cSrcweir     if( m_xContainer->hasByName(aName) )
373cdf0e10cSrcweir         m_xContainer->getByName(aName) >>= aRet;
374*329107e9Smseidel 
375*329107e9Smseidel     return aRet;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir //------------------------------------------------------------------------------
379cdf0e10cSrcweir 
380*329107e9Smseidel rtl::OUString
getDownloadDestination() const381cdf0e10cSrcweir UpdateCheckConfig::getDownloadDestination() const
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     rtl::OUString aName = UNISTRING(DOWNLOAD_DESTINATION);
384cdf0e10cSrcweir     rtl::OUString aRet;
385*329107e9Smseidel 
386cdf0e10cSrcweir     const_cast <UpdateCheckConfig *> (this)->getByName(aName) >>= aRet;
387*329107e9Smseidel 
388*329107e9Smseidel     return aRet;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir //------------------------------------------------------------------------------
392cdf0e10cSrcweir 
393*329107e9Smseidel void
storeLocalFileName(const rtl::OUString & rLocalFileName,sal_Int64 nFileSize)394cdf0e10cSrcweir UpdateCheckConfig::storeLocalFileName(const rtl::OUString& rLocalFileName, sal_Int64 nFileSize)
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     const sal_uInt8 nItems = 2;
397cdf0e10cSrcweir     const rtl::OUString aNameList[nItems] = { UNISTRING(LOCAL_FILE), UNISTRING(DOWNLOAD_SIZE) };
398cdf0e10cSrcweir     const uno::Any aValueList[nItems] = { uno::makeAny(rLocalFileName), uno::makeAny(nFileSize) };
399*329107e9Smseidel 
400cdf0e10cSrcweir     for( sal_uInt8 i=0; i < nItems; ++i )
401cdf0e10cSrcweir     {
402cdf0e10cSrcweir         if( m_xContainer->hasByName(aNameList[i]) )
403cdf0e10cSrcweir             m_xContainer->replaceByName(aNameList[i], aValueList[i]);
404cdf0e10cSrcweir         else
405cdf0e10cSrcweir             m_xContainer->insertByName(aNameList[i], aValueList[i]);
406cdf0e10cSrcweir     }
407*329107e9Smseidel 
408cdf0e10cSrcweir     commitChanges();
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir //------------------------------------------------------------------------------
412cdf0e10cSrcweir 
413*329107e9Smseidel void
clearLocalFileName()414cdf0e10cSrcweir UpdateCheckConfig::clearLocalFileName()
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     const sal_uInt8 nItems = 2;
417cdf0e10cSrcweir     const rtl::OUString aNameList[nItems] = { UNISTRING(LOCAL_FILE), UNISTRING(DOWNLOAD_SIZE) };
418*329107e9Smseidel 
419cdf0e10cSrcweir     for( sal_uInt8 i=0; i < nItems; ++i )
420cdf0e10cSrcweir     {
421cdf0e10cSrcweir         if( m_xContainer->hasByName(aNameList[i]) )
422cdf0e10cSrcweir             m_xContainer->removeByName(aNameList[i]);
423cdf0e10cSrcweir     }
424*329107e9Smseidel 
425cdf0e10cSrcweir     commitChanges();
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir //------------------------------------------------------------------------------
429cdf0e10cSrcweir 
430*329107e9Smseidel void
storeDownloadPaused(bool paused)431cdf0e10cSrcweir UpdateCheckConfig::storeDownloadPaused(bool paused)
432cdf0e10cSrcweir {
433cdf0e10cSrcweir     replaceByName(UNISTRING(DOWNLOAD_PAUSED) , uno::makeAny(paused));
434cdf0e10cSrcweir     commitChanges();
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir //------------------------------------------------------------------------------
438cdf0e10cSrcweir 
439cdf0e10cSrcweir void
updateLastChecked()440cdf0e10cSrcweir UpdateCheckConfig::updateLastChecked()
441cdf0e10cSrcweir {
442cdf0e10cSrcweir     TimeValue systime;
443cdf0e10cSrcweir     osl_getSystemTime(&systime);
444*329107e9Smseidel 
445cdf0e10cSrcweir     sal_Int64 lastCheck = systime.Seconds;
446cdf0e10cSrcweir 
447*329107e9Smseidel     replaceByName(UNISTRING(LAST_CHECK), uno::makeAny(lastCheck));
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir //------------------------------------------------------------------------------
451cdf0e10cSrcweir 
452cdf0e10cSrcweir void
storeUpdateFound(const UpdateInfo & rInfo,const rtl::OUString & aCurrentBuild)453cdf0e10cSrcweir UpdateCheckConfig::storeUpdateFound( const UpdateInfo& rInfo, const rtl::OUString& aCurrentBuild)
454cdf0e10cSrcweir 
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     bool autoDownloadEnabled = isAutoDownloadEnabled();
457*329107e9Smseidel 
458*329107e9Smseidel     uno::Any aValues[nUpdateEntryProperties] =
459*329107e9Smseidel     {
460*329107e9Smseidel         uno::makeAny(rInfo.Version),
461*329107e9Smseidel         uno::makeAny(rInfo.BuildId),
462cdf0e10cSrcweir         uno::makeAny(rInfo.Description),
463*329107e9Smseidel         uno::makeAny(rInfo.Sources[0].URL),
464cdf0e10cSrcweir         uno::makeAny(rInfo.Sources[0].IsDirect ? sal_True : sal_False),
465cdf0e10cSrcweir         uno::makeAny(getReleaseNote(rInfo, 1, autoDownloadEnabled) ),
466cdf0e10cSrcweir         uno::makeAny(getReleaseNote(rInfo, 2, autoDownloadEnabled) ),
467cdf0e10cSrcweir         uno::makeAny(getReleaseNote(rInfo, 3, autoDownloadEnabled) ),
468cdf0e10cSrcweir         uno::makeAny(getReleaseNote(rInfo, 4, autoDownloadEnabled) ),
469cdf0e10cSrcweir         uno::makeAny(getReleaseNote(rInfo, 5, autoDownloadEnabled) ),
470*329107e9Smseidel         uno::makeAny(aCurrentBuild)
471cdf0e10cSrcweir     };
472*329107e9Smseidel 
473cdf0e10cSrcweir     rtl::OUString aName;
474cdf0e10cSrcweir     for( sal_uInt32 n=0; n < nUpdateEntryProperties; ++n )
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir         aName = rtl::OUString::createFromAscii(aUpdateEntryProperties[n]);
477*329107e9Smseidel 
478cdf0e10cSrcweir         if( m_xContainer->hasByName(aName) )
479cdf0e10cSrcweir             m_xContainer->replaceByName(aName, aValues[n]);
480cdf0e10cSrcweir         else
481cdf0e10cSrcweir             m_xContainer->insertByName(aName,aValues[n]);
482cdf0e10cSrcweir     }
483*329107e9Smseidel 
484cdf0e10cSrcweir     commitChanges();
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir //------------------------------------------------------------------------------
488cdf0e10cSrcweir 
489*329107e9Smseidel void
clearUpdateFound()490cdf0e10cSrcweir UpdateCheckConfig::clearUpdateFound()
491cdf0e10cSrcweir {
492cdf0e10cSrcweir     rtl::OUString aName;
493*329107e9Smseidel 
494cdf0e10cSrcweir     for( sal_uInt32 n=0; n < nUpdateEntryProperties; ++n )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         aName = rtl::OUString::createFromAscii(aUpdateEntryProperties[n]);
497*329107e9Smseidel 
498cdf0e10cSrcweir         try {
499cdf0e10cSrcweir             if( m_xContainer->hasByName(aName) )
500cdf0e10cSrcweir                 m_xContainer->removeByName(aName);
501cdf0e10cSrcweir         } catch(const lang::WrappedTargetException& ) {
502cdf0e10cSrcweir             // Can not remove value, probably in share layer
503cdf0e10cSrcweir             OSL_ASSERT(false);
504cdf0e10cSrcweir             m_xContainer->replaceByName(aName, uno::makeAny(rtl::OUString()));
505cdf0e10cSrcweir         }
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir     /* As we have removed UpdateVersionFound from the shared configuration
509cdf0e10cSrcweir      * existing entries in the user layer do not have a oor operation and
510*329107e9Smseidel      * thus are completely ignored (which also means they can not be removed).
511cdf0e10cSrcweir      */
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     commitChanges();
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir //------------------------------------------------------------------------------
517cdf0e10cSrcweir 
518*329107e9Smseidel uno::Sequence< rtl::OUString >
getServiceNames()519cdf0e10cSrcweir UpdateCheckConfig::getServiceNames()
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aServiceList(1);
522cdf0e10cSrcweir     aServiceList[0] = UNISTRING( "com.sun.star.setup.UpdateCheckConfig");
523cdf0e10cSrcweir     return aServiceList;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir //------------------------------------------------------------------------------
527cdf0e10cSrcweir 
528*329107e9Smseidel rtl::OUString
getImplName()529cdf0e10cSrcweir UpdateCheckConfig::getImplName()
530*329107e9Smseidel {
531cdf0e10cSrcweir     return UNISTRING( "vnd.sun.UpdateCheckConfig");
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
534cdf0e10cSrcweir //------------------------------------------------------------------------------
535cdf0e10cSrcweir 
536*329107e9Smseidel uno::Type SAL_CALL
getElementType()537*329107e9Smseidel UpdateCheckConfig::getElementType() throw (uno::RuntimeException)
538*329107e9Smseidel {
539*329107e9Smseidel     return m_xContainer->getElementType();
540cdf0e10cSrcweir }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir //------------------------------------------------------------------------------
543cdf0e10cSrcweir 
544*329107e9Smseidel sal_Bool SAL_CALL
hasElements()545*329107e9Smseidel UpdateCheckConfig::hasElements() throw (uno::RuntimeException)
546*329107e9Smseidel {
547*329107e9Smseidel     return m_xContainer->hasElements();
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir //------------------------------------------------------------------------------
551cdf0e10cSrcweir 
552*329107e9Smseidel uno::Any SAL_CALL
getByName(const::rtl::OUString & aName)553*329107e9Smseidel UpdateCheckConfig::getByName( const ::rtl::OUString& aName )
554*329107e9Smseidel     throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     uno::Any aValue = m_xContainer->getByName( aName );
557*329107e9Smseidel 
558cdf0e10cSrcweir     // Provide dynamic default value
559cdf0e10cSrcweir     if( aName.equalsAscii(DOWNLOAD_DESTINATION) )
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir         rtl::OUString aStr;
562cdf0e10cSrcweir         aValue >>= aStr;
563*329107e9Smseidel 
564cdf0e10cSrcweir         if( aStr.getLength() == 0 )
565cdf0e10cSrcweir             aValue = uno::makeAny(getDesktopDirectory());
566cdf0e10cSrcweir     }
567*329107e9Smseidel 
568cdf0e10cSrcweir     return aValue;
569cdf0e10cSrcweir }
570*329107e9Smseidel 
571cdf0e10cSrcweir //------------------------------------------------------------------------------
572cdf0e10cSrcweir 
573*329107e9Smseidel uno::Sequence< ::rtl::OUString > SAL_CALL
getElementNames()574cdf0e10cSrcweir UpdateCheckConfig::getElementNames(  ) throw (uno::RuntimeException)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     return m_xContainer->getElementNames();
577cdf0e10cSrcweir }
578*329107e9Smseidel 
579cdf0e10cSrcweir //------------------------------------------------------------------------------
580*329107e9Smseidel 
581*329107e9Smseidel sal_Bool SAL_CALL
hasByName(const::rtl::OUString & aName)582cdf0e10cSrcweir UpdateCheckConfig::hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
583cdf0e10cSrcweir {
584cdf0e10cSrcweir     return m_xContainer->hasByName( aName );
585cdf0e10cSrcweir }
586*329107e9Smseidel 
587cdf0e10cSrcweir //------------------------------------------------------------------------------
588*329107e9Smseidel 
589*329107e9Smseidel void SAL_CALL
replaceByName(const::rtl::OUString & aName,const uno::Any & aElement)590cdf0e10cSrcweir UpdateCheckConfig::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement )
591*329107e9Smseidel     throw (lang::IllegalArgumentException, container::NoSuchElementException,
592cdf0e10cSrcweir            lang::WrappedTargetException, uno::RuntimeException)
593cdf0e10cSrcweir {
594*329107e9Smseidel     return m_xContainer->replaceByName( aName, aElement );
595cdf0e10cSrcweir }
596cdf0e10cSrcweir 
597cdf0e10cSrcweir //------------------------------------------------------------------------------
598cdf0e10cSrcweir // XChangesBatch
599cdf0e10cSrcweir 
600*329107e9Smseidel void SAL_CALL
commitChanges()601*329107e9Smseidel UpdateCheckConfig::commitChanges()
602cdf0e10cSrcweir     throw (lang::WrappedTargetException, uno::RuntimeException)
603cdf0e10cSrcweir {
604cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
605cdf0e10cSrcweir     if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
606cdf0e10cSrcweir     {
607cdf0e10cSrcweir         util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
608cdf0e10cSrcweir         xChangesBatch->commitChanges();
609cdf0e10cSrcweir 
610cdf0e10cSrcweir         if( m_rListener.is() )
611cdf0e10cSrcweir         {
612cdf0e10cSrcweir             const sal_Int32 nChanges = aChangesSet.getLength();
613cdf0e10cSrcweir             rtl::OUString aString;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir             for( sal_Int32 i=0; i<nChanges; ++i )
616cdf0e10cSrcweir             {
617cdf0e10cSrcweir                 aChangesSet[i].Accessor >>= aString;
618*329107e9Smseidel 
619cdf0e10cSrcweir                 // FIXME: use non IgnoreAsciiCase version as soon as it becomes available
620cdf0e10cSrcweir                 if( aString.endsWithIgnoreAsciiCaseAsciiL(AUTOCHECK_ENABLED "']", sizeof(AUTOCHECK_ENABLED)+1) )
621cdf0e10cSrcweir                 {
622cdf0e10cSrcweir                     sal_Bool bEnabled = sal_False;
623cdf0e10cSrcweir                     aChangesSet[i].Element >>= bEnabled;
624cdf0e10cSrcweir                     m_rListener->autoCheckStatusChanged(sal_True == bEnabled);
625cdf0e10cSrcweir                 }
626cdf0e10cSrcweir                 // FIXME: use non IgnoreAsciiCase version as soon as it becomes available
627cdf0e10cSrcweir                 else if( aString.endsWithIgnoreAsciiCaseAsciiL(CHECK_INTERVAL "']", sizeof(CHECK_INTERVAL)+1) )
628cdf0e10cSrcweir                 {
629cdf0e10cSrcweir                     m_rListener->autoCheckIntervalChanged();
630cdf0e10cSrcweir                 }
631cdf0e10cSrcweir             }
632cdf0e10cSrcweir         }
633cdf0e10cSrcweir     }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir     xChangesBatch = uno::Reference< util::XChangesBatch > ( m_xAvailableUpdates, uno::UNO_QUERY );
636cdf0e10cSrcweir     if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
637cdf0e10cSrcweir     {
638cdf0e10cSrcweir         util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
639cdf0e10cSrcweir         xChangesBatch->commitChanges();
640cdf0e10cSrcweir     }
641cdf0e10cSrcweir     xChangesBatch = uno::Reference< util::XChangesBatch > ( m_xIgnoredUpdates, uno::UNO_QUERY );
642cdf0e10cSrcweir     if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() )
643cdf0e10cSrcweir     {
644cdf0e10cSrcweir         util::ChangesSet aChangesSet = xChangesBatch->getPendingChanges();
645cdf0e10cSrcweir         xChangesBatch->commitChanges();
646cdf0e10cSrcweir     }
647cdf0e10cSrcweir }
648cdf0e10cSrcweir 
649cdf0e10cSrcweir //------------------------------------------------------------------------------
650cdf0e10cSrcweir 
651*329107e9Smseidel sal_Bool SAL_CALL
hasPendingChanges()652cdf0e10cSrcweir UpdateCheckConfig::hasPendingChanges(  ) throw (uno::RuntimeException)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
655cdf0e10cSrcweir     if( xChangesBatch.is() )
656cdf0e10cSrcweir         return xChangesBatch->hasPendingChanges();
657*329107e9Smseidel 
658cdf0e10cSrcweir     return sal_False;
659cdf0e10cSrcweir }
660*329107e9Smseidel 
661cdf0e10cSrcweir //------------------------------------------------------------------------------
662*329107e9Smseidel 
663*329107e9Smseidel uno::Sequence< util::ElementChange > SAL_CALL
getPendingChanges()664cdf0e10cSrcweir UpdateCheckConfig::getPendingChanges(  ) throw (uno::RuntimeException)
665cdf0e10cSrcweir {
666cdf0e10cSrcweir     uno::Reference< util::XChangesBatch > xChangesBatch(m_xContainer, uno::UNO_QUERY);
667cdf0e10cSrcweir     if( xChangesBatch.is() )
668cdf0e10cSrcweir         return xChangesBatch->getPendingChanges();
669*329107e9Smseidel 
670cdf0e10cSrcweir     return uno::Sequence< util::ElementChange >();
671cdf0e10cSrcweir }
672cdf0e10cSrcweir 
673cdf0e10cSrcweir //------------------------------------------------------------------------------
storeExtensionVersion(const rtl::OUString & rExtensionName,const rtl::OUString & rVersion)674cdf0e10cSrcweir bool UpdateCheckConfig::storeExtensionVersion( const rtl::OUString& rExtensionName,
675cdf0e10cSrcweir                                                const rtl::OUString& rVersion )
676cdf0e10cSrcweir {
677cdf0e10cSrcweir     bool bNotify = true;
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     if ( m_xAvailableUpdates->hasByName( rExtensionName ) )
680cdf0e10cSrcweir         uno::Reference< beans::XPropertySet >( m_xAvailableUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->setPropertyValue( PROPERTY_VERSION, uno::Any( rVersion ) );
681cdf0e10cSrcweir     else
682cdf0e10cSrcweir     {
683cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > elem( uno::Reference< lang::XSingleServiceFactory >( m_xAvailableUpdates, uno::UNO_QUERY_THROW )->createInstance(), uno::UNO_QUERY_THROW );
684cdf0e10cSrcweir         elem->setPropertyValue( PROPERTY_VERSION, uno::Any( rVersion ) );
685cdf0e10cSrcweir         m_xAvailableUpdates->insertByName( rExtensionName, uno::Any( elem ) );
686cdf0e10cSrcweir     }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir     if ( m_xIgnoredUpdates->hasByName( rExtensionName ) )
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         ::rtl::OUString aIgnoredVersion;
691cdf0e10cSrcweir         uno::Any aValue( uno::Reference< beans::XPropertySet >( m_xIgnoredUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
692cdf0e10cSrcweir         aValue >>= aIgnoredVersion;
693cdf0e10cSrcweir         if ( aIgnoredVersion.getLength() == 0 ) // no version means ignore all updates
694cdf0e10cSrcweir             bNotify = false;
695cdf0e10cSrcweir         else if ( aIgnoredVersion == rVersion ) // the user wanted to ignore this update
696cdf0e10cSrcweir             bNotify = false;
697cdf0e10cSrcweir     }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     commitChanges();
700cdf0e10cSrcweir 
701cdf0e10cSrcweir     return bNotify;
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir //------------------------------------------------------------------------------
checkExtensionVersion(const rtl::OUString & rExtensionName,const rtl::OUString & rVersion)705cdf0e10cSrcweir bool UpdateCheckConfig::checkExtensionVersion( const rtl::OUString& rExtensionName,
706cdf0e10cSrcweir                                                const rtl::OUString& rVersion )
707cdf0e10cSrcweir {
708cdf0e10cSrcweir     if ( m_xAvailableUpdates->hasByName( rExtensionName ) )
709cdf0e10cSrcweir     {
710cdf0e10cSrcweir         ::rtl::OUString aStoredVersion;
711cdf0e10cSrcweir         uno::Any aValue( uno::Reference< beans::XPropertySet >( m_xAvailableUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
712cdf0e10cSrcweir         aValue >>= aStoredVersion;
713cdf0e10cSrcweir 
714cdf0e10cSrcweir         if ( m_xIgnoredUpdates->hasByName( rExtensionName ) )
715cdf0e10cSrcweir         {
716cdf0e10cSrcweir             ::rtl::OUString aIgnoredVersion;
717cdf0e10cSrcweir             uno::Any aValue2( uno::Reference< beans::XPropertySet >( m_xIgnoredUpdates->getByName( rExtensionName ), uno::UNO_QUERY_THROW )->getPropertyValue( PROPERTY_VERSION ) );
718cdf0e10cSrcweir             aValue2 >>= aIgnoredVersion;
719cdf0e10cSrcweir             if ( aIgnoredVersion.getLength() == 0 ) // no version means ignore all updates
720cdf0e10cSrcweir                 return false;
721cdf0e10cSrcweir             else if ( aIgnoredVersion == aStoredVersion ) // the user wanted to ignore this update
722cdf0e10cSrcweir                 return false;
723cdf0e10cSrcweir             // TODO: else delete ignored entry?
724cdf0e10cSrcweir         }
725cdf0e10cSrcweir         if ( isVersionGreater( rVersion, aStoredVersion ) )
726cdf0e10cSrcweir             return true;
727cdf0e10cSrcweir         else
728cdf0e10cSrcweir         {
729cdf0e10cSrcweir             m_xAvailableUpdates->removeByName( rExtensionName );
730cdf0e10cSrcweir             commitChanges();
731cdf0e10cSrcweir         }
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     return false;
735cdf0e10cSrcweir }
736cdf0e10cSrcweir 
737cdf0e10cSrcweir //------------------------------------------------------------------------------
getSubVersion(const rtl::OUString & rVersion,sal_Int32 * nIndex)738cdf0e10cSrcweir rtl::OUString UpdateCheckConfig::getSubVersion( const rtl::OUString& rVersion,
739cdf0e10cSrcweir                                                 sal_Int32 *nIndex )
740cdf0e10cSrcweir {
741cdf0e10cSrcweir     while ( *nIndex < rVersion.getLength() && rVersion[*nIndex] == '0')
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         ++*nIndex;
744cdf0e10cSrcweir     }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir     return rVersion.getToken( 0, '.', *nIndex );
747cdf0e10cSrcweir }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir //------------------------------------------------------------------------------
750cdf0e10cSrcweir // checks if the second version string is greater than the first one
751cdf0e10cSrcweir 
isVersionGreater(const rtl::OUString & rVersion1,const rtl::OUString & rVersion2)752cdf0e10cSrcweir bool UpdateCheckConfig::isVersionGreater( const rtl::OUString& rVersion1,
753cdf0e10cSrcweir                                           const rtl::OUString& rVersion2 )
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     for ( sal_Int32 i1 = 0, i2 = 0; i1 >= 0 || i2 >= 0; )
756cdf0e10cSrcweir     {
757cdf0e10cSrcweir         ::rtl::OUString sSub1( getSubVersion( rVersion1, &i1 ) );
758cdf0e10cSrcweir         ::rtl::OUString sSub2( getSubVersion( rVersion2, &i2 ) );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir         if ( sSub1.getLength() < sSub2.getLength() ) {
761cdf0e10cSrcweir             return true;
762*329107e9Smseidel         } else if ( sSub1.getLength() > sSub2.getLength() ) {
763cdf0e10cSrcweir             return false;
764cdf0e10cSrcweir         } else if ( sSub1 < sSub2 ) {
765cdf0e10cSrcweir             return true;
766cdf0e10cSrcweir         } else if ( sSub1 > sSub2 ) {
767cdf0e10cSrcweir             return false;
768cdf0e10cSrcweir         }
769cdf0e10cSrcweir     }
770cdf0e10cSrcweir     return false;
771cdf0e10cSrcweir }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir //------------------------------------------------------------------------------
774cdf0e10cSrcweir //------------------------------------------------------------------------------
775cdf0e10cSrcweir //------------------------------------------------------------------------------
776*329107e9Smseidel 
777*329107e9Smseidel rtl::OUString SAL_CALL
getImplementationName()778*329107e9Smseidel UpdateCheckConfig::getImplementationName() throw (uno::RuntimeException)
779cdf0e10cSrcweir {
780*329107e9Smseidel 	return getImplName();
781cdf0e10cSrcweir }
782*329107e9Smseidel 
783cdf0e10cSrcweir //------------------------------------------------------------------------------
784*329107e9Smseidel 
785*329107e9Smseidel sal_Bool SAL_CALL
supportsService(rtl::OUString const & serviceName)786*329107e9Smseidel UpdateCheckConfig::supportsService(rtl::OUString const & serviceName)
787*329107e9Smseidel 	throw (uno::RuntimeException)
788cdf0e10cSrcweir {
789*329107e9Smseidel 	uno::Sequence< rtl::OUString > aServiceNameList = getServiceNames();
790*329107e9Smseidel 
791*329107e9Smseidel 	for( sal_Int32 n=0; n < aServiceNameList.getLength(); n++ )
792*329107e9Smseidel 		if( aServiceNameList[n].equals(serviceName) )
793*329107e9Smseidel 			return sal_True;
794*329107e9Smseidel 
795*329107e9Smseidel 	return sal_False;
796cdf0e10cSrcweir }
797*329107e9Smseidel 
798cdf0e10cSrcweir //------------------------------------------------------------------------------
799*329107e9Smseidel 
800*329107e9Smseidel uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames()801*329107e9Smseidel UpdateCheckConfig::getSupportedServiceNames() throw (uno::RuntimeException)
802cdf0e10cSrcweir {
803*329107e9Smseidel 	return getServiceNames();
804cdf0e10cSrcweir }
805cdf0e10cSrcweir 
806