From f26b663172d80c300df993465b6a01369795a76f Mon Sep 17 00:00:00 2001 From: Damjan Jovanovic Date: Mon, 7 Jun 2010 21:40:26 +0200 Subject: [PATCH] winemenubuilder: Also extract .lnk icons from file types. --- programs/winemenubuilder/winemenubuilder.c | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/programs/winemenubuilder/winemenubuilder.c b/programs/winemenubuilder/winemenubuilder.c index a40a657e274..276c4e48de7 100644 --- a/programs/winemenubuilder/winemenubuilder.c +++ b/programs/winemenubuilder/winemenubuilder.c @@ -172,6 +172,9 @@ static char *xdg_config_dir; static char *xdg_data_dir; static char *xdg_desktop_dir; +static WCHAR* assoc_query(ASSOCSTR assocStr, LPCWSTR name, LPCWSTR extra); +static char *extract_icon(LPCWSTR path, int index, const char *destFilename, BOOL bWait); + /* Icon extraction routines * * FIXME: should use PrivateExtractIcons and friends @@ -814,6 +817,39 @@ static int ExtractFromICO(LPCWSTR szFileName, char *szXPMFileName) return 0; } +static int ExtractFromFileType(LPCWSTR szFileName, char *szXPMFileName) +{ + int ret = 1; + WCHAR *extension; + WCHAR *icon = NULL; + WCHAR *comma; + int index = 0; + char *output_path = NULL; + + extension = strrchrW(szFileName, '.'); + if (extension == NULL) + goto end; + + icon = assoc_query(ASSOCSTR_DEFAULTICON, extension, NULL); + if (icon == NULL) + goto end; + + comma = strrchrW(icon, ','); + if (comma) + { + *comma = 0; + index = atoiW(comma + 1); + } + output_path = extract_icon(icon, index, NULL, FALSE); + if (output_path) + ret = rename(output_path, szXPMFileName); + +end: + HeapFree(GetProcessHeap(), 0, icon); + HeapFree(GetProcessHeap(), 0, output_path); + return ret; +} + static BOOL create_default_icon( const char *filename, const char* comment ) { FILE *fXPM; @@ -1031,6 +1067,8 @@ static char *extract_icon( LPCWSTR path, int index, const char *destFilename, BO sprintf(xpm_path,"%s/%04x_%s.png",iconsdir,crc,ico_name); if (ExtractFromICO( path, xpm_path)) goto end; + if (ExtractFromFileType( path, xpm_path )) + goto end; if (!bWait) { if (destFilename)