From 4056581a2164f0571bc0ad6d0ab21e6f148ec823 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 29 Apr 2004 14:41:26 +0000 Subject: [PATCH] Implement AddDesktopItem() and DeleteDesktopItem(). svn path=/trunk/; revision=9242 --- reactos/lib/userenv/desktop.c | 246 +++++++++++++++++++++++++++++++ reactos/lib/userenv/makefile | 8 +- reactos/lib/userenv/profile.c | 11 +- reactos/lib/userenv/userenv.def | 5 + reactos/lib/userenv/userenv.edf | 5 + reactos/w32api/include/userenv.h | 8 + 6 files changed, 278 insertions(+), 5 deletions(-) create mode 100644 reactos/lib/userenv/desktop.c diff --git a/reactos/lib/userenv/desktop.c b/reactos/lib/userenv/desktop.c new file mode 100644 index 00000000000..70a9fb6352f --- /dev/null +++ b/reactos/lib/userenv/desktop.c @@ -0,0 +1,246 @@ +/* $Id: desktop.c,v 1.1 2004/04/29 14:41:26 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/userenv/desktop.c + * PURPOSE: Desktop and start menu support functions. + * PROGRAMMER: Eric Kohl + */ + +#include +#include +#include +#include +#include + +#include "internal.h" + + +/* FUNCTIONS ***************************************************************/ + +static BOOL +GetDesktopPath (BOOL bCommonPath, + LPWSTR lpDesktopPath) +{ + WCHAR szPath[MAX_PATH]; + DWORD dwLength; + DWORD dwType; + HKEY hKey; + + DPRINT ("GetDesktopPath() called\n"); + + if (RegOpenKeyExW (HKEY_CURRENT_USER, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", + 0, + KEY_ALL_ACCESS, + &hKey)) + { + DPRINT1 ("RegOpenKeyExW() failed\n"); + return FALSE; + } + + dwLength = MAX_PATH * sizeof(WCHAR); + if (RegQueryValueExW (hKey, + bCommonPath ? L"Common Desktop" : L"Desktop", + 0, + &dwType, + (LPBYTE)szPath, + &dwLength)) + { + DPRINT1 ("RegQueryValueExW() failed\n"); + RegCloseKey (hKey); + return FALSE; + } + + RegCloseKey (hKey); + + if (dwType == REG_EXPAND_SZ) + { + ExpandEnvironmentStringsW (szPath, + lpDesktopPath, + MAX_PATH); + } + else + { + wcscpy (lpDesktopPath, szPath); + } + + DPRINT ("GetDesktopPath() done\n"); + + return TRUE; +} + + +BOOL WINAPI +AddDesktopItemA (BOOL bCommonItem, + LPCSTR lpItemName, + LPCSTR lpArguments, + LPCSTR lpIconLocation, + INT iIcon, + LPCSTR lpWorkingDirectory, + WORD wHotKey, + INT iShowCmd) +{ + DPRINT1 ("AddDesktopItemA() not implemented!\n"); + return FALSE; +} + + +BOOL WINAPI +AddDesktopItemW (BOOL bCommonItem, + LPCWSTR lpItemName, + LPCWSTR lpArguments, + LPCWSTR lpIconLocation, + INT iIcon, + LPCWSTR lpWorkingDirectory, + WORD wHotKey, + INT iShowCmd) +{ + WCHAR szLinkPath[MAX_PATH]; + WCHAR szArguments[MAX_PATH]; + WCHAR szCommand[MAX_PATH]; + LPWSTR Ptr; + DWORD dwLength; + IShellLinkW* psl; + IPersistFile* ppf; + HRESULT hr; + BOOL bResult; + + DPRINT ("AddDesktopItemW() called\n"); + + bResult = FALSE; + + if (!GetDesktopPath (bCommonItem, szLinkPath)) + { + DPRINT1 ("GetDesktopPath() failed\n"); + return FALSE; + } + + DPRINT ("Desktop path: '%S'\n", szLinkPath); + + /* FIXME: Make sure the path exists */ + + wcscat (szLinkPath, L"\\"); + wcscat (szLinkPath, lpItemName); + wcscat (szLinkPath, L".lnk"); + DPRINT ("Link path: '%S'\n", szLinkPath); + + /* Split 'lpArguments' string into command and arguments */ + Ptr = wcschr (lpArguments, L' '); + DPRINT ("Ptr %p lpArguments %p\n", Ptr, lpArguments); + if (Ptr != NULL) + { + dwLength = (DWORD)(Ptr - lpArguments); + DPRINT ("dwLength %lu\n", dwLength); + memcpy (szCommand, lpArguments, dwLength * sizeof(WCHAR)); + szCommand[dwLength] = 0; + Ptr++; + wcscpy (szArguments, Ptr); + } + else + { + wcscpy (szCommand, lpArguments); + szArguments[0] = 0; + } + DPRINT ("szCommand: '%S'\n", szCommand); + DPRINT ("szArguments: '%S'\n", szArguments); + + CoInitialize(NULL); + + hr = CoCreateInstance(&CLSID_ShellLink, + NULL, + CLSCTX_INPROC_SERVER, + &IID_IShellLinkW, + (LPVOID*)&psl); + if (!SUCCEEDED(hr)) + { + CoUninitialize(); + return FALSE; + } + + hr = psl->lpVtbl->QueryInterface(psl, + &IID_IPersistFile, + (LPVOID*)&ppf); + if (SUCCEEDED(hr)) + { + psl->lpVtbl->SetDescription(psl, + lpItemName); + + psl->lpVtbl->SetPath(psl, + szCommand); + + psl->lpVtbl->SetArguments(psl, + szArguments); + + psl->lpVtbl->SetIconLocation(psl, + lpIconLocation, + iIcon); + + if (lpWorkingDirectory != NULL) + { + psl->lpVtbl->SetWorkingDirectory(psl, + lpWorkingDirectory); + } + else + { + psl->lpVtbl->SetWorkingDirectory(psl, + L"%HOMEDRIVE%%HOMEPATH%"); + } + + psl->lpVtbl->SetHotkey(psl, + wHotKey); + + psl->lpVtbl->SetShowCmd(psl, + iShowCmd); + + hr = ppf->lpVtbl->Save(ppf, + szLinkPath, + TRUE); + if (SUCCEEDED(hr)) + bResult = TRUE; + + ppf->lpVtbl->Release(ppf); + } + + psl->lpVtbl->Release(psl); + + CoUninitialize(); + + DPRINT ("AddDesktopItemW() done\n"); + + return bResult; +} + + +BOOL WINAPI +DeleteDesktopItemA (BOOL bCommonItem, + LPCSTR lpItemName) +{ + DPRINT1 ("DeleteDesktopItemA() not implemented!\n"); + return FALSE; +} + + +BOOL WINAPI +DeleteDesktopItemW (BOOL bCommonItem, + LPCWSTR lpItemName) +{ + WCHAR szLinkPath[MAX_PATH]; + + DPRINT ("DeleteDesktopItemW() called\n"); + + if (!GetDesktopPath (bCommonItem, szLinkPath)) + { + DPRINT1 ("GetDesktopPath() failed\n"); + return FALSE; + } + + wcscat (szLinkPath, L"\\"); + wcscat (szLinkPath, lpItemName); + wcscat (szLinkPath, L".lnk"); + DPRINT ("Link path: '%S'\n", szLinkPath); + + return DeleteFile (szLinkPath); +} + +/* EOF */ diff --git a/reactos/lib/userenv/makefile b/reactos/lib/userenv/makefile index 032ca9cbcf9..571786f411d 100644 --- a/reactos/lib/userenv/makefile +++ b/reactos/lib/userenv/makefile @@ -6,17 +6,17 @@ TARGET_NAME = userenv TARGET_BASE = 0x74850000 -TARGET_CFLAGS = -fno-builtin -D__USE_W32API +TARGET_CFLAGS = -fno-builtin -D__USE_W32API -D_WIN32_IE=0x0400 # require os code to explicitly request A/W version of structs/functions TARGET_CFLAGS += -DUNICODE -D_UNICODE -Wall -Werror TARGET_LFLAGS = -nostdlib -nostartfiles -TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a +TARGET_SDKLIBS = ntdll.a kernel32.a advapi32.a ole32.a wine_uuid.a -TARGET_OBJECTS = directory.o environment.o profile.o misc.o registry.o \ - setup.o userenv.o +TARGET_OBJECTS = desktop.o directory.o environment.o profile.o misc.o \ + registry.o setup.o userenv.o DEP_OBJECTS = $(TARGET_OBJECTS) diff --git a/reactos/lib/userenv/profile.c b/reactos/lib/userenv/profile.c index 664e24d02b7..d52872ecac8 100644 --- a/reactos/lib/userenv/profile.c +++ b/reactos/lib/userenv/profile.c @@ -1,4 +1,4 @@ -/* $Id: profile.c,v 1.9 2004/04/19 10:51:17 ekohl Exp $ +/* $Id: profile.c,v 1.10 2004/04/29 14:41:26 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -646,6 +646,15 @@ CheckForLoadedProfile (HANDLE hToken) } +BOOL WINAPI +LoadUserProfileA (HANDLE hToken, + LPPROFILEINFOA lpProfileInfo) +{ + DPRINT ("LoadUserProfileA() not implemented\n"); + return FALSE; +} + + BOOL WINAPI LoadUserProfileW (HANDLE hToken, LPPROFILEINFOW lpProfileInfo) diff --git a/reactos/lib/userenv/userenv.def b/reactos/lib/userenv/userenv.def index 8eb7e669068..4c52e97a033 100644 --- a/reactos/lib/userenv/userenv.def +++ b/reactos/lib/userenv/userenv.def @@ -3,12 +3,17 @@ EXPORTS InitializeProfiles@0 @100 NONAME CreateUserProfileA@8 @109 NONAME CreateUserProfileW@8 @110 NONAME +AddDesktopItemA@32 @113 NONAME +AddDesktopItemW@32 @114 NONAME +DeleteDesktopItemA@8 @115 NONAME +DeleteDesktopItemW@8 @116 NONAME CreateEnvironmentBlock@12 DestroyEnvironmentBlock@4 GetAllUsersProfileDirectoryW@8 GetDefaultUserProfileDirectoryW@8 GetProfilesDirectoryW@8 GetUserProfileDirectoryW@12 +LoadUserProfileA@8 LoadUserProfileW@8 UnloadUserProfile@8 ;EOF diff --git a/reactos/lib/userenv/userenv.edf b/reactos/lib/userenv/userenv.edf index 173edb76516..20a0169c053 100644 --- a/reactos/lib/userenv/userenv.edf +++ b/reactos/lib/userenv/userenv.edf @@ -3,12 +3,17 @@ EXPORTS InitializeProfiles=InitializeProfiles@0 @100 NONAME CreateUserProfileA=CreateUserProfileA@8 @109 NONAME CreateUserProfileW=CreateUserProfileW@8 @110 NONAME +AddDesktopItemA=AddDesktopItemA@32 @113 NONAME +AddDesktopItemW=AddDesktopItemW@32 @114 NONAME +DeleteDesktopItemA=DeleteDesktopItemA@8 @115 NONAME +DeleteDesktopItemW=DeleteDesktopItemW@8 @116 NONAME CreateEnvironmentBlock=CreateEnvironmentBlock@12 DestroyEnvironmentBlock=DestroyEnvironmentBlock@4 GetAllUsersProfileDirectoryW=GetAllUsersProfileDirectoryW@8 GetDefaultUserProfileDirectoryW=GetDefaultUserProfileDirectoryW@8 GetProfilesDirectoryW=GetProfilesDirectoryW@8 GetUserProfileDirectoryW=GetUserProfileDirectoryW@12 +LoadUserProfileA=LoadUserProfileA@8 LoadUserProfileW=LoadUserProfileW@8 UnloadUserProfile=UnloadUserProfile@8 ;EOF diff --git a/reactos/w32api/include/userenv.h b/reactos/w32api/include/userenv.h index 53d550b1165..3328758fe6c 100644 --- a/reactos/w32api/include/userenv.h +++ b/reactos/w32api/include/userenv.h @@ -40,6 +40,10 @@ typedef struct _PROFILEINFOW BOOL WINAPI InitializeProfiles (VOID); BOOL WINAPI CreateUserProfileA (PSID, LPCSTR); BOOL WINAPI CreateUserProfileW (PSID, LPCWSTR); +BOOL WINAPI AddDesktopItemA (BOOL, LPCSTR, LPCSTR, LPCSTR, INT, LPCSTR, WORD, INT); +BOOL WINAPI AddDesktopItemW (BOOL, LPCWSTR, LPCWSTR, LPCWSTR, INT, LPCWSTR, WORD, INT); +BOOL WINAPI DeleteDesktopItemA (BOOL, LPCSTR); +BOOL WINAPI DeleteDesktopItemW (BOOL, LPCWSTR); /* end private */ BOOL WINAPI LoadUserProfileA (HANDLE, LPPROFILEINFOA); BOOL WINAPI LoadUserProfileW (HANDLE, LPPROFILEINFOW); @@ -62,6 +66,8 @@ typedef PROFILEINFOW PROFILEINFO; typedef LPPROFILEINFOW LPPROFILEINFO; /* begin private */ #define CreateUserProfile CreateUserProfileW +#define AddDesktopItem AddDesktopItemW +#define DeleteDesktopItem DeleteDesktopItemW /* end private */ #define LoadUserProfile LoadUserProfileW #define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryW @@ -73,6 +79,8 @@ typedef PROFILEINFOA PROFILEINFO; typedef LPPROFILEINFOA LPPROFILEINFO; /* begin private */ #define CreateUserProfile CreateUserProfileA +#define AddDesktopItem AddDesktopItemA +#define DeleteDesktopItem DeleteDesktopItemA /* end private */ #define LoadUserProfile LoadUserProfileA #define GetAllUsersProfileDirectory GetAllUsersProfileDirectoryA