OXYGENHUB
◆ main openmsx / src / imgui / ImGuiDiskManipulator.hh
3.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef IMGUI_DISK_MANIPULATOR_HH
2
#define IMGUI_DISK_MANIPULATOR_HH
3
4
#include "ImGuiPart.hh"
5
6
#include "DiskManipulator.hh"
7
#include "SectorAccessibleDisk.hh"
8
9
#include <ctime>
10
#include <map>
11
#include <memory>
12
#include <optional>
13
#include <string>
14
#include <string_view>
15
#include <variant>
16
#include <vector>
17
18
namespace openmsx {
19
20
class DiskContainer;
21
class DiskPartition;
22
class MSXtar;
23
24
class ImGuiDiskManipulator final : public ImGuiPart
25
{
26
public:
27
	using ImGuiPart::ImGuiPart;
28
29
	void paint(MSXMotherBoard* motherBoard) override;
30
31
public:
32
	bool show = false;
33
34
private:
35
	struct FileInfo {
36
		std::string filename;
37
		size_t size = 0;
38
		time_t modified = 0;
39
		MSXDirEntry::AttribValue attrib{0};
40
		bool isDirectory = false;
41
		bool isSelected = false;
42
	};
43
	struct Nop {};
44
	struct ChangeDir { std::string_view name; };
45
	struct Delete { std::string_view name; };
46
	struct Rename { std::string_view name; };
47
	using Action = std::variant<Nop, ChangeDir, Delete, Rename>;
48
49
	struct DrivePartitionTar {
50
		DiskContainer* drive;
51
		std::unique_ptr<DiskPartition> disk; // will often be the full disk
52
		std::unique_ptr<MSXtar> tar;
53
	};
54
	[[nodiscard]] DiskContainer* getDrive();
55
	[[nodiscard]] std::optional<DiskManipulator::DriveAndPartition> getDriveAndDisk();
56
	[[nodiscard]] std::optional<DrivePartitionTar> getMsxStuff();
57
58
	[[nodiscard]] bool isValidMsxDirectory(DrivePartitionTar& stuff, const std::string& dir) const;
59
	[[nodiscard]] std::string getDiskImageName();
60
	[[nodiscard]] std::vector<FileInfo> dirMSX(DrivePartitionTar& stuff);
61
	void refreshMsx(DrivePartitionTar& stuff);
62
	void refreshHost();
63
	void checkSort(std::vector<FileInfo>& files, bool& forceSort) const;
64
	[[nodiscard]] Action drawTable(std::vector<FileInfo>& files, int& lastClickIdx, bool& forceSort, bool msxSide) const;
65
	void insertMsxDisk();
66
	void exportDiskImage();
67
	void msxParentDirectory();
68
	void hostParentDirectory();
69
	void msxRefresh();
70
	void hostRefresh();
71
	[[nodiscard]] bool setupTransferHostToMsx(DrivePartitionTar& stuff);
72
	void executeTransferHostToMsx(DrivePartitionTar& stuff);
73
	void transferMsxToHost(DrivePartitionTar& stuff);
74
75
private:
76
	struct PartitionSize {
77
		unsigned count;
78
		enum Unit : int { KB, MB };
79
		int unit = KB;
80
81
		[[nodiscard]] unsigned asSectorCount() const {
82
			return count * (((unit == KB) ? 1024 : (1024 * 1024)) / SectorAccessibleDisk::SECTOR_SIZE);
83
		}
84
	};
85
86
	std::vector<FileInfo> msxFileCache;
87
	std::vector<FileInfo> hostFileCache;
88
	std::string selectedDrive = "virtual_drive";
89
	std::string msxDir = "/", editMsxDir = "/";
90
	std::string hostDir, editHostDir;
91
	std::string editModal;
92
	std::string renameFrom;
93
	int msxLastClick = -1;
94
	int hostLastClick = -1;
95
	bool hostNeedRefresh = true;
96
	bool hostForceSort = false;
97
98
	enum TransferHostToMsxPhase : uint8_t {
99
		IDLE,
100
		CHECK,
101
		EXECUTE_PRESERVE,
102
		EXECUTE_OVERWRITE,
103
	} transferHostToMsxPhase = IDLE;
104
	std::vector<FileInfo> existingFiles;
105
	std::vector<FileInfo> existingDirs;
106
107
	// std::less<> is better, but runs into a gcc-16 bug (fixed 2026/09/04):
108
	//   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126716
109
	//std::map<std::string, std::vector<FileInfo>, std::less<>> duplicateEntries;
110
	std::map<std::string, std::vector<FileInfo>> duplicateEntries;
111
112
	enum NewDiskType : int { UNPARTITIONED = 0, PARTITIONED = 1 };
113
	int newDiskType = UNPARTITIONED;
114
	int bootType = static_cast<int>(MSXBootSectorType::DOS2);
115
	PartitionSize unpartitionedSize = {.count = 720, .unit = PartitionSize::KB};
116
	std::vector<PartitionSize> partitionSizes;
117
};
118
119
} // namespace openmsx
120
121
#endif