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, std::string_view 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  [[nodiscard]] std::string help (const std::vector<std::string>& tokens) const override;
44  void tabCompletion(std::vector<std::string>& tokens) const override;
45 
46  [[nodiscard]] std::string getMachinePrefix() const;
47  [[nodiscard]] Drives::iterator findDriveSettings(DiskContainer& drive);
48  [[nodiscard]] Drives::iterator findDriveSettings(std::string_view driveName);
49  [[nodiscard]] DriveSettings& getDriveSettings(std::string_view diskname);
50  [[nodiscard]] static std::unique_ptr<DiskPartition> getPartition(
51  const DriveSettings& driveData);
52  [[nodiscard]] static std::unique_ptr<MSXtar> getMSXtar(SectorAccessibleDisk& disk,
53  DriveSettings& driveData);
54 
55  static void create(span<const TclObject> tokens);
56  void savedsk(const DriveSettings& driveData, std::string filename);
57  void format(DriveSettings& driveData, bool dos1);
58  std::string chdir(DriveSettings& driveData, std::string_view filename);
59  void mkdir(DriveSettings& driveData, std::string_view filename);
60  [[nodiscard]] std::string dir(DriveSettings& driveData);
61  std::string import(DriveSettings& driveData,
62  span<const TclObject> lists);
63  void exprt(DriveSettings& driveData, std::string_view dirname,
64  span<const TclObject> lists);
65 
66  Reactor& reactor;
67 };
68 
69 } // namespace openmsx
70 
71 #endif
void unregisterDrive(DiskContainer &drive)
DiskManipulator(CommandController &commandController, Reactor &reactor)
void registerDrive(DiskContainer &drive, std::string_view prefix)
Contains the main loop of openMSX.
Definition: Reactor.hh:67
Definition: span.hh:126
void partition(SectorAccessibleDisk &disk, const std::vector< unsigned > &sizes)
Write a partition table to the given disk and format each partition.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename