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 <array>
8#include <memory>
9#include <optional>
10#include <string_view>
11#include <vector>
12
13namespace openmsx {
14
15class CommandController;
16class DiskContainer;
17class SectorAccessibleDisk;
18class DiskPartition;
19class MSXtar;
20class Reactor;
21class MsxChar2Unicode;
22enum class MSXBootSectorType;
23
24class DiskManipulator final : public Command
25{
26public:
27 explicit DiskManipulator(CommandController& commandController,
28 Reactor& reactor);
30
31 void registerDrive(DiskContainer& drive, std::string_view prefix);
32 void unregisterDrive(DiskContainer& drive);
33
34 // for use in ImGuiDiskManipulator
35 [[nodiscard]] std::vector<std::string> getDriveNamesForCurrentMachine() const;
38 std::unique_ptr<DiskPartition> partition; // will often be the full disk
39 };
40 [[nodiscard]] DiskContainer* getDrive(std::string_view driveName) const;
41 [[nodiscard]] std::optional<DriveAndPartition> getDriveAndDisk(std::string_view driveName) const;
42 void create(const std::string& filename_, MSXBootSectorType bootType, const std::vector<unsigned>& sizes);
43
44private:
45 struct DriveSettings
46 {
47 std::string getWorkingDir(unsigned p);
48 void setWorkingDir(unsigned p, std::string_view dir);
49
50 DiskContainer* drive;
51 std::string driveName; // includes machine prefix
53 unsigned partition;
54 private:
55 std::vector<std::string> workingDir;
56 };
57 using Drives = std::vector<DriveSettings>;
58 Drives drives; // unordered
59
60 // Command interface
61 void execute(std::span<const TclObject> tokens, TclObject& result) override;
62 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
63 void tabCompletion(std::vector<std::string>& tokens) const override;
64
65 [[nodiscard]] std::string getMachinePrefix() const;
66 [[nodiscard]] Drives::iterator findDriveSettings(DiskContainer& drive);
67 [[nodiscard]] Drives::iterator findDriveSettings(std::string_view driveName);
68 [[nodiscard]] DriveSettings& getDriveSettings(std::string_view diskName);
69 [[nodiscard]] static DiskPartition getPartition(
70 const DriveSettings& driveData);
71 [[nodiscard]] MSXtar getMSXtar(SectorAccessibleDisk& disk,
72 DriveSettings& driveData);
73
74 void create(std::span<const TclObject> tokens);
75 void partition(std::span<const TclObject> tokens);
76 void savedsk(const DriveSettings& driveData, std::string filename);
77 void format(std::span<const TclObject> tokens);
78 std::string chdir(DriveSettings& driveData, std::string_view filename);
79 void mkdir(DriveSettings& driveData, std::string_view filename);
80 [[nodiscard]] std::string dir(DriveSettings& driveData);
81 [[nodiscard]] std::string deleteEntry(DriveSettings& driveData, std::string_view entry);
82 [[nodiscard]] std::string rename(DriveSettings& driveData, std::string_view oldName, std::string_view newName);
83 std::string import(DriveSettings& driveData,
84 std::span<const TclObject> lists, bool overwrite);
85 void exprt(DriveSettings& driveData, std::string_view dirname,
86 std::span<const TclObject> lists);
87
88 Reactor& reactor;
89};
90
91} // namespace openmsx
92
93#endif
void unregisterDrive(DiskContainer &drive)
void create(const std::string &filename_, MSXBootSectorType bootType, const std::vector< unsigned > &sizes)
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:72
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:9
std::unique_ptr< DiskPartition > partition