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  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_UNOTOOLS_BOOTSTRAP_HXX
21 #define INCLUDED_UNOTOOLS_BOOTSTRAP_HXX
22 
23 #include <unotools/unotoolsdllapi.h>
24 #include <rtl/ustring.hxx>
25 
26 namespace utl
27 {
28     /** provides configuration information needed for application startup.
29 
30         This class handles the startup information for the office application.
31            It encapsulates knowledge of how to retrieve such information and how
32            to diagnose failures to retrieve required data.
33 
34     */
35     class UNOTOOLS_DLLPUBLIC Bootstrap
36     {
37     // the static interface
38     public: // some common information items
39 
40         /// retrieve the product key; defaults to executable name (without extension)
41         static OUString getProductKey();
42 
43         /// retrieve the product key; uses the given default, if not found
44         static OUString getProductKey(OUString const& _sDefault);
45 
46         /// retrieve the BUILDID information item; uses the given default, if not found
47         static OUString getBuildIdData(OUString const& _sDefault);
48 
49         /// retrieve the BuildVersion information item; uses the given default, if not found
50         static OUString getBuildVersion(OUString const& _sDefault);
51 
52         /// reload cached data
53         static void reloadData();
54 
55     public: // retrieve path information about the installation location
56         enum PathStatus
57         {
58             PATH_EXISTS,  // Success: Found a path to an existing file or directory
59             PATH_VALID,   // Found a valid path, but the file or directory does not exist
60             DATA_INVALID, // Retrieved a string for this path, that is not a valid file url or system path
61             DATA_MISSING, // Could not retrieve any data for this path
62             DATA_UNKNOWN  // No attempt to retrieve data for this path was made
63         };
64 
65         /// get a file URL to the common base installation [${insturl}]
66         static PathStatus locateBaseInstallation(OUString& _rURL);
67 
68         /// get a file URL to the user installation [${userurl}]
69         static PathStatus locateUserInstallation(OUString& _rURL);
70 
71         /// get a file URL to the user data directory [default is ${userurl}/user]
72         static PathStatus locateUserData(OUString& _rURL);
73 
74     // the next two items are mainly supported for diagnostic purposes. both items may be unused
75         /// get a file URL to the bootstrap INI file used [e.g. ${insturl}/program/bootraprc]
76         static PathStatus locateBootstrapFile(OUString& _rURL);
77         /// get a file URL to the version locator INI file used [e.g. ${SYSUSERCONFIG}/sversion.ini]
78         static PathStatus locateVersionFile(OUString& _rURL);
79 
80     public: // evaluate the validity of the installation
81         /// high-level status of bootstrap success
82         enum Status
83         {
84             DATA_OK,              /// user-dir and share-dir do exist, product key found or can be defaulted to exe-name
85             MISSING_USER_INSTALL, /// ${userurl} does not exist; or version-file cannot be found or is invalid
86             INVALID_USER_INSTALL, /// can locate ${userurl}, but user-dir is missing
87             INVALID_BASE_INSTALL  /// other failure: e.g. cannot locate share-dir; bootstraprc missing or invalid; no product key
88         };
89 
90         /// error code for detailed diagnostics of bootstrap failures
91         enum FailureCode
92         {
93             NO_FAILURE,                   /// bootstrap was successful
94             MISSING_INSTALL_DIRECTORY,    /// the shared installation directory could not be located
95             MISSING_BOOTSTRAP_FILE,       /// the bootstrap INI file could not be found or read
96             MISSING_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI is missing a required entry
97             INVALID_BOOTSTRAP_FILE_ENTRY, /// the bootstrap INI contains invalid data
98             MISSING_VERSION_FILE,         /// the version locator INI file could not be found or read
99             MISSING_VERSION_FILE_ENTRY,   /// the version locator INI has no entry for this version
100             INVALID_VERSION_FILE_ENTRY,   /// the version locator INI entry is not a valid directory URL
101             MISSING_USER_DIRECTORY,       /// the user installation directory does not exist
102             INVALID_BOOTSTRAP_DATA        /// some bootstrap data was invalid in unexpected ways
103         };
104 
105         /** Evaluates the status of the installation and returns a diagnostic
106             message and error code corresponding to this status
107         */
108         static Status checkBootstrapStatus(OUString& _rDiagnosticMessage, FailureCode& _rErrCode);
109 
110     public:
111         /// get the working directory of the process
112         static bool getProcessWorkingDir(OUString &rUrl);
113 
114     public:
115         // singleton impl-class
116         class Impl;
117         static const Impl& data(); // the data related to the bootstrap.ini file
118     };
119 }
120 
121 #endif
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
124