17[[nodiscard]]
static TclObject initialFilePoolSettingValue()
24 "-types",
"system_rom"),
26 "-types",
"rom disk tape"));
33 [&] {
return getDirectories(); },
34 [&](std::string_view message) { reportProgress(message); })
36 controller,
"__filepool",
37 "This is an internal setting. Don't change this directly, "
38 "instead use the 'filepool' command.",
39 initialFilePoolSettingValue().
getString())
41 , sha1SumCommand(controller)
43 filePoolSetting.attach(*
this);
44 reactor.getEventDistributor().registerEventListener(
EventType::QUIT, *
this);
50 filePoolSetting.
detach(*
this);
55 return core.
getFile(fileType, sha1sum);
68 if (elem ==
"system_rom") {
70 }
else if (elem ==
"rom") {
72 }
else if (elem ==
"disk") {
74 }
else if (elem ==
"tape") {
77 throw CommandException(
"Unknown type: ", elem);
88 const TclObject& all = filePoolSetting.
getValue();
89 for (
auto i :
xrange(all.getListLength(interp))) {
90 FilePoolCore::Dir dir;
93 TclObject line = all.getListIndex(interp, i);
94 unsigned numItems = line.getListLength(interp);
96 throw CommandException(
97 "Expected a list with an even number "
98 "of elements, but got ", line.getString());
100 for (
unsigned j = 0; j < numItems; j += 2) {
101 std::string_view name = line.getListIndex(interp, j + 0).getString();
102 TclObject value = line.getListIndex(interp, j + 1);
103 if (name ==
"-path") {
104 dir.path = value.getString();
106 }
else if (name ==
"-types") {
107 dir.types = parseTypes(interp, value);
109 throw CommandException(
"Unknown item: ", name);
113 throw CommandException(
114 "Missing -path item: ", line.getString());
117 throw CommandException(
118 "Missing -types item: ", line.getString());
120 result.push_back(std::move(dir));
122 }
catch (CommandException&
e) {
124 "Error while parsing '__filepool' setting",
e.getMessage());
129void FilePool::update(
const Setting&
setting)
noexcept
132 (void)getDirectories();
135void FilePool::reportProgress(std::string_view message)
137 if (quit) core.
abort();
142int FilePool::signalEvent(
const Event& event)
153FilePool::Sha1SumCommand::Sha1SumCommand(
154 CommandController& commandController_)
155 : Command(commandController_,
"sha1sum")
159void FilePool::Sha1SumCommand::execute(std::span<const TclObject> tokens, TclObject& result)
161 checkNumArgs(tokens, 2,
"filename");
163 auto& filePool =
OUTER(FilePool, sha1SumCommand);
164 result = filePool.getSha1Sum(file).toString();
167std::string FilePool::Sha1SumCommand::help(std::span<const TclObject> )
const
169 return "Calculate sha1 value for the given file. If the file is "
170 "(g)zipped the sha1 is calculated on the unzipped version.";
173void FilePool::Sha1SumCommand::tabCompletion(std::vector<std::string>& tokens)
const
void printProgress(std::string_view message)
void printWarning(std::string_view message)
void repaint()
Redraw the display.
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
void abort()
This is only meaningful to call from within the 'reportProgress' callback (constructor parameter).
std::vector< Dir > Directories
FilePool(CommandController &controller, Reactor &reactor)
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
Contains the main loop of openMSX.
EventDistributor & getEventDistributor()
Interpreter & getInterpreter() const
const TclObject & getValue() const final
Gets the current value of this setting as a TclObject.
This class represents the result of a sha1 calculation (a 160-bit value).
void detach(Observer< T > &observer)
unsigned getListLength(Interpreter &interp) const
TclObject getListIndex(Interpreter &interp, unsigned index) const
void addListElement(const T &t)
zstring_view getString() const
string expandTilde(string path)
Expand the '~' character to the users home directory.
const string & getUserDataDir()
Get the openMSX data dir in the user's home directory.
This file implemented 3 utility functions:
const FileContext & systemFileContext()
EventType getType(const Event &event)
FileContext userFileContext(string_view savePath)
TclObject makeTclDict(Args &&... args)
#define OUTER(type, member)
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto xrange(T e)