VarItem *VarItem::CreateFloat(const char *aPath, float aValue, float aMinimum, float aMaximum) { if (VarItem *item = Database::varitem.Get(Hash(aPath))) return item; unsigned int id = BuildPath(aPath); VarFloat *item = new VarFloat(id, aValue, aMinimum, aMaximum); Database::varitem.Put(id, item); return item; }
VarItem *VarItem::CreateString(const char *aPath, std::string aValue) { if (VarItem *item = Database::varitem.Get(Hash(aPath))) return item; unsigned int id = BuildPath(aPath); VarString *item = new VarString(id, aValue); Database::varitem.Put(id, item); return item; }
DEF_FUZZ(Pathop, fuzz) { SkOpBuilder builder; uint8_t stragglerOp; fuzz->next(&stragglerOp); SkPath path; BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb); builder.add(path, static_cast<SkPathOp>(stragglerOp % (kLastOp + 1))); SkPath result; builder.resolve(&result); }
ScreenRuler::ScreenRuler(QWidget *parent) : QMainWindow(parent, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint), m_leftMouseButtonPressed(false), m_horDotsPerCM(44), m_verDotsPerCM(44), m_bHorizontalRuler(false) { UpdateDisplayPixelsPerCM(); ResizeRuler(); BuildPath(); }
void cPath::AttemptToFindAlternative() { if (m_NearestPointToTarget == GetCell(m_Source)) { FinishCalculation(ePathFinderStatus::PATH_NOT_FOUND); } else { m_Destination = m_NearestPointToTarget->m_Location; BuildPath(); FinishCalculation(ePathFinderStatus::NEARBY_FOUND); } }
//高位钻孔参数报告 static void DealIntListDatas( const CString& field, CString& data ) { CString dataDirName = _T( "Datas\\" ); CString fileName; fileName =BuildPath ( BuildPath( GetAppPathDir(), dataDirName ),_T( "瓦斯抽采-字符串-整数列表.txt" ) ); AcIfstream inFile( fileName ); while(!inFile.eof()) { ACHAR cIntIdx[_MAX_PATH], cFiled[_MAX_PATH],cData[_MAX_PATH]; inFile >> cFiled >> cIntIdx >> cData; if(inFile.fail()) break; CString strIdx,strF; strIdx.Format(_T("%s"),cIntIdx); strF.Format(_T("%s"),cFiled); if(field == strF && data == strIdx) { data.Format(_T("%s"),cData); //acutPrintf(_T("\n字段:%s\t整数索引:%s\t对应值:%s\n"),field,strIdx,data); } } inFile.close(); }
void ScreenRuler::mousePressEvent(QMouseEvent* event) { if (Qt::LeftButton == event->button()) { m_leftMouseButtonPressed = true; m_originMouseGloblePos = event->globalPos(); m_originWidgetPos = pos(); } else if (Qt::RightButton == event->button()) { m_bHorizontalRuler = !m_bHorizontalRuler; ResizeRuler(); BuildPath(); update(); } }
DEF_FUZZ(PathMeasure, fuzz) { uint8_t bits; fuzz->next(&bits); SkScalar distance[6]; for (auto index = 0; index < 6; ++index) { fuzz->next(&distance[index]); } SkPath path; BuildPath(fuzz, &path, SkPath::Verb::kDone_Verb); SkRect bounds = path.getBounds(); SkScalar maxDim = SkTMax(bounds.width(), bounds.height()); SkScalar resScale = maxDim / 1000; SkPathMeasure measure(path, bits & 1, resScale); SkPoint position; SkVector tangent; ignoreResult(measure.getPosTan(distance[0], &position, &tangent)); SkPath dst; ignoreResult(measure.getSegment(distance[1], distance[2], &dst, (bits >> 1) & 1)); ignoreResult(measure.nextContour()); ignoreResult(measure.getPosTan(distance[3], &position, &tangent)); ignoreResult(measure.getSegment(distance[4], distance[5], &dst, (bits >> 2) & 1)); }
int main(void){ int i,j; int path[NMAX],nr_nodes,found,first,d; FILE* input = fopen("input.txt","r"); fscanf(input,"%d",&n); for(i=0;i<=n-1;i++) for(j=0;j<=n-1;j++){ fscanf(input,"%d",&capacity[i][j]); flow[i][j]=0; } printf("Source node: ");scanf("%d",&s); printf("Sink node: ");scanf("%d",&t); maximum_flow = 0; do{ //calculates the rezidual graphic for(i=0;i<n;i++) for(j=0;j<n;j++) rezidual_flow[i][j] = capacity[i][j] - flow[i][j]; BuildPath(path,&nr_nodes,&found); if(!found) break; first = 1; d=0; for(i=0;i<nr_nodes-1;i++) if(first || d>rezidual_flow[path[i]][path[i+1]]){ first = 0; d = rezidual_flow[path[i]][path[i+1]]; }//end if maximum_flow += d; for(i=0;i<nr_nodes-1;i++) flow[path[i]][path[i+1]] += d; }while(1);//end do printf("\nThe Maximum Flow is: %d \n",maximum_flow); //system("pause"); return 0; }
void PathDecomposer::FindClosedPaths(TracingContext& ctx) { ctx.paths.clear(); image_size_t height = ctx.potraceImg.GetH(); image_size_t width = ctx.potraceImg.GetW(); for (image_size_t y = 0; y < height; ++y) { for (image_size_t x = 0; x < width; ++x) { if (ctx.potraceImg.RB(x, y) == PixelColor::Black) { PotracePath path(ctx.potraceImg.IsInvertedRB(x, y)); path.AddPoint(x, y); path.AddPoint(x, y + 1); //going to the bottom edge of the pixel BuildPath(ctx.potraceImg, path); vector<Point2> interiorPoints = path.GetInteriorPoints(); ctx.potraceImg.InvertPixels(interiorPoints); if (ctx.opts.despecklingPixels == 0 || interiorPoints.size() > ctx.opts.despecklingPixels) { ctx.paths.push_back(path); } } } } }
HRESULT _stdcall CMyTreeView::Drop(IDataObject *pDataObject,DWORD grfKeyState, POINTL pt,DWORD *pdwEffect) { TVHITTESTINFO tvht; LPITEMIDLIST pidlDirectory = NULL; TCHAR szDestDirectory[MAX_PATH + 1]; KillTimer(m_hTreeView,DRAGEXPAND_TIMER_ID); tvht.pt.x = pt.x; tvht.pt.y = pt.y; ScreenToClient(m_hTreeView,(LPPOINT)&tvht.pt); TreeView_HitTest(m_hTreeView,&tvht); /* Is the mouse actually over an item? */ if(!(tvht.flags & LVHT_NOWHERE) && (tvht.hItem != NULL) && m_bDataAccept) { pidlDirectory = BuildPath(tvht.hItem); GetDisplayName(pidlDirectory,szDestDirectory,SIZEOF_ARRAY(szDestDirectory),SHGDN_FORPARSING); CDropHandler *pDropHandler = CDropHandler::CreateNew(); pDropHandler->Drop(pDataObject, grfKeyState,pt,pdwEffect,m_hTreeView, m_DragType,szDestDirectory,NULL,FALSE); pDropHandler->Release(); CoTaskMemFree(pidlDirectory); } RestoreState(); m_pDropTargetHelper->Drop(pDataObject,(POINT *)&pt,*pdwEffect); return S_OK; }
ezResult ezImageConversion::Convert(const ezImageView& source, ezImage& target, ezImageFormat::Enum targetFormat) { ezImageFormat::Enum sourceFormat = source.GetImageFormat(); // Trivial copy if (sourceFormat == targetFormat) { if (&source != &target) { // copy if not already the same target.ResetAndCopy(source); } return EZ_SUCCESS; } ezHybridArray<ConversionPathNode, 16> path; ezUInt32 numScratchBuffers = 0; if (BuildPath(sourceFormat, targetFormat, &source == &target, path, numScratchBuffers).Failed()) { return EZ_FAILURE; } return Convert(source, target, path, numScratchBuffers); }
SPECIALURLTYPE TransformUrl(wxString&Url) { SPECIALURLTYPE ut = GetSpecialUrlType(Url); const wxString location = Url.Mid(ut & 0x0F); const wxString exePath = wxPathOnly(wxStandardPaths::Get().GetExecutablePath()); if (SUT_BIN == ut) { #ifdef __WXMSW__ Url = BuildPath(exePath, location) + wxT(".exe"); if (!PathExists(Url)) Url = BuildPath(exePath, wxT("Bin"), location) + wxT(".exe"); #else Url = BuildPath(exePath, location); #endif } else if (SUT_DOC == ut) { #ifdef __WXMSW__ wxString path = BuildPath(exePath, location); #else wxString path = BuildPath(wxT(PREFIX_DOC), location); #endif if ((!CanOpenChm() || !wxFileExists(path)) && 0 == location.CmpNoCase(wxT("NSIS.chm"))) { path = BuildPath(wxPathOnly(path), wxT("Docs"), wxT("Manual.html")); // DOCTYPES=htmlsingle if (!wxFileExists(path)) path = BuildPath(wxPathOnly(path), wxT("Contents.html")); // DOCTYPES=html (Not adding /Docs/ because it has already been appended) } Url = path; } else if (SUT_WEB == ut) { Url = location; } return ut; }
void vmsFileUtil::BuildPathToFile(LPCSTR pszPathName) { BuildPath (GetPathFromPathName (pszPathName)); }
void CSettingTypeRelativePath::Save(int /*Index*/, const char * Value) { m_Directory = ""; m_FileName = Value; BuildPath(); }
int _tmain(int argc, _TCHAR* argv[]) { string strSkinPath; //皮肤路径,相对于程序的.rc文件 vector<string> vecIdMaps; string strRes; //rc2文件名 string strHead; //资源头文件,如winres.h string strName2ID; //名字-ID映射表XML char cYes=0; //强制改写标志 int c; printf("%s\n",GetCommandLineA()); while ((c = getopt(argc, argv, _T("i:r:h:n:y:p:"))) != EOF) { switch (c) { case _T('i'):vecIdMaps.push_back(optarg);break; case _T('r'):strRes=optarg;break; case _T('h'):strHead=optarg;break; case _T('n'):strName2ID=optarg;break; case _T('y'):cYes=1;optind--;break; case _T('p'):strSkinPath=optarg;break; } } if(vecIdMaps.size()==0 && strName2ID.length()==0) { printf("error: not specify valid idmap file\n"); return 3; } if(strName2ID.length() && vecIdMaps.size()) {//自动更新name2id表 TiXmlDocument xmlName2ID; xmlName2ID.LoadFile(strName2ID.c_str()); map<string,int> mapNamedID; TiXmlElement *pXmlName2ID=xmlName2ID.FirstChildElement("name2id"); int nCurID=ID_AUTO_START; while(pXmlName2ID) { string strName=pXmlName2ID->Attribute("name"); int uID=0; pXmlName2ID->Attribute("id",&uID); mapNamedID[strName]=uID; if(uID>nCurID) nCurID=uID; //获得当前的最大ID pXmlName2ID=pXmlName2ID->NextSiblingElement("name2id"); } int nNewNamedID=0; for(vector<string>::iterator it=vecIdMaps.begin();it!=vecIdMaps.end();it++) { TiXmlDocument xmlDocIdMap; xmlDocIdMap.LoadFile(it->c_str()); TiXmlElement *pXmlIdmap=xmlDocIdMap.FirstChildElement("resid"); while(pXmlIdmap) { int layer=0; pXmlIdmap->Attribute("layer",&layer); if(layer && _stricmp(pXmlIdmap->Attribute("type"),"xml")==0) { string strXmlLayer=pXmlIdmap->Attribute("file"); if(!strSkinPath.empty()) strXmlLayer=strSkinPath+"\\"+strXmlLayer; if(strXmlLayer.length()) {//找到一个窗口描述XML TiXmlDocument xmlDocLayer; xmlDocLayer.LoadFile(strXmlLayer.c_str()); nNewNamedID+=UpdateName2ID(&mapNamedID,&xmlName2ID,xmlDocLayer.RootElement(),nCurID); } } pXmlIdmap=pXmlIdmap->NextSiblingElement("resid"); } } if(nNewNamedID) {//有新的命名控件加入,更新Name2ID表 FILE *f=fopen(strName2ID.c_str(),"w"); if(f) { xmlName2ID.Print(f); fclose(f); } } } __time64_t fs1=0; __time64_t fs2=0; string strTimeStamp; FILE *fts=NULL; if(vecIdMaps.size()) { //check modify flag strTimeStamp=strRes+".ts"; FILE *fts=fopen(strTimeStamp.c_str(),"r+b"); if(fts) { fread(&fs1,1,sizeof(fs1),fts); fclose(fts); } vector<string>::iterator it=vecIdMaps.begin(); while(it!=vecIdMaps.end()) { fs2+=GetLastWriteTime(it->c_str()); it++; } //build xml id map if(fs1==fs2 || vecIdMaps.size()==0) { if(vecIdMaps.size()) printf("idmap files have not been modified.\n"); }else { DWORD dwAttr=GetFileAttributesA(strRes.c_str()); if(dwAttr & FILE_ATTRIBUTE_READONLY) { if(!cYes) { printf("error: resource file is readonly. set -y to make sure to do it.\n"); return 2; } SetFileAttributesA(strRes.c_str(),dwAttr&~FILE_ATTRIBUTE_READONLY); } fts=fopen(strTimeStamp.c_str(),"wb"); if(fts) {//record time stamp fwrite(&fs2,1,sizeof(fs2),fts); fclose(fts); } vector<IDMAPRECORD> vecIdMapRecord; //load xml description of resource to vector vector<string>::iterator it=vecIdMaps.begin(); while(it!=vecIdMaps.end()) { TiXmlDocument xmlDoc; if(xmlDoc.LoadFile(it->c_str())) { TiXmlElement *xmlEle=xmlDoc.RootElement(); while(xmlEle) { if(strcmp(xmlEle->Value(),"resid")==0) { IDMAPRECORD rec={0}; const char *pszValue; pszValue=xmlEle->Attribute("type"); if(pszValue) MultiByteToWideChar(CP_UTF8,0,pszValue,-1,rec.szType,100); pszValue=xmlEle->Attribute("id"); if(pszValue) rec.nID=atoi(pszValue); pszValue=xmlEle->Attribute("id_name"); if(pszValue) MultiByteToWideChar(CP_UTF8,0,pszValue,-1,rec.szID,200); pszValue=xmlEle->Attribute("file"); if(pszValue) { string str; if(!strSkinPath.empty()){ str=strSkinPath+"\\"+pszValue;} else str=pszValue; MultiByteToWideChar(CP_UTF8,0,str.c_str(),str.length(),rec.szPath,MAX_PATH); } if(rec.szType[0] && rec.nID && rec.szPath[0]) { if(rec.szID[0]==0) swprintf(rec.szID,L"IDC_%s_%d",rec.szType,rec.nID); vecIdMapRecord.push_back(rec); } } xmlEle=xmlEle->NextSiblingElement(); } } it++; } //build output string by wide char wstring strOut; strOut+=RB_HEADER_W; strOut+=L"\n"; vector<IDMAPRECORD>::iterator it2=vecIdMapRecord.begin(); while(it2!=vecIdMapRecord.end()) { WCHAR szRec[2000]; wstring strFile=BuildPath(it2->szPath); swprintf(szRec,L"DEFINE_%s(%s,\t%d,\t\"%s\")\n",it2->szType,it2->szID,it2->nID,strFile.c_str()); strOut+=szRec; it2++; } strOut+=RB_TAILOR_W; //write output string to target res file FILE * f=fopen(strRes.c_str(),"r+b"); if(f) { BYTE szFlag[2]={0}; int nReaded=fread(szFlag,1,2,f); if(nReaded==2 && szFlag[0]==0xFF && szFlag[1]==0xFE)//detect utf32 { InsertBlockToFileW(f,strOut); }else {//multibyte int nLen=WideCharToMultiByte(CP_ACP,0,strOut.c_str(),strOut.length(),NULL,0,NULL,NULL); char *pBuf=new char[nLen+1]; WideCharToMultiByte(CP_ACP,0,strOut.c_str(),strOut.length(),pBuf,nLen,NULL,NULL); pBuf[nLen]=0; fseek(f,0,SEEK_SET); InsertBlockToFileA(f,pBuf); delete []pBuf; } fclose(f); } printf("build resouce successed!\n"); } } //build resource head if(strName2ID.length()) { fs1=0; strTimeStamp=strHead+".ts"; fts=fopen(strTimeStamp.c_str(),"rb"); if(fts) { fread(&fs1,sizeof(__time64_t),1,fts); fclose(fts); } fs2=GetLastWriteTime(strName2ID.c_str()); if(fs1==fs2 || strName2ID.length()==0) { if(strName2ID.length()) printf("name2id xml descriptor is not changed!\n"); }else { DWORD dwAttr=GetFileAttributesA(strHead.c_str()); if(dwAttr & FILE_ATTRIBUTE_READONLY) { if(!cYes) { printf("error: head file is readonly. set -y to make sure to do it.\n"); return 2; } SetFileAttributesA(strHead.c_str(),dwAttr&~FILE_ATTRIBUTE_READONLY); } fts=fopen(strTimeStamp.c_str(),"wb"); if(fts) {//record time stamp fwrite(&fs2,1,sizeof(fs2),fts); fclose(fts); } vector<NAME2IDRECORD> vecName2ID; //load xml description of resource to vector TiXmlDocument xmlDoc; if(xmlDoc.LoadFile(strName2ID.c_str())) { TiXmlElement *xmlEle=xmlDoc.RootElement(); while(xmlEle) { if(strcmp(xmlEle->Value(),"name2id")==0) { NAME2IDRECORD rec={0}; const char *pszValue; pszValue=xmlEle->Attribute("name"); if(pszValue) MultiByteToWideChar(CP_UTF8,0,pszValue,-1,rec.szName,100); pszValue=xmlEle->Attribute("id"); if(pszValue) rec.nID=atoi(pszValue); pszValue=xmlEle->Attribute("remark"); if(pszValue) MultiByteToWideChar(CP_UTF8,0,pszValue,-1,rec.szRemark,300); if(rec.szName[0] && rec.nID) vecName2ID.push_back(rec); } xmlEle=xmlEle->NextSiblingElement(); } } //build output string by wide char wstring strOut; strOut+=RB_HEADER_W; strOut+=L"\n"; vector<NAME2IDRECORD>::iterator it2=vecName2ID.begin(); while(it2!=vecName2ID.end()) { WCHAR szRec[2000]; if(it2->szRemark[0]) swprintf(szRec,L"#define\t%s\t\t%d \t//%s\n",it2->szName,it2->nID,it2->szRemark); else swprintf(szRec,L"#define\t%s\t\t%d\n",it2->szName,it2->nID); strOut+=szRec; it2++; } strOut+=RB_TAILOR_W; //write output string to target res file FILE * f=fopen(strHead.c_str(),"r+b"); if(f) { BYTE szFlag[2]={0}; int nReaded=fread(szFlag,1,2,f); if(nReaded==2 && szFlag[0]==0xFF && szFlag[1]==0xFE)//detect utf32 { InsertBlockToFileW(f,strOut); }else {//multibyte int nLen=WideCharToMultiByte(CP_ACP,0,strOut.c_str(),strOut.length(),NULL,0,NULL,NULL); char *pBuf=new char[nLen+1]; WideCharToMultiByte(CP_ACP,0,strOut.c_str(),strOut.length(),pBuf,nLen,NULL,NULL); pBuf[nLen]=0; fseek(f,0,SEEK_SET); InsertBlockToFileA(f,pBuf); delete []pBuf; } fclose(f); } printf("build header file successed!\n"); } } return 0; }
UBool PathFinder::Flee(const ULong & flags, const ULong & f, const EERIE_3D & danger, const Float & safe_dist, SLong * rstep, UWord ** rlist) { MINOSNode * node, *child; long _from; //Init open and close lists Clean(); if (!rlist || !rstep) return UFALSE; if (Distance(map_d[f].pos, danger) >= safe_dist) { *rlist = (UWord *)malloc(sizeof(UWord)); ** rlist = (UWord)f; *rstep = 1; return UTRUE; } _from = f; //Create start node and put it on open list if (!(node = CreateNode(_from, NULL))) { Clean(); *rstep = 0; return UFALSE; } node->g_cost = 0; if (flags & MINOS_STEALTH) AddEnlightmentCost(node); node->f_cost = safe_dist - Distance(map_d[_from].pos, danger); if (node->f_cost < 0.0F) node->f_cost = 0.0F; node->f_cost += node->g_cost; if (open.Append(node)) { free(node); Clean(); *rstep = 0; return UFALSE; } //A* main loop while (node = GetBestNode()) { //If it's the goal node then we've done if (Distance(map_d[node->data].pos, danger) >= safe_dist) { if (close.Append(node)) { free(node); *rstep = 0; return UFALSE; } //BuildPath(rlist, rstep); if (BuildPath(rlist, rstep)) { Clean(); *rstep = 0; return UFALSE; } Clean(); return UTRUE; } //Otherwise, generate child from current node long _pipo = node->data; for (SWord i(0); i < map_d[_pipo].nblinked; i++) { child = CreateNode(map_d[_pipo].linked[i], node); if (!child) { free(node); Clean(); *rstep = 0; return UFALSE; } //Cost to reach this node if ((map_d[child->data].flags & ANCHOR_FLAG_BLOCKED) || map_d[child->data].height > height || map_d[child->data].radius < radius) free(child); else { child->g_cost = node->g_cost + Distance(map_d[child->data].pos, map_d[node->data].pos); if (flags & MINOS_STEALTH) AddEnlightmentCost(child); if (Check(child)) { Float dist; if (open.Append(child)) { free(node); free(child); *rstep = 0; return UFALSE; } //Get total cost for this node child->f_cost = child->g_cost; dist = Distance(map_d[child->data].pos, danger); if ((dist = safe_dist - dist) > 0.0F) child->f_cost += fac5 * dist; } else free(child); } } //Put node onto close list as we have now examined this node if (close.Append(node)) { free(node); Clean(); *rstep = 0; return UFALSE; } } Clean(); *rstep = 0; //No path found!!! return UFALSE; }
/////////////////////////////////////////////////////////////////////////////// // // // Methods // // // /////////////////////////////////////////////////////////////////////////////// UBool PathFinder::Move(const ULong & flags, const ULong & f, const ULong & t, SLong * rstep, UWord ** rlist) { MINOSNode * node, *child; long _from, _to; //Init open and close lists Clean(); if (!rlist || !rstep) return UFALSE; if (f == t) { *rlist = (UWord *)malloc(sizeof(UWord)); ** rlist = (UWord)t; *rstep = 1; return UTRUE; } _from = f, _to = t; //Create start node and put it on open list if (!(node = CreateNode(_from, NULL))) { Clean(); // Cyril *rstep = 0; return UFALSE; } node->g_cost = 0; node->f_cost = Distance(map_d[_from].pos, map_d[_to].pos); if (flags & MINOS_STEALTH) AddEnlightmentCost(node); if (open.Append(node)) { free(node); Clean(); // Cyril *rstep = 0; return UFALSE; } //A* main loop while (node = GetBestNode()) { //If it's the goal node then we've done if (node->data == _to) { if (close.Append(node)) { free(node); Clean(); *rstep = 0; return UFALSE; } if (BuildPath(rlist, rstep)) { Clean(); *rstep = 0; return UFALSE; } Clean(); // Cyril return UTRUE; } //Otherwise, generate child from current node long _pipo(node->data); for (SWord i(0); i < map_d[_pipo].nblinked; i++) { //Create new child child = CreateNode(map_d[_pipo].linked[i], node); if (!child) { free(node); Clean(); // Cyril *rstep = 0; return UFALSE; } //Cost to reach this node if ((map_d[child->data].flags & ANCHOR_FLAG_BLOCKED) || map_d[child->data].height > height || map_d[child->data].radius < radius) free(child); else { child->g_cost = node->g_cost + Distance(map_d[child->data].pos, map_d[node->data].pos); if (flags & MINOS_STEALTH) AddEnlightmentCost(child); if (Check(child)) { if (open.Append(child)) { free(node); free(child); *rstep = 0; return UFALSE; } //Get total cost for this node child->f_cost = heuristic * child->g_cost + (1.0F - heuristic) * Distance(map_d[child->data].pos, map_d[_to].pos); } else free(child); } } //Put node onto close list as we have now examined this node if (close.Append(node)) { free(node); Clean(); // Cyril *rstep = 0; return UFALSE; } } //No path found!!! Clean(); *rstep = 0; return UFALSE; }
template<class A, class B, class C> wxString BuildPath(const A&a, const B&b, const C&c) { return BuildPath(BuildPath(GetCStr(a), GetCStr(b)), GetCStr(c)); }
HRESULT LTEffectInclude::Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes ) { if(pFileName[0] == '\0') { return E_FAIL; } if(PushPath(pFileName) == false) { *ppData = NULL; *pBytes = 0; return E_FAIL; } char szFilename[_MAX_PATH]; BuildPath(szFilename, pFileName, _MAX_PATH); intptr_t hFile; struct _finddata_t file; int nFileSize = 0; if( (hFile = _findfirst( szFilename, &file )) != -1L ) { nFileSize = (int)file.size; } else { return E_FAIL; } uint8* pData = new uint8[nFileSize]; memset(pData, 0, nFileSize); if(pData == NULL) { return E_OUTOFMEMORY; } #ifdef _DEBUG // Output our include solver tree... char szDepth[_MAX_PATH]; memset(szDepth, 0, _MAX_PATH); for(int k = 0; k < (int)m_PathList.size(); ++k) { szDepth[k] = '\t'; } char szDebugBuf[_MAX_PATH]; sprintf(szDebugBuf, "%s: %s%s size: (%d)\n", ((int)m_PathList.size() <= 1) ? "Solving" : "Including", szDepth, szFilename, nFileSize); OutputDebugString(szDebugBuf); #endif FILE *fp = fopen(szFilename, "rb"); if(!fp) { delete [] pData; *ppData = NULL; *pBytes = 0; return E_FAIL; } fread(pData, nFileSize, 1, fp); fclose(fp); //pData[nFileSize] = '\0'; *ppData = pData; *pBytes = nFileSize;//+1; return S_OK; }
void TransTableS::BuildSOP( const unsigned short ourWinRanks[DDS_SUITS], const unsigned short aggrArg[DDS_SUITS], const nodeCardsType& first, const long long lengths, const int tricks, const int firstHand, const bool flag) { int winMask[DDS_SUITS]; int winOrderSet[DDS_SUITS]; char low[DDS_SUITS]; for (int ss = 0; ss < DDS_SUITS; ss++) { int w = ourWinRanks[ss]; if (w == 0) { winMask[ss] = 0; winOrderSet[ss] = 0; low[ss] = 15; } else { w = w & (-w); /* Only lowest win */ const unsigned short temp = static_cast<unsigned short>(aggrArg[ss] & (-w)); winMask[ss] = aggp[temp].winMask[ss]; winOrderSet[ss] = aggp[temp].aggrRanks[ss]; low[ss] = static_cast<char>(TTlowestRank[temp]); } } bool res; posSearchTypeSmall * np = SearchLenAndInsert( rootnp[tricks][firstHand], lengths, true, tricks, firstHand, res); nodeCardsType * cardsP = BuildPath( winMask, winOrderSet, static_cast<int>(first.ubound), static_cast<int>(first.lbound), static_cast<char>(first.bestMoveSuit), static_cast<char>(first.bestMoveRank), np, res); if (res) { cardsP->ubound = static_cast<char>(first.ubound); cardsP->lbound = static_cast<char>(first.lbound); if (flag) { cardsP->bestMoveSuit = static_cast<char>(first.bestMoveSuit); cardsP->bestMoveRank = static_cast<char>(first.bestMoveRank); } else { cardsP->bestMoveSuit = 0; cardsP->bestMoveRank = 0; } for (int k = 0; k < DDS_SUITS; k++) cardsP->leastWin[k] = 15 - low[k]; } }
void ThumbCacheEnumerate(int level) { LPTCHEADER ptchdr; LPTCENTRY ptcent; unsigned char *thumbdata; unsigned int pos; gdImagePtr thumb; int nentries = 0, ndelentries = 0; if (!ThumbCacheBurstReadBegin(0)) { fprintf(stderr, "ERROR: failed to open cache for mapping\n"); return; } if (level >= TC_DUMP_IMGS) { if (!outpath[0]) { fprintf(stderr, "ERROR: must specify an output path\n"); return; } if (createdir(outpath) == -1 && errno != EEXIST) { perror("mkdir"); return; } if (chdir(outpath) == -1) { perror("chdir"); return; } } ptchdr = (LPTCHEADER)cachemap.addr; if (level >= TC_DUMP_INFO) { printf("Directory last modified: %s" "Thumb cache entries:\n" "file " "thumb key\tthumb len\tlast modified\n", asctime(localtime(&ptchdr->lastupdate))); } pos = sizeof(TCHEADER); while (pos < cachemap.maplen) { ptcent = (LPTCENTRY)((char *)cachemap.addr + pos); if (ptcent->mtime != TC_MTIME_DELETED) { if (level >= TC_DUMP_INFO) { printf("%-26s%f\t%d\t%s", ptcent->filename, ptcent->thumbkey, ptcent->thumbfsize, asctime(localtime(&ptcent->mtime))); } if (level >= TC_DUMP_IMGS) { thumbdata = (unsigned char *)ptcent + sizeof(TCENTRY) + ptcent->fnlen + 1; thumb = gdImageCreateFromPngPtr(ptcent->thumbfsize, thumbdata); if (!thumb) { fprintf(stderr, "ERROR: failed to create image from thumbcache\n"); continue; } if (!ImgSavePng(ptcent->filename, thumb)) { if (errno == ENOENT) { if (verbose) printf("creating directory structure for %s\n", ptcent->filename); if (!BuildPath(ptcent->filename)) { fprintf(stderr, "ERROR: failed to build " "directory to %s\n", ptcent->filename); gdImageDestroy(thumb); continue; } if (!ImgSavePng(ptcent->filename, thumb)) { fprintf(stderr, "ERROR: failed to save %s after " "building directory\n", ptcent->filename); gdImageDestroy(thumb); continue; } } else { fprintf(stderr, "ERROR: failed to save %s\n", ptcent->filename); gdImageDestroy(thumb); continue; } } gdImageDestroy(thumb); } nentries++; } else { ndelentries++; } pos += sizeof(TCENTRY) + ptcent->fnlen + 1 + ptcent->thumbfsize; } if (level >= TC_DUMP_IMGS && chdir(workdir) == -1) { perror("chdir"); return; } printf("Number of thumb cache entries: %d\n" "Number of deleted thumb cache entries: %d\n", nentries, ndelentries); ThumbCacheBurstReadEnd(); }
bool cPath::StepOnce() { cPathCell * CurrentCell = OpenListPop(); // Path not reachable. if (CurrentCell == nullptr) { AttemptToFindAlternative(); return true; } // Path found. if (CurrentCell->m_Location == m_Destination) { BuildPath(); FinishCalculation(ePathFinderStatus::PATH_FOUND); return true; } // Calculation not finished yet // Check if we have a new NearestPoint. if ((m_Destination - CurrentCell->m_Location).Length() < 5) { if (m_Rand.NextInt(4) == 0) { m_NearestPointToTarget = CurrentCell; } } else if (CurrentCell->m_H < m_NearestPointToTarget->m_H) { m_NearestPointToTarget = CurrentCell; } // process a currentCell by inspecting all neighbors. // Now we start checking adjacent cells. // If true, no need to do more checks in that direction bool DoneEast = false, DoneWest = false, DoneNorth = false, DoneSouth = false; // If true, we can walk in that direction without changing height // This is used for deciding if to calculate diagonals bool WalkableEast = false, WalkableWest = false, WalkableNorth = false, WalkableSouth = false; // If we can jump without hitting the ceiling if (BodyFitsIn(CurrentCell->m_Location + Vector3i(0, 1, 0), CurrentCell->m_Location)) { // For ladder climbing ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, 0), CurrentCell, JUMP_G_COST); // Check east-up if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, 1, 0), CurrentCell, JUMP_G_COST)) { DoneEast = true; } // Check west-up if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, 1, 0), CurrentCell, JUMP_G_COST)) { DoneWest = true; } // Check north-up if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, -1), CurrentCell, JUMP_G_COST)) { DoneNorth = true; } // Check south-up if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, 1), CurrentCell, JUMP_G_COST)) { DoneSouth = true; } } // Check North, South, East, West at our own height or below. We are willing to jump up to 3 blocks down. if (!DoneEast) { for (int y = 0; y >= -3; --y) { if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, y, 0), CurrentCell, NORMAL_G_COST)) { DoneEast = true; if (y == 0) { WalkableEast = true; } break; } } } if (!DoneWest) { for (int y = 0; y >= -3; --y) { if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, y, 0), CurrentCell, NORMAL_G_COST)) { DoneWest = true; if (y == 0) { WalkableWest = true; } break; } } } if (!DoneSouth) { for (int y = 0; y >= -3; --y) { if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, 1), CurrentCell, NORMAL_G_COST)) { DoneWest = true; if (y == 0) { WalkableSouth = true; } break; } } } if (!DoneNorth) { for (int y = 0; y >= -3; --y) { if (ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, y, -1), CurrentCell, NORMAL_G_COST)) { DoneNorth = true; if (y == 0) { WalkableNorth = true; } break; } } } // Check diagonals if (WalkableNorth && WalkableEast) { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, 0, -1), CurrentCell, DIAGONAL_G_COST); } if (WalkableNorth && WalkableWest) { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, 0, -1), CurrentCell, DIAGONAL_G_COST); } if (WalkableSouth && WalkableEast) { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, 0, 1), CurrentCell, DIAGONAL_G_COST); } if (WalkableSouth && WalkableWest) { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, 0, 1), CurrentCell, DIAGONAL_G_COST); } return false; }
void CSkeletonGroup::Repath() { BuildPath(); m_bRepath = false; }
bool cPath::StepOnce() { cPathCell * CurrentCell = OpenListPop(); // Path not reachable. if (CurrentCell == nullptr) { AttemptToFindAlternative(); return true; } // Path found. if (CurrentCell->m_Location == m_Destination) { BuildPath(); FinishCalculation(ePathFinderStatus::PATH_FOUND); return true; } // Calculation not finished yet. // Check if we have a new NearestPoint. // TODO I don't like this that much, there should be a smarter way. if ((m_Destination - CurrentCell->m_Location).Length() < 5) { if (m_Rand.NextInt(4) == 0) { m_NearestPointToTarget = CurrentCell; } } else if (CurrentCell->m_H < m_NearestPointToTarget->m_H) { m_NearestPointToTarget = CurrentCell; } // process a currentCell by inspecting all neighbors. // Check North, South, East, West on our height. ProcessIfWalkable(CurrentCell->m_Location + Vector3i(1, 0, 0), CurrentCell, 10); ProcessIfWalkable(CurrentCell->m_Location + Vector3i(-1, 0, 0), CurrentCell, 10); ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 0, 1), CurrentCell, 10); ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 0, -1), CurrentCell, 10); // Check diagonals on XY plane. // x = -1: west, x = 1: east. for (int x = -1; x <= 1; x += 2) { if (GetCell(CurrentCell->m_Location + Vector3i(x, 0, 0))->m_IsSolid) // If there's a solid our east / west. { if (!GetCell(CurrentCell->m_Location + Vector3i(0, 1, 0))->m_IsSolid) // If there isn't a solid above. { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, 1, 0), CurrentCell, JUMP_G_COST); // Check east-up / west-up. } } else { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, -1, 0), CurrentCell, 14); // Else check east-down / west-down. } } // Check diagonals on the YZ plane. for (int z = -1; z <= 1; z += 2) { if (GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid) // If there's a solid our north / south. { if (!GetCell(CurrentCell->m_Location + Vector3i(0, 1, 0))->m_IsSolid) // If there isn't a solid above. { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, 1, z), CurrentCell, JUMP_G_COST); // Check north-up / south-up. } } else { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(0, -1, z), CurrentCell, 14); // Else check north-down / south-down. } } // Check diagonals on the XZ plane. (Normal diagonals, this plane is special because of gravity, etc) for (int x = -1; x <= 1; x += 2) { for (int z = -1; z <= 1; z += 2) { // This condition prevents diagonal corner cutting. if (!GetCell(CurrentCell->m_Location + Vector3i(x, 0, 0))->m_IsSolid && !GetCell(CurrentCell->m_Location + Vector3i(0, 0, z))->m_IsSolid) { // This prevents falling of "sharp turns" e.g. a 1x1x20 rectangle in the air which breaks in a right angle suddenly. if (GetCell(CurrentCell->m_Location + Vector3i(x, -1, 0))->m_IsSolid && GetCell(CurrentCell->m_Location + Vector3i(0, -1, z))->m_IsSolid) { ProcessIfWalkable(CurrentCell->m_Location + Vector3i(x, 0, z), CurrentCell, 14); // 14 is a good enough approximation of sqrt(10 + 10). } } } } return false; }
void Pathfinder::UpdatePath() { //need to set all parents to null before recalculating the path. //if not, there's an infinite loop in BuildPath() for (std::vector<PathNode>::iterator itr = m_nodes.begin(); itr != m_nodes.end(); ++itr) { itr->SetParent(nullptr); } //set StartNode and EndNode m_startNode = NearestNode(m_StartPosition); m_endNode = NearestNode(m_EndPosition); //recalculate all estimated costs int16_t cost = 0; PathNode * node; for (std::vector<PathNode>::iterator itr = m_nodes.begin(); itr != m_nodes.end(); ++itr) { node = &(*itr); if (node->GetCost() != -1) { //estimated based on pixels distance float cost = node->GetCost(); float estimated = (sqrt(pow((m_endNode->GetPos().mX - node->GetPos().mX), 2) + pow(m_endNode->GetPos().mY - node->GetPos().mY, 2))); node->SetEstimatedCost(estimated); node->SetCost(cost + estimated); node->SetTotalCost(cost + estimated); } } //A* m_openNodes.clear(); m_closedNodes.clear(); m_startNode->SetCost(0); m_startNode->SetTotalCost(0); m_openNodes.push_back(m_startNode); bool objectiveFound = false; while (!m_openNodes.empty() && !objectiveFound) { PathNode * node = *(m_openNodes.begin()); m_openNodes.erase(m_openNodes.begin()); if (node->GetPos().mX == m_endNode->GetPos().mX && node->GetPos().mY == m_endNode->GetPos().mY) { BuildPath(node); } else { for (std::vector<Polygon::Edge>::iterator itr = node->GetPolygon()->m_edges.begin(); itr != node->GetPolygon()->m_edges.end(); ++itr) { printf("EDGE: %d - %d\n", node->GetPolygon()->m_id, itr->m_neighbour->m_id); PathNode * nextNode = nullptr; for (std::vector<PathNode>::iterator pathNodeItr = m_nodes.begin(); pathNodeItr != m_nodes.end(); ++pathNodeItr) { if (pathNodeItr->GetPolygon()->m_id == itr->m_neighbour->m_id) { nextNode = &(*pathNodeItr); } } if (nextNode == m_endNode) { nextNode->SetParent(node); nextNode->SetTotalCost(node->GetTotalCost() + nextNode->GetCost()); BuildPath(nextNode); objectiveFound = true; break; } if (nextNode->GetCost() != -1) { if (node == nextNode) { continue; } else if (find(m_closedNodes.begin(), m_closedNodes.end(), nextNode) != m_closedNodes.end()) { continue; } else if (find(m_openNodes.begin(), m_openNodes.end(), nextNode) != m_openNodes.end()) { if (nextNode->GetTotalCost() > 0 && nextNode->GetTotalCost() > node->GetTotalCost() + nextNode->GetCost()) { nextNode->SetTotalCost(node->GetTotalCost() + nextNode->GetCost()); nextNode->SetParent(node); } } else { nextNode->SetParent(node); m_openNodes.push_back(nextNode); } } } std::vector<PathNode *>::iterator el = find(m_openNodes.begin(), m_openNodes.end(), node); if (el != m_openNodes.end()) { m_openNodes.erase(el); } m_closedNodes.push_back(node); } } }
BOOL InstallWowFaxPrinter(PSZ szSection, PSZ szKey, PSZ szString) { CHAR szTmp[MAX_PATH]; PSZ szSrcPath; DWORD dwNeeded; DRIVER_INFO_2 DriverInfo; PRINTER_INFO_2 PrinterInfo; PORT_INFO_1 PortInfo; HKEY hKey = 0, hSubKey = 0; BOOL bRetVal; LOGDEBUG(0,("InstallWowFaxPrinter, Section = %s, Key = %s, String = %s\n", szSection, szKey, szString)); // Write the entry to the registry. We'll keep shadow entries // in the registry for the WOW fax applications and drivers to // read, since the entries that the spooler writes pertain // to winspool, not the 16-bit fax driver. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion\\WOW\\WowFax", 0, KEY_WRITE, &hKey ) == ERROR_SUCCESS) { if (RegCreateKey(hKey, szSection, &hSubKey) == ERROR_SUCCESS) { RegSetValueEx(hSubKey, szKey, 0, REG_SZ, szString, strlen(szString)+1); RegCloseKey(hKey); RegCloseKey(hSubKey); // Dynamically link to spooler API's if (!(*spoolerapis[WOW_GetPrinterDriverDirectory].lpfn)) { if (!LoadLibraryAndGetProcAddresses("WINSPOOL.DRV", spoolerapis, WOW_SPOOLERAPI_COUNT)) { LOGDEBUG(0,("InstallWowFaxPrinter, Unable to load WINSPOOL API's\n")); return(FALSE); } } // Copy the printer driver files. RtlZeroMemory(&DriverInfo, sizeof(DRIVER_INFO_2)); RtlZeroMemory(&PrinterInfo, sizeof(PRINTER_INFO_2)); if (!(*spoolerapis[WOW_GetPrinterDriverDirectory].lpfn)(NULL, NULL, 1, szTmp, MAX_PATH, &dwNeeded)) { LOGDEBUG(0,("InstallWowFaxPrinter, GetPrinterDriverDirectory failed: 0x%X\n", GetLastError())); return(FALSE); } // This is a dummy. We've no data file, but spooler won't take NULL. DriverInfo.pDataFile = BuildPath(szTmp, WOWFAX_DLL_NAME_A); DriverInfo.pDriverPath = BuildPath(szTmp, WOWFAX_DLL_NAME_A); LOGDEBUG(0,("InstallWowFaxPrinter, pDriverPath = %s\n", DriverInfo.pDataFile)); szSrcPath = BuildPath(pszSystemDirectory, WOWFAX_DLL_NAME_A); CopyFile(szSrcPath, DriverInfo.pDriverPath, FALSE); free_w(szSrcPath); DriverInfo.pConfigFile = BuildPath(szTmp, WOWFAXUI_DLL_NAME_A); szSrcPath = BuildPath(pszSystemDirectory, WOWFAXUI_DLL_NAME_A); CopyFile(szSrcPath, DriverInfo.pConfigFile, FALSE); free_w(szSrcPath); // Install the printer driver. DriverInfo.cVersion = 1; DriverInfo.pName = "Windows 3.1 Compatible Fax Driver"; if ((*spoolerapis[WOW_AddPrinterDriver].lpfn)(NULL, 2, &DriverInfo) == FALSE) { bRetVal = (GetLastError() == ERROR_PRINTER_DRIVER_ALREADY_INSTALLED); } if (bRetVal) { // Parse out the printer name. RtlZeroMemory(&PrinterInfo, sizeof(PRINTER_INFO_2)); PrinterInfo.pPrinterName = szKey; LOGDEBUG(0,("InstallWowFaxPrinter, pPrinterName = %s\n", PrinterInfo.pPrinterName)); // Use private API to add a NULL port. Printer guys need to fix // redirection to NULL bug. RtlZeroMemory(&PortInfo, sizeof(PORT_INFO_1)); PrinterInfo.pPortName = "NULL"; PortInfo.pName = PrinterInfo.pPortName; // Get "Local Port" string. LoadString(hmodWOW32, iszWowFaxLocalPort, szTmp, sizeof szTmp); (*spoolerapis[WOW_AddPortEx].lpfn)(NULL, 1, &PortInfo, szTmp); // Set the other defaults and install the printer. PrinterInfo.pDriverName = "Windows 3.1 Compatible Fax Driver"; PrinterInfo.pPrintProcessor = "WINPRINT"; PrinterInfo.pDatatype = "RAW"; if ((*spoolerapis[WOW_AddPrinter].lpfn)(NULL, 2, &PrinterInfo) == 0) { bRetVal = (GetLastError() == ERROR_PRINTER_ALREADY_EXISTS); } #ifdef DBG if (!bRetVal) { LOGDEBUG(0,("InstallWowFaxPrinter, AddPrinter failed: 0x%X\n", GetLastError())); } #endif } else { LOGDEBUG(0,("InstallWowFaxPrinter, AddPrinterDriver failed: 0x%X\n", GetLastError())); } free_w(DriverInfo.pDataFile); free_w(DriverInfo.pDriverPath); free_w(DriverInfo.pConfigFile); return(bRetVal); } else { LOGDEBUG(0,("InstallWowFaxPrinter, Unable to create Key: %s\n", szSection)); } } else { LOGDEBUG(0,("InstallWowFaxPrinter, Unable to open key: HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\WOW\\WowFax\n")); } if (hKey) { RegCloseKey(hKey); if (hSubKey) { RegCloseKey(hSubKey); } } return(FALSE); }
CSiteManagerItemData_Site* CSiteManager::GetSiteByPath(wxString sitePath) { wxChar c = sitePath[0]; if (c != '0' && c != '1') { wxMessageBox(_("Site path has to begin with 0 or 1."), _("Invalid site path")); return 0; } sitePath = sitePath.Mid(1); // We have to synchronize access to sitemanager.xml so that multiple processed don't write // to the same file or one is reading while the other one writes. CInterProcessMutex mutex(MUTEX_SITEMANAGER); CXmlFile file; TiXmlElement* pDocument = 0; if (c == '0') pDocument = file.Load(_T("sitemanager")); else { const wxString& defaultsDir = wxGetApp().GetDefaultsDir(); if (defaultsDir == _T("")) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } wxFileName name(defaultsDir, _T("fzdefaults.xml")); pDocument = file.Load(name); } if (!pDocument) { wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR); return 0; } TiXmlElement* pElement = pDocument->FirstChildElement("Servers"); if (!pElement) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } std::list<wxString> segments; if (!UnescapeSitePath(sitePath, segments) || segments.empty()) { wxMessageBox(_("Site path is malformed."), _("Invalid site path")); return 0; } TiXmlElement* pChild = GetElementByPath(pElement, segments); if (!pChild) { wxMessageBox(_("Site does not exist."), _("Invalid site path")); return 0; } TiXmlElement* pBookmark; if (!strcmp(pChild->Value(), "Bookmark")) { pBookmark = pChild; pChild = pChild->Parent()->ToElement(); segments.pop_back(); } else pBookmark = 0; CSiteManagerItemData_Site* data = ReadServerElement(pChild); if (!data) { wxMessageBox(_("Could not read server item."), _("Invalid site path")); return 0; } if (pBookmark) { TiXmlHandle handle(pBookmark); wxString localPath; CServerPath remotePath; TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text(); if (localDir) localPath = ConvLocal(localDir->Value()); TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text(); if (remoteDir) remotePath.SetSafePath(ConvLocal(remoteDir->Value())); if (!localPath.empty() && !remotePath.IsEmpty()) { data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false); } else data->m_sync = false; data->m_localDir = localPath; data->m_remoteDir = remotePath; } data->m_path = BuildPath( c, segments ); return data; }
void cDirectoryListing::InternalRetrieve( void ) { char filePath[512]; #if UOX_PLATFORM != PLATFORM_WIN32 DIR *dir = opendir("."); struct dirent *dirp = NULL; struct stat dirstat; while( ( dirp = readdir( dir ) ) ) { stat( dirp->d_name, &dirstat ); if( S_ISDIR( dirstat.st_mode ) ) { if( strcmp( dirp->d_name, "." ) && strcmp( dirp->d_name, ".." ) && doRecursion ) { subdirectories.push_back( cDirectoryListing( dirp->d_name, extension, doRecursion ) ); Console.Print( "%s/%s/n", currentDir.c_str(), dirp->d_name ); } continue; } shortList.push_back( dirp->d_name ); sprintf( filePath, "%s/%s", CurrentWorkingDir().c_str(), dirp->d_name ); filenameList.push_back( filePath ); } #else WIN32_FIND_DATA toFind; HANDLE findHandle = FindFirstFile( extension.c_str(), &toFind ); // grab first file that meets spec BOOL retVal = 0; if( findHandle != INVALID_HANDLE_VALUE ) // there is a file { shortList.push_back( toFind.cFileName ); sprintf( filePath, "%s/%s", currentDir.c_str(), toFind.cFileName ); filenameList.push_back( filePath ); retVal = 1; // let's continue } while( retVal != 0 ) // while there are still files { retVal = FindNextFile( findHandle, &toFind ); // grab the next file if( retVal != 0 ) { shortList.push_back( toFind.cFileName ); sprintf( filePath, "%s/%s", currentDir.c_str(), toFind.cFileName ); filenameList.push_back( filePath ); } } if( findHandle != INVALID_HANDLE_VALUE ) { FindClose( findHandle ); findHandle = INVALID_HANDLE_VALUE; } if( doRecursion ) { std::string temp; WIN32_FIND_DATA dirFind; HANDLE directoryHandle = FindFirstFile( "*.*", &dirFind ); BOOL dirRetval = 0; if( directoryHandle != INVALID_HANDLE_VALUE ) // there is a file { if( ( dirFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY ) { if( strcmp( dirFind.cFileName, "." ) && strcmp( dirFind.cFileName, ".." ) ) { temp = BuildPath( dirFind.cFileName ); subdirectories.push_back( cDirectoryListing( temp, extension, doRecursion ) ); } // it's a directory } dirRetval = 1; // let's continue } while( dirRetval != 0 ) // while there are still files { dirRetval = FindNextFile( directoryHandle, &dirFind ); // grab the next file if( dirRetval != 0 ) { if( ( dirFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY ) { if( strcmp( dirFind.cFileName, "." ) && strcmp( dirFind.cFileName, ".." ) ) { temp = BuildPath( dirFind.cFileName ); subdirectories.push_back( cDirectoryListing( temp, extension, doRecursion ) ); } // it's a directory } } } if( directoryHandle != INVALID_HANDLE_VALUE ) { FindClose( directoryHandle ); directoryHandle = INVALID_HANDLE_VALUE; } } #endif }