Skip to content

Commit

Permalink
libdoomsday|FS: Listing all files specified on the command line
Browse files Browse the repository at this point in the history
DoomsdayApp can now enumerate all the (FS2) files that were passed
via command line arguments.
  • Loading branch information
skyjake committed Jan 6, 2017
1 parent ac19921 commit bb9c67e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
6 changes: 6 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h
Expand Up @@ -92,6 +92,12 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp
*/
void initPackageFolders();

/**
* Lists all the files found on the command line "-file" option (and its aliases).
* @return List of files.
*/
QList<de::File *> filesFromCommandLine() const;

enum Behavior
{
AllowReload = 0x1,
Expand Down
44 changes: 40 additions & 4 deletions doomsday/apps/libdoomsday/src/doomsdayapp.cpp
Expand Up @@ -199,10 +199,24 @@ DENG2_PIMPL(DoomsdayApp)

CommandLine::get().forAllParameters(option, [] (duint pos, String const &)
{
auto &cmdLine = CommandLine::get();
cmdLine.makeAbsolutePath(pos);
DirectoryFeed::manuallyPopulateSingleFile(cmdLine.at(pos),
FS::get().makeFolder(String("/sys/cmdline/arg%1").arg(pos, 3, 10, QChar('0'))));
try
{
auto &cmdLine = CommandLine::get();
cmdLine.makeAbsolutePath(pos);
Folder &argFolder = FS::get().makeFolder(String("/sys/cmdline/arg%1").arg(pos, 3, 10, QChar('0')));
File const &argFile = DirectoryFeed::manuallyPopulateSingleFile
(cmdLine.at(pos), argFolder);
// For future reference, store the name of the actual intended file as
// metadata in the "arg00N" folder. This way we don't need to go looking
// for it again later.
argFolder.objectNamespace().set("argPath", argFile.path());
}
catch (Error const &er)
{
throw Error("DoomsdayApp::initCommandLineFiles",
QString("Problem with file path in command line argument %1: %2")
.arg(pos).arg(er.asText()));
}
});
}

Expand Down Expand Up @@ -465,6 +479,28 @@ void DoomsdayApp::initPackageFolders()
d->initPackageFolders();
}

QList<File *> DoomsdayApp::filesFromCommandLine() const
{
QList<File *> files;
FS::locate<Folder const>("/sys/cmdline").forContents([&files] (String name, File &file)
{
try
{
if (name.startsWith("arg"))
{
files << &FS::locate<File>(file.as<Folder>().objectNamespace().gets("argPath"));
}
}
catch (Error const &er)
{
LOG_RES_ERROR("Problem with a file specified on the command line: %s")
<< er.asText();
}
return LoopContinue;
});
return files;
}

void DoomsdayApp::determineGlobalPaths()
{
d->determineGlobalPaths();
Expand Down

0 comments on commit bb9c67e

Please sign in to comment.