2017-11-15 09:04:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <Common\path.h>
|
|
|
|
#include <Common\FileClass.h>
|
|
|
|
#include <Common\StdString.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
if (__argc < 4)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPath SourceFile(__argv[1]), DestFile(__argv[2]);
|
|
|
|
if (!SourceFile.Exists())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DestFile.Exists())
|
|
|
|
{
|
|
|
|
if (!DestFile.Delete())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFile InFile(SourceFile, CFileBase::modeRead);
|
|
|
|
if (!InFile.IsOpen())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
InFile.SeekToBegin();
|
|
|
|
uint32_t FileLen = InFile.GetLength();
|
|
|
|
std::auto_ptr<uint8_t> InputData(new uint8_t[FileLen]);
|
|
|
|
InFile.Read(InputData.get(), FileLen);
|
2018-05-22 16:38:15 +00:00
|
|
|
strvector VersionData = stdstr(std::string((char *)InputData.get(), FileLen)).Tokenize("\n");
|
2017-11-15 09:04:09 +00:00
|
|
|
|
|
|
|
strvector verinfo = stdstr(__argv[3]).Tokenize('-');
|
|
|
|
if (verinfo.size() < 3 || verinfo.size() > 4)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (verinfo.size() == 4)
|
|
|
|
{
|
|
|
|
verinfo[2] += "-" + verinfo[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
CFile OutFile(DestFile, CFileBase::modeWrite | CFileBase::modeCreate);
|
|
|
|
if (!OutFile.IsOpen())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0, n = VersionData.size() - 1; i < n; i++)
|
|
|
|
{
|
|
|
|
stdstr &line = VersionData[i];
|
2018-05-22 16:38:15 +00:00
|
|
|
line += "\n";
|
2017-11-15 09:04:09 +00:00
|
|
|
if (_strnicmp(line.c_str(), "#define VERSION_BUILD", 21) == 0)
|
|
|
|
{
|
2018-05-22 16:38:15 +00:00
|
|
|
line = "#define VERSION_BUILD " + verinfo[1] + "\n";
|
2017-11-15 09:04:09 +00:00
|
|
|
}
|
|
|
|
if (_strnicmp(line.c_str(), "#define GIT_VERSION", 18) == 0)
|
|
|
|
{
|
2018-05-22 16:38:15 +00:00
|
|
|
line = "#define GIT_VERSION \"" + verinfo[2] + "\"\n";
|
2017-11-15 09:04:09 +00:00
|
|
|
}
|
2018-05-22 16:38:15 +00:00
|
|
|
if (!OutFile.Write(line.c_str(), (uint32_t)line.length()))
|
2017-11-15 09:04:09 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|