OXYGENHUB
◆ main openmsx / src / fdc / DiskManipulator.hh
3.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef FILEMANIPULATOR_HH
2
#define FILEMANIPULATOR_HH
3
4
#include "Command.hh"
5
#include "DiskPartition.hh"
6
7
#include <memory>
8
#include <optional>
9
#include <string_view>
10
#include <vector>
11
12
namespace openmsx {
13
14
class CommandController;
15
class DiskContainer;
16
class SectorAccessibleDisk;
17
class DiskPartition;
18
class MSXtar;
19
class Reactor;
20
enum class MSXBootSectorType;
21
22
class DiskManipulator final : public Command
23
{
24
public:
25
	explicit DiskManipulator(CommandController& commandController,
26
	                         Reactor& reactor);
27
	~DiskManipulator();
28
29
	void registerDrive(DiskContainer& drive, std::string_view prefix);
30
	void unregisterDrive(DiskContainer& drive);
31
32
	// for use in ImGuiDiskManipulator
33
	[[nodiscard]] std::vector<std::string> getDriveNamesForCurrentMachine() const;
34
	struct DriveAndPartition {
35
		DiskContainer* drive;
36
		std::unique_ptr<DiskPartition> partition; // will often be the full disk
37
	};
38
	[[nodiscard]] DiskContainer* getDrive(std::string_view fullName) const;
39
	[[nodiscard]] std::optional<DriveAndPartition> getDriveAndDisk(std::string_view fullName) const;
40
	void create(const std::string& filename_, MSXBootSectorType bootType, const std::vector<unsigned>& sizes) const;
41
42
private:
43
	struct DriveSettings
44
	{
45
		std::string getWorkingDir(unsigned p);
46
		void setWorkingDir(unsigned p, std::string_view dir);
47
48
		DiskContainer* drive;
49
		std::string driveName; // includes machine prefix
50
		/** 0 = whole disk, 1.. = partition number */
51
		unsigned partition;
52
	private:
53
		std::vector<std::string> workingDir;
54
	};
55
	using Drives = std::vector<DriveSettings>;
56
	Drives drives; // unordered
57
58
	// Command interface
59
	void execute(std::span<const TclObject> tokens, TclObject& result) override;
60
	[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
61
	void tabCompletion(std::vector<std::string>& tokens) const override;
62
63
	[[nodiscard]] std::string getMachinePrefix() const;
64
	[[nodiscard]] Drives::iterator findDriveSettings(DiskContainer& drive);
65
	[[nodiscard]] Drives::iterator findDriveSettings(std::string_view driveName);
66
	[[nodiscard]] DriveSettings& getDriveSettings(std::string_view diskName);
67
	[[nodiscard]] static DiskPartition getPartition(
68
		const DriveSettings& driveData);
69
	[[nodiscard]] MSXtar getMSXtar(SectorAccessibleDisk& disk,
70
	                               DriveSettings& driveData) const;
71
72
	void create(std::span<const TclObject> tokens) const;
73
	void partition(std::span<const TclObject> tokens);
74
	void savedsk(const DriveSettings& driveData, std::string filename) const;
75
	void format(std::span<const TclObject> tokens);
76
	std::string chdir(DriveSettings& driveData, std::string_view filename) const;
77
	void mkdir(DriveSettings& driveData, std::string_view filename) const;
78
	[[nodiscard]] std::string dir(DriveSettings& driveData) const;
79
	[[nodiscard]] std::string deleteEntry(DriveSettings& driveData, std::string_view entry) const;
80
	[[nodiscard]] std::string rename(DriveSettings& driveData, std::string_view oldName, std::string_view newName) const;
81
	std::string imprt(DriveSettings& driveData,
82
	                  std::span<const TclObject> lists, bool overwrite) const;
83
	void exprt(DriveSettings& driveData, std::string_view dirname,
84
	           std::span<const TclObject> lists) const;
85
86
	Reactor& reactor;
87
};
88
89
} // namespace openmsx
90
91
#endif