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>
|
|
|
|
|
2015-06-10 23:34:14 +00:00
|
|
|
#if _WIN32
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 06:03:59 +00:00
|
|
|
#include "HECL/Database.hpp"
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
namespace HECL
|
|
|
|
{
|
|
|
|
namespace Database
|
2015-05-21 02:33:05 +00:00
|
|
|
{
|
|
|
|
|
2015-07-06 01:35:08 +00:00
|
|
|
LogVisor::LogModule LogModule("HECLDatabase");
|
|
|
|
|
2015-06-09 23:21:45 +00:00
|
|
|
/**********************************************
|
|
|
|
* Project::ConfigFile
|
|
|
|
**********************************************/
|
|
|
|
|
2015-06-09 22:19:59 +00:00
|
|
|
static inline bool CheckNewLineAdvance(std::string::const_iterator& it)
|
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (*it == '\n')
|
2015-06-09 22:19:59 +00:00
|
|
|
{
|
|
|
|
it += 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (*it == '\r')
|
|
|
|
{
|
|
|
|
if (*(it+1) == '\n')
|
|
|
|
{
|
|
|
|
it += 2;
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
it += 1;
|
|
|
|
return true;
|
2015-06-09 22:19:59 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-12 09:08:49 +00:00
|
|
|
Project::ConfigFile::ConfigFile(const Project& project, const SystemString& name,
|
|
|
|
const SystemString& subdir)
|
2015-05-21 02:33:05 +00:00
|
|
|
{
|
2015-06-12 09:08:49 +00:00
|
|
|
m_filepath = project.m_rootPath.getAbsolutePath() + subdir + name;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
std::vector<std::string>& Project::ConfigFile::lockAndRead()
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (m_lockedFile)
|
|
|
|
return m_lines;
|
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
m_lockedFile = HECL::Fopen(m_filepath.c_str(), _S("a+"), LWRITE);
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
std::string mainString;
|
|
|
|
char readBuf[1024];
|
|
|
|
size_t readSz;
|
2015-06-10 23:34:14 +00:00
|
|
|
while ((readSz = fread(readBuf, 1, 1024, m_lockedFile)))
|
2015-06-09 22:57:21 +00:00
|
|
|
mainString += std::string(readBuf, readSz);
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
std::string::const_iterator begin = mainString.begin();
|
|
|
|
std::string::const_iterator end = mainString.begin();
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-10 23:34:14 +00:00
|
|
|
m_lines.clear();
|
2015-06-09 22:57:21 +00:00
|
|
|
while (end != mainString.end())
|
|
|
|
{
|
|
|
|
std::string::const_iterator origEnd = end;
|
|
|
|
if (*end == '\0')
|
|
|
|
break;
|
|
|
|
else if (CheckNewLineAdvance(end))
|
2015-06-09 22:19:59 +00:00
|
|
|
{
|
2015-06-09 22:57:21 +00:00
|
|
|
if (begin != origEnd)
|
2015-06-10 23:34:14 +00:00
|
|
|
m_lines.push_back(std::string(begin, origEnd));
|
2015-06-09 22:57:21 +00:00
|
|
|
begin = end;
|
|
|
|
continue;
|
2015-06-09 22:19:59 +00:00
|
|
|
}
|
2015-06-09 22:57:21 +00:00
|
|
|
++end;
|
|
|
|
}
|
|
|
|
if (begin != end)
|
2015-06-10 23:34:14 +00:00
|
|
|
m_lines.push_back(std::string(begin, end));
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-10 23:34:14 +00:00
|
|
|
return m_lines;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
void Project::ConfigFile::addLine(const std::string& line)
|
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (!checkForLine(line))
|
|
|
|
m_lines.push_back(line);
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
void Project::ConfigFile::removeLine(const std::string& refLine)
|
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (!m_lockedFile)
|
2015-07-06 01:35:08 +00:00
|
|
|
{
|
2015-07-18 04:35:01 +00:00
|
|
|
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__,
|
|
|
|
"Project::ConfigFile::lockAndRead not yet called");
|
2015-07-06 01:35:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
for (auto it = m_lines.begin();
|
2015-06-13 20:10:37 +00:00
|
|
|
it != m_lines.end();)
|
2015-05-21 02:33:05 +00:00
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (!(*it).compare(refLine))
|
2015-06-13 20:10:37 +00:00
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
it = m_lines.erase(it);
|
2015-06-13 20:10:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2015-05-21 02:33:05 +00:00
|
|
|
}
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
bool Project::ConfigFile::checkForLine(const std::string& refLine)
|
|
|
|
{
|
2015-06-10 23:34:14 +00:00
|
|
|
if (!m_lockedFile)
|
2015-07-06 01:35:08 +00:00
|
|
|
{
|
2015-07-18 04:35:01 +00:00
|
|
|
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__,
|
|
|
|
"Project::ConfigFile::lockAndRead not yet called");
|
2015-07-06 01:35:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
|
|
|
|
for (const std::string& line : m_lines)
|
2015-06-09 22:57:21 +00:00
|
|
|
if (!line.compare(refLine))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-10 23:34:14 +00:00
|
|
|
void Project::ConfigFile::unlockAndDiscard()
|
|
|
|
{
|
|
|
|
if (!m_lockedFile)
|
2015-07-06 01:35:08 +00:00
|
|
|
{
|
2015-07-18 04:35:01 +00:00
|
|
|
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__,
|
|
|
|
"Project::ConfigFile::lockAndRead not yet called");
|
2015-07-06 01:35:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
|
|
|
|
m_lines.clear();
|
|
|
|
fclose(m_lockedFile);
|
|
|
|
m_lockedFile = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
bool Project::ConfigFile::unlockAndCommit()
|
2015-06-10 23:34:14 +00:00
|
|
|
{
|
|
|
|
if (!m_lockedFile)
|
2015-07-06 01:35:08 +00:00
|
|
|
{
|
2015-07-18 04:35:01 +00:00
|
|
|
LogModule.reportSource(LogVisor::FatalError, __FILE__, __LINE__,
|
|
|
|
"Project::ConfigFile::lockAndRead not yet called");
|
2015-07-06 01:35:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
SystemString newPath = m_filepath + _S(".part");
|
|
|
|
FILE* newFile = HECL::Fopen(newPath.c_str(), _S("w"), LWRITE);
|
|
|
|
bool fail = false;
|
2015-06-10 23:34:14 +00:00
|
|
|
for (const std::string& line : m_lines)
|
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
if (fwrite(line.c_str(), 1, line.size(), newFile) != line.size())
|
|
|
|
{
|
|
|
|
fail = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fwrite("\n", 1, 1, newFile) != 1)
|
|
|
|
{
|
|
|
|
fail = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
}
|
|
|
|
m_lines.clear();
|
2015-06-11 09:41:10 +00:00
|
|
|
fclose(newFile);
|
2015-06-10 23:34:14 +00:00
|
|
|
fclose(m_lockedFile);
|
|
|
|
m_lockedFile = NULL;
|
2015-06-11 09:41:10 +00:00
|
|
|
if (fail)
|
|
|
|
{
|
2015-07-22 19:14:50 +00:00
|
|
|
#if HECL_UCS2
|
|
|
|
_wunlink(newPath.c_str());
|
|
|
|
#else
|
2015-06-11 09:41:10 +00:00
|
|
|
unlink(newPath.c_str());
|
2015-07-22 19:14:50 +00:00
|
|
|
#endif
|
2015-06-11 09:41:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-22 19:14:50 +00:00
|
|
|
#if HECL_UCS2
|
|
|
|
_wrename(newPath.c_str(), m_filepath.c_str());
|
|
|
|
#else
|
2015-06-11 09:41:10 +00:00
|
|
|
rename(newPath.c_str(), m_filepath.c_str());
|
2015-07-22 19:14:50 +00:00
|
|
|
#endif
|
2015-06-11 09:41:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-10 23:34:14 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 23:21:45 +00:00
|
|
|
/**********************************************
|
|
|
|
* Project
|
|
|
|
**********************************************/
|
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
Project::Project(const ProjectRootPath& rootPath)
|
2015-06-11 04:55:06 +00:00
|
|
|
: m_rootPath(rootPath),
|
2015-09-30 06:23:07 +00:00
|
|
|
m_workRoot(*this, _S("")),
|
|
|
|
m_dotPath(m_workRoot, _S(".hecl")),
|
2015-07-18 04:35:01 +00:00
|
|
|
m_cookedRoot(m_dotPath, _S("cooked")),
|
2015-06-11 04:55:06 +00:00
|
|
|
m_specs(*this, _S("specs")),
|
|
|
|
m_paths(*this, _S("paths")),
|
2015-06-12 04:02:23 +00:00
|
|
|
m_groups(*this, _S("groups"))
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
|
|
|
/* Stat for existing project directory (must already exist) */
|
2015-07-22 19:14:50 +00:00
|
|
|
Sstat myStat;
|
2015-06-10 02:40:03 +00:00
|
|
|
if (HECL::Stat(m_rootPath.getAbsolutePath().c_str(), &myStat))
|
2015-07-26 02:52:02 +00:00
|
|
|
{
|
|
|
|
LogModule.report(LogVisor::Error, _S("unable to stat %s"), m_rootPath.getAbsolutePath().c_str());
|
|
|
|
return;
|
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
if (!S_ISDIR(myStat.st_mode))
|
2015-07-26 02:52:02 +00:00
|
|
|
{
|
|
|
|
LogModule.report(LogVisor::Error, _S("provided path must be a directory; '%s' isn't"), m_rootPath.getAbsolutePath().c_str());
|
|
|
|
return;
|
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
/* Create project directory structure */
|
2015-07-18 04:35:01 +00:00
|
|
|
m_dotPath.makeDir();
|
|
|
|
m_cookedRoot.makeDir();
|
2015-06-11 09:41:10 +00:00
|
|
|
|
2015-06-12 04:02:23 +00:00
|
|
|
/* Ensure beacon is valid or created */
|
2015-07-18 04:35:01 +00:00
|
|
|
ProjectPath beaconPath(m_dotPath, _S("beacon"));
|
|
|
|
FILE* bf = HECL::Fopen(beaconPath.getAbsolutePath().c_str(), _S("a+b"));
|
2015-06-12 04:02:23 +00:00
|
|
|
struct BeaconStruct
|
|
|
|
{
|
2015-07-11 22:42:40 +00:00
|
|
|
HECL::FourCC magic;
|
2015-06-12 04:02:23 +00:00
|
|
|
uint32_t version;
|
|
|
|
} beacon;
|
|
|
|
#define DATA_VERSION 1
|
2015-07-11 22:42:40 +00:00
|
|
|
static const HECL::FourCC HECLfcc("HECL");
|
2015-06-12 04:02:23 +00:00
|
|
|
if (fread(&beacon, 1, sizeof(beacon), bf) != sizeof(beacon))
|
|
|
|
{
|
|
|
|
fseek(bf, 0, SEEK_SET);
|
2015-07-11 22:42:40 +00:00
|
|
|
beacon.magic = HECLfcc;
|
2015-06-12 04:02:23 +00:00
|
|
|
beacon.version = SBig(DATA_VERSION);
|
|
|
|
fwrite(&beacon, 1, sizeof(beacon), bf);
|
|
|
|
}
|
|
|
|
fclose(bf);
|
2015-07-11 22:42:40 +00:00
|
|
|
if (beacon.magic != HECLfcc ||
|
2015-06-12 04:02:23 +00:00
|
|
|
SBig(beacon.version) != DATA_VERSION)
|
2015-07-06 01:35:08 +00:00
|
|
|
{
|
|
|
|
LogModule.report(LogVisor::FatalError, "incompatible project version");
|
|
|
|
return;
|
|
|
|
}
|
2015-06-12 04:02:23 +00:00
|
|
|
|
|
|
|
/* Compile current dataspec */
|
|
|
|
rescanDataSpecs();
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
bool Project::addPaths(const std::vector<ProjectPath>& paths)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
m_paths.lockAndRead();
|
|
|
|
for (const ProjectPath& path : paths)
|
|
|
|
m_paths.addLine(path.getRelativePathUTF8());
|
|
|
|
return m_paths.unlockAndCommit();
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-06-09 22:19:59 +00:00
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
bool Project::removePaths(const std::vector<ProjectPath>& paths, bool recursive)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
std::vector<std::string>& existingPaths = m_paths.lockAndRead();
|
2015-06-11 09:41:10 +00:00
|
|
|
if (recursive)
|
|
|
|
{
|
|
|
|
for (const ProjectPath& path : paths)
|
|
|
|
{
|
|
|
|
std::string recursiveBase = path.getRelativePathUTF8();
|
|
|
|
for (auto it = existingPaths.begin();
|
2015-06-13 20:12:55 +00:00
|
|
|
it != existingPaths.end();)
|
2015-06-11 09:41:10 +00:00
|
|
|
{
|
|
|
|
if (!(*it).compare(0, recursiveBase.size(), recursiveBase))
|
2015-06-13 20:10:37 +00:00
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
it = existingPaths.erase(it);
|
2015-06-13 20:10:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
2015-06-11 09:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (const ProjectPath& path : paths)
|
|
|
|
m_paths.removeLine(path.getRelativePathUTF8());
|
|
|
|
return m_paths.unlockAndCommit();
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-09 22:57:21 +00:00
|
|
|
bool Project::addGroup(const HECL::ProjectPath& path)
|
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
m_groups.lockAndRead();
|
|
|
|
m_groups.addLine(path.getRelativePathUTF8());
|
|
|
|
return m_groups.unlockAndCommit();
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
bool Project::removeGroup(const ProjectPath& path)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
m_groups.lockAndRead();
|
|
|
|
m_groups.removeLine(path.getRelativePathUTF8());
|
|
|
|
return m_groups.unlockAndCommit();
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-12 04:02:23 +00:00
|
|
|
void Project::rescanDataSpecs()
|
|
|
|
{
|
|
|
|
m_compiledSpecs.clear();
|
|
|
|
m_specs.lockAndRead();
|
2015-07-01 23:53:05 +00:00
|
|
|
for (const DataSpecEntry* spec : DATA_SPEC_REGISTRY)
|
2015-06-12 04:02:23 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
HECL::SystemString specStr(spec->m_name);
|
|
|
|
SystemUTF8View specUTF8(specStr);
|
2015-07-22 19:14:50 +00:00
|
|
|
m_compiledSpecs.push_back({*spec, ProjectPath(m_cookedRoot, HECL::SystemString(spec->m_name) + _S(".spec")),
|
2015-07-18 04:35:01 +00:00
|
|
|
m_specs.checkForLine(specUTF8) ? true : false});
|
2015-06-12 04:02:23 +00:00
|
|
|
}
|
|
|
|
m_specs.unlockAndDiscard();
|
|
|
|
}
|
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
bool Project::enableDataSpecs(const std::vector<SystemString>& specs)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
m_specs.lockAndRead();
|
|
|
|
for (const SystemString& spec : specs)
|
2015-07-22 19:14:50 +00:00
|
|
|
{
|
|
|
|
SystemUTF8View specView(spec);
|
|
|
|
m_specs.addLine(specView);
|
|
|
|
}
|
2015-07-18 04:35:01 +00:00
|
|
|
bool result = m_specs.unlockAndCommit();
|
|
|
|
rescanDataSpecs();
|
|
|
|
return result;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 09:41:10 +00:00
|
|
|
bool Project::disableDataSpecs(const std::vector<SystemString>& specs)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-06-11 09:41:10 +00:00
|
|
|
m_specs.lockAndRead();
|
|
|
|
for (const SystemString& spec : specs)
|
2015-07-22 19:14:50 +00:00
|
|
|
{
|
|
|
|
SystemUTF8View specView(spec);
|
|
|
|
m_specs.removeLine(specView);
|
|
|
|
}
|
2015-07-18 04:35:01 +00:00
|
|
|
bool result = m_specs.unlockAndCommit();
|
|
|
|
rescanDataSpecs();
|
|
|
|
return result;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
class CookProgress
|
|
|
|
{
|
|
|
|
FProgress& m_progFunc;
|
|
|
|
const SystemChar* m_dir = nullptr;
|
|
|
|
const SystemChar* m_file = nullptr;
|
|
|
|
int lidx = 0;
|
|
|
|
float m_prog = 0.0;
|
|
|
|
public:
|
|
|
|
CookProgress(FProgress& progFunc) : m_progFunc(progFunc) {}
|
|
|
|
void changeDir(const SystemChar* dir) {m_dir = dir; ++lidx;}
|
|
|
|
void changeFile(const SystemChar* file, float prog) {m_file = file; m_prog = prog;}
|
|
|
|
void reportFile(const DataSpecEntry* specEnt)
|
|
|
|
{
|
|
|
|
SystemString submsg(m_file);
|
|
|
|
submsg += _S(" (");
|
|
|
|
submsg += specEnt->m_name;
|
|
|
|
submsg += _S(')');
|
|
|
|
m_progFunc(m_dir, submsg.c_str(), lidx, m_prog);
|
|
|
|
}
|
|
|
|
void reportDirComplete() {m_progFunc(m_dir, nullptr, lidx, 1.0);}
|
|
|
|
};
|
|
|
|
|
|
|
|
using SpecInst = std::pair<const DataSpecEntry*, std::unique_ptr<IDataSpec>>;
|
|
|
|
|
|
|
|
static void VisitFile(const ProjectPath& path,
|
|
|
|
std::vector<SpecInst>& specInsts,
|
|
|
|
CookProgress& progress)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
for (SpecInst& spec : specInsts)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
if (spec.second->canCook(path))
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
ProjectPath cooked = path.getCookedPath(*spec.first);
|
|
|
|
if (path.getModtime() > cooked.getModtime())
|
|
|
|
{
|
|
|
|
progress.reportFile(spec.first);
|
|
|
|
spec.second->doCook(path, cooked);
|
|
|
|
}
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
static void VisitDirectory(const ProjectPath& dir, bool recursive,
|
|
|
|
std::vector<SpecInst>& specInsts,
|
|
|
|
CookProgress& progress)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
std::vector<ProjectPath> children;
|
2015-09-30 06:23:07 +00:00
|
|
|
dir.getDirChildren(children);
|
2015-10-04 04:35:18 +00:00
|
|
|
|
|
|
|
/* Pass 1: child file count */
|
|
|
|
int childFileCount = 0;
|
2015-09-30 06:23:07 +00:00
|
|
|
for (ProjectPath& child : children)
|
|
|
|
{
|
|
|
|
switch (child.getPathType())
|
|
|
|
{
|
|
|
|
case ProjectPath::PT_FILE:
|
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
++childFileCount;
|
2015-09-30 06:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-10-04 04:35:18 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass 2: child files */
|
|
|
|
int progNum = 0;
|
|
|
|
float progDenom = childFileCount;
|
|
|
|
progress.changeDir(dir.getLastComponent());
|
|
|
|
for (ProjectPath& child : children)
|
|
|
|
{
|
|
|
|
switch (child.getPathType())
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
case ProjectPath::PT_FILE:
|
|
|
|
{
|
|
|
|
progress.changeFile(child.getLastComponent(), progNum++/progDenom);
|
|
|
|
VisitFile(child, specInsts, progress);
|
2015-09-30 06:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 04:35:18 +00:00
|
|
|
progress.reportDirComplete();
|
|
|
|
|
|
|
|
/* Pass 3: child directories */
|
|
|
|
if (recursive)
|
|
|
|
{
|
|
|
|
for (ProjectPath& child : children)
|
|
|
|
{
|
|
|
|
switch (child.getPathType())
|
|
|
|
{
|
|
|
|
case ProjectPath::PT_DIRECTORY:
|
|
|
|
{
|
|
|
|
VisitDirectory(child, recursive, specInsts, progress);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
static void VisitGlob(const ProjectPath& path, bool recursive,
|
|
|
|
std::vector<SpecInst>& specInsts,
|
|
|
|
CookProgress& progress)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
std::vector<ProjectPath> children;
|
|
|
|
path.getGlobResults(children);
|
2015-09-30 06:23:07 +00:00
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
/* Pass 1: child file count */
|
|
|
|
int childFileCount = 0;
|
|
|
|
for (ProjectPath& child : children)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
switch (child.getPathType())
|
|
|
|
{
|
|
|
|
case ProjectPath::PT_FILE:
|
|
|
|
{
|
|
|
|
++childFileCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
2015-10-04 04:35:18 +00:00
|
|
|
|
|
|
|
/* Pass 2: child files */
|
|
|
|
int progNum = 0;
|
|
|
|
float progDenom = childFileCount;
|
|
|
|
progress.changeDir(path.getLastComponent());
|
|
|
|
for (ProjectPath& child : children)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
switch (child.getPathType())
|
|
|
|
{
|
|
|
|
case ProjectPath::PT_FILE:
|
|
|
|
{
|
|
|
|
progress.changeFile(child.getLastComponent(), progNum++/progDenom);
|
|
|
|
VisitFile(child, specInsts, progress);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
2015-10-04 04:35:18 +00:00
|
|
|
progress.reportDirComplete();
|
|
|
|
|
|
|
|
/* Pass 3: child directories */
|
|
|
|
if (recursive)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
for (ProjectPath& child : children)
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
switch (child.getPathType())
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
|
|
|
case ProjectPath::PT_DIRECTORY:
|
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
VisitDirectory(child, recursive, specInsts, progress);
|
2015-09-30 06:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 04:35:18 +00:00
|
|
|
}
|
2015-09-30 06:23:07 +00:00
|
|
|
|
2015-10-04 04:35:18 +00:00
|
|
|
bool Project::cookPath(const ProjectPath& path, FProgress progress, bool recursive)
|
|
|
|
{
|
|
|
|
/* Construct DataSpec instances for cooking */
|
|
|
|
std::vector<SpecInst> specInsts;
|
|
|
|
specInsts.reserve(m_compiledSpecs.size());
|
|
|
|
for (const ProjectDataSpec& spec : m_compiledSpecs)
|
|
|
|
if (spec.active)
|
|
|
|
specInsts.emplace_back(&spec.spec,
|
|
|
|
std::unique_ptr<IDataSpec>(spec.spec.m_factory(*this, TOOL_COOK)));
|
|
|
|
|
|
|
|
/* Iterate complete directory/file/glob list */
|
|
|
|
CookProgress cookProg(progress);
|
|
|
|
switch (path.getPathType())
|
2015-09-30 06:23:07 +00:00
|
|
|
{
|
2015-10-04 04:35:18 +00:00
|
|
|
case ProjectPath::PT_FILE:
|
|
|
|
{
|
|
|
|
cookProg.changeFile(path.getLastComponent(), 0.0);
|
|
|
|
VisitFile(path, specInsts, cookProg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ProjectPath::PT_DIRECTORY:
|
|
|
|
{
|
|
|
|
VisitDirectory(path, recursive, specInsts, cookProg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ProjectPath::PT_GLOB:
|
|
|
|
{
|
|
|
|
VisitGlob(path, recursive, specInsts, cookProg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
2015-09-30 06:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Project::interruptCook()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-10 02:40:03 +00:00
|
|
|
bool Project::cleanPath(const ProjectPath& path, bool recursive)
|
2015-06-09 22:57:21 +00:00
|
|
|
{
|
2015-07-22 19:14:50 +00:00
|
|
|
return false;
|
2015-06-09 22:57:21 +00:00
|
|
|
}
|
2015-05-21 02:33:05 +00:00
|
|
|
|
2015-06-11 04:55:06 +00:00
|
|
|
PackageDepsgraph Project::buildPackageDepsgraph(const ProjectPath& path)
|
2015-05-21 02:33:05 +00:00
|
|
|
{
|
2015-07-22 19:14:50 +00:00
|
|
|
return PackageDepsgraph();
|
2015-05-21 02:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-06-10 02:40:03 +00:00
|
|
|
}
|