1 /* $Id: desktop.c,v 1.6 2004/05/07 11:18:53 ekohl 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
,
153 WCHAR szLinkPath
[MAX_PATH
];
154 WCHAR szArguments
[MAX_PATH
];
155 WCHAR szCommand
[MAX_PATH
];
156 WIN32_FIND_DATA FindData
;
165 DPRINT ("AddDesktopItemW() called\n");
169 if (!GetDesktopPath (bCommonDesktop
, szLinkPath
))
171 DPRINT1 ("GetDesktopPath() failed\n");
174 DPRINT ("Desktop path: '%S'\n", szLinkPath
);
176 /* Make sure the path exists */
177 hFind
= FindFirstFileW (szLinkPath
,
179 if (hFind
== INVALID_HANDLE_VALUE
)
181 DPRINT ("'%S' does not exist\n", szLinkPath
);
183 /* Create directory path */
184 if (!CreateDirectoryPath (szLinkPath
, NULL
))
189 DPRINT ("'%S' exists\n", szLinkPath
);
193 /* Append backslash, item name and ".lnk" extension */
194 wcscat (szLinkPath
, L
"\\");
195 wcscat (szLinkPath
, lpItemName
);
196 wcscat (szLinkPath
, L
".lnk");
197 DPRINT ("Link path: '%S'\n", szLinkPath
);
199 /* Split 'lpArguments' string into command and arguments */
200 Ptr
= wcschr (lpArguments
, L
' ');
201 DPRINT ("Ptr %p lpArguments %p\n", Ptr
, lpArguments
);
204 dwLength
= (DWORD
)(Ptr
- lpArguments
);
205 DPRINT ("dwLength %lu\n", dwLength
);
206 memcpy (szCommand
, lpArguments
, dwLength
* sizeof(WCHAR
));
207 szCommand
[dwLength
] = 0;
209 wcscpy (szArguments
, Ptr
);
213 wcscpy (szCommand
, lpArguments
);
216 DPRINT ("szCommand: '%S'\n", szCommand
);
217 DPRINT ("szArguments: '%S'\n", szArguments
);
221 hr
= CoCreateInstance(&CLSID_ShellLink
,
223 CLSCTX_INPROC_SERVER
,
232 hr
= psl
->lpVtbl
->QueryInterface(psl
,
237 psl
->lpVtbl
->SetDescription(psl
,
240 psl
->lpVtbl
->SetPath(psl
,
243 psl
->lpVtbl
->SetArguments(psl
,
246 psl
->lpVtbl
->SetIconLocation(psl
,
250 if (lpWorkingDirectory
!= NULL
)
252 psl
->lpVtbl
->SetWorkingDirectory(psl
,
257 psl
->lpVtbl
->SetWorkingDirectory(psl
,
258 L
"%HOMEDRIVE%%HOMEPATH%");
261 psl
->lpVtbl
->SetHotkey(psl
,
264 psl
->lpVtbl
->SetShowCmd(psl
,
267 hr
= ppf
->lpVtbl
->Save(ppf
,
273 ppf
->lpVtbl
->Release(ppf
);
276 psl
->lpVtbl
->Release(psl
);
280 DPRINT ("AddDesktopItemW() done\n");
287 DeleteDesktopItemA (BOOL bCommonItem
,
290 DPRINT1 ("DeleteDesktopItemA() not implemented!\n");
296 DeleteDesktopItemW (BOOL bCommonItem
,
299 WCHAR szLinkPath
[MAX_PATH
];
301 DPRINT ("DeleteDesktopItemW() called\n");
303 if (!GetDesktopPath (bCommonItem
, szLinkPath
))
305 DPRINT1 ("GetDesktopPath() failed\n");
309 wcscat (szLinkPath
, L
"\\");
310 wcscat (szLinkPath
, lpItemName
);
311 wcscat (szLinkPath
, L
".lnk");
312 DPRINT ("Link path: '%S'\n", szLinkPath
);
314 return DeleteFile (szLinkPath
);
319 CreateGroupA (LPCSTR lpGroupName
,
322 DPRINT1 ("CreateGroupA() not implemented!\n");
328 CreateGroupW (LPCWSTR lpGroupName
,
331 WCHAR szGroupPath
[MAX_PATH
];
333 DPRINT1 ("CreateGroupW() called\n");
335 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
338 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
340 DPRINT1 ("GetProgramsPath() failed\n");
343 DPRINT1 ("Programs path: '%S'\n", szGroupPath
);
345 wcscat (szGroupPath
, L
"\\");
346 wcscat (szGroupPath
, lpGroupName
);
347 DPRINT1 ("Group path: '%S'\n", szGroupPath
);
349 /* Create directory path */
350 if (!CreateDirectoryPath (szGroupPath
, NULL
))
353 /* FIXME: Notify the shell */
355 DPRINT1 ("CreateGroupW() done\n");
362 DeleteGroupA (LPCSTR lpGroupName
,
365 DPRINT1 ("DeleteGroupA() not implemented!\n");
371 DeleteGroupW (LPCWSTR lpGroupName
,
374 WCHAR szGroupPath
[MAX_PATH
];
376 DPRINT ("DeleteGroupW() called\n");
378 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
381 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
383 DPRINT1 ("GetProgramsPath() failed\n");
386 DPRINT ("Programs path: '%S'\n", szGroupPath
);
388 wcscat (szGroupPath
, L
"\\");
389 wcscat (szGroupPath
, lpGroupName
);
390 DPRINT ("Group path: '%S'\n", szGroupPath
);
392 /* Remove directory path */
393 if (!RemoveDirectoryPath (szGroupPath
))
396 /* FIXME: Notify the shell */
398 DPRINT ("DeleteGroupW() done\n");
405 AddItemA (LPCSTR lpGroupName
,
409 LPCSTR lpIconLocation
,
411 LPCSTR lpWorkingDirectory
,
415 DPRINT1 ("AddItemA() not implemented!\n");
421 AddItemW (LPCWSTR lpGroupName
,
425 LPCWSTR lpIconLocation
,
427 LPCWSTR lpWorkingDirectory
,
431 WCHAR szLinkPath
[MAX_PATH
];
432 WCHAR szArguments
[MAX_PATH
];
433 WCHAR szCommand
[MAX_PATH
];
434 WIN32_FIND_DATA FindData
;
443 DPRINT ("AddItemW() called\n");
447 if (!GetProgramsPath (bCommonGroup
, szLinkPath
))
449 DPRINT1 ("GetProgramsPath() failed\n");
453 DPRINT ("Programs path: '%S'\n", szLinkPath
);
455 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
457 wcscat (szLinkPath
, L
"\\");
458 wcscat (szLinkPath
, lpGroupName
);
460 /* Make sure the path exists */
461 hFind
= FindFirstFileW (szLinkPath
,
463 if (hFind
== INVALID_HANDLE_VALUE
)
465 DPRINT ("'%S' does not exist\n", szLinkPath
);
466 if (!CreateGroupW (lpGroupName
,
472 DPRINT ("'%S' exists\n", szLinkPath
);
477 wcscat (szLinkPath
, L
"\\");
478 wcscat (szLinkPath
, lpItemName
);
479 wcscat (szLinkPath
, L
".lnk");
480 DPRINT ("Link path: '%S'\n", szLinkPath
);
482 /* Split 'lpArguments' string into command and arguments */
483 Ptr
= wcschr (lpArguments
, L
' ');
484 DPRINT ("Ptr %p lpArguments %p\n", Ptr
, lpArguments
);
487 dwLength
= (DWORD
)(Ptr
- lpArguments
);
488 DPRINT ("dwLength %lu\n", dwLength
);
489 memcpy (szCommand
, lpArguments
, dwLength
* sizeof(WCHAR
));
490 szCommand
[dwLength
] = 0;
492 wcscpy (szArguments
, Ptr
);
496 wcscpy (szCommand
, lpArguments
);
499 DPRINT ("szCommand: '%S'\n", szCommand
);
500 DPRINT ("szArguments: '%S'\n", szArguments
);
504 hr
= CoCreateInstance(&CLSID_ShellLink
,
506 CLSCTX_INPROC_SERVER
,
515 hr
= psl
->lpVtbl
->QueryInterface(psl
,
520 psl
->lpVtbl
->SetDescription(psl
,
523 psl
->lpVtbl
->SetPath(psl
,
526 psl
->lpVtbl
->SetArguments(psl
,
529 psl
->lpVtbl
->SetIconLocation(psl
,
533 if (lpWorkingDirectory
!= NULL
)
535 psl
->lpVtbl
->SetWorkingDirectory(psl
,
540 psl
->lpVtbl
->SetWorkingDirectory(psl
,
541 L
"%HOMEDRIVE%%HOMEPATH%");
544 psl
->lpVtbl
->SetHotkey(psl
,
547 psl
->lpVtbl
->SetShowCmd(psl
,
550 hr
= ppf
->lpVtbl
->Save(ppf
,
556 ppf
->lpVtbl
->Release(ppf
);
559 psl
->lpVtbl
->Release(psl
);
563 DPRINT ("AddItemW() done\n");
570 DeleteItemA (LPCSTR lpGroupName
,
575 DPRINT1 ("DeleteItemA() not implemented!\n");
581 DeleteItemW (LPCWSTR lpGroupName
,
586 WCHAR szItemPath
[MAX_PATH
];
589 DPRINT ("DeleteItemW() called\n");
591 if (!GetProgramsPath (bCommonGroup
, szItemPath
))
593 DPRINT1 ("GetProgramsPath() failed\n");
596 DPRINT ("Programs path: '%S'\n", szItemPath
);
598 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
600 wcscat (szItemPath
, L
"\\");
601 wcscat (szItemPath
, lpGroupName
);
604 wcscat (szItemPath
, L
"\\");
605 wcscat (szItemPath
, lpItemName
);
606 wcscat (szItemPath
, L
".lnk");
607 DPRINT ("Item path: '%S'\n", szItemPath
);
609 if (!DeleteFileW (szItemPath
))
612 /* FIXME: Notify the shell */
616 Ptr
= wcsrchr (szItemPath
, L
'\\');
621 DPRINT ("Item path: '%S'\n", szItemPath
);
622 if (RemoveDirectoryW (szItemPath
))
624 /* FIXME: Notify the shell */
628 DPRINT ("DeleteItemW() done\n");