1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 #include "base/optional.h"
11 
12 #include <QtCore/QFile>
13 #include <QtCore/QString>
14 #include <QtCore/QByteArray>
15 
16 namespace Export {
17 namespace Output {
18 
19 struct Result;
20 class Stats;
21 
22 class File {
23 public:
24 	File(const QString &path, Stats *stats);
25 
26 	[[nodiscard]] int size() const;
27 	[[nodiscard]] bool empty() const;
28 
29 	[[nodiscard]] Result writeBlock(const QByteArray &block);
30 
31 	[[nodiscard]] static QString PrepareRelativePath(
32 		const QString &folder,
33 		const QString &suggested);
34 
35 	[[nodiscard]] static Result Copy(
36 		const QString &source,
37 		const QString &path,
38 		Stats *stats);
39 
40 private:
41 	[[nodiscard]] Result reopen();
42 	[[nodiscard]] Result writeBlockAttempt(const QByteArray &block);
43 
44 	[[nodiscard]] Result error() const;
45 	[[nodiscard]] Result fatalError() const;
46 
47 	QString _path;
48 	int _offset = 0;
49 	std::optional<QFile> _file;
50 
51 	Stats *_stats = nullptr;
52 	bool _inStats = false;
53 
54 };
55 
56 } // namespace Output
57 } // namespace File
58