wxString CUpdater::GetLocalFile( build const& b, bool allow_existing ) { wxString const fn = GetFilename( b.url_ ); wxString const dl = GetDownloadDir().GetPath(); int i = 1; wxString f = dl + fn; while( CLocalFileSystem::GetFileType(f) != CLocalFileSystem::unknown && (!allow_existing || !VerifyChecksum(f, b.size_, b.hash_))) { if( ++i > 99 ) { return _T(""); } wxString ext; int pos; if( !fn.Right(8).CmpNoCase(_T(".tar.bz2")) ) { pos = fn.size() - 8; } else { pos = fn.Find('.', true); } if( pos == -1 ) { f = dl + fn + wxString::Format(_T(" (%d)"), i); } else { f = dl + fn.Left(pos) + wxString::Format(_T(" (%d)"), i) + fn.Mid(pos); } } return f; }
HRESULT CreateAssemblyDirPath( LPCTSTR pszCustomPath, DWORD dwInstaller, DWORD dwCacheFlags, BOOL bUser, LPTSTR pszPath, DWORD *pcchSize) { HRESULT hr = S_OK; LPWSTR pszCacheLoc = NULL; if (dwCacheFlags & ASM_CACHE_GAC) { hr = GetGACDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } else if(dwCacheFlags & ASM_CACHE_ZAP) { hr = GetZapDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } else if (dwCacheFlags & ASM_CACHE_DOWNLOAD) { if (pszCustomPath != NULL) { // Use custom path as the base StrCpy(pszPath, pszCustomPath); StrCat(pszPath, FUSION_CACHE_DIR_DOWNLOADED_SZ); } else { // Else use the default hr = GetDownloadDir(&pszCacheLoc); if(hr != S_OK) goto exit; StrCpy(pszPath, pszCacheLoc); } } else { // Assert; } exit : return hr; }
STDAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath, PDWORD pcchPath) { HRESULT hr = S_OK; LPWSTR pszTemp = NULL; DWORD dwLen=0; if( !pcchPath || !dwCacheFlags || (dwCacheFlags & (dwCacheFlags-1))) return E_INVALIDARG; if(dwCacheFlags & ASM_CACHE_ZAP) { hr = GetZapDir(&pszTemp); } else if(dwCacheFlags & ASM_CACHE_GAC) { hr = GetGACDir(&pszTemp); } else if(dwCacheFlags & ASM_CACHE_DOWNLOAD) { hr = GetDownloadDir(&pszTemp); } else { hr = E_INVALIDARG; } if(FAILED(hr)) goto exit; dwLen = lstrlen(pszTemp); if(pwzCachePath && (*pcchPath > dwLen)) { StrCpy(pwzCachePath, pszTemp); } else { hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } *pcchPath = dwLen+1; exit : return hr; }
HRESULT CreateMutexForCache() { HRESULT hr=S_OK; CCriticalSection cs(&g_csInitClb); LPWSTR pszFusion = L"__Fusion_Cache_Mutex_"; LPWSTR pszCache = NULL; TCHAR szMutexName[MAX_PATH+1]; HANDLE hMutex; hr = cs.Lock(); if (FAILED(hr)) goto exit; if(g_hCacheMutex) goto exit; if(FAILED(hr = GetDownloadDir(&pszCache))) { // This guys does not have download cache; so we don't need mutex. hr = S_OK; g_hCacheMutex = INVALID_HANDLE_VALUE; goto exit; } if(FAILED(hr = CreateHandleName(pszFusion, pszCache, szMutexName))) goto exit; // Create the Mutex hMutex = CreateMutex(NULL, FALSE, szMutexName); if(!hMutex) { hr = FusionpHresultFromLastError(); } else { hr = S_OK; g_hCacheMutex = hMutex; } exit : return hr; }
bool CUpdateWizard::SetLocalFile() { wxString filename = m_urlFile; int pos = filename.Find('/', true); if (pos != -1) filename = filename.Mid(pos + 1); const CLocalPath defaultDownloadDir = GetDownloadDir(); CLocalPath downloadDir(COptions::Get()->GetOption(OPTION_UPDATECHECK_DOWNLOADDIR)); if (downloadDir.empty() || !downloadDir.Exists()) downloadDir = defaultDownloadDir; const int flags = wxFD_SAVE | wxFD_OVERWRITE_PROMPT; const wxString& ext = filename.Right(4); wxString type; if (ext == _T(".exe")) type = _("Executable"); if (ext == _T(".bz2")) type = _("Archive"); else type = _("Package"); wxString filter = wxString::Format(_T("%s (*%s)|*%s"), type.c_str(), ext.c_str(), ext.c_str()); wxFileDialog dialog(this, _("Select download location for package"), downloadDir.GetPath(), filename, filter, flags); if (dialog.ShowModal() != wxID_OK) return false; wxString targetFile; if (!downloadDir.SetPath(dialog.GetPath(), &targetFile)) { wxMessageBox(_("Error, file name cannot be parsed.")); return false; } if (downloadDir != defaultDownloadDir) COptions::Get()->SetOption(OPTION_UPDATECHECK_DOWNLOADDIR, downloadDir.GetPath()); else COptions::Get()->SetOption(OPTION_UPDATECHECK_DOWNLOADDIR, _T("")); { wxLogNull log; wxRemoveFile(downloadDir.GetPath() + targetFile); } if (wxFileName::FileExists(downloadDir.GetPath() + targetFile)) { wxMessageBox(_("Error, local file exists but cannot be removed")); return false; } const wxString file = downloadDir.GetPath() + targetFile + _T(".tmp"); m_localFile = file; int i = 1; while (wxFileName::FileExists(m_localFile)) { i++; m_localFile = file + wxString::Format(_T("%d"), i); } return true; }