char* DirectoryHelper::CreatePath(const char *path1, const char *path2) { bool relative = true; while( *path1 == DIR_SLASH || *path1 == DIR_BAD_SLASH ) { relative = false; path1++; } dir_lock.Lock(); strcpy(create_path, root_dir); if( relative ) { strcat(create_path, DIR_SLASH_S); strcat(create_path, current_dir); } dir_lock.Unlock(); strcat(create_path, DIR_SLASH_S); strcat(create_path, path1); CleanupPath(create_path, true); if( path2 != NULL ) { strcat(create_path, DIR_SLASH_S); strcat(create_path, path2); CleanupPath(create_path, true); } return create_path; }
void DirectoryHelper::SetRootDirectory(const char *path) { dir_lock.Lock(); strcpy(root_dir, path); CleanupPath(root_dir, true); dir_lock.Unlock(); }
Path::Path() : m_sPath("") { #if defined(WIN32) ExtractDriveLetter(); #endif CleanupPath(); }
Path::Path(const std::string & sPath) : m_sPath(sPath) { #if defined(WIN32) ExtractDriveLetter(); #endif CleanupPath(); }
Path::Path(LPCSTR sPath) : m_sPath(sPath) { #if defined(WIN32) ExtractDriveLetter(); #endif CleanupPath(); }
int OpenProfilesFolder() { sprintf(browser.dir, "%s/profiles/", appPath); int device = 0; FindDevice(browser.dir, &device); CleanupPath(browser.dir); ResetBrowser(); // reset browser return ParseDirectory(); }
Path::Path(const std::string & sPath, bool bCleanup) : m_sPath(sPath) { #if defined(_WINDOWS) ExtractDriveLetter(); #endif if(bCleanup) { CleanupPath(); } }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char ext[4]; char temppath[MAXPATHLEN]; if (type == FILE_ROM) { // Check path length if ((strlen(browser.dir) + 1 + strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { // ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s", browser.dir, browserList[browser.selIndex].filename); } } else { // if (GCSettings.SaveMethod == DEVICE_AUTO) // GCSettings.SaveMethod = autoSaveMethod(SILENT); // // if (GCSettings.SaveMethod == DEVICE_AUTO) // return false; switch (type) { case FILE_SRAM: case FILE_SNAPSHOT: if (type == FILE_SRAM) sprintf(ext, "srm"); else sprintf(ext, "gpz"); if (filenum >= -1) { if (filenum == -1) sprintf(file, "%s.%s", filename, ext); else if (filenum == 0) sprintf(file, "%s Auto.%s", filename, ext); else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; case FILE_CHEAT: sprintf(file, "%s.cht", "test"); break; } sprintf(temppath, "uda:/%s/%s", emu.getFolderName(), file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }
void DirectoryHelper::ChangeDirectory(const char *path) { bool relative = true; while( *path == DIR_SLASH || *path == DIR_BAD_SLASH ) { relative = false; path++; } dir_lock.Lock(); if( relative ) { strcat(current_dir, DIR_SLASH_S); strcat(current_dir, path); }else{ strcpy(current_dir, path); } CleanupPath(current_dir, false); dir_lock.Unlock(); }
int PushSearchPath (SearchPaths* P, const char* NewPath) /* Add a new search path to the head of an existing search path list, provided ** that it's not already there. If the path is already at the first position, ** return zero, otherwise return a non zero value. */ { /* Generate a clean copy of NewPath */ char* Path = CleanupPath (NewPath); /* If we have paths, check if Path is already at position zero */ if (CollCount (P) > 0 && strcmp (CollConstAt (P, 0), Path) == 0) { /* Match. Delete the copy and return to the caller */ xfree (Path); return 0; } /* Insert a clean copy of the path at position 0, return success */ CollInsert (P, Path, 0); return 1; }
static void Add (SearchPaths* P, const char* New) /* Cleanup a new search path and add it to the list */ { /* Add a clean copy of the path to the collection */ CollAppend (P, CleanupPath (New)); }
/**************************************************************************** * BrowserChangeFolder * * Update current directory and set new entry list if directory has changed ***************************************************************************/ int BrowserChangeFolder() { int device = 0; FindDevice(browser.dir, &device); if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave { inSz = false; SzClose(); } if(!UpdateDirName()) return -1; HaltParseThread(); CleanupPath(browser.dir); ResetBrowser(); if(browser.dir[0] != 0) { if(strstr(browser.dir, ".7z")) { BrowserLoadSz(); } else { ParseDirectory(true, true); } FindAndSelectLastLoadedFile(); } if(browser.numEntries == 0) { browser.dir[0] = 0; int i=0; #ifdef HW_RVL AddBrowserEntry(); sprintf(browserList[i].filename, "sd:/"); sprintf(browserList[i].displayname, "SD Card"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "usb:/"); sprintf(browserList[i].displayname, "USB Mass Storage"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_USB; i++; #else AddBrowserEntry(); sprintf(browserList[i].filename, "carda:/"); sprintf(browserList[i].displayname, "SD Gecko Slot A"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "cardb:/"); sprintf(browserList[i].displayname, "SD Gecko Slot B"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; #endif AddBrowserEntry(); sprintf(browserList[i].filename, "smb:/"); sprintf(browserList[i].displayname, "Network Share"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SMB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "dvd:/"); sprintf(browserList[i].displayname, "Data DVD"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_DVD; i++; browser.numEntries += i; } if(browser.dir[0] == 0) { GCSettings.LoadFolder[0] = 0; GCSettings.LoadMethod = 0; } else { char * path = StripDevice(browser.dir); if(path != NULL) strcpy(GCSettings.LoadFolder, path); FindDevice(browser.dir, &GCSettings.LoadMethod); } return browser.numEntries; }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char folder[1024]; char ext[4]; char temppath[MAXPATHLEN]; if(type == FILE_ROM) { // Check path length if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else { if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = autoSaveMethod(SILENT); if(GCSettings.SaveMethod == DEVICE_AUTO) return false; switch(type) { case FILE_SRAM: case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); if(type == FILE_SRAM) sprintf(ext, "srm"); else sprintf(ext, "frz"); if(filenum >= -1) { if(filenum == -1) sprintf(file, "%s.%s", filename, ext); else if(filenum == 0) if (GCSettings.AppendAuto <= 0) sprintf(file, "%s.%s", filename, ext); else sprintf(file, "%s Auto.%s", filename, ext); else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; case FILE_CHEAT: sprintf(folder, GCSettings.CheatFolder); sprintf(file, "%s.cht", Memory.ROMFilename); break; } sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }
EPUB3_BEGIN_NAMESPACE string NavigationPoint::AbsolutePath(ConstPackagePtr pkg) const { if (_content.empty()) return string::EmptyString; string full = pkg->BasePath(); NavigationElementPtr parent = Owner(); NavigationTablePtr root; do { if (!bool(parent)) break; root = std::dynamic_pointer_cast<NavigationTable>(parent); if (!bool(root)) { NavigationPointPtr pt = std::dynamic_pointer_cast<NavigationPoint>(parent); if (!bool(pt)) break; parent = pt->Owner(); } } while (!bool(root)); if (bool(root)) { string sourceRoot = root->SourceHref(); auto pos = sourceRoot.rfind('/'); if (pos == string::npos) pos = 0; sourceRoot.erase(pos); full += sourceRoot; } try { if (_content[0] == '/' && full[full.size() - 1] == '/') { full += _content.c_str() + 1; } else if (_content[0] != '/' && full[full.size() - 1] != '/') { full += '/'; full += _content; } else { full += _content; } } catch (std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; } full = CleanupPath(full); auto pos = full.rfind('#'); if (pos != string::npos) full.erase(pos); return full; }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char folder[1024]; char ext[4]; char temppath[MAXPATHLEN]; if(type == FILE_ROM) { // Check path length if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else if (type == FILE_BORDER_PNG) { const char* loadedpath = filename; if (loadedpath == NULL) loadedpath = "default"; // Ensure that loadedname contains only the filename, not the path const char* loadedname = strrchr(loadedpath, '/'); if (loadedname == NULL) loadedname = loadedpath; // Check path length if ((strlen(pathPrefix[GCSettings.LoadMethod]) + strlen(GCSettings.BorderFolder) + strlen(loadedname)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } StripExt(file, loadedname); sprintf(temppath, "%s%s/%s.png", pathPrefix[GCSettings.LoadMethod], GCSettings.BorderFolder, file); } else { if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = autoSaveMethod(SILENT); if(GCSettings.SaveMethod == DEVICE_AUTO) return false; switch(type) { case FILE_SRAM: case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); if(type == FILE_SRAM) sprintf(ext, "sav"); else sprintf(ext, "sgm"); if(filenum >= -1) { if(filenum == -1) sprintf(file, "%s.%s", filename, ext); else if(filenum == 0) if (GCSettings.AppendAuto <= 0) { sprintf(file, "%s.%s", filename, ext); } else { sprintf(file, "%s Auto.%s", filename, ext); } else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; } sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }
/**************************************************************************** * BrowserChangeFolder * * Update current directory and set new entry list if directory has changed ***************************************************************************/ int BrowserChangeFolder() { int device = 0; FindDevice(browser.dir, &device); if(!UpdateDirName()){ return -1; } HaltParseThread(); // halt parsing CleanupPath(browser.dir); ResetBrowser(); // reset browser if(browser.dir[0] != 0){ ParseDirectory(); } if(browser.numEntries == 0) { browser.dir[0] = 0; int i=0; #if 0 AddBrowserEntry(); sprintf(browserList[i].filename, "uda:/"); sprintf(browserList[i].displayname, "USB Mass Storage"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_USB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "sda0:/"); sprintf(browserList[i].displayname, "Hard Drive"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "smb:/"); sprintf(browserList[i].displayname, "Network Share"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SMB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "dvd:/"); sprintf(browserList[i].displayname, "Data DVD"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_DVD; i++; #else // dynamic use int iusb = 0; int ihdd = 0; int imisc = 0; for (int id = 3; id < STD_MAX; id++) { if (devoptab_list[id]->structSize) { AddBrowserEntry(); sprintf(browserList[i].filename, "%s:/", devoptab_list[id]->name); browserList[i].length = 0; browserList[i].isdir = 1; switch(browserList[i].filename[0]) { case 'u': { browserList[i].icon = ICON_USB; sprintf(browserList[i].displayname, "USB Mass Storage %d", iusb++); break; } case 's': { browserList[i].icon = ICON_SD; sprintf(browserList[i].displayname, "Hard Drive %d", ihdd++); break; } default: { browserList[i].icon = ICON_DVD; sprintf(browserList[i].displayname, "DVD %d", imisc++); break; } } printf("findDevices : %s\r\n", browserList[i].filename); i++; } } #endif browser.numEntries += i; } if(browser.dir[0] == 0) { GCSettings.LoadFolder[0] = 0; GCSettings.LoadMethod = 0; } else { char * path = StripDevice(browser.dir); if(path != NULL) strcpy(GCSettings.LoadFolder, path); FindDevice(browser.dir, &GCSettings.LoadMethod); } return browser.numEntries; }