1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

use IFileDialog when running on Vista or later

* When compiled with MinGW, this was always disabled due to forcing XP as
  the lowest common denominator and using #ifdefs
* This should also help with OFN_NOCHANGEDIR seemingly being ignored
* Sadly, this change also adds ~20KB to our *compressed* size... :(
This commit is contained in:
Pete Batard 2016-03-23 16:56:49 +00:00
parent cbf1a60365
commit 2c90a06668
5 changed files with 454 additions and 156 deletions

View file

@ -15,4 +15,4 @@ rufus_SOURCES = badblocks.c checksum.c dos.c dos_locale.c drive.c format.c icon.
rufus_CFLAGS = -I./ms-sys/inc -I./syslinux/libfat -I./syslinux/libinstaller -I./syslinux/win -I./libcdio $(AM_CFLAGS)
rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows
rufus_LDADD = rufus_rc.o bled/libbled.a ms-sys/libmssys.a syslinux/libfat/libfat.a syslinux/libinstaller/libinstaller.a syslinux/win/libwin.a \
libcdio/iso9660/libiso9660.a libcdio/udf/libudf.a libcdio/driver/libdriver.a -lsetupapi -lole32 -lgdi32 -lwininet -lshlwapi -lcrypt32 -lwintrust
libcdio/iso9660/libiso9660.a libcdio/udf/libudf.a libcdio/driver/libdriver.a -lsetupapi -lole32 -lgdi32 -lwininet -lshlwapi -lcrypt32 -lwintrust -lcomdlg32 -luuid

View file

@ -276,7 +276,7 @@ rufus_SOURCES = badblocks.c checksum.c dos.c dos_locale.c drive.c format.c icon.
rufus_CFLAGS = -I./ms-sys/inc -I./syslinux/libfat -I./syslinux/libinstaller -I./syslinux/win -I./libcdio $(AM_CFLAGS)
rufus_LDFLAGS = $(AM_LDFLAGS) -mwindows
rufus_LDADD = rufus_rc.o bled/libbled.a ms-sys/libmssys.a syslinux/libfat/libfat.a syslinux/libinstaller/libinstaller.a syslinux/win/libwin.a \
libcdio/iso9660/libiso9660.a libcdio/udf/libudf.a libcdio/driver/libdriver.a -lsetupapi -lole32 -lgdi32 -lwininet -lshlwapi -lcrypt32 -lwintrust
libcdio/iso9660/libiso9660.a libcdio/udf/libudf.a libcdio/driver/libdriver.a -lsetupapi -lole32 -lgdi32 -lwininet -lshlwapi -lcrypt32 -lwintrust -lcomdlg32 -luuid
all: all-recursive

View file

@ -272,3 +272,307 @@ typedef unsigned __int64 uintptr_t;
typedef unsigned int uintptr_t;
#endif
#endif
/*
* IFile[Open]Dialog interface for Vista and later (from MinGW headers)
*/
#ifdef DDKBUILD
typedef struct _COMDLG_FILTERSPEC {
LPCWSTR pszName;
LPCWSTR pszSpec;
} COMDLG_FILTERSPEC;
#endif
#ifndef __IFileDialog_INTERFACE_DEFINED__
#define __IFileDialog_INTERFACE_DEFINED__
enum _FILEOPENDIALOGOPTIONS {
FOS_OVERWRITEPROMPT = 0x2,
FOS_STRICTFILETYPES = 0x4,
FOS_NOCHANGEDIR = 0x8,
FOS_PICKFOLDERS = 0x20,
FOS_FORCEFILESYSTEM = 0x40,
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_NOVALIDATE = 0x100,
FOS_ALLOWMULTISELECT = 0x200,
FOS_PATHMUSTEXIST = 0x800,
FOS_FILEMUSTEXIST = 0x1000,
FOS_CREATEPROMPT = 0x2000,
FOS_SHAREAWARE = 0x4000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_DONTADDTORECENT = 0x2000000,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_DEFAULTNOMINIMODE = 0x20000000,
FOS_FORCEPREVIEWPANEON = 0x40000000
};
typedef enum FDAP {
FDAP_BOTTOM = 0,
FDAP_TOP = 1
} FDAP;
typedef DWORD FILEOPENDIALOGOPTIONS;
DEFINE_GUID(IID_IFileDialog, 0x42f85136, 0xdb7e, 0x439c, 0x85, 0xf1, 0xe4, 0x07, 0x5d, 0x13, 0x5f, 0xc8);
typedef struct IFileDialogVtbl {
BEGIN_INTERFACE
/*** IUnknown methods ***/
HRESULT(STDMETHODCALLTYPE *QueryInterface)(
IFileDialog* This,
REFIID riid,
void **ppvObject);
ULONG(STDMETHODCALLTYPE *AddRef)(
IFileDialog* This);
ULONG(STDMETHODCALLTYPE *Release)(
IFileDialog* This);
/*** IModalWindow methods ***/
HRESULT(STDMETHODCALLTYPE *Show)(
IFileDialog* This,
HWND hwndOwner);
/*** IFileDialog methods ***/
HRESULT(STDMETHODCALLTYPE *SetFileTypes)(
IFileDialog* This,
UINT cFileTypes,
const COMDLG_FILTERSPEC *rgFilterSpec);
HRESULT(STDMETHODCALLTYPE *SetFileTypeIndex)(
IFileDialog* This,
UINT iFileType);
HRESULT(STDMETHODCALLTYPE *GetFileTypeIndex)(
IFileDialog* This,
UINT *piFileType);
HRESULT(STDMETHODCALLTYPE *Advise)(
IFileDialog* This,
IFileDialogEvents *pfde,
DWORD *pdwCookie);
HRESULT(STDMETHODCALLTYPE *Unadvise)(
IFileDialog* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE *SetOptions)(
IFileDialog* This,
FILEOPENDIALOGOPTIONS fos);
HRESULT(STDMETHODCALLTYPE *GetOptions)(
IFileDialog* This,
FILEOPENDIALOGOPTIONS *pfos);
HRESULT(STDMETHODCALLTYPE *SetDefaultFolder)(
IFileDialog* This,
IShellItem *psi);
HRESULT(STDMETHODCALLTYPE *SetFolder)(
IFileDialog* This,
IShellItem *psi);
HRESULT(STDMETHODCALLTYPE *GetFolder)(
IFileDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *GetCurrentSelection)(
IFileDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *SetFileName)(
IFileDialog* This,
LPCWSTR pszName);
HRESULT(STDMETHODCALLTYPE *GetFileName)(
IFileDialog* This,
LPWSTR *pszName);
HRESULT(STDMETHODCALLTYPE *SetTitle)(
IFileDialog* This,
LPCWSTR pszTitle);
HRESULT(STDMETHODCALLTYPE *SetOkButtonLabel)(
IFileDialog* This,
LPCWSTR pszText);
HRESULT(STDMETHODCALLTYPE *SetFileNameLabel)(
IFileDialog* This,
LPCWSTR pszLabel);
HRESULT(STDMETHODCALLTYPE *GetResult)(
IFileDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *AddPlace)(
IFileDialog* This,
IShellItem *psi,
FDAP fdap);
HRESULT(STDMETHODCALLTYPE *SetDefaultExtension)(
IFileDialog* This,
LPCWSTR pszDefaultExtension);
HRESULT(STDMETHODCALLTYPE *Close)(
IFileDialog* This,
HRESULT hr);
HRESULT(STDMETHODCALLTYPE *SetClientGuid)(
IFileDialog* This,
REFGUID guid);
HRESULT(STDMETHODCALLTYPE *ClearClientData)(
IFileDialog* This);
HRESULT(STDMETHODCALLTYPE *SetFilter)(
IFileDialog* This,
IShellItemFilter *pFilter);
END_INTERFACE
} IFileDialogVtbl;
interface IFileDialog {
CONST_VTBL IFileDialogVtbl* lpVtbl;
};
#endif
#ifndef __IFileOpenDialog_INTERFACE_DEFINED__
#define __IFileOpenDialog_INTERFACE_DEFINED__
DEFINE_GUID(IID_IFileOpenDialog, 0xd57c7288, 0xd4ad, 0x4768, 0xbe, 0x02, 0x9d, 0x96, 0x95, 0x32, 0xd9, 0x60);
typedef struct IFileOpenDialogVtbl {
BEGIN_INTERFACE
/*** IUnknown methods ***/
HRESULT(STDMETHODCALLTYPE *QueryInterface)(
IFileOpenDialog* This,
REFIID riid,
void **ppvObject);
ULONG(STDMETHODCALLTYPE *AddRef)(
IFileOpenDialog* This);
ULONG(STDMETHODCALLTYPE *Release)(
IFileOpenDialog* This);
/*** IModalWindow methods ***/
HRESULT(STDMETHODCALLTYPE *Show)(
IFileOpenDialog* This,
HWND hwndOwner);
/*** IFileDialog methods ***/
HRESULT(STDMETHODCALLTYPE *SetFileTypes)(
IFileOpenDialog* This,
UINT cFileTypes,
const COMDLG_FILTERSPEC *rgFilterSpec);
HRESULT(STDMETHODCALLTYPE *SetFileTypeIndex)(
IFileOpenDialog* This,
UINT iFileType);
HRESULT(STDMETHODCALLTYPE *GetFileTypeIndex)(
IFileOpenDialog* This,
UINT *piFileType);
HRESULT(STDMETHODCALLTYPE *Advise)(
IFileOpenDialog* This,
IFileDialogEvents *pfde,
DWORD *pdwCookie);
HRESULT(STDMETHODCALLTYPE *Unadvise)(
IFileOpenDialog* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE *SetOptions)(
IFileOpenDialog* This,
FILEOPENDIALOGOPTIONS fos);
HRESULT(STDMETHODCALLTYPE *GetOptions)(
IFileOpenDialog* This,
FILEOPENDIALOGOPTIONS *pfos);
HRESULT(STDMETHODCALLTYPE *SetDefaultFolder)(
IFileOpenDialog* This,
IShellItem *psi);
HRESULT(STDMETHODCALLTYPE *SetFolder)(
IFileOpenDialog* This,
IShellItem *psi);
HRESULT(STDMETHODCALLTYPE *GetFolder)(
IFileOpenDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *GetCurrentSelection)(
IFileOpenDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *SetFileName)(
IFileOpenDialog* This,
LPCWSTR pszName);
HRESULT(STDMETHODCALLTYPE *GetFileName)(
IFileOpenDialog* This,
LPWSTR *pszName);
HRESULT(STDMETHODCALLTYPE *SetTitle)(
IFileOpenDialog* This,
LPCWSTR pszTitle);
HRESULT(STDMETHODCALLTYPE *SetOkButtonLabel)(
IFileOpenDialog* This,
LPCWSTR pszText);
HRESULT(STDMETHODCALLTYPE *SetFileNameLabel)(
IFileOpenDialog* This,
LPCWSTR pszLabel);
HRESULT(STDMETHODCALLTYPE *GetResult)(
IFileOpenDialog* This,
IShellItem **ppsi);
HRESULT(STDMETHODCALLTYPE *AddPlace)(
IFileOpenDialog* This,
IShellItem *psi,
FDAP fdap);
HRESULT(STDMETHODCALLTYPE *SetDefaultExtension)(
IFileOpenDialog* This,
LPCWSTR pszDefaultExtension);
HRESULT(STDMETHODCALLTYPE *Close)(
IFileOpenDialog* This,
HRESULT hr);
HRESULT(STDMETHODCALLTYPE *SetClientGuid)(
IFileOpenDialog* This,
REFGUID guid);
HRESULT(STDMETHODCALLTYPE *ClearClientData)(
IFileOpenDialog* This);
HRESULT(STDMETHODCALLTYPE *SetFilter)(
IFileOpenDialog* This,
IShellItemFilter *pFilter);
/*** IFileOpenDialog methods ***/
HRESULT(STDMETHODCALLTYPE *GetResults)(
IFileOpenDialog* This,
IShellItemArray **ppenum);
HRESULT(STDMETHODCALLTYPE *GetSelectedItems)(
IFileOpenDialog* This,
IShellItemArray **ppsai);
END_INTERFACE
} IFileOpenDialogVtbl;
interface IFileOpenDialog {
CONST_VTBL IFileOpenDialogVtbl* lpVtbl;
};
#endif

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 2.8.886"
CAPTION "Rufus 2.8.887"
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -320,8 +320,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,8,886,0
PRODUCTVERSION 2,8,886,0
FILEVERSION 2,8,887,0
PRODUCTVERSION 2,8,887,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -338,13 +338,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.8.886"
VALUE "FileVersion", "2.8.887"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2016 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.8.886"
VALUE "ProductVersion", "2.8.887"
END
END
BLOCK "VarFileInfo"

View file

@ -44,9 +44,7 @@
#include "settings.h"
#include "license.h"
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
PF_TYPE_DECL(WINAPI, HRESULT, SHCreateItemFromParsingName, (PCWSTR, IBindCtx*, REFIID, void **));
#endif
PF_TYPE_DECL(WINAPI, LPITEMIDLIST, SHSimpleIDListFromPath, (PCWSTR pszPath));
#define INIT_VISTA_SHELL32 PF_INIT(SHCreateItemFromParsingName, Shell32)
#define INIT_XP_SHELL32 PF_INIT(SHSimpleIDListFromPath, Shell32)
@ -135,8 +133,6 @@ void BrowseForFolder(void) {
BROWSEINFOW bi;
LPITEMIDLIST pidl;
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
WCHAR *wpath;
size_t i;
HRESULT hr;
@ -147,8 +143,8 @@ void BrowseForFolder(void) {
char* tmp_path = NULL;
dialog_showing++;
// Even if we have Vista support with the compiler,
// it does not mean we have the Vista API available
#ifndef DDKBUILD // WDK being uncooperative yet again...
if (nWindowsVersion >= WINDOWS_VISTA) {
INIT_VISTA_SHELL32;
if (IS_VISTA_SHELL32_AVAILABLE) {
hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC,
@ -217,9 +213,9 @@ fallback:
if (pfod != NULL) {
pfod->lpVtbl->Release(pfod);
}
#else
dialog_showing++;
}
#endif
INIT_XP_SHELL32;
memset(&bi, 0, sizeof(BROWSEINFOW));
bi.hwndOwner = hMainDialog;
@ -253,21 +249,19 @@ char* FileDialog(BOOL save, char* path, const ext_t* ext, DWORD options)
size_t i, j, ext_strlen;
BOOL r;
char* filepath = NULL;
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
HRESULT hr = FALSE;
IFileDialog *pfd = NULL;
IShellItem *psiResult;
COMDLG_FILTERSPEC* filter_spec;
wchar_t *wpath = NULL, *wfilename = NULL;
IShellItem *si_path = NULL; // Automatically freed
#endif
if ((ext == NULL) || (ext->count == 0) || (ext->extension == NULL) || (ext->description == NULL))
return NULL;
dialog_showing++;
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
#ifndef DDKBUILD
if (nWindowsVersion >= WINDOWS_VISTA) {
INIT_VISTA_SHELL32;
filter_spec = (COMDLG_FILTERSPEC*)calloc(ext->count + 1, sizeof(COMDLG_FILTERSPEC));
if ((IS_VISTA_SHELL32_AVAILABLE) && (filter_spec != NULL)) {
@ -342,11 +336,11 @@ char* FileDialog(BOOL save, char* path, const ext_t* ext, DWORD options)
dialog_showing--;
return filepath;
}
fallback:
if (pfd != NULL) {
pfd->lpVtbl->Release(pfd);
}
}
#endif
memset(&ofn, 0, sizeof(ofn));