LibreOffice Module unotools (master) 1
VersionConfig.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10#pragma once
11
12#include <officecfg/Setup.hxx>
14#include <o3tl/string_view.hxx>
15
16#include <com/sun/star/lang/IllegalArgumentException.hpp>
17
18namespace utl
19{
26static bool isProductVersionUpgraded(bool aUpdateVersion)
27{
28 OUString sSetupVersion = utl::ConfigManager::getProductVersion();
29 sal_Int32 iCurrent = o3tl::toInt32(o3tl::getToken(sSetupVersion, 0, '.')) * 10
30 + o3tl::toInt32(o3tl::getToken(sSetupVersion, 1, '.'));
31 OUString sLastVersion = officecfg::Setup::Product::ooSetupLastVersion::get().value_or("0.0");
32 sal_Int32 iLast = o3tl::toInt32(o3tl::getToken(sLastVersion, 0, '.')) * 10
33 + o3tl::toInt32(o3tl::getToken(sLastVersion, 1, '.'));
34 if (iCurrent > iLast)
35 {
36 if (aUpdateVersion)
37 { //update lastversion
38 try
39 {
40 std::shared_ptr<comphelper::ConfigurationChanges> batch(
42 officecfg::Setup::Product::ooSetupLastVersion::set(sSetupVersion, batch);
43 batch->commit();
44 }
45 catch (css::lang::IllegalArgumentException&)
46 { //If the value was readOnly.
47 SAL_WARN("desktop.updater", "Updating property ooSetupLastVersion to version "
48 << sSetupVersion
49 << " failed (read-only property?)");
50 }
51 }
52 return true;
53 }
54 return false;
55}
56}
static std::shared_ptr< ConfigurationChanges > create()
static OUString getProductVersion()
Definition: configmgr.cxx:99
#define SAL_WARN(area, stream)
OUString get(TranslateId sContextAndId, const std::locale &loc)
Definition: resmgr.cxx:211
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
static bool isProductVersionUpgraded(bool aUpdateVersion)
This method is called when there's a need to determine if the current version of LibreOffice has been...