void Pathname::SetDirectory(const char *dir) { bool copydrv; //directory doesn't contain drive, need copy from original bool addslash; //directory doesn't ending by backslash, need add it int len = strlen(dir); copydrv = HasDrive() && !HasDrive(dir); //copy original drive, if exists and directory doesn't contaion drive if (strncmp(dir,"\\\\",2) == 0) copydrv = false; //network path, don't copy drive addslash = len && dir[len-1]!='\\'; //add slash if (addslash || copydrv) { char *c = (char *)alloca((len+4)*sizeof(dir[0])); //allocate some space for string if (addslash && copydrv) sprintf(c,"%c%c%s\\",_path[0],_path[1],dir); //add drive and add slash else if (addslash) sprintf(c,"%s\\",dir); //add slash only else sprintf(c,"%c%c%s",_path[0],_path[1],dir); //add drive only dir = c; //this is new path for now len = strlen(dir); } if (len<_filetitle-_path) //there is space for store path {strcpy(_path,dir); RebuildPath();} //store it and rebuild result else RebuildData(dir,_filetitle,_extension,len,strlen(_filetitle),strlen(_extension)); //rebuild internal data complettly }
void Pathname::SetDrive(const char dr) { if (HasDrive()) { if (dr == 0) { strcpy(_path,_path+2); strcpy(_fullpath,_fullpath+2); } else { _path[0] = dr; _fullpath[0] = dr; } } else if (dr != 0) { int np = IsNetworkPath(); if (np) { _path[0] = dr; _path[1] =':'; strcpy(_path+2,_path+np); RebuildPath(); } else { char *c = (char *)alloca((strlen(_path)+4)*sizeof(*c)); sprintf(c,"%c:%s",dr,_path); SetDirectory(c); } } }
static BOOL CALLCONV RebuildPath(HWND hTreeCtrl, HTREEITEM hItem, LPWSTR szPath) { WCHAR name[MAX_PATH]; TVITEMW item; HTREEITEM hParent; name[0]=0; item.hItem = hItem; item.cchTextMax = MAX_PATH-1; item.pszText = name; item.mask = TVIF_TEXT|TVIF_PARAM; TreeView_GetItem(hTreeCtrl,&item); hParent = TreeView_GetParent(hTreeCtrl,hItem); if(hParent) { RebuildPath(hTreeCtrl, hParent, szPath); lstrcatW(szPath,L"\\"); } if(item.lParam == TVNT_DIR) { lstrcatW(szPath,item.pszText+1); szPath[lstrlenW(szPath)-1]=0; return TRUE; } else if(item.lParam == TVNT_EMPTY) { szPath[0] = 0; return TRUE; } else { lstrcatW(szPath,item.pszText); return TRUE; } }
void Pathname::SetFiletitle(const char *title) { int len = strlen(title); if (len<_extension-_filetitle) { memcpy(_filetitle,title,len+1); RebuildPath(); } else { RebuildData(_path,title,_extension,strlen(_path),len,strlen(_extension)); } }
void Pathname::RebuildData(const char *path, const char *filetitle, const char *extension, int pathlen, int titlelen, int extlen) { int totalsize = (pathlen+titlelen+extlen)*2+10; char *olddata = _fullpath; _fullpath = new char[totalsize]; _path = _fullpath+pathlen+titlelen+extlen+1; memcpy(_path,path,pathlen+1); _filetitle = _path+pathlen+1; memcpy(_filetitle,filetitle,titlelen+1); _extension = _filetitle+titlelen+1; memcpy(_extension,extension,extlen+1); _end = _extension+extlen+1; RebuildPath(); delete [] olddata; }
void Pathname::SetExtension(const char *ext) { int len = strlen(ext); if (ext[0] && ext[0]!='.') { char *s = (char *)alloca((len+2)*sizeof(*s)); sprintf(s,".%s",ext); ext = s; len++; } if (len<_end-_extension) { memcpy(_extension,ext,len+1); RebuildPath(); } else { RebuildData(_path,_filetitle,ext,strlen(_path),strlen(_filetitle),len); } }
void Pathname::SetFilename(const char *filename) { char *dot = strrchr(filename,'.'); if (dot == NULL) { SetFiletitle(filename); SetExtension(""); return; } int tllen = dot-filename; int exlen = strlen(dot); char *c = (char *)alloca((tllen+1)*sizeof(*c)); memcpy(c,filename,tllen); c[tllen] = 0; if (exlen+tllen+1<_end-_filetitle) { memcpy(_filetitle,c,tllen+1); _extension = _filetitle+tllen+1; memcpy(_extension,dot,exlen+1); RebuildPath(); } else RebuildData(_path,c,dot,strlen(_path),tllen,exlen); }
// // AStar::operator() - Chapter 18, page 638 // PathPlan* AStar::operator()(PathingNode* pStartNode, PathingNode* pGoalNode) { GCC_ASSERT(pStartNode); GCC_ASSERT(pGoalNode); // if the start and end nodes are the same, we're close enough to b-line to the goal if (pStartNode == pGoalNode) return NULL; // set our members m_pStartNode = pStartNode; m_pGoalNode = pGoalNode; // The open set is a priority queue of the nodes to be evaluated. If it's ever empty, it means // we couldn't find a path to the goal. The start node is the only node that is initially in // the open set. AddToOpenSet(m_pStartNode, NULL); while (!m_openSet.empty()) { // grab the most likely candidate PathPlanNode* pNode = m_openSet.front(); // If this node is our goal node, we've successfully found a path. if (pNode->GetPathingNode() == m_pGoalNode) return RebuildPath(pNode); // we're processing this node so remove it from the open set and add it to the closed set m_openSet.pop_front(); AddToClosedSet(pNode); // get the neighboring nodes PathingNodeList neighbors; pNode->GetPathingNode()->GetNeighbors(neighbors); // loop though all the neighboring nodes and evaluate each one for (PathingNodeList::iterator it = neighbors.begin(); it != neighbors.end(); ++it) { PathingNode* pNodeToEvaluate = *it; // Try and find a PathPlanNode object for this node. PathingNodeToPathPlanNodeMap::iterator findIt = m_nodes.find(pNodeToEvaluate); // If one exists and it's in the closed list, we've already evaluated the node. We can // safely skip it. if (findIt != m_nodes.end() && findIt->second->IsClosed()) continue; // figure out the cost for this route through the node float costForThisPath = pNode->GetGoal() + pNodeToEvaluate->GetCostFromNode(pNode->GetPathingNode()); bool isPathBetter = false; // Grab the PathPlanNode if there is one. PathPlanNode* pPathPlanNodeToEvaluate = NULL; if (findIt != m_nodes.end()) pPathPlanNodeToEvaluate = findIt->second; // No PathPlanNode means we've never evaluated this pathing node so we need to add it to // the open set, which has the side effect of setting all the heuristic data. It also // means that this is the best path through this node that we've found so the nodes are // linked together (which is why we don't bother setting isPathBetter to true; it's done // for us in AddToOpenSet()). if (!pPathPlanNodeToEvaluate) pPathPlanNodeToEvaluate = AddToOpenSet(pNodeToEvaluate,pNode); // If this node is already in the open set, check to see if this route to it is better than // the last. else if (costForThisPath < pPathPlanNodeToEvaluate->GetGoal()) isPathBetter = true; // If this path is better, relink the nodes appropriately, update the heuristics data, and // reinsert the node into the open list priority queue. if (isPathBetter) { pPathPlanNodeToEvaluate->UpdatePrevNode(pNode); ReinsertNode(pPathPlanNodeToEvaluate); } } } // If we get here, there's no path to the goal. return NULL; }
static INT_PTR CALLBACK TemplateDlg(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static HWND hTreeCtrl; static HWND hOkBtn; static HWND hEditBtn; static HWND hInsertBtn; static HWND hRemoveMarkerBtn; static int LDX, LDY, BDX; static LPARAM param; if(WM_INITDIALOG == uMsg) { RECT rcWR, rcCR; POINT pt; EDITINFO ei; param = lParam; GetClientRect(hWndDlg,&rcWR); hTreeCtrl = GetDlgItem(hWndDlg,IDC_TREE); hOkBtn = GetDlgItem(hWndDlg,IDOK); hEditBtn = GetDlgItem(hWndDlg,IDC_EDIT); hInsertBtn = GetDlgItem(hWndDlg,IDC_INSERT); hRemoveMarkerBtn = GetDlgItem(hWndDlg, IDC_REMMARKER); GetWindowRect(hTreeCtrl,&rcCR); pt.x = rcCR.right; pt.y = rcCR.bottom; ScreenToClient(hWndDlg,&pt); LDX = rcWR.right - pt.x; LDY = rcWR.bottom - pt.y; GetWindowRect(hOkBtn,&rcCR); pt.x=rcCR.left; pt.y=0; ScreenToClient(hWndDlg,&pt); BDX = rcWR.right - pt.x; { TVINSERTSTRUCTW tvi; HTREEITEM hEmpty; WCHAR szRoot[MAX_PATH]; SHFILEINFOW sfi; HIMAGELIST hList = (HIMAGELIST)SHGetFileInfoW(g_szAkelPath,0,&sfi,sizeof(sfi),SHGFI_SYSICONINDEX|SHGFI_SMALLICON); TreeView_SetImageList(hTreeCtrl,hList,TVSIL_NORMAL); lstrcpyW(szRoot,g_szAkelPath); lstrcatW(szRoot,TEMPLATES_PATH); FillTreeCtrl(hTreeCtrl,szRoot,TVI_ROOT); TreeView_SortChildren(hTreeCtrl,TVI_ROOT,FALSE); tvi.hParent = TVI_ROOT; tvi.hInsertAfter = TVI_FIRST; tvi.item.pszText = L"<Empty>"; tvi.item.lParam = TVNT_EMPTY; tvi.item.iImage = tvi.item.iSelectedImage = 3; tvi.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE; hEmpty = TreeView_InsertItem(hTreeCtrl,&tvi); if(TreeView_GetCount(hTreeCtrl)>0) { TreeView_SelectItem(hTreeCtrl,hEmpty); EnableWindow(hOkBtn,TRUE); } else { EnableWindow(hOkBtn,FALSE); } } if(!(lParam&DCP_ALLOWEDIT)) { DestroyWindow(hEditBtn); hEditBtn = NULL; } if(SendMessageW(g_hMainWnd,AKD_GETEDITINFO,(WPARAM)NULL,(LPARAM)&ei)) { if(!IsWindow(ei.hWndEdit) || (!(lParam&DCP_ALLOWINSERT))) { DestroyWindow(hInsertBtn); hInsertBtn = NULL; } } SendMessageW(hRemoveMarkerBtn, BM_SETCHECK,g_bRemoveMarker?BST_CHECKED:BST_UNCHECKED,0); PostMessageW(hWndDlg,WM_COMMAND,MAKEWPARAM(IDC_TREE,LBN_SELCHANGE),0); RestorePosition(hWndDlg); #ifndef NO_SMALL_ICON SendMessageW(hWndDlg, WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)g_hMainIcon); #endif SendMessageW(hWndDlg, WM_SETICON,(WPARAM)ICON_BIG,(LPARAM)g_hMainIcon); return TRUE; } else if(WM_COMMAND == uMsg) { if(((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDC_EDIT) || (LOWORD(wParam) == IDC_INSERT)) && (HIWORD(wParam) == BN_CLICKED)) { HTREEITEM hItem = TreeView_GetSelection(hTreeCtrl); TVITEM item; INT_PTR len = 0; if(!hItem) return TRUE; item.hItem = hItem; item.lParam = 0; item.mask = TVIF_PARAM; if(!TreeView_GetItem(hTreeCtrl,&item)) return TRUE; if(item.lParam==TVNT_DIR) return TRUE; lstrcpyW(g_szTemplate,g_szAkelPath); lstrcatW(g_szTemplate,TEMPLATES_PATH); lstrcatW(g_szTemplate,L"\\"); g_bRemoveMarker = (SendMessageW(hRemoveMarkerBtn, BM_GETCHECK, 0, 0)==BST_CHECKED)?TRUE:FALSE; UpdateSettings(TSF_REMOVEMARKER,FALSE); len = lstrlenW(g_szTemplate); if(RebuildPath(hTreeCtrl, hItem, g_szTemplate+len)) { if(lstrlenW(g_szTemplate) == len) { //! Opening empty template g_szTemplate[0] = 0; } EndDialog(hWndDlg,LOWORD(wParam)); } else { g_szTemplate[0]=0; } return TRUE; } else if((LOWORD(wParam)==IDCANCEL) && (HIWORD(wParam) == BN_CLICKED)) { EndDialog(hWndDlg,IDCANCEL); return TRUE; } } else if(WM_NOTIFY == uMsg) { if(IDC_TREE == wParam) { if(((LPNMHDR)lParam)->code == TVN_SELCHANGED) { LPNMTREEVIEWW ptv = (LPNMTREEVIEWW)lParam; if(ptv->itemNew.hItem && (ptv->itemNew.mask&TVIF_PARAM)) { if(hOkBtn) { EnableWindow(hOkBtn, (ptv->itemNew.lParam != TVNT_DIR)); } if(hEditBtn) { EnableWindow(hEditBtn, ptv->itemNew.lParam == TVNT_FILE); } if(hInsertBtn) { EnableWindow(hInsertBtn, ptv->itemNew.lParam == TVNT_FILE); } } return TRUE; } else if(((LPNMHDR)lParam)->code == NM_DBLCLK) { DWORD pos = GetMessagePos(); TVHITTESTINFO thi; HTREEITEM hit=0; thi.pt.x = GET_X_LPARAM(pos); thi.pt.y = GET_Y_LPARAM(pos); ScreenToClient(hTreeCtrl,&thi.pt); thi.hItem =0; thi.flags =0; hit = TreeView_HitTest(hTreeCtrl,&thi); if(thi.hItem) { TVITEM item; item.hItem = thi.hItem; item.mask = TVIF_PARAM; TreeView_GetItem(hTreeCtrl,&item); if(hOkBtn) { EnableWindow(hOkBtn, item.lParam != TVNT_DIR); } if(hEditBtn) { EnableWindow(hEditBtn, item.lParam == TVNT_FILE); } if(hInsertBtn) { EnableWindow(hInsertBtn, item.lParam != TVNT_DIR); } if(item.lParam != TVNT_DIR) PostMessageW(hWndDlg,WM_COMMAND,MAKEWPARAM(IDOK,BN_CLICKED),0); } return TRUE; } } } else if(WM_CLOSE == uMsg) { PostMessageW(hWndDlg,WM_COMMAND,MAKEWPARAM(IDCANCEL,BN_CLICKED),0); return TRUE; } else if(WM_DESTROY == uMsg) { SavePosition(hWndDlg); } else if(WM_SIZE == uMsg) { RECT rcWindow, rcNew; POINT pt; GetClientRect(hWndDlg,&rcWindow); GetWindowRect(hTreeCtrl,&rcNew); pt.x = rcNew.left; pt.y = rcNew.top; ScreenToClient(hWndDlg,&pt); MoveWindow(hTreeCtrl,pt.x,pt.y,rcWindow.right-LDX-pt.x, rcWindow.bottom-LDY-pt.y,TRUE); MoveButton(hWndDlg,hOkBtn,rcWindow, BDX); MoveButton(hWndDlg,GetDlgItem(hWndDlg,IDCANCEL),rcWindow, BDX); MoveButton(hWndDlg,hEditBtn,rcWindow, BDX); MoveButton(hWndDlg,hInsertBtn,rcWindow, BDX); MoveButton(hWndDlg,hRemoveMarkerBtn,rcWindow,BDX); InvalidateRect(hWndDlg,NULL,TRUE); } else if(WM_PAINT == uMsg) { RECT rc; PAINTSTRUCT ps; HDC dc = BeginPaint(hWndDlg, &ps); if(dc) { GetClientRect(hWndDlg, &rc); rc.left = rc.right - GetSystemMetrics(SM_CXVSCROLL); rc.top = rc.bottom - GetSystemMetrics(SM_CYVSCROLL); DrawFrameControl(dc, &rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); EndPaint(hWndDlg, &ps); } } return FALSE; }