Go to the documentation of this file.
24 [[nodiscard]]
string help(
const vector<string>& tokens)
const override;
31 [[nodiscard]]
static string initialFilePoolSettingValue()
38 "-types",
"system_rom"),
40 "-types",
"rom disk tape"));
47 [&] {
return getDirectories(); },
48 [&](std::string_view message) { reportProgress(message); })
50 controller,
"__filepool",
51 "This is an internal setting. Don't change this directly, "
52 "instead use the 'filepool' command.",
53 initialFilePoolSettingValue())
56 filePoolSetting.
attach(*
this);
59 sha1SumCommand = std::make_unique<Sha1SumCommand>(controller, *
this);
65 filePoolSetting.
detach(*
this);
70 return core.
getFile(fileType, sha1sum);
83 if (elem ==
"system_rom") {
84 result |= FileType::SYSTEM_ROM;
85 }
else if (elem ==
"rom") {
87 }
else if (elem ==
"disk") {
88 result |= FileType::DISK;
89 }
else if (elem ==
"tape") {
92 throw CommandException(
"Unknown type: ", elem);
103 const TclObject& all = filePoolSetting.
getValue();
104 for (
auto i :
xrange(all.getListLength(interp))) {
105 FilePoolCore::Dir dir;
106 bool hasPath =
false;
108 TclObject line = all.getListIndex(interp, i);
109 unsigned numItems = line.getListLength(interp);
111 throw CommandException(
112 "Expected a list with an even number "
113 "of elements, but got ", line.getString());
115 for (
unsigned j = 0; j < numItems; j += 2) {
116 std::string_view name = line.getListIndex(interp, j + 0).getString();
117 TclObject value = line.getListIndex(interp, j + 1);
118 if (name ==
"-path") {
119 dir.path = value.getString();
121 }
else if (name ==
"-types") {
122 dir.types = parseTypes(interp, value);
124 throw CommandException(
"Unknown item: ", name);
128 throw CommandException(
129 "Missing -path item: ", line.getString());
132 throw CommandException(
133 "Missing -types item: ", line.getString());
135 result.push_back(std::move(dir));
137 }
catch (CommandException& e) {
139 "Error while parsing '__filepool' setting", e.getMessage());
144 void FilePool::update(
const Setting& setting)
146 assert(&setting == &filePoolSetting); (void)setting;
147 (void)getDirectories();
150 void FilePool::reportProgress(std::string_view message)
152 if (quit) core.
abort();
157 int FilePool::signalEvent(
const std::shared_ptr<const Event>& event)
170 :
Command(commandController_,
"sha1sum")
171 , filePool(filePool_)
184 return "Calculate sha1 value for the given file. If the file is "
185 "(g)zipped the sha1 is calculated on the unzipped version.";
void execute(span< const TclObject > tokens, TclObject &result) override
Execute this command.
void checkNumArgs(span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
Interpreter & getInterpreter() const
void detach(Observer< T > &observer)
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
std::string toString() const
constexpr auto xrange(T e)
void tabCompletion(vector< string > &tokens) const override
Attempt tab completion for this command.
void printProgress(std::string_view message)
std::vector< Dir > Directories
TclObject makeTclDict(Args &&... args)
Sha1SumCommand(CommandController &commandController, FilePool &filePool)
EventDistributor & getEventDistributor()
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
FileContext userFileContext(string_view savePath)
void attach(Observer< T > &observer)
void addListElement(const T &t)
TclObject getListIndex(Interpreter &interp, unsigned index) const
FilePool(CommandController &controller, Reactor &reactor)
Contains the main loop of openMSX.
void printWarning(std::string_view message)
Sha1Sum getSha1Sum(File &file)
Calculate sha1sum for the given File object.
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
const TclObject & getValue() const final
Gets the current value of this setting as a TclObject.
string help(const vector< string > &tokens) const override
Print help for this command.
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
This class represents the result of a sha1 calculation (a 160-bit value).
TemporaryString tmpStrCat(Ts &&... ts)
void repaint()
Redraw the display.
const FileContext & systemFileContext()
unsigned getListLength(Interpreter &interp) const
const string & getUserDataDir()
Get the openMSX data dir in the user's home directory.
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void abort()
This is only meaningful to call from within the 'reportProgress' callback (constructor parameter).
This file implemented 3 utility functions:
string expandTilde(string path)
Expand the '~' character to the users home directory.
zstring_view getString() const