DWORD GetServiceInfFilePath(LPTSTR lpFilename, DWORD nSize, BOOL bWifiOrNormal) { // Get Path to This Module DWORD nResult; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; nResult = GetModuleFileName(NULL, lpFilename, nSize); if (nResult == 0) { return 0; } _tsplitpath(lpFilename, szDrive, szDir, NULL, NULL); if (bWifiOrNormal) { _tmakepath(lpFilename, szDrive, szDir, NDISLWF_SERVICE_INF_FILE_WIFI, _T(".inf")); } else { _tmakepath(lpFilename, szDrive, szDir, NDISLWF_SERVICE_INF_FILE, _T(".inf")); } return (DWORD)_tcslen(lpFilename); }
void CBCGPBaseInfoWriter::ParseFilePath(const CString& pathName, CString& dirName, CString& fileName) { dirName.Empty (); fileName.Empty (); TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szName[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; #if _MSC_VER < 1400 _tsplitpath (pathName, szDrive, szDir, szName, szExt); _tmakepath (dirName.GetBuffer (_MAX_PATH), szDrive, szDir, NULL, NULL); #else _tsplitpath_s (pathName, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szName, _MAX_FNAME, szExt, _MAX_EXT); _tmakepath_s (dirName.GetBuffer (_MAX_PATH), _MAX_PATH, szDrive, szDir, NULL, NULL); #endif dirName.ReleaseBuffer (); #if _MSC_VER < 1400 _tmakepath (fileName.GetBuffer (_MAX_FNAME), NULL, NULL, szName, szExt); #else _tmakepath_s (fileName.GetBuffer (_MAX_PATH), _MAX_PATH, NULL, NULL, szName, szExt); #endif fileName.ReleaseBuffer (); }
bool CSourceSaver::Process(CPartFile* file, UINT maxSourcesToSave) // return false if sources not saved { if ((int)(::GetTickCount() - m_dwLastTimeSaved) > RESAVETIME) { TCHAR szslsfilepath[_MAX_PATH]; _tmakepath(szslsfilepath,NULL,(CString)file->GetTempPath()+_T("\\Source Lists"), file->GetPartMetFileName(),_T(".txtsrc")); //MORPH - Changed by SiRoB, SLS keep only for rare files, reduce Saved Source and life time //if (file->GetAvailableSrcCount() > 100 && file->GetDownPriority() < PR_HIGH) if (file->GetAvailableSrcCount() > 25) { if (PathFileExists(szslsfilepath)) _tremove(szslsfilepath); return false; } m_dwLastTimeSaved = ::GetTickCount() + (rand() * 30000 / RAND_MAX) - 15000; SourceList srcs; LoadSourcesFromFile(file, &srcs, szslsfilepath); SaveSources(file, &srcs, szslsfilepath, maxSourcesToSave); if ((int)(::GetTickCount() - m_dwLastTimeLoaded) > RELOADTIME) { m_dwLastTimeLoaded = ::GetTickCount() + (rand() * 30000 / RAND_MAX) - 15000; AddSourcesToDownload(file, &srcs); } while (!srcs.IsEmpty()) delete srcs.RemoveHead(); return true; } return false; }
bool CHTMLSection::SetHTMLFile( LPCTSTR pcszFilename ) { bool bRetVal = false; LPTSTR pcszHTML = NULL; UINT uLength = 0; if( LoadTextFile( pcszFilename, pcszHTML, uLength ) ) { TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath( pcszFilename, drive, dir, fname, ext ); TCHAR path_buffer[_MAX_PATH]; _tmakepath( path_buffer, drive, dir, NULL, NULL ); SetHTML( pcszHTML, uLength, path_buffer ); bRetVal = true; delete[] pcszHTML; } return bRetVal; }
void CScannerWnd::OnTimer(UINT nIDEvent) { CIEPatcherDlg * pDlg = ((CIEPatcherApp *) AfxGetApp())->m_pIEPatcherDlg; if (pDlg) { CString sFileToProcess; if (pDlg->GetPendingFileToScan(sFileToProcess)) { PatchStatus ps = CIEPatcherDlg::ScanFile(sFileToProcess); AfxGetMainWnd()->SendMessage(WM_UPDATEFILESTATUS, (WPARAM) ps, (LPARAM) (const TCHAR *) sFileToProcess); } else if (pDlg->GetPendingFileToPatch(sFileToProcess)) { TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFile[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(sFileToProcess, szDrive, szDir, szFile, szExt); CString sFileOut; TCHAR szPath[_MAX_PATH]; sFileOut.Format(_T("moz_%s"), szFile); _tmakepath(szPath, szDrive, szDir, sFileOut, szExt); PatchStatus ps; CIEPatcherDlg::PatchFile(sFileToProcess, szPath, &ps); AfxGetMainWnd()->SendMessage(WM_UPDATEFILESTATUS, (WPARAM) ps, (LPARAM) (const TCHAR *) sFileToProcess); } } CWnd::OnTimer(nIDEvent); }
void CLog::StartNewLogFile() { time_t tStarted = m_tStarted; Close(); TCHAR szDateLogStarted[40]; _tcsftime(szDateLogStarted, ARRSIZE(szDateLogStarted), _T("%Y.%m.%d %H.%M.%S"), localtime(&tStarted)); TCHAR szDrv[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szNam[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(m_strFilePath, szDrv, szDir, szNam, szExt); CString strLogBakNam; strLogBakNam = szNam; strLogBakNam += _T(" - "); strLogBakNam += szDateLogStarted; TCHAR szLogBakFilePath[MAX_PATH]; _tmakepath(szLogBakFilePath, szDrv, szDir, strLogBakNam, szExt); if (_trename(m_strFilePath, szLogBakFilePath) != 0) _tremove(m_strFilePath); Open(); }
void RegisterMonolithicDPlay() { HKEY hKey = NULL; const char * szKey = "CLSID\\{DA9CABC6-C724-4265-A61D-6E78EB2042B4}\\InprocServer32"; // check to see if it's already registered, and if so, do nothing, otherwise register it if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_CLASSES_ROOT, szKey, 0, KEY_READ, &hKey)) { // Get the module path TCHAR szFilePath[_MAX_PATH * 2], szDrive[_MAX_DRIVE], szDir[_MAX_DIR * 2]; ::GetModuleFileName(NULL, szFilePath, sizeofArray(szFilePath)); _tsplitpath(szFilePath, szDrive, szDir, NULL, NULL); _tmakepath(szFilePath, szDrive, szDir, NULL, NULL); int cch = _tcslen(szFilePath); if (TEXT('\\') == szFilePath[cch - 1]) szFilePath[cch - 1] = TEXT('\0'); // Update the registry from the DPMono.rgs USES_CONVERSION; _ATL_REGMAP_ENTRY regmap[] = { {L"MODULE_PATH", T2COLE(szFilePath)}, {NULL , NULL}, }; _Module.UpdateRegistryFromResource(IDR_DPMONO, true, regmap); } else { RegCloseKey(hKey); } }
void CSourceSaver::DeleteFile(CPartFile* file) { TCHAR szslsfilepath[_MAX_PATH]; // khaos::kmod+ Source Lists directory _tmakepath(szslsfilepath,NULL,(CString)file->GetTempPath()+_T("\\Source Lists"), file->GetPartMetFileName(),_T(".txtsrc")); if (_tremove(szslsfilepath)) if (errno != ENOENT) AddLogLine(true, _T("Failed to delete 'Temp\\Source Lists\\%s.txtsrc', you will need to do this by hand."), file->GetPartMetFileName()); }
static CString GetAppPathDir() { TCHAR szModulePath[_MAX_PATH]; GetModuleFileName( _hdllInstance, szModulePath, _MAX_PATH ); TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; _tsplitpath( szModulePath, drive, dir, NULL, NULL ); TCHAR szPath[_MAX_PATH] = {0}; _tmakepath( szPath, drive, dir, NULL, NULL ); return CString( szPath ); }
CString& FileMisc::MakePath(CString& sPath, const TCHAR* szDrive, const TCHAR* szDir, const TCHAR* szFName, const TCHAR* szExt) { TCHAR szPath[MAX_PATH]; #if _MSC_VER >= 1400 _tmakepath_s(szPath, MAX_PATH, szDrive, szDir, szFName, szExt); #else _tmakepath(szPath, szDrive, szDir, szFName, szExt); #endif sPath = szPath; return sPath; }
DWORD GetServiceSysFilePath(LPTSTR lpFilename, DWORD nSize) { // Get Path to This Module DWORD nResult; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; nResult = GetModuleFileName(NULL, lpFilename, nSize); if (nResult == 0) { return 0; } _tsplitpath(lpFilename, szDrive, szDir, NULL, NULL); _tmakepath(lpFilename, szDrive, szDir, NDISLWF_SERVICE_INF_FILE, _T(".sys")); return (DWORD)_tcslen(lpFilename); }
DWORD GetWFPCalloutInfFilePath(LPTSTR lpFilename, DWORD nSize) { // Get Path to This Module DWORD nResult; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; nResult = GetModuleFileName(NULL, lpFilename, nSize); if (nResult == 0) { return 0; } _tsplitpath(lpFilename, szDrive, szDir, NULL, NULL); _tmakepath(lpFilename, szDrive, szDir, WFP_CALLOUT_INF_FILE, _T(".inf")); return (DWORD)_tcslen(lpFilename); }
void EvalService::loadPlugin( const CString& arxFilePath ) { TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFile[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath( ( LPCTSTR )arxFilePath, szDrive, szDir, szFile, szExt ); // 拆分路径 CString serviceName; serviceName.Format( _T( "%s_SERVICE_NAME" ), CString( szFile ).MakeUpper() ); /* 问题:插件(cmsr2010.arx)加载过程中无法找到所有使用的其它dll * 奇怪:正常加载dll应该从当前目录下搜索,按理说应该是能够找到的??? * 临时解决方案: * 1) 将插件所在文件夹路径添加到dll搜索路径 * 2) 或将dll的路径添加到path环境变量 * 3) 或提前加载插件(手动或在VVLoader中自动加载) */ // 构造arx所在文件夹路径 TCHAR szPath[_MAX_PATH]; _tmakepath( szPath, szDrive, szDir, NULL, NULL ); // 合并盘符 // 将该路径添加到dll搜索路径中 // API使用前提:xp sp1(>=0x0502),在stdafx.h中修改 SetDllDirectory( szPath ); m_pEvalPluginManager->load( arxFilePath, serviceName ); //TCHAR szDllPath[_MAX_PATH]; //GetDllDirectory(_MAX_PATH, szDllPath); //AfxMessageBox(szDllPath); // 还原dll搜索路径 SetDllDirectory( NULL ); // 打印显示路径为空 // 注:191版本能够正常运行,测试显示路径也是为空(默认) //TCHAR szDllPath2[_MAX_PATH]; //GetDllDirectory(_MAX_PATH, szDllPath2); //AfxMessageBox(szDllPath2); }
//This function tests whether we have read access to the //contents of a directory. Note: This function counts on the //fact that the path is a *directory* path, terminated in backslash. // bool CanReadFromDir(const wchar_t *kpFile) { #ifdef _WIN32 //Try to use _tfindfirst() to get a handle. //If we have read access to the directory, this //is always guaranteed to succeed because "." //will be present even if it's an empty directory wchar_t szPath[_MAX_PATH], szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFname[_MAX_FNAME], szExt[_MAX_EXT]; _tsplitpath(kpFile, szDrive, szDir, szFname, szExt); assert(_tcslen(szFname) == 0); assert(_tcslen(szExt) == 0); _tmakepath( szPath, szDrive, szDir, L"*", //NOXLATE L"");//NOXLATE _wfinddata_t info; intptr_t lHandle = _tfindfirst(szPath, &info); if (-1 == lHandle) { //Nope, no read access. return false; } //Looks like we have read access! _findclose(lHandle); #else // // Used MgFileUtil methods instead. // #endif return true; }
BOOL CDBFExplorerDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; CStructureDlg dlg(AfxGetMainWnd()); dlg.m_strTitle = _T("Create New DBF file"); if (dlg.DoModal() == IDOK) { TCHAR szPath[MAX_PATH]; GetTempPath(_countof(szPath), szPath); _tmakepath(m_szTempFileName, NULL, szPath, GetTitle(), _T(DBF_FILEEXT)); if (m_dBaseFile->Create(m_szTempFileName, dlg.m_strFieldArray) == DBASE_SUCCESS) { if (OnOpenDocument(m_szTempFileName)) { SetModifiedFlag(TRUE); return TRUE; } return FALSE; } } return FALSE; }
void AppToolBar::CreateToolBars() { CMDIFrameWnd* pMainFrame = acedGetAcadFrame(); pMainFrame->LockWindowUpdate(); // 获取主菜单组 IAcadMenuGroup* mnuGrp = NULL; if ( !GetAcadMenuGroup( &mnuGrp ) ) return ; //得到所有菜单组 HRESULT hr = S_OK; IAcadToolbars* acToolbars = NULL; hr = mnuGrp->get_Toolbars( &acToolbars ); CString appFileName = acedGetAppName(); //取出完整的应用程序名称,含路径 TCHAR dir[_MAX_DIR], drive[_MAX_DRIVE], path[_MAX_PATH]; _tsplitpath( appFileName, drive, dir, NULL, NULL ); _tmakepath( path, drive, dir, NULL, NULL ); VARIANT index; VariantInit( &index ); V_VT( &index ) = VT_I4; TCHAR MenuName[256]; int delta = 30; // 工具栏间距 int top = 200, left = 200; for ( int i = 0; i < m_menuCount; i++ ) { IAcadToolbar* acToolbar = NULL; _tcscpy( MenuName, m_TopMenuNames[i] ); hr = acToolbars->Add( MenuName, &acToolbar ); acToolbar->put_Visible( true ); acToolbar->Dock( acToolbarFloating ); acToolbar->Float( top + i * delta, left, 1 ); CCADToolButtonArray* Menus = m_menus[i]; COleVariant flyOutButton; for ( int j = 0; j < Menus->GetSize(); j++ ) { // 添加按钮 V_I4( &index ) = ( long )j; CADToolButton* btn = Menus->GetAt( j ); IAcadToolbarItem* acToolbarItem = NULL; if( _tcscmp( _T( "--" ), btn->name ) == 0 ) { hr = acToolbar->AddSeparator( index, &acToolbarItem ); } else { hr = acToolbar->AddToolbarButton( index, btn->name, btn->help, btn->order, flyOutButton, &acToolbarItem ); CString bmpFile; bmpFile.Format( _T( "%s%s\\%s" ), path, BMP_DIR, btn->bmp ); TCHAR szBmpFile[256]; _tcscpy( szBmpFile, bmpFile ); //acutPrintf(_T("\n路径:%s"), szBmpFile); hr = acToolbarItem->SetBitmaps( szBmpFile, szBmpFile ); } } //acToolbarItem->Release(); acToolbar->Release(); } acToolbars->Release(); mnuGrp->Release(); pMainFrame->UnlockWindowUpdate(); stcMyToolBarNames.Copy( m_TopMenuNames ); //将工具栏名称存入静态数组中,卸载时使用 }
void CIPFilterDlg::OnBnClickedAppend() { CString strFilePath; if (DialogBrowseFile(strFilePath, GetResString(IDS_IPFILTERFILES))) { CWaitCursor curWait; CString strTempUnzipFilePath; CZIPFile zip; if (zip.Open(strFilePath)) { CZIPFile::File* zfile = zip.GetFile(_T("guarding.p2p")); if (zfile) { _tmakepath(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); if (zfile->Extract(strTempUnzipFilePath)) strFilePath = strTempUnzipFilePath; else { CString strError; strError.Format(_T("Failed to extract IP filter file \"guarding.p2p\" from ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError); } } else { CString strError; strError.Format(_T("Failed to find IP filter file \"guarding.p2p\" in ZIP file \"%s\"."), strFilePath); AfxMessageBox(strError); } zip.Close(); } else { CGZIPFile gz; if (gz.Open(strFilePath)) { _tmakepath(strTempUnzipFilePath.GetBuffer(MAX_PATH), NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); strTempUnzipFilePath.ReleaseBuffer(); // add filename and extension of uncompressed file to temporary file CString strUncompressedFileName = gz.GetUncompressedFileName(); if (!strUncompressedFileName.IsEmpty()) { strTempUnzipFilePath += _T('.'); strTempUnzipFilePath += strUncompressedFileName; } if (gz.Extract(strTempUnzipFilePath)) strFilePath = strTempUnzipFilePath; } gz.Close(); } if (theApp.ipfilter->AddFromFile(strFilePath, true)) { InitIPFilters(); m_ipfilter.Update(-1); } if (!strTempUnzipFilePath.IsEmpty()) _tremove(strTempUnzipFilePath); } }
/*! 指定拡張子のファイルに対応するファイルを開く補助関数 @date 2003.06.28 Moca ヘッダ・ソースファイルオープン機能のコードを統合 @date 2008.04.09 ryoji 処理対象(file_ext)と開く対象(open_ext)の扱いが逆になっていたのを修正 */ BOOL CEditView::OPEN_ExtFromtoExt( BOOL bCheckOnly, //!< [in] true: チェックのみ行ってファイルは開かない BOOL bBeepWhenMiss, //!< [in] true: ファイルを開けなかった場合に警告音を出す const TCHAR* file_ext[], //!< [in] 処理対象とする拡張子 const TCHAR* open_ext[], //!< [in] 開く対象とする拡張子 int file_extno, //!< [in] 処理対象拡張子リストの要素数 int open_extno, //!< [in] 開く対象拡張子リストの要素数 const TCHAR* errmes //!< [in] ファイルを開けなかった場合に表示するエラーメッセージ ) { //From Here Feb. 7, 2001 JEPRO 追加 int i; //To Here Feb. 7, 2001 /* 編集中ファイルの拡張子を調べる */ for( i = 0; i < file_extno; i++ ){ if( CheckEXT( GetDocument()->m_cDocFile.GetFilePath(), file_ext[i] ) ){ goto open_c; } } if( bBeepWhenMiss ){ ErrorBeep(); } return FALSE; open_c:; TCHAR szPath[_MAX_PATH]; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; TCHAR szFname[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; HWND hwndOwner; _tsplitpath( GetDocument()->m_cDocFile.GetFilePath(), szDrive, szDir, szFname, szExt ); for( i = 0; i < open_extno; i++ ){ _tmakepath( szPath, szDrive, szDir, szFname, open_ext[i] ); if( !fexist(szPath) ){ if( i < open_extno - 1 ) continue; if( bBeepWhenMiss ){ ErrorBeep(); } return FALSE; } break; } if( bCheckOnly ){ return TRUE; } /* 指定ファイルが開かれているか調べる */ /* 開かれている場合は開いているウィンドウのハンドルも返す */ /* ファイルを開いているか */ if( CShareData::getInstance()->IsPathOpened( szPath, &hwndOwner ) ){ }else{ /* 文字コードはこのファイルに合わせる */ SLoadInfo sLoadInfo; sLoadInfo.cFilePath = szPath; sLoadInfo.eCharCode = GetDocument()->GetDocumentEncoding(); sLoadInfo.bViewMode = false; CControlTray::OpenNewEditor( G_AppInstance(), this->GetHwnd(), sLoadInfo, NULL, true ); /* ファイルを開いているか */ if( CShareData::getInstance()->IsPathOpened( szPath, &hwndOwner ) ){ }else{ // 2011.01.12 ryoji エラーは表示しないでおく // ファイルサイズが大きすぎて読むかどうか問い合わせているような場合でもエラー表示になるのは変 // OpenNewEditor()または起動された側のメッセージ表示で十分と思われる //ErrorMessage( this->GetHwnd(), _T("%ts\n\n%ts\n\n"), errmes, szPath ); return FALSE; } } /* アクティブにする */ ActivateFrameWindow( hwndOwner ); // 2004/06/21 novice タグジャンプ機能追加 // 2004/07/09 genta/Moca タグジャンプバックの登録が取り除かれていたが、 // こちらでも従来どおり登録する TagJump tagJump; /* カーソル位置変換 レイアウト位置(行頭からの表示桁位置、折り返しあり行位置) → 物理位置(行頭からのバイト数、折り返し無し行位置) */ GetDocument()->m_cLayoutMgr.LayoutToLogic( GetCaret().GetCaretLayoutPos(), &tagJump.point ); tagJump.hwndReferer = CEditWnd::getInstance()->GetHwnd(); // タグジャンプ情報の保存 CTagJumpManager().PushTagJump(&tagJump); return TRUE; }
//******************************************************************************* BOOL CBCGPTagManager::LoadFromFile (LPCTSTR lpszFileName) { ASSERT_VALID (this); ASSERT (lpszFileName != NULL); SetBuffer (NULL); CString strFileName = lpszFileName; CString strBuffer; CString strPath = strFileName; if (strFileName.Find (TCHAR('\\')) == -1 && strFileName.Find (TCHAR('/')) == -1 && strFileName.Find (TCHAR(':')) == -1) { TCHAR lpszFilePath [_MAX_PATH]; if (::GetModuleFileName (NULL, lpszFilePath, _MAX_PATH) > 0) { TCHAR path_buffer[_MAX_PATH]; TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; #if _MSC_VER < 1400 _tsplitpath (lpszFilePath, drive, dir, NULL, NULL); _tsplitpath (strFileName, NULL, NULL, fname, ext); _tmakepath (path_buffer, drive, dir, fname, ext); #else _tsplitpath_s (lpszFilePath, drive, _MAX_DRIVE, dir, _MAX_DIR, NULL, 0, NULL, 0); _tsplitpath_s (strFileName, NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT); _tmakepath_s (path_buffer, drive, dir, fname, ext); #endif strPath = path_buffer; } } try { CStdioFile file; if (!file.Open (strPath, CFile::modeRead)) { TRACE(_T("CBCGPTagManager::LoadFromFile: File not found: %s"), strFileName); return FALSE; } CString str; while (file.ReadString (str)) { strBuffer += str; } } catch (CFileException* pEx) { pEx->ReportError (); pEx->Delete (); return FALSE; } SetBuffer (strBuffer); return TRUE; }
void CDlgPluginSetup::OnOK() { // TODO: この位置にその他の検証用のコードを追加してください CSuperTagEditorApp *pApp = (CSuperTagEditorApp *)AfxGetApp(); CString strINI; wchar_t drive[_MAX_DRIVE]; wchar_t dir[_MAX_DIR]; wchar_t buff[_MAX_PATH] = {'\0'}; { wchar_t* szName = pApp->MakeFileName(L"ini"); _tsplitpath(szName, drive, dir, NULL, NULL); _tmakepath(buff, drive, dir, L"Plugin", L"ini"); strINI = buff; delete szName; //DeleteFile(strINI); } Profile_Initialize(strINI, FALSE); CString strSection; for (int nIndex=0;nIndex<m_listPlugin.GetItemCount();nIndex++) { PSTEPlugin pPlugin = (PSTEPlugin)m_listPlugin.GetItemData(nIndex); pPlugin->bUse = ListView_GetCheckState(m_listPlugin.GetSafeHwnd(), nIndex) ? true : false; strSection.Format(L"Load%03d", nIndex); // 相対パスに変換 wchar_t pDrive[_MAX_DRIVE]; wchar_t pDir[_MAX_DIR]; wchar_t pFname[_MAX_FNAME]; wchar_t pExt[_MAX_EXT]; wchar_t pBuff[_MAX_PATH] = {'\0'}; _tsplitpath(pPlugin->sFileName, pDrive, pDir, pFname, pExt); if (wcscmp(pDrive, drive) == 0) { //wchar_t pWDir[_MAX_DIR]; //wchar_t pWFname[_MAX_FNAME]; //wchar_t pRDir[_MAX_DIR] = {'\0'}; //wchar_t pRFname[_MAX_FNAME]; CString strRelDir = L""; ULONG nPathSeparatorIndex; BOOL bAnyParent; ULONG i; nPathSeparatorIndex = 0; i = 0; #ifndef iskanji #define iskanji(c) ((c) >= 0x81 && (c) <= 0x9f || (c) >= 0xe0 && (c) <= 0xfc) #endif while ((dir[i] == pDir[i] ) && (dir[i] != 0)) { if (!iskanji(dir[i])) { if (dir[i] == '\\' ) { nPathSeparatorIndex = i; } } else { i++; } i++; } if (dir[nPathSeparatorIndex] != '\\') { strRelDir = pDir; } else { i = nPathSeparatorIndex + 1; bAnyParent = FALSE; while (dir[i] != 0) { if (dir[i] == '\\') { bAnyParent = TRUE; strRelDir += L"..\\"; } i++; } if (!bAnyParent) { strRelDir += L".\\"; } } strRelDir += pDir+nPathSeparatorIndex+1; _tmakepath(pBuff, NULL, strRelDir, pFname, pExt); } else { // 変換なし _tmakepath(pBuff, pDrive, pDir, pFname, pExt); } MyWriteProfileString(strSection, L"Path", pBuff/*pPlugin->sFileName*/); //WritePrivateProfileString(strSection, L"Path", pPlugin->sFileName, strINI); MyWriteProfileString(strSection, L"Use", pPlugin->bUse ? L"1" : L"0"); //WritePrivateProfileString(strSection, L"Use", pPlugin->bUse ? L"1" : L"0", strINI); } Profile_Flush(strINI); Profile_Free(); CDialog::OnOK(); }
void CPPgSecurity::OnLoadIPFFromURL() { CString url; GetDlgItemText(IDC_UPDATEURL,url); if (!url.IsEmpty()) { // add entered URL to LRU list even if it's not yet known whether we can download from this URL (it's just more convenient this way) if (m_pacIPFilterURL && m_pacIPFilterURL->IsBound()) m_pacIPFilterURL->AddItem(url, 0); TCHAR szTempFilePath[MAX_PATH]; _tmakepath(szTempFilePath, NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T("tmp")); CHttpDownloadDlg dlgDownload; dlgDownload.m_strTitle = _T("Downloading IP filter file"); dlgDownload.m_sURLToDownload = url; dlgDownload.m_sFileToDownloadInto = szTempFilePath; if (dlgDownload.DoModal() != IDOK) { _tremove(szTempFilePath); LogWarning(LOG_STATUSBAR, _T("IP Filter download failed")); return; } bool bIsZipFile = false; bool bUnzipped = false; CZIPFile zip; if (zip.Open(szTempFilePath)) { bIsZipFile = true; CZIPFile::File* zfile = zip.GetFile(_T("guarding.p2p")); if (zfile) { TCHAR szTempUnzipFilePath[MAX_PATH]; _tmakepath(szTempUnzipFilePath, NULL, thePrefs.GetConfigDir(), DFLT_IPFILTER_FILENAME, _T(".unzip.tmp")); if (zfile->Extract(szTempUnzipFilePath)) { zip.Close(); zfile = NULL; if (_tremove(theApp.ipfilter->GetDefaultFilePath()) != 0) TRACE("*** Error: Failed to remove default IP filter file \"%s\" - %s\n", theApp.ipfilter->GetDefaultFilePath(), strerror(errno)); if (_trename(szTempUnzipFilePath, theApp.ipfilter->GetDefaultFilePath()) != 0) TRACE("*** Error: Failed to rename uncompressed IP filter file \"%s\" to default IP filter file \"%s\" - %s\n", szTempUnzipFilePath, theApp.ipfilter->GetDefaultFilePath(), strerror(errno)); if (_tremove(szTempFilePath) != 0) TRACE("*** Error: Failed to remove temporary IP filter file \"%s\" - %s\n", szTempFilePath, strerror(errno)); bUnzipped = true; } else LogError(LOG_STATUSBAR, _T("Failed to extract IP filter file from downloaded IP filter ZIP file \"%s\"."), szTempFilePath); } else LogError(LOG_STATUSBAR, _T("Downloaded IP filter file \"%s\" is a ZIP file with unexpected content."), szTempFilePath); zip.Close(); } if (!bIsZipFile && !bUnzipped) { _tremove(theApp.ipfilter->GetDefaultFilePath()); _trename(szTempFilePath, theApp.ipfilter->GetDefaultFilePath()); } } OnReloadIPFilter(); }
int CBCGPRecentFilesListBox::AddItem(const CString& strFilePath, UINT nCmd, BOOL bPin) { if (strFilePath.IsEmpty()) { return -1; } TCHAR path[_MAX_PATH]; TCHAR name[_MAX_PATH]; TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; #if _MSC_VER < 1400 _tsplitpath (strFilePath, drive, dir, fname, ext); _tmakepath (path, drive, dir, NULL, NULL); _tmakepath (name, NULL, NULL, fname, ext); #else _tsplitpath_s (strFilePath, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT); _tmakepath_s (path, drive, dir, NULL, NULL); _tmakepath_s (name, NULL, NULL, fname, ext); #endif CString strItem; if (m_bFoldersMode) { CString strPath = path; if (strPath.GetLength() > 0 && (strPath[strPath.GetLength() - 1] == _T('\\') || strPath[strPath.GetLength() - 1] == _T('/'))) { strPath = strPath.Left(strPath.GetLength() - 1); } int nIndex = max(strPath.ReverseFind(_T('\\')), strPath.ReverseFind(_T('/'))); if (nIndex >= 0) { strItem = strPath.Right(strPath.GetLength() - nIndex - 1); } } else { strItem = name; } strItem += _T("\n"); strItem += path; int nIndex = -1; if (FindStringExact(-1, strItem) < 0) { nIndex = AddString(strItem); SetItemData(nIndex, (DWORD_PTR)nCmd); if (bPin) { SetItemPinned(nIndex); } CString strFile = m_bFoldersMode ? path : strFilePath; SHFILEINFO sfi; if (::SHGetFileInfo (strFile, 0, &sfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SHELLICONSIZE | SHGFI_LARGEICON)) { m_arIcons.Add(sfi.hIcon); } else { m_arIcons.Add(NULL); } } return nIndex; }
void FolderTree::DisplayPath(const tstring &sPath, HTREEITEM hParent, bool bUseSetRedraw /* = true */) { //CWaitCursor c; //Speed up the job by turning off redraw if (bUseSetRedraw) SetRedraw(false); //Remove all the items currently under hParent HTREEITEM hChild = GetChildItem(hParent); while (hChild) { DeleteItem(hChild); hChild = GetChildItem(hParent); } //Should we display the root folder if (m_bShowRootedFolder && (hParent == TVI_ROOT)) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_sFQPath = m_sRootFolder; pItem->m_sRelativePath = m_sRootFolder; m_hRootedFolder = InsertFileItem(TVI_ROOT, pItem, false, GetIconIndex(m_sRootFolder), GetSelIconIndex(m_sRootFolder), true); Expand(m_hRootedFolder, TVE_EXPAND); return; } //find all the directories underneath sPath int nDirectories = 0; tstring sFile; if (sPath[sPath.size()-1] != _T('\\')) sFile = sPath + _T("\\"); else sFile = sPath; WIN32_FIND_DATA fData; HANDLE hFind; hFind = FindFirstFile((sFile + _T("*")).c_str(), &fData); if(hFind != INVALID_HANDLE_VALUE) { do { tstring filename = fData.cFileName; if((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (filename != _T(".")) && (filename != _T(".."))) { ++nDirectories; tstring path = sFile + filename; TCHAR szPath[_MAX_PATH]; TCHAR szFname[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(path.c_str(), NULL, NULL, szFname, szExt); _tmakepath(szPath, NULL, NULL, szFname, szExt); FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_sFQPath = path; pItem->m_sRelativePath = szPath; InsertFileItem(hParent, pItem, m_bShowSharedUsingDifferentIcon && IsShared(path), GetIconIndex(path), GetSelIconIndex(path), true); } } while (FindNextFile(hFind, &fData)); } FindClose(hFind); //Now sort the items we just added TVSORTCB tvsortcb; tvsortcb.hParent = hParent; tvsortcb.lpfnCompare = CompareByFilenameNoCase; tvsortcb.lParam = 0; SortChildrenCB(&tvsortcb); //We want to add them before sorting checkRemovedDirs(sFile, hParent); //If no items were added then remove the "+" indicator from hParent if(nDirectories == 0) SetHasPlusButton(hParent, FALSE); //Turn back on the redraw flag if(bUseSetRedraw) SetRedraw(true); }
HRESULT CPigEngine::Construct() { // Get the path name of the module TCHAR szModule[_MAX_PATH]; _VERIFYE(GetModuleFileName(_Module.GetModuleInstance(), szModule, sizeofArray(szModule))); // Break the path name of the module into pieces TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szName[_MAX_FNAME]; _tsplitpath(szModule, szDrive, szDir, szName, NULL); // Open the registry key of the AppID CRegKey key; RETURN_FAILED(_Module.OpenAppIDRegKey(key, KEY_READ)); // Create the event logger object RETURN_FAILED(m_spEventLogger.CreateInstance("AGC.EventLogger")); // Initialize the event logger object CComBSTR bstrEventSource(L"PigSrv"); CComBSTR bstrRegKey(L"HKCR\\AppID\\{F132B4E3-C6EF-11D2-85C9-00C04F68DEB0}"); IAGCEventLoggerPrivatePtr spPrivate(m_spEventLogger); RETURN_FAILED(spPrivate->Initialize(bstrEventSource, bstrRegKey)); // Load the MissionServer registry value LoadRegString(key, TEXT("MissionServer"), m_bstrMissionServer); // Load the AccountServer registry value LoadRegString(key, TEXT("AccountServer"), m_bstrAccountServer); // Load the ZoneAuthServer registry value LoadRegString(key, TEXT("ZoneAuthServer"), m_bstrZoneAuthServer); // Load the ZoneAuthTimeout registry value DWORD dwZoneAuthTimeout; if (ERROR_SUCCESS == key.QueryValue(dwZoneAuthTimeout, TEXT("ZoneAuthTimeout"))) m_nZoneAuthTimeout = static_cast<long>(dwZoneAuthTimeout); // Load the LobbyMode registry value DWORD dwLobbyMode; if (ERROR_SUCCESS == key.QueryValue(dwLobbyMode, TEXT("LobbyMode"))) m_eLobbyMode = (PigLobbyMode_Club <= dwLobbyMode && dwLobbyMode <= PigLobbyMode_Free) ? static_cast<PigLobbyMode>(dwLobbyMode) : PigLobbyMode_Club; // Attempt to read the ScriptDir value from the registry ZString strScriptDir; LoadRegString(key, TEXT("ScriptDir"), strScriptDir); // Create a directory name from the root directory, by default if (strScriptDir.IsEmpty()) { TCHAR szScriptDir[_MAX_PATH + 1]; _tmakepath(szScriptDir, szDrive, szDir, TEXT("Scripts"), NULL); strScriptDir = szScriptDir; } // Ensure that m_bstrScriptDir ends with a whack int nLastChar = strScriptDir.GetLength() - 1; if (TEXT('\\') != strScriptDir[nLastChar]) strScriptDir += ZString("\\"); // Save the directory name m_bstrScriptDir = strScriptDir; // Create the pigs collection object with a ref count assert(!m_pPigs); CComObject<CPigs>* pPigs = NULL; RETURN_FAILED(pPigs->CreateInstance(&pPigs)); (m_pPigs = pPigs)->AddRef(); // Indicate success return S_OK; }
extern "C" bool CGT_LoadTextFileToMem( CGT_CDiagMsg* pdm, const CG_Edipos* pEdp, const TCHAR* pszPath, const TCHAR* pszFile, TCHAR** ppCharBuffer, unsigned long* pulLength, __int64* pftLastWrite ) { int iRet; unsigned long ulen; TCHAR buffer[2*MAX_PATH]; const TCHAR* pszFull; if(FC_StringIsAbsPath(pszFile)) { pszFull = pszFile; } else { _tmakepath(buffer, NULL, pszPath, pszFile, NULL); assert(lstrlen(buffer) < FC_ARRAY_LEN(buffer)); pszFull = buffer; } //assert: must now be full path: assert(FC_StringIsAbsPath(pszFull)); //printf("load->%s\r\n", (const char*)full); ulen = CGT_MAXMEM_FILE_SIZE; iRet = FC_LoadDiskTextFileToMem( pszFull, ppCharBuffer, &ulen, pftLastWrite ); if(pulLength) *pulLength = ulen; /* 0: no error 1: file does simply not exist. 2: file cannot be opened or read (possibly missing permission) Use win32 GetLastError() for more information. 3: file is larger than *pulLength (>0) 4: Unicode to Multibyte conversion error (error currently not supported) -1: Out of memory */ switch(iRet) { case 0: break; case -1: pdm->msg0(CG_E_OUTOFMEM, pEdp); break; case 1: pdm->msg1(CG_E_FILE_NOT_EXIST, pEdp, pszFull); break; case 2: { FC_CString jot; pdm->msg2(CG_E_FILE_OPEN, pEdp, pszFull, jot.fmtSysErr(GetLastError())); } break; case 3: pdm->msg1(CG_E_FILE_TO_LARGE, pEdp, pszFull); break; case 4: default: assert(!"unexpected return"); } return iRet==0; }
//This function tests whether a specified file is "valid," allowing the //caller to specify various conditions for validity (must the file exist? //must it be a directory? must it be writable?) // //The function returns true if valid, false if not. // //Validity conditions: // // If the filename includes a path, then it must be a valid path // (i.e., the directory where the file or directory is located // must exist). // // If bExists is true, the file or directory itself must exist. // (This flag is redundant and assumed true if bCanWrite is // false; we can't read a nonexistent object!) // // If bIsDir is true, the specified file must be a directory. // If bIsDir is false, the specified file must NOT be a directory. // // If bCanWrite is true, then the specified file or directory // must be "writable". That means that the directory it's located // in must not be read-only, and if the file or directory // already exists, then it must not be read-only either. // // TODO If the pReason pointer is not NULL, then if the function fails, // it will store the string ID of the reason for failure there. // bool ValidateFile( const wchar_t *kpFile, //the file name to validate bool bExists, //if true, function fails if file doesn't exist bool bIsDir, //if true, function fails if file isn't a dir bool bCanWrite, //if true, function fails if file isn't writable EFileValidity *pReason) //if not NULL, stores result code { SmartCriticalClass critical(true); //If we are requesting validation for read access, then the //file must exist to be valid. Nonexistent items aren't readable. if (!bCanWrite) bExists = true; #ifdef _WIN32 //Decide what functions we'll use for testing read/write ability typedef bool (*FileTestFunc)(const wchar_t *); FileTestFunc CanReadItem, CanWriteItem; if (bIsDir) { CanReadItem = CanReadFromDir; CanWriteItem = CanWriteToDir; } else { CanReadItem = CanReadFromFile; CanWriteItem = CanWriteToFile; } #endif if ((NULL == kpFile) || (0 == wcslen(kpFile))) { //We were given an empty string. Obviously, this can't //be a valid file or directory. if (NULL != pReason) { *pReason = kFileInvalidEmptyString; } return false; } #ifdef _WIN32 wchar_t szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFname[_MAX_FNAME], szExt[_MAX_EXT], szDirPath[_MAX_PATH]; UINT32 dwResult; //If kpFile includes drive or path information, //make sure it's in an existing directory _tsplitpath(kpFile, szDrive, szDir, szFname, szExt); if (0 == _tcslen(szDir)) { //No directory was specified, so assume current directory. _tcscpy(szDir, L".\\");//NOXLATE } _tmakepath(szDirPath, szDrive, szDir, NULL, NULL); dwResult = GetFileAttributes(szDirPath); if (0xFFFFFFFF == dwResult) { //Nonexistent directory! Example: Specified //path was C:\foo\blah.txt, and there is no //directory C:\foo. if (NULL != pReason) { *pReason = kFileInvalidPath; } return false; } if (!(FILE_ATTRIBUTE_DIRECTORY & dwResult)) { //Not a directory! Example: Specified path //was C:\foo\blah.txt, and it turns out //that C:\foo exists but is a file (not a //directory). Kinda weird, but we have to //consider the possibility. if (NULL != pReason) { *pReason = kFileInvalidPath; } return false; } //See if the file exists. If bExists is true, fail if //it doesn't exist. dwResult = GetFileAttributes(kpFile); bool bFileExists = (0xFFFFFFFF != dwResult); if (bExists && !bFileExists) { //Doesn't exist! if (NULL != pReason) { *pReason = kFileInvalidDoesNotExist; } return false; } //If the file actually exists, make sure that whether it's a //directory or a file matches what the user specified. if (bFileExists) { if (bIsDir) { //Must be a directory. Fail if it's a file. if (!(FILE_ATTRIBUTE_DIRECTORY & dwResult)) { //Not a directory! if (NULL != pReason) { *pReason = kFileInvalidNotADir; } return false; } } else { //Must be a file. Fail if it's a directory. if (FILE_ATTRIBUTE_DIRECTORY & dwResult) { //Not a file! if (NULL != pReason) { *pReason = kFileInvalidIsADir; } return false; } } } //If bCanWrite is true, make sure we can write to the //file, and fail if we can't. bool bOk = true; if (bCanWrite) { if (bFileExists) { //The file already exists. bOk = CanWriteItem(kpFile); } //if the file already exists else { //The file doesn't already exist, so just make sure //we can write to the directory it's in. bOk = CanWriteItem(szDirPath); } //if the file doesn't already exist if (!bOk) { //We don't have write access to the item! if (NULL != pReason) { *pReason = kFileInvalidCantWrite; } return false; } } //if the file must be writable else { //The file doesn't have to be writable, but it has //to be readable. The file must exist; if it doesn't //already exist, it's ipso facto not readable. if (!CanReadItem(kpFile)) { //We don't have read access to the item! if (NULL != pReason) { *pReason = kFileInvalidCantRead; } return false; } //if we can't read from the dir } //if the file must be readable, but doesn't have to be writable #else UINT32 dwResult; //See if the file exists. If bExists is true, fail if //it doesn't exist. bool bFileExists = MgFileUtil::PathnameExists(kpFile); if (bExists && !bFileExists) { if (NULL != pReason) { *pReason = kFileInvalidPath; } } //If the file actually exists, make sure that whether it's a //directory or a file matches what the user specified. if (bFileExists) { if (bIsDir) { // Must be a directory. Fail if its a file. if (!MgFileUtil::IsDirectory(kpFile)) { // Not a directory! if (NULL != pReason) { *pReason = kFileInvalidNotADir; } return false; } } else { // Must be a file. Fail if it's a directory. if (!MgFileUtil::IsFile(kpFile)) { // Not a file! if (NULL != pReason) { *pReason = kFileInvalidIsADir; } return false; } } } // If bCanWrite is true, make sure we can write to the // file, and fail if we can't. bool bOk = true; if (bCanWrite) { if (bFileExists) { // The file already exists struct _stat statInfo; MgFileUtil::GetFileStatus(kpFile, statInfo); if (S_IWUSR & (statInfo.st_mode)) { bOk = true; } } else { // File doesn't already exist, so just make sure //we can write to the directory it's in. try { MgFileUtil::CreateDirectory(kpFile); MgFileUtil::DeleteDirectory(kpFile); bOk = true; } catch (MgException *e) { SAFE_RELEASE(e); bOk = false; } } if (!bOk) { // We don't have write access to the item! if (NULL != pReason) { *pReason = kFileInvalidCantWrite; } return false; } } // if the file must be writable else { // The file doesn't have to be writable, but it has // to be readable. The file must exist; if it doesn't // already exist, it's ipso facto no readable. if (bFileExists) { // The file already exists struct _stat statInfo; MgFileUtil::GetFileStatus(kpFile, statInfo); if (S_IRUSR & (statInfo.st_mode)) { bOk = true; } } if (!bFileExists || !bOk) { // We don't have read access to the item! if (NULL != pReason) { *pReason = kFileInvalidCantRead; } return false; } // if we can't read from the dir } // if the file must be readable, but doesn't have to be writeable #endif // If we made it this far, it must be valid! if (NULL != pReason) { *pReason = kFileIsValid; } return true; }
extern "C" bool CGT_WriteFile( CGT_CDiagMsg*pdm, const TCHAR* pszPath, const TCHAR* pszFile, const void* pBuffer, long nBytes, long flags ) { FILE* pF; int iItems; TCHAR full[2*MAX_PATH]; bool bFirstTry; TCHAR mode[3]; if(pszPath && !FC_StringIsAbsPath(pszFile)) _tmakepath(full, NULL, pszPath, pszFile, NULL); else lstrcpy(full, pszFile); assert(lstrlen(full) < FC_ARRAY_LEN(full)); //assert: must now be full path: assert(FC_StringIsAbsPath(full)); if(flags & CGT_WF_TOLOWER) _tcslwr(full); bFirstTry = true; mode[0] = (flags & CGT_WF_APPEND) ? _T('a') : _T('w'); mode[1] = (flags & CGT_WF_TEXTMODE) ? _T('t') : _T('b'); mode[2] = 0; tryAgain: iItems =0; pF = _tfopen(full, mode); if(pF) { iItems = fwrite(pBuffer, 1, nBytes, pF); fclose(pF); if(iItems!=nBytes) pdm->msg1(CG_E_WRITE_FILE_FAILED, NULL, full); } else if(bFirstTry && (flags & CGT_WF_CRT_PATH)) { FC_CString jot; bFirstTry = false; //here we create the folder if not exists //assume that the error was due to non existent folder... jot.load(full).stripFilePart(); if(FC_CreateSubDir(jot)) goto tryAgain; else pdm->msg1(CG_E_MKDIR_FAILED, NULL, jot);//TODO should be fatal error. } else { FC_CString jot; pdm->msg2(CG_E_FILE_OPEN, NULL, full, jot.fmtSysErr(GetLastError())); } return iItems==nBytes; }
void CFileAndFolder::DisplayPath(const CString& sPath, HTREEITEM hParent, BOOL bUseSetRedraw) { CWaitCursor c; //Speed up the job by turning off redraw // if (bUseSetRedraw) // SetRedraw(FALSE); //Remove all the items currently under hParent HTREEITEM hChild = m_Tree.GetChildItem(hParent); while (hChild) { m_Tree.DeleteItem(hChild); hChild = m_Tree.GetChildItem(hParent); } //Find all the directories and files underneath sPath CSortedArray<CString, CString&> DirectoryPaths; CSortedArray<CString, CString&> FilePaths; CFileFind find; CString sFile; if (sPath.GetAt(sPath.GetLength()-1) == _T('\\')) sFile = sPath + _T("*.*"); else sFile = sPath + _T("\\*.*"); BOOL bFind = find.FindFile(sFile); while (bFind) { bFind = find.FindNextFile(); if (find.IsDirectory()) { if (!find.IsDots()) { CString sPath = find.GetFilePath(); DirectoryPaths.Add(sPath); } } else { if (!find.IsHidden() && m_bShowFiles) { CString sPath = find.GetFilePath(); FilePaths.Add(sPath); } } } //Now sort the 2 arrays prior to added to the tree control DirectoryPaths.SetCompareFunction(CompareByFilenameNoCase); FilePaths.SetCompareFunction(CompareByFilenameNoCase); DirectoryPaths.Sort(); FilePaths.Sort(); //Now add all the directories to the tree control for (int i=0; i<DirectoryPaths.GetSize(); i++) { CString& sPath = DirectoryPaths.ElementAt(i); TCHAR path_buffer[_MAX_PATH]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath(sPath, NULL, NULL, fname, ext); _tmakepath(path_buffer, NULL, NULL, fname, ext); InsertFileItem(path_buffer, sPath, hParent); } //And the files to the tree control (if required) for (i=0; i<FilePaths.GetSize(); i++) { CString& sPath = FilePaths.ElementAt(i); TCHAR path_buffer[_MAX_PATH]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath(sPath, NULL, NULL, fname, ext); _tmakepath(path_buffer, NULL, NULL, fname, ext); InsertFileItem(path_buffer, sPath, hParent); } //Turn back on the redraw flag // if (bUseSetRedraw) // SetRedraw(TRUE); }