//! constructor CFileSystem::CFileSystem() { #ifdef _DEBUG setDebugName("CFileSystem"); #endif setFileListSystem(FILESYSTEM_NATIVE); //! reset current working directory getWorkingDirectory(); #ifdef __IRR_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ ArchiveLoader.push_back(new CArchiveLoaderZIP(this)); #endif #ifdef __IRR_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ ArchiveLoader.push_back(new CArchiveLoaderMount(this)); #endif #ifdef __IRR_COMPILE_WITH_PAK_ARCHIVE_LOADER_ ArchiveLoader.push_back(new CArchiveLoaderPAK(this)); #endif #ifdef __IRR_COMPILE_WITH_TAR_ARCHIVE_LOADER_ ArchiveLoader.push_back(new CArchiveLoaderTAR(this)); #endif }
void FilePath::getAbsolutePath(OovStringRef const path, eFilePathTypes fpt) { if(FilePathIsAbsolutePath(path)) { if(fpt == FP_Dir) appendDir(path); else appendFile(path); } else { getWorkingDirectory(); FilePath newPath(path, fpt); int count = newPath.discardLeadingRelSegments(); size_t pos = getPosEndDir(); for(int i=0; i<count; i++) { pos = getPosLeftPathSep(pos, RP_RetPosNatural); } appendPathAtPos(newPath, pos); } normalizePathSeps(pathStdStr()); if(fpt == FP_Dir) { if(!FilePathIsEndPathSep(pathStdStr())) pathStdStr().append("/"); } }
FileStream::FileStream(const char* filename) : mFilename(filename) { char temp[256]; getWorkingDirectory(temp, 256); strcat(temp, "\\"); strcat(temp, filename); file = fopen(temp, "rb"); }
void beginProgram (int argumentCount, char **argumentVector) { #if defined(GRUB_RUNTIME) #else /* at exit */ atexit(endProgram); #endif /* at exit */ initializeSystemObject(); prepareLocale(); if ((programPath = getProgramPath())) { registerProgramMemory("program-path", &programPath); } else { programPath = argumentVector[0]; } if (!isExplicitPath(programPath)) { char *path = findProgram(programPath); if (!path) path = testProgram(".", programPath); if (path) programPath = path; } if (isExplicitPath(programPath)) { #if defined(HAVE_REALPATH) && defined(PATH_MAX) if (!isAbsolutePath(programPath)) { char buffer[PATH_MAX]; char *path = realpath(programPath, buffer); if (path) { char *realPath = strdup(path); if (realPath) { programPath = realPath; } else { logMallocError(); } } else { logSystemError("realpath"); } } #endif /* defined(HAVE_REALPATH) && defined(PATH_MAX) */ if (!isAbsolutePath(programPath)) { char *directory; if ((directory = getWorkingDirectory())) { char *path; if ((path = makePath(directory, programPath))) programPath = path; free(directory); } } } programName = locatePathName(programPath); pushLogPrefix(programName); }
std::string CLArguments::matchPath(std::string dir) { if(dir.find_first_of("/")==0 || dir.find(":")!=std::string::npos) { return (dir); } std::string result=getWorkingDirectory()+dir; return(result); }
std::string Directory::makePath(const std::string* directory, const std::string* fileName) { std::string path; if ((directory == nullptr) || (directory->empty())) { path.assign(getWorkingDirectory()); } else { path.assign(*directory); } if ((fileName != nullptr) && (!fileName->empty())) { path = path + _pathDelimiter + *fileName; } return path; }
void ObjectOverviewModel::build() { cleanUp(); auto ioManager = model_.ioManager(); ioManager->createProjectStructure(); std::string wdir = ioManager->getWorkingDirectory(); auto assets = ioManager->findFolder(wdir, "assets"); if(assets.empty()) { std::cout << "assets not found? this wasn't supposed to happen" << std::endl; } else buildAssets(ioManager, assets); auto data = ioManager->findFolder(wdir, "data"); if(data.empty()) { std::cout << "data not found? this wasn't supposed to happen" << std::endl; } else buildData(ioManager, data); }
WriteFileStream::WriteFileStream(const char* filename, bool append, bool exist) { char temp[256]; getWorkingDirectory(temp, 256); strcat(temp, "\\"); strcat(temp, filename); if(append) { file = fopen(temp, "ab+"); } else if(exist) { file = fopen(temp, "rb+"); } else { file = fopen(temp, "wb+"); } if(!file) { LOG("Could not open file for writing\n"); } }
//Analogous to getUniqueNewFolderPathInWorkingDirectory, this function returns a unique file path using the parameter as a template QFileInfo FileSystemManager::getUniqueNewFilePathInWorkingDirectory(QString fileName) { QFileInfo newFile; int file_extension_division = fileName.lastIndexOf("."); QString ext = fileName.mid(file_extension_division,fileName.size()-file_extension_division); QString fileBase = fileName.mid(0,file_extension_division); QString oldBase = fileBase; int x = 1; do { QString counter = QString::number(x); fileBase.append(counter); fileBase.append(ext); newFile = make_file(GLOBAL(getWorkingDirectory()), fileBase); fileBase = oldBase; x++; } while (exists(newFile)); return newFile; }
const char * getOverrideDirectory (void) { static const char *directory = NULL; if (!directory) { static const char subdirectory[] = "." PACKAGE_NAME; { char *homeDirectory = getHomeDirectory(); if (homeDirectory) { directory = makePath(homeDirectory, subdirectory); free(homeDirectory); if (directory) goto gotDirectory; } } { char *workingDirectory = getWorkingDirectory(); if (workingDirectory) { directory = makePath(workingDirectory, subdirectory); free(workingDirectory); if (directory) goto gotDirectory; } } directory = ""; logMessage(LOG_WARNING, "no override directory"); goto ready; gotDirectory: logMessage(LOG_INFO, "Override Directory: %s", directory); registerProgramMemory("override-directory", &directory); } ready: return *directory? directory: NULL; }
int wmain(int argc, wchar_t *argv[]) { /* make sure Corsair's utility isn't running */ auto check1 = findWindowByPartialTitle("Corsair Utility Engine"); auto check2 = findWindowByPartialTitle("CorsairHID"); if (check1 != NULL || check2 != NULL) { printf("Please close Corsair Utility Engine before using this application!\n"); return 1; } /* make sure args are correct */ if (argc != 2) { printf("Usage: me.exe script.lua\n"); return 1; } /* hide me */ ShowWindow(GetConsoleWindow(), SW_HIDE); /* set up script paths */ std::wstring workingDirectory = getWorkingDirectory(); std::wstring libraryPath = workingDirectory + L"\\library.lua"; std::wstring scriptPath = argv[1]; /* execute script */ keyboardScript script; script.doFile(libraryPath.c_str()); script.doFile(scriptPath.c_str()); script.doMainLoop(); return 0; }
void ConnectedShortcut::connect(const wstring& settingsArgs) { if (isConnected()) return; wstring args = getArguments(); wstring target = CommandLineParser::escapeArgument(getPath()); wstring description = SHORT_APP_NAME L" + " + getDescription(); wstring workingDirectory = getWorkingDirectory(); if (!args.empty()) target.push_back(L' '); if (!settingsArgs.empty() && settingsArgs.back() != L' ') target.insert(target.begin(), L' '); // SetPath seems to change the working directory, too. // We want to keep the original directory, however. m_pLink->SetPath(getSelfPath().data()); m_pLink->SetArguments((settingsArgs + target + args).data()); m_pLink->SetDescription(description.data()); m_pLink->SetWorkingDirectory(workingDirectory.data()); m_isConnectedCachedResult = true; }
void Chapter::download() { sf::Http web(Manga::MangaHost); sf::Http::Request request(m_uri); sf::Http::Response response = web.sendRequest(request); sf::Http::Response::Status status = response.getStatus(); if (status == sf::Http::Response::Ok) { std::string body(response.getBody()); //Erase all of the \n eraseN(body); if (testing) { char html_file[300]; sprintf(html_file, "test/chapter_%u_page1.html", m_num_chapter); FILE* f = fopen(html_file, "w"); fwrite(body.c_str(), sizeof(char), body.size(), f); fclose(f); std::cout<<"Html page output to file: "<<html_file<<"\n"; } sscanf(getParse(body, Manga::parseChapterPages).c_str(), "%u", &m_pages); if (testing) std::cout<<"number of pages for chapter "<<m_num_chapter<<" parsed: "<<m_pages<<"\n"; //Clean images for (std::vector<Image*>::iterator it(m_images.begin()); it != m_images.end(); ++it) delete *it; m_images.resize(m_pages); for (unsigned int i(0); i<m_images.size(); ++i) m_images[i] = new Image; //we ad the fisrt image m_images[0]->setUrl(getParse(body, Manga::parsePageImg)); m_images[0]->setDir(m_dir); char filename[300]; sprintf(filename, "%s %u-1", m_manga->m_name.c_str(), m_num_chapter); m_images[0]->setFileName(filename); if (!testing) { m_images[0]->thDownload(); std::cout<<"Image 1/"<<m_images.size()<<" found.\n"; } std::string next_page(getParse(body, Manga::parsePageNext)); switch (Manga::mangaPath) { case URL_uri: break; case URL_absolute: next_page = getUri(next_page); break; case URL_relative: next_page = getWorkingDirectory(m_uri) + next_page; break; default: break; } if (testing) std::cout<<"Image 1 parsed: "<<m_images[0]->getUrl()<<"\nNext page parsed (Uri format): "<<next_page<<"\n"; for (unsigned int i(1); i<m_images.size(); ++i) { request.setUri(next_page); response = web.sendRequest(request); status = response.getStatus(); if (status == sf::Http::Response::Ok) { std::string body(response.getBody()); //Erase all of the \n eraseN(body); if (testing && i == 1) { char html_file[300]; sprintf(html_file, "test/chapter_%u_other_page.html", m_num_chapter); FILE* f = fopen(html_file, "w"); fwrite(body.c_str(), sizeof(char), body.size(), f); fclose(f); std::cout<<"Html page output to file: "<<html_file<<"\n"; } m_images[i]->setUrl(getParse(body, Manga::parsePageImg)); m_images[i]->setDir(m_dir); sprintf(filename, "%s %u-%u", m_manga->m_name.c_str(), m_num_chapter, i+1); m_images[i]->setFileName(filename); if (!testing) { m_images[i]->thDownload(); std::cout<<"Image "<<i+1<<"/"<<m_images.size()<<" found.\n"; } next_page = getParse(body, Manga::parsePageNext); switch (Manga::mangaPath) { case URL_uri: break; case URL_absolute: next_page = getUri(next_page); break; case URL_relative: next_page = getWorkingDirectory(m_uri) + next_page; break; default: break; } if (testing) std::cout<<"Image "<<i+1<<" parsed: "<<m_images[i]->getUrl()<<"\nNext page parsed: "<<next_page<<"\n"; } else std::cout<<"Error getting page: "<<status<<"\n"; } //std::cout<<"img:"<<getParse(body, Manga::parsePageImg)<<" next page: "<<getParse(body, Manga::parsePageNext)<<"\n"; //Download imgs //for (int i=0; i<1; ++i) m_images[i]->thDownload(); } else std::cout<<"Error checking chapter: "<<status<<"\n"; }
std::string repo::core::RepoLogger::getFullFilePath() { return getWorkingDirectory() + PATH_SEPARATOR + getFilename(); }
//! Creates a list of files and directories in the current working directory IFileList* CFileSystem::createFileList() { FileEntry e2; FileEntry e3; if ( FileSystemType == FILESYSTEM_NATIVE ) return new CFileList(); CFileList* r = new CFileList( "virtual" ); r->Path = WorkingDirectory [ FILESYSTEM_VIRTUAL ]; for ( u32 i = 0; i != FileArchives.size(); ++i) { CFileList* flist[2] = { 0, 0 }; //! merge relative folder file archives if ( FileArchives[i]->getArchiveType() == "mount" ) { EFileSystemType currentType = setFileListSystem ( FILESYSTEM_NATIVE ); core::string<c16> save ( getWorkingDirectory () ); core::string<c16> current; current = FileArchives[i]->getArchiveName() + WorkingDirectory [ FILESYSTEM_VIRTUAL ]; flattenFilename ( current ); if ( changeWorkingDirectoryTo ( current ) ) { flist[0] = new CFileList( "mountpoint" ); flist[0]->constructNative (); changeWorkingDirectoryTo ( save ); } setFileListSystem ( currentType ); } else if ( FileArchives[i]->getArchiveType() == "zip" ) { flist[0] = new CFileList( "zip" ); flist[1] = new CFileList( "zip directory" ); // add relative navigation e2.isDirectory = 1; e2.Name = "."; e2.FullName = r->Path + e2.Name; e2.Size = 0; flist[1]->Files.push_back ( e2 ); e2.Name = ".."; e2.FullName = r->Path + e2.Name; flist[1]->Files.push_back ( e2 ); for ( u32 g = 0; g < FileArchives[i]->getFileCount(); ++g) { const SZipFileEntry *e = (SZipFileEntry*) FileArchives[i]->getFileInfo(g); s32 test = isInSameDirectory ( r->Path, e->zipFileName ); if ( test < 0 || test > 1 ) continue; e2.Size = e->header.DataDescriptor.UncompressedSize; e2.isDirectory = e2.Size == 0; // check missing directories if ( !e2.isDirectory && test == 1 ) { e3.Size = 0; e3.isDirectory = 1; e3.FullName = e->path; e3.Name = e->path.subString ( r->Path.size(), e->path.size() - r->Path.size() - 1 ); if ( flist[1]->Files.binary_search ( e3 ) < 0 ) flist[1]->Files.push_back ( e3 ); } else { e2.FullName = e->zipFileName; e2.Name = e->simpleFileName; if ( !e2.isDirectory ) core::deletePathFromFilename ( e2.Name ); flist[0]->Files.push_back ( e2 ); } } } // add file to virtual directory for ( u32 g = 0; g < 2; ++g ) { if ( !flist[g] ) continue; for ( u32 j = 0; j != flist[g]->Files.size(); ++j ) r->Files.push_back ( flist[g]->Files[j] ); flist[g]->drop(); } } r->Files.sort(); return r; }
void MainWindow::actionOpen_Directory(){ QDesktopServices::openUrl(QUrl("file:///"+getWorkingDirectory(), QUrl::TolerantMode)); }
//! Creates a list of files and directories in the current working directory IFileList* CFileSystem::createFileList() { CFileList* r = 0; io::path Path = getWorkingDirectory(); Path.replace('\\', '/'); if (Path.lastChar() != '/') Path.append('/'); //! Construct from native filesystem if (FileSystemType == FILESYSTEM_NATIVE) { io::path fullPath; // -------------------------------------------- //! Windows version #ifdef _IRR_WINDOWS_API_ #if !defined ( _WIN32_WCE ) r = new CFileList(Path, true, false); struct _finddata_t c_file; long hFile; if( (hFile = _findfirst( "*", &c_file )) != -1L ) { do { fullPath = Path + c_file.name; r->addItem(fullPath, c_file.size, (_A_SUBDIR & c_file.attrib) != 0, 0); } while( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); } #endif //TODO add drives //entry.Name = "E:\\"; //entry.isDirectory = true; //Files.push_back(entry); #endif // -------------------------------------------- //! Linux version #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_)) r = new CFileList(Path, false, false); r->addItem(Path + "..", 0, true, 0); //! We use the POSIX compliant methods instead of scandir DIR* dirHandle=opendir(Path.c_str()); if (dirHandle) { struct dirent *dirEntry; while ((dirEntry=readdir(dirHandle))) { u32 size = 0; bool isDirectory = false; fullPath = Path + dirEntry->d_name; if((strcmp(dirEntry->d_name, ".")==0) || (strcmp(dirEntry->d_name, "..")==0)) { continue; } struct stat buf; if (stat(dirEntry->d_name, &buf)==0) { size = buf.st_size; isDirectory = S_ISDIR(buf.st_mode); } #if !defined(_IRR_SOLARIS_PLATFORM_) && !defined(__CYGWIN__) // only available on some systems else { isDirectory = dirEntry->d_type == DT_DIR; } #endif r->addItem(fullPath, size, isDirectory, 0); } closedir(dirHandle); } #endif } else { //! create file list for the virtual filesystem r = new CFileList(Path, false, false); //! add relative navigation SFileListEntry e2; SFileListEntry e3; //! PWD r->addItem(Path + ".", 0, true, 0); //! parent r->addItem(Path + "..", 0, true, 0); //! merge archives for (u32 i=0; i < FileArchives.size(); ++i) { const IFileList *merge = FileArchives[i]->getFileList(); for (u32 j=0; j < merge->getFileCount(); ++j) { if (core::isInSameDirectory(Path, merge->getFullFileName(j)) == 0) { io::path fullPath = merge->getFullFileName(j); r->addItem(fullPath, merge->getFileSize(j), merge->isDirectory(j), 0); } } } } if (r) r->sort(); return r; }
void logToFileAt(char * stringToLog, char * logFilePath) { char * currentDir = getWorkingDirectory(); changeDirectoryTo(logFilePath); logToFile(stringToLog); changeDirectoryTo(currentDir); }
void Manga::downloadInformation() { sf::Http web(MangaHost); sf::Http::Request request(m_uri); sf::Http::Response response = web.sendRequest(request); sf::Http::Response::Status status = response.getStatus(); if (status == sf::Http::Response::Ok) { //std::cout<<"Link is valid\n"; std::string body(response.getBody()); //Erase all of the \n eraseN(body); if (testing) { if (!directoryExists("test")) createDirectory("test"); FILE* f = fopen("test/body.html", "w"); fwrite(body.c_str(), sizeof(char), body.size(), f); fclose(f); std::cout<<"Html page output to file: test/body.html\n"; } //Start parsing m_name = getParse(body, parseMangaName); //Supress all white spaces at the end of the name!! for (int i(m_name.size()-1); i>=0; --i) { if (m_name[i] == ' ') m_name.resize(i); else break; } std::string last_chapter(getParse(body, parseChapters)); sscanf(last_chapter.c_str(), "%u", &m_num_chapters); if (testing) std::cout<<"Name parsed: "<<m_name<<".\nChapter count parsed: "<<last_chapter<<"\n"; if (!testing) { if (!directoryExists("mangas")) createDirectory("mangas"); if (!directoryExists("mangas/" + m_name)) createDirectory("mangas/" + m_name); } if (m_cover != NULL) delete m_cover; m_cover = new Image(getParse(body, parseCover), "mangas/" + m_name + "/"); if (!testing) m_cover->thDownload(); else std::cout<<"Cover parsed: "<<m_cover->getUrl()<<"\n"; m_loaded = true; //Fill list of chapters sf::Clock clock; size_t first(0); std::string chapter_web_list(getParse(body, parseChapterList)); //erase all the \n!! eraseN(chapter_web_list); if (testing) { FILE* f = fopen("test/chapter_list.html", "w"); fwrite(chapter_web_list.c_str(), sizeof(char), chapter_web_list.size(), f); fclose(f); std::cout<<"Html page output to file: test/chapter_list.html\n"; } unsigned int chapter_i(1); while(true) { first = chapter_web_list.find(parseChapterListElement.begin[0], first); if (first == chapter_web_list.npos) break; else first += parseChapterListElement.begin[0].size(); std::string chapter_url, chapter_name(getParse(chapter_web_list.substr(first), Manga::parseChapterListName)); switch (Manga::chapterPath) { case URL_uri: chapter_url = getParse(chapter_web_list.substr(first), parseChapterListUri); break; case URL_absolute: //std::cout<<getParse(chapter_web_list.substr(first), parseChapterListUri)<<" tachan!\n"; chapter_url = getUri(getParse(chapter_web_list.substr(first), parseChapterListUri)); break; case URL_relative: chapter_url = getWorkingDirectory(m_uri) + getParse(chapter_web_list.substr(first), parseChapterListUri); break; default: break; } m_chapters.push_back(Chapter(chapter_url, this, chapter_i, chapter_name)); //std::cout<<"Added chapter: "<<m_chapters.back()<<"\n"; ++chapter_i; } if (Manga::chapterListReversed) // reverse the chapter list { m_chapters.reverse(); chapter_i = 1; for (std::list<Chapter>::iterator it(m_chapters.begin()); it != m_chapters.end(); ++it) { it->setChapter(chapter_i); ++chapter_i; } } if (testing) { std::cout<<m_chapters.size()<<" chapters were parsed\n"; for (std::list<Chapter>::iterator it(m_chapters.begin()); it != m_chapters.end(); ++it) std::cout<<"Chapter "<<it->m_num_chapter<<" parsed: "<<it->m_name<<" at "<<it->m_uri<<"\n"; } //std::cout<<"Chapter list created in: "<<clock.getElapsedTime().asSeconds()<<" sec\n"; } else std::cout<<"Error downloading manga info: "<<status<<"\n"; }