void EvalDir(const void *data, qCtx *ctx, qStr *out, qArgAry *args) { VALID_ARGC("dir", 2, 3); CStr path = (*args)[0]; if (!path) { ctx->ThrowF(out, 601, "Empty directory path is invalid"); return; } if (!safe_fcheck(ctx, path, 'r')) { ctx->ThrowF(out, 601, "Failed to open directory. %y", GetLastError()); return; } CStr body = args->GetAt(1); int mask = 0; if (args->Count() > 2) { mask = ParseInt((*args)[2]); } if (!mask) mask = -1; ScanDir(path, mask, body, ctx, out); }
void InstallObjects(void) { DebugPrint ( "Entering Install Objects function.", __FILE__, __LINE__, PROG_FLOW); ScanDir (".", ".object", (void *) LoadObject, 8, 0, PreOrder); // once the objects are found and loaded then initialize them after this. }
void Browser::Run(const char *pRessourcePath) { Init(pRessourcePath); // Disable auto render on format SetAutoRender(0); #ifdef WIN32 strcpy(currentPath, "c:/"); #else // strcpy(currentPath, "uda0:/"); handle = -1; char * s = NULL; int next_device_n = 0; next_device_n = get_devices(next_device_n, s); strcpy(currentPath, s); ScanDir(); #endif while (1) { RenderApp(); Update(); } }
void CArchiveScanner::ScanDirs(const std::vector<std::string>& scanDirs) { std::lock_guard<spring::recursive_mutex> lck(scannerMutex); std::deque<std::string> foundArchives; isDirty = true; // scan for all archives for (const std::string& dir: scanDirs) { if (FileSystem::DirExists(dir)) { LOG("Scanning: %s", dir.c_str()); ScanDir(dir, foundArchives); } } // check for duplicates reached by links //XXX too slow also ScanArchive() skips duplicates itself, too /*for (auto it = foundArchives.begin(); it != foundArchives.end(); ++it) { auto jt = it; ++jt; while (jt != foundArchives.end()) { std::string f1 = StringToLower(FileSystem::GetFilename(*it)); std::string f2 = StringToLower(FileSystem::GetFilename(*jt)); if ((f1 == f2) || FileSystem::ComparePaths(*it, *jt)) { jt = foundArchives.erase(jt); } else { ++jt; } } }*/ // Create archiveInfos etc. if not in cache already for (const std::string& archive: foundArchives) { ScanArchive(archive, false); #if !defined(DEDICATED) && !defined(UNITSYNC) Watchdog::ClearTimer(WDT_MAIN); #endif } // Now we'll have to parse the replaces-stuff found in the mods for (auto& aii: archiveInfos) { for (const std::string& replaceName: aii.second.archiveData.GetReplaces()) { // Overwrite the info for this archive with a replaced pointer const std::string& lcname = StringToLower(replaceName); ArchiveInfo& ai = archiveInfos[lcname]; ai.path = ""; ai.origName = lcname; ai.modified = 1; ai.archiveData = ArchiveData(); ai.updated = true; ai.replaced = aii.first; } } }
void cMenuBrowseFiles::Set(void) { Clear(); if (!*m_CurrentDir) m_CurrentDir = m_ConfigLastDir; int RootDirLen = strlen(xc.media_root_dir); if (strncmp(m_CurrentDir, xc.media_root_dir, RootDirLen)) { LOGMSG("Not allowing browsing to %s (root is %s)", *m_CurrentDir, xc.media_root_dir); m_CurrentDir = xc.media_root_dir; } if (m_CurrentDir[0] != '/') { #if defined(APIVERSNUM) && (APIVERSNUM < 20102) m_CurrentDir = VideoDirectory; #else m_CurrentDir = cVideoDirectory::Name(); #endif } // find deepest accessible directory from path while (!ScanDir(m_CurrentDir) && strlen(m_CurrentDir) > 1) { m_CurrentDir = ParentDir(m_CurrentDir); } // add link to parent folder int CurrentDirLen = strlen(m_CurrentDir); if (CurrentDirLen > 1 && CurrentDirLen > RootDirLen) Add(new cFileListItem("..",true)); Sort(); SetCurrent(Get(Count()>1 && CurrentDirLen>1 ? 1 : 0)); // select last selected item cString lastParent = ParentDir(m_ConfigLastDir); if (!strncmp(m_CurrentDir, lastParent, CurrentDirLen)) { cString item = LastDir(m_ConfigLastDir); if (*item) { for (cFileListItem *it = (cFileListItem*)First(); it; it = (cFileListItem*)Next(it)) if (!strcmp(it->Name(), item)) SetCurrent(it); } } strn0cpy(m_ConfigLastDir, m_CurrentDir, sizeof(xc.browse_files_dir)); StoreConfig(); SetHelpButtons(); Display(); }
QStringList ScanDir (QDir::Filters filter, const QString& path, bool recursive) { QDir baseDir (path); QStringList paths; for (const auto& entry : baseDir.entryInfoList (filter)) { paths << entry.absoluteFilePath (); if (recursive && entry.isDir ()) paths << ScanDir (filter, entry.absoluteFilePath (), recursive); } return paths; }
void CFileSelectDialog::Update() { iArray->Reset(); _LOG(_L("Update")); _LOGDATA(_L("CurrDir at enter: %S"),&iCurrentPath); if( iCurrentPath.Compare(_L(""))==0) { _LOG(_L("( iCurrentPath.Compare(_L(""))==0)")); _LOG(_L("Will load drive list")); LoadDriveList(); } else {_LOG(_L("Will scan dir"));ScanDir();} }
void Browser::Run(const char *pRessourcePath) { Init(pRessourcePath); // Disable auto render on format SetAutoRender(0); #ifdef WIN32 strcpy(currentPath, "c:/"); #else handle = 0; char path[2048]; handle = get_devices(handle, path); strcpy(currentPath, path); ScanDir(); #endif while (1) { RenderApp(); Update(); } }
nsresult ProcessUpdates(nsIFile *greDir, nsIFile *appDir, nsIFile *updRootDir, int argc, char **argv) { nsresult rv; nsCOMPtr<nsIFile> updatesDir; rv = updRootDir->Clone(getter_AddRefs(updatesDir)); if (NS_FAILED(rv)) return rv; rv = updatesDir->AppendNative(NS_LITERAL_CSTRING("updates")); if (NS_FAILED(rv)) return rv; PRBool exists; rv = updatesDir->Exists(&exists); if (NS_FAILED(rv) || !exists) return rv; nsCOMArray<nsIFile> dirEntries; rv = ScanDir(updatesDir, &dirEntries); if (NS_FAILED(rv)) return rv; if (dirEntries.Count() == 0) return NS_OK; // look for the first update subdirectory with a status of pending for (int i = 0; i < dirEntries.Count(); ++i) { nsCOMPtr<nsILocalFile> statusFile; if (GetStatusFile(dirEntries[i], statusFile) && IsPending(statusFile)) { ApplyUpdate(greDir, dirEntries[i], statusFile, appDir, argc, argv); break; } } return NS_OK; }
int ScanDir::scan(ScanItem* si, ScanItemList& list, int data) { clear(); _dirsFinished = 0; _fileSize = 0; _dirty = true; if (isForbiddenDir(si->absPath)) { if (_parent) _parent->subScanFinished(); return 0; } KUrl u; u.setPath(si->absPath); if (!KAuthorized::authorizeUrlAction("list", KUrl(), u)) { if (_parent) _parent->subScanFinished(); return 0; } QDir d(si->absPath); const QStringList fileList = d.entryList( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); if (fileList.count()>0) { KDE_struct_stat buff; _files.reserve(fileList.count()); QStringList::ConstIterator it; for (it = fileList.constBegin(); it != fileList.constEnd(); ++it ) { if (KDE::lstat( si->absPath + QLatin1Char('/') + (*it), &buff ) != 0) continue; _files.append( ScanFile(*it, buff.st_size) ); _fileSize += buff.st_size; } } const QStringList dirList = d.entryList( QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot ); if (dirList.count()>0) { _dirs.reserve(dirList.count()); QStringList::ConstIterator it; for (it = dirList.constBegin(); it != dirList.constEnd(); ++it ) { _dirs.append( ScanDir(*it, _manager, this, data) ); QString newpath = si->absPath; if (!newpath.endsWith(QChar('/'))) newpath.append("/"); newpath.append(*it); list.append( new ScanItem( newpath, &(_dirs.last()) )); } _dirCount += _dirs.count(); } callScanStarted(); callSizeChanged(); if (_dirs.count() == 0) { callScanFinished(); if (_parent) _parent->subScanFinished(); } return _dirs.count(); }
/** The following test, tests CFileMan and CDirScan API on folders private and sys to confirm that any operation on these folders for any app with incorrect capability returns KErrPermissionDenied. This test step was added as a result of DEF051428 ("PlatSec: Incorrect errors returned by f32") */ LOCAL_C void TestCaging() { CFileMan* fMan=CFileMan::NewL(TheFs); TInt r; if(fMan!=NULL) { // Checking the private path TBuf<30> privatepath; r=TheFs.PrivatePath(privatepath); test.Printf(_L("Private Path is=%S"),&privatepath); r = TheFs.MkDir(_L("\\Caged\\")); test_Value(r, r == KErrNone || r==KErrAlreadyExists); CDir* entryCount=NULL; r=TheFs.GetDir(_L("\\*.*"),KEntryAttNormal,ESortNone,entryCount); test_KErrNone(r); TInt rootCount= entryCount->Count(); delete entryCount; entryCount=NULL; //Testing Copy CDir* entryCount2=NULL; r=fMan->Copy(_L("\\sys\\"),_L("\\Caged\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->Copy(_L("\\*"),_L("\\Caged\\")); test_KErrNone(r); r=TheFs.GetDir(_L("\\Caged\\*.*"),KEntryAttNormal,ESortNone,entryCount2); test_KErrNone(r); TInt cagedCount= entryCount2->Count(); test(cagedCount==rootCount); delete entryCount2; entryCount2=NULL; // Check if both copied sys and private are empty (no information is exposed) CDir* entryCount3=NULL; r=TheFs.GetDir(_L("\\Caged\\private\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount3); test_Value(r, r == KErrPathNotFound); delete entryCount3; entryCount3=NULL; CDir* entryCount4=NULL; r=TheFs.GetDir(_L("\\Caged\\sys\\*.*"),KEntryAttNormal|KEntryAttDir,ESortNone,entryCount4); test_Value(r, r == KErrPathNotFound); delete entryCount4; entryCount4=NULL; r=fMan->Copy(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); test_Value(r, r == KErrPermissionDenied); // Create a test file RFile testFile; r = testFile.Replace(TheFs, _L("\\capTest"),EFileWrite); test_Value(r, r == KErrNone || r==KErrAlreadyExists); testFile.Close(); TFileName name; name = privatepath; name.Append(_L("privateFile.tst")); RFile privateFile; r = privateFile.Replace(TheFs, name,EFileWrite); test_Value(r, r == KErrNone || r==KErrAlreadyExists); privateFile.Close(); r=fMan->Copy(_L("\\capTest"),_L("\\private\\two\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Copy(_L("\\capTest"),_L("\\sys\\bin\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Copy(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Copy(_L("\\sys\\*"),_L("\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->Copy(name,_L("\\sys\\")); test_Value(r, r == KErrPermissionDenied); // Testing Move r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(_L("\\private\\two\\moo.."),_L("\\private\\one\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(_L("\\private\\two\\moo"),_L("\\private\\one\\moo..")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(name,_L("\\privateFile.tst")); test_KErrNone(r); r=fMan->Move(_L("\\privateFile.tst"),name); test_KErrNone(r); r=fMan->Move(_L("\\capTest"),_L("\\private\\two\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(_L("\\capTest"),_L("\\sys\\bin\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(_L("\\sys\\bin\\capTest"),_L("\\sys\\bin\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(_L("\\sys\\*"),_L("\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->Move(name,_L("\\sys\\")); test_Value(r, r == KErrPermissionDenied); // Testing Attribs r=fMan->Attribs(_L("\\private\\two\\moo"),KEntryAttReadOnly,0,TTime(0)); test_Value(r, r == KErrPermissionDenied); r=fMan->Attribs(_L("\\private\\moo"),KEntryAttReadOnly,0,TTime(0)); test_Value(r, r == KErrPermissionDenied); r=fMan->Attribs(name,KEntryAttReadOnly,0,TTime(0)); test_KErrNone(r); r=fMan->Attribs(name,0,KEntryAttReadOnly,TTime(0)); test_KErrNone(r); // Testing RmDir r=fMan->RmDir(_L("\\private\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->RmDir(_L("\\private\\two\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->RmDir(_L("\\private\\tw?\\")); test_Value(r, r == KErrPermissionDenied); r=fMan->RmDir(_L("\\sys\\")); test_Value(r, r == KErrPermissionDenied); // Testing Rename r=fMan->Rename(_L("\\private\\two\\moo"),_L("\\private\\two\\mew")); test_Value(r, r == KErrPermissionDenied); // Testing Delete r=fMan->Delete(_L("\\private\\two\\test")); test_Value(r, r == KErrPermissionDenied); r=fMan->Delete(_L("\\private\\moo")); test_Value(r, r == KErrPermissionDenied); r=fMan->Delete(_L("\\sys\\moo")); test_Value(r, r == KErrPermissionDenied); //Something that actually exists in Private r=fMan->Rename(name,_L("\\private\\00000001\\moo")); test_KErrNone(r); r=fMan->Rename(_L("\\private\\00000001\\moo"),name); test_KErrNone(r); r=fMan->Copy(name,_L("\\private\\00000001\\moo")); test_KErrNone(r); r=fMan->Delete(_L("\\private\\00000001\\moo")); test_KErrNone(r); // Clean up the test data r=fMan->RmDir(_L("\\Caged\\")); test_KErrNone(r); r=fMan->Delete(_L("\\capTest")); test_KErrNone(r); r=fMan->Delete(name); test_KErrNone(r); delete(fMan); } // CDirScan tests ScanDir(_L("\\"), CDirScan::EScanUpTree, KErrNone); ScanDir(_L("\\"), CDirScan::EScanDownTree, KErrNone); ScanDir(_L("\\private\\"), CDirScan::EScanDownTree, KErrPermissionDenied); ScanDir(_L("\\private\\"), CDirScan::EScanUpTree, KErrPermissionDenied); }
void Browser::Update() { #ifdef WIN32 W32Update(); #endif Hw::SystemPoll(); get_controller_data(&ctrl, 0); { int up = 0; int down = 0; // button pressed if(ctrl.up && !old_ctrl.up){ up++; lChange[0]=mftb(); } else if (ctrl.down && !old_ctrl.down){ down++; lChange[1]=mftb(); } // button released if(!ctrl.up){ lChange[0]=0; } if(!ctrl.down){ lChange[1]=0; } uint64_t now = mftb(); if(lChange[0]>0) if(tb_diff_msec(now,lChange[0])>250){ static int uh=0; uh=!uh; if (uh) up++; } if(lChange[1]>0) if(tb_diff_msec(now,lChange[1])>250){ static int dh=0; dh=!dh; if (dh) down++; } //if (get_controller_data(&ctrl, 0)) { if (up) { switch (panelSelected) { case PANEL_FILE_LIST: entrySelected--; break; case PANEL_ACTION: actionSelected--; break; } } if (down) { switch (panelSelected) { case PANEL_FILE_LIST: entrySelected++; break; case PANEL_ACTION: actionSelected++; break; } } if (ctrl.b && !old_ctrl.b) { switch (panelSelected) { case PANEL_FILE_LIST: append_dir_to_path(currentPath, ".."); ScanDir(); break; } } if (ctrl.back && !old_ctrl.back) { #ifdef LIBXENON switch (panelSelected) { case PANEL_FILE_LIST: char path[2048]; handle = get_devices(handle, path); strcpy(currentPath, path); ScanDir(); break; } #endif } if ( (ctrl.start && !old_ctrl.start) || (ctrl.a && !old_ctrl.a) ) { switch (panelSelected) { case PANEL_FILE_LIST: { if (vEntry.size() == 0) break; FileEntry currentEntry = vEntry.at(entrySelected); if (currentEntry.type == 1) { append_dir_to_path(currentPath, (char*) currentEntry.name.c_str()); ScanDir(); } else { sprintf(currentFile, "%s/%s", currentPath, currentEntry.name.c_str()); if (ActionLaunchFile != NULL) ActionLaunchFile(currentFile); } break; } case PANEL_ACTION: { if (nbAction == 0) break; // Exec action ... //FileEntry currentEntry = vEntry.at(entrySelected); lpBrowserActionEntry currentAction = vAction[actionSelected]; if (currentAction != NULL && currentAction->action != NULL) { currentAction->param = (void*) currentPath; //currentAction->param = currentAction->action(currentAction); } break; } } } if (ctrl.left && !old_ctrl.left) { //if(panelSelected!=PANEL_PROGRESS) panelSelected--; } if (ctrl.right && !old_ctrl.right) { //if(panelSelected!=PANEL_PROGRESS) panelSelected++; } // clamp ... CLAMP(entrySelected, 0, vEntry.size() - 1); CLAMP(actionSelected, 0, nbAction - 1); CLAMP(panelSelected, 0, 1); // Save the old value old_ctrl = ctrl; // Erase for the big loop memset(&ctrl, 0, sizeof (struct controller_data_s)); } }
void CatalogImages::Impl::ProcessFiles(const String& dir, bool subdirs, const std::vector<bool>& scan_types, const String& title, const String& description, int img_size, bool folder_scan, int jpeg_compr) { dir_stack_.clear(); cur_dir_ = 0; root_dir_ = 0; ScanDir(dir, subdirs); if (root_dir_ == 0) return; if (parentWnd_) ::PostMessage(parentWnd_, MESSAGE, files_.size(), DIR_SCAN_DONE); //TODO: save header record with catalog info //no of images, types scanned, directory structure, etc... std::vector<uint8> header; PrepareHeader(header, dir, title, description, root_dir_.get(), folder_scan); uint64 header_offset= dbImages_.Append(header); tags_.clear(); failed_.clear(); // now write images ProcessFiles(img_size, jpeg_compr); // write special record with statistics //TODO: std::vector<uint8> stats; stats.reserve(200); MemPointer p; // p.SetResizeCallback(boost::bind(&vector<uint8>::resize, &stats, _1)); p.SetResizeCallback(boost::bind(&ResizeBuffer, &stats, _1, &p)); p.SetByteOrder(false); // little endian p.PutUInt32('tats'); // stat p.PutUInt32(static_cast<uint32>(tags_.size())); for (TagMap::const_iterator it= tags_.begin(); it != tags_.end(); ++it) { p.WriteWString(it->first); const size_t count= it->second.size(); p.PutUInt32(static_cast<uint32>(count)); for (size_t i= 0; i < count; ++i) p.PutUInt64(it->second[i]); } p.PutUInt32(0); p.PutUInt32(0); p.PutUInt32(0); p.PutUInt32(0); uint64 stats_offset_= dbImages_.Append(stats); if (parentWnd_) ::PostMessage(parentWnd_, MESSAGE, 0, IMG_PROC_DONE); // update total amount of images in the catalog header_.img_count_ = static_cast<uint32>(counter_); header_.statistics_record_offset_ = stats_offset_; header_.Write(header); dbImages_.Update(header_offset, header); }