metaforce/hecl/lib/database/CProject.cpp

209 lines
5.0 KiB
C++
Raw Normal View History

2015-05-21 02:33:05 +00:00
#include <sys/stat.h>
#include <errno.h>
2015-06-09 22:19:59 +00:00
#include <stdio.h>
2015-05-21 02:33:05 +00:00
#include <string.h>
#include <system_error>
#include "HECLDatabase.hpp"
namespace HECLDatabase
{
2015-06-09 22:19:59 +00:00
static inline bool CheckNewLineAdvance(std::string::const_iterator& it)
{
if (*it == '\n' || *it == '\0')
{
it += 1;
return true;
}
else if (*it == '\r')
{
if (*(it+1) == '\n')
{
it += 2;
return true;
}
}
return false;
}
2015-05-21 02:33:05 +00:00
class CProject : public IProject
{
2015-06-09 22:19:59 +00:00
HECL::SystemString m_rootPath;
class ConfigFile
{
const CProject& m_project;
const HECL::SystemString& m_name;
HECL::SystemString m_filepath;
public:
ConfigFile(const CProject& project, const HECL::SystemString& name)
: m_project(project), m_name(name)
{
m_filepath = project.m_rootPath + _S("/.hecl/config/") + name;
}
std::vector<std::string> readLines()
{
FILE* fp = HECL::Fopen(m_filepath.c_str(), _S("r"));
std::string mainString;
char readBuf[1024];
size_t readSz;
while ((readSz = fread(readBuf, 1, 1024, fp)))
mainString += std::string(readBuf, readSz);
fclose(fp);
std::string::const_iterator begin = mainString.begin();
std::string::const_iterator end = mainString.begin();
std::vector<std::string> retval;
while (end != mainString.end())
{
std::string::const_iterator origEnd = end;
if (CheckNewLineAdvance(end))
{
if (begin != origEnd)
retval.push_back(std::string(begin, origEnd));
begin = end;
continue;
}
++end;
}
if (begin != end)
retval.push_back(std::string(begin, end));
return retval;
}
void addLine(const std::string& line)
{
std::vector<std::string> curLines = readLines();
FILE* fp = HECL::Fopen(m_filepath.c_str(), _S("w"));
for (std::string& line : curLines)
{
fwrite(line.data(), 1, line.length(), fp);
fwrite("\n", 1, 1, fp);
}
fwrite(line.data(), 1, line.length(), fp);
fwrite("\n", 1, 1, fp);
fclose(fp);
}
void removeLine(const std::string& refLine)
{
std::vector<std::string> curLines = readLines();
FILE* fp = HECL::Fopen(m_filepath.c_str(), _S("w"));
for (std::string& line : curLines)
{
if (line.compare(refLine))
{
fwrite(line.data(), 1, line.length(), fp);
fwrite("\n", 1, 1, fp);
}
}
fclose(fp);
}
bool checkForLine(const std::string& refLine)
{
std::vector<std::string> curLines = readLines();
for (std::string& line : curLines)
{
if (!line.compare(refLine))
return true;
}
return false;
}
};
2015-05-21 02:33:05 +00:00
public:
CProject(const std::string& rootPath)
: m_rootPath(rootPath)
{
/* Stat for existing project directory (must already exist) */
struct stat myStat;
if (stat(m_rootPath.c_str(), &myStat))
throw std::error_code(errno, std::system_category());
if (!S_ISDIR(myStat.st_mode))
throw std::invalid_argument("provided path must be a directory; '" + m_rootPath + "' isn't");
2015-06-09 22:19:59 +00:00
/* Create project directory structure */
HECL::MakeDir(m_rootPath + "/.hecl");
HECL::MakeDir(m_rootPath + "/.hecl/cooked");
HECL::MakeDir(m_rootPath + "/.hecl/config");
2015-05-21 02:33:05 +00:00
/* Create or open databases */
}
2015-05-22 08:21:44 +00:00
~CProject()
{
2015-05-21 02:33:05 +00:00
}
void registerLogger(HECL::TLogger logger)
{
}
2015-05-27 09:09:05 +00:00
const HECL::ProjectRootPath& getProjectRootPath(bool absolute) const
2015-05-21 02:33:05 +00:00
{
}
2015-06-09 22:19:59 +00:00
bool addPaths(const std::vector<HECL::ProjectPath>& paths)
2015-05-21 02:33:05 +00:00
{
}
2015-06-09 22:19:59 +00:00
bool removePaths(const std::vector<HECL::ProjectPath>& paths, bool recursive)
2015-05-21 02:33:05 +00:00
{
}
bool addGroup(const std::string& path)
{
}
bool removeGroup(const std::string& path)
{
}
2015-06-09 22:19:59 +00:00
const std::map<const std::string, const bool>& listPlatforms()
{
}
bool enablePlatforms(const std::vector<std::string>& platforms)
{
}
bool disablePlatforms(const std::vector<std::string>& platforms)
{
}
2015-05-21 02:33:05 +00:00
bool cookPath(const std::string& path,
2015-06-09 22:19:59 +00:00
std::function<void(std::string&, Cost, unsigned)> feedbackCb,
bool recursive)
2015-05-21 02:33:05 +00:00
{
}
void interruptCook()
{
}
bool cleanPath(const std::string& path, bool recursive)
{
}
bool packagePath(const std::string& path, bool recursive)
{
}
};
2015-05-27 09:09:05 +00:00
IProject* OpenProject(const std::string& rootPath)
2015-05-21 02:33:05 +00:00
{
return new CProject(rootPath);
}
}