Esempio n. 1
0
//---------------------------------------------------------------------------
void __fastcall TConfigForm::btnBrowseClick(TObject *Sender)
{
	WCHAR buf[MAX_PATH];
	BROWSEINFOW bi;
	PIDLIST_ABSOLUTE pidl;

	wcscpy_s(buf, MAX_PATH, hAddressBook->Text.c_str());

	bi.hwndOwner = this->Handle;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = buf;
	bi.lpszTitle = _(L"Choose address book location").c_str();
	bi.ulFlags = BIF_EDITBOX;
	bi.lpfn = NULL;
	bi.lParam = NULL;
	bi.iImage = 0;

	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
	if ((pidl = SHBrowseForFolderW(&bi)) != NULL) {
		if (SHGetPathFromIDListW(pidl, buf))
			hAddressBook->Text = buf;
		IMalloc *pMalloc = NULL;
		SHGetMalloc(&pMalloc);
		pMalloc->Free(pidl);
		pMalloc->Release();
	}
	CoUninitialize();
}
Esempio n. 2
0
plFileName plBrowseFolder::GetFolder(const plFileName &startPath, const ST::string &title, HWND hwndOwner)
{
    BROWSEINFOW bi;
    memset(&bi, 0, sizeof(bi));
    ST::wchar_buffer titleW = title.to_wchar();
    ST::wchar_buffer startPathW = startPath.WideString();
    bi.hwndOwner    = hwndOwner;
    bi.lpszTitle    = titleW.data();
    bi.lpfn         = BrowseCallbackProc;
    bi.lParam       = (LPARAM) startPathW.data();

    LPITEMIDLIST iil = SHBrowseForFolderW(&bi);
    plFileName path;
    if (!iil) {
        // Browse failed, or cancel was selected
        path = ST::null;
    } else {
        // Browse succeded.  Get the path.
        wchar_t buffer[MAX_PATH];
        SHGetPathFromIDListW(iil, buffer);
        path = ST::string::from_wchar(buffer);
    }

    // Free the memory allocated by SHBrowseForFolder
    LPMALLOC pMalloc;
    SHGetMalloc(&pMalloc);
    pMalloc->Free(iil);
    pMalloc->Release();

    return path;
}
Esempio n. 3
0
HRESULT CBandSiteMenu::_CreateNewISFBand(HWND hwnd, REFIID riid, void** ppv)
{
    WCHAR path[MAX_PATH];
    WCHAR message[256];
    BROWSEINFOW bi = { hwnd, NULL, path };

    if (LoadStringW(GetModuleHandleW(L"browseui.dll"), IDS_BROWSEFORNEWTOOLAR, message, _countof(message)))
        bi.lpszTitle = message;
    else
        bi.lpszTitle = L"Choose a folder";

    CComHeapPtr<ITEMIDLIST> pidlSelected;
    pidlSelected.Attach(SHBrowseForFolderW(&bi));
    if (pidlSelected == NULL)
        return S_FALSE;

    CComPtr<IShellFolderBand> pISFB;
    HRESULT hr = CISFBand_CreateInstance(IID_IShellFolderBand, (PVOID*)&pISFB);
    if (FAILED_UNEXPECTEDLY(hr))
        return hr;

    hr = pISFB->InitializeSFB(NULL, pidlSelected);
    if (FAILED_UNEXPECTEDLY(hr))
        return hr;

    return pISFB->QueryInterface(riid, ppv);
}
void COptionsDirectoriesPage::SelectDirectory(LanguageStringID Title, CModifiedEditBox & EditBox, CModifiedButton & Default, CModifiedButton & selected)
{
	wchar_t Buffer[MAX_PATH], Directory[MAX_PATH];
	LPITEMIDLIST pidl;
	BROWSEINFOW bi;

	stdstr InitialDir = EditBox.GetWindowText();

	bi.hwndOwner = m_hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = Buffer;
	bi.lpszTitle = GS(Title);
	bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
	bi.lpfn = (BFFCALLBACK)SelectDirCallBack;
	bi.lParam = (DWORD)InitialDir.c_str();
	if ((pidl = SHBrowseForFolderW(&bi)) != NULL)
	{
		if (SHGetPathFromIDListW(pidl, Directory))
		{
			stdstr path;
			CPath SelectedDir(path.FromUTF16(Directory), "");
			EditBox.SetChanged(true);
			EditBox.SetWindowText(SelectedDir);
			Default.SetChanged(true);
			Default.SetCheck(BST_UNCHECKED);
			selected.SetCheck(BM_SETCHECK);
			SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
		}
	}
}
Esempio n. 5
0
BBString *bbSystemRequestDir( BBString *text,BBString *dir ){

	BBString *str=&bbEmptyString;

	if( _usew ){
		LPMALLOC shm;
		ITEMIDLIST *idlist;
		BROWSEINFOW bi={0};
		wchar_t buf[MAX_PATH],*p;

		GetFullPathNameW( bbTmpWString(dir),MAX_PATH,buf,&p );
		
		bi.hwndOwner=GetActiveWindow();
		bi.lpszTitle=bbTmpWString( text );
		bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
		bi.lpfn=BrowseForFolderCallbackW;
		bi.lParam=(LPARAM)buf;
		
		beginPanel();
		idlist=SHBrowseForFolderW(&bi);
		endPanel();
		
		if( idlist ){
			SHGetPathFromIDListW( idlist,buf );
			str=bbStringFromWString( buf );
			//SHFree( idlist );	//?!?	
		}
	} else {
		LPMALLOC shm;
		ITEMIDLIST *idlist;
		BROWSEINFOA bi={0};
		char buf[MAX_PATH],*p;
		
		GetFullPathNameA( bbTmpCString(dir),MAX_PATH,buf,&p );

		bi.hwndOwner=GetActiveWindow();
		bi.lpszTitle=bbTmpCString( text );
		bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
		bi.lpfn=BrowseForFolderCallbackA;
		bi.lParam=(LPARAM)buf;
		
		beginPanel();
		idlist=SHBrowseForFolderA(&bi);
		endPanel();
		
		if( idlist ){
			SHGetPathFromIDListA( idlist,buf );
			str=bbStringFromCString( buf );
			//SHFree( idlist );	//?!?	
		}
	}
	return str;
}
Esempio n. 6
0
wchar_t *FolderDlgInnerW(HWND hWnd, wchar_t *title, wchar_t *default_dir)
{
	BROWSEINFOW info;
	wchar_t display_name[MAX_PATH];
	FOLDER_DLG_INNER_DATA data;
	LPMALLOC pMalloc;
	wchar_t *ret = NULL;
	if (UniIsEmptyStr(title))
	{
		title = NULL;
	}
	if (UniIsEmptyStr(default_dir))
	{
		default_dir = NULL;
	}

	Zero(&data, sizeof(data));
	data.default_dir = default_dir;

	Zero(display_name, sizeof(display_name));
	Zero(&info, sizeof(info));
	info.hwndOwner = hWnd;
	info.pidlRoot = NULL;
	info.pszDisplayName = display_name;
	info.lpszTitle = title;
	info.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_SHAREABLE;
	info.lpfn = FolderDlgInnerCallbackW;
	info.lParam = (LPARAM)&data;

	if (SUCCEEDED(SHGetMalloc(&pMalloc)))
	{
		LPITEMIDLIST pidl;

		pidl = SHBrowseForFolderW(&info);

		if (pidl)
		{
			wchar_t tmp[MAX_PATH];

			if (SHGetPathFromIDListW(pidl, tmp))
			{
				ret = CopyUniStr(tmp);
			}

			pMalloc->Free(pidl);
		}

		pMalloc->Release();
	}

	return ret;
}
Esempio n. 7
0
/*************************************************************************
 * SHBrowseForFolderA [SHELL32.@]
 * SHBrowseForFolder  [SHELL32.@]
 */
LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi)
{
    BROWSEINFOW bi;
    LPITEMIDLIST lpid;
    INT len;
    LPWSTR title;

    TRACE("%p\n", lpbi);

    bi.hwndOwner = lpbi->hwndOwner;
    bi.pidlRoot = lpbi->pidlRoot;
    if (lpbi->pszDisplayName)
    {
        bi.pszDisplayName = HeapAlloc( GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR) );
        MultiByteToWideChar( CP_ACP, 0, lpbi->pszDisplayName, -1, bi.pszDisplayName, MAX_PATH );
    }
    else
        bi.pszDisplayName = NULL;

    if (lpbi->lpszTitle)
    {
        len = MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, NULL, 0 );
        title = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
        MultiByteToWideChar( CP_ACP, 0, lpbi->lpszTitle, -1, title, len );
    }
    else
        title = NULL;

    bi.lpszTitle = title;
    bi.ulFlags = lpbi->ulFlags;
    bi.lpfn = lpbi->lpfn;
    bi.lParam = lpbi->lParam;
    bi.iImage = lpbi->iImage;
    lpid = SHBrowseForFolderW( &bi );
    if (bi.pszDisplayName)
    {
        WideCharToMultiByte( CP_ACP, 0, bi.pszDisplayName, -1,
                             lpbi->pszDisplayName, MAX_PATH, 0, NULL);
        HeapFree( GetProcessHeap(), 0, bi.pszDisplayName );
    }
    HeapFree(GetProcessHeap(), 0, title);
    lpbi->iImage = bi.iImage;
    return lpid;
}
Esempio n. 8
0
HRESULT STDMETHODCALLTYPE CShellDispatch::BrowseForFolder(LONG Hwnd, BSTR Title, LONG Options, VARIANT RootFolder, Folder **ppsdf)
{
    TRACE("(%p, %lu, %ls, %lu, %s, %p)\n", this, Hwnd, Title, Options, debugstr_variant(&RootFolder), ppsdf);

    *ppsdf = NULL;

    if (!is_optional_argument(&RootFolder))
        FIXME("root folder is ignored\n");

    BROWSEINFOW bi = { 0 };
    bi.hwndOwner = reinterpret_cast<HWND>(LongToHandle(Hwnd));
    bi.lpszTitle = Title;
    bi.ulFlags = Options;

    CComHeapPtr<ITEMIDLIST> selection;
    selection.Attach(SHBrowseForFolderW(&bi));
    if (!selection)
        return S_FALSE;

    return ShellObjectCreatorInit<CFolder>(static_cast<LPITEMIDLIST>(selection), IID_PPV_ARG(Folder, ppsdf));
}
Esempio n. 9
0
static LPITEMIDLIST WINAPI SHBrowseForFolderUW(PBROWSEINFO lpbi)
{
	// BROWSEINFOA and BROWSEINFOW don't contain any actual string data,
	// so the structs can be copied.
	BROWSEINFOW wbi;
	memcpy(&wbi, lpbi, sizeof(wbi));
	
	// Convert constant strings from UTF-8 to UTF-16.
	wchar_t *lpszwTitle = NULL;
	
	if (lpbi->lpszTitle)
	{
		lpszwTitle = w32u_UTF8toUTF16(lpbi->lpszTitle);
		wbi.lpszTitle = lpszwTitle;
	}
	
	// Allocate the return buffer.
	wchar_t *pszwDisplayName = NULL;
	if (lpbi->pszDisplayName)
	{
		// This is assumed to be MAX_PATH characters.
		pszwDisplayName = (wchar_t*)malloc(MAX_PATH * sizeof(wchar_t));
		wbi.pszDisplayName = pszwDisplayName;
	}
	
	// Get the directory list entry.
	LPITEMIDLIST pidl = SHBrowseForFolderW(&wbi);
	
	// Convert the non-constant strings from UTF-16 to UTF-8.
	if (wbi.pszDisplayName)
	{
		WideCharToMultiByte(CP_UTF8, 0, wbi.pszDisplayName, MAX_PATH,
				     lpbi->pszDisplayName, MAX_PATH, NULL, NULL);
	}
	
	// Free the strings.
	free(lpszwTitle);
	free(pszwDisplayName);
	return pidl;
}
Esempio n. 10
0
struct _ITEMIDLIST *SHBrowseForFolderUTF8(struct _browseinfoA *bi)
{
  if (bi && (WDL_HasUTF8(bi->pszDisplayName) || WDL_HasUTF8(bi->lpszTitle)) AND_IS_NOT_WIN9X)
  {
    MBTOWIDE(wfn,bi->pszDisplayName);
    if (wfn_ok)
    {
      MBTOWIDE(wtxt,bi->lpszTitle);
      if (wtxt_ok)
      {
        BROWSEINFOW biw ={ bi->hwndOwner,bi->pidlRoot,wfn,wtxt,bi->ulFlags,bi->lpfn,(LPARAM)bi->lParam,bi->iImage };
        LPITEMIDLIST idlist = SHBrowseForFolderW(&biw);
        MBTOWIDE_FREE(wfn);
        MBTOWIDE_FREE(wtxt);
        return (struct _ITEMIDLIST *) idlist;
      }
      MBTOWIDE_FREE(wtxt);
    }
    MBTOWIDE_FREE(wfn);
  }
  return (struct _ITEMIDLIST *)SHBrowseForFolderA(bi);
}
Esempio n. 11
0
BOOL ChooseFolder(HWND hwnd)
{
    BOOL bRet = FALSE;
    BROWSEINFOW bi;
    ATL::CStringW szChooseFolderText;

    szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);

    ZeroMemory(&bi, sizeof(bi));
    bi.hwndOwner = hwnd;
    bi.pidlRoot = NULL;
    bi.lpszTitle = szChooseFolderText.GetString();
    bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;

    if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
    {
        ATL::CStringW szBuf;

        LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
        if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
        {
            szBuf.ReleaseBuffer();
            if (!szBuf.IsEmpty())
            {
                SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString());
                bRet = TRUE;
            }
        }
        else
        {
            szBuf.ReleaseBuffer();
        }

        CoTaskMemFree(lpItemList);
        CoUninitialize();
    }

    return bRet;
}
Esempio n. 12
0
bbString bbRequesters::RequestDir( bbString title,bbString dir ){

	CoInitialize( 0 );
	
	dir=dir.replace( "/","\\" );

	LPMALLOC shm;
	BROWSEINFOW bi={0};
	
	WCHAR buf[MAX_PATH],*p;
	GetFullPathNameW( dir.toWString(),MAX_PATH,buf,&p );
	
	bi.hwndOwner=GetActiveWindow();
	bi.lpszTitle=tmpWString( title );
	bi.ulFlags=BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
	bi.lpfn=BrowseForFolderCallbackW;
	bi.lParam=(LPARAM)buf;
	
	beginPanel();

	bbString str;
	
	if( ITEMIDLIST *idlist=SHBrowseForFolderW( &bi ) ){
		SHGetPathFromIDListW( idlist,buf );
		str=bbString( buf );
		//SHFree( idlist );	//?!?
	}
	
	endPanel();
	
	free( (void*)bi.lpszTitle );

	str=str.replace( "\\","/" );
	if( !str.endsWith( "/" ) ) str+="/";

	return str;
}
Esempio n. 13
0
QString GwtCallback::getExistingDirectory(const QString& caption,
                                         const QString& dir)
{
   QString resolvedDir = resolveAliasedPath(dir);

   QString result;
#ifdef _WIN32
   if (dir.isNull())
   {
      // Bug
      wchar_t szDir[MAX_PATH];
      BROWSEINFOW bi;
      bi.hwndOwner = pOwnerWindow_->winId();
      bi.pidlRoot = NULL;
      bi.pszDisplayName = szDir;
      bi.lpszTitle = L"Select a folder:";
      bi.ulFlags = BIF_RETURNONLYFSDIRS;
      bi.lpfn = NULL;
      bi.lpfn = 0;
      bi.iImage = -1;
      LPITEMIDLIST pidl = SHBrowseForFolderW(&bi);
      if (!pidl || !SHGetPathFromIDListW(pidl, szDir))
         result = QString();
      else
         result = QString::fromWCharArray(szDir);
   }
   else
   {
      result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir);
   }
#else
   result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir);
#endif

   webView()->page()->mainFrame()->setFocus();
   return createAliasedPath(result);
}
Esempio n. 14
0
// MW-2005-05-15: Updated for new answer command restructuring
int MCA_folder(MCStringRef p_title, MCStringRef p_prompt, MCStringRef p_initial, unsigned int p_options, MCStringRef &r_value, MCStringRef &r_result)
{
	if (MCmajorosversion >= 0x0600 && MCModeMakeLocalWindows())
		return MCA_file(p_title, p_prompt, nil, p_initial, p_options | MCA_OPTION_FOLDER_DIALOG, r_value, r_result);

// MW-2005-05-27: We'll use a static (I know bad me) to store the version
//   of the shell dll.
	static int s_shell_version = -1;
	static MCStringRef s_last_folder = MCValueRetain(kMCEmptyString);

	MCAutoStringRef t_native_filename;

	if (p_initial != NULL)
	{
		MCAutoStringRef t_std_path;

		/* UNCHECKED */ MCS_pathfromnative(p_initial, &t_std_path);
		t_native_filename = *t_std_path;
	}
	else
		t_native_filename = MCValueRetain(s_last_folder);

	if (!MCModeMakeLocalWindows())
    {
		MCAutoStringRef t_answer_path;
		MCRemoteFolderDialog(p_title, p_prompt, *t_native_filename, &t_answer_path);
        if (*t_answer_path != nil)
		{
			MCAutoStringRef t_std_path;

			/* UNCHECKED */ MCS_pathfromnative(*t_answer_path, &t_std_path);
			MCValueAssign(s_last_folder, *t_std_path);
		}
		r_value = MCValueRetain(*t_answer_path);
		return 0;
	}

	if (s_shell_version == -1)
		s_shell_version = get_dll_version(L"shell32.dll");

	bool sheet = (p_options & MCA_OPTION_SHEET) != 0;

	BROWSEINFOW bi;
	memset(&bi, 0, sizeof(BROWSEINFOW));

	Window pw;
	pw = MCModeGetParentWindow();

	if (pw != DNULL)
		bi.hwndOwner = (HWND)pw->handle.window;

	MCAutoStringRefAsWString t_prompt_wstr;
	MCAutoStringRefAsWString t_native_filename_wstr;
	/* UNCHECKED */ t_prompt_wstr.Lock(p_prompt);

	bi.pidlRoot = NULL;
	bi.lpszTitle = *t_prompt_wstr;
	bi.ulFlags = BIF_RETURNONLYFSDIRS;
	if (s_shell_version >= 500)
		bi.ulFlags |= BIF_NEWDIALOGSTYLE;
	if (*t_native_filename != nil && !MCStringIsEmpty(*t_native_filename))
	{
		t_native_filename_wstr.Lock(*t_native_filename);
		
		bi . lpfn = BrowseCallbackProc;
		bi . lParam = (LPARAM)*t_native_filename_wstr;
	}
	else
	{
		bi.lpfn = NULL;
		bi.lParam = NULL;
	}
	LPITEMIDLIST lpiil;
	LPMALLOC lpm;
	SHGetMalloc(&lpm);

	DWORD t_error;
	lpiil = SHBrowseForFolderW(&bi);
	if (lpiil == NULL)
	{
		t_error = GetLastError();
	}
	
	MCAutoArray<unichar_t> t_buffer;
	/* UNCHECKED */ t_buffer.New(MAX_PATH);

	if (lpiil != NULL && SHGetPathFromIDListW(lpiil, t_buffer.Ptr()))
	{
		if (s_last_folder != NULL)
			MCValueRelease(s_last_folder);

		size_t t_length;
		/* UNCHECKED */ StringCchLength(t_buffer.Ptr(), t_buffer.Size(), &t_length);
		/* UNCHECKED */ MCStringCreateWithChars(t_buffer.Ptr(), t_length, s_last_folder);

		MCAutoStringRef t_std_path;
		/* UNCHECKED */ MCS_pathfromnative(s_last_folder, &t_std_path);

		r_value = MCValueRetain(*t_std_path);
	}
	else
		r_result = MCSTR(MCcancelstring);

	//  SMR 1880 clear shift and button state
	waitonbutton();

	lpm->Free(lpiil);
	lpm->Release();

	return 0;
}
Esempio n. 15
0
/*
 * Browse for a folder and update the folder edit box
 */
void BrowseForFolder(void) {

	BROWSEINFOW bi;
	LPITEMIDLIST pidl;
	WCHAR *wpath;
	size_t i;
	HRESULT hr;
	IShellItem *psi = NULL;
	IShellItem *si_path = NULL;	// Automatically freed
	IFileOpenDialog *pfod = NULL;
	WCHAR *fname;
	char* tmp_path = NULL;

	dialog_showing++;
	hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC,
		&IID_IFileOpenDialog, (LPVOID)&pfod);
	if (FAILED(hr)) {
		dprintf("CoCreateInstance for FileOpenDialog failed: error %X", hr);
		pfod = NULL;	// Just in case
		goto fallback;
	}
	hr = pfod->lpVtbl->SetOptions(pfod, FOS_PICKFOLDERS);
	if (FAILED(hr)) {
		dprintf("Failed to set folder option for FileOpenDialog: error %X", hr);
		goto fallback;
	}
	// Set the initial folder (if the path is invalid, will simply use last)
	wpath = utf8_to_wchar(szFolderPath);
	// The new IFileOpenDialog makes us split the path
	fname = NULL;
	if ((wpath != NULL) && (wcslen(wpath) >= 1)) {
		for (i = wcslen(wpath) - 1; i != 0; i--) {
			if (wpath[i] == L'\\') {
				wpath[i] = 0;
				fname = &wpath[i + 1];
				break;
			}
		}
	}

	hr = SHCreateItemFromParsingName(wpath, NULL, &IID_IShellItem, (LPVOID)&si_path);
	if (SUCCEEDED(hr)) {
		if (wpath != NULL) {
			pfod->lpVtbl->SetFolder(pfod, si_path);
		}
		if (fname != NULL) {
			pfod->lpVtbl->SetFileName(pfod, fname);
		}
	}
	safe_free(wpath);

	hr = pfod->lpVtbl->Show(pfod, hMainDialog);
	if (SUCCEEDED(hr)) {
		hr = pfod->lpVtbl->GetResult(pfod, &psi);
		if (SUCCEEDED(hr)) {
			psi->lpVtbl->GetDisplayName(psi, SIGDN_FILESYSPATH, &wpath);
			tmp_path = wchar_to_utf8(wpath);
			CoTaskMemFree(wpath);
			if (tmp_path == NULL) {
				dprintf("Could not convert path");
			} else {
				static_strcpy(szFolderPath, tmp_path);
				safe_free(tmp_path);
			}
		} else {
			dprintf("Failed to set folder option for FileOpenDialog: error %X", hr);
		}
	} else if ((hr & 0xFFFF) != ERROR_CANCELLED) {
		// If it's not a user cancel, assume the dialog didn't show and fallback
		dprintf("Could not show FileOpenDialog: error %X", hr);
		goto fallback;
	}
	pfod->lpVtbl->Release(pfod);
	dialog_showing--;
	return;
fallback:
	if (pfod != NULL) {
		pfod->lpVtbl->Release(pfod);
	}

	memset(&bi, 0, sizeof(BROWSEINFOW));
	bi.hwndOwner = hMainDialog;
	bi.lpszTitle = L"Please select folder";
	bi.lpfn = BrowseInfoCallback;
	// BIF_NONEWFOLDERBUTTON = 0x00000200 is unknown on MinGW
	bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS |
		BIF_DONTGOBELOWDOMAIN | BIF_EDITBOX | 0x00000200;
	pidl = SHBrowseForFolderW(&bi);
	if (pidl != NULL) {
		CoTaskMemFree(pidl);
	}
	dialog_showing--;
}
Esempio n. 16
0
sBool sSystemOpenFileDialog(const sChar *label,const sChar *extensions,sInt flags,const sStringDesc &buffer)
{
  sChar oldpath[2048];
  OPENFILENAMEW ofn;
  sInt result=0;

  // determine default extension (=first in list)
  sString<256> defaultExt;
  defaultExt = extensions;
  sInt pipePos;
  if((pipePos = sFindFirstChar(defaultExt,'|')) != -1)
    defaultExt[pipePos] = 0;

  sChar ext[2048];
  sClear(ext);
  sChar *extp = ext;
  sInt filterindex = 0;

  if((flags & 3) == sSOF_LOAD && sFindChar(extensions,'|')>=0) // opening, more than one extension specified?
  {
    filterindex = 1;
    static const sChar allSupported[] = L"All supported extensions";
    sCopyMem(extp,allSupported,sizeof(allSupported));
    extp += sCOUNTOF(allSupported);

    // add all supported extensions
    const sChar *curExt = extensions;
    sBool first = sTRUE;

    for(;;)
    {
      while(*curExt=='|') curExt++;
      if(!*curExt) break;

      if(!first)
        *extp++ = ';';

      *extp++ = '*';
      *extp++ = '.';
      while(*curExt!='|' && *curExt)
        *extp++ = *curExt++;

      first = sFALSE;
    }

    *extp++ = 0;
  }

  for(;;)
  {
    while(*extensions=='|') extensions++;
    if(!*extensions) break;
    const sChar *ext1 = extensions;
    while(*ext1!='|' && *ext1)
      *extp++ = *ext1++;
    *extp++ = 0;
    *extp++ = '*';
    *extp++ = '.';
    while(*extensions!='|' && *extensions)
      *extp++ = *extensions++;
    *extp++ = 0;
  }

  static const sChar allFiles[] = L"All files (*.*)\0*.*\0";
  sCopyMem(extp,allFiles,sizeof(allFiles));
  extp += sCOUNTOF(allFiles);

  sSetMem(&ofn,0,sizeof(ofn));
  ofn.lStructSize = sizeof(ofn);
  ofn.hwndOwner = sHWND;
  ofn.lpstrFile = buffer.Buffer;
  ofn.nMaxFile = buffer.Size;
  ofn.lpstrFilter = ext;
  ofn.nFilterIndex = filterindex;
  ofn.lpstrTitle = label;
  ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

  if(0)     // this stuff does not work in windows any more. thanks to microsoft being so very intuitive
  {
    sString<sMAXPATH> initialdir;
    sGetCurrentDir(initialdir);
    initialdir.AddPath(buffer.Buffer);
    sChar *lastslash = 0;
    for(sInt i=0;initialdir[i];i++)
      if(initialdir[i]=='/' || initialdir[i]=='\\')
        lastslash = &initialdir[i];
    if(lastslash)
      *lastslash = 0;
    if(buffer.Buffer[0]!=0)
      ofn.lpstrInitialDir = initialdir;
  }

  if(!defaultExt.IsEmpty())
    ofn.lpstrDefExt = defaultExt;

  for(sInt i=0;buffer.Buffer[i];i++) if(buffer.Buffer[i]=='/') buffer.Buffer[i]='\\';
  sInt len = sGetStringLen(buffer.Buffer);
  if(len>0 && buffer.Buffer[len-1]=='\\') buffer.Buffer[len-1]=0;

  GetCurrentDirectoryW(sCOUNTOF(oldpath),oldpath);
  sWin32::ModalDialogActive = sTRUE;

  switch(flags & 3)
  {
  case sSOF_LOAD:
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;
    if (flags&sSOF_MULTISELECT) ofn.Flags|=OFN_ALLOWMULTISELECT;
    result = GetOpenFileNameW(&ofn);
    break;
  case sSOF_SAVE:
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_EXPLORER;
    result = GetSaveFileNameW(&ofn);
    break;
  case sSOF_DIR:
    { CoInitializeEx(0L,COINIT_APARTMENTTHREADED);
      BROWSEINFO bi;
      memset(&bi, 0, sizeof(bi));
      bi.ulFlags   = BIF_USENEWUI;
      bi.hwndOwner = GetDesktopWindow();
      bi.lpszTitle = label;

      SetActiveWindow(GetDesktopWindow());
      UpdateWindow(GetDesktopWindow());

      LPITEMIDLIST pIDL;
      pIDL = SHBrowseForFolderW(&bi);
      if(pIDL!=0L)
      { // Create a buffer to store the path, then 
        // get the path.
        sChar buffer2[_MAX_PATH] = L"\0";
        if(SHGetPathFromIDList(pIDL, buffer2) != 0)
        {
          // Set the string value.
          sCopyString(buffer,buffer2);
          result = true;
        }
        // free the item id list
        CoTaskMemFree(pIDL);
      }
    }
    break;
  default:
    result = 0;
    break;
  }

  sWin32::ModalDialogActive = sFALSE;
  SetCurrentDirectoryW(oldpath);

  for(sInt i=0;buffer.Buffer[i];i++)
    if(buffer.Buffer[i]=='\\') buffer.Buffer[i]='/';

  return result;
}
Esempio n. 17
0
EXPORT PIDLIST_ABSOLUTE WINAPI SHBrowseForFolderWStub(LPBROWSEINFOW lpbi)
{return SHBrowseForFolderW(lpbi);}
Esempio n. 18
0
int file_open_dialog(Value *vret, const char *title, RefArray *filter, WndHandle parent, int type)
{
    enum {
        RETBUF_MAX = 32 * 1024,
    };
    int ret = FALSE;
    wchar_t *title_p = cstr_to_utf16(title, -1);
    wchar_t *filter_p = NULL;
    wchar_t *wbuf = malloc(RETBUF_MAX);
    int offset = 0;

    memset(wbuf, 0, RETBUF_MAX);

    if (type == FILEOPEN_DIR) {
        BROWSEINFOW bi;
        LPMALLOC pm = NULL;

        if (SHGetMalloc(&pm) != E_FAIL) {
            ITEMIDLIST *id;

            memset(&bi, 0, sizeof(bi));
            bi.hwndOwner = parent;
            bi.ulFlags = BIF_RETURNONLYFSDIRS;
            bi.lpszTitle = title_p;

            id = SHBrowseForFolderW(&bi);
            if (id != NULL){
                SHGetPathFromIDListW(id, wbuf);
                pm->lpVtbl->Free(pm, id);
                pm->lpVtbl->Release(pm);
                ret = TRUE;
            }
        }
    } else {
        OPENFILENAMEW of;
        memset(&of, 0, sizeof(of));
        of.hwndOwner = parent;
        of.lpstrFile = wbuf;
        of.nMaxFile = RETBUF_MAX - 16;
        of.hInstance = GetModuleHandle(NULL);
        of.lStructSize = sizeof(of);
        of.Flags = OFN_NOCHANGEDIR | OFN_CREATEPROMPT;
        of.lpstrTitle = title_p;

        if (filter != NULL) {
            filter_p = make_filter_string(filter);
            of.lpstrFilter = filter_p;
        }

        switch (type) {
        case FILEOPEN_OPEN:
            of.Flags |= OFN_HIDEREADONLY;
            ret = (GetOpenFileNameW(&of) != 0);
            break;
        case FILEOPEN_OPEN_MULTI:
            of.Flags |= OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
            ret = (GetOpenFileNameW(&of) != 0);
            offset = of.nFileOffset;
            break;
        case FILEOPEN_SAVE:
            of.Flags |= OFN_OVERWRITEPROMPT | OFN_EXTENSIONDIFFERENT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
            ret = (GetSaveFileNameW(&of) != 0);
            break;
        }
    }

    if (ret) {
        if (type == FILEOPEN_OPEN_MULTI) {
            RefArray *aret = fs->refarray_new(0);
            wchar_t *p = wbuf;
            int dlen = wcslen(p);
            *vret = vp_Value(aret);

            if (offset <= dlen) {
                array_add_file(aret, p);
            } else {
                wchar_t *dir_part = p;
                p = &p[offset];

                while (*p != L'\0'){
                    wchar_t *filename = concat_filename(dir_part, p);
                    array_add_file(aret, filename);
                    free(filename);
                    p += wcslen(p) + 1;
                }
            }
        } else {
            *vret = utf16_file_Value(wbuf);
        }
    }

    free(title_p);
    free(wbuf);
    free(filter_p);

    return ret;
}
Esempio n. 19
0
static void browse_for_install_folder() {
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

    IFileOpenDialog *pFileOpen;
    hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_ALL, &IID_IFileOpenDialog, (void*)&pFileOpen);
    if (SUCCEEDED(hr)) {
        hr = pFileOpen->lpVtbl->SetOptions(pFileOpen, FOS_PICKFOLDERS);
        hr = pFileOpen->lpVtbl->SetTitle(pFileOpen, L"Tox Install Location");
        hr = pFileOpen->lpVtbl->Show(pFileOpen, NULL);

        if (SUCCEEDED(hr)) {
            IShellItem *pItem;
            hr = pFileOpen->lpVtbl->GetResult(pFileOpen, &pItem);

            if (SUCCEEDED(hr)) {
                PWSTR pszFilePath;
                hr = pItem->lpVtbl->GetDisplayName(pItem, SIGDN_FILESYSPATH, &pszFilePath);

                if (SUCCEEDED(hr)) {
                    set_utox_path(pszFilePath);
                    CoTaskMemFree(pszFilePath);
                }
                pItem->lpVtbl->Release(pItem);
            }
        }
        pFileOpen->lpVtbl->Release(pFileOpen);

        CoUninitialize();
    }
    else {
        wchar_t path[MAX_PATH];
        BROWSEINFOW bi = {
            .pszDisplayName = path,
            .lpszTitle = L"Install Location",
            .ulFlags = BIF_USENEWUI | BIF_NONEWFOLDERBUTTON,
        };
        LPITEMIDLIST lpItem = SHBrowseForFolderW(&bi);
        if (!lpItem) {
            return;
        }

        SHGetPathFromIDListW(lpItem, path);
        set_utox_path(path);
    }
}

static void check_updates() {
    set_current_status("fetching new version data...");

    int new_version = check_new_version();
    set_download_progress(0);

    if (new_version == -1) {
        if (!is_tox_installed) {
            MessageBox(main_window, "Error fetching latest version data. Please check your internet connection.\n\nExiting now...", "Error", MB_OK | MB_SETFOREGROUND);
            exit(0);
        } else {
            open_utox_and_exit();
        }
    }

    set_current_status("version data fetched successfully");
    Button_Enable(GetDlgItem(main_window, ID_INSTALL_BUTTON), 1);

    if (is_tox_installed) {

        if (new_version) {
            ShowWindow(main_window, SW_SHOW);
            set_current_status("found new version");

            if (MessageBox(NULL, "A new version of uTox is available.\nUpdate?", "uTox Updater", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND) == IDYES) {
                download_and_install_new_utox_version();
            }
        }

        open_utox_and_exit();
    }
}