Skip to content

Commit

Permalink
os/filesystem: synced with MiniScript file system
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasdr committed Dec 1, 2023
1 parent 2adc4c9 commit 2f35ede
Show file tree
Hide file tree
Showing 26 changed files with 195 additions and 149 deletions.
2 changes: 1 addition & 1 deletion src/tdme/application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ int Application::run(int argc, char** argv, const string& title, InputEventHandl

void Application::setIcon() {
auto logoFileName = StringTools::replace(StringTools::toLowerCase(executableFileName), ".exe", "") + "-icon.png";
if (FileSystem::getInstance()->fileExists("resources/platforms/icons/" + logoFileName) == false) logoFileName = "default-icon.png";
if (FileSystem::getInstance()->exists("resources/platforms/icons/" + logoFileName) == false) logoFileName = "default-icon.png";
auto texture = TextureReader::read("resources/platforms/icons", logoFileName, false, false);
if (texture != nullptr) {
auto textureData = texture->getRGBTextureData();
Expand Down
16 changes: 8 additions & 8 deletions src/tdme/engine/fileio/models/FBXReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,12 @@ Node* FBXReader::processMeshNode(FbxNode* fbxNode, Model* model, Node* parentNod
}
if (diffuseTextureFileName.length() > 0) {
specularMaterialProperties->setDiffuseTexture(
FileSystem::getInstance()->fileExists(
FileSystem::getInstance()->getCanonicalPath(pathName, FileSystem::getInstance()->getFileName(diffuseTextureFileName))
FileSystem::getInstance()->exists(
FileSystem::getInstance()->composeURI(pathName, FileSystem::getInstance()->getFileName(diffuseTextureFileName))
)?pathName:FileSystem::getInstance()->getPathName(diffuseTextureFileName),
FileSystem::getInstance()->getFileName(diffuseTextureFileName),
FileSystem::getInstance()->fileExists(
FileSystem::getInstance()->getCanonicalPath(pathName, FileSystem::getInstance()->getFileName(diffuseTransparencyTextureFileName))
FileSystem::getInstance()->exists(
FileSystem::getInstance()->composeURI(pathName, FileSystem::getInstance()->getFileName(diffuseTransparencyTextureFileName))
)?pathName:FileSystem::getInstance()->getPathName(diffuseTransparencyTextureFileName),
FileSystem::getInstance()->getFileName(diffuseTransparencyTextureFileName)
);
Expand All @@ -630,8 +630,8 @@ Node* FBXReader::processMeshNode(FbxNode* fbxNode, Model* model, Node* parentNod
FbxCast<FbxFileTexture>(fbxProperty.GetSrcObject<FbxLayeredTexture>(0))->GetFileName();
if (normalTextureFileName.length() > 0) {
specularMaterialProperties->setNormalTexture(
FileSystem::getInstance()->fileExists(
FileSystem::getInstance()->getCanonicalPath(pathName, FileSystem::getInstance()->getFileName(normalTextureFileName))
FileSystem::getInstance()->exists(
FileSystem::getInstance()->composeURI(pathName, FileSystem::getInstance()->getFileName(normalTextureFileName))
)?pathName:FileSystem::getInstance()->getPathName(normalTextureFileName),
FileSystem::getInstance()->getFileName(normalTextureFileName)
);
Expand All @@ -647,8 +647,8 @@ Node* FBXReader::processMeshNode(FbxNode* fbxNode, Model* model, Node* parentNod
FbxCast<FbxFileTexture>(fbxProperty.GetSrcObject<FbxLayeredTexture>(0))->GetFileName();
if (specularTextureFileName.length() > 0) {
specularMaterialProperties->setSpecularTexture(
FileSystem::getInstance()->fileExists(
FileSystem::getInstance()->getCanonicalPath(pathName, FileSystem::getInstance()->getFileName(specularTextureFileName))
FileSystem::getInstance()->exists(
FileSystem::getInstance()->composeURI(pathName, FileSystem::getInstance()->getFileName(specularTextureFileName))
)?pathName:FileSystem::getInstance()->getPathName(specularTextureFileName),
FileSystem::getInstance()->getFileName(specularTextureFileName)
);
Expand Down
6 changes: 3 additions & 3 deletions src/tdme/engine/fileio/models/TMReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ Model* TMReader::read(const vector<uint8_t>& data, const string& pathName, const
}

const string TMReader::getTexturePath(const string& modelPathName, const string& texturePathName, const string& textureFileName) {
if (FileSystem::getInstance()->fileExists(texturePathName + "/" + textureFileName) == true) {
if (FileSystem::getInstance()->exists(texturePathName + "/" + textureFileName) == true) {
return texturePathName;
} else
if (FileSystem::getInstance()->fileExists(modelPathName + "/" + textureFileName) == true) {
if (FileSystem::getInstance()->exists(modelPathName + "/" + textureFileName) == true) {
return modelPathName;
} else
if (FileSystem::getInstance()->fileExists(FileSystem::getInstance()->getPathName(modelPathName) + "/" + textureFileName) == true) {
if (FileSystem::getInstance()->exists(FileSystem::getInstance()->getPathName(modelPathName) + "/" + textureFileName) == true) {
return FileSystem::getInstance()->getPathName(modelPathName);
} else {
return texturePathName;
Expand Down
2 changes: 1 addition & 1 deletion src/tdme/engine/fileio/prototypes/PrototypeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ Prototype* PrototypeReader::read(int id, const string& pathName, const Value& jP
}

const string PrototypeReader::getResourcePathName(const string& pathName, const string& fileName) {
string resourceFile = FileSystem::getInstance()->getCanonicalPath(
string resourceFile = FileSystem::getInstance()->getCanonicalURI(
StringTools::startsWith(FileSystem::getInstance()->getPathName(fileName), "/") == true?
FileSystem::getInstance()->getPathName(fileName):
pathName + "/" + FileSystem::getInstance()->getPathName(fileName),
Expand Down
2 changes: 1 addition & 1 deletion src/tdme/engine/fileio/scenes/SceneReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Scene* SceneReader::readFromModel(const string& pathName, const string& fileName
if (progressCallback != nullptr) progressCallback->progress(0.0f);

string modelPathName = pathName + "/" + fileName + "-models";
if (FileSystem::getInstance()->fileExists(modelPathName)) {
if (FileSystem::getInstance()->exists(modelPathName)) {
FileSystem::getInstance()->removePath(modelPathName, true);
}
FileSystem::getInstance()->createPath(modelPathName);
Expand Down
4 changes: 2 additions & 2 deletions src/tdme/engine/fileio/textures/TextureReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Texture* TextureReader::read(const string& pathName, const string& fileName, boo
Texture* texture = nullptr;

// make canonical
auto canonicalFilePath = FileSystem::getInstance()->getCanonicalPath(pathName, fileName);
auto canonicalFilePath = FileSystem::getInstance()->getCanonicalURI(pathName, fileName);
auto canonicalPathName = FileSystem::getInstance()->getPathName(canonicalFilePath);
auto canonicalFileName = FileSystem::getInstance()->getFileName(canonicalFilePath);

Expand Down Expand Up @@ -94,7 +94,7 @@ Texture* TextureReader::read(const string& pathName, const string& fileName, boo

Texture* TextureReader::read2(const string& texturePathName, const string& textureFileName, const string& transparencyTexturePathName, const string& transparencyTextureFileName, bool useCache, bool powerOfTwo, const string& idPrefix) {
// make canonical
auto canonicalFile = FileSystem::getInstance()->getCanonicalPath(texturePathName, textureFileName);
auto canonicalFile = FileSystem::getInstance()->getCanonicalURI(texturePathName, textureFileName);
auto canonicalPathName = FileSystem::getInstance()->getPathName(canonicalFile);
auto canonicalFileName = FileSystem::getInstance()->getFileName(canonicalFile);
auto cacheId = idPrefix + canonicalPathName + "/" + canonicalFileName + "/transparency";
Expand Down
8 changes: 4 additions & 4 deletions src/tdme/engine/logics/LogicMiniScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5213,10 +5213,10 @@ void LogicMiniScript::registerMethods() {
try {
auto _pathName = pathName;
if (miniScript->context->getApplicationRootPathName().empty() == false) {
_pathName = FileSystem::getInstance()->getCanonicalPath(miniScript->context->getApplicationRootPathName(), pathName);
_pathName = FileSystem::getInstance()->getCanonicalURI(miniScript->context->getApplicationRootPathName(), pathName);
}
Prototype* prototype = nullptr;
auto canonicalPath = FileSystem::getInstance()->getCanonicalPath(_pathName, fileName);
auto canonicalPath = FileSystem::getInstance()->getCanonicalURI(_pathName, fileName);
auto prototypeIt = miniScript->prototypes.find(canonicalPath);
if (prototypeIt != miniScript->prototypes.end()) {
prototypeIt->second.counter++;
Expand Down Expand Up @@ -5302,10 +5302,10 @@ void LogicMiniScript::registerMethods() {
try {
auto _pathName = pathName;
if (miniScript->context->getApplicationRootPathName().empty() == false) {
_pathName = FileSystem::getInstance()->getCanonicalPath(miniScript->context->getApplicationRootPathName(), pathName);
_pathName = FileSystem::getInstance()->getCanonicalURI(miniScript->context->getApplicationRootPathName(), pathName);
}
Prototype* prototype = nullptr;
auto canonicalPath = FileSystem::getInstance()->getCanonicalPath(_pathName, fileName);
auto canonicalPath = FileSystem::getInstance()->getCanonicalURI(_pathName, fileName);
auto prototypeIt = miniScript->prototypes.find(canonicalPath);
if (prototypeIt != miniScript->prototypes.end()) {
prototypeIt->second.counter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void VKGL3CoreShaderProgram::loadShader(VKRenderer::shader_type& shader, int32_t
shader.hash = SHA256::encode(shader.cacheId + "." + to_string(type) + definitions + functions);

// do we have a cached shader already?
if (FileSystem::getInstance()->fileExists("shader/vk/" + shader.cacheId + ".properties") == true) {
if (FileSystem::getInstance()->exists("shader/vk/" + shader.cacheId + ".properties") == true) {
Properties vkShaderCache;
vkShaderCache.load("shader/vk", shader.cacheId + ".properties");
if (shader.hash != vkShaderCache.get("shader.hash", "")) {
Expand Down Expand Up @@ -887,7 +887,7 @@ bool VKGL3CoreShaderProgram::linkProgram(VKRenderer::program_type& program) {
}

// check if we can use a cache
if (FileSystem::getInstance()->fileExists("shader/vk/program-" + to_string(program.id) + ".properties") == true) {
if (FileSystem::getInstance()->exists("shader/vk/program-" + to_string(program.id) + ".properties") == true) {
// use cache
useCache = true;

Expand Down
2 changes: 1 addition & 1 deletion src/tdme/engine/subsystems/renderer/VKRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ void VKRenderer::initialize()

// create VK shader cache folder
try {
if (FileSystem::getInstance()->fileExists("shader/vk") == false) {
if (FileSystem::getInstance()->exists("shader/vk") == false) {
FileSystem::getInstance()->createPath("shader/vk");
}
} catch (Exception& exception) {
Expand Down
2 changes: 1 addition & 1 deletion src/tdme/gui/GUIParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ GUIScreenNode* GUIParser::parse(const string& xml, const unordered_map<string, s
//
guiScreenNode = new GUIScreenNode(
(pathName.empty() == false?pathName + "/":"") + fileName,
applicationRootPath.empty() == true?".":FileSystem::getInstance()->getCanonicalPath(applicationRootPath, ""),
applicationRootPath.empty() == true?".":FileSystem::getInstance()->getCanonicalURI(applicationRootPath, ""),
applicationSubPathName,
string(AVOID_NULLPTR_STRING(xmlRoot->Attribute("id"))),
GUINode::createFlow(string(AVOID_NULLPTR_STRING(xmlRoot->Attribute("flow")))),
Expand Down
4 changes: 2 additions & 2 deletions src/tdme/gui/nodes/GUIScreenNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,10 @@ void GUIScreenNode::forwardEvents() {
void GUIScreenNode::getProjectFilePathNameAndFileName(const string &fileName, string& projectFilePathName, string& projectFileFileName) {
try {
string projectFileCanonicalFileName;
if (FileSystem::getInstance()->fileExists(fileName) == true) {
if (FileSystem::getInstance()->exists(fileName) == true) {
projectFileCanonicalFileName = fileName;
} else {
projectFileCanonicalFileName = FileSystem::getInstance()->getCanonicalPath(applicationRootPathName, fileName);
projectFileCanonicalFileName = FileSystem::getInstance()->getCanonicalURI(applicationRootPathName, fileName);
}
projectFilePathName = FileSystem::getInstance()->getPathName(projectFileCanonicalFileName);
projectFileFileName = FileSystem::getInstance()->getFileName(projectFileCanonicalFileName);
Expand Down
17 changes: 13 additions & 4 deletions src/tdme/os/filesystem/ArchiveFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const string& ArchiveFileSystem::getArchiveFileName() {
return fileName;
}

const string ArchiveFileSystem::getFileName(const string& pathName, const string& fileName) {
const string ArchiveFileSystem::composeURI(const string& pathName, const string& fileName) {
return pathName + "/" + fileName;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ bool ArchiveFileSystem::isDrive(const string& pathName) {
return false;
}

bool ArchiveFileSystem::fileExists(const string& fileName) {
bool ArchiveFileSystem::exists(const string& fileName) {
// compose relative file name and remove ./
auto relativeFileName = fileName;
if (StringTools::startsWith(relativeFileName, "./") == true) relativeFileName = StringTools::substring(relativeFileName, 2);
Expand Down Expand Up @@ -325,12 +325,12 @@ void ArchiveFileSystem::setContentFromStringArray(const string& pathName, const
throw FileSystemException("ArchiveFileSystem::setContentFromStringArray(): This operation is not supported in archive file system");
}

const string ArchiveFileSystem::getCanonicalPath(const string& pathName, const string& fileName) {
const string ArchiveFileSystem::getCanonicalURI(const string& pathName, const string& fileName) {
string unixPathName = StringTools::replace(pathName, "\\", "/");
string unixFileName = StringTools::replace(fileName, "\\", "/");

//
auto pathString = getFileName(unixPathName, unixFileName);
auto pathString = composeURI(unixPathName, unixFileName);

// separate into path components
vector<string> pathComponents;
Expand Down Expand Up @@ -407,6 +407,15 @@ const string ArchiveFileSystem::getFileName(const string& fileName) {
return StringTools::substring(unixFileName, lastPathSeparator + 1, unixFileName.length());
}

const string ArchiveFileSystem::removeFileExtension(const string& fileName) {
auto idx = fileName.rfind('.');
if (idx == string::npos) {
return fileName;
} else {
return fileName.substr(0, idx);
}
}

void ArchiveFileSystem::createPath(const string& pathName) {
throw FileSystemException("ArchiveFileSystem::createPath(): This operation is not supported in archive file system");
}
Expand Down
48 changes: 25 additions & 23 deletions src/tdme/os/filesystem/ArchiveFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,33 @@ class tdme::os::filesystem::ArchiveFileSystem final: public FileSystemInterface
const string& getArchiveFileName();

// overridden methods
const string getFileName(const string& path, const string& fileName) override;
void list(const string& pathName, vector<string>& files, FileNameFilter* filter = nullptr, bool addDrives = false) override;
bool isPath(const string& pathName) override;
bool isDrive(const string& pathName) override;
bool fileExists(const string& fileName) override;
// overridden methods
const string composeURI(const string& pathName, const string& fileName);
uint64_t getFileSize(const string& pathName, const string& fileName);
const string getContentAsString(const string& pathName, const string& fileName);
void setContentFromString(const string& pathName, const string& fileName, const string& content);
void getContent(const string& pathName, const string& fileName, vector<uint8_t>& content);
void setContent(const string& pathName, const string& fileName, const vector<uint8_t>& content);
void getContentAsStringArray(const string& pathName, const string& fileName, vector<string>& content);
void setContentFromStringArray(const string& pathName, const string& fileName, const vector<string>& content);
void list(const string& pathName, vector<string>& files, FileNameFilter* filter = nullptr, bool addDrives = false);
bool isPath(const string& uri);
bool isDrive(const string& uri);
bool exists(const string& uri);
bool isExecutable(const string& pathName, const string& fileName) override;
void setExecutable(const string& pathName, const string& fileName) override;
uint64_t getFileSize(const string& pathName, const string& fileName) override;
const string getContentAsString(const string& pathName, const string& fileName) override;
void setContentFromString(const string& pathName, const string& fileName, const string& content) override;
void getContent(const string& pathName, const string& fileName, vector<uint8_t>& content) override;
void setContent(const string& pathName, const string& fileName, const vector<uint8_t>& content) override;
void getContentAsStringArray(const string& pathName, const string& fileName, vector<string>& content) override;
void setContentFromStringArray(const string& pathName, const string& fileName, const vector<string>& content) override;
const string getCanonicalPath(const string& pathName, const string& fileName) override;
const string getCurrentWorkingPathName() override;
void changePath(const string& pathName) override;
const string getPathName(const string& fileName) override;
const string getFileName(const string& fileName) override;
void createPath(const string& pathName) override;
void removePath(const string& pathName, bool recursive) override;
void removeFile(const string& pathName, const string& fileName) override;
void rename(const string& fileNameFrom, const string& fileNameTo) override;
bool getThumbnailAttachment(const string& pathName, const string& fileName, vector<uint8_t>& thumbnailAttachmentContent) override;
bool getThumbnailAttachment(const vector<uint8_t>& content, vector<uint8_t>& thumbnailAttachmentContent) override;
const string getCanonicalURI(const string& pathName, const string& fileName);
const string getCurrentWorkingPathName();
void changePath(const string& pathName);
const string getPathName(const string& uri);
const string getFileName(const string& uri);
const string removeFileExtension(const string& fileName);
void createPath(const string& pathName);
void removePath(const string& pathName, bool recursive);
void removeFile(const string& pathName, const string& fileName);
void rename(const string& fileNameFrom, const string& fileNameTo);
bool getThumbnailAttachment(const string& pathName, const string& fileName, vector<uint8_t>& thumbnailAttachmentContent);
bool getThumbnailAttachment(const vector<uint8_t>& content, vector<uint8_t>& thumbnailAttachmentContent);

/**
* Compute SHA256 hash
Expand Down
Loading

0 comments on commit 2f35ede

Please sign in to comment.