void web_page::set_base_url( const litehtml::tchar_t* base_url ) { #ifndef LITEHTML_UTF8 if(base_url) { if(PathIsRelative(base_url) && !PathIsURL(base_url)) { make_url(base_url, m_url.c_str(), m_base_path); } else { m_base_path = base_url; } } else { m_base_path = m_url; } #else LPWSTR bu = cairo_font::utf8_to_wchar(base_url); if(bu) { if(PathIsRelative(bu) && !PathIsURL(bu)) { make_url(bu, m_url.c_str(), m_base_path); } else { m_base_path = bu; } } else { m_base_path = m_url; } #endif }
void CProjectNew::OnOK() { UpdateData(TRUE); if ( m_strName.IsEmpty() ) { AfxMessageBox("Project name cannot be empty string."); return; } if ( PathIsRelative(m_strProjectDir) ) { AfxMessageBox("Path to project directory must be absolute."); return; } if ( GetFileAttributes(m_strProjectDir)!=FILE_ATTRIBUTE_DIRECTORY && !CreateDirectory(m_strProjectDir, NULL) ) { AfxMessageBox("Cannot create project directory."); return; } int nItem = m_types.GetNextItem(-1, LVNI_SELECTED|LVNI_ALL); if ( nItem==-1 ) { AfxMessageBox("Select project type."); return; } m_nType = m_types.GetItemData(nItem); CDialog::OnOK(); }
/// Directory handling /// ================== BOOL md_dir_set(UINT32 dir_seg4, UINT16 dir_off) { CHAR dir_raw[MAX_PATH]; TCHAR dir_ucs2[MAX_PATH]; OEMCHAR *dos_dir; OEMCHAR *real_dir; BOOL ret; dos_dir = mem_read_sjis2ucs2(dir_raw, dir_ucs2, dir_seg4, dir_off, MAX_PATH); real_dir = md_drive_parse(dos_dir); // Changing to an empty string would lead to an error, crashing DOS if(real_dir[0] == _T('\0')) { ret = 1; } else { ret = SetCurrentDirectory(real_dir); } // Don't set errors here! // Changing the registers quickly leads to // DOS crashing inside its own DIR function if(ret) { if(PathIsRelative(dos_dir)) { OEMCHAR tmp[MAX_PATH]; lstrcpy(tmp, cur_dir); PathAddBackslash(tmp); lstrcat(tmp, real_dir); PathCanonicalize(cur_dir, tmp); } else { lstrcpy(cur_dir, real_dir); } } // Don't override DOS' handling of this one return FALSE; }
void CRenameDlg::OnOK() { UpdateData(); m_name.Trim(); bool nameAllowed = ((m_originalName != m_name) || !m_renameRequired) && !m_name.IsEmpty(); if (!nameAllowed) { m_bBalloonVisible = true; ShowEditBalloon(IDC_NAME, IDS_WARN_RENAMEREQUIRED, IDS_ERR_ERROR, TTI_ERROR); return; } CTGitPath path(m_name); if (!path.IsValidOnWindows() || !PathIsRelative(m_name)) { m_bBalloonVisible = true; ShowEditBalloon(IDC_NAME, IDS_WARN_NOVALIDPATH, IDS_ERR_ERROR, TTI_ERROR); return; } if (m_pInputValidator) { CString sError = m_pInputValidator(IDC_NAME, m_name); if (!sError.IsEmpty()) { m_bBalloonVisible = true; ShowEditBalloon(IDC_NAME, sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), TTI_ERROR); return; } } CHorizontalResizableStandAloneDialog::OnOK(); }
// converts relative path to absolute path int expand_dirname(char *dirname, char *drive) { char relative[MAX_PATH]; char absolute[MAX_PATH]; BOOL status; if (PathIsRelative(dirname)) { _ASSERTE(strlen(drive) < NUM_OF(relative)); strcpy(relative, drive); _ASSERTE(strlen(relative) + strlen(dirname) < NUM_OF(relative)); strcat(relative, dirname); status = PathSearchAndQualify(relative, absolute, NUM_OF(absolute)); _ASSERTE(status); if (':' == absolute[1]) { drive[0] = absolute[0]; drive[1] = absolute[1]; drive[2] = 0; strcpy(dirname, &absolute[2]); } else { strcpy(dirname, absolute); } } fix_dirname(dirname); return 0; }
/** * Returns the .git-path (if .git is a file, read the repository path and return it) * adminDir always ends with "\" */ bool GitAdminDir::GetAdminDirPath(const CString& projectTopDir, CString& adminDir, bool* isWorktree) { CString wtAdminDir; if (!GetWorktreeAdminDirPath(projectTopDir, wtAdminDir)) return false; CString pathToCommonDir = wtAdminDir + L"commondir"; if (!PathFileExists(pathToCommonDir)) { adminDir = wtAdminDir; if (isWorktree) *isWorktree = false; return true; } CAutoFILE pFile = _wfsopen(pathToCommonDir, L"rb", SH_DENYWR); if (!pFile) return false; int size = 65536; CStringA commonDirA; int length = (int)fread(commonDirA.GetBufferSetLength(size), sizeof(char), size, pFile); commonDirA.ReleaseBuffer(length); CString commonDir = CUnicodeUtils::GetUnicode(commonDirA); commonDir.TrimRight(L"\r\n"); commonDir.Replace(L'/', L'\\'); if (PathIsRelative(commonDir)) adminDir = CPathUtils::BuildPathWithPathDelimiter(wtAdminDir + commonDir); else adminDir = CPathUtils::BuildPathWithPathDelimiter(commonDir); if (isWorktree) *isWorktree = true; return true; }
CString CPathUtils::GetLongPathname(const CString& path) { if (path.IsEmpty()) return path; TCHAR pathbufcanonicalized[MAX_PATH]; // MAX_PATH ok. DWORD ret = 0; CString sRet; if (!PathIsURL(path) && PathIsRelative(path)) { ret = GetFullPathName(path, 0, NULL, NULL); if (ret) { std::unique_ptr<TCHAR[]> pathbuf(new TCHAR[ret + 1]); if ((ret = GetFullPathName(path, ret, pathbuf.get(), NULL)) != 0) sRet = CString(pathbuf.get(), ret); } } else if (PathCanonicalize(pathbufcanonicalized, path)) { ret = ::GetLongPathName(pathbufcanonicalized, NULL, 0); std::unique_ptr<TCHAR[]> pathbuf(new TCHAR[ret + 2]); ret = ::GetLongPathName(pathbufcanonicalized, pathbuf.get(), ret + 1); sRet = CString(pathbuf.get(), ret); } else { ret = ::GetLongPathName(path, NULL, 0); std::unique_ptr<TCHAR[]> pathbuf(new TCHAR[ret + 2]); ret = ::GetLongPathName(path, pathbuf.get(), ret + 1); sRet = CString(pathbuf.get(), ret); } if (ret == 0) return path; return sRet; }
void CSimSysManager::vSetConfigData(xmlNodePtr pNode) { INT nWndPos = S_FALSE; vInitailizeSimSysInfo(); if( NULL != pNode ) { pNode = pNode->xmlChildrenNode; while (pNode != NULL) { if ((!xmlStrcmp(pNode->name, (const xmlChar*)"Window_Position"))) { nWndPos = xmlUtils::ParseWindowsPlacement(pNode, CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement); } if ((!xmlStrcmp(pNode->name, (const xmlChar*)"Sym_Path"))) { xmlChar* key = xmlNodeListGetString(pNode->doc, pNode->xmlChildrenNode, 1); if(NULL != key) { CString omStrFileName; if(PathIsRelative((char*)key) == TRUE) { std::string omStrConfigFolder; std::string omPath; char configPath[MAX_PATH]; AfxGetMainWnd()->SendMessage(MSG_GET_CONFIGPATH, (WPARAM)configPath, 0); CUtilFunctions::nGetBaseFolder(configPath, omStrConfigFolder ); char chAbsPath[MAX_PATH]; PathCombine(chAbsPath, omStrConfigFolder.c_str(), (char*)key); omStrFileName = chAbsPath; } else { omStrFileName = (char*)key; } vLoadSimInfoFromConfiguration((char*)omStrFileName.GetBuffer(MAX_PATH)); xmlFree(key); } } pNode = pNode->next; } } if(nWndPos == S_FALSE) { /*CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement.rcNormalPosition.top = 160; CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement.rcNormalPosition.left = 520; CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement.rcNormalPosition.right = 1458; CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement.rcNormalPosition.bottom = 686; CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement.showCmd = SW_NORMAL;*/ CGlobalObj::ouGetObj(m_eBus).bGetDefaultValue(SIMSYS_WND_PLACEMENT, CGlobalObj::ouGetObj(m_eBus).m_wWindowPlacement); } if (m_pomSimSysTreeView != NULL) { if (m_pomSimSysTreeView->IsWindowVisible()) { m_pomSimSysTreeView->bPopulateTree(); } } }
void CChordEaseApp::MakeAbsolutePath(CString& Path) { if (PathIsRelative(Path)) { // if path is relative CPathStr AbsPath(GetDataFolderPath()); AbsPath.Append(Path); Path = AbsPath; } }
std::string I_GetUserFileName (const char *file) { #if defined(UNIX) && !defined(GEKKO) // return absolute or explicitly relative pathnames unmodified, // so launchers or CLI/console users have control over netdemo placement if (file && (file[0] == PATHSEPCHAR || // /path/to/file (file[0] == '.' && file[1] == PATHSEPCHAR) || // ./file (file[0] == '.' && file[1] == '.' && file[2] == PATHSEPCHAR))) // ../file return std::string (file); std::string path = I_GetHomeDir(); if(path[path.length() - 1] != PATHSEPCHAR) path += PATHSEP; path += ".odamex"; struct stat info; if (stat (path.c_str(), &info) == -1) { if (mkdir (path.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) == -1) { I_FatalError ("Failed to create %s directory:\n%s", path.c_str(), strerror (errno)); } } else { if (!S_ISDIR(info.st_mode)) { I_FatalError ("%s must be a directory", path.c_str()); } } path += PATHSEP; path += file; #elif defined(_XBOX) std::string path = "T:"; path += PATHSEP; path += file; #else if (!PathIsRelative(file)) return std::string (file); std::string path = I_GetBinaryDir(); if(path[path.length() - 1] != PATHSEPCHAR) path += PATHSEP; path += file; #endif FixPathSeparator(path); return path; }
std::wstring LyricSourceLRC::getSavePath(const metadb_handle_ptr &track) { std::string path = track->get_path(); std::wstring wpath = EncodingFunc::ToUTF16(path.substr(boost::find_last(path, "://").end() - path.begin())); wpath = wpath.substr(0, wpath.find_last_of(L".")); if(track->get_subsong_index() != 0) wpath += boost::lexical_cast<std::wstring>(track->get_subsong_index()); wpath += L".lrc"; if(m_config["lrcsavepath"].length()) { class LRCTitleFormatCallback : public main_thread_callback { private: HANDLE m_event; std::string *m_out; const std::string &m_format; const metadb_handle_ptr &m_track; public: LRCTitleFormatCallback(HANDLE event, std::string *out, const std::string &format, const metadb_handle_ptr &track) : m_event(event), m_format(format), m_out(out), m_track(track) {} virtual void callback_run() { core_api::ensure_main_thread(); pfc::string8 out; service_ptr_t<titleformat_object> script; static_api_ptr_t<titleformat_compiler>()->compile(script, m_format.c_str()); m_track->format_title(NULL, out, script, NULL); m_out->assign(out.get_ptr()); SetEvent(m_event); } }; std::wstring dirname = wpath.substr(0, wpath.find_last_of(L'\\') + 1); std::wstring filename = wpath.substr(wpath.find_last_of(L"\\") + 1); HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); std::string out; std::string pathtmp = m_config["lrcsavepath"]; if(pathtmp.at(pathtmp.length() - 1) != '\\') pathtmp += '\\'; service_ptr_t<LRCTitleFormatCallback> p_callback = new service_impl_t<LRCTitleFormatCallback>(event, &out, pathtmp, track); static_api_ptr_t<main_thread_callback_manager>()->add_callback(p_callback); p_callback.release(); WaitForSingleObject(event, INFINITE); CloseHandle(event); wpath = EncodingFunc::ToUTF16(out); if(PathIsRelative(wpath.c_str())) wpath = dirname + wpath; if(GetFileAttributes(wpath.c_str()) & FILE_ATTRIBUTE_DIRECTORY && (GetLastError() != ERROR_FILE_NOT_FOUND && GetLastError() != ERROR_PATH_NOT_FOUND)) wpath += filename; return wpath; } if(path.find_first_of("file://") == std::string::npos) return std::wstring(L""); if(path.find_first_of("unpack://") == std::string::npos) return std::wstring(L""); return wpath; }
CString CFilePatchesDlg::GetFullPath(int nIndex) { CString temp = m_pPatch->GetStrippedPath(nIndex); temp.Replace('/', '\\'); //temp = temp.Mid(temp.Find('\\')+1); if (PathIsRelative(temp)) temp = m_sPath + temp; return temp; }
int is_definite( const char * filename ) { #ifdef _UNIX_ return (filename[0] == '/') || (filename[0] == '.'); #else // Should we assume windows?! // Windows impl return (PathIsRelative( filename ) == FALSE) || (filename[0] == '.'); #endif }
static void* dl_open(const char* name, int flags) { if (name == NULL) { return GetModuleHandle(NULL); } else { DWORD dwFlags = PathIsRelative(name) ? 0 : LOAD_WITH_ALTERED_SEARCH_PATH; return LoadLibraryEx(name, NULL, dwFlags); } }
bool SubmoduleAddCommand::Execute() { bool bRet = false; CSubmoduleAddDlg dlg; dlg.m_strPath = cmdLinePath.GetDirectory().GetWinPathString(); dlg.m_strProject = g_Git.m_CurrentDir; if( dlg.DoModal() == IDOK ) { if (dlg.m_bAutoloadPuttyKeyFile) CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); CString cmd; if(dlg.m_strPath.Left(g_Git.m_CurrentDir.GetLength()) == g_Git.m_CurrentDir) dlg.m_strPath = dlg.m_strPath.Right(dlg.m_strPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1); CString branch; if(dlg.m_bBranch) branch.Format(_T(" -b %s "), (LPCTSTR)dlg.m_strBranch); CString force; if (dlg.m_bForce) force = _T("--force"); dlg.m_strPath.Replace(_T('\\'),_T('/')); dlg.m_strRepos.Replace(_T('\\'),_T('/')); cmd.Format(_T("git.exe submodule add %s %s -- \"%s\" \"%s\""), (LPCTSTR)branch, (LPCTSTR)force, (LPCTSTR)dlg.m_strRepos, (LPCTSTR)dlg.m_strPath); CProgressDlg progress; progress.m_GitCmd=cmd; progress.DoModal(); if (progress.m_GitStatus == 0) { if (dlg.m_bAutoloadPuttyKeyFile) { SetCurrentDirectory(g_Git.m_CurrentDir); CGit subgit; dlg.m_strPath.Replace(_T('/'), _T('\\')); subgit.m_CurrentDir = PathIsRelative(dlg.m_strPath) ? g_Git.CombinePath(dlg.m_strPath) : dlg.m_strPath; if (subgit.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL)) { CMessageBox::Show(NULL, _T("Fail set config remote.origin.puttykeyfile"), _T("TortoiseGit"), MB_OK| MB_ICONERROR); return FALSE; } } } bRet = TRUE; } return bRet; }
static void fixRelativePaths(strings &dirs, const char_t *basepath) { for (strings::iterator d = dirs.begin(); d != dirs.end(); d++) if (PathIsRelative(d->c_str())) { char_t absdir[MAX_PATH]; _makepath_s(absdir, countof(absdir), NULL, basepath, d->c_str(), NULL); char_t absdirC[MAX_PATH]; PathCanonicalize(absdirC, absdir); *d = absdirC; } }
bool sbncIsAbsolutePath(const char *Path) { #ifdef _WIN32 return !PathIsRelative(Path); #else if (Path[0] == '/') { return true; } return false; #endif }
int osd_is_absolute_path(const char *path) { int result = FALSE; TCHAR *t_path = tstring_from_utf8(path); if (t_path != NULL) { result = !PathIsRelative(t_path); free(t_path); } return result; }
bool osd_is_absolute_path(std::string const &path) { bool result = false; TCHAR *t_path = tstring_from_utf8(path.c_str()); if (t_path != nullptr) { result = !PathIsRelative(t_path); osd_free(t_path); } return result; }
static jboolean Windows_pathIsRelative(JNIEnv* env, jclass, jstring javaPath) { ScopedUtfChars path(env, javaPath); if (path.c_str() == NULL) { return false; } if (path.size() > MAX_PATH) { return false; // TODO: Possible throw an exception in this case... } return PathIsRelative(path.c_str()); }
// Find a record corresponding to the given source file, line number and optionally column number. // (at the moment the column parameter is ignored) // // If there are several *consecutively declared* records for the same line then they are all returned. // The list of records is added to the vector 'records' // // If there is no record for that line, the record corresponding to the nearest line is selected // (within a range of EPSILON_LINE) // // The function returns PDFSYNCERR_SUCCESS if a matching record was found. UINT Pdfsync::SourceToRecord(const WCHAR* srcfilename, UINT line, UINT col, Vec<size_t> &records) { if (!srcfilename) return PDFSYNCERR_INVALID_ARGUMENT; ScopedMem<WCHAR> srcfilepath; // convert the source file to an absolute path if (PathIsRelative(srcfilename)) srcfilepath.Set(PrependDir(srcfilename)); else srcfilepath.Set(str::Dup(srcfilename)); if (!srcfilepath) return PDFSYNCERR_OUTOFMEMORY; // find the source file entry size_t isrc; for (isrc = 0; isrc < srcfiles.Count(); isrc++) if (path::IsSame(srcfilepath, srcfiles.At(isrc))) break; if (isrc == srcfiles.Count()) return PDFSYNCERR_UNKNOWN_SOURCEFILE; if (fileIndex.At(isrc).start == fileIndex.At(isrc).end) return PDFSYNCERR_NORECORD_IN_SOURCEFILE; // there is not any record declaration for that particular source file // look for sections belonging to the specified file // starting with the first section that is declared within the scope of the file. UINT min_distance = EPSILON_LINE; // distance to the closest record size_t lineIx = (size_t)-1; // closest record-line index for (size_t isec = fileIndex.At(isrc).start; isec < fileIndex.At(isrc).end; isec++) { // does this section belong to the desired file? if (lines.At(isec).file != isrc) continue; UINT d = abs((int)lines.At(isec).line - (int)line); if (d < min_distance) { min_distance = d; lineIx = isec; if (0 == d) break; // We have found a record for the requested line! } } if (lineIx == (size_t)-1) return PDFSYNCERR_NORECORD_FOR_THATLINE; // we read all the consecutive records until we reach a record belonging to another line for (size_t i = lineIx; i < lines.Count() && lines.At(i).line == lines.At(lineIx).line; i++) records.Push(lines.At(i).record); return PDFSYNCERR_SUCCESS; }
bool IsPathRelative(const std::string& path) { #if defined _WIN32 || defined __WIN32__ return PathIsRelative(path.c_str()) == 1; #else if (path.size() > 0 && path[0] == '/') { return false; } else { return true; } #endif }
static bool IsTool(const CString& toolname, LPCTSTR setting) { if (IsToolBasename(toolname, setting)) return true; if (!IsToolBasename(toolname, PathFindFileName(setting))) return false; if (PathIsRelative(setting) || !PathFileExists(setting)) return false; return true; }
void fileGetSamePathFileName(PSTR szArgv0,PSTR szName,PSTR szPath) { if (PathIsRelative(szName)){ strncpy(szPath,szArgv0,sizeof(szPath)); strcpy(PathFindFileName(szPath),szName); } else{ strncpy(szPath,szName,sizeof(szPath)); } #ifdef WIN32 strlwr(szPath); #endif //WIN32 }
int file_IsPathRelative(const char* path) { #ifdef WINDOWS if (PathIsRelative(path) == TRUE) { return 1; } return 0; #else if (file_IsDirectorySeparator(path[0])) { return 0; } return 1; #endif }
tstring AppSettings::GetRelativeTexPath(LPCTSTR fname, LPCTSTR prefix) const { TCHAR buffer[MAX_PATH]; if (textureUseFullPath == 1) // full path name { GetFullPathName(fname, _countof(buffer), buffer, nullptr); return tstring(buffer); } else if (textureUseFullPath == -1) // only filename { return tstring(PathFindFileName(fname)); } if (!PathIsRelative(fname)) { TCHAR root[MAX_PATH]; TCHAR file[MAX_PATH]; GetFullPathName(fname, _countof(file), file, nullptr); PathMakePretty(file); for (tstringlist::const_iterator itr = textureRootPaths.begin(), end = textureRootPaths.end(); itr != end; ++itr) { GetFullPathName((*itr).c_str(), _countof(root), root, nullptr); PathAddBackslash(root); PathMakePretty(root); if (-1 != _taccess(root, 0)) { size_t len = _tcslen(root); if (0 == _tcsnicmp(root, file, len)) return tstring(file + len); } } } else // Test if its relative to one of the specified root paths just return the texture { for (tstringlist::const_iterator itr = textureRootPaths.begin(), end = textureRootPaths.end(); itr != end; ++itr) { PathCombine(buffer, itr->c_str(), fname); if (-1 != _taccess(buffer, 0)) { return fname; } } } // check if prefix is in place if so then just return fname as is for (LPCTSTR path = fname; path != nullptr; path = PathFindNextComponent(path)) { if (_tcsnicmp(path, prefix, _tcslen(prefix)) == 0) return tstring(path); } // Now just combine prefix with file portion of the name PathCombine(buffer, prefix, PathFindFileName(fname)); return tstring(buffer); }
int CPatch::CountMatches(const CString& path) { int matches = 0; for (int i=0; i<GetNumberOfFiles(); ++i) { CString temp = GetFilename(i); temp.Replace('/', '\\'); if (PathIsRelative(temp)) temp = path + _T("\\")+ temp; if (PathFileExists(temp)) matches++; } return matches; }
svn_error_t * SVNPatch::patchfile_func( void *baton, svn_boolean_t * filtered, const char * canon_path_from_patchfile, const char * /*patch_abspath*/, const char * /*reject_abspath*/, apr_pool_t * /*scratch_pool*/ ) { SVNPatch * pThis = (SVNPatch*)baton; if (pThis) { CString relpath = CUnicodeUtils::GetUnicode(canon_path_from_patchfile); relpath = PathIsRelative(relpath) ? relpath : relpath.Mid(pThis->m_targetpath.GetLength()); *filtered = relpath.CompareNoCase(pThis->m_filetopatch) != 0; } return NULL; }
int GitPatch::CountMatches(const CString& path) const { int matches = 0; for (int i=0; i<GetNumberOfFiles(); ++i) { CString temp = GetStrippedPath(i); temp.Replace('/', '\\'); if ((PathIsRelative(temp)) || ((temp.GetLength() > 1) && (temp[0]=='\\') && (temp[1]!='\\')) ) temp = path + _T("\\")+ temp; if (PathFileExists(temp)) ++matches; } return matches; }
int GitPatch::CountDirMatches(const CString& path) const { int matches = 0; for (int i=0; i<GetNumberOfFiles(); ++i) { CString temp = GetStrippedPath(i); temp.Replace('/', '\\'); if (PathIsRelative(temp)) temp = path + _T("\\")+ temp; // remove the filename temp = temp.Left(temp.ReverseFind('\\')); if (PathFileExists(temp)) ++matches; } return matches; }