1 /* $Id: desktop.c,v 1.8 2004/07/12 10:33:04 weiden Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/userenv/desktop.c
6 * PURPOSE: Desktop and start menu support functions.
7 * PROGRAMMER: Eric Kohl
19 /* FUNCTIONS ***************************************************************/
22 GetDesktopPath (BOOL bCommonPath
,
25 WCHAR szPath
[MAX_PATH
];
30 DPRINT ("GetDesktopPath() called\n");
32 if (RegOpenKeyExW (HKEY_CURRENT_USER
,
33 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
38 DPRINT1 ("RegOpenKeyExW() failed\n");
42 dwLength
= MAX_PATH
* sizeof(WCHAR
);
43 if (RegQueryValueExW (hKey
,
44 bCommonPath
? L
"Common Desktop" : L
"Desktop",
50 DPRINT1 ("RegQueryValueExW() failed\n");
57 if (dwType
== REG_EXPAND_SZ
)
59 ExpandEnvironmentStringsW (szPath
,
65 wcscpy (lpDesktopPath
, szPath
);
68 DPRINT ("GetDesktopPath() done\n");
75 GetProgramsPath (BOOL bCommonPath
,
76 LPWSTR lpProgramsPath
)
78 WCHAR szPath
[MAX_PATH
];
83 DPRINT ("GetProgramsPath() called\n");
85 if (RegOpenKeyExW (HKEY_CURRENT_USER
,
86 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
91 DPRINT1 ("RegOpenKeyExW() failed\n");
95 dwLength
= MAX_PATH
* sizeof(WCHAR
);
96 if (RegQueryValueExW (hKey
,
97 bCommonPath
? L
"Common Programs" : L
"Programs",
103 DPRINT1 ("RegQueryValueExW() failed\n");
110 if (dwType
== REG_EXPAND_SZ
)
112 ExpandEnvironmentStringsW (szPath
,
118 wcscpy (lpProgramsPath
,
122 DPRINT ("GetProgramsPath() done\n");
129 AddDesktopItemA (BOOL bCommonItem
,
132 LPCSTR lpIconLocation
,
134 LPCSTR lpWorkingDirectory
,
138 DPRINT1 ("AddDesktopItemA() not implemented!\n");
144 AddDesktopItemW (BOOL bCommonDesktop
,
147 LPCWSTR lpIconLocation
,
149 LPCWSTR lpWorkingDirectory
,
154 WCHAR szLinkPath
[MAX_PATH
];
155 WCHAR szArguments
[MAX_PATH
];
156 WCHAR szCommand
[MAX_PATH
];
157 WIN32_FIND_DATA FindData
;
166 DPRINT ("AddDesktopItemW() called\n");
170 if (!GetDesktopPath (bCommonDesktop
, szLinkPath
))
172 DPRINT1 ("GetDesktopPath() failed\n");
175 DPRINT ("Desktop path: '%S'\n", szLinkPath
);
177 /* Make sure the path exists */
178 hFind
= FindFirstFileW (szLinkPath
,
180 if (hFind
== INVALID_HANDLE_VALUE
)
182 DPRINT ("'%S' does not exist\n", szLinkPath
);
184 /* Create directory path */
185 if (!CreateDirectoryPath (szLinkPath
, NULL
))
190 DPRINT ("'%S' exists\n", szLinkPath
);
194 /* Append backslash, item name and ".lnk" extension */
195 wcscat (szLinkPath
, L
"\\");
196 wcscat (szLinkPath
, lpItemName
);
197 wcscat (szLinkPath
, L
".lnk");
198 DPRINT ("Link path: '%S'\n", szLinkPath
);
200 /* Split 'lpArguments' string into command and arguments */
201 Ptr
= wcschr (lpArguments
, L
' ');
202 DPRINT ("Ptr %p lpArguments %p\n", Ptr
, lpArguments
);
205 dwLength
= (DWORD
)(Ptr
- lpArguments
);
206 DPRINT ("dwLength %lu\n", dwLength
);
207 memcpy (szCommand
, lpArguments
, dwLength
* sizeof(WCHAR
));
208 szCommand
[dwLength
] = 0;
210 wcscpy (szArguments
, Ptr
);
214 wcscpy (szCommand
, lpArguments
);
217 DPRINT ("szCommand: '%S'\n", szCommand
);
218 DPRINT ("szArguments: '%S'\n", szArguments
);
220 /* dynamically load ole32.dll */
221 if(!LoadDynamicImports(&DynOle32
, &Ole32
))
223 DPRINT1("USERENV: Unable to load OLE32.DLL\n");
227 Ole32
.fn
.CoInitialize(NULL
);
229 hr
= Ole32
.fn
.CoCreateInstance(&CLSID_ShellLink
,
231 CLSCTX_INPROC_SERVER
,
236 Ole32
.fn
.CoUninitialize();
237 UnloadDynamicImports(&Ole32
);
241 hr
= psl
->lpVtbl
->QueryInterface(psl
,
246 psl
->lpVtbl
->SetDescription(psl
,
249 psl
->lpVtbl
->SetPath(psl
,
252 psl
->lpVtbl
->SetArguments(psl
,
255 psl
->lpVtbl
->SetIconLocation(psl
,
259 if (lpWorkingDirectory
!= NULL
)
261 psl
->lpVtbl
->SetWorkingDirectory(psl
,
266 psl
->lpVtbl
->SetWorkingDirectory(psl
,
267 L
"%HOMEDRIVE%%HOMEPATH%");
270 psl
->lpVtbl
->SetHotkey(psl
,
273 psl
->lpVtbl
->SetShowCmd(psl
,
276 hr
= ppf
->lpVtbl
->Save(ppf
,
282 ppf
->lpVtbl
->Release(ppf
);
285 psl
->lpVtbl
->Release(psl
);
287 Ole32
.fn
.CoUninitialize();
289 UnloadDynamicImports(&Ole32
);
291 DPRINT ("AddDesktopItemW() done\n");
298 DeleteDesktopItemA (BOOL bCommonItem
,
301 DPRINT1 ("DeleteDesktopItemA() not implemented!\n");
307 DeleteDesktopItemW (BOOL bCommonItem
,
310 WCHAR szLinkPath
[MAX_PATH
];
312 DPRINT ("DeleteDesktopItemW() called\n");
314 if (!GetDesktopPath (bCommonItem
, szLinkPath
))
316 DPRINT1 ("GetDesktopPath() failed\n");
320 wcscat (szLinkPath
, L
"\\");
321 wcscat (szLinkPath
, lpItemName
);
322 wcscat (szLinkPath
, L
".lnk");
323 DPRINT ("Link path: '%S'\n", szLinkPath
);
325 return DeleteFile (szLinkPath
);
330 CreateGroupA (LPCSTR lpGroupName
,
333 DPRINT1 ("CreateGroupA() not implemented!\n");
339 CreateGroupW (LPCWSTR lpGroupName
,
342 WCHAR szGroupPath
[MAX_PATH
];
344 DPRINT1 ("CreateGroupW() called\n");
346 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
349 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
351 DPRINT1 ("GetProgramsPath() failed\n");
354 DPRINT1 ("Programs path: '%S'\n", szGroupPath
);
356 wcscat (szGroupPath
, L
"\\");
357 wcscat (szGroupPath
, lpGroupName
);
358 DPRINT1 ("Group path: '%S'\n", szGroupPath
);
360 /* Create directory path */
361 if (!CreateDirectoryPath (szGroupPath
, NULL
))
364 /* FIXME: Notify the shell */
366 DPRINT1 ("CreateGroupW() done\n");
373 DeleteGroupA (LPCSTR lpGroupName
,
376 DPRINT1 ("DeleteGroupA() not implemented!\n");
382 DeleteGroupW (LPCWSTR lpGroupName
,
385 WCHAR szGroupPath
[MAX_PATH
];
387 DPRINT ("DeleteGroupW() called\n");
389 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
392 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
394 DPRINT1 ("GetProgramsPath() failed\n");
397 DPRINT ("Programs path: '%S'\n", szGroupPath
);
399 wcscat (szGroupPath
, L
"\\");
400 wcscat (szGroupPath
, lpGroupName
);
401 DPRINT ("Group path: '%S'\n", szGroupPath
);
403 /* Remove directory path */
404 if (!RemoveDirectoryPath (szGroupPath
))
407 /* FIXME: Notify the shell */
409 DPRINT ("DeleteGroupW() done\n");
416 AddItemA (LPCSTR lpGroupName
,
420 LPCSTR lpIconLocation
,
422 LPCSTR lpWorkingDirectory
,
426 DPRINT1 ("AddItemA() not implemented!\n");
432 AddItemW (LPCWSTR lpGroupName
,
436 LPCWSTR lpIconLocation
,
438 LPCWSTR lpWorkingDirectory
,
443 WCHAR szLinkPath
[MAX_PATH
];
444 WCHAR szArguments
[MAX_PATH
];
445 WCHAR szCommand
[MAX_PATH
];
446 WIN32_FIND_DATA FindData
;
455 DPRINT ("AddItemW() called\n");
459 if (!GetProgramsPath (bCommonGroup
, szLinkPath
))
461 DPRINT1 ("GetProgramsPath() failed\n");
465 DPRINT ("Programs path: '%S'\n", szLinkPath
);
467 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
469 wcscat (szLinkPath
, L
"\\");
470 wcscat (szLinkPath
, lpGroupName
);
472 /* Make sure the path exists */
473 hFind
= FindFirstFileW (szLinkPath
,
475 if (hFind
== INVALID_HANDLE_VALUE
)
477 DPRINT ("'%S' does not exist\n", szLinkPath
);
478 if (!CreateGroupW (lpGroupName
,
484 DPRINT ("'%S' exists\n", szLinkPath
);
489 wcscat (szLinkPath
, L
"\\");
490 wcscat (szLinkPath
, lpItemName
);
491 wcscat (szLinkPath
, L
".lnk");
492 DPRINT ("Link path: '%S'\n", szLinkPath
);
494 /* Split 'lpArguments' string into command and arguments */
495 Ptr
= wcschr (lpArguments
, L
' ');
496 DPRINT ("Ptr %p lpArguments %p\n", Ptr
, lpArguments
);
499 dwLength
= (DWORD
)(Ptr
- lpArguments
);
500 DPRINT ("dwLength %lu\n", dwLength
);
501 memcpy (szCommand
, lpArguments
, dwLength
* sizeof(WCHAR
));
502 szCommand
[dwLength
] = 0;
504 wcscpy (szArguments
, Ptr
);
508 wcscpy (szCommand
, lpArguments
);
511 DPRINT ("szCommand: '%S'\n", szCommand
);
512 DPRINT ("szArguments: '%S'\n", szArguments
);
514 /* dynamically load ole32.dll */
515 if(!LoadDynamicImports(&DynOle32
, &Ole32
))
517 DPRINT1("USERENV: Unable to load OLE32.DLL\n");
521 Ole32
.fn
.CoInitialize(NULL
);
523 hr
= Ole32
.fn
.CoCreateInstance(&CLSID_ShellLink
,
525 CLSCTX_INPROC_SERVER
,
530 Ole32
.fn
.CoUninitialize();
531 UnloadDynamicImports(&Ole32
);
535 hr
= psl
->lpVtbl
->QueryInterface(psl
,
540 psl
->lpVtbl
->SetDescription(psl
,
543 psl
->lpVtbl
->SetPath(psl
,
546 psl
->lpVtbl
->SetArguments(psl
,
549 psl
->lpVtbl
->SetIconLocation(psl
,
553 if (lpWorkingDirectory
!= NULL
)
555 psl
->lpVtbl
->SetWorkingDirectory(psl
,
560 psl
->lpVtbl
->SetWorkingDirectory(psl
,
561 L
"%HOMEDRIVE%%HOMEPATH%");
564 psl
->lpVtbl
->SetHotkey(psl
,
567 psl
->lpVtbl
->SetShowCmd(psl
,
570 hr
= ppf
->lpVtbl
->Save(ppf
,
576 ppf
->lpVtbl
->Release(ppf
);
579 psl
->lpVtbl
->Release(psl
);
581 Ole32
.fn
.CoUninitialize();
582 UnloadDynamicImports(&Ole32
);
584 DPRINT ("AddItemW() done\n");
591 DeleteItemA (LPCSTR lpGroupName
,
596 DPRINT1 ("DeleteItemA() not implemented!\n");
602 DeleteItemW (LPCWSTR lpGroupName
,
607 WCHAR szItemPath
[MAX_PATH
];
610 DPRINT ("DeleteItemW() called\n");
612 if (!GetProgramsPath (bCommonGroup
, szItemPath
))
614 DPRINT1 ("GetProgramsPath() failed\n");
617 DPRINT ("Programs path: '%S'\n", szItemPath
);
619 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
621 wcscat (szItemPath
, L
"\\");
622 wcscat (szItemPath
, lpGroupName
);
625 wcscat (szItemPath
, L
"\\");
626 wcscat (szItemPath
, lpItemName
);
627 wcscat (szItemPath
, L
".lnk");
628 DPRINT ("Item path: '%S'\n", szItemPath
);
630 if (!DeleteFileW (szItemPath
))
633 /* FIXME: Notify the shell */
637 Ptr
= wcsrchr (szItemPath
, L
'\\');
642 DPRINT ("Item path: '%S'\n", szItemPath
);
643 if (RemoveDirectoryW (szItemPath
))
645 /* FIXME: Notify the shell */
649 DPRINT ("DeleteItemW() done\n");