Skip to content

Commit

Permalink
Resources|libdoomsday: Identifying data files and indexing WAD files
Browse files Browse the repository at this point in the history
DoomsdayApp checks all the configured and known locations for WAD files
and populates the /local/wads folder. Currently this is done in
addition to the client's FS1-based code for doing the same task
(that is slated to be retired later).

DataBundle checks the indexed data files (WADs and other formats)
against the databundles.dei registry, which defines the criteria for
generating packages out of known files.

res::LumpDirectory is a new class in libdoomsday for parsing a WAD
file's lump directory and performing basic lookup operations in it.
  • Loading branch information
skyjake committed Jan 12, 2016
1 parent d239877 commit f9969b3
Show file tree
Hide file tree
Showing 20 changed files with 1,249 additions and 162 deletions.
2 changes: 0 additions & 2 deletions doomsday/apps/client/include/sys_system.h
Expand Up @@ -40,8 +40,6 @@ DENG_EXTERN_C void Sys_Quit();

void Sys_HideMouseCursor();

de::NativePath Sys_SteamBasePath();

void Sys_Sleep(de::dint millisecs);

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -418,9 +418,9 @@ void ClientApp::initialize()
// Initialize definitions before the files are indexed.
Def_Init();

addInitPackage("net.dengine.base");
addInitPackage("net.dengine.client");
initSubsystems(); // loads Config
DoomsdayApp::initialize();

// Set up the log alerts (observes Config variables).
d->logAlarm.alertMask.init();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -325,7 +325,7 @@ static void createPackagesScheme()
// Add paths to games bought with/using Steam.
if(!CommandLine_Check("-nosteamapps"))
{
NativePath steamBase = Sys_SteamBasePath();
NativePath steamBase = DoomsdayApp::steamBasePath();
if(!steamBase.isEmpty())
{
NativePath steamPath = steamBase / "SteamApps/common/";
Expand Down
22 changes: 0 additions & 22 deletions doomsday/apps/client/src/sys_system.cpp
Expand Up @@ -268,28 +268,6 @@ void Sys_HideMouseCursor()
#endif
}

de::NativePath Sys_SteamBasePath()
{
#ifdef WIN32
// The path to Steam can be queried from the registry.
{
QSettings st("HKEY_CURRENT_USER\\Software\\Valve\\Steam\\", QSettings::NativeFormat);
de::String path = st.value("SteamPath").toString();
if(!path.isEmpty()) return path;
}

{
QSettings st("HKEY_LOCAL_MACHINE\\Software\\Valve\\Steam\\", QSettings::NativeFormat);
de::String path = st.value("InstallPath").toString();
if(!path.isEmpty()) return path;
}
#elif MACOSX
return de::NativePath(QDir::homePath()) / "Library/Application Support/Steam/";
#endif
/// @todo Where are steam apps located on Ubuntu?
return "";
}

/**
* Called when Doomsday should quit (will be deferred until convenient).
*/
Expand Down
14 changes: 13 additions & 1 deletion doomsday/apps/libdoomsday/include/doomsday/doomsdayapp.h
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_DOOMSDAYAPP_H
Expand All @@ -26,8 +26,11 @@
#include "players.h"

#include <de/NativePath>
#include <de/Info>
#include <string>

namespace res { class Bundles; }

/**
* Common application-level state and components.
*
Expand All @@ -39,6 +42,13 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp
public:
DoomsdayApp(Players::Constructor playerConstructor);

/**
* Initialize application state.
*/
void initialize();

void identifyDataBundles();

void determineGlobalPaths();

bool isUsingUserDir() const;
Expand All @@ -54,11 +64,13 @@ class LIBDOOMSDAY_PUBLIC DoomsdayApp

public:
static DoomsdayApp &app();
static res::Bundles &bundles();
static Plugins &plugins();
static Games &games();
static Players &players();
static Game &currentGame();
static BusyMode &busyMode();
static de::NativePath steamBasePath();

private:
DENG2_PRIVATE(d)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/libdoomsday/include/doomsday/filesys/datafile.h
@@ -1,4 +1,4 @@
/** @file datafile.h Classic data files: LMP, DED, DEH.
/** @file datafile.h Classic data files: WAD, LMP, DED, DEH.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -19,7 +19,7 @@
#ifndef LIBDOOMSDAY_DATAFILE_H
#define LIBDOOMSDAY_DATAFILE_H

#include "databundle.h"
#include "../resource/databundle.h"
#include <de/ByteArrayFile>

/**
Expand Down
@@ -1,4 +1,4 @@
/** @file datafolder.h Classic data files: PK3, WAD.
/** @file datafolder.h Classic data files: PK3.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -19,14 +19,16 @@
#ifndef LIBDOOMSDAY_DATAFOLDER_H
#define LIBDOOMSDAY_DATAFOLDER_H

#include "databundle.h"
#include "../resource/databundle.h"
#include <de/Folder>

/**
* FS2 file for classic container-like data files: PK3 and WAD.
* FS2 file for classic container-like data files: PK3.
*
* Containers are represented as folders so that their contents can be
* accessed via the file tree.
*
* @todo WAD files should use DataFolder.
*/
class LIBDOOMSDAY_PUBLIC DataFolder : public de::Folder, public DataBundle
{
Expand Down
56 changes: 56 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/resource/bundles.h
@@ -0,0 +1,56 @@
/** @file bundles.h Data bundle indexing.
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_RESOURCE_BUNDLES_H
#define LIBDOOMSDAY_RESOURCE_BUNDLES_H

#include "databundle.h"
#include <de/Info>

namespace res {

/**
* Index for data bundles.
*/
class Bundles
{
public:
typedef QList<de::Info::BlockElement const *> BlockElements;

DENG2_ERROR(InvalidError);

public:
Bundles();

/**
* Returns the collection of information for identifying known data files.
* @return Info document.
*/
de::Info const &identityRegistry() const;

BlockElements formatEntries(DataBundle::Format format) const;

void identify();

private:
DENG2_PRIVATE(d)
};

} // namespace res

#endif // LIBDOOMSDAY_RESOURCE_BUNDLES_H
Expand Up @@ -20,12 +20,16 @@
#define LIBDOOMSDAY_DATABUNDLE_H

#include "../libdoomsday.h"
#include "lumpdirectory.h"
#include <de/filesys/IInterpreter>
#include <de/Folder>

/**
* Abstract base class for classic data files: PK3, WAD, LMP, DED, DEH.
*
* Specialized libcore Files representing loadable data files should be derived
* from DataBundle.
*
* Generates Doomsday 2 compatible metadata for data files, allowing them to
* be treated as packages at runtime.
*
Expand All @@ -37,7 +41,9 @@
class LIBDOOMSDAY_PUBLIC DataBundle : public de::IByteArray
{
public:
enum Format { Pk3, Wad, Lump, Ded, Dehacked };
enum Format { Unknown, Pk3, Wad, Iwad, Pwad, Lump, Ded, Dehacked };

DENG2_ERROR(FormatError);

struct LIBDOOMSDAY_PUBLIC Interpreter : public de::filesys::IInterpreter {
de::File *interpretFile(de::File *sourceData) const override;
Expand All @@ -50,11 +56,39 @@ class LIBDOOMSDAY_PUBLIC DataBundle : public de::IByteArray
Format format() const;
de::String description() const;

/**
* Generates appropriate packages accoding to the contents of the data bundle.
*/
void identifyPackages() const;

/**
* Determines if the bundle is nested inside another bundle.
*/
bool isNested() const;

/**
* Finds the bundle that contains this bundle, if this bundle is a
* nested one.
*
* @return DataBundle that contains this bundle, or @c nullptr if not
* nested. Ownership not transferred.
*/
DataBundle const *containerBundle() const;

/**
* Returns the WAD file lump directory.
* @return LumpDirectory for WADs; @c nullptr for non-WAD formats.
*/
res::LumpDirectory const *lumpDirectory() const;

// Implements IByteArray.
Size size() const;
void get(Offset at, Byte *values, Size count) const;
void set(Offset at, Byte const *values, Size count);

protected:
void setFormat(Format format);

private:
DENG2_PRIVATE(d)
};
Expand Down
@@ -0,0 +1,85 @@
/** @file lumpdirectory.h
*
* @authors Copyright (c) 2016 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_RESOURCE_LUMPDIRECTORY_H
#define LIBDOOMSDAY_RESOURCE_LUMPDIRECTORY_H

#include "../libdoomsday.h"
#include <de/File>

namespace res {

/**
* Directory of WAD lumps.
*
* Utility for accessing the lump directory of a WAD file. The information is
* presented as it exists in the file without any modifications.
*/
class LIBDOOMSDAY_PUBLIC LumpDirectory
{
public:
enum Type { Invalid, Iwad, Pwad };

struct Entry
{
de::Block name; ///< Name of the lump.
de::duint32 offset; ///< Position in the file, in bytes.
de::duint32 size; ///< Size of the lump.
};

typedef de::dsize Pos;

DENG2_ERROR(OffsetError);

public:
/**
* Reads the lump directory from a byte array.
*
* @param wadData Data of a WAD file. No reference to the data is kept
* afterwards.
*/
LumpDirectory(de::IByteArray const &wadData);

bool isValid() const;

Type type() const;

/**
* Returns the number of lumps.
*/
Pos count() const;

Entry const &entry(Pos pos) const;

/**
* Returns the CRC32 of the directory entries. This is not influenced by
* the contents of the lumps.
*/
de::duint32 crc32() const;

bool has(de::Block const &lumpName) const;

de::duint32 lumpSize(de::Block const &lumpName) const;

private:
DENG2_PRIVATE(d)
};

} // namespace res

#endif // LIBDOOMSDAY_RESOURCE_LUMPDIRECTORY_H
Expand Up @@ -25,7 +25,7 @@
#include <de/NativePath>
#include <de/PathTree>
#include <de/System>
#include <de/libcore.h>
#include <de/Info>

/**
* Base class for the resource management subsystem.
Expand Down

0 comments on commit f9969b3

Please sign in to comment.