1 /* $Id: desktop.c,v 1.7 2004/07/11 22:35:07 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 LoadDynamicImports(&DynOle32
, &Ole32
);
223 Ole32
.fn
.CoInitialize(NULL
);
225 hr
= Ole32
.fn
.CoCreateInstance(&CLSID_ShellLink
,
227 CLSCTX_INPROC_SERVER
,
232 Ole32
.fn
.CoUninitialize();
233 UnloadDynamicImports(&Ole32
);
237 hr
= psl
->lpVtbl
->QueryInterface(psl
,
242 psl
->lpVtbl
->SetDescription(psl
,
245 psl
->lpVtbl
->SetPath(psl
,
248 psl
->lpVtbl
->SetArguments(psl
,
251 psl
->lpVtbl
->SetIconLocation(psl
,
255 if (lpWorkingDirectory
!= NULL
)
257 psl
->lpVtbl
->SetWorkingDirectory(psl
,
262 psl
->lpVtbl
->SetWorkingDirectory(psl
,
263 L
"%HOMEDRIVE%%HOMEPATH%");
266 psl
->lpVtbl
->SetHotkey(psl
,
269 psl
->lpVtbl
->SetShowCmd(psl
,
272 hr
= ppf
->lpVtbl
->Save(ppf
,
278 ppf
->lpVtbl
->Release(ppf
);
281 psl
->lpVtbl
->Release(psl
);
283 Ole32
.fn
.CoUninitialize();
285 UnloadDynamicImports(&Ole32
);
287 DPRINT ("AddDesktopItemW() done\n");
294 DeleteDesktopItemA (BOOL bCommonItem
,
297 DPRINT1 ("DeleteDesktopItemA() not implemented!\n");
303 DeleteDesktopItemW (BOOL bCommonItem
,
306 WCHAR szLinkPath
[MAX_PATH
];
308 DPRINT ("DeleteDesktopItemW() called\n");
310 if (!GetDesktopPath (bCommonItem
, szLinkPath
))
312 DPRINT1 ("GetDesktopPath() failed\n");
316 wcscat (szLinkPath
, L
"\\");
317 wcscat (szLinkPath
, lpItemName
);
318 wcscat (szLinkPath
, L
".lnk");
319 DPRINT ("Link path: '%S'\n", szLinkPath
);
321 return DeleteFile (szLinkPath
);
326 CreateGroupA (LPCSTR lpGroupName
,
329 DPRINT1 ("CreateGroupA() not implemented!\n");
335 CreateGroupW (LPCWSTR lpGroupName
,
338 WCHAR szGroupPath
[MAX_PATH
];
340 DPRINT1 ("CreateGroupW() called\n");
342 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
345 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
347 DPRINT1 ("GetProgramsPath() failed\n");
350 DPRINT1 ("Programs path: '%S'\n", szGroupPath
);
352 wcscat (szGroupPath
, L
"\\");
353 wcscat (szGroupPath
, lpGroupName
);
354 DPRINT1 ("Group path: '%S'\n", szGroupPath
);
356 /* Create directory path */
357 if (!CreateDirectoryPath (szGroupPath
, NULL
))
360 /* FIXME: Notify the shell */
362 DPRINT1 ("CreateGroupW() done\n");
369 DeleteGroupA (LPCSTR lpGroupName
,
372 DPRINT1 ("DeleteGroupA() not implemented!\n");
378 DeleteGroupW (LPCWSTR lpGroupName
,
381 WCHAR szGroupPath
[MAX_PATH
];
383 DPRINT ("DeleteGroupW() called\n");
385 if (lpGroupName
== NULL
|| *lpGroupName
== 0)
388 if (!GetProgramsPath (bCommonGroup
, szGroupPath
))
390 DPRINT1 ("GetProgramsPath() failed\n");
393 DPRINT ("Programs path: '%S'\n", szGroupPath
);
395 wcscat (szGroupPath
, L
"\\");
396 wcscat (szGroupPath
, lpGroupName
);
397 DPRINT ("Group path: '%S'\n", szGroupPath
);
399 /* Remove directory path */
400 if (!RemoveDirectoryPath (szGroupPath
))
403 /* FIXME: Notify the shell */
405 DPRINT ("DeleteGroupW() done\n");
412 AddItemA (LPCSTR lpGroupName
,
416 LPCSTR lpIconLocation
,
418 LPCSTR lpWorkingDirectory
,
422 DPRINT1 ("AddItemA() not implemented!\n");
428 AddItemW (LPCWSTR lpGroupName
,
432 LPCWSTR lpIconLocation
,
434 LPCWSTR lpWorkingDirectory
,
439 WCHAR szLinkPath
[MAX_PATH
];
440 WCHAR szArguments
[MAX_PATH
];
441 WCHAR szCommand
[MAX_PATH
];
442 WIN32_FIND_DATA FindData
;
451 DPRINT ("AddItemW() called\n");
455 if (!GetProgramsPath (bCommonGroup
, szLinkPath
))
457 DPRINT1 ("GetProgramsPath() failed\n");
461 DPRINT ("Programs path: '%S'\n", szLinkPath
);
463 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
465 wcscat (szLinkPath
, L
"\\");
466 wcscat (szLinkPath
, lpGroupName
);
468 /* Make sure the path exists */
469 hFind
= FindFirstFileW (szLinkPath
,
471 if (hFind
== INVALID_HANDLE_VALUE
)
473 DPRINT ("'%S' does not exist\n", szLinkPath
);
474 if (!CreateGroupW (lpGroupName
,
480 DPRINT ("'%S' exists\n", szLinkPath
);
485 wcscat (szLinkPath
, L
"\\");
486 wcscat (szLinkPath
, lpItemName
);
487 wcscat (szLinkPath
, L
".lnk");
488 DPRINT ("Link path: '%S'\n", szLinkPath
);
490 /* Split 'lpArguments' string into command and arguments */
491 Ptr
= wcschr (lpArguments
, L
' ');
492 DPRINT ("Ptr %p lpArguments %p\n", Ptr
, lpArguments
);
495 dwLength
= (DWORD
)(Ptr
- lpArguments
);
496 DPRINT ("dwLength %lu\n", dwLength
);
497 memcpy (szCommand
, lpArguments
, dwLength
* sizeof(WCHAR
));
498 szCommand
[dwLength
] = 0;
500 wcscpy (szArguments
, Ptr
);
504 wcscpy (szCommand
, lpArguments
);
507 DPRINT ("szCommand: '%S'\n", szCommand
);
508 DPRINT ("szArguments: '%S'\n", szArguments
);
510 /* dynamically load ole32.dll */
511 LoadDynamicImports(&DynOle32
, &Ole32
);
513 Ole32
.fn
.CoInitialize(NULL
);
515 hr
= Ole32
.fn
.CoCreateInstance(&CLSID_ShellLink
,
517 CLSCTX_INPROC_SERVER
,
522 Ole32
.fn
.CoUninitialize();
523 UnloadDynamicImports(&Ole32
);
527 hr
= psl
->lpVtbl
->QueryInterface(psl
,
532 psl
->lpVtbl
->SetDescription(psl
,
535 psl
->lpVtbl
->SetPath(psl
,
538 psl
->lpVtbl
->SetArguments(psl
,
541 psl
->lpVtbl
->SetIconLocation(psl
,
545 if (lpWorkingDirectory
!= NULL
)
547 psl
->lpVtbl
->SetWorkingDirectory(psl
,
552 psl
->lpVtbl
->SetWorkingDirectory(psl
,
553 L
"%HOMEDRIVE%%HOMEPATH%");
556 psl
->lpVtbl
->SetHotkey(psl
,
559 psl
->lpVtbl
->SetShowCmd(psl
,
562 hr
= ppf
->lpVtbl
->Save(ppf
,
568 ppf
->lpVtbl
->Release(ppf
);
571 psl
->lpVtbl
->Release(psl
);
573 Ole32
.fn
.CoUninitialize();
574 UnloadDynamicImports(&Ole32
);
576 DPRINT ("AddItemW() done\n");
583 DeleteItemA (LPCSTR lpGroupName
,
588 DPRINT1 ("DeleteItemA() not implemented!\n");
594 DeleteItemW (LPCWSTR lpGroupName
,
599 WCHAR szItemPath
[MAX_PATH
];
602 DPRINT ("DeleteItemW() called\n");
604 if (!GetProgramsPath (bCommonGroup
, szItemPath
))
606 DPRINT1 ("GetProgramsPath() failed\n");
609 DPRINT ("Programs path: '%S'\n", szItemPath
);
611 if (lpGroupName
!= NULL
&& *lpGroupName
!= 0)
613 wcscat (szItemPath
, L
"\\");
614 wcscat (szItemPath
, lpGroupName
);
617 wcscat (szItemPath
, L
"\\");
618 wcscat (szItemPath
, lpItemName
);
619 wcscat (szItemPath
, L
".lnk");
620 DPRINT ("Item path: '%S'\n", szItemPath
);
622 if (!DeleteFileW (szItemPath
))
625 /* FIXME: Notify the shell */
629 Ptr
= wcsrchr (szItemPath
, L
'\\');
634 DPRINT ("Item path: '%S'\n", szItemPath
);
635 if (RemoveDirectoryW (szItemPath
))
637 /* FIXME: Notify the shell */
641 DPRINT ("DeleteItemW() done\n");