openMSX
ImGuiDiskManipulator.hh
Go to the documentation of this file.
1#ifndef IMGUI_DISK_MANIPULATOR_HH
2#define IMGUI_DISK_MANIPULATOR_HH
3
4#include "ImGuiPart.hh"
5
6#include "DiskManipulator.hh"
8
9#include <ctime>
10#include <map>
11#include <memory>
12#include <optional>
13#include <string>
14#include <string_view>
15#include <variant>
16#include <vector>
17
18namespace openmsx {
19
20class DiskContainer;
21class DiskPartition;
22class MSXtar;
23
24class ImGuiDiskManipulator final : public ImGuiPart
25{
26public:
28
29 void paint(MSXMotherBoard* motherBoard) override;
30
31public:
32 bool show = false;
33
34private:
35 struct FileInfo {
36 std::string filename;
37 size_t size = 0;
38 time_t modified = 0;
40 bool isDirectory = false;
41 bool isSelected = false;
42 };
43 struct Nop {};
44 struct ChangeDir { std::string_view name; };
45 struct Delete { std::string_view name; };
46 struct Rename { std::string_view name; };
47 using Action = std::variant<Nop, ChangeDir, Delete, Rename>;
48
49 struct DrivePartitionTar {
50 DiskContainer* drive;
51 std::unique_ptr<DiskPartition> disk; // will often be the full disk
52 std::unique_ptr<MSXtar> tar;
53 };
54 [[nodiscard]] DiskContainer* getDrive();
55 [[nodiscard]] std::optional<DiskManipulator::DriveAndPartition> getDriveAndDisk();
56 [[nodiscard]] std::optional<DrivePartitionTar> getMsxStuff();
57
58 [[nodiscard]] bool isValidMsxDirectory(DrivePartitionTar& stuff, const std::string& dir) const;
59 [[nodiscard]] std::string getDiskImageName();
60 [[nodiscard]] std::vector<FileInfo> dirMSX(DrivePartitionTar& stuff);
61 void refreshMsx(DrivePartitionTar& stuff);
62 void refreshHost();
63 void checkSort(std::vector<FileInfo>& files, bool& forceSort) const;
64 [[nodiscard]] Action drawTable(std::vector<FileInfo>& files, int& lastClickIdx, bool& forceSort, bool drawAttrib) const;
65 void insertMsxDisk();
66 void exportDiskImage();
67 void msxParentDirectory();
68 void hostParentDirectory();
69 void msxRefresh();
70 void hostRefresh();
71 [[nodiscard]] bool setupTransferHostToMsx(DrivePartitionTar& stuff);
72 void executeTransferHostToMsx(DrivePartitionTar& stuff);
73 void transferMsxToHost(DrivePartitionTar& stuff);
74
75private:
76 struct PartitionSize {
77 unsigned count;
78 enum Unit : int { KB, MB };
79 int unit = KB;
80
81 [[nodiscard]] unsigned asSectorCount() const {
82 return count * (((unit == KB) ? 1024 : (1024 * 1024)) / SectorAccessibleDisk::SECTOR_SIZE);
83 }
84 };
85
86 std::vector<FileInfo> msxFileCache;
87 std::vector<FileInfo> hostFileCache;
88 std::string selectedDrive = "virtual_drive";
89 std::string msxDir = "/", editMsxDir = "/";
90 std::string hostDir, editHostDir;
91 std::string editModal;
92 std::string renameFrom;
93 int msxLastClick = -1;
94 int hostLastClick = -1;
95 bool hostNeedRefresh = true;
96 bool hostForceSort = false;
97
98 enum TransferHostToMsxPhase {
99 IDLE,
100 CHECK,
101 EXECUTE_PRESERVE,
102 EXECUTE_OVERWRITE,
103 } transferHostToMsxPhase = IDLE;
104 std::vector<FileInfo> existingFiles;
105 std::vector<FileInfo> existingDirs;
106 std::map<std::string, std::vector<FileInfo>, std::less<>> duplicateEntries;
107
108 enum NewDiskType : int { UNPARTITIONED = 0, PARTITIONED = 1 };
109 int newDiskType = UNPARTITIONED;
110 int bootType = static_cast<int>(MSXBootSectorType::DOS2);
111 PartitionSize unpartitionedSize = {720, PartitionSize::KB};
112 std::vector<PartitionSize> partitionSizes;
113};
114
115} // namespace openmsx
116
117#endif
void paint(MSXMotherBoard *motherBoard) override
ImGuiPart(ImGuiManager &manager_)
Definition ImGuiPart.hh:12
ALWAYS_INLINE unsigned count(const uint8_t *pIn, const uint8_t *pMatch, const uint8_t *pInLimit)
Definition lz4.cc:146
This file implemented 3 utility functions:
Definition Autofire.cc:11