Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
io_utils.h
1// SPDX-FileCopyrightText: © 2018-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "zrythm-config.h"
7
8#include <filesystem>
9#include <optional>
10
11#include "utils/utf8_string.h"
12
13#include <QTemporaryDir>
14#include <QTemporaryFile>
15
16namespace zrythm::utils::io
17{
18namespace fs = std::filesystem;
19
23utils::Utf8String
24get_path_separator_string ();
25
29std::filesystem::path
30get_home_path ();
31
32std::filesystem::path
33get_temp_path ();
34
47std::filesystem::path
48get_dir (const std::filesystem::path &filename);
49
55void
56mkdir (const std::filesystem::path &dir);
57
63bool
64touch_file (const std::filesystem::path &file_path);
65
66std::filesystem::path
67uri_to_file (const utils::Utf8String &uri);
68
72std::filesystem::path
73file_strip_ext (const std::filesystem::path &filename);
74
78std::filesystem::path
79file_get_ext (const std::filesystem::path &file);
80
91std::filesystem::path
92path_get_basename (const std::filesystem::path &filename);
93
105std::filesystem::path
106path_get_basename_without_ext (const std::filesystem::path &filename);
107
112qint64
113file_get_last_modified_datetime (const std::filesystem::path &filename);
114
115Utf8String
116file_get_last_modified_datetime_as_str (const std::filesystem::path &filename);
117
128bool
129remove (const std::filesystem::path &path);
130
149std::unique_ptr<QTemporaryDir>
150make_tmp_dir (
151 std::optional<QString> template_path = std::nullopt,
152 bool in_temp_dir = true);
153
157inline std::unique_ptr<QTemporaryDir>
158make_tmp_dir_at_path (const std::filesystem::path &absolute_template_path)
159{
160 return make_tmp_dir (
161 Utf8String::from_path (absolute_template_path).to_qstring (), false);
162}
163
173std::unique_ptr<QTemporaryFile>
174make_tmp_file (
175 std::optional<utils::Utf8String> template_path = std::nullopt,
176 bool in_temp_dir = true);
177
186bool
187rmdir (const std::filesystem::path &path, bool force);
188
195std::vector<std::filesystem::path>
196get_files_in_dir_as_basenames (const std::filesystem::path &_dir);
197
205std::vector<std::filesystem::path>
206get_files_in_dir_ending_in (
207 const std::filesystem::path &_dir,
208 bool recursive,
209 const std::optional<utils::Utf8String> &end_string);
210
218std::vector<std::filesystem::path>
219get_files_in_dir (const std::filesystem::path &_dir);
220
232void
233copy_dir (
234 const std::filesystem::path &destdir,
235 const std::filesystem::path &srcdir,
236 bool follow_symlinks,
237 bool recursive);
238
250void
251copy_file (
252 const std::filesystem::path &destfile,
253 const std::filesystem::path &srcfile);
254
263void
264move_file (
265 const std::filesystem::path &destfile,
266 const std::filesystem::path &srcfile,
267 bool force = false);
268
277std::filesystem::path
278get_next_available_filepath (const std::filesystem::path &filepath);
279
287Utf8String
288get_legal_file_name (const Utf8String &file_name);
289
293Utf8String
294get_legal_path_name (const Utf8String &path);
295
296#ifdef _WIN32
300utils::Utf8String
301get_registry_string_val (const utils::Utf8String &key);
302#endif
303
304#if defined(__APPLE__) && ZRYTHM_IS_INSTALLER_VER
310[[gnu::nonnull]] int
311get_bundle_path (char * bundle_path);
312#endif
313
317bool
318path_exists (const std::filesystem::path &path);
319
320bool
321is_file_hidden (const std::filesystem::path &file);
322
328[[nodiscard]] bool
329reflink_file (
330 const std::filesystem::path &dest,
331 const std::filesystem::path &src);
332
340[[nodiscard]] QByteArray
341read_file_contents (const std::filesystem::path &path);
342
350void
351set_file_contents (
352 const std::filesystem::path &path,
353 const char * contents,
354 size_t size);
355
363void
364set_file_contents (
365 const std::filesystem::path &file_path,
366 const utils::Utf8String &data);
367
376QStringList
377split_paths (const QString &paths);
378
379}; // namespace zrythm::utils::io