Skip to content

Commit 2dc29ea

Browse files
committed
git-extra: include msysGit's create-shortcut.exe helper
This version was taken straight from msysGit's https://github.com/msysgit/msysgit/baef0eff Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 185b71b commit 2dc29ea

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.swp
22
/git-extra/pkg/
3+
/git-extra/src/

git-extra/PKGBUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@ SigLevel = Optional\n\
3636
"post_upgrade () {" \
3737
" post_install" \
3838
"}" > $startdir/$pkgname.install
39+
40+
gcc -o create-shortcut.exe $startdir/create-shortcut.c -luuid -lole32
3941
}
4042

4143
package() {
44+
case "$CARCH" in
45+
i686)
46+
mingwdir="mingw32"
47+
;;
48+
x86_64)
49+
mingwdir="mingw64"
50+
;;
51+
esac
52+
4253
install -d -m755 $pkgdir/etc/profile.d
4354
install -d -m755 $pkgdir/usr/bin
55+
install -d -m755 $pkgdir/$mingwdir/bin
4456
install -m755 $startdir/vimrc $pkgdir/etc
4557
install -m755 $startdir/vi $pkgdir/usr/bin
58+
install -m755 create-shortcut.exe $pkgdir/$mingwdir/bin
4659
install -m755 $startdir/git-prompt.sh $pkgdir/etc/profile.d
4760
install -m755 $startdir/aliases.sh $pkgdir/etc/profile.d
4861
}

git-extra/create-shortcut.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include <stdio.h>
2+
#include <shlobj.h>
3+
4+
void die(const char *message)
5+
{
6+
CoUninitialize();
7+
fprintf(stderr, "%s\n", message);
8+
fprintf(stderr, "last error: %d\n", GetLastError());
9+
exit(1);
10+
}
11+
12+
int main(int argc, char **argv)
13+
{
14+
const char *progname = argv[0];
15+
const char *work_dir = NULL, *arguments = NULL, *icon_file = NULL;
16+
const char *description = NULL;
17+
int show_cmd = 1;
18+
19+
static WCHAR wsz[1024];
20+
HRESULT hres;
21+
IShellLink* psl;
22+
IPersistFile* ppf;
23+
24+
25+
while (argc > 2) {
26+
if (argv[1][0] != '-')
27+
break;
28+
if (!strcmp(argv[1], "--work-dir"))
29+
work_dir = argv[2];
30+
else if (!strcmp(argv[1], "--arguments"))
31+
arguments = argv[2];
32+
else if (!strcmp(argv[1], "--show-cmd"))
33+
show_cmd = atoi(argv[2]);
34+
else if (!strcmp(argv[1], "--icon-file"))
35+
icon_file = argv[2];
36+
else if (!strcmp(argv[1], "--description"))
37+
description = argv[2];
38+
else {
39+
fprintf(stderr, "Unknown option: %s\n", argv[1]);
40+
return 1;
41+
}
42+
43+
argc -= 2;
44+
argv += 2;
45+
}
46+
47+
if (argc > 1 && !strcmp(argv[1], "--")) {
48+
argc--;
49+
argv++;
50+
}
51+
52+
if (argc < 3) {
53+
fprintf(stderr, "Usage: %s [options] <source> <destination>\n",
54+
progname);
55+
return 1;
56+
}
57+
58+
hres = CoInitialize(NULL);
59+
if (FAILED(hres))
60+
die ("Could not initialize OLE");
61+
62+
hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
63+
&IID_IShellLink, (void **)&psl);
64+
65+
if (FAILED(hres))
66+
die ("Could not get ShellLink interface");
67+
68+
hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
69+
(void **) &ppf);
70+
71+
if (FAILED(hres))
72+
die ("Could not get PersistFile interface");
73+
74+
hres = psl->lpVtbl->SetPath(psl, argv[1]);
75+
if (FAILED(hres))
76+
die ("Could not set path");
77+
78+
if (work_dir)
79+
psl->lpVtbl->SetWorkingDirectory(psl, work_dir);
80+
81+
if (show_cmd)
82+
psl->lpVtbl->SetShowCmd(psl, show_cmd);
83+
84+
if (icon_file)
85+
psl->lpVtbl->SetIconLocation(psl, icon_file, 0);
86+
if (arguments)
87+
psl->lpVtbl->SetArguments(psl, arguments);
88+
if (description)
89+
psl->lpVtbl->SetDescription(psl, description);
90+
91+
wsz[0] = 0;
92+
MultiByteToWideChar(CP_ACP,
93+
0, argv[2], -1, wsz, 1024);
94+
hres = ppf->lpVtbl->Save(ppf,
95+
(const WCHAR*)wsz, TRUE);
96+
97+
ppf->lpVtbl->Release(ppf);
98+
psl->lpVtbl->Release(psl);
99+
100+
if (FAILED(hres))
101+
die ("Could not save link");
102+
103+
CoUninitialize();
104+
return 0;
105+
}

0 commit comments

Comments
 (0)