PsfPacker: Added tags support.

git-svn-id: http://svn.purei.org/purei/trunk@602 b36208d7-6611-0410-8bec-b1987f11c4a2
This commit is contained in:
jpd002 2010-03-18 05:24:33 +00:00
parent c87bdc491a
commit 853281138a
8 changed files with 111 additions and 7 deletions

View File

@ -184,6 +184,14 @@
RelativePath=".\Source\PsfFsWriter.cpp"
>
</File>
<File
RelativePath=".\Source\PsfTagsDescription.cpp"
>
</File>
<File
RelativePath=".\Source\PsfTagsWriter.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
@ -198,6 +206,14 @@
RelativePath=".\Source\PsfFsWriter.h"
>
</File>
<File
RelativePath=".\Source\PsfTagsDescription.h"
>
</File>
<File
RelativePath=".\Source\PsfTagsWriter.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

View File

@ -5,6 +5,8 @@
#include "StdStream.h"
#include "PsfFsDescription.h"
#include "PsfFsWriter.h"
#include "PsfTagsDescription.h"
#include "PsfTagsWriter.h"
#include "xml/Node.h"
#include "xml/Parser.h"
#include "xml/Utils.h"
@ -28,6 +30,7 @@ int main(int argc, const char** argv)
}
PsfFs::DirectoryPtr rootDir;
PsfTags::TagList tags;
{
std::tr1::shared_ptr<Framework::Xml::CNode> documentRoot;
@ -48,6 +51,11 @@ int main(int argc, const char** argv)
}
{
Framework::Xml::CNode* tagsNode = documentRoot->Select("Package/Tags");
if(tagsNode != NULL)
{
tags = PsfTags::ParseTags(tagsNode);
}
Framework::Xml::CNode* filesystemNode = documentRoot->Select("Package/Filesystem");
if(filesystemNode != NULL)
{
@ -94,6 +102,9 @@ int main(int argc, const char** argv)
output.Seek(0, Framework::STREAM_SEEK_SET);
output.Write(&header, sizeof(PSFHEADER));
output.Seek(0, Framework::STREAM_SEEK_END);
PsfTags::CWriter::Write(output, tags);
}
catch(const std::exception& exception)
{

View File

@ -1,4 +1,5 @@
#include "PsfFsWriter.h"
#include "StdStream.h"
#include <boost/filesystem/operations.hpp>
#include <boost/shared_array.hpp>
#include <zlib.h>
@ -18,13 +19,13 @@ CWriter::~CWriter()
}
void CWriter::Write(Framework::CStdStream& output, const DirectoryPtr& directory, const boost::filesystem::path& basePath)
void CWriter::Write(Framework::CStream& output, const DirectoryPtr& directory, const boost::filesystem::path& basePath)
{
CWriter writer(basePath, output.Tell());
writer.WriteDirectory(output, directory, NULL);
}
void CWriter::WriteFile(Framework::CStdStream& output, const FilePtr& file, DIRENTRY* dirEntry)
void CWriter::WriteFile(Framework::CStream& output, const FilePtr& file, DIRENTRY* dirEntry)
{
assert(dirEntry != NULL);
@ -75,7 +76,7 @@ void CWriter::WriteFile(Framework::CStdStream& output, const FilePtr& file, DIRE
}
}
void CWriter::WriteDirectory(Framework::CStdStream& output, const DirectoryPtr& directory, DIRENTRY* dirEntry)
void CWriter::WriteDirectory(Framework::CStream& output, const DirectoryPtr& directory, DIRENTRY* dirEntry)
{
std::vector<DIRENTRY> dirEntries;
dirEntries.reserve(directory->nodes.size());

View File

@ -1,7 +1,7 @@
#ifndef _PSFFSWRITER_H_
#define _PSFFSWRITER_H_
#include "StdStream.h"
#include "Stream.h"
#include "PsfFsDescription.h"
#include <boost/filesystem/path.hpp>
@ -10,7 +10,7 @@ namespace PsfFs
class CWriter
{
public:
static void Write(Framework::CStdStream&, const DirectoryPtr&, const boost::filesystem::path&);
static void Write(Framework::CStream&, const DirectoryPtr&, const boost::filesystem::path&);
private:
CWriter(const boost::filesystem::path&, uint64);
@ -24,8 +24,8 @@ namespace PsfFs
uint32 blockSize;
};
void WriteFile(Framework::CStdStream&, const FilePtr&, DIRENTRY*);
void WriteDirectory(Framework::CStdStream&, const DirectoryPtr&, DIRENTRY*);
void WriteFile(Framework::CStream&, const FilePtr&, DIRENTRY*);
void WriteDirectory(Framework::CStream&, const DirectoryPtr&, DIRENTRY*);
boost::filesystem::path m_basePath;
uint64 m_baseOffset;

View File

@ -0,0 +1,21 @@
#include <algorithm>
#include "PsfTagsDescription.h"
PsfTags::TagList PsfTags::ParseTags(Framework::Xml::CNode* tagsNode)
{
TagList result;
for(Framework::Xml::CNode::NodeIterator nodeIterator(tagsNode->GetChildrenBegin());
nodeIterator != tagsNode->GetChildrenEnd(); nodeIterator++)
{
Framework::Xml::CNode* node = (*nodeIterator);
if(!node->IsTag()) continue;
std::string tagName = node->GetText();
std::string tagValue = node->GetInnerText();
std::transform(tagName.begin(), tagName.end(), tagName.begin(), tolower);
result[tagName] = tagValue;
}
return result;
}

View File

@ -0,0 +1,14 @@
#ifndef _PSFTAGSDESCRIPTION_H_
#define _PSFTAGSDESCRIPTION_H_
#include <map>
#include "xml/Node.h"
namespace PsfTags
{
typedef std::map<std::string, std::string> TagList;
TagList ParseTags(Framework::Xml::CNode*);
}
#endif

View File

@ -0,0 +1,22 @@
#include "PsfTagsWriter.h"
using namespace PsfTags;
void CWriter::Write(Framework::CStream& output, const TagList& tags)
{
if(tags.size() == 0) return;
const char* tagHeader = "[TAG]";
output.Write(tagHeader, strlen(tagHeader));
for(TagList::const_iterator tagIterator(tags.begin());
tagIterator != tags.end(); tagIterator++)
{
const std::string& tagName(tagIterator->first);
const std::string& tagValue(tagIterator->second);
output.Write(tagName.c_str(), tagName.length());
output.Write8('=');
output.Write(tagValue.c_str(), tagValue.length());
output.Write8(0x0A);
}
}

View File

@ -0,0 +1,19 @@
#ifndef _PSFTAGSWRITER_H_
#define _PSFTAGSWRITER_H_
#include "Stream.h"
#include "PsfTagsDescription.h"
namespace PsfTags
{
class CWriter
{
public:
static void Write(Framework::CStream&, const TagList&);
private:
};
};
#endif