Skip to content

Commit

Permalink
Add magic file header
Browse files Browse the repository at this point in the history
0xD3 0x3D will be added to .ds3 file as the starting two bytes.
This is to force text editor treat .ds3 file as binary file instead of normal text file.
  • Loading branch information
huxingyi committed Feb 19, 2023
1 parent c38487b commit 002d192
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dust3d/base/ds3_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
namespace dust3d {

std::string Ds3FileReader::m_applicationName = std::string("DUST3D");
std::string Ds3FileReader::m_magicApplicationName = char(0xd3) + (char(0x3d) + std::string("DUST3D"));
std::string Ds3FileReader::m_fileFormatVersion = std::string("1.0");
std::string Ds3FileReader::m_headFormat = std::string("xml");

Expand All @@ -55,7 +56,7 @@ Ds3FileReader::Ds3FileReader(const std::uint8_t* fileData, size_t fileSize)
dust3dDebug << "Unexpected file header";
return;
}
if (tokens[0] != Ds3FileReader::m_applicationName) {
if (tokens[0] != Ds3FileReader::m_magicApplicationName && tokens[0] != Ds3FileReader::m_applicationName) {
dust3dDebug << "Unrecognized application name:" << tokens[0];
return;
}
Expand Down Expand Up @@ -174,7 +175,7 @@ bool Ds3FileWriter::save(const std::string& filename)
std::string headerXml = headerXmlStream.str();
char firstLine[1024];
int firstLineSizeExcludeSizeSelf = sprintf(firstLine, "%s %s %s ",
Ds3FileReader::m_applicationName.c_str(),
Ds3FileReader::m_magicApplicationName.c_str(),
Ds3FileReader::m_fileFormatVersion.c_str(),
Ds3FileReader::m_headFormat.c_str());
unsigned int headerSize = (unsigned int)(firstLineSizeExcludeSizeSelf + 12 + headerXml.size());
Expand Down
2 changes: 2 additions & 0 deletions dust3d/base/ds3_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class Ds3FileReader {
void loadItem(const std::string& name, std::vector<std::uint8_t>* byteArray);
const std::vector<Ds3ReaderItem>& items() const;
static std::string m_applicationName;
static std::string m_magicApplicationName;
static std::string m_fileFormatVersion;
static std::string m_headFormat;
static uint8_t m_magicNumber[2];

private:
std::map<std::string, Ds3ReaderItem> m_itemsMap;
Expand Down

0 comments on commit 002d192

Please sign in to comment.