filesystem.h 5.44 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
 */
#define DATOVKA_BASE_DIR_NAME "Datovka"
33 34 35
#define DATOVKA_SEND_DIR_NAME "Send"
#define DATOVKA_CERT_DIR_NAME "Cert"
#define DATOVKA_LOGS_DIR_NAME "Logs"
36 37
#define DATOVKA_MAIL_DIR_NAME "Email"
#define DATOVKA_TEMP_DIR_NAME "Temp"
38

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

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

52 53 54 55 56 57 58
/*!
 * @brief Return path to location where the application stores send files.
 *
 * @return Full path.
 */
QString appSendDirPath(void);

59
/*!
60
 * @brief Return path to location where the application stores certificates.
61
 *
62
 * @return Full path.
63
 */
64
QString appCertDirPath(void);
65

66
/*!
67 68
 * @brief Return path to location where email content (attachments) can be
 *     stored.
69
 *
70 71
 * @param[in] msgIdStr String containing message identifier.
 * @return Full path containing the supplied identifier.
72
 */
73
QString appEmailDirPath(const QString &msgIdStr);
74

75 76 77 78 79 80 81
/*!
 * @brief Return path to location where the application stores log files.
 *
 * @return Full path.
 */
QString appLogDirPath(void);

82
/*!
83 84
 * @brief Return path to location where attachments of a particular message
 *     can be stored.
85
 *
86 87
 * @param[in] msgIdStr String containing message identifier.
 * @return Full path containing the supplied identifier.
88
 */
89
QString appMsgAttachDirPath(const QString &msgIdStr);
90

91 92 93 94 95 96 97 98 99
/*!
 * @brief Return path to location where attachments of a particular message
 *     can be stored for iOS.
 *
 * @param[in] msgIdStr String containing message identifier.
 * @return Full path containing the supplied identifier.
 */
QString appMsgAttachDirPathiOS(const QString &msgIdStr);

100
/*!
101
 * @brief Return path to location where temporary files can be stored.
102
 *
103
 * @return Full path to temporary folder.
104
 */
105
QString appTmpDirPath(void);
106 107

/*!
108 109
 * @brief Remove directory from application document storage including its
 *     content.
110
 *
111
 * @param[in] dirName Directory name.
112
 */
113
void removeDirFromDocLoc(const QString &dirName);
114 115

/*!
116
 * @brief Returns name of existing directory to store data to.
117
 *
118 119 120
 * @param[in] type Location type, must match supported QStandardPaths::StandardLocation.
 * @return Directory name of existing directory or empty string on error.
 */
121
QString existingWritableLoc(int type);
122 123 124 125 126

/*!
 * @brief Return path for attachment saving.
 *
 * @return Path to location where attachment can be stored.
127
 */
128
QString dfltAttachSavingLoc(void);
129 130

/*!
131
 * @brief Return default location for database files and datovka.conf.
132
 *
133
 * @return Location path or empty string on error.
134
 */
135
QString dfltDbAndConfigLoc(void);
136

137
/*!
138 139 140
 * @brief Get full paths of ZFO files in supplied directory.
 *
 * @note Does Not follow symbolic links.
141
 *
142 143 144
 * @param[in] dirPath Directory path.
 * @param[in] subdirs Include subdirectories.
 * @return List of full paths of found zfo files.
145
 */
146
QStringList zfoFilesFromDir(const QString &dirPath, bool subdirs);
147

148 149 150 151 152 153 154 155 156
/*!
 * @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);

/*!
157 158 159 160 161
 * @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".
162
 *
163 164 165 166
 * @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.
167
 */
168
QString existingAppPath(const QString &basePath, const QString &dirName);
169 170 171 172 173 174 175 176 177 178 179 180

/*!
 * @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);
181 182 183 184 185 186 187 188 189 190 191 192

/*!
 * @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);