diff --git a/reactos/lib/userenv/desktop.c b/reactos/lib/userenv/desktop.c index f842e2a504a..04fd343216a 100644 --- a/reactos/lib/userenv/desktop.c +++ b/reactos/lib/userenv/desktop.c @@ -1,4 +1,4 @@ -/* $Id: desktop.c,v 1.4 2004/05/04 13:11:22 ekohl Exp $ +/* $Id: desktop.c,v 1.5 2004/05/05 15:29:15 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -153,6 +153,8 @@ AddDesktopItemW (BOOL bCommonDesktop, WCHAR szLinkPath[MAX_PATH]; WCHAR szArguments[MAX_PATH]; WCHAR szCommand[MAX_PATH]; + WIN32_FIND_DATA FindData; + HANDLE hFind; LPWSTR Ptr; DWORD dwLength; IShellLinkW* psl; @@ -169,11 +171,26 @@ AddDesktopItemW (BOOL bCommonDesktop, DPRINT1 ("GetDesktopPath() failed\n"); return FALSE; } - DPRINT ("Desktop path: '%S'\n", szLinkPath); - /* FIXME: Make sure the path exists */ + /* Make sure the path exists */ + hFind = FindFirstFileW (szLinkPath, + &FindData); + if (hFind == INVALID_HANDLE_VALUE) + { + DPRINT1 ("'%S' does not exist\n", szLinkPath); + /* FIXME: create directory path */ + if (!CreateDirectoryW (szLinkPath, NULL)) + return FALSE; + } + else + { + DPRINT1 ("'%S' exists\n", szLinkPath); + FindClose (hFind); + } + + /* Append backslash, item name and ".lnk" extension */ wcscat (szLinkPath, L"\\"); wcscat (szLinkPath, lpItemName); wcscat (szLinkPath, L".lnk"); @@ -329,7 +346,7 @@ CreateGroupW (LPCWSTR lpGroupName, wcscat (szGroupPath, lpGroupName); DPRINT ("Group path: '%S'\n", szGroupPath); - /* FIXME: Create nested directories */ + /* FIXME: Create directory path */ if (!CreateDirectoryW (szGroupPath, NULL)) return FALSE; @@ -372,7 +389,7 @@ DeleteGroupW (LPCWSTR lpGroupName, wcscat (szGroupPath, lpGroupName); DPRINT ("Group path: '%S'\n", szGroupPath); - /* FIXME: Remove nested directories */ + /* FIXME: Remove directory path */ if (!RemoveDirectoryW (szGroupPath)) return FALSE; @@ -384,6 +401,171 @@ DeleteGroupW (LPCWSTR lpGroupName, } +BOOL WINAPI +AddItemA (LPCSTR lpGroupName, + BOOL bCommonGroup, + LPCSTR lpItemName, + LPCSTR lpArguments, + LPCSTR lpIconLocation, + INT iIcon, + LPCSTR lpWorkingDirectory, + WORD wHotKey, + INT iShowCmd) +{ + DPRINT1 ("AddItemA() not implemented!\n"); + return FALSE; +} + + +BOOL WINAPI +AddItemW (LPCWSTR lpGroupName, + BOOL bCommonGroup, + 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]; + WIN32_FIND_DATA FindData; + HANDLE hFind; + LPWSTR Ptr; + DWORD dwLength; + IShellLinkW* psl; + IPersistFile* ppf; + HRESULT hr; + BOOL bResult; + + DPRINT ("AddDesktopItemW() called\n"); + + bResult = FALSE; + + if (!GetProgramsPath (bCommonGroup, szLinkPath)) + { + DPRINT1 ("GetProgramsPath() failed\n"); + return FALSE; + } + + DPRINT ("Programs path: '%S'\n", szLinkPath); + + if (lpGroupName != NULL && *lpGroupName != 0) + { + wcscat (szLinkPath, L"\\"); + wcscat (szLinkPath, lpGroupName); + + /* Make sure the path exists */ + hFind = FindFirstFileW (szLinkPath, + &FindData); + if (hFind == INVALID_HANDLE_VALUE) + { + DPRINT ("'%S' does not exist\n", szLinkPath); + if (!CreateGroupW (lpGroupName, + bCommonGroup)) + return FALSE; + } + else + { + DPRINT ("'%S' exists\n", szLinkPath); + FindClose (hFind); + } + } + + 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 DeleteItemA (LPCSTR lpGroupName, BOOL bCommonGroup, @@ -436,6 +618,7 @@ DeleteItemW (LPCWSTR lpGroupName, return TRUE; *Ptr = 0; + DPRINT ("Item path: '%S'\n", szItemPath); if (RemoveDirectoryW (szItemPath)) { /* FIXME: Notify the shell */ diff --git a/reactos/lib/userenv/userenv.def b/reactos/lib/userenv/userenv.def index 9e76dec868f..5536bf26be0 100644 --- a/reactos/lib/userenv/userenv.def +++ b/reactos/lib/userenv/userenv.def @@ -5,6 +5,8 @@ CreateGroupA@8 @101 NONAME CreateGroupW@8 @102 NONAME DeleteGroupA@8 @103 NONAME DeleteGroupW@8 @104 NONAME +AddItemA@36 @105 NONAME +AddItemW@36 @106 NONAME DeleteItemA@16 @107 NONAME DeleteItemW@16 @108 NONAME CreateUserProfileA@8 @109 NONAME diff --git a/reactos/lib/userenv/userenv.edf b/reactos/lib/userenv/userenv.edf index 05b97575bcb..7644d15cbe0 100644 --- a/reactos/lib/userenv/userenv.edf +++ b/reactos/lib/userenv/userenv.edf @@ -5,6 +5,8 @@ CreateGroupA=CreateGroupA@8 @101 NONAME CreateGroupW=CreateGroupW@8 @102 NONAME DeleteGroupA=DeleteGroupA@8 @103 NONAME DeleteGroupW=DeleteGroupW@8 @104 NONAME +AddItemA=AddItemA@36 @105 NONAME +AddItemW=AddItemW@36 @106 NONAME DeleteItemA=DeleteItemA@16 @107 NONAME DeleteItemW=DeleteItemW@16 @108 NONAME CreateUserProfileA=CreateUserProfileA@8 @109 NONAME diff --git a/reactos/w32api/include/userenv.h b/reactos/w32api/include/userenv.h index bd836e92d30..003ff700059 100644 --- a/reactos/w32api/include/userenv.h +++ b/reactos/w32api/include/userenv.h @@ -48,6 +48,8 @@ BOOL WINAPI CreateGroupA (LPCSTR, BOOL); BOOL WINAPI CreateGroupW (LPCWSTR, BOOL); BOOL WINAPI DeleteGroupA (LPCSTR, BOOL); BOOL WINAPI DeleteGroupW (LPCWSTR, BOOL); +BOOL WINAPI AddItemA (LPCSTR, BOOL, LPCSTR, LPCSTR, LPCSTR, INT, LPCSTR, WORD, INT); +BOOL WINAPI AddItemW (LPCWSTR, BOOL, LPCWSTR, LPCWSTR, LPCWSTR, INT, LPCWSTR, WORD, INT); BOOL WINAPI DeleteItemA (LPCSTR, BOOL, LPCSTR, BOOL); BOOL WINAPI DeleteItemW (LPCWSTR, BOOL, LPCWSTR, BOOL); /* end private */ @@ -76,6 +78,7 @@ typedef LPPROFILEINFOW LPPROFILEINFO; #define DeleteDesktopItem DeleteDesktopItemW #define CreateGroup CreateGroupW #define DeleteGroup DeleteGroupW +#define AddItem AddItemW #define DeleteItem DeleteItemW /* end private */ #define LoadUserProfile LoadUserProfileW @@ -92,6 +95,7 @@ typedef LPPROFILEINFOA LPPROFILEINFO; #define DeleteDesktopItem DeleteDesktopItemA #define CreateGroup CreateGroupA #define DeleteGroup DeleteGroupA +#define AddItem AddItemA #define DeleteItem DeleteItemA /* end private */ #define LoadUserProfile LoadUserProfileA