int MainMenu::add_load(char *new_path) { char filename[BCTEXTLEN]; FileSystem dir; int total_loads = recent_load->items.total; if(total_loads == 0) { filemenu->add_item(new BC_MenuItem("-")); } int new_total = recent_load->add_item(NULL, new_path); if (new_total > total_loads) { // just create a new item if there is room for it int i = new_total - 1; load[i] = new LoadPrevious(mwindow); dir.extract_name(filename, new_path, 0); load[i]->set_text(filename); load[i]->set_path(new_path); filemenu->add_item(load[i]); } // reassign the paths to adjust for the shift down for(int i = 0; i < new_total; i++) { char *path = recent_load->items.values[i]->get_text(); dir.extract_name(filename, path, 0); load[i]->set_text(filename); load[i]->set_path(path); } return 0; }
void AtomicGlowApp::Setup() { IPCClientApp::Setup(); // AtomicGlow is always headless engineParameters_["Headless"] = true; FileSystem* filesystem = GetSubsystem<FileSystem>(); engineParameters_.InsertNew("LogName", filesystem->GetAppPreferencesDir("AtomicEditor", "Logs") + "AtomicGlow.log"); ToolSystem* tsystem = new ToolSystem(context_); context_->RegisterSubsystem(tsystem); ToolEnvironment* env = new ToolEnvironment(context_); context_->RegisterSubsystem(env); String projectPath; for (unsigned i = 0; i < arguments_.Size(); ++i) { if (arguments_[i].Length() > 1) { String argument = arguments_[i].ToLower(); String value = i + 1 < arguments_.Size() ? arguments_[i + 1] : String::EMPTY; if (argument == "--project" && value.Length()) { if (GetExtension(value) == ".atomic") { value = GetPath(value); } if (filesystem->DirExists(value)) { } else { ErrorExit(ToString("%s project path does not exist", value.CString())); } projectPath = AddTrailingSlash(value); } } } if (!env->Initialize()) { ErrorExit("Unable to initialize tool environment from %s"); return; } engineParameters_["ResourcePrefixPaths"] = env->GetRootSourceDir() + "/Resources/"; engineParameters_["ResourcePaths"] = ToString("CoreData;EditorData;%sResources;%sCache", projectPath.CString(), projectPath.CString()); }
static status_t get_new_vnode(fs_volume* volume, ino_t id, VnodeToInode** _vti) { FileSystem* fs = reinterpret_cast<FileSystem*>(volume->private_volume); Inode* inode; VnodeToInode* vti; status_t result = acquire_vnode(volume, id); if (result == B_OK) { ASSERT(get_vnode(volume, id, reinterpret_cast<void**>(_vti)) == B_OK); unremove_vnode(volume, id); // Release after acquire put_vnode(volume, id); vti = *_vti; if (vti->Get() == NULL) { result = fs->GetInode(id, &inode); if (result != B_OK) { put_vnode(volume, id); return result; } vti->Replace(inode); } return B_OK; } return get_vnode(volume, id, reinterpret_cast<void**>(_vti)); }
bool CubemapGenerator::InitPaths() { String scenePath = sceneEditor_->GetFullPath(); String pathName; String fileName; String ext; SplitPath(scenePath, pathName, fileName, ext); outputPathAbsolute_ = pathName + "Cubemaps/" + fileName + "/"; FileSystem* fileSystem = GetSubsystem<FileSystem>(); if (!fileSystem->DirExists(outputPathAbsolute_)) { if (!fileSystem->CreateDirs(pathName, "Cubemaps/" + fileName + "/")) { LOGERRORF("CubemapGenerator::InitRender - Unable to create path: %s", outputPathAbsolute_.CString()); return false; } } // TODO: There should be a better way of getting the resource path ToolSystem* tsystem = GetSubsystem<ToolSystem>(); Project* project = tsystem->GetProject(); resourcePath_ = outputPathAbsolute_; resourcePath_.Replace(project->GetResourcePath(), ""); resourcePath_ = AddTrailingSlash(resourcePath_); return true; }
void ShapeWipeMain::init_shapes() { if(!shapes_initialized) { FileSystem fs; fs.set_filter("*.png"); char shape_path[BCTEXTLEN]; sprintf(shape_path, "%s%s", get_plugin_dir(), SHAPE_SEARCHPATH); fs.update(shape_path); for(int i = 0; i < fs.total_files(); i++) { FileItem *file_item = fs.get_entry(i); if(!file_item->get_is_dir()) { shape_paths.append(strdup(file_item->get_path())); char *ptr = strdup(file_item->get_name()); char *ptr2 = strrchr(ptr, '.'); if(ptr2) *ptr2 = 0; shape_titles.append(ptr); } } shapes_initialized = 1; } }
void Render::start_progress() { char filename[BCTEXTLEN]; char string[BCTEXTLEN]; FileSystem fs; progress_max = Units::to_int64(default_asset->sample_rate * (total_end - total_start)) + Units::to_int64(preferences->render_preroll * packages->total_allocated * default_asset->sample_rate); progress_timer->update(); last_eta = 0; if(mwindow) { // Generate the progress box fs.extract_name(filename, default_asset->path); sprintf(string, _("Rendering %s..."), filename); // Don't bother with the filename since renderfarm defeats the meaning progress = mwindow->mainprogress->start_progress(_("Rendering..."), progress_max); render_progress = new RenderProgress(mwindow, this); render_progress->start(); } }
bool ResourceOps::CheckCreate2DLevel(const String& resourcePath, const String& resourceName, bool reportError) { Editor* editor = GetSubsystem<Editor>(); Project* project = editor->GetProject(); String fullpath = resourcePath + resourceName; if (!resourceName.EndsWith(".tmx")) fullpath += ".tmx"; FileSystem* fs = GetSubsystem<FileSystem>(); if (fs->FileExists(fullpath)) { if (reportError) { String errorMsg; errorMsg.AppendWithFormat("The level:\n\n%s\n\nalready exists", fullpath.CString()); editor->PostModalError("Create 2D Level Error", errorMsg); } return false; } return true; }
int IndexFile::get_index_filename(char *source_filename, char *index_directory, char *index_filename, char *input_filename) { // Replace slashes and dots int i, j; int len = strlen(input_filename); for(i = 0, j = 0; i < len; i++) { if(input_filename[i] != '/' && input_filename[i] != '.') source_filename[j++] = input_filename[i]; else { if(i > 0) source_filename[j++] = '_'; } } source_filename[j] = 0; FileSystem fs; fs.join_names(index_filename, index_directory, source_filename); strcat(index_filename, ".idx"); return 0; }
LicenseSystem::LicenseSystem(Context* context) : Object(context) , eulaAgreementConfirmed_(false) { FileSystem* filesystem = GetSubsystem<FileSystem>(); licenseFilePath_ = filesystem->GetAppPreferencesDir("AtomicEditor", "License"); licenseFilePath_ = AddTrailingSlash(licenseFilePath_); if (!filesystem->DirExists(licenseFilePath_)) { Poco::File dirs(licenseFilePath_.CString()); dirs.createDirectories(); } licenseCachePath_ = licenseFilePath_; licenseCachePath_ += "AtomicLicenseCache"; licenseFilePath_ += "AtomicLicense"; eulaAgreementPath_ = filesystem->GetAppPreferencesDir("AtomicEditor", "License"); eulaAgreementPath_ = AddTrailingSlash(eulaAgreementPath_); eulaAgreementPath_ += "EulaConfirmed"; ResetLicense(); }
String AEEditorPrefs::GetPreferencesPath() { FileSystem* fileSystem = GetSubsystem<FileSystem>(); String path = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences"); path += "prefs.json"; return path; }
bool AEEditorPrefs::LoadPreferences(JSONValue& prefs) { FileSystem* fileSystem = GetSubsystem<FileSystem>(); String path = GetPreferencesPath(); if (!fileSystem->FileExists(path)) { if (!CreateDefaultPreferences(path, prefs)) return false; } else { SharedPtr<File> file(new File(context_, path, FILE_READ)); SharedPtr<JSONFile> jsonFile(new JSONFile(context_)); if (!jsonFile->BeginLoad(*file)) { file->Close(); if (!CreateDefaultPreferences(path, prefs)) return false; } else { prefs = jsonFile->GetRoot(); } file->Close(); } return true; }
//-------------------------------------------------------------- //-------------------------------------------------------------- void AppDataStore::RefreshFromFile() { FileSystem* pFileSystem = Application::Get()->GetFileSystem(); if(pFileSystem->DoesFileExist(StorageLocation::k_saveData, k_filename) == true) { FileStreamSPtr fileStream = pFileSystem->CreateFileStream(StorageLocation::k_saveData, k_filename, FileMode::k_readBinary); if (fileStream != nullptr) { fileStream->SeekG(0, SeekDir::k_end); u32 encryptedDataSize = fileStream->TellG(); fileStream->SeekG(0, SeekDir::k_beginning); std::unique_ptr<s8[]> encryptedData(new s8[encryptedDataSize]); fileStream->Read(encryptedData.get(), encryptedDataSize); fileStream.reset(); std::string decrypted = AESEncrypt::DecryptString(reinterpret_cast<const u8*>(encryptedData.get()), encryptedDataSize, k_privateKey); XMLUPtr xml = XMLUtils::ParseDocument(decrypted); XML::Node* root = XMLUtils::GetFirstChildElement(xml->GetDocument()); if(nullptr != root) { m_dictionary = ParamDictionarySerialiser::FromXml(root); } } } m_needsSynchonised = false; }
//-------------------------------------------------------------- //-------------------------------------------------------------- void AppDataStore::Save() { std::unique_lock<std::mutex> lock(m_mutex); if(m_needsSynchonised == true) { // Convert to XML XML::Document doc; XML::Node* rootNode = doc.allocate_node(rapidxml::node_type::node_element); doc.append_node(rootNode); ParamDictionarySerialiser::ToXml(m_dictionary, rootNode); // Encrypt std::string strDocToBeEncrypted = XMLUtils::ToString(&doc); AESEncrypt::Data encryptedData = AESEncrypt::EncryptString(strDocToBeEncrypted, k_privateKey); // Write to disk FileSystem* pFileSystem = Application::Get()->GetFileSystem(); FileStreamSPtr pFileStream = pFileSystem->CreateFileStream(StorageLocation::k_saveData, k_filename, FileMode::k_writeBinary); if(pFileStream != nullptr) { pFileStream->Write(reinterpret_cast<const s8*>(encryptedData.m_data.get()), encryptedData.m_size); pFileStream.reset(); } m_needsSynchonised = false; } }
bool DirFile::readMetadata() { FileSystem* filesys = FileSystem::get_instance(); FileSystem::FileList files; /*int ret =*/ filesys->ListFiles(path + "*", files); // TODO: check if directory actually exists count = files.size(); FileSystem::FileList::iterator iter; for (iter = files.begin(); iter != files.end(); ++iter) { std::string name = *iter; std::string::size_type pos = name.rfind("/"); if (pos != std::string::npos) { name.erase(0, pos+1); pout << "DirFile: " << name << std::endl; storeIndexedName(name); } } return true; }
void FileStreamTfs::open() { try{ if (m_openMode == FileStream::ReadOnly){ if (m_fin != NULL) return; m_fin = new InputStream; m_fin->open(m_filename.c_str(), 0); //cout <<"FileStreamTfs opens " <<m_filename <<" for read " <<endl; } else if (m_openMode == FileStream::Append){ //cout <<"FileStreamTfs opens " <<m_filename <<" for append " <<endl; if (m_fout != NULL) return; FileSystem fs; if (!fs.existFile(m_filename)){ fs.createFile(m_filename, 1, 0); } m_fout = new AppendStream; m_fout->open(m_filename.c_str(), 0); } } catch (tfs::api::TFSException& e){ throw FSError(string("FileStreamTfs open file failed :") + m_filename + " error=>" + e.what()); } }
void LicenseSystem::Initialize() { FileSystem* filesystem = GetSubsystem<FileSystem>(); eulaAgreementConfirmed_ = filesystem->FileExists(eulaAgreementPath_); if (!eulaAgreementConfirmed_) { SendEvent(E_LICENSE_EULAREQUIRED); return; } else { SendEvent(E_LICENSE_EULAACCEPTED); } // TODO: Cleanup for MIT if (!LoadLicense() || !key_.Length()) { ResetLicense(); SendEvent(E_LICENSE_ACTIVATIONREQUIRED); return; } else { // RequestServerVerification(key_); } }
static int FileSystem_ScanDir(duk_context* ctx) { duk_push_this(ctx); FileSystem* fs = js_to_class_instance<FileSystem>(ctx, -1, 0); if ( !duk_is_string(ctx, 0) || !duk_is_string(ctx, 1) || !duk_is_number(ctx, 2) || !duk_is_boolean(ctx, 3)) { duk_push_string(ctx, "FileSystem::ScanDir bad args"); duk_throw(ctx); } const char* pathName = duk_to_string(ctx, 0); const char* filter = duk_to_string(ctx, 1); unsigned flags = duk_to_number(ctx, 2); bool recursive = duk_to_boolean(ctx, 3) ? true : false; Vector<String> result; fs->ScanDir(result, pathName, filter, flags, recursive); duk_push_array(ctx); for (unsigned i = 0; i < result.Size(); i++) { duk_push_string(ctx, result[i].CString()); duk_put_prop_index(ctx, -2, i); } return 1; }
BC_Window* BatchRenderThread::new_gui() { current_start = 0.0; current_end = 0.0; default_job = new BatchRenderJob(mwindow->preferences); if(!file_entries) { file_entries = new ArrayList<BC_ListBoxItem*>; FileSystem fs; char string[BCTEXTLEN]; // Load current directory fs.update(getcwd(string, BCTEXTLEN)); for(int i = 0; i < fs.total_files(); i++) { file_entries->append( new BC_ListBoxItem( fs.get_entry(i)->get_name())); } } char path[BCTEXTLEN]; path[0] = 0; load_jobs(path, mwindow->preferences); load_defaults(mwindow->defaults); this->gui = new BatchRenderGUI(mwindow, this, mwindow->session->batchrender_x, mwindow->session->batchrender_y, mwindow->session->batchrender_w, mwindow->session->batchrender_h); this->gui->create_objects(); return this->gui; }
/** * Repositions the offset of the open file associated with the file * descriptor fd to the argument offset. * */ void sys_lseek( System *sys, Registers ®isters ) { FileSystem *fs; File* file; if ( sys && (fs = (sys->getFileSystem())) && (file = fs->getFile( registers.r1 )) ) { size_t offset; switch ( registers.r3 ) { case SEEK_SET: // The offset is set to offset bytes. offset = registers.r2; break; case SEEK_CUR: // The offset is set to its current location plus offset bytes. offset = file->getOffset() + registers.r2; break; case SEEK_END: // The offset is set to the size of the file plus offset bytes. offset = file->getSize() + registers.r2; break; default: // SEEK_DATA and SEEK_HOLE warning( "sys_lseek: unsupported whence value." ); registers.r0 = (uintr_t) -1; return; } if ( fs->seek( registers.r1, offset ) ) { registers.r0 = offset; return; } } registers.r0 = (uintr_t) -1; }
int archivefs_getattr(const char* path, struct stat* info) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs = NULL; FileNode* node; int ret; if (!getFile(fpath, &fs, &node)) { /* fs byl nalezen, ale soubor ne */ if (fs != NULL) { print_err("GETATTR", path, ENOENT); return -ENOENT; } if ((ret = stat(fpath, info)) != 0) { ret = errno; print_err("GETATTR", path, ret); } return -ret; } struct stat* node_info = fs->getAttr(node); memcpy(info, node_info, sizeof(struct stat)); // printStat(info); return 0; }
void ResourceOps::HandleNewFolder(const String& resourcePath, bool reportError) { Editor* editor = GetSubsystem<Editor>(); FileSystem* fs = GetSubsystem<FileSystem>(); if (fs->DirExists(resourcePath) || fs->FileExists(resourcePath)) { if (reportError) { String errorMsg; errorMsg.AppendWithFormat("Already exists:\n\n %s", resourcePath.CString()); editor->PostModalError("New Folder Error", errorMsg); } return; } if (!fs->CreateDir(resourcePath)) { if (reportError) { String errorMsg; errorMsg.AppendWithFormat("Could not create:\n\n %s", resourcePath.CString()); editor->PostModalError("New Folder Error", errorMsg); } return; } // file watcher doesn't currently handle subdir GetSubsystem<MainFrame>()->GetProjectFrame()->Refresh(); }
int archivefs_mknod(const char* path, mode_t mode, dev_t dev) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs; int ret; if (!getFile(fpath, &fs, NULL)) { ret = mknod(fpath, mode, dev); if (ret) { ret = errno; print_err("MKNOD", fpath, ret); } return -ret; } char* file; parsePathName(fpath, &file); struct fuse_context* context = fuse_get_context(); if (fs->parentAccess(file, W_OK|X_OK, context->uid, context->gid)) return -EACCES; ret = fs->mknod(file, mode); if (ret) print_err("MKNOD", path, ret); return -ret; }
bool Asset::CheckCacheFile() { if (importer_.Null()) return true; FileSystem* fs = GetSubsystem<FileSystem>(); AssetDatabase* db = GetSubsystem<AssetDatabase>(); String cachePath = db->GetCachePath(); String cacheFile = cachePath + guid_; unsigned modifiedTime = fs->GetLastModifiedTime(path_); if (importer_->RequiresCacheFile()) { if (!fs->FileExists(cacheFile) || fs->GetLastModifiedTime(cacheFile) < modifiedTime) return false; } if (fs->GetLastModifiedTime(GetDotAssetFilename()) < modifiedTime) { return false; } return true; }
int archivefs_create(const char *path, mode_t mode, struct fuse_file_info *info) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs; int ret; if (!getFile(fpath, &fs, NULL)) { ret = creat(fpath, mode); if (ret == -1) { ret = errno; print_err("CREATE", path, ret); return -ret; } info->fh = intptr_t(ret); return 0; } FileNode* node; char* file; parsePathName(fpath, &file); struct fuse_context* context = fuse_get_context(); if (fs->parentAccess(file, W_OK|X_OK, context->uid, context->gid)) return -EACCES; ret = fs->create(file, mode, &node); if (ret) print_err("CREATE", path, ret); info->fh = intptr_t(new FileHandle(fs, node)); return -ret; }
void AssetDatabase::PruneOrphanedDotAssetFiles() { if (project_.Null()) { LOGDEBUG("AssetDatabase::PruneOrphanedDotAssetFiles - called without project loaded"); return; } FileSystem* fs = GetSubsystem<FileSystem>(); const String& resourcePath = project_->GetResourcePath(); Vector<String> allResults; fs->ScanDir(allResults, resourcePath, "*.asset", SCAN_FILES, true); for (unsigned i = 0; i < allResults.Size(); i++) { String dotAssetFilename = resourcePath + allResults[i]; String assetFilename = ReplaceExtension(dotAssetFilename, ""); // remove orphaned asset files if (!fs->FileExists(assetFilename) && !fs->DirExists(assetFilename)) { LOGINFOF("Removing orphaned asset file: %s", dotAssetFilename.CString()); fs->Delete(dotAssetFilename); } } }
int archivefs_truncate(const char* path, off_t size) { char fpath[PATH_MAX]; fullpath(fpath, path); FileSystem* fs; FileNode* node; int ret; if (!getFile(fpath, &fs, &node)) { ret = truncate(fpath, size); if (ret) { ret = errno; } } else { struct fuse_context* context = fuse_get_context(); if (fs->access(node, W_OK, context->uid, context->gid)) return -EACCES; ret = fs->truncate(node, size); } if (ret) print_err("TRUNCATE", path, ret); return -ret; }
static status_t nfs4_get_vnode(fs_volume* volume, ino_t id, fs_vnode* vnode, int* _type, uint32* _flags, bool reenter) { FileSystem* fs = reinterpret_cast<FileSystem*>(volume->private_volume); TRACE("volume = %p, id = %" B_PRIi64, volume, id); VnodeToInode* vnodeToInode = new VnodeToInode(id, fs); if (vnodeToInode == NULL) return B_NO_MEMORY; Inode* inode; status_t result = fs->GetInode(id, &inode); if (result != B_OK) { delete vnodeToInode; return result; } vnodeToInode->Replace(inode); vnode->ops = &gNFSv4VnodeOps; vnode->private_node = vnodeToInode; *_type = inode->Type(); *_flags = 0; return B_OK; }
int archivefs_opendir(const char *path, struct fuse_file_info *info) { char fpath[PATH_MAX]; fullpath(fpath, path); /* Stejná logika jako u archivefs_open. */ DIR* dir; if ((dir = opendir(fpath)) != NULL) { info->fh = intptr_t(dir); return 0; } FileSystem* fs; FileNode* node; if (!getFile(fpath, &fs, &node)) { print_err("OPENDIR", path, ENOENT); return -ENOENT; } struct fuse_context* context = fuse_get_context(); if (fs->access(node, R_OK, context->uid, context->gid)) return -EACCES; info->fh = intptr_t(new FileHandle(fs, node)); return 0; }
static status_t nfs4_create(fs_volume* volume, fs_vnode* dir, const char* name, int openMode, int perms, void** _cookie, ino_t* _newVnodeID) { FileSystem* fs = reinterpret_cast<FileSystem*>(volume->private_volume); OpenFileCookie* cookie = new OpenFileCookie(fs); if (cookie == NULL) return B_NO_MEMORY; *_cookie = cookie; VnodeToInode* vti = reinterpret_cast<VnodeToInode*>(dir->private_node); TRACE("volume = %p, dir = %" B_PRIi64 ", name = %s, openMode = %d," \ " perms = %d", volume, vti->ID(), name, openMode, perms); VnodeToInodeLocker _(vti); Inode* inode = vti->Get(); if (inode == NULL) return B_ENTRY_NOT_FOUND; MutexLocker createLocker(fs->CreateFileLock()); OpenDelegationData data; status_t result = inode->Create(name, openMode, perms, cookie, &data, _newVnodeID); if (result != B_OK) { delete cookie; return result; } result = get_new_vnode(volume, *_newVnodeID, &vti); if (result != B_OK) { delete cookie; return result; } VnodeToInodeLocker _child(vti); Inode* child = vti->Get(); if (child == NULL) { delete cookie; put_vnode(volume, *_newVnodeID); return B_ENTRY_NOT_FOUND; } child->SetOpenState(cookie->fOpenState); if (data.fType != OPEN_DELEGATE_NONE) { Delegation* delegation = new(std::nothrow) Delegation(data, child, cookie->fOpenState->fClientID); if (delegation != NULL) { delegation->fInfo = cookie->fOpenState->fInfo; delegation->fFileSystem = child->GetFileSystem(); child->SetDelegation(delegation); } } TRACE("*cookie = %p, *newVnodeID = %" B_PRIi64, *_cookie, *_newVnodeID); return result; }
int MainMenu::init_loads(BC_Hash *defaults) { //printf("MainMenu::init_loads 1\n"); //printf("MainMenu::init_loads 1\n"); char string[BCTEXTLEN], path[BCTEXTLEN], filename[BCTEXTLEN]; //printf("MainMenu::init_loads 1\n"); FileSystem dir; recent_load->load_items(); int total_loads = recent_load->items.total; //printf("MainMenu::init_loads 2\n"); if(total_loads > 0) filemenu->add_item(new BC_MenuItem("-")); for(int i = 0; i < total_loads; i++) { char *path = recent_load->items.values[i]->get_text(); filemenu->add_item(load[i] = new LoadPrevious(mwindow)); //printf("MainMenu::init_loads 5\n"); dir.extract_name(filename, path, 0); //printf("MainMenu::init_loads 6\n"); load[i]->set_text(filename); //printf("MainMenu::init_loads 7\n"); load[i]->set_path(path); //printf("MainMenu::init_loads 8\n"); } //printf("MainMenu::init_loads 9\n"); return 0; }