Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / unotools / VersionConfig.hxx
blob5e40b0af8756450a788215d37f6fd8600ded77be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 #pragma once
12 #include <officecfg/Setup.hxx>
13 #include <unotools/configmgr.hxx>
14 #include <o3tl/string_view.hxx>
15 #include <rtl/ustring.hxx>
16 #include <sal/log.hxx>
18 #include <com/sun/star/lang/IllegalArgumentException.hpp>
20 namespace utl
22 /** This method is called when there's a need to determine if the
23 * current version of LibreOffice has been upgraded to a newer one.
25 @param aUpdateVersion This variable is used to determine if
26 LibreOffice's previous version should be updated.
28 static bool isProductVersionUpgraded(bool aUpdateVersion)
30 OUString sSetupVersion = utl::ConfigManager::getProductVersion();
31 sal_Int32 iCurrent = o3tl::toInt32(o3tl::getToken(sSetupVersion, 0, '.')) * 10
32 + o3tl::toInt32(o3tl::getToken(sSetupVersion, 1, '.'));
33 OUString sLastVersion = officecfg::Setup::Product::ooSetupLastVersion::get().value_or("0.0");
34 sal_Int32 iLast = o3tl::toInt32(o3tl::getToken(sLastVersion, 0, '.')) * 10
35 + o3tl::toInt32(o3tl::getToken(sLastVersion, 1, '.'));
36 if (iCurrent > iLast)
38 if (aUpdateVersion)
39 { //update lastversion
40 try
42 std::shared_ptr<comphelper::ConfigurationChanges> batch(
43 comphelper::ConfigurationChanges::create());
44 officecfg::Setup::Product::ooSetupLastVersion::set(sSetupVersion, batch);
45 batch->commit();
47 catch (css::lang::IllegalArgumentException&)
48 { //If the value was readOnly.
49 SAL_WARN("desktop.updater", "Updating property ooSetupLastVersion to version "
50 << sSetupVersion
51 << " failed (read-only property?)");
54 return true;
56 return false;