[ui] ensure the default download directory for updates is the current app dir

* Closes #299
* Also fix update save dialog not retrieving the path when compiled for Vista or later
This commit is contained in:
Pete Batard 2014-03-17 20:42:10 +00:00
parent 54b7fdcddc
commit 77d9e919d2
5 changed files with 25 additions and 16 deletions

View File

@ -433,9 +433,10 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
update_check_in_progress = TRUE;
verbose = ReadRegistryKey32(REGKEY_HKCU, REGKEY_VERBOSE_UPDATES);
// Without this the FileDialog will produce error 0x8001010E when compiled for Vista or later
IGNORE_RETVAL(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED));
// Unless the update was forced, wait a while before performing the update check
if (!force_update_check) {
// TODO: Also check on inactivity
// It would of course be a lot nicer to use a timer and wake the thread, but my
// development time is limited and this is FASTER to implement.
do {

View File

@ -1062,7 +1062,7 @@ BOOL CALLBACK LogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
log_size = GetDlgItemTextU(hDlg, IDC_LOG_EDIT, log_buffer, log_size);
if (log_size != 0) {
log_size--; // remove NUL terminator
filepath = FileDialog(TRUE, app_dir, "rufus.log", "log", lmprintf(MSG_108));
filepath = FileDialog(TRUE, app_dir, "rufus.log", "log", lmprintf(MSG_108), 0);
if (filepath != NULL) {
FileIO(TRUE, filepath, &log_buffer, &log_size);
}
@ -2092,9 +2092,9 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
} else {
safe_free(iso_path);
if (selection_default == DT_IMG)
iso_path = FileDialog(FALSE, NULL, "*.img", "img", "DD Image");
iso_path = FileDialog(FALSE, NULL, "*.img", "img", "DD Image", 0);
else
iso_path = FileDialog(FALSE, NULL, "*.iso", "iso", lmprintf(MSG_036));
iso_path = FileDialog(FALSE, NULL, "*.iso", "iso", lmprintf(MSG_036), 0);
if (iso_path == NULL) {
CreateTooltip(hSelectISO, lmprintf(MSG_173), -1);
break;

View File

@ -339,7 +339,7 @@ extern BOOL InstallSyslinux(DWORD drive_index, char drive_letter);
DWORD WINAPI FormatThread(void* param);
extern BOOL CreateProgress(void);
extern BOOL SetAutorun(const char* path);
extern char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_desc);
extern char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_desc, DWORD options);
extern BOOL FileIO(BOOL save, char* path, char** buffer, DWORD* size);
extern unsigned char* GetResource(HMODULE module, char* name, char* type, const char* desc, DWORD* len, BOOL duplicate);
extern BOOL SetLGP(BOOL bRestore, BOOL* bExistingKey, const char* szPath, const char* szPolicy, DWORD dwValue);

View File

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 1.4.6.438"
CAPTION "Rufus 1.4.6.439"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -165,7 +165,7 @@ END
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 1.4.6.438"
CAPTION "Rufus 1.4.6.439"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -427,8 +427,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,6,438
PRODUCTVERSION 1,4,6,438
FILEVERSION 1,4,6,439
PRODUCTVERSION 1,4,6,439
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -445,13 +445,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.4.6.438"
VALUE "FileVersion", "1.4.6.439"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.4.6.438"
VALUE "ProductVersion", "1.4.6.439"
END
END
BLOCK "VarFileInfo"

View File

@ -241,8 +241,11 @@ fallback:
* Return the UTF8 path of a file selected through a load or save dialog
* Will use the newer IFileOpenDialog if *compiled* for Vista or later
* All string parameters are UTF-8
* IMPORTANT NOTE: On Vista and later, remember that you need to call
* CoInitializeEx() for *EACH* thread you invoke FileDialog from, as
* GetDisplayName() will return error 0x8001010E otherwise.
*/
char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_desc)
char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_desc, DWORD options)
{
DWORD tmp;
OPENFILENAMEA ofn;
@ -280,7 +283,8 @@ char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_des
&IID_IFileDialog, (LPVOID)&pfd);
if (FAILED(hr)) {
uprintf("CoCreateInstance for FileOpenDialog failed: error %X\n", hr);
SetLastError(hr);
uprintf("CoCreateInstance for FileOpenDialog failed: %s\n", WindowsErrorString());
pfd = NULL; // Just in case
goto fallback;
}
@ -319,12 +323,16 @@ char* FileDialog(BOOL save, char* path, char* filename, char* ext, char* ext_des
if (SUCCEEDED(hr)) {
filepath = wchar_to_utf8(wpath);
CoTaskMemFree(wpath);
} else {
SetLastError(hr);
uprintf("Unable to access file path: %s\n", WindowsErrorString());
}
psiResult->lpVtbl->Release(psiResult);
}
} else if ((hr & 0xFFFF) != ERROR_CANCELLED) {
// If it's not a user cancel, assume the dialog didn't show and fallback
uprintf("Could not show FileOpenDialog: error %X\n", hr);
SetLastError(hr);
uprintf("Could not show FileOpenDialog: %s\n", WindowsErrorString());
goto fallback;
}
pfd->lpVtbl->Release(pfd);
@ -363,7 +371,7 @@ fallback:
ofn.lpstrFilter = ext_string;
// Initial dir
ofn.lpstrInitialDir = path;
ofn.Flags = OFN_OVERWRITEPROMPT;
ofn.Flags = OFN_OVERWRITEPROMPT | options;
// Show Dialog
if (save) {
r = GetSaveFileNameU(&ofn);
@ -1245,7 +1253,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR
break;
}
for (i=(int)strlen(update.download_url); (i>0)&&(update.download_url[i]!='/'); i--);
filepath = FileDialog(TRUE, app_dir, (char*)&update.download_url[i+1], "exe", lmprintf(MSG_037));
filepath = FileDialog(TRUE, app_dir, (char*)&update.download_url[i+1], "exe", lmprintf(MSG_037), OFN_NOCHANGEDIR);
if (filepath == NULL) {
uprintf("Could not get save path\n");
break;