void showFilesInExplorer(const std::vector<std::string>& files) { size_t n = files.size(); if (n == 0) return; std::string folder = fixPath(files[0]); size_t i = folder.find_last_of('\\'); if (i != std::string::npos) folder = folder.substr(0, i); #ifdef _WIN32 ITEMIDLIST* dir = ILCreateFromPathA(folder.c_str()); LPITEMIDLIST* items = new LPITEMIDLIST[n]; for (size_t i = 0; i < n; ++i) items[i] = ILCreateFromPathA(fixPath(files[i]).c_str()); SHOpenFolderAndSelectItems(dir, (unsigned int)n, (LPCITEMIDLIST*)items, 0); for (size_t i = 0; i < n; ++i) ILFree(items[i]); ILFree(dir); delete[] items; #endif }
QString Utils::tildaToHome(const QString &s) { if (s==constTilda) { return fixPath(QDir::homePath()); } if (s.startsWith(constTilda+constDirSep)) { return fixPath(QDir::homePath()+constDirSepStr+s.mid(1), false); } return s; }
QString Utils::convertPathFromDisplay(const QString &path, bool isFolder) { QString p=path.trimmed(); if (p.isEmpty()) { return p; } if (p.startsWith(constHttp)) { return fixPath(p); } return tildaToHome(fixPath(QDir::fromNativeSeparators(p), isFolder)); }
char* Ntop::getValidPath(char *__path) { char _path[MAX_PATH]; struct stat buf; #ifdef WIN32 const char *install_dir = (const char *)get_install_dir(); #endif const char* dirs[] = { startup_dir, #ifndef WIN32 "/usr/local/share/ntopng", CONST_DEFAULT_INSTALL_DIR, #else install_dir, #endif NULL }; if(strncmp(__path, "./", 2) == 0) { snprintf(_path, MAX_PATH, "%s/%s", startup_dir, &__path[2]); fixPath(_path); if(stat(_path, &buf) == 0) { free(__path); return(strdup(_path)); } } if((__path[0] == '/') || (__path[0] == '\\')) { /* Absolute paths */ if(stat(__path, &buf) == 0) { return(__path); } } else snprintf(_path, MAX_PATH, "%s", __path); /* relative paths */ for(int i=0; dirs[i] != NULL; i++) { char path[MAX_PATH]; snprintf(path, sizeof(path), "%s/%s", dirs[i], _path); fixPath(path); if(stat(path, &buf) == 0) { free(__path); return(strdup(path)); } } free(__path); return(strdup("")); }
void loadTIKI(const char *fname) { int len; char *txt; char *p; const char *fixedPath; const char *token; char path[MAX_TOOLPATH]; float scale; len = F_LoadBuf(fname,(byte**)&txt); if(len == -1) { T_Error("loadTIKI: Cannot open %s\n",fname); return; } path[0] = 0; scale = 1.f; // NOTE: this will not open the "fname" file! COM_BeginParseSession(fname); p = txt; token = COM_ParseExt(&p, qtrue); while(token[0]) { if (!Q_stricmp(token, "path") || !Q_stricmp(token, "$path")) { token = COM_ParseExt(&p, qtrue); strcpy(path,token); } else if (!Q_stricmp(token, "scale")) { token = COM_ParseExt(&p, qtrue); scale = atof(token); } else if (!Q_stricmp(token, "skelmodel")) { token = COM_ParseExt(&p, qtrue); mainModel = readSKD(fixPath(token,path,fname),scale); } else if(strstr(token,".skc")) { tAnim_t *a; fixedPath = fixPath(token,path,fname); a = appendSKC(mainModel,fixedPath,scale); if(a) { strcpy(inAnimFNames[numAnims],fixedPath); anims[numAnims] = a; numAnims++; } } token = COM_ParseExt(&p, qtrue); } F_FreeBuf(txt); }
void DAT2::readFileEntry() const { assert( m_filecount != 0); // Load more items per call, // otherwise it takes _ages_ until everything is in. uint32_t load_per_cycle = 50; if( load_per_cycle > m_filecount ) load_per_cycle = m_filecount; m_filecount -= load_per_cycle; // Save the old index in an exception save way. IndexSaver isaver(m_data.get()); // Move index to file list and read the entries. m_data->setIndex(m_currentIndex); RawDataDAT2::s_info info; while( load_per_cycle-- ) { uint32_t namelen = m_data->read32Little(); info.name = fixPath(m_data->readString(namelen)); info.type = m_data->read8(); info.unpackedLength = m_data->read32Little(); info.packedLength = m_data->read32Little(); info.offset = m_data->read32Little(); m_filelist.insert(std::make_pair(info.name, info)); } m_currentIndex = m_data->getCurrentIndex(); // Finally log on completion and stop the timer. if( m_filecount == 0 ) { FL_LOG(_log, LMsg("MFFalloutDAT2, All file entries in '") << m_datpath << "' loaded."); m_timer.stop(); } }
bool createRecursionDir(std::string path) { if (path.length() == 0) return true; std::string sub; fixPath(path); std::string::size_type pos = path.find('/'); while (pos != std::string::npos) { std::string cur = path.substr(0, pos-0); if (cur.length() > 0 && !isDirectory(cur)) { bool ret = false; #ifdef WIN32 ret = CreateDirectoryA(cur.c_str(), NULL) ? true : false; #else ret = (mkdir(cur.c_str(), S_IRWXU|S_IRWXG|S_IRWXO) == 0); #endif if (!ret) { return false; } } pos = path.find('/', pos+1); } return true; }
bool getSourceDirFromName (const char * name) { char * filename = joinStrings (name, ""); int a, lastSlash = -1; for (a = 0; filename[a]; a ++) { if (filename[a] == '/' || filename[a] == '\\') { lastSlash = a; } } if (lastSlash != -1) { char slashChar = filename[lastSlash]; filename[lastSlash] = 0; if (chdir (filename)) { fprintf (stderr, "Can't move to source directory %s", filename); return false; } filename[lastSlash] = slashChar; } char buff[1000]; if (! getcwd (buff, 1000)) { fprintf (stderr, "I can't work out which directory I'm in..."); return false; } sourceDirectory = joinStrings (buff, ""); fixPath (sourceDirectory, true); return true; }
bool Utils::mkdir_tree(char *path) { int permission = 0777, i, rc; struct stat s; fixPath(path); if(stat(path, &s) != 0) { /* Start at 1 to skip the root */ for(i=1; path[i] != '\0'; i++) if(path[i] == CONST_PATH_SEP) { #ifdef WIN32 /* Do not create devices directory */ if((i > 1) && (path[i-1] == ':')) continue; #endif path[i] = '\0'; rc = mkdir_s(path, permission); path[i] = CONST_PATH_SEP; } rc = mkdir_s(path, permission); return(rc == 0 ? true : false); } else return(true); /* Already existing */ }
void FindInFilesDialog::browseForDir(){ QString dir=_ui->dirLineEdit->text(); QString path=fixPath( QFileDialog::getExistingDirectory( this,"Select directory",dir,QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks ) ); if( path.isEmpty() ) return; _ui->dirLineEdit->setText( path ); }
bool mkdir(const u::string &dir) { u::string fix = fixPath(dir); const char *path = fix.c_str(); #ifdef _WIN32 return ::_mkdir(path) == 0; #else return ::mkdir(path, 0775); #endif }
bool FileManager::mount(const std::string& path) { if (PHYSFS_mount(fixPath(path).c_str(), nullptr, 0) == 0) { Log::write(Log::Error, fmt::format("Error: Unable to mount path. {}", path)); return false; } return true; }
QString Utils::homeToTilda(const QString &s) { QString hp=QDir::homePath(); if (s==hp) { return constTilda; } if (s.startsWith(hp+constDirSepStr)) { return constTilda+fixPath(s.mid(hp.length()), false); } return s; }
bool Directory::Exist(const String &path) { /*DIR *dir = opendir(fixPath(path).pathEncode().c_str()); if(!dir) return false; closedir(dir); return true;*/ stat_t st; if(pla::stat(fixPath(path).pathEncode().c_str(), &st)) return false; return S_ISDIR(st.st_mode); }
void Directory::open(const String &path) { close(); mDir = opendir(fixPath(path).pathEncode().c_str()); if(!mDir) throw Exception(String("Unable to open directory: ")+path); mPath = path; if(mPath[mPath.size()-1] != Separator) mPath+= Separator; }
void PrefsDialog::onBrowseForPath(){ if( sender()==_ui->monkeyPathButton ){ QString path=QFileDialog::getExistingDirectory( this,"Select Monkey directory","",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks ); if( path.isEmpty() ) return; path=fixPath( path ); _prefs->setValue( "monkeyPath",path ); _ui->monkeyPathWidget->setText( path ); }else if( sender()==_ui->blitzmaxPathButton ){ QString path=QFileDialog::getExistingDirectory( this,"Select BlitzMax directory","",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks ); if( path.isEmpty() ) return; path=fixPath( path ); _prefs->setValue( "blitzmaxPath",path ); _ui->blitzmaxPathWidget->setText( path ); } }
bool remove(const u::string &path, pathType type) { u::string fix = fixPath(path); if (type == kFile) return ::remove(fix.c_str()) == 0; // type == kDirectory #ifdef _WIN32 return ::_rmdir(fix.c_str()) == 0; #else return ::rmdir(fix.c_str()) == 0; #endif }
QString Option::fixPathToLocalOS(const QString& in, bool fix_env, bool canonical) { QString tmp(in); if(fix_env) fixEnvVariables(tmp); if(canonical) tmp = fixPath(tmp); #if defined(Q_OS_WIN32) || defined(Q_OS_OS2) return tmp.replace('/', '\\'); #else return tmp.replace('\\', '/'); #endif }
void DAT1::loadFileList(const std::string& dirname) { const uint32_t filecount = m_data->read32Big(); m_data->moveIndex(4*3); for (uint32_t i = 0; i < filecount; ++i) { RawDataDAT1::s_info info; info.name = fixPath(dirname + "/" + readString()); info.type = m_data->read32Big(); info.offset = m_data->read32Big(); info.unpackedLength = m_data->read32Big(); info.packedLength = m_data->read32Big(); m_filelist.insert(std::make_pair(info.name, info)); } }
void PrefsDialog::onBrowseForPath() { QString path = QFileDialog::getExistingDirectory( this,"Select Monkey directory","",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks ); if( path.isEmpty() ) return; path = fixPath( path ); QString trans; if( MainWindow::isValidMonkeyPath(path, trans) ) { _prefs->setValue( "monkeyPath",path ); _prefs->setValue( "transPath",trans ); _ui->monkeyPathWidget->setText( path ); } else { QMessageBox::warning( this,"","Invalid Monkey Path!\nPlease, choose the root directory of Monkey." ); _prefs->setValue( "monkeyPath","" ); } }
QString Utils::getDir(const QString &file) { bool isCueFile=file.contains("/cue:///") && file.contains("?pos="); QString d(file); int slashPos(d.lastIndexOf(constDirSep)); if(slashPos!=-1) { d.remove(slashPos+1, d.length()); } if (isCueFile) { d.remove("cue:///"); } return fixPath(d); }
QString Option::fixPathToTargetOS(const QString& in, bool fix_env, bool canonical) { QString tmp(in); if(fix_env) fixEnvVariables(tmp); if(canonical) tmp = fixPath(tmp); QString rep; if(Option::target_mode == TARG_MAC9_MODE) tmp = tmp.replace('/', Option::dir_sep).replace('\\', Option::dir_sep); else if(Option::target_mode == TARG_WIN_MODE || Option::target_mode == TARG_OS2_MODE) tmp = tmp.replace('/', Option::dir_sep); else tmp = tmp.replace('\\', Option::dir_sep); return tmp; }
void FindInFilesDialog::readSettings(){ QSettings settings; if( settings.value( "settingsVersion" ).toInt()<2 ){ _ui->typesLineEdit->setText( "*.monkey" ); _ui->dirLineEdit->setText( Prefs::prefs()->getString( "monkeyPath" ) ); return; } settings.beginGroup( "findInFilesDialog" ); _ui->findLineEdit->setText( settings.value( "findText" ).toString() ); _ui->typesLineEdit->setText( settings.value( "fileTypes" ).toString() ); _ui->dirLineEdit->setText( fixPath( settings.value( "directory" ).toString() ) ); _ui->casedCheckBox->setChecked( settings.value( "caseSensitive" ).toBool() ); _ui->recursiveCheckBox->setChecked( settings.value( "recursive" ).toBool() ); restoreGeometry( settings.value( "geometry" ).toByteArray() ); settings.endGroup(); }
void parseArgs(int argCount, char* args[]) { bool hasSourceFile = false; if (argCount < 2) { abort("no parameters specified"); } for (int i = 1; i < argCount; i++) { if (isFlag(args[i])) { switch(args[i][1]) { case 'd': DEBUG_FLAG = true; break; default: std::stringstream ss; ss << "unrecognized parameter: \"" << args[i] << "\""; abort(ss.str()); } } else { sourceFileName = args[i]; fixPath(&sourceFileName); sourceFileBaseName = sourceFileName.substr(0,sourceFileName.find_last_of('.')); } } }
static void rtems_tfs_eval_path(rtems_filesystem_eval_path_context_t *self) { int eval_flags = rtems_filesystem_eval_path_get_flags(self); if ((eval_flags & RTEMS_FS_MAKE) == 0) { int rw = RTEMS_FS_PERMS_READ | RTEMS_FS_PERMS_WRITE; if ((eval_flags & rw) != rw) { rtems_filesystem_location_info_t *currentloc = rtems_filesystem_eval_path_get_currentloc(self); char *current = currentloc->node_access; size_t currentlen = strlen(current); const char *path = rtems_filesystem_eval_path_get_path(self); size_t pathlen = rtems_filesystem_eval_path_get_pathlen(self); size_t len = currentlen + pathlen; rtems_filesystem_eval_path_clear_path(self); current = realloc(current, len + 1); if (current != NULL) { memcpy(current + currentlen, path, pathlen); current [len] = '\0'; if (!rtems_tfs_is_directory(current, len)) { fixPath (current); } currentloc->node_access = current; } else { rtems_filesystem_eval_path_error(self, ENOMEM); } } else { rtems_filesystem_eval_path_error(self, EINVAL); } } else { rtems_filesystem_eval_path_error(self, EIO); } }
djvFileInfoList djvFileInfoUtil::list( const QString & path, djvSequence::COMPRESS compress) { //DJV_DEBUG("djvFileInfoUtil::list"); //DJV_DEBUG_PRINT("path = " << path); //DJV_DEBUG_PRINT("compress = " << compress); djvFileInfoList out; djvFileInfo * cache = 0; QString fixedPath = fixPath(path); #if defined(DJV_WINDOWS) WIN32_FIND_DATA data; HANDLE h = FindFirstFileEx( QString(fixedPath + "*").toLatin1().data(), FindExInfoBasic, &data, FindExSearchNameMatch, NULL, FIND_FIRST_EX_LARGE_FETCH); if (h != INVALID_HANDLE_VALUE) { const char * p = data.cFileName; size_t l = strlen(p); if (! isDotDir(p, l)) { out.append(djvFileInfo(fixedPath + QString(p))); } while (FindNextFile(h, &data)) { p = data.cFileName; l = strlen(p); if (! isDotDir(p, l)) { if (! out.count()) { out.append(djvFileInfo(fixedPath + QString(p))); } else { const djvFileInfo tmp(fixedPath + QString(p)); int i = 0; if (compress && cache) { if (! cache->addSequence(tmp)) { cache = 0; } } if (compress && ! cache) { for (; i < out.count(); ++i) { if (out[i].addSequence(tmp)) { cache = &out[i]; break; } } } if (! compress || i == out.count()) { out.append(tmp); } } } } FindClose(h); } /*#elif defined(DJV_LINUX) struct linux_dirent64 { ino64_t d_ino; off64_t d_off; unsigned short d_reclen; unsigned char d_type; char d_name[]; }; int fd = open(path.toLatin1().data(), O_RDONLY | O_DIRECTORY); if (fd != -1) { djvMemoryBuffer<quint8> buf(djvMemory::megabyte); quint8 * p = buf.data(); while (1) { int readCount = syscall(SYS_getdents64, fd, p, buf.size()); if (-1 == readCount) break; if (0 == readCount) break; for (int i = 0; i < readCount;) { struct linux_dirent64 * de = (struct linux_dirent64 *)(p + i); if (de->d_ino != DT_UNKNOWN) { size_t l = strlen(de->d_name); if (! isDotDir(de->d_name, l)) { if (! out.count()) { out.append(djvFileInfo(fixedPath + de->d_name)); } else { const djvFileInfo tmp(fixedPath + de->d_name); int i = 0; if (compress && cache) { if (! cache->addSequence(tmp)) { cache = 0; } } if (compress && ! cache) { for (; i < out.count(); ++i) { if (out[i].addSequence(tmp)) { cache = &out[i]; break; } } } if (! compress || i == out.count()) { out.append(tmp); } } } } i += de->d_reclen; } } close (fd); } */ #else // DJV_WINDOWS DIR * dir = opendir(path.toLatin1().data()); if (dir) { struct dirent * de = 0; while ((de = readdir(dir)) != 0) { const char * p = de->d_name; const int l = strlen(p); if (! isDotDir(p, l)) { if (! out.count()) { out.append(djvFileInfo(fixedPath + QString(p))); } else { const djvFileInfo tmp(fixedPath + QString(p)); int i = 0; if (compress && cache) { if (! cache->addSequence(tmp)) { cache = 0; } } if (compress && ! cache) { for (; i < out.count(); ++i) { if (out[i].addSequence(tmp)) { cache = &out[i]; break; } } } if (! compress || i == out.count()) { out.append(tmp); } } } } closedir(dir); } #endif // DJV_WINDOWS for (int i = 0; i < out.count(); ++i) { out[i]._sequence.sort(); } if (djvSequence::COMPRESS_RANGE == compress) { for (int i = 0; i < out.count(); ++i) { if (out[i]._sequence.frames.count()) { out[i]._sequence.setFrames( out[i]._sequence.start(), out[i]._sequence.end()); } } } for (int i = 0; i < out.count(); ++i) { if (djvFileInfo::SEQUENCE == out[i].type()) { out[i]._number = djvSequenceUtil::sequenceToString(out[i]._sequence); } } return out; }
bool Directory::Remove(const String &path) { return (rmdir(fixPath(path).pathEncode().c_str()) == 0); }
void Directory::Create(const String &path) { if(mkdirmod(fixPath(path).pathEncode().c_str(), 0770) != 0) throw Exception("Cannot create directory \""+path+"\""); }
u::file fopen(const u::string& infile, const char *type) { return ::fopen(fixPath(infile).c_str(), type); }
int executeBuiltinCommand(char* cmd, int argc, char** argv) { int status = SUCCESS; if (strcmp(cmd, "cd") == 0) { char* dest = (char*)malloc(MAX_LENGTH); if (argc == 2) { dest = argv[1]; fixPath(dest); } else if (argc > 2) { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "cd: too many arguments\n"); setTermColor(stderr, oldColor); status = ERROR; } else { sprintf(dest, "%s", getenv("HOME")); } int val = chdir(dest); } else if (strcmp(cmd, "alias") == 0) { if (argc == 3) { char* name = argv[1]; char* word = argv[2]; mapAlias(name, word); } else if (argc == 1) { printAliasTable(); } else { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "alias: need 3 arguments, got %d\n", argc); setTermColor(stderr, oldColor); status = ERROR; } } else if (strcmp(cmd, "unalias") == 0) { if (argc == 2) { char* name = argv[1]; unmapAlias(name); } else { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "unalias: need 2 arguments, got %d\n", argc); setTermColor(stderr, oldColor); status = ERROR; } } else if (strcmp(cmd, "printenv") == 0) { if (argc < 2) { printEnv(); } else { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "printenv: too many arguments"); setTermColor(stderr, oldColor); status = ERROR; } } else if (strcmp(cmd, "setenv") == 0) { if (argc == 3) { char* variable = argv[1]; char* word = argv[2]; setEnv(variable, word); } else { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "setenv: need 3 arguments, got %d\n", argc); setTermColor(stderr, oldColor); status = ERROR; } } else if (strcmp(cmd, "unsetenv") == 0) { if (argc == 2) { char* variable = argv[1]; unsetEnv(variable); } else { const char* oldColor = setTermColor(stderr, KRED); fprintf(stderr, "unsetenv: need 2 arguments, got %d\n", argc); setTermColor(stderr, oldColor); status = ERROR; } } else if (strcmp(cmd, "bye") == 0) { exit(EXIT_SUCCESS); } else { status = ERROR; } return status; }