filesystem.h 4.99 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
#pragma once
25 26 27 28

#include <QByteArray>
#include <QString>

29
/*!
30
 * @brief Datovka file store directory names.
31 32 33
 */
#define DATOVKA_BASE_DIR_NAME "Datovka"
#define DATOVKA_CERT_DIR_NAME "Certs"
34
#define DATOVKA_LOG_DIR_NAME "Logs"
35 36
#define DATOVKA_MAIL_DIR_NAME "Email"
#define DATOVKA_TEMP_DIR_NAME "Temp"
37

38 39 40 41 42
/*!
 * @brief Max number of log files.
 */
#define DATOVKA_MAX_LOG_FILES 5

43
/*!
44 45 46 47
 * @brief Join two directoris to path.
 * @param[in] dirName1 First directory name.
 * @param[in] dirName2 Second irectory name.
 * @return Directory path.
48
 */
49
QString joinDirs(const QString &dirName1, const QString &dirName2);
50

51
/*!
52
 * @brief Return path to location where the application stores certificates.
53
 *
54
 * @return Full path.
55
 */
56
QString appCertDirPath(void);
57

58
/*!
59 60
 * @brief Return path to location where email content (attachments) can be
 *     stored.
61
 *
62 63
 * @param[in] msgIdStr String containing message identifier.
 * @return Full path containing the supplied identifier.
64
 */
65
QString appEmailDirPath(const QString &msgIdStr);
66

67 68 69 70 71 72 73
/*!
 * @brief Return path to location where the application stores log files.
 *
 * @return Full path.
 */
QString appLogDirPath(void);

74
/*!
75 76
 * @brief Return path to location where attachments of a particular message
 *     can be stored.
77
 *
78 79
 * @param[in] msgIdStr String containing message identifier.
 * @return Full path containing the supplied identifier.
80
 */
81
QString appMsgAttachDirPath(const QString &msgIdStr);
82 83

/*!
84
 * @brief Return path to location where temporary files can be stored.
85
 *
86
 * @return Full path to temporary folder.
87
 */
88
QString appTmpDirPath(void);
89 90

/*!
91 92
 * @brief Remove directory from application document storage including its
 *     content.
93
 *
94
 * @param[in] dirName Directory name.
95
 */
96
void removeDirFromDocLoc(const QString &dirName);
97 98

/*!
99
 * @brief Returns name of existing directory to store data to.
100
 *
101 102 103
 * @param[in] type Location type, must match supported QStandardPaths::StandardLocation.
 * @return Directory name of existing directory or empty string on error.
 */
104
QString existingWritableLoc(int type);
105 106 107 108 109

/*!
 * @brief Return path for attachment saving.
 *
 * @return Path to location where attachment can be stored.
110
 */
111
QString dfltAttachSavingLoc(void);
112 113

/*!
114
 * @brief Return default location for database files and datovka.conf.
115
 *
116
 * @return Location path or empty string on error.
117
 */
118
QString dfltDbAndConfigLoc(void);
119

120
/*!
121 122 123
 * @brief Get full paths of ZFO files in supplied directory.
 *
 * @note Does Not follow symbolic links.
124
 *
125 126 127
 * @param[in] dirPath Directory path.
 * @param[in] subdirs Include subdirectories.
 * @return List of full paths of found zfo files.
128
 */
129
QStringList zfoFilesFromDir(const QString &dirPath, bool subdirs);
130

131 132 133 134 135 136 137 138 139
/*!
 * @brief Check if file with given path exists.
 *
 * @param[in] filePath Full file path.
 * @return Full path with non-conflicting file if file already exists.
 */
QString nonconflictingFileName(QString filePath);

/*!
140 141 142 143 144
 * @brief Return path to directory in supplied base path. Create directory if
 *     it does not exist.
 *
 * @note If "Base" and "Path" are supplied, then the resulting directory is
 *     going to be "Base/DATOVKA_BASE_DIR_NAME/Path".
145
 *
146 147 148 149
 * @param[in] basePath Base path.
 * @param[in] dirName Directory name.
 * @return Full path to directory in supplied base path if directory exists or
 *     it could be created. Empty sting otherwise.
150
 */
151
QString existingAppPath(const QString &basePath, const QString &dirName);
152 153 154 155 156 157 158 159 160 161 162 163

/*!
 * @brief Create file and write data to it.
 *
 * @param[in] filePath File path.
 * @param[in] fileName File name.
 * @param[in] data Data to be written into file.
 * @param[in] deleteOnError Delete created file when cannot be entirely written.
 * @return Full path to written file on success, empty string on failure.
 */
QString writeFile(const QString &filePath, const QString &fileName,
    const QByteArray &data, bool deleteOnError = false);
164 165 166 167 168 169 170 171 172 173 174 175

/*!
 * @brief Delete oldest log file from local storage.
 */
void deleteOldestLogFile(void);

/*!
 * @brief Construct log path and file file.
 *
 * @return Full path including log file name.
 */
QString constructLogFileName(void);