openMSX
DiskManipulator.hh
Go to the documentation of this file.
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
12namespace openmsx {
13
14class CommandController;
15class DiskContainer;
16class SectorAccessibleDisk;
17class DiskPartition;
18class MSXtar;
19class Reactor;
20enum class MSXBootSectorType;
21
22class DiskManipulator final : public Command
23{
24public:
25 explicit DiskManipulator(CommandController& commandController,
26 Reactor& reactor);
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;
36 std::unique_ptr<DiskPartition> partition; // will often be the full disk
37 };
38 [[nodiscard]] DiskContainer* getDrive(std::string_view driveName) const;
39 [[nodiscard]] std::optional<DriveAndPartition> getDriveAndDisk(std::string_view driveName) const;
40 void create(const std::string& filename_, MSXBootSectorType bootType, const std::vector<unsigned>& sizes) const;
41
42private:
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
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
void unregisterDrive(DiskContainer &drive)
void create(const std::string &filename_, MSXBootSectorType bootType, const std::vector< unsigned > &sizes) const
DiskContainer * getDrive(std::string_view driveName) const
void registerDrive(DiskContainer &drive, std::string_view prefix)
std::optional< DriveAndPartition > getDriveAndDisk(std::string_view driveName) const
std::vector< std::string > getDriveNamesForCurrentMachine() const
Contains the main loop of openMSX.
Definition Reactor.hh:74
unsigned partition(SectorAccessibleDisk &disk, std::span< const unsigned > sizes, MSXBootSectorType bootType)
Write a partition table to the given disk and format each partition.
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::unique_ptr< DiskPartition > partition