void initialize_config(libconfig::Config& configuration) { tstring environment_path = sx_config_path(); tpath config_path = environment_path.empty() ? tpath(home_directory()) / L".sx.cfg" : tpath(environment_path); set_config_path(configuration, config_path.generic_string().c_str()); }
void get_path_extents(PathIterator& path, const agg::trans_affine& trans, double* x0, double* y0, double* x1, double* y1, double* xm, double* ym) { typedef agg::conv_transform<PathIterator> transformed_path_t; typedef PathNanRemover<transformed_path_t> nan_removed_t; typedef agg::conv_curve<nan_removed_t> curve_t; double x, y; unsigned code; transformed_path_t tpath(path, trans); nan_removed_t nan_removed(tpath, true, path.has_curves()); curve_t curved_path(nan_removed); curved_path.rewind(0); while ((code = curved_path.vertex(&x, &y)) != agg::path_cmd_stop) { if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) { continue; } if (x < *x0) *x0 = x; if (y < *y0) *y0 = y; if (x > *x1) *x1 = x; if (y > *y1) *y1 = y; /* xm and ym are the minimum positive values in the data, used by log scaling */ if (x > 0.0 && x < *xm) *xm = x; if (y > 0.0 && y < *ym) *ym = y; } }
void _cleanup_path(PathIterator& path, const agg::trans_affine& trans, bool remove_nans, bool do_clip, const agg::rect_base<double>& rect, e_snap_mode snap_mode, double stroke_width, bool do_simplify, bool return_curves, std::vector<double>& vertices, std::vector<npy_uint8>& codes) { typedef agg::conv_transform<PathIterator> transformed_path_t; typedef PathNanRemover<transformed_path_t> nan_removal_t; typedef PathClipper<nan_removal_t> clipped_t; typedef PathSnapper<clipped_t> snapped_t; typedef PathSimplifier<snapped_t> simplify_t; typedef agg::conv_curve<simplify_t> curve_t; transformed_path_t tpath(path, trans); nan_removal_t nan_removed(tpath, remove_nans, path.has_curves()); clipped_t clipped(nan_removed, do_clip, rect); snapped_t snapped(clipped, snap_mode, path.total_vertices(), stroke_width); simplify_t simplified(snapped, do_simplify, path.simplify_threshold()); vertices.reserve(path.total_vertices() * 2); codes.reserve(path.total_vertices()); if (return_curves) { __cleanup_path(simplified, vertices, codes); } else { curve_t curve(simplified); __cleanup_path(curve, vertices, codes); } }
void get_path_extents(PathIterator& path, const agg::trans_affine& trans, double* x0, double* y0, double* x1, double* y1, double* xm, double* ym) { typedef agg::conv_transform<PathIterator> transformed_path_t; typedef agg::conv_curve<transformed_path_t> curve_t; double x, y; unsigned code; transformed_path_t tpath(path, trans); curve_t curved_path(tpath); curved_path.rewind(0); while ((code = curved_path.vertex(&x, &y)) != agg::path_cmd_stop) { if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) continue; /* if (MPL_notisfinite64(x) || MPL_notisfinite64(y)) continue; We should not need the above, because the path iterator should already be filtering out invalid values. */ if (x < *x0) *x0 = x; if (y < *y0) *y0 = y; if (x > *x1) *x1 = x; if (y > *y1) *y1 = y; /* xm and ym are the minimum positive values in the data, used by log scaling */ if (x > 0.0 && x < *xm) *xm = x; if (y > 0.0 && y < *ym) *ym = y; } }
std::vector< std::string > file_t::read_dir(const std::string& dir) { DIR* d(nullptr); struct dirent* dent(nullptr); struct dirent* res(nullptr); std::vector< std::string > retval; std::vector< std::string > tmp; std::string tpath(""); signed long nmax(::pathconf(dir.c_str(), _PC_NAME_MAX)); std::size_t len(0); signed int rdret(0); d = ::opendir(dir.c_str()); if (nullptr == d) throw std::runtime_error("Error in ::opendir()"); if (0 > nmax) nmax = 256; len = offsetof(struct dirent, d_name) + nmax + 1; dent = reinterpret_cast< struct dirent* >(new uint8_t[len]); ::memset(dent, 0, len); do { rdret = ::readdir_r(d, dent, &res); if (0 > rdret) throw std::runtime_error("Error in ::readdir_r()"); if (nullptr == res) break; switch (dent->d_type) { case DT_DIR: if (! ::strcmp(dent->d_name, "..") || ! ::strcmp(dent->d_name, ".")) break; tpath = dir + "/" + dent->d_name; tmp = file_t::read_dir(tpath.c_str()); retval.insert(retval.end(), tmp.begin(), tmp.end()); break; case DT_REG: retval.push_back(dir + "/" + dent->d_name); break; default: break; } } while(1); return retval; }
Py::Object _path_module::convert_path_to_polygons(const Py::Tuple& args) { typedef agg::conv_transform<PathIterator> transformed_path_t; typedef SimplifyPath<transformed_path_t> simplify_t; typedef agg::conv_curve<simplify_t> curve_t; typedef std::vector<double> vertices_t; args.verify_length(4); PathIterator path(args[0]); agg::trans_affine trans = py_to_agg_transformation_matrix(args[1], false); double width = Py::Float(args[2]); double height = Py::Float(args[3]); bool simplify = path.should_simplify() && width != 0.0 && height != 0.0; transformed_path_t tpath(path, trans); simplify_t simplified(tpath, false, simplify, width, height); curve_t curve(simplified); Py::List polygons; vertices_t polygon; double x, y; unsigned code; polygon.reserve(path.total_vertices() * 2); while ((code = curve.vertex(&x, &y)) != agg::path_cmd_stop) { if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) { if (polygon.size() >= 2) { polygon.push_back(polygon[0]); polygon.push_back(polygon[1]); _add_polygon(polygons, polygon); } polygon.clear(); } else { if (code == agg::path_cmd_move_to) { _add_polygon(polygons, polygon); polygon.clear(); } polygon.push_back(x); polygon.push_back(y); } } _add_polygon(polygons, polygon); return polygons; }
FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; String tpath( path ); if ( tpath[ tpath.size() - 1 ] == '/' || tpath[ tpath.size() - 1 ] == '\\' ) { tpath += "*"; } else { tpath += "\\*"; } WIN32_FIND_DATAW findFileData; HANDLE hFind = FindFirstFileW( (LPCWSTR)tpath.toWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { std::string name( String( findFileData.cFileName ).toUtf8() ); std::string fpath( path + name ); if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } while( FindNextFileW( hFind, &findFileData ) ) { name = String( findFileData.cFileName ).toUtf8(); fpath = path + name; if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } } FindClose( hFind ); } return files; }
wxFileName CodeLiteDiff::SaveEditorToTmpfile(IEditor* editor) const { wxString content = editor->GetEditorText(); if(content.empty()) { return wxFileName(); // Nothing to diff } wxString tpath(wxFileName::GetTempDir()); tpath << wxFileName::GetPathSeparator() << "CLdiff" << wxFileName::GetPathSeparator(); wxFileName::Mkdir(tpath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); wxFileName tmpFile(wxFileName::CreateTempFileName(tpath + editor->GetFileName().GetName())); if(!tmpFile.IsOk()) { return wxFileName(); } tmpFile.SetExt(editor->GetFileName().GetExt()); wxFFile fp(tmpFile.GetFullPath(), "w+b"); if(fp.IsOpened()) { fp.Write(content); fp.Close(); } else { return wxFileName(); } return tmpFile; }
void TemplateWindow::CheckTemplates(void) { // This checks for the Templates folder in the Paladin application directory // and if it doesn't exist or it's empty, we make sure that it exists and // at least has empty project templates for each of the four basic types of projects DPath templatePath(gAppPath.GetFolder()); templatePath << "Templates"; bool needInit = false; if (!BEntry(templatePath.GetFullPath()).Exists()) needInit = true; if (!needInit) { BDirectory dir(templatePath.GetFullPath()); if (dir.CountEntries() == 0) needInit = true; } if (needInit) { create_directory(templatePath.GetFullPath(),0777); DPath tpath(templatePath); BFile file; BString filedata; tpath.Append("Addon"); create_directory(tpath.GetFullPath(),0777); tpath.Append("TEMPLATEINFO"); file.SetTo(tpath.GetFullPath(), B_READ_WRITE | B_CREATE_FILE); filedata = "TYPE=Shared\n"; file.Write(filedata.String(),filedata.Length()); tpath = templatePath; tpath.Append("Empty Application"); create_directory(tpath.GetFullPath(),0777); tpath.Append("TEMPLATEINFO"); file.SetTo(tpath.GetFullPath(), B_READ_WRITE | B_CREATE_FILE); filedata = "TYPE=Application\n"; file.Write(filedata.String(),filedata.Length()); tpath = templatePath; tpath.Append("Kernel Driver"); create_directory(tpath.GetFullPath(),0777); tpath.Append("TEMPLATEINFO"); file.SetTo(tpath.GetFullPath(), B_READ_WRITE | B_CREATE_FILE); filedata = "TYPE=Driver\n"; file.Write(filedata.String(),filedata.Length()); tpath = templatePath; tpath.Append("Shared Library"); create_directory(tpath.GetFullPath(),0777); tpath.Append("TEMPLATEINFO"); file.SetTo(tpath.GetFullPath(), B_READ_WRITE | B_CREATE_FILE); filedata = "TYPE=Shared\n"; file.Write(filedata.String(),filedata.Length()); tpath = templatePath; tpath.Append("Static Library"); create_directory(tpath.GetFullPath(),0777); tpath.Append("TEMPLATEINFO"); file.SetTo(tpath.GetFullPath(), B_READ_WRITE | B_CREATE_FILE); filedata = "TYPE=Static\n"; file.Write(filedata.String(),filedata.Length()); } }
Py::Object _path_module::convert_to_svg(const Py::Tuple& args) { args.verify_length(5); PathIterator path(args[0]); agg::trans_affine trans = py_to_agg_transformation_matrix(args[1].ptr(), false); Py::Object clip_obj = args[2]; bool do_clip; agg::rect_base<double> clip_rect(0, 0, 0, 0); if (clip_obj.isNone() || !clip_obj.isTrue()) { do_clip = false; } else { double x1, y1, x2, y2; Py::Tuple clip_tuple(clip_obj); x1 = Py::Float(clip_tuple[0]); y1 = Py::Float(clip_tuple[1]); x2 = Py::Float(clip_tuple[2]); y2 = Py::Float(clip_tuple[3]); clip_rect.init(x1, y1, x2, y2); do_clip = true; } bool simplify; Py::Object simplify_obj = args[3]; if (simplify_obj.isNone()) { simplify = path.should_simplify(); } else { simplify = simplify_obj.isTrue(); } int precision = Py::Int(args[4]); #if PY_VERSION_HEX < 0x02070000 char format[64]; snprintf(format, 64, "%s.%dg", "%", precision); #endif typedef agg::conv_transform<PathIterator> transformed_path_t; typedef PathNanRemover<transformed_path_t> nan_removal_t; typedef PathClipper<nan_removal_t> clipped_t; typedef PathSimplifier<clipped_t> simplify_t; transformed_path_t tpath(path, trans); nan_removal_t nan_removed(tpath, true, path.has_curves()); clipped_t clipped(nan_removed, do_clip, clip_rect); simplify_t simplified(clipped, simplify, path.simplify_threshold()); size_t buffersize = path.total_vertices() * (precision + 5) * 4; char* buffer = (char *)malloc(buffersize); char* p = buffer; const char codes[] = {'M', 'L', 'Q', 'C'}; const int waits[] = { 1, 1, 2, 3}; int wait = 0; unsigned code; double x = 0, y = 0; while ((code = simplified.vertex(&x, &y)) != agg::path_cmd_stop) { if (wait == 0) { *p++ = '\n'; if (code == 0x4f) { *p++ = 'z'; *p++ = '\n'; continue; } *p++ = codes[code-1]; wait = waits[code-1]; } else { *p++ = ' '; } #if PY_VERSION_HEX >= 0x02070000 char* str; str = PyOS_double_to_string(x, 'g', precision, 0, NULL); p += snprintf(p, buffersize - (p - buffer), str); PyMem_Free(str); *p++ = ' '; str = PyOS_double_to_string(y, 'g', precision, 0, NULL); p += snprintf(p, buffersize - (p - buffer), str); PyMem_Free(str); #else char str[64]; PyOS_ascii_formatd(str, 64, format, x); p += snprintf(p, buffersize - (p - buffer), str); *p++ = ' '; PyOS_ascii_formatd(str, 64, format, y); p += snprintf(p, buffersize - (p - buffer), str); #endif --wait; } #if PY3K PyObject* result = PyUnicode_FromStringAndSize(buffer, p - buffer); #else PyObject* result = PyString_FromStringAndSize(buffer, p - buffer); #endif free(buffer); return Py::Object(result, true); }
STDMETHODIMP CShellExt::IsMemberOf(LPCWSTR pwszPath, DWORD /*dwAttrib*/) { PreserveChdir preserveChdir; git_wc_status_kind status = git_wc_status_none; bool readonlyoverlay = false; bool lockedoverlay = false; if (pwszPath == NULL) return S_FALSE; const TCHAR* pPath = pwszPath; // the shell sometimes asks overlays for invalid paths, e.g. for network // printers (in that case the path is "0", at least for me here). if (_tcslen(pPath)<2) return S_FALSE; // since the shell calls each and every overlay handler with the same filepath // we use a small 'fast' cache of just one path here. // To make sure that cache expires, clear it as soon as one handler is used. AutoLocker lock(g_csGlobalCOMGuard); if (_tcscmp(pPath, g_filepath.c_str())==0) { status = g_filestatus; readonlyoverlay = g_readonlyoverlay; lockedoverlay = g_lockedoverlay; } else { if (!g_ShellCache.IsPathAllowed(pPath)) { int drivenumber = -1; if ((m_State == FileStateVersioned) && g_ShellCache.ShowExcludedAsNormal() && ((drivenumber=PathGetDriveNumber(pPath))!=0)&&(drivenumber!=1) && PathIsDirectory(pPath) && g_ShellCache.HasSVNAdminDir(pPath, true)) { return S_OK; } return S_FALSE; } switch (g_ShellCache.GetCacheType()) { case ShellCache::exe: { CTGitPath tpath(pPath); if(!tpath.HasAdminDir()) { status = git_wc_status_none; break; } if(tpath.IsAdminDir()) { status = git_wc_status_none; break; } TSVNCacheResponse itemStatus; SecureZeroMemory(&itemStatus, sizeof(itemStatus)); if (m_remoteCacheLink.GetStatusFromRemoteCache(tpath, &itemStatus, true)) { status = GitStatus::GetMoreImportant(itemStatus.m_status.text_status, itemStatus.m_status.prop_status); /* if ((itemStatus.m_kind == git_node_file)&&(status == git_wc_status_normal)&&((itemStatus.m_needslock && itemStatus.m_owner[0]==0)||(itemStatus.m_readonly))) readonlyoverlay = true; if (itemStatus.m_owner[0]!=0) lockedoverlay = true;*/ } } break; case ShellCache::dll: case ShellCache::dllFull: { // Look in our caches for this item const FileStatusCacheEntry * s = m_CachedStatus.GetCachedItem(CTGitPath(pPath)); if (s) { status = s->status; } else { // No cached status available // since the dwAttrib param of the IsMemberOf() function does not // have the SFGAO_FOLDER flag set at all (it's 0 for files and folders!) // we have to check if the path is a folder ourselves :( if (PathIsDirectory(pPath)) { if (g_ShellCache.HasSVNAdminDir(pPath, TRUE)) { if ((!g_ShellCache.IsRecursive()) && (!g_ShellCache.IsFolderOverlay())) { status = git_wc_status_normal; } else { const FileStatusCacheEntry * s = m_CachedStatus.GetFullStatus(CTGitPath(pPath), TRUE); status = s->status; // GitFolderStatus does not list unversioned files/dir so they would always end up as normal below // so let's assume file/dir is unversioned if not found in cache /*// sub-dirs that are empty (or contain no versioned files) are reported as unversioned (and should be kept as such) if (status != git_wc_status_unversioned) { // if get status fails then display status as 'normal' on folder (since it contains .git) // TODO: works for svn since each folder has .svn, not sure if git needs additinoal processing status = GitStatus::GetMoreImportant(git_wc_status_normal, status); }*/ } } else { status = git_wc_status_none; } } else { const FileStatusCacheEntry * s = m_CachedStatus.GetFullStatus(CTGitPath(pPath), FALSE); status = s->status; } } #if 0 if ((s)&&(status == git_wc_status_normal)&&(s->needslock)&&(s->owner[0]==0)) readonlyoverlay = true; if ((s)&&(s->owner[0]!=0)) lockedoverlay = true; #endif } break; default: case ShellCache::none: { // no cache means we only show a 'versioned' overlay on folders // with an admin directory if (PathIsDirectory(pPath)) { if (g_ShellCache.HasSVNAdminDir(pPath, TRUE)) { status = git_wc_status_normal; } else { status = git_wc_status_none; } } else { status = git_wc_status_none; } } break; } ATLTRACE(_T("Status %d for file %s\n"), status, pwszPath); } g_filepath.clear(); g_filepath = pPath; g_filestatus = status; g_readonlyoverlay = readonlyoverlay; g_lockedoverlay = lockedoverlay; //the priority system of the shell doesn't seem to work as expected (or as I expected): //as it seems that if one handler returns S_OK then that handler is used, no matter //if other handlers would return S_OK too (they're never called on my machine!) //So we return S_OK for ONLY ONE handler! switch (status) { // note: we can show other overlays if due to lack of enough free overlay // slots some of our overlays aren't loaded. But we assume that // at least the 'normal' and 'modified' overlay are available. case git_wc_status_none: return S_FALSE; case git_wc_status_unversioned: if (g_ShellCache.ShowUnversionedOverlay() && g_unversionedovlloaded && (m_State == FileStateUnversionedOverlay)) { g_filepath.clear(); return S_OK; } return S_FALSE; case git_wc_status_ignored: if (g_ShellCache.ShowIgnoredOverlay() && g_ignoredovlloaded && (m_State == FileStateIgnoredOverlay)) { g_filepath.clear(); return S_OK; } return S_FALSE; case git_wc_status_normal: case git_wc_status_external: case git_wc_status_incomplete: if ((readonlyoverlay)&&(g_readonlyovlloaded)) { if (m_State == FileStateReadOnly) { g_filepath.clear(); return S_OK; } else return S_FALSE; } else if ((lockedoverlay)&&(g_lockedovlloaded)) { if (m_State == FileStateLockedOverlay) { g_filepath.clear(); return S_OK; } else return S_FALSE; } else if (m_State == FileStateVersioned) { g_filepath.clear(); return S_OK; } else return S_FALSE; case git_wc_status_missing: case git_wc_status_deleted: if (g_deletedovlloaded) { if (m_State == FileStateDeleted) { g_filepath.clear(); return S_OK; } else return S_FALSE; } else { // the 'deleted' overlay isn't available (due to lack of enough // overlay slots). So just show the 'modified' overlay instead. if (m_State == FileStateModified) { g_filepath.clear(); return S_OK; } else return S_FALSE; } case git_wc_status_replaced: case git_wc_status_modified: if (m_State == FileStateModified) { g_filepath.clear(); return S_OK; } else return S_FALSE; case git_wc_status_merged: if (m_State == FileStateReadOnly) { g_filepath.clear(); return S_OK; } else return S_FALSE; case git_wc_status_added: if (g_addedovlloaded) { if (m_State== FileStateAddedOverlay) { g_filepath.clear(); return S_OK; } else return S_FALSE; } else { // the 'added' overlay isn't available (due to lack of enough // overlay slots). So just show the 'modified' overlay instead. if (m_State == FileStateModified) { g_filepath.clear(); return S_OK; } else return S_FALSE; } case git_wc_status_conflicted: case git_wc_status_obstructed: if (g_conflictedovlloaded) { if (m_State == FileStateConflict) { g_filepath.clear(); return S_OK; } else return S_FALSE; } else { // the 'conflicted' overlay isn't available (due to lack of enough // overlay slots). So just show the 'modified' overlay instead. if (m_State == FileStateModified) { g_filepath.clear(); return S_OK; } else return S_FALSE; } default: return S_FALSE; } // switch (status) //return S_FALSE; }
FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) { FileInfoMap files; #ifdef EFSW_COMPILER_MSVC #ifdef UNICODE /// Unicode support just for this? MMHH... String tpath( String::fromUtf8( path ) ); if ( tpath[ tpath.size() - 1 ] == '/' || tpath[ tpath.size() - 1 ] == '\\' ) { tpath += "*"; } else { tpath += "\\*"; } WIN32_FIND_DATA findFileData; HANDLE hFind = FindFirstFile( (LPCWSTR)tpath.toWideString().c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { String name( findFileData.cFileName ); std::string fpath( path + name.toUtf8() ); if ( name != "." && name != ".." ) { files[ name.toUtf8() ] = FileInfo( fpath ); } while( FindNextFile(hFind, &findFileData ) ) { name = String( findFileData.cFileName ); fpath = path + name.toUtf8(); if ( name != "." && name != ".." ) { files[ name.toUtf8() ] = FileInfo( fpath ); } } FindClose( hFind ); } #else std::string tpath( path ); if ( tpath[ tpath.size() - 1 ] == '/' || tpath[ tpath.size() - 1 ] == '\\' ) { tpath += "*"; } else { tpath += "\\*"; } WIN32_FIND_DATA findFileData; HANDLE hFind = FindFirstFile( (LPCTSTR) tpath.c_str(), &findFileData ); if( hFind != INVALID_HANDLE_VALUE ) { std::string name( findFileData.cFileName ); std::string fpath( path + name ); if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } while( FindNextFile(hFind, &findFileData ) ) { name = std::string( findFileData.cFileName ); fpath = path + name; if ( name != "." && name != ".." ) { files[ name ] = FileInfo( fpath ); } } FindClose( hFind ); } #endif return files; #else DIR *dp; struct dirent *dirp; if( ( dp = opendir( path.c_str() ) ) == NULL) return files; while ( ( dirp = readdir(dp) ) != NULL) { if ( strcmp( dirp->d_name, ".." ) != 0 && strcmp( dirp->d_name, "." ) != 0 ) { std::string name( dirp->d_name ); std::string fpath( path + name ); files[ name ] = FileInfo( fpath ); } } closedir(dp); return files; #endif }