Beispiel #1
0
int wmain(int argc, wchar_t *argv[]) {
	if (argc < 2) {
		printf("usage: ReviveInjector.exe [/handle] <process path/process handle>\n");
		return -1;
	}

	WCHAR LogPath[MAX_PATH];
	if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, LogPath)))
	{
		wcsncat(LogPath, L"\\Revive", MAX_PATH);
		
		BOOL exists = PathFileExists(LogPath);
		if (!exists)
			exists = CreateDirectory(LogPath, NULL);

		wcsncat(LogPath, L"\\ReviveInjector.txt", MAX_PATH);
		if (exists)
			g_LogFile = _wfopen(LogPath, L"w");
	}

	LOG("Launched injector with: %ls\n", GetCommandLine());

	bool xr = !IsSteamVRRunning();
	WCHAR path[MAX_PATH] = { 0 };
	for (int i = 1; i < argc; i++)
	{
		if (wcscmp(argv[i], L"/xr") == 0)
		{
			xr = true;
		}
		else if (wcscmp(argv[i], L"/revive") == 0)
		{
			xr = false;
		}
		else if (wcscmp(argv[i], L"/handle") == 0)
		{
			return OpenProcessAndInject(argv[++i], xr);
		}
		else if (wcscmp(argv[i], L"/base") == 0)
		{
			if (!GetOculusBasePath(path, MAX_PATH))
				return -1;
			wnsprintf(path, MAX_PATH, L"%s\\%s ", path, argv[++i]);
		}
		else if (wcscmp(argv[i], L"/library") == 0)
		{
			if (!GetDefaultLibraryPath(path, MAX_PATH))
				return -1;
			wnsprintf(path, MAX_PATH, L"%s\\%s ", path, argv[++i]);
		}
		else
		{
			// Concatenate all other arguments
			wcsncat(path, argv[i], MAX_PATH);
			wcsncat(path, L" ", MAX_PATH);
		}
	}

	return CreateProcessAndInject(path, xr);
}
HRESULT CChildFrame::_RecursionExtractData(LPCTSTR lpszRoot, HTREEITEM hCurrItem, CTreeViewCtrlEx * pTreeView) 
{ 
    HRESULT hr = S_OK; 
    CTreeItem tiCurr(hCurrItem, pTreeView); 
    TREE_ITEM_DATA * pTmp = (TREE_ITEM_DATA *)tiCurr.GetData(); 
    if (NULL == pTmp) { 
        return hr; 
    } 

    TCHAR szPathCopy[MAX_PATH] = { 0 }; 
    lstrcpyn(szPathCopy, lpszRoot, _countof(szPathCopy)); 

    PathAddBackslash(szPathCopy); 

    TCHAR szCurrName[MAX_PATH/2] = { 0 }; 
    tiCurr.GetText(szCurrName, _countof(szCurrName)); 
    AdjustFileName(szCurrName); 
    
    if (STGTY_STORAGE == pTmp->dwStgType) 
    { 
        TCHAR *pIter = szCurrName; 
        while (*pIter && pIter<szCurrName+lstrlen(szCurrName)) 
        { 
            if(*pIter == '.') { *pIter = '_'; } 
            pIter ++; 
        } 

        TCHAR szNowPath[MAX_PATH] = { 0 }; 
        wnsprintf(szNowPath, _countof(szNowPath), _T("%s%s"), szPathCopy, szCurrName); 
        ::SHCreateDirectoryEx(*pTreeView, szNowPath, NULL); 
    } 
    else if (STGTY_STREAM == pTmp->dwStgType)
    { 
        TCHAR szFileName[MAX_PATH] = { 0 }; 
        wnsprintf(szFileName, _countof(szFileName), _T("%s%s"), szPathCopy, szCurrName); 

        CComPtr<IStream> spFile; 
        hr = pTmp->spStgOrStrm->QueryInterface(&spFile); 
        if (FAILED(hr)) return hr; 

        hr = WriteStreamToFile(szFileName, spFile); 
    } 

    lstrcat(szPathCopy, szCurrName); 

    HTREEITEM hChild = tiCurr.GetChild(); 

    while (NULL != hChild) 
    { 
        _RecursionExtractData(szPathCopy, hChild, pTreeView); 
        hChild = CTreeItem(hChild, pTreeView).GetNextSibling(); 
    } 

    return hr; 
} 
Beispiel #3
0
HRESULT OpenLogFile()
{
#define REG_VAL_FUSION_LOG_FILE    TEXT("FusionLogFile")

    HRESULT hr=E_FAIL;
    HANDLE  hFile = NULL;
    WCHAR       szBuf[MAX_PATH+1];
    if (PAL_FetchConfigurationString(TRUE, REG_VAL_FUSION_LOG_FILE, szBuf, MAX_PATH - 50))
        hr = S_OK;

    if(hr == S_OK)
    {
        wnsprintf(szBuf, MAX_PATH, L"%s_%d.txt", szBuf, GetCurrentProcessId());
        hFile = CreateFile(szBuf, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL,
                             CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hFile == INVALID_HANDLE_VALUE) 
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
            goto exit;
        }

        g_hLogFile = hFile;
    }

exit:

    return hr;
}
Beispiel #4
0
void XMenuBar::parseXMenuBarInfo(const TString &input, char *szReturnValue) {
	const TString prop(input.gettok(1));

	// Iterate through the names of menus added to XMenuBar.
	// N = 0 returns total number of menus
	// $xmenubar() [menu] [N]
	if (prop == "menu") {
		const int i = input.gettok(2).to_int();

		if ((i < 0) || (i > (int) this->m_vpXMenuBar.size())) {
			Dcx::errorex("$!xpopup().menubar", "Invalid index: %d", i);
			return;
		}

		// Return number of menus in menubar.
		if (i == 0)
			wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", (int) this->m_vpXMenuBar.size());
		// Return name of specified menu.
		else
			lstrcpyn(szReturnValue, this->m_vpXMenuBar[i -1]->getName().to_chr(), MIRC_BUFFER_SIZE_CCH);

		return;
	}

	szReturnValue[0] = 0;
}
Beispiel #5
0
/*
 * Convenience method to send an error-level message using the previously defined
 * default error-level message code that includes the valuE from GetLastError().
 * Specifically the message format is "%100s: error %08x" where the %100s string
 * placeholder is the supplied function name and the %08x int placeholder is the
 * value from GetLastError()
 */
void
EventLogger::SvcReportLastError(LPCTSTR szFunction)
{
	TCHAR buffer[128];
	wnsprintf(buffer, 128, TEXT("%100s: error %08x"), szFunction, GetLastError());
	SendEvent(EVENTLOG_ERROR_TYPE, defaultErrorCode, buffer);
}
Beispiel #6
0
DWORD WINAPI HashVerifyThread( PTSTR pszPath )
{
	// We will need to free the memory allocated for the data when done
	PBYTE pbRawData;

	// First, activate our manifest and AddRef our host
	ULONG_PTR uActCtxCookie = ActivateManifest(TRUE);
	ULONG_PTR uHostCookie = HostAddRef();

	// Allocate the context data that will persist across this session
	HASHVERIFYCONTEXT hvctx;

	// It's important that we zero the memory since an initial value of zero is
	// assumed for many of the elements
	ZeroMemory(&hvctx, sizeof(hvctx));

	// Prep the path
    HashNormalizeString(pszPath);
	StrTrim(pszPath, TEXT(" "));
	hvctx.pszPath = pszPath;

	// Load the raw data
	pbRawData = HashVerifyLoadData(&hvctx);

	if (hvctx.pszFileData && (hvctx.hList = SLCreateEx(TRUE)))
	{
		HashVerifyParseData(&hvctx);

		DialogBoxParam(
			g_hModThisDll,
			MAKEINTRESOURCE(IDD_HASHVERF),
			NULL,
			HashVerifyDlgProc,
			(LPARAM)&hvctx
		);

		SLRelease(hvctx.hList);
	}
	else if (*pszPath)
	{
		// Technically, we could reach this point by either having a file read
		// error or a memory allocation error, but I really don't feel like
		// doing separate messages for what are supposed to be rare edge cases.
		TCHAR szFormat[MAX_STRINGRES], szMessage[0x100];
		LoadString(g_hModThisDll, IDS_HV_LOADERROR_FMT, szFormat, countof(szFormat));
		wnsprintf(szMessage, countof(szMessage), szFormat, pszPath);
		MessageBox(NULL, szMessage, NULL, MB_OK | MB_ICONERROR);
	}

	free(pbRawData);
	free(pszPath);

	// Clean up the manifest activation and release our host
	DeactivateManifest(uActCtxCookie);
	HostRelease(uHostCookie);

	InterlockedDecrement(&g_cRefThisDll);
	return(0);
}
Beispiel #7
0
HRESULT DeleteAssemblyBits(LPCTSTR pszManifestPath)
{
    HRESULT hr = S_OK;
    TCHAR szPath[MAX_PATH+1];
    DWORD           dwLen = 0;

    if(!pszManifestPath)
        goto exit;

    dwLen = lstrlen(pszManifestPath);
    ASSERT(dwLen <= MAX_PATH);

    lstrcpy(szPath, pszManifestPath);

    // making c:\foo\a.dll -> c:\foo for RemoveDirectoryAndChd()
    while( szPath[dwLen] != '\\' && dwLen > 0 )
        dwLen--;

    if( szPath[dwLen] == '\\')
        szPath[dwLen] = '\0';

    //  remove the disk file
    hr = RemoveDirectoryAndChildren(szPath);

    if( (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )  
            || (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) )
    {
        // file is not there, this not an error.
        hr = S_OK;
        goto exit;
    }

    if(hr == S_OK)
    {
        // making c:\foo\a.dll -> c:\foo for RemoveDirectory();
        while( szPath[dwLen] != '\\' && dwLen > 0 )
            dwLen--;

        if( szPath[dwLen] == '\\')
            szPath[dwLen] = '\0';

        // now that we have two levels of dirs...try to remove parent dir also
        // this succeeds only if it is empty, don't worry about return value.
        RemoveDirectory(szPath);
    }
#ifdef DEBUG
    else
    {
        WCHAR szMsgBuf[MAX_PATH*2 + 1];
        wnsprintf( szMsgBuf, MAX_PATH*2, L"     DeleteAssemblyBits:  RemoveDirectoryAndChildren FAILED for <%s> hr = <%x> \r\n",
                                      szPath, hr );
        WriteToLogFile(szMsgBuf);
    }
#endif  // DEBUG

exit :
    return hr;
}
Beispiel #8
0
void FusionFormatGUID(GUID guid, LPWSTR pszBuf, DWORD cchSize)
{

    ASSERT(pszBuf && cchSize);

    wnsprintf(pszBuf,  cchSize, L"{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
            guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1],
            guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
}
BOOL WINAPI RegDelete( HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpSubst )
{
	LONG lResult;
	TCHAR szJoinedKey[0x7F];
	if (lpSubst) wnsprintf(szJoinedKey, countof(szJoinedKey), lpSubKey, lpSubst);

	lResult = SHDeleteKey(hKey, (lpSubst) ? szJoinedKey : lpSubKey);
	return(lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND);
}
void AudioGroupFilePresenter::populatePageColumn(VSTEditor& editor, int collectionIdx, int fileIdx, int groupIdx) {
  LVITEM item = {};
  item.mask = LVIF_TEXT | LVIF_PARAM;

  ListView_DeleteAllItems(editor.m_pageListView);
  if (collectionIdx < m_iteratorVec.size()) {
    CollectionIterator& it = m_iteratorVec[collectionIdx];
    if (fileIdx < it->second->m_iteratorVec.size()) {
      AudioGroupCollection::GroupIterator& git = it->second->m_iteratorVec[fileIdx];
      if (groupIdx < git->second->m_groupTokens.size()) {
        AudioGroupDataCollection::GroupToken& groupTok = git->second->m_groupTokens[groupIdx];
        if (groupTok.m_song) {
          std::map<uint8_t, const amuse::SongGroupIndex::PageEntry*> sortPages;
          for (auto& pair : groupTok.m_song->m_normPages)
            sortPages[pair.first] = pair.second;

          size_t idx = 0;
          for (auto& pair : sortPages) {
            wchar_t name[256];
            wnsprintf(name, 256, L"%d (%s)", pair.first, GMNames[pair.first] ? GMNames[pair.first] : L"???");
            item.pszText = name;
            item.iItem = idx++;
            item.lParam = pair.first;
            ListView_InsertItem(editor.m_pageListView, &item);
          }

          sortPages.clear();
          for (auto& pair : groupTok.m_song->m_drumPages)
            sortPages[pair.first] = pair.second;

          for (auto& pair : sortPages) {
            wchar_t name[256];
            wnsprintf(name, 256, L"%d (%s)", pair.first, GMPercNames[pair.first] ? GMPercNames[pair.first] : L"???");
            item.pszText = name;
            item.iItem = idx++;
            item.lParam = 0x80000000 | pair.first;
            ListView_InsertItem(editor.m_pageListView, &item);
          }
        }
      }
    }
  }
}
Beispiel #11
0
void RemoveDirectoryIfEmpty(LPWSTR pszCachePath, LPWSTR pszParentDir)
{
    WCHAR pszDirPath[MAX_PATH+1];

    if( pszCachePath[0] && pszParentDir[0])
    {
        wnsprintf(pszDirPath, MAX_PATH, L"%s\\%s", pszCachePath, pszParentDir);
        RemoveDirectory(pszDirPath);
    }
}
Beispiel #12
0
//--------------------------------------------------------------------------
// CreateHandleName
//--------------------------------------------------------------------------
HRESULT CreateHandleName(LPWSTR pszBase, LPWSTR pszSpecific, LPWSTR pszMutexName)
{
    // Locals
    HRESULT     hr=S_OK;
    DWORD       cchName;
    LPWSTR      pszT;
    LPWSTR      pszPrefix = L"Global\\Rotor";
    WCHAR       szName[MAX_PATH+1];

    // Invalid Args
    ASSERT(pszBase && pszSpecific && pszMutexName);

    // Compute Length
    // 16 == file_size_max_digits_
    cchName = lstrlen(pszBase) + lstrlen(pszSpecific) + lstrlen(pszPrefix);

    if(cchName >= MAX_PATH)
    {
        hr = E_FAIL;
        goto exit;
    }

    // Format the name
    wnsprintf(szName, (cchName+1), L"%s%s", pszBase, pszSpecific);

    // Remove backslashes from this string
    for (pszT=(szName); *pszT != '\0'; pszT++)
    {
        // Replace Back Slashes
        if (*pszT == '\\')
        {
            // With _
            *pszT = '_';
        }
    }

    if(!_wcslwr(szName))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    pszMutexName[0] = '\0';

    {
        StrCpy(pszMutexName, pszPrefix);
    }

    StrCat(pszMutexName, szName);

exit:
    // Done
    return hr;
}
Beispiel #13
0
void stack_build_string(callback_state *state, short line_no){
	wchar_t temp[256];
	if (state->index==0 || state->group_name==NULL)
		return;

	if (wcscmp(state->group_name, state->class_name) == 0) {
		if (wcscmp(state->group_name, state->routine_name) == 0) {
			wnsprintf(temp, 256, L"%s Line: %d", state->routine_name, line_no);
		} else {
			wnsprintf(temp, 256, L"%s.%s Line: %d", state->group_name, state->routine_name, line_no);
		}
	} else {
		wnsprintf(temp, 256, L"%s.%s.%s Line: %d", state->group_name, state->class_name, state->routine_name, line_no);
	}
	if (state->values != NULL){
		value *val=ot_array_index(state->vm, state->values, state->index -1);
		set_string(state->vm, temp, val);
	}
	if (state->trace!=NULL)
		lstrcatW(state->trace, temp);
}
Beispiel #14
0
void DcxDivider::parseInfoRequest( TString & input, char * szReturnValue ) {

	const TString prop(input.gettok(3));

	// [NAME] [ID] [PROP]
	if (prop == "position") {
		int iDivPos = 0;

		SendMessage(this->m_Hwnd, DV_GETDIVPOS, (WPARAM) NULL, (LPARAM) &iDivPos);
		wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", iDivPos);
		return;
	}
	else if (prop == "isvertical") {
		wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", (GetWindowStyle(this->m_Hwnd) & DVS_VERT));
		return;
	}

	if ( this->parseGlobalInfoRequest( input, szReturnValue ) )
		return;

	szReturnValue[0] = 0;
}
Beispiel #15
0
HKEY WINAPI RegOpen( HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpSubst )
{
	HKEY hKeyRet = NULL;
	TCHAR szJoinedKey[0x7F];
	if (lpSubst) wnsprintf(szJoinedKey, countof(szJoinedKey), lpSubKey, lpSubst);

	if (RegCreateKeyEx(hKey, (lpSubst) ? szJoinedKey : lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKeyRet, NULL) == ERROR_SUCCESS)
	{
		Wow64DisableRegReflection(hKeyRet);
		return(hKeyRet);
	}

	return(NULL);
}
Beispiel #16
0
LRESULT CAddressBand::OnTipText(UINT idControl, NMHDR *notifyHeader, BOOL &bHandled)
{
    if (notifyHeader->hwndFrom == fGoButton)
    {
        WCHAR szText[MAX_PATH];
        WCHAR szFormat[MAX_PATH];
        LPNMTBGETINFOTIP pGIT = (LPNMTBGETINFOTIP)notifyHeader;

        if (::GetWindowTextW(fEditControl, szText, _countof(szText)))
        {
            LoadStringW(_AtlBaseModule.GetResourceInstance(), IDS_GOBUTTONTIPTEMPLATE, szFormat, _countof(szFormat));
            wnsprintf(pGIT->pszText, pGIT->cchTextMax, szFormat, szText);
        }
        else
            *pGIT->pszText = 0;
    }
    return 0;
}
void AudioGroupFilePresenter::populateGroupColumn(VSTEditor& editor, int collectionIdx, int fileIdx) {
  LVITEM item = {};
  item.mask = LVIF_TEXT;

  ListView_DeleteAllItems(editor.m_groupListView);
  ListView_DeleteAllItems(editor.m_pageListView);
  if (collectionIdx < m_iteratorVec.size()) {
    CollectionIterator& it = m_iteratorVec[collectionIdx];
    if (fileIdx < it->second->m_iteratorVec.size()) {
      size_t idx = 0;
      AudioGroupCollection::GroupIterator& git = it->second->m_iteratorVec[fileIdx];
      for (AudioGroupDataCollection::GroupToken& gtok : git->second->m_groupTokens) {
        wchar_t name[256];
        wnsprintf(name, 256, L"%d (%s)", gtok.m_groupId, gtok.m_song ? L"Song" : L"SFX");
        item.pszText = name;
        item.iItem = idx++;
        ListView_InsertItem(editor.m_groupListView, &item);
      }
    }
  }
}
Beispiel #18
0
VOID WINAPI HashSaveDlgInit( PHASHSAVECONTEXT phsctx )
{
    HWND hWnd = phsctx->hWnd;

    // Load strings
    {
        SetControlText(hWnd, IDC_PAUSE, IDS_HS_PAUSE);
        SetControlText(hWnd, IDC_CANCEL, IDS_HS_CANCEL);
    }

    // Set the window icon and title
    {
        PTSTR pszFileName = phsctx->ofn.lpstrFile + phsctx->ofn.nFileOffset;
        TCHAR szFormat[MAX_STRINGRES];
        LoadString(g_hModThisDll, IDS_HS_TITLE_FMT, szFormat, countof(szFormat));
        wnsprintf(phsctx->scratch.sz, countof(phsctx->scratch.sz), szFormat, pszFileName);

        SendMessage(
            hWnd,
            WM_SETTEXT,
            0,
            (LPARAM)phsctx->scratch.sz
        );

        SendMessage(
            hWnd,
            WM_SETICON,
            ICON_BIG, // No need to explicitly set the small icon
            (LPARAM)LoadIcon(g_hModThisDll, MAKEINTRESOURCE(IDI_FILETYPE))
        );
    }

    // Initialize miscellaneous stuff
    {
        phsctx->dwFlags = 0;
        phsctx->cTotal = 0;
    }
}
Beispiel #19
0
/*!
* \brief Displays output text to the mIRC status window.
*/
void mIRCLinker::echo(const TCHAR *data) {
	wnsprintf(m_pData, MIRC_BUFFER_SIZE_CCH, TEXT("//echo -s %s"), data);
	SendMessage(m_mIRCHWND, WM_MCOMMAND, MIRCF_UNICODE, m_iMapCnt);
}
Beispiel #20
0
void mIRCLinker::signal(const TCHAR *msg) {
	wnsprintf(m_pData, MIRC_BUFFER_SIZE_CCH, TEXT("//.signal -n DCX %s"), msg);
	SendMessage(m_mIRCHWND, WM_MCOMMAND, MIRCF_UNICODE, m_iMapCnt);
}
Beispiel #21
0
/*!
* \brief $xdid Parsing Function
*
* \param input [NAME] [ID] [PROP] (OPTIONS)
* \param szReturnValue mIRC Data Container
*
* \return > void
*/
void DcxEdit::parseInfoRequest(TString &input, char *szReturnValue) {
	const int numtok = input.numtok( );

	const TString prop(input.gettok( 3 ));

	// [NAME] [ID] [PROP] [N]
	if (prop == "text") {
		if (this->isStyle(ES_MULTILINE)) {
			if (numtok > 3) {
				const int nLine = input.gettok( 4 ).to_int();

				if (nLine > 0 && nLine <= this->m_tsText.numtok("\r\n")) {
					lstrcpyn(szReturnValue, this->m_tsText.gettok(nLine, "\r\n").to_chr(), MIRC_BUFFER_SIZE_CCH);
					return;
				}
			}
		}
		else {
			lstrcpyn(szReturnValue, this->m_tsText.to_chr(), MIRC_BUFFER_SIZE_CCH);
			return;
		}
	}
	// [NAME] [ID] [PROP]
	else if (prop == "num") {
		if (this->isStyle(ES_MULTILINE))
			wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", this->m_tsText.numtok("\r\n"));
		else
			lstrcpy(szReturnValue,"1");	// single line control so always 1 line.
		return;
	}
	// [NAME] [ID] [PROP]
	else if (prop == "ispass") {
		if (this->isStyle(ES_PASSWORD))
			lstrcpy(szReturnValue, "$true");
		else
			lstrcpy(szReturnValue, "$false");

		return;
	}
   // [NAME] [ID] [PROP]
	else if (prop == "isreadonly") {
      if (this->isStyle(ES_READONLY))
			lstrcpy(szReturnValue, "$true");
		else
			lstrcpy(szReturnValue, "$false");

		return;
	}
	// [NAME] [ID] [PROP]
	else if (prop == "caretpos") {
		DWORD dwAbsoluteStartSelPos = 0;

		// caret startsel position
		SendMessage(this->m_Hwnd, EM_GETSEL, (WPARAM) &dwAbsoluteStartSelPos, NULL);

		if (this->isStyle(ES_MULTILINE)) {
			// current line
			const int iLinePos = SendMessage(this->m_Hwnd, EM_LINEFROMCHAR, (WPARAM)-1, NULL);
			// line offset
			const int iAbsoluteCharPos = (int) SendMessage(this->m_Hwnd, EM_LINEINDEX, (WPARAM)-1, NULL);

			wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d %d", iLinePos +1, dwAbsoluteStartSelPos - iAbsoluteCharPos);
		}
		else {
			// return selstart
			wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d %d", 1, dwAbsoluteStartSelPos);
		}

		return;
	}
	else if (prop == "selstart") {
		DWORD dwSelStart = 0; // selection range starting position

		SendMessage(this->m_Hwnd, EM_GETSEL, (WPARAM) &dwSelStart, NULL);
		wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", dwSelStart);
		return;
	}
	else if (prop == "selend") {
		DWORD dwSelEnd = 0;   // selection range ending position

		SendMessage(this->m_Hwnd, EM_GETSEL, NULL, (LPARAM) &dwSelEnd);
		wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d", dwSelEnd);
		return;
	}
	else if (prop == "sel") {
		DWORD dwSelStart = 0; // selection range starting position
		DWORD dwSelEnd = 0;   // selection range ending position

		SendMessage(this->m_Hwnd, EM_GETSEL, (WPARAM) &dwSelStart, (LPARAM) &dwSelEnd);
		wnsprintf(szReturnValue, MIRC_BUFFER_SIZE_CCH, "%d %d", dwSelStart, dwSelEnd);
		return;
	}
	else if (prop == "seltext") {
		DWORD dwSelStart = 0; // selection range starting position
		DWORD dwSelEnd = 0;   // selection range ending position

		SendMessage(this->m_Hwnd, EM_GETSEL, (WPARAM) &dwSelStart, (LPARAM) &dwSelEnd);
		lstrcpyn(szReturnValue, this->m_tsText.mid(dwSelStart, dwSelEnd - dwSelStart).to_chr(), MIRC_BUFFER_SIZE_CCH);
		return;
	}
	else if (prop == "cue") {
		if (this->m_tsCue.len())
			lstrcpyn(szReturnValue, this->m_tsCue.to_chr(), MIRC_BUFFER_SIZE_CCH);
		return;
	}
	else if (this->parseGlobalInfoRequest(input, szReturnValue))
		return;

	szReturnValue[0] = 0;
}
Beispiel #22
0
BOOL WINAPI HashCalcWriteResult( PHASHCALCCONTEXT phcctx, PHASHCALCITEM pItem )
{
	PCTSTR pszHash;
	PVOID pvLine;
	INT cchLine, cbLine;  // Length of line, in TCHARs or BYTEs, EXCLUDING the terminator

	if (!pItem->bValid)
		return(FALSE);

	// Set szFormat is necessary
	if (phcctx->szFormat[0] == 0)
	{
		// Did I ever mention that I hate SFV?
		// The reason we tracked cchMax was because of this idiotic format
		if (phcctx->ofn.nFilterIndex == 1)
		{
			wnsprintf(
				phcctx->szFormat,
				countof(phcctx->szFormat),
				TEXT("%%-%ds %%s\r\n"),
				phcctx->cchMax - phcctx->cchAdjusted
			);
		}
		else
		{
			SSStaticCpy(phcctx->szFormat, TEXT("%s *%s\r\n"));
		}
	}

	// Translate the filter index to a hash
	switch (phcctx->ofn.nFilterIndex)
	{
		case 1: pszHash = pItem->results.szHexCRC32; break;
		case 2: pszHash = pItem->results.szHexMD4;   break;
		case 3: pszHash = pItem->results.szHexMD5;   break;
		case 4: pszHash = pItem->results.szHexSHA1;  break;
	}

	// Format the line
	#define HashCalcFormat(a, b) wnsprintf(phcctx->scratch.sz, MAX_PATH_BUFFER, phcctx->szFormat, a, b)
	cchLine = (phcctx->ofn.nFilterIndex == 1) ?
		HashCalcFormat(pItem->szPath + phcctx->cchAdjusted, pszHash) : // SFV
		HashCalcFormat(pszHash, pItem->szPath + phcctx->cchAdjusted);  // everything else
	#undef HashCalcFormat

	if (cchLine > 0)
	{
		// Convert to the correct encoding
		switch (phcctx->opt.dwSaveEncoding)
		{
			case 0:
			{
				// UTF-8
				#ifdef UNICODE
				cbLine = WStrToUTF8(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1;
				#else
				         AStrToWStr(phcctx->scratch.szA, phcctx->scratch.szW, countof(phcctx->scratch.szW));
				cbLine = WStrToUTF8(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1;
				#endif

				pvLine = phcctx->scratch.szA;
				break;
			}

			case 1:
			{
				// UTF-16
				#ifndef UNICODE
				cchLine = AStrToWStr(phcctx->scratch.szA, phcctx->scratch.szW, countof(phcctx->scratch.szW)) - 1;
				#endif

				cbLine = cchLine * sizeof(WCHAR);
				pvLine = phcctx->scratch.szW;
				break;
			}

			case 2:
			{
				// ANSI
				#ifdef UNICODE
				cbLine = WStrToAStr(phcctx->scratch.szW, phcctx->scratch.szA, countof(phcctx->scratch.szA)) - 1;
				#else
				cbLine = cchLine;
				#endif

				pvLine = phcctx->scratch.szA;
				break;
			}
		}

		if (cbLine > 0)
		{
			INT cbWritten;
			WriteFile(phcctx->hFileOut, pvLine, cbLine, &cbWritten, NULL);
			if (cbLine != cbWritten) return(FALSE);
		}
		else return(FALSE);
	}
	else return(FALSE);

	return(TRUE);
}
LRESULT CChildFrame::OnFileExtractData(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{ 
    HRESULT hr = E_FAIL; 

    TREE_ITEM_DATA * pTmp = (TREE_ITEM_DATA *)m_pData.GetData(); 

    if (NULL == pTmp) return 0; 

    TCHAR szText[MAX_PATH] = { 0 }; 
    m_pData.GetText(szText, _countof(szText)); 
    ATLTRACE(_T("---------%s\n"), szText); 

    if (STGTY_STREAM == pTmp->dwStgType) 
    { 
        TCHAR szFileName[MAX_PATH] = { 0 }; 

        if (NULL == _tcschr(szText, '.')) 
        { 
            _tcscat(szText, _T(".bin")); 
        } 

        AdjustFileName(szText); 

        TCHAR szFilter[MAX_PATH] = { 0 }; 
        { 
            // assembling filter string 
            TCHAR szAllFiles[MAX_PATH] = { 0 }; 
            AtlLoadString(IDS_ALL_FILES, szAllFiles, _countof(szAllFiles)); 

            wnsprintf(szFilter, _countof(szFilter), _T("%s(*.*)|*.*||"), szAllFiles); 
        } 

        CModifiedFileDialog fd ( FALSE, _T(""), szText, OFN_HIDEREADONLY, szFilter, m_hWnd ); 

        
        if ( IDOK != fd.DoModal(this->m_hWnd) ) 
            return 0; 
        
        lstrcpyn(szFileName, fd.m_szFileName, _countof(szFileName)); 

        if (PathFileExists(szFileName)) { 
            TCHAR szFmt[MAX_PATH] = { 0 }; 
            AtlLoadString(IDS_FILE_EXISTS, szFmt, _countof(szFmt)); 
            TCHAR szMsg[MAX_PATH*2] = { 0 }; 
            wnsprintf(szMsg, _countof(szMsg), szFmt, szFileName); 
            if ( IDYES != AtlMessageBox(m_hWnd, szMsg, IDS_WARNING, MB_YESNO|MB_ICONWARNING)) { 
                return 0; 
            } 
        } 

        CComPtr<IStream> spFile; 
        hr = pTmp->spStgOrStrm->QueryInterface(&spFile); 
        if (FAILED(hr)) return hr; 

        hr = WriteStreamToFile(szFileName, spFile); 
    } 

    else if (STGTY_STORAGE == pTmp->dwStgType) 
    { 
        CModifiedFolderDialog fd ( GetTopLevelParent(), IDS_SELECT_DIR, 
            BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE ); 

        TCHAR szCurrPath[MAX_PATH] = { 0 }; 
        GetCurrentDirectory(_countof(szCurrPath), szCurrPath); 

        fd.SetInitialDir( szCurrPath ); 

        if ( IDOK != fd.DoModal() ) 
            return 0; 

        lstrcpyn(szCurrPath, fd.GetFolderPath(), _countof(szCurrPath)); 
        PathAddBackslash(szCurrPath); 

        SHCreateDirectoryEx(*this, szCurrPath, NULL); 

        // recursion 
        _RecursionExtractData(szCurrPath, m_pData, &m_wndCatalog); 
    } 

    return 0; 
} 
BOOL CChildFrame::OpenCompositeDocument(LPCTSTR lpszFileName) 
{ 
    USES_CONVERSION; 

    CWaitCursor wait; 

    HRESULT hResult = E_FAIL; 
    IStorage * ptrRootStg = NULL; // root storage 
    HWND hWnd = (HWND)m_hWnd; 

    hResult = ::StgIsStorageFile( T2COLE(m_szFileName) ); 
    if( S_OK != hResult ) 
    { 
        TCHAR szFmt[MAX_PATH] = { 0 }; 
        AtlLoadString(IDS_OPEN_ARCHIVE_ERROR, szFmt, _countof(szFmt)); 

        TCHAR szOut[MAX_PATH*2] = { 0 }; 
        wnsprintf(szOut, _countof(szOut), szFmt, lpszFileName); 

        AtlMessageBox(m_hWnd, szOut, IDS_ERROR, MB_OK|MB_ICONSTOP); 
        return FALSE; 
    }

    // open the Compound document 
    hResult = ::StgOpenStorage( T2COLE(m_szFileName), NULL, 
        STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 
        0, 0, &ptrRootStg ); 
    if( FAILED(hResult) )
    { 
        TCHAR szFmt[MAX_PATH] = { 0 }; 
        AtlLoadString(IDS_OPEN_FILE_ERROR, szFmt, _countof(szFmt)); 

        TCHAR szError[MAX_PATH] = { 0 }; 

        TCHAR szOut[MAX_PATH*2] = { 0 }; 
        wnsprintf(szOut, _countof(szOut), szFmt, 
            lpszFileName, GetErrorString(S_OK, szError, _countof(szError))); 

        AtlMessageBox(m_hWnd, szOut, IDS_ERROR, MB_OK|MB_ICONSTOP); 
        return FALSE;
    } 

    TREE_ITEM_DATA * pRootData = new TREE_ITEM_DATA(ptrRootStg, STGTY_STORAGE); 

    HTREEITEM hRoot = m_wndCatalog.InsertItem ( 
        TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
        PathFindFileName(m_szFileName), 
        0, 1, TVIS_EXPANDED, 0, 
        reinterpret_cast<LPARAM>(pRootData), 
        NULL, NULL); 


    std::stack < StgInfo > FolderStack; 
    HTREEITEM htiParent = hRoot; 
    IEnumSTATSTG * ptrEnum = NULL; 

    hResult = ptrRootStg->EnumElements( 0, NULL, 0, &ptrEnum ); 
    if( FAILED(hResult) ) { 
        ptrRootStg->Release(); 
        return 0; 
    } 

    TCHAR szSwap[MAX_PATH] = { 0 }; 

	LARGE_INTEGER nStorageLength;
	nStorageLength.QuadPart = 0;
    STATSTG StatStg = { 0 }; 
    while( S_OK == hResult ) 
    { 
        hResult = ptrEnum->Next( 1, &StatStg, NULL ); 
        if( S_FALSE == hResult ) 
        { 
            ptrRootStg->Release(); 
            ptrEnum->Release(); 

            // m_wndCatalog.Expand(strFolder); 

            if( !FolderStack.empty() ) 
            { 
				TCHAR szCurText[MAX_PATH] = {0};
				m_wndCatalog.GetItemText(htiParent, szCurText, _countof(szCurText));
				CString strTotal;
				strTotal.Format(TEXT("%s(%ld)"), szCurText, nStorageLength);
				m_wndCatalog.SetItemText(htiParent, strTotal);

				ptrRootStg  = FolderStack.top().pStg; 
                ptrEnum     = FolderStack.top().pEnum; 
                htiParent   = FolderStack.top().hParent; 
                FolderStack.pop(); 

                hResult = S_OK; 
            } 

            continue; 
        } 

        switch(StatStg.type) 
        { 
        case STGTY_STORAGE: // 是存储对象, "文件夹" 
            { 
				//先清零
				nStorageLength.QuadPart = 0;
                IStorage * ptrChildStg = NULL;

                HRESULT hr = ptrRootStg->OpenStorage( StatStg.pwcsName, NULL, 
                    STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 
                    0, 0, &ptrChildStg ); 
                if( SUCCEEDED(hr) ) 
                { 
                    TREE_ITEM_DATA * pData = new TREE_ITEM_DATA(ptrChildStg, StatStg.type); 

                    HTREEITEM hFolder = m_wndCatalog.InsertItem ( 
                        TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
                        WCHAR2TCHAR(StatStg.pwcsName, szSwap, _countof(szSwap)), 
                        0, 1, TVIS_EXPANDED, 0, 
                        reinterpret_cast<LPARAM>(pData), 
                        htiParent, NULL); 

                    // 父存储入栈 
                    FolderStack.push( StgInfo(ptrRootStg, ptrEnum, htiParent) );

                    // 子存储替代父存储 
                    ptrRootStg = ptrChildStg; 
                    htiParent = hFolder; 
                    hr = ptrChildStg->EnumElements( 0, NULL, 0, &ptrEnum ); 
                } 
            } 
            break; 
        case STGTY_STREAM:  // 是流, "文件" 
            { 
                CComPtr<IStream> spStream; 
                HRESULT hr = ptrRootStg->OpenStream(StatStg.pwcsName, NULL, 
                    STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &spStream); 
                ATLASSERT(SUCCEEDED(hr)); 
				
				LARGE_INTEGER nSeekPos;
				nSeekPos.QuadPart = 0LL;
				ULARGE_INTEGER nLength = {0};
				hr = spStream->Seek(nSeekPos, STREAM_SEEK_END, &nLength);
				CString strStreamName;
				WCHAR2TCHAR(StatStg.pwcsName, szSwap, _countof(szSwap));
				if (SUCCEEDED(hr))
				{
					nStorageLength.QuadPart += nLength.QuadPart;
					strStreamName.Format(TEXT("%s(%ld)"), szSwap, nLength);
				}
				else
				{
					strStreamName.Format(TEXT("%s(0)"), szSwap);
				}
                TREE_ITEM_DATA * pData = new TREE_ITEM_DATA(spStream, StatStg.type); 
                m_wndCatalog.InsertItem ( 
                    TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
                    strStreamName, 
                    2, 2, TVIS_EXPANDED, 0, 
                    reinterpret_cast<LPARAM>(pData), 
                    htiParent, NULL); 
            } 
            break; 
        case STGTY_LOCKBYTES: 
            ATLTRACE(_T("===== STGTY_LOCKBYTES %d ====="), StatStg.type); 
            break; 
        case STGTY_PROPERTY: 
            ATLTRACE(_T("===== STGTY_PROPERTY %d ====="), StatStg.type); 
            break; 
        default: 
            ATLASSERT(!_T("Unknown storage type!!!")); 
            break; 
        } 

        ::CoTaskMemFree( StatStg.pwcsName ); // 释放名称所使用的内存 
    }

    return 0;
}
Beispiel #25
0
HRESULT MoveAllFilesFromDir(LPWSTR pszSrcDirPath, LPWSTR pszDestDirPath)
{
    HRESULT hr = S_OK;
    TCHAR szDestFilePath[MAX_PATH+1];
    TCHAR szBuf[MAX_PATH+1];
    HANDLE hf = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA fd;
    StrCpy(szBuf, pszSrcDirPath);
    StrCat(szBuf, TEXT("\\*"));

    if ((hf = FindFirstFile(szBuf, &fd)) == INVALID_HANDLE_VALUE) 
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    StrCpy(szBuf, pszSrcDirPath);

    do
    {
        if ( (StrCmp(fd.cFileName, TEXT(".")) == 0) || 
             (StrCmp(fd.cFileName, TEXT("..")) == 0))
            continue;

        wnsprintf(szBuf, MAX_PATH-1, TEXT("%s\\%s"), pszSrcDirPath, fd.cFileName);
        if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
        {
            wnsprintf(szDestFilePath, MAX_PATH-1, TEXT("%s\\%s"), pszDestDirPath, fd.cFileName);
            if(!MoveFile( szBuf, szDestFilePath))
            {
                hr = FusionpHresultFromLastError();
#ifdef DEBUG
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"   MoveFile(%s, %s) FAILED with  <%x> \r\n",
                                              szBuf, szDestFilePath, hr );
                WriteToLogFile(szMsgBuf);
#endif  // DEBUG

                if( (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )  
                       || (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) )
                {
                    hr = S_OK;
                }
                else
                {
                    break;
                }
            }
        }
        else
        {
        }

    } while (FindNextFile(hf, &fd));

    if ((hr == S_OK) && (GetLastError() != ERROR_NO_MORE_FILES))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    if (hf != INVALID_HANDLE_VALUE)
    {
        FindClose(hf);
        hf = INVALID_HANDLE_VALUE;
    }

    // after moving all files attempt to remove the source dir
    if (!RemoveDirectory(pszSrcDirPath)) 
    {
        hr = FusionpHresultFromLastError();
#ifdef DEBUG
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"     RemoveDirectory(%s) FAILED in MoveAllFilesFromDir with  <%x> \r\n",
                                              pszSrcDirPath, hr );
                WriteToLogFile(szMsgBuf);
#endif  // DEBUG

        if( (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )  
               || (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) )
        {
            hr = S_OK;
        }
    }

exit :

    if (hf != INVALID_HANDLE_VALUE)
    {
        FindClose(hf);
        hf = INVALID_HANDLE_VALUE;
    }

    return hr;
}
Beispiel #26
0
HRESULT DeleteAssemblyFiles(DWORD dwCacheFlags, LPCWSTR pszCustomPath, LPWSTR pszManFilePath)
{
    HRESULT hr = S_OK;
    LPTSTR pszTemp=NULL;
    LPWSTR pszManifestPath=pszManFilePath;
    TCHAR szPendDelDirPath[MAX_PATH+1];
    TCHAR szAsmDirPath[MAX_PATH+1];
#define TEMP_PEND_DIR 10

    DWORD dwLen = 0;

    if(!pszManifestPath)
    {
        hr = E_FAIL;
        goto exit;
    }

    dwLen = lstrlen(pszManifestPath);
    ASSERT(dwLen <= MAX_PATH);

    lstrcpy(szAsmDirPath, pszManifestPath);

    pszTemp = PathFindFileName(szAsmDirPath);

    if(pszTemp > szAsmDirPath)
    {
        *(pszTemp-1) = L'\0';
    }

    dwLen = MAX_PATH;
    hr = GetPendingDeletePath( pszCustomPath, dwCacheFlags, szPendDelDirPath, &dwLen);
    if (FAILED(hr)) {
        goto exit;
    }

    if(lstrlen(szPendDelDirPath) + TEMP_PEND_DIR  > MAX_PATH)
    {
        hr = HRESULT_FROM_WIN32(FUSION_E_INVALID_NAME);
        goto exit;
    }

    GetRandomFileName( szPendDelDirPath, TEMP_PEND_DIR);

    if(!MoveFile( szAsmDirPath, szPendDelDirPath))
    {
        hr = FusionpHresultFromLastError();
#ifdef DEBUG
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"     MoveFile((%s, %s)) FAILED in DeleteAssemblyFiles with  <%x> \r\n",
                                              szAsmDirPath, szPendDelDirPath, hr );
                WriteToLogFile(szMsgBuf);
#endif  // DEBUG

        if( (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) )  
               || (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) )
        {
            hr = S_OK;
            goto exit;
        }
    }
    else
    {
        hr = RemoveDirectoryAndChildren(szPendDelDirPath);
        hr = S_OK; // don't worry about passing back error here. its already in pend-del dir.
        goto exit;
    }

    // looks like there are some in-use files here.
    // move all the asm files to pend del dir.
    if(!CreateDirectory(szPendDelDirPath, NULL))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    hr = MoveAllFilesFromDir(szAsmDirPath, szPendDelDirPath);

    if(hr == S_OK)
    {
        // assembly deleted successfully delete/pend all temp files.
        hr = RemoveDirectoryAndChildren(szPendDelDirPath);
        hr = S_OK; // don't worry about passing back error here. its already in pend-del dir.
    }
    else
    {
        // could not delete assembly; restore all files back to original state.
#ifdef DEBUG
        HRESULT hrTemp =
#endif
        MoveAllFilesFromDir(szPendDelDirPath, szAsmDirPath);
#ifdef DEBUG
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"     Restored all files back to <%s> hr = <%x> hrTemp = <%x> \r\n",
                                              szAsmDirPath, hr, hrTemp );
                WriteToLogFile(szMsgBuf);
#endif  // DEBUG

        hr = HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION);
    }

exit :

    if(hr == S_OK)
    {
        pszTemp = PathFindFileName(szAsmDirPath);

        if(pszTemp > szAsmDirPath)
        {
            *(pszTemp-1) = L'\0';
        }

        // now that we have two levels of dirs...try to remove parent dir also
        // this succeeds only if it is empty, don't worry about return value.
        RemoveDirectory(szAsmDirPath);
    }

    return hr;
}
Beispiel #27
0
STDAPI CopyPDBs(IAssembly *pAsm)
{
    HRESULT                                       hr = S_OK;
    IAssemblyName                                *pName = NULL;
    IAssemblyModuleImport                        *pModImport = NULL;
    DWORD                                         dwSize;
    WCHAR                                         wzAsmCachePath[MAX_PATH];
    WCHAR                                         wzFileName[MAX_PATH];
    WCHAR                                         wzSourcePath[MAX_PATH];
    WCHAR                                         wzPDBName[MAX_PATH];
    WCHAR                                         wzPDBSourcePath[MAX_PATH];
    WCHAR                                         wzPDBTargetPath[MAX_PATH];
    WCHAR                                         wzModPath[MAX_PATH];
    LPWSTR                                        wzCodebase=NULL;
    LPWSTR                                        wzModName = NULL;
    DWORD                                         dwIdx = 0;
    LPWSTR                                        wzTmp = NULL;

    if (!pAsm) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    if (pAsm->GetAssemblyLocation(NULL) == E_NOTIMPL) {
        // This is a registered "known assembly" (ie. the process EXE).
        // We don't copy PDBs for the process EXE because it's never
        // shadow copied.

        hr = S_FALSE;
        goto Exit;
    }

    // Find the source location. Make sure this is a file:// URL (ie. we
    // don't support retrieving the PDB over http://).

    hr = pAsm->GetAssemblyNameDef(&pName);
    if (FAILED(hr)) {
        goto Exit;
    }

    wzCodebase = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!wzCodebase)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    dwSize = MAX_URL_LENGTH * sizeof(WCHAR);
    hr = pName->GetProperty(ASM_NAME_CODEBASE_URL, (void *)wzCodebase, &dwSize);
    if (FAILED(hr)) {
        goto Exit;
    }

    if (!UrlIsW(wzCodebase, URLIS_FILEURL)) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    dwSize = MAX_PATH;
    hr = PathCreateFromUrlWrap(wzCodebase, wzSourcePath, &dwSize, 0);
    if (FAILED(hr)) {
        goto Exit;
    }

    wzTmp = PathFindFileName(wzSourcePath);
    ASSERT(wzTmp > (LPWSTR)wzSourcePath);
    *wzTmp = L'\0';
        
   // Find the target location in the cache.
   
    dwSize = MAX_PATH;
    hr = pAsm->GetManifestModulePath(wzAsmCachePath, &dwSize);
    if (FAILED(hr)) {
        goto Exit;
    }

    wzTmp = PathFindFileName(wzAsmCachePath);
    ASSERT(wzTmp > (LPWSTR)wzAsmCachePath);

    StrCpy(wzFileName, wzTmp);
    *wzTmp = L'\0';


    // Copy the manifest PDB.

    // Hack for now
    dwSize = MAX_PATH;
    hr = GetPDBName(wzFileName, wzPDBName, &dwSize);
    if (FAILED(hr)) {
        goto Exit;
    }

    wnsprintfW(wzPDBSourcePath, MAX_PATH, L"%ws%ws", wzSourcePath, wzPDBName);
    wnsprintf(wzPDBTargetPath, MAX_PATH, L"%ws%ws", wzAsmCachePath, wzPDBName);

    if (GetFileAttributes(wzPDBTargetPath) == (DWORD) -1 && lstrcmpiW(wzPDBSourcePath, wzPDBTargetPath)) {
        CopyFile(wzPDBSourcePath, wzPDBTargetPath, TRUE);
    }

    // Copy the module PDBs.

    dwIdx = 0;
    while (SUCCEEDED(hr)) {
        hr = pAsm->GetNextAssemblyModule(dwIdx++, &pModImport);

        if (SUCCEEDED(hr)) {
            if (pModImport->IsAvailable()) {
                dwSize = MAX_PATH;
                hr = pModImport->GetModulePath(wzModPath, &dwSize);
                if (FAILED(hr)) {
                    SAFERELEASE(pModImport);
                    goto Exit;
                }

                wzModName = PathFindFileName(wzModPath);
                ASSERT(wzModName);

                dwSize = MAX_PATH;
                hr = GetPDBName(wzModName, wzPDBName, &dwSize);
                if (FAILED(hr)) {
                    SAFERELEASE(pModImport);
                    goto Exit;
                }

                wnsprintfW(wzPDBSourcePath, MAX_PATH, L"%ws%ws", wzSourcePath,
                           wzPDBName);
                wnsprintfW(wzPDBTargetPath, MAX_PATH, L"%ws%ws", wzAsmCachePath,
                           wzPDBName);

                if (GetFileAttributes(wzPDBTargetPath) == (DWORD) -1 && lstrcmpiW(wzPDBSourcePath, wzPDBTargetPath)) {
                    CopyFile(wzPDBSourcePath, wzPDBTargetPath, TRUE);
                }
            }

            SAFERELEASE(pModImport);
        }
    }

    // Copy complete. Return success.

    if (hr == HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS)) {
        hr = S_OK;
    }

Exit:
    SAFERELEASE(pName);
    SAFEDELETEARRAY(wzCodebase);
    return hr;
}
Beispiel #28
0
HRESULT RemoveDirectoryAndChildren(LPWSTR szDir)
{
    HRESULT hr = S_OK;
    HANDLE hf = INVALID_HANDLE_VALUE;
    TCHAR szBuf[MAX_PATH];
    WIN32_FIND_DATA fd;
    LPWSTR wzCanonicalized=NULL;
    WCHAR wzPath[MAX_PATH];
    DWORD dwSize;

    if (!szDir || !lstrlenW(szDir)) {
        hr = E_INVALIDARG;
        goto Exit;
    }

    wzPath[0] = L'\0';

    wzCanonicalized = NEW(WCHAR[MAX_URL_LENGTH+1]);
    if (!wzCanonicalized)
    {
        hr = E_OUTOFMEMORY;
        goto Exit;
    }

    dwSize = MAX_URL_LENGTH;
    hr = UrlCanonicalizeW(szDir, wzCanonicalized, &dwSize, 0);
    if (FAILED(hr)) {
        goto Exit;
    }

    dwSize = MAX_PATH;
    hr = PathCreateFromUrlW(wzCanonicalized, wzPath, &dwSize, 0);
    if (FAILED(hr)) {
        goto Exit;
    }

    // Cannot delete root. Path must have greater length than "x:\"
    if (lstrlenW(wzPath) < 4) {
        ASSERT(0);
        hr = HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED);
        goto Exit;
    }

    if (RemoveDirectory(wzPath)) {
        goto Exit;
    }

    // ha! we have a case where the directory is probbaly not empty

    StrCpy(szBuf, wzPath);
    StrCat(szBuf, TEXT("\\*"));

    if ((hf = FindFirstFile(szBuf, &fd)) == INVALID_HANDLE_VALUE) {
        hr = FusionpHresultFromLastError();
        goto Exit;
    }

    do {

        if ( (StrCmp(fd.cFileName, TEXT(".")) == 0) || 
             (StrCmp(fd.cFileName, TEXT("..")) == 0))
            continue;

        wnsprintf(szBuf, MAX_PATH-1, TEXT("%s\\%s"), wzPath, fd.cFileName);
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {

            SetFileAttributes(szBuf, 
                FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_NORMAL);

            if (FAILED((hr=RemoveDirectoryAndChildren(szBuf)))) {
                goto Exit;
            }

        } else {

            SetFileAttributes(szBuf, FILE_ATTRIBUTE_NORMAL);
            if (!DeleteFile(szBuf)) {
                hr = FusionpHresultFromLastError();
#ifdef DEBUG
                if((hr != HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
                        && (hr != HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)))
                {
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"     RemoveDirectoryAndChildren: DeleteFile(<%s>) failed hr = <%x>\r\n",
                                              szBuf, hr);
                WriteToLogFile(szMsgBuf);
                }
#endif  // DEBUG
                goto Exit;
            }
        }


    } while (FindNextFile(hf, &fd));


    if (GetLastError() != ERROR_NO_MORE_FILES) {

        hr = FusionpHresultFromLastError();
        goto Exit;
    }

    if (hf != INVALID_HANDLE_VALUE) {
        FindClose(hf);
        hf = INVALID_HANDLE_VALUE;
    }

    // here if all subdirs/children removed
    /// re-attempt to remove the main dir
    if (!RemoveDirectory(wzPath)) {
        hr = FusionpHresultFromLastError();
#ifdef DEBUG
                WCHAR szMsgBuf[MAX_PATH*2 + 1];
                wnsprintf( szMsgBuf, MAX_PATH*2, L"     RemoveDirectoryAndChildren: RemoveDirectory(<%s>) failed hr = <%x>\r\n",
                                              wzPath, hr);
                WriteToLogFile(szMsgBuf);
#endif  // DEBUG

        goto Exit;
    }

Exit:
    if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
        hr = HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION);

    if (hf != INVALID_HANDLE_VALUE)
        FindClose(hf);

    SAFEDELETEARRAY(wzCanonicalized);
    return hr;
}
Beispiel #29
0
HRESULT FlushOldAssembly(LPCWSTR pszCustomPath, LPWSTR pszAsmDirPath, LPWSTR pszManifestFileName, BOOL bForceDelete)
{
    HRESULT hr = S_OK;
    LPTSTR pszTemp=NULL, pszAsmDirName=NULL;
    TCHAR szParentDirPath[MAX_PATH+1];
    TCHAR szBuf[MAX_PATH+1];
    HANDLE hf = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA fd;

    ASSERT(pszAsmDirPath);

    lstrcpy(szParentDirPath, pszAsmDirPath);

    pszTemp = PathFindFileName(szParentDirPath);

    if(pszTemp > szParentDirPath)
    {
        *(pszTemp-1) = L'\0';
    }
    else
    {
        hr = E_UNEXPECTED;
        goto exit;
    }

    pszAsmDirName = pszTemp;
    StrCpy(szBuf, szParentDirPath);
    StrCat(szBuf, TEXT("\\*"));

    if ((hf = FindFirstFile(szBuf, &fd)) == INVALID_HANDLE_VALUE) 
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    do
    {
        if ( (StrCmp(fd.cFileName, TEXT(".")) == 0) || 
             (StrCmp(fd.cFileName, TEXT("..")) == 0))
            continue;

        if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
        {
            if(StrCmp(fd.cFileName, pszAsmDirName))
            {
                wnsprintf(szBuf, MAX_PATH, L"%s\\%s\\%s", szParentDirPath, fd.cFileName, pszManifestFileName);
                hr = CScavenger::DeleteAssembly(ASM_CACHE_DOWNLOAD, pszCustomPath, szBuf, bForceDelete);
#ifdef DEBUG
                if(hr != S_OK)
                {
                    WCHAR szMsgBuf[MAX_PATH*2 + 1];
                    wnsprintf( szMsgBuf, MAX_PATH*2, L"         Flushing <%s> returned  hr = <%x> \r\n",
                                                  szBuf, hr );
                    WriteToLogFile(szMsgBuf);
                }
#endif  // DEBUG

                if(hr != S_OK)
                    goto exit;
            }
        }
        else
        {
        }

    } while (FindNextFile(hf, &fd));

    if((hr == S_OK) && (GetLastError() != ERROR_NO_MORE_FILES))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

exit :

    if(hf != INVALID_HANDLE_VALUE)
    {
        FindClose(hf);
        hf = INVALID_HANDLE_VALUE;
    }

    return hr;
}
Beispiel #30
0
HRESULT CleanupTempDir(DWORD dwCacheFlags, LPCWSTR pszCustomPath)
{
    HRESULT hr = S_OK;
    TCHAR szPendDelDirPath[MAX_PATH+1];
    TCHAR szBuf[MAX_PATH+1];
    HANDLE hf = INVALID_HANDLE_VALUE;
    WIN32_FIND_DATA fd;

    DWORD dwLen = MAX_PATH;

    hr = GetPendingDeletePath( pszCustomPath, dwCacheFlags, szPendDelDirPath, &dwLen);
    if (FAILED(hr)) {
        goto exit;
    }

    StrCpy(szBuf, szPendDelDirPath);
    StrCat(szBuf, TEXT("\\*"));

    if((hf = FindFirstFile(szBuf, &fd)) == INVALID_HANDLE_VALUE) 
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

    do
    {
        if ( (StrCmp(fd.cFileName, TEXT(".")) == 0) || 
             (StrCmp(fd.cFileName, TEXT("..")) == 0))
            continue;

        wnsprintf(szBuf, MAX_PATH-1, TEXT("%s\\%s"), szPendDelDirPath, fd.cFileName);

        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            hr = RemoveDirectoryAndChildren(szBuf);
        }
        else
        {
            if(!DeleteFile(szBuf))
                hr = FusionpHresultFromLastError();

        }

    } while (FindNextFile(hf, &fd));

    if((hr == S_OK) && (GetLastError() != ERROR_NO_MORE_FILES))
    {
        hr = FusionpHresultFromLastError();
        goto exit;
    }

exit :

    if(hf != INVALID_HANDLE_VALUE)
    {
        FindClose(hf);
        hf = INVALID_HANDLE_VALUE;
    }

    return hr;
}