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 <string_view>
6 #include <vector>
7 #include <memory>
8 
9 namespace openmsx {
10 
11 class CommandController;
12 class DiskContainer;
13 class SectorAccessibleDisk;
14 class DiskPartition;
15 class MSXtar;
16 class Reactor;
17 
18 class DiskManipulator final : public Command
19 {
20 public:
21  explicit DiskManipulator(CommandController& commandController,
22  Reactor& reactor);
24 
25  void registerDrive(DiskContainer& drive, const std::string& prefix);
26  void unregisterDrive(DiskContainer& drive);
27 
28 private:
29  static constexpr unsigned MAX_PARTITIONS = 31;
30  struct DriveSettings
31  {
32  DiskContainer* drive;
33  std::string driveName; // includes machine prefix
34  std::string workingDir[MAX_PARTITIONS + 1];
36  unsigned partition;
37  };
38  using Drives = std::vector<DriveSettings>;
39  Drives drives; // unordered
40 
41  // Command interface
42  void execute(span<const TclObject> tokens, TclObject& result) override;
43  std::string help (const std::vector<std::string>& tokens) const override;
44  void tabCompletion(std::vector<std::string>& tokens) const override;
45 
46  std::string getMachinePrefix() const;
47  Drives::iterator findDriveSettings(DiskContainer& drive);
48  Drives::iterator findDriveSettings(std::string_view name);
49  DriveSettings& getDriveSettings(std::string_view diskname);
50  std::unique_ptr<DiskPartition> getPartition(
51  const DriveSettings& driveData);
52  std::unique_ptr<MSXtar> getMSXtar(SectorAccessibleDisk& disk,
53  DriveSettings& driveData);
54 
55  void create(span<const TclObject> tokens);
56  void savedsk(const DriveSettings& driveData,
57  std::string_view filename);
58  void format(DriveSettings& driveData, bool dos1);
59  std::string chdir(DriveSettings& driveData, std::string_view filename);
60  void mkdir(DriveSettings& driveData, std::string_view filename);
61  std::string dir(DriveSettings& driveData);
62  std::string import(DriveSettings& driveData,
63  span<const TclObject> lists);
64  void exprt(DriveSettings& driveData, std::string_view dirname,
65  span<const TclObject> lists);
66 
67  Reactor& reactor;
68 };
69 
70 } // namespace openmsx
71 
72 #endif
Contains the main loop of openMSX.
Definition: Reactor.hh:66
Definition: span.hh:34
void registerDrive(DiskContainer &drive, const std::string &prefix)
constexpr const char *const filename
DiskManipulator(CommandController &commandController, Reactor &reactor)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void partition(SectorAccessibleDisk &disk, const std::vector< unsigned > &sizes)
Write a partition table to the given disk and format each partition.
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
void unregisterDrive(DiskContainer &drive)