| 1 |
#include "ReadmeTxt.h" |
| 2 |
|
| 3 |
#include "i18n.h" |
| 4 |
#include "iarchive.h" |
| 5 |
#include "itextstream.h" |
| 6 |
#include "ifilesystem.h" |
| 7 |
|
| 8 |
namespace map |
| 9 |
{ |
| 10 |
|
| 11 |
std::string ReadmeTxt::getFilename() |
| 12 |
{ |
| 13 |
return NAME(); |
| 14 |
} |
| 15 |
|
| 16 |
const std::string& ReadmeTxt::getContents() |
| 17 |
{ |
| 18 |
return _contents; |
| 19 |
} |
| 20 |
|
| 21 |
void ReadmeTxt::setContents(const std::string& contents) |
| 22 |
{ |
| 23 |
_contents = contents; |
| 24 |
} |
| 25 |
|
| 26 |
ReadmeTxtPtr ReadmeTxt::CreateFromString(const std::string& contents) |
| 27 |
{ |
| 28 |
ReadmeTxtPtr info(new ReadmeTxt); |
| 29 |
|
| 30 |
// The readme.txt parser appears to be rather simple |
| 31 |
info->_contents = contents; |
| 32 |
|
| 33 |
return info; |
| 34 |
} |
| 35 |
|
| 36 |
ReadmeTxtPtr ReadmeTxt::CreateFromStream(std::istream& stream) |
| 37 |
{ |
| 38 |
// Read all the stream contents into a string |
| 39 |
std::string str(std::istreambuf_iterator<char>(stream), {}); |
| 40 |
return CreateFromString(str); |
| 41 |
} |
| 42 |
|
| 43 |
ReadmeTxtPtr ReadmeTxt::LoadForCurrentMod() |
| 44 |
{ |
| 45 |
std::string readmeTxtPath = GetOutputPathForCurrentMod() + NAME(); |
| 46 |
|
| 47 |
rMessage() << "Trying to open file " << readmeTxtPath << std::endl; |
| 48 |
|
| 49 |
ArchiveTextFilePtr file = GlobalFileSystem().openTextFileInAbsolutePath(readmeTxtPath); |
| 50 |
|
| 51 |
if (file) |
| 52 |
{ |
| 53 |
std::istream stream(&(file->getInputStream())); |
| 54 |
return CreateFromStream(stream); |
| 55 |
} |
| 56 |
|
| 57 |
return std::make_shared<ReadmeTxt>(); |
| 58 |
} |
| 59 |
|
| 60 |
std::string ReadmeTxt::toString() |
| 61 |
{ |
| 62 |
return _contents; |
| 63 |
} |
| 64 |
|
| 65 |
} |