Revision 3088 src/filesel.c

filesel.c (revision 3088)
25 25
#include <gtk/gtkexpander.h>
26 26
#include <gtk/gtkstock.h>
27 27

  
28
#ifdef G_OS_WIN32
29
#  define COBJMACROS
30
#  include <windows.h>
31
#  include <objbase.h>
32
#  include <objidl.h>
33
#  include <shlobj.h>
34
#endif
35

  
28 36
#include "main.h"
29 37
#include "filesel.h"
30 38
#include "manage_window.h"
......
51 59
					(GtkFileChooser		*chooser,
52 60
					 gpointer		 data);
53 61
#endif
62
#ifdef G_OS_WIN32
63
static gchar *filesel_get_link		(const gchar		*link_file);
64
#endif
54 65

  
55 66

  
56 67
gchar *filesel_select_file(const gchar *title, const gchar *file,
......
185 196

  
186 197
	inc_lock();
187 198

  
199
again:
188 200
	if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
189 201
		list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
190 202
		if (list) {
203
#ifdef G_OS_WIN32
204
			/* follow Windows shortcut */
205
			if (g_slist_length(list) == 1) {
206
				gchar *selected = (gchar *)list->data;
207
				gchar *target;
208
				const gchar *ext;
209

  
210
				if ((ext = strrchr(selected, '.')) &&
211
				    g_ascii_strcasecmp(ext, ".lnk") == 0) {
212
					target = filesel_get_link(selected);
213
					if (is_dir_exist(target)) {
214
						gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), target);
215
						g_free(target);
216
						slist_free_strings(list);
217
						g_slist_free(list);
218
						list = NULL;
219
					    	goto again;
220
					} else if (is_file_exist(target)) {
221
						slist_free_strings(list);
222
						g_slist_free(list);
223
						list = g_slist_append(NULL, target);
224
					} else {
225
					    	g_free(target);
226
					}
227
				}
228
			}
229
#endif
191 230
			cwd = gtk_file_chooser_get_current_folder
192 231
				(GTK_FILE_CHOOSER(dialog));
193 232
			if (cwd) {
......
348 387
	return ret;
349 388
}
350 389
#endif
390

  
391
#ifdef G_OS_WIN32
392
static gchar *filesel_get_link(const gchar *link_file)
393
{
394
	WIN32_FIND_DATAW wfd;
395
	IShellLinkW *psl;
396
	IPersistFile *ppf;
397
	HRESULT hr;
398
	wchar_t *wlink_file;
399
	wchar_t wtarget[MAX_PATH];
400
	gchar *target = NULL;
401

  
402
	wtarget[0] = 0L;
403

  
404
	debug_print("link_file: %s\n", link_file);
405

  
406
	CoInitialize(NULL);
407
	if (S_OK == CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (void **)&psl)) {
408
		if (S_OK == IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (void **)&ppf)) {
409
			wlink_file = g_utf8_to_utf16(link_file, -1, NULL, NULL, NULL);
410
			hr = IPersistFile_Load(ppf, wlink_file, STGM_READ);
411
			if (S_OK == hr) {
412
				IShellLinkW_GetPath(psl, wtarget, MAX_PATH, &wfd, SLGP_UNCPRIORITY);
413
				target = g_utf16_to_utf8(wtarget, -1, NULL, NULL, NULL);
414
			}
415
			IPersistFile_Release(ppf);
416
			g_free(wlink_file);
417
		}
418
		IShellLinkW_Release(psl);
419
	}
420
	CoUninitialize();
421

  
422
	if (target)
423
		debug_print("target: %s\n", target);
424
	else
425
		debug_print("target not found\n");
426

  
427
	return target;
428
}
429
#endif

Also available in: Unified diff