Installer: Update Inno Setup to version 5.5.3 (Unicode)
[msysgit.git] / share / msysGit / create-shortcut.c
blobdf5e13c921e88757ddc8a53c614c3ee46f9b9a52
1 #include <stdio.h>
2 #include <shlobj.h>
4 void die(const char *message)
6 CoUninitialize();
7 fprintf(stderr, "%s\n", message);
8 fprintf(stderr, "last error: %d\n", GetLastError());
9 exit(1);
12 int main(int argc, char **argv)
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;
19 static WCHAR wsz[1024];
20 HRESULT hres;
21 IShellLink* psl;
22 IPersistFile* ppf;
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;
43 argc -= 2;
44 argv += 2;
47 if (argc > 1 && !strcmp(argv[1], "--")) {
48 argc--;
49 argv++;
52 if (argc < 3) {
53 fprintf(stderr, "Usage: %s [options] <source> <destination>\n",
54 progname);
55 return 1;
58 hres = CoInitialize(NULL);
59 if (FAILED(hres))
60 die ("Could not initialize OLE");
62 hres = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
63 &IID_IShellLink, (void **)&psl);
65 if (FAILED(hres))
66 die ("Could not get ShellLink interface");
68 hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
69 (void **) &ppf);
71 if (FAILED(hres))
72 die ("Could not get PersistFile interface");
74 hres = psl->lpVtbl->SetPath(psl, argv[1]);
75 if (FAILED(hres))
76 die ("Could not set path");
78 if (work_dir)
79 psl->lpVtbl->SetWorkingDirectory(psl, work_dir);
81 if (show_cmd)
82 psl->lpVtbl->SetShowCmd(psl, show_cmd);
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);
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);
97 ppf->lpVtbl->Release(ppf);
98 psl->lpVtbl->Release(psl);
100 if (FAILED(hres))
101 die ("Could not save link");
103 CoUninitialize();
104 return 0;