VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
MediaFile.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "MediaFileTypes.h"
16#include <sstream>
17#include <fstream>
18#include <filesystem>
19
20namespace vc64 {
21
22namespace fs = ::std::filesystem;
23
24class MediaFile {
25
26public:
27
28 virtual ~MediaFile() = default;
29
30
31 //
32 // Static methods
33 //
34
35 // Determines the type of an arbitrary file on file
36 static FileType type(const fs::path &path);
37
38 // Factory methods
39 static MediaFile *make(const fs::path &path);
40 static MediaFile *make(const fs::path &path, FileType type);
41 static MediaFile *make(const u8 *buf, isize len, FileType type);
42 static MediaFile *make(class FileSystem &fs, FileType type); // TODO: add const
43 static MediaFile *make(struct DriveAPI &drive, FileType type);
44
45
46 //
47 // Methods
48 //
49
50 // Returns the media type of this file
51 virtual FileType type() const { return FILETYPE_UNKNOWN; }
52
53 // Returns the size of this file
54 virtual isize getSize() const = 0;
55
56 // Returns a pointer to the file data
57 virtual u8 *getData() const = 0;
58
59 // Returns the logical name of this file
60 virtual string name() const = 0;
61
62 // Returns a fingerprint (hash value) for this file
63 virtual u64 fnv() const = 0;
64
65 // Return a timestamp (if present)
66 virtual time_t timestamp() const { return time_t(0); }
67
68 // Return the size of the preview image (only available for snapshot files)
69 virtual std::pair <isize,isize> previewImageSize() const { return { 0, 0 }; }
70
71 // Return a preview image (only available for snapshot files)
72 virtual const u32 *previewImageData() const { return nullptr; }
73
74 //
75 virtual void flash(u8 *buf, isize offset = 0) const = 0;
76
77
78 //
79 // Serializing
80 //
81
82public:
83
84 virtual void readFromStream(std::istream &stream) = 0;
85 virtual void readFromFile(const fs::path &path) = 0;
86 virtual void readFromBuffer(const u8 *buf, isize len) = 0;
87
88 virtual void writeToStream(std::ostream &stream) = 0;
89 virtual void writeToFile(const fs::path &path) = 0;
90 virtual void writeToBuffer(u8 *buf) = 0;
91};
92
93}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16