//比较两个文件名是否是同一个文件 int compareTwoFileName(const char* szFileName1, const char* szFileName2) { char szTempFileName1[MAX_PATH] = {0}; char szTempFileName2[MAX_PATH] = {0}; _snprintf(szTempFileName1, MAX_PATH, "%s", szFileName1); _snprintf(szTempFileName2, MAX_PATH, "%s", szFileName2); PathRemoveBlanks(szTempFileName1); PathRemoveBlanks(szTempFileName2); PathRemoveBackslash(szTempFileName1); PathRemoveBackslash(szTempFileName2); int nRet = _stricmp(szTempFileName1, szTempFileName2); if(nRet == 0) return 0; char szShortFileName1[MAX_PATH] = {0}; char szShortFileName2[MAX_PATH] = {0}; if(GetShortPathName(szTempFileName1, szShortFileName1, MAX_PATH)) { strcpy(szTempFileName1, szShortFileName1); } if(GetShortPathName(szTempFileName2, szShortFileName2, MAX_PATH)) { strcpy(szTempFileName2, szShortFileName2); } return _stricmp(szTempFileName1, szTempFileName2); }
tstring file_str() const { TCHAR buf[MAX_PATH]; memcpy(buf, this->buf, sizeof(this->buf)); PathRemoveBackslash(buf); return buf; }
MBASEAPI void MIRACLEEXPORT logInit( LPCTSTR path /*= NULL*/,LPCTSTR prefix /*= NULL*/,bool bDeleteLast/*=TRUE*/ ) { DeleteFile(strDebugFile); DeleteFile(strErrorFile); if(path != NULL) { if(PathIsDirectory(path)) { CString prestr = prefix; if(prestr.GetLength() != 0) if(!mirTestIsValidForFileName(prestr)) { ASSERT(FALSE); prestr = ""; } char path2[FILE_PATH_MAX]; strcpy_s(path2,FILE_PATH_MAX,path); PathRemoveBackslash(path2); strcat_s(path2,FILE_PATH_MAX,"\\"); strDebugFile = path2 ; strErrorFile = path2; strDebugFile = strDebugFile + prestr +"Debug.txt"; strErrorFile = strErrorFile + prestr +"Error.txt"; } } if(bDeleteLast) { DeleteFile(strDebugFile); DeleteFile(strErrorFile); } initlog = true; logDebug("Debug Messaging System Written by Hakan ÖZGÜR"); }
//============================================================================= // // DriveBox_GetSelDrive // BOOL DriveBox_GetSelDrive(HWND hwnd,LPWSTR lpszDrive,int nDrive,BOOL fNoSlash) { COMBOBOXEXITEM cbei; LPDC_ITEMDATA lpdcid; int i = (int)SendMessage(hwnd,CB_GETCURSEL,0,0); // CB_ERR means no Selection if (i == CB_ERR) return FALSE; // Get DC_ITEMDATA* of selected Item cbei.mask = CBEIF_LPARAM; cbei.iItem = i; SendMessage(hwnd,CBEM_GETITEM,0,(LPARAM)&cbei); lpdcid = (LPDC_ITEMDATA)cbei.lParam; // Get File System Path for Drive IL_GetDisplayName(lpdcid->lpsf,lpdcid->pidl,SHGDN_FORPARSING,lpszDrive,nDrive); // Remove Backslash if required (makes Drive relative!!!) if (fNoSlash) PathRemoveBackslash(lpszDrive); return TRUE; }
void CSettingsDictPage::OnBrowseLocation() { TCHAR szPath[_MAX_PATH]; CString strTitle = LoadString(IDS_DICT_LOCATION_PROMPT); BROWSEINFO info; ZeroMemory(&info, sizeof(info)); info.hwndOwner = m_hWnd; info.pszDisplayName = szPath; info.lpszTitle = strTitle; info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_USENEWUI; info.lpfn = BrowseCallbackProc; info.lParam = (LPARAM) this; LPITEMIDLIST pItem = SHBrowseForFolder(&info); if (pItem == NULL) return; if (SHGetPathFromIDList(pItem, szPath)) { PathRemoveBackslash(szPath); m_strDictLocation = szPath; UpdateData(false); } LPMALLOC pMalloc; if (SUCCEEDED(SHGetMalloc(&pMalloc))) pMalloc->Free(pItem); }
TCHAR* FTPCache::ExpandPath(const TCHAR * path) { if (!path) return NULL; tstring replacestring(path); if (_ConfigPath) { replacestring = SU::ReplaceString(replacestring, TEXT("%CONFIGDIR%"), _ConfigPath); } else { replacestring = SU::ReplaceString(replacestring, TEXT("%CONFIGDIR%"), TEXT(".")); } replacestring = SU::ReplaceString(replacestring, TEXT("%USERNAME%"), m_activeUser); replacestring = SU::ReplaceString(replacestring, TEXT("%HOSTNAME%"), m_activeHost); TCHAR * expanded = new TCHAR[MAX_PATH]; BOOL res = PathSearchAndQualify(replacestring.c_str(), expanded, MAX_PATH); if (res == FALSE) { delete [] expanded; return NULL; } PathRemoveBackslash(expanded); //OutMsg("Expanded %T to %T", path, expanded); return expanded; }
/// <summary>Removes the trailing backslash, if any</summary> /// <returns>New path without the trailing backslash</returns> Path Path::RemoveBackslash() const { CharArrayPtr buf( Copy() ); // Supply copy of buffer PathRemoveBackslash(buf.get()); return buf.get(); }
/// キャッシュファイルへのパスを取得 static void GetCachePath( PWCHAR filePath, LPCWSTR FileName ) { RtlZeroMemory(filePath, MAX_PATH+1); wcsncpy(filePath, CacheDirectory, wcslen(CacheDirectory)); wcsncat(filePath, FileName, wcslen(FileName)); PathRemoveBackslash(filePath); }
CSettingsDictPage::CSettingsDictPage() : CPropertyPage(CSettingsDictPage::IDD) { m_strDictLocation = theApp.GetAppSettings()->strDictLocation; PathRemoveBackslash(m_strDictLocation.GetBuffer(_MAX_PATH)); m_strDictLocation.ReleaseBuffer(); }
static CString GetParsentFolder(LPCTSTR szFullPath) { CString strParsentPath(szFullPath); PathRemoveBackslash(strParsentPath); PathRemoveFileSpec(strParsentPath); if (strParsentPath.IsEmpty()) strParsentPath = szFullPath; return strParsentPath; }
/// オリジナルのファイルへのパスを取得 static void GetFilePath( PWCHAR filePath, LPCWSTR FileName ) { RtlZeroMemory(filePath, MAX_PATH+1); wcsncpy(filePath, RootDirectory, wcslen(RootDirectory)); if (StrCmp(FileName,L"\\")!=0) wcsncat(filePath, FileName, wcslen(FileName)); PathRemoveBackslash(filePath); }
bool ExplorerCmd::EvaluateOption(LPCTSTR option) { String opt_str; // Remove quote characters, as they are evaluated at this point. for(; *option; ++option) if (*option != '"') opt_str += *option; option = opt_str; if (option[0] == '/') { ++option; // option /e for windows in explorer mode if (!_tcsicmp(option, TEXT("e"))) _flags |= OWM_EXPLORE; // option /root for rooted explorer windows else if (!_tcsicmp(option, TEXT("root"))) _flags |= OWM_ROOTED; // non-standard options: /mdi, /sdi else if (!_tcsicmp(option, TEXT("mdi"))) _mdi = true; else if (!_tcsicmp(option, TEXT("sdi"))) _mdi = false; else if (!_tcsicmp(option, TEXT("n"))) { // Do nothing } else if (!_tcsicmp(option, TEXT("select"))) { SelectOpt = TRUE; } else return false; } else { if (!_path.empty()) return false; if((SelectOpt == TRUE) && (PathFileExists(option))) { WCHAR szDir[MAX_PATH]; _wsplitpath(option, szPath, szDir, NULL, NULL); wcscat(szPath, szDir); PathRemoveBackslash(szPath); _path = szPath; SelectOpt = FALSE; } else _path = opt_str; } return true; }
HRESULT UpdatePublisherPolicyTimeStampFile(IAssemblyName *pName) { HRESULT hr = S_OK; DWORD dwSize; HANDLE hFile = INVALID_HANDLE_VALUE; WCHAR wzTimeStampFile[MAX_PATH + 1]; WCHAR wzAsmName[MAX_PATH]; ASSERT(pName); // If the name of the assembly begins with "policy." then update // the publisher policy timestamp file. wzAsmName[0] = L'\0'; dwSize = MAX_PATH; hr = pName->GetProperty(ASM_NAME_NAME, wzAsmName, &dwSize); if (FAILED(hr)) { goto Exit; } if (StrCmpNI(wzAsmName, POLICY_ASSEMBLY_PREFIX, lstrlenW(POLICY_ASSEMBLY_PREFIX))) { // No work needs to be done goto Exit; } // Touch the file dwSize = MAX_PATH; hr = GetCachePath(ASM_CACHE_GAC, wzTimeStampFile, &dwSize); if (lstrlenW(wzTimeStampFile) + lstrlenW(FILENAME_PUBLISHER_PCY_TIMESTAMP) + 1 >= MAX_PATH) { hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); goto Exit; } PathRemoveBackslash(wzTimeStampFile); lstrcatW(wzTimeStampFile, FILENAME_PUBLISHER_PCY_TIMESTAMP); hFile = CreateFileW(wzTimeStampFile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { hr = HRESULT_FROM_WIN32(GetLastError()); goto Exit; } Exit: if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); } return hr; }
HRESULT SetGACDir() { if( (lstrlen(g_szWindowsDir) + lstrlen(FUSION_CACHE_DIR_GAC_SZ) ) > MAX_PATH ) return HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME); StrCpy(g_GACDir, g_szWindowsDir); PathRemoveBackslash(g_GACDir); StrCat(g_GACDir, FUSION_CACHE_DIR_GAC_SZ); return S_OK; }
CFilePath &CFilePath::RemoveBackslash() { if (GetLastChar(msPath) == gsBackslash) { CStringLock Buffer(msPath, msPath.GetLength()+1); PathRemoveBackslash(Buffer); } return *this; }
/** * @brief Generate temporary folder name and creates it. * @param pszTempPath - generated temporary path name. * @param nTempPathSize - size of path buffer in characters. * @return true if operation was completed successfully. */ BOOL CreateTempFolder(PTSTR pszTempPath, size_t nTempPathSize) { TCHAR szSysTempPath[MAX_PATH]; GetTempPath(countof(szSysTempPath), szSysTempPath); PathRemoveBackslash(szSysTempPath); DWORD dwTicks = GetTickCount(); for (;;) { _stprintf_s(pszTempPath, nTempPathSize, _T("%s\\TEMP%lu"), szSysTempPath, dwTicks); if (CreateDirectory(pszTempPath, NULL)) return TRUE; if (GetLastError() != ERROR_ALREADY_EXISTS) return FALSE; ++dwTicks; } }
void CPreviewApps::RunApp(CPartFile* file, UINT uMenuID) { const SPreviewApp& svc = m_aApps.GetAt(uMenuID - MP_PREVIEW_APP_MIN); CString strPartFilePath = file->GetFullName(); // strip available ".met" extension to get the part file name. if (strPartFilePath.GetLength()>4 && strPartFilePath.Right(4)==_T(".met")) strPartFilePath.Delete(strPartFilePath.GetLength()-4,4); // if the path contains spaces, quote the entire path if (strPartFilePath.Find(_T(' ')) != -1) strPartFilePath = _T('\"') + strPartFilePath + _T('\"'); // get directory of video player application CString strCommandDir = svc.strCommand; int iPos = strCommandDir.ReverseFind(_T('\\')); if (iPos == -1) strCommandDir.Empty(); else strCommandDir = strCommandDir.Left(iPos + 1); PathRemoveBackslash(strCommandDir.GetBuffer()); strCommandDir.ReleaseBuffer(); CString strArgs = svc.strCommandArgs; if (!strArgs.IsEmpty()) strArgs += _T(' '); strArgs += strPartFilePath; file->FlushBuffer(true); CString strCommand = svc.strCommand; ExpandEnvironmentStrings(strCommand); ExpandEnvironmentStrings(strArgs); ExpandEnvironmentStrings(strCommandDir); TRACE("Starting preview application:\n"); TRACE(" Command =%s\n", strCommand); TRACE(" Args =%s\n", strArgs); TRACE(" Dir =%s\n", strCommandDir); ShellExecute(NULL, _T("open"), strCommand, strArgs, strCommandDir, SW_SHOWNORMAL); }
CString CShareableFile::GetInfoSummary() const { CString strFolder = GetPath(); PathRemoveBackslash(strFolder.GetBuffer()); strFolder.ReleaseBuffer(); CString strType = GetFileTypeDisplayStr(); if (strType.IsEmpty()) strType = _T("-"); CString info; info.Format(_T("%s\n") + GetResString(IDS_FD_SIZE) + _T(" %s\n<br_head>\n") + GetResString(IDS_TYPE) + _T(": %s\n") + GetResString(IDS_FOLDER) + _T(": %s"), GetFileName(), CastItoXBytes(GetFileSize(), false, false), strType, strFolder); return info; }
HRESULT PathConvertMappedDriveToUNC(PCWSTR pszPath, PWSTR *ppszUNC) { *ppszUNC = NULL; HRESULT hr = E_FAIL; #if 0 // build simple root "C:" (with no slash) since WNetGetConnection does not deal with these WCHAR szDrive[3] = {pszPath[0], pszPath[1], 0}; if (DRIVE_REMOTE == GetDriveType(szDrive)) { WCHAR szRemoteName[MAX_PATH]; DWORD dwLen = ARRAYSIZE(szRemoteName); if (NO_ERROR == WNetGetConnection(szDrive, szRemoteName, &dwLen)) { // +3 to skip to "\foo" in "C:\foo" WCHAR szUNC[MAX_PATH]; PathCombine(szUNC, szRemoteName, pszPath + 3); hr = SHStrDup(szUNC, ppszUNC); } } #else // alternate implementation struct { UNIVERSAL_NAME_INFO uni; // a pointer WCHAR szBuf[MAX_PATH]; // buffer for path, make bigger in the future } uniBuffer; DWORD cbBuffer = sizeof(uniBuffer); // test this with disconnected drive letters, might fail for them hr = HRESULT_FROM_WIN32(WNetGetUniversalNameW(pszPath, UNIVERSAL_NAME_INFO_LEVEL, &uniBuffer, &cbBuffer)); if (SUCCEEDED(hr)) { PathRemoveBackslash(uniBuffer.uni.lpUniversalName); // some cases return trailing slash hr = SHStrDup(uniBuffer.uni.lpUniversalName, ppszUNC); } #endif return hr; }
HRESULT GetAssemblyStagingPath(LPCTSTR pszCustomPath, DWORD dwCacheFlags, BOOL bUser, LPTSTR pszPath, DWORD *pcchSize) { HRESULT hr = S_OK; LPTSTR pszCacheLoc = NULL; ASSERT(pcchSize); if (pszCustomPath != NULL) { // Use custom path as the base StrCpy(pszPath, pszCustomPath); } else { if(FAILED(hr = GetCacheLoc(dwCacheFlags, &pszCacheLoc))) goto exit; // Else use the default StrCpy(pszPath, pszCacheLoc); } // check for buffer overflow if( ((DWORD)(lstrlenW(pszPath) + lstrlenW(FUSION_CACHE_STAGING_DIR_SZ) + 10)) > (*pcchSize)) { hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); goto exit; } PathRemoveBackslash(pszPath); StrCat(pszPath, FUSION_CACHE_STAGING_DIR_SZ); PathAddBackslash(pszPath); hr = CreateDirectoryForAssembly(8, pszPath, pcchSize); exit : return hr; }
int CALLBACK BrowseFolderCallback(HWND hwnd,UINT uMsg,LPARAM lpData,LPARAM lParam) { switch (uMsg) { case BFFM_INITIALIZED: { // フォルダ参照時の初期フォルダを設定する LPCTSTR pszDirectory=reinterpret_cast<LPCTSTR>(lParam); if (pszDirectory[0]!='\0') { TCHAR szFolder[MAX_PATH]; lstrcpy(szFolder,pszDirectory); PathRemoveBackslash(szFolder); SendMessage(hwnd,BFFM_SETSELECTION, TRUE,reinterpret_cast<LPARAM>(szFolder)); } } break; } return 0; }
LRESULT CFileTreeView::OnUserDirUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (!m_editDir.m_strDir.IsEmpty()) { if (!PathIsRoot((LPCWSTR)m_editDir.m_strDir)) { PathRemoveBackslash(m_editDir.m_strDir.GetBuffer(MAX_PATH)); PathRemoveFileSpec(m_editDir.m_strDir.GetBuffer(MAX_PATH)); PathAddBackslash(m_editDir.m_strDir.GetBuffer(MAX_PATH)); m_editDir.m_strDir.ReleaseBuffer(); } else { m_editDir.m_strDir = L""; } m_editDir.SetWindowText((LPCWSTR)(m_editDir.m_strDir)); m_editDir.SetSel(m_editDir.m_strDir.GetLength(), m_editDir.m_strDir.GetLength()); TreeView_SelectItem(m_Org.m_hWnd, NULL); m_Org.SetRootFolder((LPCWSTR)m_editDir.m_strDir); } RecordMemberVariable(); return 0; }
HRESULT __stdcall vcInitialize() { GetTempPath(MAX_PATH, g_szTempPath); PathRemoveBackslash(g_szTempPath); GetModuleFileName(NULL, g_szModulePath, MAX_PATH); PathRemoveFileSpec(g_szModulePath); CreateLogFile(); GetOSDisplayString(); GetSystemInformations(); InitGdiplus(); InitCommonResource(); InitHSBControlWindow(); ffmpeg_init(); LoadProfiles(); InitMediaMananger(); InitVideoPlayer(); InitVideoRender(); StringCchCopy(g_merge_info.m_Name, 256, L"merged"); if (LoadOptions() != S_OK) { SHGetFolderPath(NULL, CSIDL_MYVIDEO | CSIDL_FLAG_CREATE, NULL, 0, g_opt.m_OutputPath); g_opt.m_Parallel = g_cpu_count; g_opt.m_FillColor2 = 0xFFFFFFFF; } if (LoadProfileSettings() != S_OK) { ZeroMemory(&g_ProfileSettings, sizeof(g_ProfileSettings)); GetDefaultProfileSetting1(g_ProfileSettings, GROUP_VIDEO); } CopyProfileSettings(); return S_OK; }
CString CDir::ChangeDir(const CString& sPathIn, const CString& sAddIn, const CString& sHomeIn) { /* this function is pretty crappy but needed to fix ZNC's strange way of handling file paths */ CString sResult; CString sPath(sPathIn); CString sAdd(sAddIn); CString sHomeDir(sHomeIn); if (sHomeDir.empty()) { // use the default home dir, if no custom home dir has been passed in. sHomeDir = CZNC::Get().GetHomePath(); } // we want to use backslashes for this function's inner workings. sHomeDir.Replace("/", "\\"); sPath.Replace("/", "\\"); sAdd.Replace("/", "\\"); if (sAdd == "~") { // if the add dir is the home dir (why?!), use that as result... sResult = sHomeDir; } else { if(!PathIsRelative(sAdd.c_str())) { // if add already is an absolute path, use it for the result... // ... however, it can still contain ./ or ../ stuff, // which will be resolved later. sResult = sAdd; } else { // if the first part of the path (sPath) is relative, // make it absolute, starting from the znc.exe directory: if(PathIsRelative(sPath.c_str())) { char szLocalPath[1024] = {0}; // get the full path to znc.exe and strip off "znc.exe" from the end: if(GetModuleFileName(NULL, szLocalPath, 1023) != 0 && szLocalPath[0]) { PathRemoveFileSpec(szLocalPath); if(PathIsDirectory(szLocalPath)) { // append the relative sPath to our znc.exe dir, // thereby making it absolute. char szAbsolutePathBuffer[1024] = {0}; PathCombine(szAbsolutePathBuffer, szLocalPath, sPath.c_str()); // PathCombine will also resolve any ./ or ../ parts in the path. // use the now-absolute path: sPath = szAbsolutePathBuffer; } } } // append the (relative) sAdd path to the (absolute) sPath path: char szAbsoluteResultBuffer[1024] = {0}; PathCombine(szAbsoluteResultBuffer, sPath.c_str(), sAdd.c_str()); sResult = szAbsoluteResultBuffer; } } char szResultBuffer[1024] = {0}; // make sure no ./ or ../ stuff survives this function. never. if(!sResult.empty() && PathCanonicalize(szResultBuffer, sResult.c_str())) { if(sAdd.empty() || sAdd[sAdd.length() - 1] != '\\') { PathRemoveBackslash(szResultBuffer); } else { PathAddBackslash(szResultBuffer); } sResult = szResultBuffer; sResult.Replace("\\", "/"); return sResult; } else { abort(); return ""; // to shut up compiler warning } #else CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString& sHome) { CString sHomeDir(sHome); if (sHomeDir.empty()) { sHomeDir = CZNC::Get().GetHomePath(); } if (sAdd == "~") { return sHomeDir; } CString sAddDir(sAdd); if (sAddDir.Left(2) == "~/") { sAddDir.LeftChomp(); sAddDir = sHomeDir + sAddDir; } CString sRet = ((sAddDir.size()) && (sAddDir[0] == '/')) ? "" : sPath; sAddDir += "/"; CString sCurDir; if (sRet.Right(1) == "/") { sRet.RightChomp(); } for (unsigned int a = 0; a < sAddDir.size(); a++) { switch (sAddDir[a]) { case '/': if (sCurDir == "..") { sRet = sRet.substr(0, sRet.rfind('/')); } else if ((sCurDir != "") && (sCurDir != ".")) { sRet += "/" + sCurDir; } sCurDir = ""; break; default: sCurDir += sAddDir[a]; break; } } return (sRet.empty()) ? "/" : sRet; #endif }
LRESULT CFolderInputDialog::WndProc(HWND window, UINT msg, WPARAM wp, LPARAM lp) { static CButton btn_dir, btn_ok, btn_cancel; static CEditBox edit_dir; static CLabel label_dir; switch (msg) { case WM_INITDIALOG: { // Allow D&D (Drag & Drop) DragAcceptFiles(window, TRUE); UINT id = 10000; int x = 10; int y = -10; SetWindowText(window, _T("Select a destination")); label_dir.Create(window, _T("Input folder name"), id++, x, y += 20, 100, 20); edit_dir.Create(window, m_save_dir, id++, x, y += 20, 300, 22); btn_dir.Create(window, _T("Browse"), id++, x + 300, y + 1, 40, 20); btn_ok.Create(window, _T("OK"), IDOK, 110, y += 30, 70, 23); btn_cancel.Create(window, _T("Cancel"), IDCANCEL, 190, y, 70, 23); edit_dir.SetFocus(); btn_ok.SetDef(); Init(380, y + 60); return FALSE; } case WM_DROPFILES: { TCHAR save_dir[_MAX_DIR]; HDROP drop = reinterpret_cast<HDROP>(wp); DragQueryFile(drop, 0, save_dir, sizeof(save_dir)); edit_dir.SetText(save_dir); return FALSE; } case WM_COMMAND: // Browse button is pressed if (LOWORD(wp) == btn_dir.GetID()) { TCHAR save_dir[_MAX_DIR]; lstrcpy(save_dir, m_save_dir); CFolderDialog folder_dialog; if (folder_dialog.DoModal(window, _T("Select a folder"), save_dir) == TRUE) edit_dir.SetText(save_dir); return FALSE; } // OK button is pressed if (LOWORD(wp) == IDOK) { edit_dir.GetText(m_save_dir, _MAX_DIR); PathRemoveBackslash(m_save_dir); EndDialog(window, IDOK); return TRUE; } // Cancel button is pressed if (LOWORD(wp) == IDCANCEL) { EndDialog(window, IDCANCEL); return TRUE; } return FALSE; } return FALSE; }
HRESULT SetDownLoadDir() { HRESULT hr = S_OK; LPWSTR pszCacheLoc = NULL; if(FAILED(hr = GetCacheLoc(ASM_CACHE_DOWNLOAD, &pszCacheLoc))) goto exit; if( (lstrlen(pszCacheLoc) + lstrlen(FUSION_CACHE_DIR_DOWNLOADED_SZ)) > MAX_PATH ) { hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME); goto exit; } StrCpy(g_DownloadDir, pszCacheLoc); PathRemoveBackslash(g_DownloadDir); StrCat(g_DownloadDir, FUSION_CACHE_DIR_DOWNLOADED_SZ); PathAddBackslash(g_DownloadDir); #define DOWNLOAD_CACHE_OBFUSCATION_LENGTH 16 WIN32_FIND_DATA findData; WCHAR wzPath[MAX_PATH]; HANDLE hFind; BOOL bFoundObfuscated; if (lstrlenW(g_DownloadDir) + (DOWNLOAD_CACHE_OBFUSCATION_LENGTH * 2) + 1 >= MAX_PATH) { hr = HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW); goto exit; } bFoundObfuscated = FALSE; memset(&findData, 0, sizeof(findData)); wnsprintfW(wzPath, MAX_PATH, L"%ws*.*", g_DownloadDir); hFind = FindFirstFile(wzPath, &findData); if (hFind != INVALID_HANDLE_VALUE) { do { if (!lstrcmpW(findData.cFileName, L".") || !lstrcmpW(findData.cFileName, L"..")) { continue; } if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { lstrcatW(g_DownloadDir, findData.cFileName); bFoundObfuscated = TRUE; break; } } while (FindNextFile(hFind, &findData)); FindClose(hFind); } if (!bFoundObfuscated) { WCHAR wzRandom[(DOWNLOAD_CACHE_OBFUSCATION_LENGTH * 2) + 1]; BYTE bBuffer[DOWNLOAD_CACHE_OBFUSCATION_LENGTH]; if (!PAL_Random(FALSE, bBuffer, DOWNLOAD_CACHE_OBFUSCATION_LENGTH)) { hr = HRESULT_FROM_WIN32(GetLastError()); goto exit; } wzRandom[0] = L'\0'; CParseUtils::BinToUnicodeHex(bBuffer, DOWNLOAD_CACHE_OBFUSCATION_LENGTH, wzRandom); lstrcatW(g_DownloadDir, wzRandom); } // StrCat(g_DownloadDir, szCorVer); exit : return hr; }
void CDetailInfo::UpdateInfo(CPartFile* pFile, DWORD dwMask) { try { m_ListDetail.DeleteAllItems(); if (NULL == pFile || 0 == dwMask) return; m_pCurFile = pFile; m_dwCurMask = dwMask; int iItem; CString str; CPartFile *lpPartFile = pFile;//DYNAMIC_DOWNCAST(CPartFile, pFile); iItem = 0; if (IM_FILENAME & dwMask) { str = pFile->GetFileName(); m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_FILENAME)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILESIZE & dwMask) { str = CastItoXBytes(pFile->GetFileSize(), false, false); m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_SIZE)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem, 1, GetResString(IDS_UNKNOWN)); iItem++; } if (IM_FILETYPE & dwMask) { str = pFile->GetFileTypeDisplayStr(); m_ListDetail.InsertItem(iItem, GetResString(IDS_TYPE)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem, 1, GetResString(IDS_UNKNOWN)); iItem++; } if (IM_LINK & dwMask) { str = GetLink(pFile); bool bRefer = false; if(str.Left(7).CompareNoCase(_T("http://")) == 0) { if(str.Find(_T('<'))>0) { bRefer = true; str = str.Left(str.Find(_T('<'))); } if(str.Find(_T('#'))>0) str = str.Left(str.Find(_T('#'))); } if(!str.IsEmpty()) { m_ListDetail.InsertItem(iItem, GetResString(IDS_DOWNLOAD_LINK)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if(bRefer) { CString refer = GetLink(pFile); refer = refer.Right(refer.GetLength() - 1 - refer.Find(_T('='))); if(refer.Find(_T('>')) > 0) refer.Remove(_T('>')); m_ListDetail.InsertItem(iItem,GetResString(IDS_REFER_LINK)); m_ListDetail.SetItemText(iItem,1,refer); iItem++; } } if (IM_SOURCEURL & dwMask) { str = pFile->GetPartFileURL(); bool bRefer = false; if(str.Find(_T('<'))>0) { bRefer = true; str = str.Left(str.Find(_T('<'))); } if(str.Find(_T('#'))>0) str = str.Left(str.Find(_T('#'))); if(!str.IsEmpty()) { m_ListDetail.InsertItem(iItem, GetResString(IDS_URL_LINK)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if(bRefer) { CString strRefer = pFile->GetPartFileURL(); strRefer = strRefer.Right(strRefer.GetLength() -1 - strRefer.Find(_T('=') )); if(strRefer.Find(_T('>'))>0) strRefer.Remove(_T('>')); m_ListDetail.InsertItem(iItem,GetResString(IDS_REFER_LINK)); m_ListDetail.SetItemText(iItem,1,strRefer); iItem++; } } if (IM_PRIORITY & dwMask) { if(dwMask == CDetailInfo::IM_COMBINE_DOWNLOAD) str = PriorityToString(pFile->GetDownPriority(), pFile->IsAutoDownPriority()); if(dwMask == CDetailInfo::IM_COMBINE_SHARE) str = PriorityToString(pFile->GetUpPriority(),pFile->IsAutoUpPriority()); m_ListDetail.InsertItem(iItem, GetResString(IDS_PRIORITY)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILEHASH & dwMask) { if (pFile->HasNullHash()) { str = _T("-"); } else { str = md4str(pFile->GetFileHash()); } m_ListDetail.InsertItem(iItem, GetResString(IDS_FILEID)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_REQUEST & dwMask) { str.Format(_T("%u (%u)"), pFile->statistic.GetRequests(), pFile->statistic.GetAllTimeRequests()); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_REQUESTS)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_TRANSFERED & dwMask) { str.Format(_T("%s (%s)"), CastItoXBytes(pFile->statistic.GetTransferred(), false, false), CastItoXBytes(pFile->statistic.GetAllTimeTransferred(), false, false)); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_TRANSFERRED)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_FILEPATH & dwMask) { str = pFile->GetPath(); PathRemoveBackslash(str.GetBuffer()); str.ReleaseBuffer(); m_ListDetail.InsertItem(iItem, GetResString(IDS_FOLDER)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_ACCEPT & dwMask) { str.Format(_T("%u (%u)"), pFile->statistic.GetAccepts(), pFile->statistic.GetAllTimeAccepts()); m_ListDetail.InsertItem(iItem, GetResString(IDS_SF_ACCEPTS)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_SOURCE & dwMask) { str.Format(_T("%u - %u"), pFile->m_nCompleteSourcesCountLo, pFile->m_nCompleteSourcesCountHi); m_ListDetail.InsertItem(iItem, GetResString(IDS_COMPLSOURCES)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } if (IM_REMAIN & dwMask) { if (NULL != lpPartFile) { str.Empty(); if (lpPartFile->GetStatus() != PS_COMPLETING && lpPartFile->GetStatus() != PS_COMPLETE ) { // time time_t restTime; if (!thePrefs.UseSimpleTimeRemainingComputation()) restTime = lpPartFile->getTimeRemaining(); else restTime = lpPartFile->getTimeRemainingSimple(); str.Format(_T("%s (%s)"), CastSecondsToHM(restTime), CastItoXBytes((lpPartFile->GetFileSize() - lpPartFile->GetCompletedSize()), false, false)); } else { str.Format(_T("%s (%s)"), _T("0"), CastItoXBytes((lpPartFile->GetFileSize() - lpPartFile->GetCompletedSize()), false, false)); } m_ListDetail.InsertItem(iItem, GetResString(IDS_DL_REMAINS)); if(!str.IsEmpty()) m_ListDetail.SetItemText(iItem, 1, str); else m_ListDetail.SetItemText(iItem,1,GetResString(IDS_UNKNOWN)); iItem++; } } if (IM_LASTCOMPLETE & dwMask) { if (NULL != lpPartFile) { // CString tempbuffer; // if (lpPartFile->m_nCompleteSourcesCountLo == 0) // { // tempbuffer.Format(_T("< %u"), lpPartFile->m_nCompleteSourcesCountHi); // } // else if (lpPartFile->m_nCompleteSourcesCountLo == lpPartFile->m_nCompleteSourcesCountHi) // { // tempbuffer.Format(_T("%u"), lpPartFile->m_nCompleteSourcesCountLo); // } // else // { // tempbuffer.Format(_T("%u - %u"), lpPartFile->m_nCompleteSourcesCountLo, lpPartFile->m_nCompleteSourcesCountHi); // } if (lpPartFile->lastseencomplete==NULL) str.Format(_T("%s" /*(%s)*/),GetResString(IDS_NEVER)/*,tempbuffer*/); else str.Format(_T("%s" /*(%s)*/),lpPartFile->lastseencomplete.Format( thePrefs.GetDateTimeFormat())/*,tempbuffer*/); m_ListDetail.InsertItem(iItem, GetResString(IDS_LASTSEENCOMPL)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } if (IM_LASTRECV & dwMask) { if (NULL != lpPartFile) { if(lpPartFile->GetFileDate()!=NULL && lpPartFile->GetRealFileSize()/*GetCompletedSize() */> (uint64)0) str = lpPartFile->GetCFileDate().Format( thePrefs.GetDateTimeFormat()); else str.Format(_T("%s"),GetResString(IDS_NEVER)); m_ListDetail.InsertItem(iItem, GetResString(IDS_FD_LASTCHANGE)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } if (IM_CATEGORY & dwMask) { if (NULL != lpPartFile) { str = (lpPartFile->GetCategory()!=0) ? thePrefs.GetCategory(lpPartFile->GetCategory())->strTitle:_T(""); m_ListDetail.InsertItem(iItem, GetResString(IDS_CAT)); m_ListDetail.SetItemText(iItem, 1, str); iItem++; } } } catch(...) { } }
void CDirectoryTreeCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point) { CPoint ptMenu(-1, -1); if (point.x != -1 && point.y != -1) { ptMenu = point; ScreenToClient(&point); } else { HTREEITEM hSel = GetNextItem(TVI_ROOT, TVGN_CARET); if (hSel) { CRect rcItem; if (GetItemRect(hSel, &rcItem, TRUE)) { ptMenu.x = rcItem.left; ptMenu.y = rcItem.top; ClientToScreen(&ptMenu); } } else ClientToScreen(&(ptMenu = (0, 0))); } HTREEITEM hItem = HitTest(point); // create the menu CTitleMenu SharedMenu; SharedMenu.CreatePopupMenu(); SharedMenu.AddMenuTitle(GetResString(IDS_SHAREDFOLDERS)); bool bMenuIsEmpty = true; // add all shared directories int iCnt = 0; for (POSITION pos = m_lstShared.GetHeadPosition(); pos != NULL; iCnt++) { CString strDisplayPath(m_lstShared.GetNext(pos)); PathRemoveBackslash(strDisplayPath.GetBuffer(strDisplayPath.GetLength())); strDisplayPath.ReleaseBuffer(); SharedMenu.AppendMenu(MF_STRING,MP_SHAREDFOLDERS_FIRST+iCnt, GetResString(IDS_VIEW1) + strDisplayPath); bMenuIsEmpty = false; } // add right clicked folder, if any if (hItem) { m_strLastRightClicked = GetFullPath(hItem); if (!IsShared(m_strLastRightClicked)) { CString strDisplayPath(m_strLastRightClicked); PathRemoveBackslash(strDisplayPath.GetBuffer(strDisplayPath.GetLength())); strDisplayPath.ReleaseBuffer(); if (!bMenuIsEmpty) SharedMenu.AppendMenu(MF_SEPARATOR); SharedMenu.AppendMenu(MF_STRING, MP_SHAREDFOLDERS_FIRST-1, GetResString(IDS_VIEW1) + strDisplayPath + GetResString(IDS_VIEW2)); bMenuIsEmpty = false; } } // display menu if (!bMenuIsEmpty) SharedMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, ptMenu.x, ptMenu.y, this); VERIFY( SharedMenu.DestroyMenu() ); }
BOOL CPreviewThread::Run() { //Xman // BEGINSLUGFILLER: SafeHash CReadWriteLock lock(&theApp.m_threadlock); if (!lock.ReadLock(0)) return 0; // END SLUGFILLER: SafeHash ASSERT (m_pPartfile) ; CFile destFile; CFile srcFile; if (!srcFile.Open(m_pPartfile->GetFilePath(), CFile::modeRead | CFile::shareDenyNone)) return FALSE; try{ uint64 nSize = m_pPartfile->GetFileSize(); CString strExtension = CString(_tcsrchr(m_pPartfile->GetFileName(), _T('.'))); CString strPreviewName = m_pPartfile->GetTempPath() + m_pPartfile->GetFileName().Mid(0, 5) + _T("_preview") + strExtension; bool bFullSized = true; if (!strExtension.CompareNoCase(_T(".mpg")) || !strExtension.CompareNoCase(_T(".mpeg"))) bFullSized = false; if (!destFile.Open(strPreviewName, CFile::modeWrite | CFile::shareDenyWrite | CFile::modeCreate)) return FALSE; srcFile.SeekToBegin(); if (bFullSized) destFile.SetLength(nSize); destFile.SeekToBegin(); BYTE abyBuffer[4096]; uint32 nRead; while (destFile.GetPosition()+4096 < PARTSIZE*2){ nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } srcFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end); uint32 nToGo = PARTSIZE*2; if (bFullSized) destFile.Seek(-(LONGLONG)(PARTSIZE*2), CFile::end); do{ nRead = (nToGo - 4096 < 1)? nToGo:4096; nToGo -= nRead; nRead = srcFile.Read(abyBuffer,4096); destFile.Write(abyBuffer,nRead); } while (nToGo); destFile.Close(); srcFile.Close(); m_pPartfile->m_bPreviewing = false; SHELLEXECUTEINFO SE = {0}; SE.fMask = SEE_MASK_NOCLOSEPROCESS; CString strCommand; CString strArgs; CString strCommandDir; if (!m_strCommand.IsEmpty()) { SE.lpVerb = _T("open"); // "open" the specified video player // get directory of video player application strCommandDir = m_strCommand; int iPos = strCommandDir.ReverseFind(_T('\\')); if (iPos == -1) strCommandDir.Empty(); else strCommandDir = strCommandDir.Left(iPos + 1); PathRemoveBackslash(strCommandDir.GetBuffer()); strCommandDir.ReleaseBuffer(); strArgs = m_strCommandArgs; if (!strArgs.IsEmpty()) strArgs += _T(' '); if (strPreviewName.Find(_T(' ')) != -1) strArgs += _T('\"') + strPreviewName + _T('\"'); else strArgs += strPreviewName; strCommand = m_strCommand; ExpandEnvironmentStrings(strCommand); ExpandEnvironmentStrings(strArgs); ExpandEnvironmentStrings(strCommandDir); SE.lpFile = strCommand; SE.lpParameters = strArgs; SE.lpDirectory = strCommandDir; } else { SE.lpVerb = NULL; // use the default verb or the open verb for the document SE.lpFile = strPreviewName; } SE.nShow = SW_SHOW; SE.cbSize = sizeof(SE); ShellExecuteEx(&SE); if (SE.hProcess){ WaitForSingleObject(SE.hProcess, INFINITE); CloseHandle(SE.hProcess); } CFile::Remove(strPreviewName); } catch(CFileException* error){ m_pPartfile->m_bPreviewing = false; error->Delete(); } return TRUE; }
void ExecutePartFile(CPartFile* file, LPCTSTR pszCommand, LPCTSTR pszCommandArgs) { if (!CheckFileOpen(file->GetFilePath(), file->GetFileName())) return; CString strQuotedPartFilePath(file->GetFilePath()); // if the path contains spaces, quote the entire path if (strQuotedPartFilePath.Find(_T(' ')) != -1) strQuotedPartFilePath = _T('\"') + strQuotedPartFilePath + _T('\"'); // get directory of video player application CString strCommandDir = pszCommand; int iPos = strCommandDir.ReverseFind(_T('\\')); if (iPos == -1) strCommandDir.Empty(); else strCommandDir = strCommandDir.Left(iPos + 1); PathRemoveBackslash(strCommandDir.GetBuffer()); strCommandDir.ReleaseBuffer(); CString strArgs = pszCommandArgs; if (!strArgs.IsEmpty()) strArgs += _T(' '); strArgs += strQuotedPartFilePath; file->FlushBuffer(true); CString strCommand = pszCommand; ExpandEnvironmentStrings(strCommand); ExpandEnvironmentStrings(strArgs); ExpandEnvironmentStrings(strCommandDir); LPCTSTR pszVerb = _T("open"); // Backward compatibility with old 'preview' command (when no preview application is specified): // "ShellExecute(NULL, NULL, strPartFilePath, NULL, NULL, SW_SHOWNORMAL);" if (strCommand.IsEmpty()) { strCommand = strArgs; strArgs.Empty(); strCommandDir.Empty(); pszVerb = NULL; } TRACE(_T("Starting preview application:\n")); TRACE(_T(" Command =%s\n"), strCommand); TRACE(_T(" Args =%s\n"), strArgs); TRACE(_T(" Dir =%s\n"), strCommandDir); DWORD_PTR dwError = (DWORD_PTR)ShellExecute(NULL, pszVerb, strCommand, strArgs.IsEmpty() ? NULL : strArgs, strCommandDir.IsEmpty() ? NULL : strCommandDir, SW_SHOWNORMAL); if (dwError <= 32) { // // Unfortunately, Windows may already have shown an error dialog which tells // the user about the failed 'ShellExecute' call. *BUT* that error dialog is not // shown in each case! // // Examples: // - Specifying an executeable which does not exist (e.g. APP.EXE) // -> (Error 2) -> No error is shown. // // - Executing a document (verb "open") which has an unregistered extension // -> (Error 31) -> Error is shown. // // I'm not sure whether this behaviour (showing an error dialog in cases of some // specific errors) is handled the same way in all Windows version -> therefore I // decide to always show an application specific error dialog! // CString strMsg; strMsg.Format(_T("Failed to execute: %s %s"), strCommand, strArgs); CString strSysErrMsg(GetShellExecuteErrMsg(dwError)); if (!strSysErrMsg.IsEmpty()) strMsg += _T("\r\n\r\n") + strSysErrMsg; AfxMessageBox(strMsg, MB_ICONSTOP); } }