void Renderer::setupEmptyDirectory(const filesystem::path &path) { FileUtils::createDir(path.str()); tinydir_dir dir; tinydir_open_sorted(&dir, path.str().c_str()); for (size_t i = 0; i < dir.n_files; ++i) { tinydir_file file; tinydir_readfile_n(&dir, &file, i); if (file.is_reg) { FileUtils::deleteFile((path / file.name).str()); } } tinydir_close(&dir); }
bool Parser::ParseProject(const filesystem::path& filePath) { if (filePath.str().empty()) { std::cout << "invalid project filename" << std::endl; return false; } auto project = JsonImporter::ImportProject(pimpl_->GetFileManager(), filePath); return ParseProject(project.get()); }
nlohmann::json ParseJsonFile(FileSystem& fileSystem, const filesystem::path& filePath) { auto stream = fileSystem.OpenStream(filePath.str()); if (stream) { std::stringstream buffer; buffer << stream->rdbuf(); return nlohmann::json::parse(buffer.str()); } return nullptr; }
void CommandLineArguments::Save(const filesystem::path& filePath) const { std::ofstream stream(filePath.str()); if (stream.is_open()) { for (auto& arg : arguments_) { stream << arg << std::endl;; } stream.close(); } }
bool Parser::ParseWorkspace(const filesystem::path& filePath) { if (filePath.str().empty()) { std::cout << "invalid workspace filename" << std::endl; return false; } WorkingDirectory::SetCurrent(filePath.make_absolute().parent_path().str()); std::cout << "{ cwd : " << WorkingDirectory::GetCurrent() << " }" << std::endl; internal::EnsureDirectoryExists(outputDirectory_); auto workspace = JsonImporter::ImportWorkspace(pimpl_->GetFileManager(), filePath.filename()); return ParseWorkspace(workspace.get()); }
std::unique_ptr<std::istream> FileSystem::OpenStream(const filesystem::path& file) { auto stream = std::make_unique<std::ifstream>(file.str()); return stream->is_open() ? std::move(stream) : nullptr; }