1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ustrbuf.hxx>
21 #include <unotools/configmgr.hxx>
22 #include <unotools/bootstrap.hxx>
23 #include <unotools/docinfohelper.hxx>
24 #include <rtl/bootstrap.hxx>
25 #include <officecfg/Office/Common.hxx>
27 using namespace ::com::sun::star
;
32 OUString
DocInfoHelper::GetGeneratorString()
34 static const OUString sGenerator
= []()
36 OUString aResultOverride
= officecfg::Office::Common::Save::Document::GeneratorOverride::get();
37 if( !aResultOverride
.isEmpty())
38 return aResultOverride
;
40 OUStringBuffer
aResult(128);
42 // First product: branded name + version
43 // version is <product_versions>_<product_extension>$<platform>
46 OUString
aValue( utl::ConfigManager::getProductName() );
47 if ( !aValue
.isEmpty() )
49 aResult
.append( aValue
.replace( ' ', '_' ) + "/" );
51 aValue
= utl::ConfigManager::getProductVersion();
52 if ( !aValue
.isEmpty() )
54 aResult
.append( aValue
.replace( ' ', '_' ) );
56 aValue
= utl::ConfigManager::getProductExtension();
57 if ( !aValue
.isEmpty() )
59 aResult
.append( aValue
.replace( ' ', '_' ) );
63 OUString
os( u
"$_OS"_ustr
);
64 OUString
arch( u
"$_ARCH"_ustr
);
65 ::rtl::Bootstrap::expandMacros(os
);
66 ::rtl::Bootstrap::expandMacros(arch
);
67 aResult
.append( "$" + os
+ "_" + arch
+ " " );
70 // second product: LibreOffice_project/<build_information>
71 // build_information has '(' and '[' encoded as '$', ')' and ']' ignored
72 // and ':' replaced by '-'
74 aResult
.append( "LibreOffice_project/" );
75 OUString
aBuildId( Bootstrap::getBuildIdData( OUString() ) );
76 for( sal_Int32 i
=0; i
< aBuildId
.getLength(); i
++ )
78 sal_Unicode c
= aBuildId
[i
];
83 aResult
.append( '$' );
89 aResult
.append( '-' );
98 return aResult
.makeStringAndClear();
103 } // end of namespace utl
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */