bool FileStorage::SearchDirectoriesToAdd(const StringRef& searchPath, DirectoryEntry* destDir /*= nullptr*/, bool recursively /*= true*/) { if (destDir == nullptr) { destDir = &mRootDir; } List<HeapString> dirList; Directory::SearchDirectories(searchPath, dirList, recursively); HeapString searchDir = Path::GetDirectory(searchPath); for (auto& dir : dirList) { StringRef subDir; if (searchDir.IsEmpty()) { subDir = dir; } else { subDir = dir.ToString().SubString(searchDir.Length() + 1); //+1 to skip '/' } auto* dirEntry = FindOrCreateDirectoryEntry(subDir, destDir); if (dirEntry == nullptr) { Log::FormatError("Cannot create dir:{}", subDir); return false; } Log::FormatInfo("Add Dir:{}", dir); } return true; }
PublishTarget PublishTarget::Parse(StringRef fileName) { if (!fileName.Contains('-')) { return MatchAll; } HeapString rawName = Path::GetFileNameWithoutExtension(fileName); rawName.RemoveBeginExclude('-'); if (rawName.IsEmpty()) { return MatchAll; } List<HeapString> outResults; StringParser::Split<char>(rawName, "-", outResults); if (outResults.IsEmpty()) { return MatchAll; } int resultTag = 0; FOR_EACH_COLLECTION(i, outResults) { const HeapString& str = *i; int* tempTag = mTagDict.TryGetValue(str); if (tempTag != nullptr) { resultTag |= *tempTag; } else if (!StdString::IsDigit(str.c_str())) { Log::FormatError("Invalid tag:{}", str.c_str()); } } PublishTarget tag = PublishTarget(resultTag); if (tag.Version == PublishVersions::None) { tag.Version = PublishVersions::All; } if (tag.Device == PublishDevices::None) { tag.Device = PublishDevices::All; } if (tag.Language == PublishLanguages::None) { tag.Language = PublishLanguages::All; } return tag; }
bool SirenTextParser::ParseFile(const FileIdRef& fileId) { HeapString text = FileSystem::Instance().ReadAllText(fileId); if (text.IsEmpty()) { Log::FormatError("Cannot find file:{}", fileId.Name); return false; } Preprocess(text); StringRef proto = text; return Parse(proto); }
bool FileStorage::SearchFilesToAdd(const StringRef& searchPath, DirectoryEntry* destDir /*= nullptr*/, bool recursively /*= true*/, bool isReadonly /*= false*/, bool overwrite /*= true*/, bool deleteOriginalFile /*= false*/) { SearchDirectoriesToAdd(searchPath, destDir, recursively); if (destDir == nullptr) { destDir = &mRootDir; } List<HeapString> fileList; Directory::SearchFiles(searchPath, fileList, recursively); HeapString searchDir = Path::GetDirectory(searchPath); for (const auto& file : fileList) { auto fs = File::OpenBinaryReader(file); if (!fs) { Log::FormatError("Cannot read file:{}", file); return false; } StringRef destFile; if (searchDir.IsEmpty()) { destFile = file; } else { destFile = file.ToString().SubString(searchDir.Length() + 1); //+1 to skip '/' } bool overwriteFile = false; if (overwrite) { if (RemoveFile(destFile)) { overwriteFile = true; } } else { if (ExistsFile(destFile)) { Log::FormatInfo("NOT overwrite file:{}", destFile); continue; } } auto* fileEntry = SaveFile(*fs, destFile, destDir); fileEntry->SetPermission(isReadonly ? FilePermission::Read : FilePermission::All); Log::FormatInfo("Add file:{} to {}", destFile, file); if (overwriteFile) { Log::FormatInfo("Overwrite file:{}", destFile); } } if (deleteOriginalFile) { for (const auto& file : fileList) { File::Delete(file); } } return true; }