Exemple #1
0
void CPPgDirectories::OnBnClickedAddUNC()
{
	InputBox inputbox;
	inputbox.SetLabels(GetResString(IDS_UNCFOLDERS), GetResString(IDS_UNCFOLDERS), _T("\\\\Server\\Share"));
	if (inputbox.DoModal() != IDOK)
		return;
	CString unc=inputbox.GetInput();

	// basic unc-check 
	if (!PathIsUNC(unc)){
		AfxMessageBox(GetResString(IDS_ERR_BADUNC), MB_ICONERROR);
		return;
	}

	if (unc.Right(1) == _T("\\"))
		unc.Delete(unc.GetLength()-1, 1);

	for (POSITION pos = thePrefs.shareddir_list.GetHeadPosition();pos != 0;){
		if (unc.CompareNoCase(thePrefs.shareddir_list.GetNext(pos))==0)
			return;
	}
	for (int posi = 0; posi < m_ctlUncPaths.GetItemCount(); posi++){
		if (unc.CompareNoCase(m_ctlUncPaths.GetItemText(posi, 0)) == 0)
			return;
	}

	m_ctlUncPaths.InsertItem(m_ctlUncPaths.GetItemCount(), unc);
	SetModified();
}
String getURL(IDataObject* dataObject, bool& success, String* title)
{
    STGMEDIUM store;
    String url;
    success = false;
    if (getWebLocData(dataObject, url, title)) {
        success = true;
        return url;
    } else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
        //URL using unicode
        UChar* data = (UChar*)GlobalLock(store.hGlobal);
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) {
        //URL using ascii
        char* data = (char*)GlobalLock(store.hGlobal);
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) {
        //file using unicode
        wchar_t* data = (wchar_t*)GlobalLock(store.hGlobal);
        if (data && data[0] && (PathFileExists(data) || PathIsUNC(data))) {
            wchar_t fileURL[INTERNET_MAX_URL_LENGTH];
            DWORD fileURLLength = sizeof(fileURL) / sizeof(fileURL[0]);
            if (SUCCEEDED(::UrlCreateFromPathW(data, fileURL, &fileURLLength, 0))) {
                url = String((UChar*)fileURL);
                if (title)
                    *title = url;
            }
        }
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(filenameFormat(), &store))) {
        //filename using ascii
        char* data = (char*)GlobalLock(store.hGlobal);
        if (data && data[0] && (PathFileExistsA(data) || PathIsUNCA(data))) {
            char fileURL[INTERNET_MAX_URL_LENGTH];
            DWORD fileURLLength = sizeof(fileURL) / sizeof(fileURL[0]);
            if (SUCCEEDED(::UrlCreateFromPathA(data, fileURL, &fileURLLength, 0))) {
                url = fileURL;
                if (title)
                    *title = url;
            }
        }
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    }
    return url;
}
String getURL(IDataObject* dataObject, DragData::FilenameConversionPolicy filenamePolicy, bool& success, String* title)
{
    STGMEDIUM store;
    String url;
    success = false;
    if (getWebLocData(dataObject, url, title))
        success = true;
    else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
        // URL using Unicode
        UChar* data = static_cast<UChar*>(GlobalLock(store.hGlobal));
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) {
        // URL using ASCII
        char* data = static_cast<char*>(GlobalLock(store.hGlobal));
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);
        ReleaseStgMedium(&store);
        success = true;
    }
#if PLATFORM(CF)
    else if (filenamePolicy == DragData::ConvertFilenames) {
        if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) {
            // file using unicode
            wchar_t* data = static_cast<wchar_t*>(GlobalLock(store.hGlobal));
            if (data && data[0] && (PathFileExists(data) || PathIsUNC(data))) {
                RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar*)data, wcslen(data)));
                if (urlFromPath(pathAsCFString.get(), url)) {
                    if (title)
                        *title = url;
                    success = true;
                }
            }
            GlobalUnlock(store.hGlobal);
            ReleaseStgMedium(&store);
        } else if (SUCCEEDED(dataObject->GetData(filenameFormat(), &store))) {
            // filename using ascii
            char* data = static_cast<char*>(GlobalLock(store.hGlobal));
            if (data && data[0] && (PathFileExistsA(data) || PathIsUNCA(data))) {
                RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCString(kCFAllocatorDefault, data, kCFStringEncodingASCII));
                if (urlFromPath(pathAsCFString.get(), url)) {
                    if (title)
                        *title = url;
                    success = true;
                }
            }
            GlobalUnlock(store.hGlobal);
            ReleaseStgMedium(&store);
        }
    }
#endif
    return url;
}
Exemple #4
0
void CPPgDirectories::FillUncList(void)
{
	m_ctlUncPaths.DeleteAllItems();

	for (POSITION pos = thePrefs.shareddir_list.GetHeadPosition(); pos != 0; )
	{
		CString folder = thePrefs.shareddir_list.GetNext(pos);
		if (PathIsUNC(folder))
			m_ctlUncPaths.InsertItem(0, folder);
	}
}
Exemple #5
0
        bool is_network_path(const std::wstring& path)
        {
            wchar_t buff[MAX_PATH];
            return
#if defined(ONECORE)
                PathIsUNCEx(path.c_str(), nullptr)
#else
                PathIsUNC(path.c_str())
#endif
                || (GetVolumePathName(path.c_str(), buff, MAX_PATH) && GetDriveType(buff) == DRIVE_REMOTE);
        }
void Explorerplusplus::HandleTreeViewSelection(void)
{
	HTREEITEM		hItem;
	LPITEMIDLIST	pidlDirectory = NULL;
	TCHAR			szDirectory[MAX_PATH];
	TCHAR			szRoot[MAX_PATH];
	UINT			uDriveType;
	BOOL			bNetworkPath = FALSE;

	if(!m_bSynchronizeTreeview)
	{
		return;
	}

	pidlDirectory = m_pActiveShellBrowser->QueryCurrentDirectoryIdl();

	GetDisplayName(pidlDirectory,szDirectory,SIZEOF_ARRAY(szDirectory),SHGDN_FORPARSING);

	if(PathIsUNC(szDirectory))
	{
		bNetworkPath = TRUE;
	}
	else
	{
		StringCchCopy(szRoot,SIZEOF_ARRAY(szRoot),szDirectory);
		PathStripToRoot(szRoot);
		uDriveType = GetDriveType(szRoot);

		bNetworkPath = (uDriveType == DRIVE_REMOTE);
	}

	/* To improve performance, do not automatically sync the
	treeview with network or UNC paths. */
	if(!bNetworkPath)
	{
		hItem = m_pMyTreeView->LocateItem(pidlDirectory);

		if(hItem != NULL)
		{
			/* TVN_SELCHANGED is NOT sent when the new selected
			item is the same as the old selected item. It is only
			sent when the two are different.
			Therefore, the only case to handle is when the treeview
			selection is changed by browsing using the listview. */
			if(TreeView_GetSelection(m_hTreeView) != hItem)
				m_bSelectingTreeViewDirectory = TRUE;

			SendMessage(m_hTreeView,TVM_SELECTITEM,(WPARAM)TVGN_CARET,(LPARAM)hItem);
		}
	}

	CoTaskMemFree(pidlDirectory);
}
String getURL(IDataObject* dataObject, bool& success, String* title)
{
    STGMEDIUM store;
    String url;
    success = false;
    if (getWebLocData(dataObject, url, title)) {
        success = true;
        return url;
    } else if (SUCCEEDED(dataObject->GetData(urlWFormat(), &store))) {
        //URL using unicode
        UChar* data = (UChar*)GlobalLock(store.hGlobal);
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);      
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(urlFormat(), &store))) {
        //URL using ascii
        char* data = (char*)GlobalLock(store.hGlobal);
        url = extractURL(String(data), title);
        GlobalUnlock(store.hGlobal);      
        ReleaseStgMedium(&store);
        success = true;
    } else if (SUCCEEDED(dataObject->GetData(filenameWFormat(), &store))) {
        //file using unicode
        wchar_t* data = (wchar_t*)GlobalLock(store.hGlobal);
        if (data && data[0] && (PathFileExists(data) || PathIsUNC(data))) {
            RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCharacters(kCFAllocatorDefault, (const UniChar*)data, wcslen(data)));
            if (urlFromPath(pathAsCFString.get(), url)) {
                if (title)
                    *title = url;
                success = true;
            }
        }
        GlobalUnlock(store.hGlobal);      
        ReleaseStgMedium(&store);
    } else if (SUCCEEDED(dataObject->GetData(filenameFormat(), &store))) {
        //filename using ascii
        char* data = (char*)GlobalLock(store.hGlobal);       
        if (data && data[0] && (PathFileExistsA(data) || PathIsUNCA(data))) {
            RetainPtr<CFStringRef> pathAsCFString(AdoptCF, CFStringCreateWithCString(kCFAllocatorDefault, data, kCFStringEncodingASCII));
            if (urlFromPath(pathAsCFString.get(), url)) {
                if (title)
                    *title = url;
                success = true;
            }
        }
        GlobalUnlock(store.hGlobal);      
        ReleaseStgMedium(&store);
    }
    return url;
}
Exemple #8
0
static void loadURL(BSTR urlBStr)
{
    IWebFrame* frame = 0;
    IWebMutableURLRequest* request = 0;
    static BSTR methodBStr = 0;

    if (!methodBStr)
        methodBStr = SysAllocString(TEXT("GET"));

    if (urlBStr && urlBStr[0] && (PathFileExists(urlBStr) || PathIsUNC(urlBStr))) {
        TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
        DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
        if (SUCCEEDED(UrlCreateFromPath(urlBStr, fileURL, &fileURLLength, 0)))
            urlBStr = fileURL;
    }

    HRESULT hr = gWebView->mainFrame(&frame);
    if (FAILED(hr))
        goto exit;

    hr = CoCreateInstance(CLSID_WebMutableURLRequest, 0, CLSCTX_ALL, IID_IWebMutableURLRequest, (void**)&request);
    if (FAILED(hr))
        goto exit;

    hr = request->initWithURL(urlBStr, WebURLRequestUseProtocolCachePolicy, 0);
    if (FAILED(hr))
        goto exit;

    hr = request->setHTTPMethod(methodBStr);
    if (FAILED(hr))
        goto exit;

    hr = frame->loadRequest(request);
    if (FAILED(hr))
        goto exit;

    SetFocus(gViewWindow);

exit:
    if (frame)
        frame->Release();
    if (request)
        request->Release();
}
HRESULT PathConvertToUNC(PCWSTR pszPath, PWSTR *ppszUNC)
{
    *ppszUNC = NULL;

    HRESULT hr;
    if (PathIsUNC(pszPath))
    {
        hr = SHStrDup(pszPath, ppszUNC);
    }
    else
    {
        hr = PathConvertMappedDriveToUNC(pszPath, ppszUNC);
        if (FAILED(hr))
        {
            hr = PathConvertLocalToUNC(pszPath, ppszUNC);
        }
    }
    return hr;
}
Exemple #10
0
//
// Do checking of the .exe type in the background so the UI doesn't
// get hung up while we scan.  This is particularly important with
// the .exe is over the network or on a floppy.
//
void CheckRunInSeparateThread( LPVOID lpVoid )
{
    LONG lBinaryType;
    DWORD cch;
    LPTSTR lpszFilePart;
    TCHAR szFile[MAX_PATH+1];
    TCHAR szFullFile[MAX_PATH+1];
    TCHAR szExp[MAX_PATH+1];
    HWND hDlg = (HWND)lpVoid;
    BOOL fCheck = TRUE, fEnable = FALSE;

    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread created and running") );

    while( g_bCheckRunInSep )
    {

        WaitForSingleObject( g_hCheckNow, INFINITE );
        ResetEvent( g_hCheckNow );

        if (g_bCheckRunInSep)
        {
            LPRUNDLG_DATA lprd;
            LPTSTR pszT;
            BOOL f16bit = FALSE;

            szFile[0] = TEXT('\0');
            szFullFile[0] = TEXT('\0');
            cch = 0;
            GetWindowText( GetDlgItem( hDlg, IDD_COMMAND ), szFile, MAX_PATH );
            // Remove & throw away arguments
            PathRemoveBlanks(szFile);

            if (PathIsUNC(szFile) || IsRemoteDrive(DRIVEID(szFile)))
            {
                f16bit = TRUE;
                fCheck = FALSE;
                fEnable = TRUE;
                goto ChangeTheBox;
            }

            // if the unquoted sting exists as a file just use it

            if (!PathFileExists(szFile))
            {
                pszT = PathGetArgs(szFile);
                if (*pszT)
                    *(pszT - 1) = TEXT('\0');

                PathUnquoteSpaces(szFile);
            }



            if (szFile[0])
            {
                ExpandEnvironmentStrings( szFile, szExp, MAX_PATH );
                szExp[ MAX_PATH ] = TEXT('\0');

                if (PathIsUNC(szExp) || IsRemoteDrive(DRIVEID(szExp)))
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                    goto ChangeTheBox;
                }

                cch = SearchPath(  NULL,
                                   szExp,
                                   TEXT(".EXE"),
                                   MAX_PATH+1,
                                   szFullFile,
                                   &lpszFilePart
                                  );
            }

            if ((cch != 0) && (cch <= MAX_PATH))
            {
                if ( (GetBinaryType( szFullFile, &lBinaryType) &&
                     (lBinaryType==SCS_WOW_BINARY))
                    )
                {
                    f16bit = TRUE;
                    fCheck = FALSE;
                    fEnable = TRUE;
                } else {
                    f16bit = FALSE;
                    fCheck = TRUE;
                    fEnable = FALSE;
                }

            } else {

                f16bit = FALSE;
                fCheck = TRUE;
                fEnable = FALSE;
            }

ChangeTheBox:
            CheckDlgButton( hDlg, IDD_RUNINSEPARATE, fCheck ? 1 : 0 );
            EnableWindow( GetDlgItem( hDlg, IDD_RUNINSEPARATE ), fEnable );

            ENTERCRITICAL;
            lprd = (LPRUNDLG_DATA)GetWindowLong(hDlg, DWL_USER);
            if (lprd)
            {
                if (f16bit)
                    lprd->dwFlags |= RFD_WOW_APP;
                else
                    lprd->dwFlags &= (~RFD_WOW_APP);
            }
            LEAVECRITICAL;

        }

    }

    CloseHandle( g_hCheckNow );
    g_hCheckNow = NULL;
    DebugMsg( DM_TRACE, TEXT("CheckRunInSeparateThread exiting now...") );
    ExitThread( 0 );

}
Exemple #11
0
HANDLE WINAPI Bio_CreateFileW( LPCWSTR lpFileName, 
	DWORD dwDesiredAccess, 
	DWORD dwShareMode, 
	LPSECURITY_ATTRIBUTES lpSecurityAttributes, 
	DWORD dwCreationDisposition, 
	DWORD dwFlagsAndAttributes, 
	HANDLE hTemplateFile )
{
	if((dwDesiredAccess == (GENERIC_WRITE | GENERIC_READ)) || (dwDesiredAccess == GENERIC_WRITE)){
		char tDestPath[1024];
		memset(tDestPath, 0, sizeof(tDestPath));
		wsprintfA(tDestPath, "%S", lpFileName);

		if(0 == dwShareMode){
			return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
				lpSecurityAttributes, dwCreationDisposition,
				dwFlagsAndAttributes, hTemplateFile);
		}

		if((dwFlagsAndAttributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY){
			return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
				lpSecurityAttributes, dwCreationDisposition,
				dwFlagsAndAttributes, hTemplateFile);
		}
		
		if((dwFlagsAndAttributes & FILE_ATTRIBUTE_COMPRESSED) == FILE_ATTRIBUTE_COMPRESSED){
			return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
				lpSecurityAttributes, dwCreationDisposition,
				dwFlagsAndAttributes, hTemplateFile);
		}
		
		if((dwFlagsAndAttributes & FILE_FLAG_DELETE_ON_CLOSE) == FILE_FLAG_DELETE_ON_CLOSE){
			return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
				lpSecurityAttributes, dwCreationDisposition,
				dwFlagsAndAttributes, hTemplateFile);
		}

		string stDp(tDestPath);
		if(PathIsNetworkPath(tDestPath) || PathIsUNC(tDestPath) || PathIsRelative(tDestPath) || string::npos != stDp.find(".zip")){
			return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
				lpSecurityAttributes, dwCreationDisposition,
				dwFlagsAndAttributes, hTemplateFile);
		}

		string sWcPath;
		string sDestPath(tDestPath);
		int pos = sDestPath.find(":\\");
		if(1 == pos && (CREATE_ALWAYS == dwCreationDisposition || OPEN_ALWAYS == dwCreationDisposition) && IsWorkCopy(tDestPath, sWcPath)){
			if(PathFileExists(tDestPath) && (GetFileAttributes(tDestPath) != FILE_ATTRIBUTE_DIRECTORY)){
				if(IsReadOnly(tDestPath)){
					CopyCreateFileW(NULL, dwDesiredAccess,dwShareMode,
						lpSecurityAttributes,dwCreationDisposition,
						dwFlagsAndAttributes,hTemplateFile);
					return INVALID_HANDLE_VALUE;
				}
			}
		}
	}

	return CopyCreateFileW(lpFileName, dwDesiredAccess, dwShareMode,
		lpSecurityAttributes, dwCreationDisposition,
		dwFlagsAndAttributes, hTemplateFile);
}