51 lines
2.2 KiB
C++
51 lines
2.2 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
#include "modern/ui/model.hpp"
|
|
|
|
namespace bmh::modern_ui {
|
|
enum class DemoFileKind { career, desktop };
|
|
struct DemoFileEntry {
|
|
std::string id, name, token, created, modified, preview_png, error;
|
|
uint64_t bytes = 0;
|
|
Json data;
|
|
bool legacy = false;
|
|
bool valid() const { return error.empty(); }
|
|
};
|
|
// Presentation-only files, deliberately separate from OBS careers and global
|
|
// UI preferences. A single atomic document owns payload and preview together.
|
|
class DemoFiles {
|
|
public:
|
|
DemoFiles(fs::path userdata, DemoFileKind,
|
|
std::shared_ptr<const Catalog> world);
|
|
static std::string clean_name(const std::string &);
|
|
static std::string name_key(const std::string &, bool compatibility = false);
|
|
static Json career_metadata(const Json &);
|
|
std::vector<DemoFileEntry> list() const;
|
|
DemoFileEntry read(const std::string &id,
|
|
const std::string &expected = {}) const;
|
|
std::string free_name(const std::string &base) const;
|
|
DemoFileEntry put(const std::string &name, const Json &data,
|
|
const std::string &preview_png = {},
|
|
const std::string &id = {},
|
|
const std::string &expected = {});
|
|
DemoFileEntry rename(const std::string &id, const std::string &expected,
|
|
const std::string &name);
|
|
void remove(const std::string &id, const std::string &expected);
|
|
DemoFileEntry import_file(const fs::path &);
|
|
void export_file(const std::string &id, const std::string &expected,
|
|
const fs::path &, bool overwrite = false) const;
|
|
fs::path preview_file(const DemoFileEntry &) const;
|
|
void validate(const Json &) const;
|
|
fs::path directory() const { return directory_; }
|
|
private:
|
|
fs::path root_, directory_;
|
|
DemoFileKind kind_;
|
|
std::shared_ptr<const Catalog> world_;
|
|
fs::path path(const std::string &) const;
|
|
DemoFileEntry decode(const fs::path &, const std::string &) const;
|
|
DemoFileEntry commit(const std::string &, const Json &, const std::string &,
|
|
const std::string &, const std::string &,
|
|
const std::string &created = {});
|
|
};
|
|
} // namespace bmh::modern_ui
|