From d4d777f2a1cb0f18976a6aa0a0d6b6e60c4a594f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 7 Sep 2007 15:58:39 +0100 Subject: [PATCH] WinGit: also install a Quick Launch icon and a StartMenu entry Signed-off-by: Johannes Schindelin --- share/WinGit/.gitignore | 2 + share/WinGit/Makefile | 3 ++ share/WinGit/create-shortcut.c | 105 +++++++++++++++++++++++++++++++++++++++++ share/WinGit/install.tcl | 82 ++++++++++++++++++++++++++++++-- share/WinGit/release.sh | 4 ++ 5 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 share/WinGit/.gitignore create mode 100644 share/WinGit/Makefile create mode 100644 share/WinGit/create-shortcut.c diff --git a/share/WinGit/.gitignore b/share/WinGit/.gitignore new file mode 100644 index 00000000..25a7384d --- /dev/null +++ b/share/WinGit/.gitignore @@ -0,0 +1,2 @@ +*.o +*.exe diff --git a/share/WinGit/Makefile b/share/WinGit/Makefile new file mode 100644 index 00000000..2989aba4 --- /dev/null +++ b/share/WinGit/Makefile @@ -0,0 +1,3 @@ +create-shortcut.exe: create-shortcut.o + $(CC) $(CFLAGS) -o $@ $< -luuid -lole32 + strip $@ diff --git a/share/WinGit/create-shortcut.c b/share/WinGit/create-shortcut.c new file mode 100644 index 00000000..df5e13c9 --- /dev/null +++ b/share/WinGit/create-shortcut.c @@ -0,0 +1,105 @@ +#include +#include + +void die(const char *message) +{ + CoUninitialize(); + fprintf(stderr, "%s\n", message); + fprintf(stderr, "last error: %d\n", GetLastError()); + exit(1); +} + +int main(int argc, char **argv) +{ + const char *progname = argv[0]; + const char *work_dir = NULL, *arguments = NULL, *icon_file = NULL; + const char *description = NULL; + int show_cmd = 1; + + static WCHAR wsz[1024]; + HRESULT hres; + IShellLink* psl; + IPersistFile* ppf; + + + while (argc > 2) { + if (argv[1][0] != '-') + break; + if (!strcmp(argv[1], "--work-dir")) + work_dir = argv[2]; + else if (!strcmp(argv[1], "--arguments")) + arguments = argv[2]; + else if (!strcmp(argv[1], "--show-cmd")) + show_cmd = atoi(argv[2]); + else if (!strcmp(argv[1], "--icon-file")) + icon_file = argv[2]; + else if (!strcmp(argv[1], "--description")) + description = argv[2]; + else { + fprintf(stderr, "Unknown option: %s\n", argv[1]); + return 1; + } + + argc -= 2; + argv += 2; + } + + if (argc > 1 && !strcmp(argv[1], "--")) { + argc--; + argv++; + } + + if (argc < 3) { + fprintf(stderr, "Usage: %s [options] \n", + progname); + return 1; + } + + hres = CoInitialize(NULL); + if (FAILED(hres)) + die ("Could not initialize OLE"); + + hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, + &IID_IShellLink, (void **)&psl); + + if (FAILED(hres)) + die ("Could not get ShellLink interface"); + + hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, + (void **) &ppf); + + if (FAILED(hres)) + die ("Could not get PersistFile interface"); + + hres = psl->lpVtbl->SetPath(psl, argv[1]); + if (FAILED(hres)) + die ("Could not set path"); + + if (work_dir) + psl->lpVtbl->SetWorkingDirectory(psl, work_dir); + + if (show_cmd) + psl->lpVtbl->SetShowCmd(psl, show_cmd); + + if (icon_file) + psl->lpVtbl->SetIconLocation(psl, icon_file, 0); + if (arguments) + psl->lpVtbl->SetArguments(psl, arguments); + if (description) + psl->lpVtbl->SetDescription(psl, description); + + wsz[0] = 0; + MultiByteToWideChar(CP_ACP, + 0, argv[2], -1, wsz, 1024); + hres = ppf->lpVtbl->Save(ppf, + (const WCHAR*)wsz, TRUE); + + ppf->lpVtbl->Release(ppf); + psl->lpVtbl->Release(psl); + + if (FAILED(hres)) + die ("Could not save link"); + + CoUninitialize(); + return 0; +} diff --git a/share/WinGit/install.tcl b/share/WinGit/install.tcl index 72461a0f..5f125adf 100644 --- a/share/WinGit/install.tcl +++ b/share/WinGit/install.tcl @@ -15,7 +15,7 @@ proc browseForTarget {} { } proc installGit {} { - global currentDirectory targetDirectory + global currentDirectory targetDirectory answer env if {[file exists $targetDirectory]} { set answer [tk_dialog .question "Target directory exists!" \ @@ -58,15 +58,91 @@ proc installGit {} { set list [open "$currentDirectory/fileList-builtins.txt" r] while {[gets $list line] >= 0} { - .listbox.list nisert end "copying builtin: $line\n" + .listbox.list insert end "copying builtin: $line\n" .listbox.list yview moveto 1 update - file copy "$currentDirectory/bin/git.exe $targetDirectory/$line" + file copy $currentDirectory/bin/git.exe $targetDirectory/$line } close $list #destroy .listbox + # Create shortcuts + + set destinations [list] + set answer [tk_dialog .question "Desktop Icon" \ + "Would you like to add a Git icon to the Desktop?" \ + question 0 Yes No] + if {$answer == 0} { + lappend destinations $env(USERPROFILE)/Desktop + } + + set answer [tk_dialog .question "Quick Launch" \ + "Would you like to add a Quick Launch icon?" \ + question 0 Yes No] + if {$answer == 0} { + set appdata [regsub -all "\\\\" $env(APPDATA) "/"] + lappend destinations \ + "$appdata/Microsoft/Internet Explorer/Quick Launch" + } + toplevel .question + wm title .question "Start Menu item" + label .question.label -text \ + "Would you like to add a start menu item?" + frame .question.name + label .question.name.name -text "Name:" + global startMenuName + set startMenuName "Git" + entry .question.name.entry -textvariable startMenuName + pack .question.name.name .question.name.entry \ + -fill x -expand true -side left + frame .question.buttons + set answer -1 + button .question.buttons.yes -text Yes -default active \ + -command { + set answer 1 + destroy .question + } + bind .question { + if {[string equal %K "Return"]} { + set answer 1 + destroy .question + } + if {[string equal %K "Escape"]} { + set answer 0 + destroy .question + } + } + button .question.buttons.no -text No -command { + set answer 0 + destroy .question + } + pack .question.buttons.yes .question.buttons.no \ + -fill x -expand true -side left + pack .question.label .question.name .question.buttons \ + -fill y -expand true + focus -force .question + tkwait window .question + if {$answer == 1} { + package require registry 1.0 + set key "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows" + set key "$key\\CurrentVersion\\Explorer\\Shell Folders" + set programs [registry get $key "Programs"] + file mkdir $programs/$startMenuName + lappend destinations $programs/$startMenuName + } + + # TODO: add git-gui + # TODO: incorporate git-cheetah + + foreach location $destinations { + exec create-shortcut.exe --work-dir $targetDirectory \ + --icon-file $targetDirectory/git.ico \ + --arguments "--login -i" \ + --description "Git for MSys" \ + $targetDirectory/bin/sh.exe $location/Git.lnk + } + tk_dialog .info "WinGit installed" \ "WinGit was successfully installed" info 0 OK diff --git a/share/WinGit/release.sh b/share/WinGit/release.sh index e386a904..42fc303f 100644 --- a/share/WinGit/release.sh +++ b/share/WinGit/release.sh @@ -13,6 +13,10 @@ TMPDIR=/tmp/WinGit (test ! -d "$TMPDIR" || echo "Removing $TMPDIR" && rm -rf "$TMPDIR") && mkdir "$TMPDIR" && +(cd "$(dirname "$0")" && + make && + cp create-shortcut.exe "$TMPDIR") && +cp /share/resources/git.ico "$TMPDIR" && cd "$TMPDIR" && echo "Copying files" && (cd / && tar cf - bin/ lib/perl5/) | -- 2.11.4.GIT