Files
CPP_Core/Core/Base/File_Helper.h
T
2026-07-24 10:54:45 +08:00

62 lines
1.8 KiB
C++

#pragma once
#include <filesystem>
#include <fstream>
#include <mutex>
#include <string_view>
#include "../system/export.h"
#include "Core/Statistics/Statistics.h"
#include "spdlog/fmt/bundled/os.h"
#include "spdlog/fmt/bundled/std.h"
namespace Psc {
// TODO: 采集文件 对应的 读取文件 回放
// TODO: 可以手动设置 刷新的按钮
// TODO: Text Shower 美化
class File_Gather_Simple {
public:
File_Gather_Simple() = default;
void init(std::string_view path, size_t size);
File_Gather_Simple(std::string_view path, size_t buffer_size);
void append(const std::uint8_t* data, size_t size);
~File_Gather_Simple();
void flush();
private:
std::string abs_path;
std::ofstream ofs;
std::string buffer;
size_t buffer_size{};
};
class File_Player {
public:
File_Player() = default;
explicit File_Player(std::string_view path);
void open(std::string_view path);
void close();
size_t read(std::uint8_t* buffer, size_t size);
[[nodiscard]] bool eof() const;
void rewind();
// 新增功能
[[nodiscard]] std::uint64_t total_size() const;
[[nodiscard]] std::uint64_t current_offset();
[[nodiscard]] std::uint64_t remaining_size();
[[nodiscard]] double progress(); // 0.0 ~ 1.0
private:
std::ifstream ifs;
std::uint64_t total_size_{0};
};
class File_Gather {
public:
File_Gather() = default;
~File_Gather() = default;
File_Gather(std::string_view path, size_t buffer_size);
void init(std::string_view path, size_t buffer_size);
void append(const std::uint8_t* data, size_t size);
void flush() {
gather_file.flush();
}
Speed_Statistics append_speed;
Value_Statistics append_value;
protected:
File_Gather_Simple gather_file;
};
} // namespace Psc