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); }
/// File handling /// ============= BOOL md_file_open(UINT32 fn_seg4, UINT16 fn_off, UINT8 flag_access, DWORD flag_create, DWORD flag_attrib) { HANDLE ret; int drive; DWORD access = GENERIC_READ; CHAR mem_str_raw[MAX_PATH]; TCHAR mem_str_ucs2[MAX_PATH]; TCHAR *mem_str; TCHAR *mem_str_start; VERBOSE(("md_file_open(%08x:%04x)", fn_seg4, fn_off)); mem_str = mem_read_sjis2ucs2(mem_str_raw, mem_str_ucs2, fn_seg4, fn_off, MAX_PATH); drive = PathGetDriveNumber(mem_str); if(drive != -1) { md_drive_set(drive); mem_str_start = PathFindNextComponent(mem_str); if(mem_str_start[0] == _T('\0')) { mem_str_start = mem_str; } } else { mem_str_start = mem_str; } if(mem_str[0] == _T('\\')) { md_drive_set(cur_drive); mem_str_start++; } if( !lstrcmp(mem_str_start, _T("CON")) || !lstrcmp(mem_str_start, _T("AUX")) || !lstrcmp(mem_str_start, _T("NUL")) || !lstrcmp(mem_str_start, _T("PRN")) ) { return FALSE; } access |= (flag_access & 0x3) >= 0x01 ? GENERIC_WRITE : 0; ret = CreateFile(mem_str_start, access, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, flag_create, flag_attrib, NULL); md_set_error(ret != INVALID_HANDLE_VALUE); if(ret != INVALID_HANDLE_VALUE) { CPU_AX = md_handle_append(ret); } return TRUE; }
/** * @brief Creates folder even if parent folder doesn't exist. * @param pszFolder - folder name. * @return true if operation was completed successfully. */ BOOL CreateFolder(PCTSTR pszFolder) { PCTSTR pszOldSegment = PathSkipRoot(pszFolder); _ASSERTE(pszOldSegment != NULL); if (pszOldSegment == NULL) return FALSE; TCHAR szFolderPath[MAX_PATH]; _tcsncpy_s(szFolderPath, countof(szFolderPath), pszFolder, pszOldSegment - pszFolder); while (*pszOldSegment) { PCTSTR pszSegment = PathFindNextComponent(pszOldSegment); _tcsncat_s(szFolderPath, countof(szFolderPath), pszOldSegment, pszSegment - pszOldSegment); if (! CreateDirectory(szFolderPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) return FALSE; pszOldSegment = pszSegment; } return TRUE; }
BOOL CReg::GetValue(YCString& Value, LPCTSTR pKeyPath, LPCTSTR pKeyName) { // Retrieve the handle of the key name LPTSTR pKeyPathNext = PathFindNextComponent(pKeyPath); YCString sKey(pKeyPath, pKeyPathNext - pKeyPath - 1); // Convert to a numeric handle name HKEY hKey; if (sKey == _T("HKEY_CLASSES_ROOT")) hKey = HKEY_CLASSES_ROOT; else if (sKey == _T("HKEY_CURRENT_USER")) hKey = HKEY_CURRENT_USER; else if (sKey == _T("HKEY_LOCAL_MACHINE")) hKey = HKEY_LOCAL_MACHINE; else if (sKey == _T("HKEY_USERS")) hKey = HKEY_USERS; else if (sKey == _T("HKEY_CURRENT_CONFIG")) hKey = HKEY_CURRENT_CONFIG; else return FALSE; // Retrieve the name of the subkey LPCTSTR pKeyPathEnd = pKeyPath + lstrlen(pKeyPath); YCString sSubKey(pKeyPathNext, pKeyPathEnd - pKeyPathNext); HKEY hkResult; if (RegOpenKeyEx(hKey, sSubKey, 0, KEY_QUERY_VALUE, &hkResult) != 0) return FALSE; BYTE data[MAX_PATH]; DWORD cbData = sizeof(data); if (RegQueryValueEx(hkResult, pKeyName, nullptr, nullptr, data, &cbData) != 0) return FALSE; Value = reinterpret_cast<LPTSTR>(data); RegCloseKey(hkResult); return TRUE; }
tstring AppSettings::FindMaterial(const tstring& fname) const { TCHAR buffer[MAX_PATH]; // Simply check for fully qualified path if (!PathIsRelative(fname.c_str())) { if (-1 != _taccess(fname.c_str(), 0)) return fname; } // Test if its relative and in one of the specified root paths for (tstringlist::const_iterator itr = materialRootPaths.begin(), end = materialRootPaths.end(); itr != end; ++itr) { PathCombine(buffer, itr->c_str(), fname.c_str()); if (-1 != _taccess(buffer, 0)) { return tstring(buffer); } } for (LPCTSTR filepart = PathFindNextComponent(fname.c_str()); filepart != nullptr; filepart = PathFindNextComponent(filepart)) { if (wildmatch(TEXT("materials\\*"), filepart)) { return FindMaterial(fname); } } return fname; }
void CCJShellTree::PopulateTree(LPCTSTR lpszPath) { LPSHELLFOLDER lpsf=NULL,lpsf2=NULL; LPITEMIDLIST lpi=NULL; HRESULT hr; TV_SORTCB tvscb; LPTSTR lpFolder = (LPTSTR)lpszPath; LPTSTR lpNextFolder; TCHAR strPath[_MAX_PATH]; LPMALLOC pMalloc; if (::SHGetMalloc(&pMalloc) == NOERROR) { // Get a pointer to the desktop folder. hr=SHGetDesktopFolder(&lpsf); if (SUCCEEDED(hr)) { USES_CONVERSION; // Initialize the tree view to be empty. DeleteAllItems(); do{ // Get the Next Component lpNextFolder = PathFindNextComponent( lpFolder ); if( lpNextFolder && *lpNextFolder ){ memcpy( strPath, lpFolder, ( lpNextFolder - lpFolder ) ); strPath[lpNextFolder - lpFolder] = _T('\0'); } else{ _tcscpy( strPath, lpFolder ); lpNextFolder = NULL; } // Get ShellFolder Pidl ULONG eaten; hr = lpsf->ParseDisplayName( NULL, NULL, T2OLE(strPath), &eaten, &lpi, NULL ); if( FAILED( hr ) ){ break; } hr=lpsf->BindToObject(lpi, 0, IID_IShellFolder,(LPVOID *)&lpsf2); if( FAILED( hr ) ){ break; } pMalloc->Free( lpi ); // Release the Parent Folder pointer. lpsf->Release(); // Chenge Folder Info lpsf = lpsf2; lpFolder = lpNextFolder; } while( lpNextFolder ); FillTreeView(lpsf,NULL,TVI_ROOT); } } tvscb.hParent = TVI_ROOT; tvscb.lParam = 0; tvscb.lpfnCompare = TreeViewCompareProc; // Sort the items in the tree view SortChildrenCB(&tvscb/*, FALSE*/); HTREEITEM hItem; hItem = GetRootItem(); Expand(hItem,TVE_EXPAND); Select(GetRootItem(),TVGN_CARET); }