]> cygwin.com Git - cygwin-apps/setup.git/blame - mklink2.cc
Implement command-line selection of packages to install and make
[cygwin-apps/setup.git] / mklink2.cc
CommitLineData
51ebb760 1#define CINTERFACE
b24c88b3 2#include <stdlib.h>
904d24fe
DD
3#include "win32.h"
4#include "shlobj.h"
b24c88b3 5#include "mklink2.h"
904d24fe 6
b24c88b3
RC
7#if 0
8static const char *cvsid =
9 "\n%%% $Id$\n";
10#endif
8507f105 11
904d24fe
DD
12/* This part of the code must be in C because the C++ interface to COM
13doesn't work. */
14
51ebb760 15extern "C"
904d24fe 16void
3c054baf 17make_link_2 (char const *exepath, char const *args, char const *icon, char const *lname)
904d24fe
DD
18{
19 IShellLink *sl;
20 IPersistFile *pf;
4875ac88 21 WCHAR widepath[MAX_PATH];
904d24fe 22
931f2755
RC
23 CoCreateInstance (&CLSID_ShellLink, NULL,
24 CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID *) & sl);
25 sl->lpVtbl->QueryInterface (sl, &IID_IPersistFile, (void **) &pf);
904d24fe
DD
26
27 sl->lpVtbl->SetPath (sl, exepath);
28 sl->lpVtbl->SetArguments (sl, args);
29 sl->lpVtbl->SetIconLocation (sl, icon, 0);
30
4875ac88 31 MultiByteToWideChar (CP_ACP, 0, lname, -1, widepath, MAX_PATH);
904d24fe
DD
32 pf->lpVtbl->Save (pf, widepath, TRUE);
33
34 pf->lpVtbl->Release (pf);
35 sl->lpVtbl->Release (sl);
36}
b24c88b3
RC
37
38#define SYMLINK_COOKIE "!<symlink>"
39
40/* Predicate: file is not currently in existence.
41 * A file race can occur otherwise.
42 */
51ebb760 43extern "C"
b24c88b3
RC
44int
45mkcygsymlink (const char *from, const char *to)
46{
47 char buf[512];
48 unsigned long w;
49 HANDLE h = CreateFileA (from, GENERIC_WRITE, 0, 0, CREATE_NEW,
50 FILE_ATTRIBUTE_NORMAL, 0);
51 if (h == INVALID_HANDLE_VALUE)
52 return 1;
53 strcpy (buf, SYMLINK_COOKIE);
54 strcat (buf, to);
55 if (WriteFile (h, buf, strlen (buf) + 1, &w, NULL))
56 {
57 CloseHandle (h);
58 SetFileAttributesA (from, FILE_ATTRIBUTE_SYSTEM);
59 return 0;
60 }
61 CloseHandle (h);
62 DeleteFileA (from);
63 return 1;
64}
This page took 0.046478 seconds and 5 git commands to generate.