export_output_file.h 1.2 KB

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