From d5dfdb900b7e9bae4548392ddd77c63d63a8136a Mon Sep 17 00:00:00 2001 From: kichik Date: Wed, 25 Sep 2002 12:54:10 +0000 Subject: [PATCH] Shortcut comment option added, 44 bytes saved. git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1181 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/exehead/exec.c | 45 ++++++++++++++++++++++++++++++++++++++++--- Source/exehead/util.c | 4 ++-- Source/script.cpp | 5 +++-- Source/tokens.cpp | 2 +- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index 6f9161cc..1673576a 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -944,12 +944,51 @@ static int NSISCALL ExecuteEntry(entry *entry_) char *buf1=process_string_fromparm_tobuf(0x11); char *buf0=process_string_fromparm_tobuf(0x02); char *buf3=process_string_fromparm_tobuf(0x33); + char *buf4=process_string_fromparm_tobuf(0x45); + + HRESULT hres; + int rv=1; + IShellLink* psl; log_printf8("CreateShortCut: out: \"%s\", in: \"%s %s\", icon: %s,%d, sw=%d, hk=%d", - buf2,buf1,buf0,buf3,parm4&0xff,(parm4&0xff00)>>8,parm4>>16); + buf2,buf1,buf0,buf3,parm4&0xff,(parm4&0xff00)>>8,parm4>>16); - if (CreateShortCut(g_hwnd, buf2, buf3[0]?buf3:NULL, parm4&0xff, buf1, buf0[0]?buf0:NULL, - state_output_directory,(parm4&0xff00)>>8,parm4>>16)) + hres=OleInitialize(NULL); + if (hres == S_FALSE || hres == S_OK) { + + hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + &IID_IShellLink, (void **) &psl); + if (SUCCEEDED(hres)) + { + IPersistFile* ppf; + + hres = psl->lpVtbl->QueryInterface(psl,&IID_IPersistFile, (void **) &ppf); + if (SUCCEEDED(hres)) + { + + hres = psl->lpVtbl->SetPath(psl,buf1); + psl->lpVtbl->SetWorkingDirectory(psl,state_output_directory); + if ((parm4&0xff00)>>8) psl->lpVtbl->SetShowCmd(psl,(parm4&0xff00)>>8); + psl->lpVtbl->SetHotkey(psl,(unsigned short)(parm4>>16)); + if (buf3[0]) psl->lpVtbl->SetIconLocation(psl,buf3,parm4&0xff); + psl->lpVtbl->SetArguments(psl,buf0); + psl->lpVtbl->SetDescription(psl,buf4); + + if (SUCCEEDED(hres)) + { + WCHAR wsz[1024]; + MultiByteToWideChar(CP_ACP, 0, buf2, -1, wsz, 1024); + hres=ppf->lpVtbl->Save(ppf,(const WCHAR*)wsz,TRUE); + if (SUCCEEDED(hres)) rv=0; + } + ppf->lpVtbl->Release(ppf); + } + psl->lpVtbl->Release(psl); + } + OleUninitialize(); + } + + if (rv) { exec_errorflag++; update_status_text_from_lang(LANGID_ERRORCREATINGSHORTCUT,buf2); diff --git a/Source/exehead/util.c b/Source/exehead/util.c index ba48f8a9..b503d28a 100644 --- a/Source/exehead/util.c +++ b/Source/exehead/util.c @@ -592,7 +592,7 @@ void NSISCALL log_write(int close) #endif #ifdef NSIS_SUPPORT_CREATESHORTCUT -int NSISCALL CreateShortCut(HWND hwnd, LPCSTR pszShortcutFile, LPCSTR pszIconFile, int iconindex, LPCSTR pszExe, LPCSTR pszArg, LPCSTR workingdir, int showmode, int hotkey) +/*int NSISCALL CreateShortCut(HWND hwnd, LPCSTR pszShortcutFile, LPCSTR pszIconFile, int iconindex, LPCSTR pszExe, LPCSTR pszArg, LPCSTR workingdir, int showmode, int hotkey) { HRESULT hres; int rv=1; @@ -633,5 +633,5 @@ int NSISCALL CreateShortCut(HWND hwnd, LPCSTR pszShortcutFile, LPCSTR pszIconFil } OleUninitialize(); return rv; -} +}*/ #endif//NSIS_SUPPORT_CREATESHORTCUT diff --git a/Source/script.cpp b/Source/script.cpp index ffa357cc..12225b17 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -2209,6 +2209,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char ent.offsets[1]=add_string(line.gettoken_str(2)); ent.offsets[2]=add_string(line.gettoken_str(3)); ent.offsets[3]=add_string(line.gettoken_str(4)); + ent.offsets[5]=add_string(line.gettoken_str(8)); int s; ent.offsets[4]=line.gettoken_int(5,&s)&0xff; if (!s) @@ -2265,9 +2266,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char ent.offsets[4] |= (c) << 16; } } - SCRIPT_MSG("CreateShortCut: \"%s\"->\"%s\" %s icon:%s,%d, showmode=0x%X, hotkey=0x%X\n", + SCRIPT_MSG("CreateShortCut: \"%s\"->\"%s\" %s icon:%s,%d, showmode=0x%X, hotkey=0x%X, comment=%s\n", line.gettoken_str(1),line.gettoken_str(2),line.gettoken_str(3), - line.gettoken_str(4),ent.offsets[4]&0xff,(ent.offsets[4]>>8)&0xff,ent.offsets[4]>>16); + line.gettoken_str(4),ent.offsets[4]&0xff,(ent.offsets[4]>>8)&0xff,ent.offsets[4]>>16,line.gettoken_str(8)); return add_entry(&ent); #else//!NSIS_SUPPORT_CREATESHORTCUT ERROR_MSG("Error: %s specified, NSIS_SUPPORT_CREATESHORTCUT not defined.\n", line.gettoken_str(0)); diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 0bae5a59..0148afda 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -38,7 +38,7 @@ static tokenType tokenlist[TOK__LAST] = {TOK_CRCCHECK,"CRCCheck",1,0,"(on|force|off)"}, {TOK_CREATEDIR,"CreateDirectory",1,0,"directory_name"}, {TOK_CREATEFONT,"CreateFont",2,5,"$(user_var: handle output) face_name [height wieght /ITALIC /UNDERLINE /STRIKE]"}, -{TOK_CREATESHORTCUT,"CreateShortCut",2,5,"shortcut_name.lnk shortcut_target [parameters [icon_file [icon index [showmode [hotkey]]]]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)\n hotkey=(ALT|CONTROL|EXT|SHIFT)|(F1-F24|A-Z)"}, +{TOK_CREATESHORTCUT,"CreateShortCut",2,6,"shortcut_name.lnk shortcut_target [parameters [icon_file [icon index [showmode [hotkey [comment]]]]]]\n showmode=(SW_SHOWNORMAL|SW_SHOWMAXIMIZED|SW_SHOWMINIMIZED)\n hotkey=(ALT|CONTROL|EXT|SHIFT)|(F1-F24|A-Z)"}, {TOK_DBOPTIMIZE,"SetDatablockOptimize",1,0,"(off|on)"}, {TOK_DELETEINISEC,"DeleteINISec",2,0,"ini_file section_name"}, {TOK_DELETEINISTR,"DeleteINIStr",3,0,"ini_file section_name entry_name"},