ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

desktop.c
Go to the documentation of this file.
00001 /*
00002  *  ReactOS kernel
00003  *  Copyright (C) 2004 ReactOS Team
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 /* $Id: desktop.c 43790 2009-10-27 10:34:16Z dgorbachev $
00020  *
00021  * COPYRIGHT:       See COPYING in the top level directory
00022  * PROJECT:         ReactOS system libraries
00023  * FILE:            lib/userenv/desktop.c
00024  * PURPOSE:         Desktop and start menu support functions.
00025  * PROGRAMMER:      Eric Kohl
00026  */
00027 
00028 #include <precomp.h>
00029 
00030 #define NDEBUG
00031 #include <debug.h>
00032 
00033 
00034 /* FUNCTIONS ***************************************************************/
00035 
00036 static BOOL
00037 GetDesktopPath (BOOL bCommonPath,
00038         LPWSTR lpDesktopPath)
00039 {
00040   WCHAR szPath[MAX_PATH];
00041   DWORD dwLength;
00042   DWORD dwType;
00043   HKEY hKey;
00044   LONG Error;
00045 
00046   DPRINT ("GetDesktopPath() called\n");
00047 
00048   Error = RegOpenKeyExW (HKEY_CURRENT_USER,
00049                  L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
00050                  0,
00051                  KEY_QUERY_VALUE,
00052                  &hKey);
00053   if (Error != ERROR_SUCCESS)
00054     {
00055       DPRINT1 ("RegOpenKeyExW() failed\n");
00056       SetLastError((DWORD)Error);
00057       return FALSE;
00058     }
00059 
00060   dwLength = MAX_PATH * sizeof(WCHAR);
00061   Error = RegQueryValueExW (hKey,
00062                 bCommonPath ? L"Common Desktop" : L"Desktop",
00063                 0,
00064                 &dwType,
00065                 (LPBYTE)szPath,
00066                &dwLength);
00067   if (Error != ERROR_SUCCESS)
00068     {
00069       DPRINT1 ("RegQueryValueExW() failed\n");
00070       RegCloseKey (hKey);
00071       SetLastError((DWORD)Error);
00072       return FALSE;
00073     }
00074 
00075   RegCloseKey (hKey);
00076 
00077   if (dwType == REG_EXPAND_SZ)
00078     {
00079       ExpandEnvironmentStringsW (szPath,
00080                  lpDesktopPath,
00081                  MAX_PATH);
00082     }
00083   else
00084     {
00085       wcscpy (lpDesktopPath, szPath);
00086     }
00087 
00088   DPRINT ("GetDesktopPath() done\n");
00089 
00090   return TRUE;
00091 }
00092 
00093 
00094 static BOOL
00095 GetProgramsPath (BOOL bCommonPath,
00096          LPWSTR lpProgramsPath)
00097 {
00098   WCHAR szPath[MAX_PATH];
00099   DWORD dwLength;
00100   DWORD dwType;
00101   HKEY hKey;
00102   LONG Error;
00103 
00104   DPRINT ("GetProgramsPath() called\n");
00105 
00106   Error = RegOpenKeyExW (HKEY_CURRENT_USER,
00107                  L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
00108                  0,
00109                  KEY_QUERY_VALUE,
00110                  &hKey);
00111   if (Error != ERROR_SUCCESS)
00112     {
00113       DPRINT1 ("RegOpenKeyExW() failed\n");
00114       SetLastError((DWORD)Error);
00115       return FALSE;
00116     }
00117 
00118   dwLength = MAX_PATH * sizeof(WCHAR);
00119   Error = RegQueryValueExW (hKey,
00120                 bCommonPath ? L"Common Programs" : L"Programs",
00121                 0,
00122                 &dwType,
00123                 (LPBYTE)szPath,
00124                 &dwLength);
00125   if (Error != ERROR_SUCCESS)
00126     {
00127       DPRINT1 ("RegQueryValueExW() failed\n");
00128       RegCloseKey (hKey);
00129       SetLastError((DWORD)Error);
00130       return FALSE;
00131     }
00132 
00133   RegCloseKey (hKey);
00134 
00135   if (dwType == REG_EXPAND_SZ)
00136     {
00137       ExpandEnvironmentStringsW (szPath,
00138                  lpProgramsPath,
00139                  MAX_PATH);
00140     }
00141   else
00142     {
00143       wcscpy (lpProgramsPath,
00144           szPath);
00145     }
00146 
00147   DPRINT ("GetProgramsPath() done\n");
00148 
00149   return TRUE;
00150 }
00151 
00152 
00153 BOOL WINAPI
00154 AddDesktopItemA (BOOL bCommonItem,
00155          LPCSTR lpItemName,
00156          LPCSTR lpArguments,
00157          LPCSTR lpIconLocation,
00158          INT iIcon,
00159          LPCSTR lpWorkingDirectory, /* Optional */
00160          WORD wHotKey,
00161          INT iShowCmd)
00162 {
00163   UNICODE_STRING ItemName;
00164   UNICODE_STRING Arguments;
00165   UNICODE_STRING IconLocation;
00166   UNICODE_STRING WorkingDirectory;
00167   BOOL bResult;
00168   NTSTATUS Status;
00169 
00170   Status = RtlCreateUnicodeStringFromAsciiz(&ItemName,
00171                         (LPSTR)lpItemName);
00172   if (!NT_SUCCESS(Status))
00173     {
00174       SetLastError (RtlNtStatusToDosError (Status));
00175       return FALSE;
00176     }
00177 
00178   Status = RtlCreateUnicodeStringFromAsciiz(&Arguments,
00179                         (LPSTR)lpArguments);
00180   if (!NT_SUCCESS(Status))
00181     {
00182       RtlFreeUnicodeString(&ItemName);
00183       SetLastError (RtlNtStatusToDosError (Status));
00184       return FALSE;
00185     }
00186 
00187   Status = RtlCreateUnicodeStringFromAsciiz(&IconLocation,
00188                         (LPSTR)lpIconLocation);
00189   if (!NT_SUCCESS(Status))
00190     {
00191       RtlFreeUnicodeString(&Arguments);
00192       RtlFreeUnicodeString(&ItemName);
00193       SetLastError (RtlNtStatusToDosError (Status));
00194       return FALSE;
00195     }
00196 
00197   if (lpWorkingDirectory != NULL)
00198     {
00199       Status = RtlCreateUnicodeStringFromAsciiz(&WorkingDirectory,
00200                         (LPSTR)lpWorkingDirectory);
00201       if (!NT_SUCCESS(Status))
00202     {
00203       RtlFreeUnicodeString(&IconLocation);
00204       RtlFreeUnicodeString(&Arguments);
00205       RtlFreeUnicodeString(&ItemName);
00206       SetLastError (RtlNtStatusToDosError (Status));
00207       return FALSE;
00208     }
00209     }
00210 
00211   bResult = AddDesktopItemW(bCommonItem,
00212                 ItemName.Buffer,
00213                 Arguments.Buffer,
00214                 IconLocation.Buffer,
00215                 iIcon,
00216                 (lpWorkingDirectory != NULL) ? WorkingDirectory.Buffer : NULL,
00217                 wHotKey,
00218                 iShowCmd);
00219 
00220   if (lpWorkingDirectory != NULL)
00221     {
00222       RtlFreeUnicodeString(&WorkingDirectory);
00223     }
00224 
00225   RtlFreeUnicodeString(&IconLocation);
00226   RtlFreeUnicodeString(&Arguments);
00227   RtlFreeUnicodeString(&ItemName);
00228 
00229   return bResult;
00230 }
00231 
00232 
00233 BOOL WINAPI
00234 AddDesktopItemW (BOOL bCommonDesktop,
00235          LPCWSTR lpItemName,
00236          LPCWSTR lpArguments,
00237          LPCWSTR lpIconLocation,
00238          INT iIcon,
00239          LPCWSTR lpWorkingDirectory,  /* Optional */
00240          WORD wHotKey,
00241          INT iShowCmd)
00242 {
00243   DYN_FUNCS Ole32;
00244   WCHAR szLinkPath[MAX_PATH];
00245   WCHAR szArguments[MAX_PATH];
00246   WCHAR szCommand[MAX_PATH];
00247   WIN32_FIND_DATAW FindData;
00248   HANDLE hFind;
00249   LPWSTR Ptr;
00250   DWORD dwLength;
00251   IShellLinkW* psl;
00252   IPersistFile* ppf;
00253   HRESULT hr;
00254   BOOL bResult;
00255 
00256   DPRINT ("AddDesktopItemW() called\n");
00257 
00258   bResult = FALSE;
00259 
00260   if (!GetDesktopPath (bCommonDesktop, szLinkPath))
00261     {
00262       DPRINT1 ("GetDesktopPath() failed\n");
00263       return FALSE;
00264     }
00265   DPRINT ("Desktop path: '%S'\n", szLinkPath);
00266 
00267   /* Make sure the path exists */
00268   hFind = FindFirstFileW (szLinkPath,
00269               &FindData);
00270   if (hFind == INVALID_HANDLE_VALUE)
00271     {
00272       DPRINT ("'%S' does not exist\n", szLinkPath);
00273 
00274       /* Create directory path */
00275       if (!CreateDirectoryPath (szLinkPath, NULL))
00276         return FALSE;
00277     }
00278   else
00279     {
00280       DPRINT ("'%S' exists\n", szLinkPath);
00281       FindClose (hFind);
00282     }
00283 
00284   /* Append backslash, item name and ".lnk" extension */
00285   wcscat (szLinkPath, L"\\");
00286   wcscat (szLinkPath, lpItemName);
00287   wcscat (szLinkPath, L".lnk");
00288   DPRINT ("Link path: '%S'\n", szLinkPath);
00289 
00290   /* Split 'lpArguments' string into command and arguments */
00291   Ptr = wcschr (lpArguments, L' ');
00292   DPRINT ("Ptr %p  lpArguments %p\n", Ptr, lpArguments);
00293   if (Ptr != NULL)
00294     {
00295       dwLength = (DWORD)(Ptr - lpArguments);
00296       DPRINT ("dwLength %lu\n", dwLength);
00297       memcpy (szCommand, lpArguments, dwLength * sizeof(WCHAR));
00298       szCommand[dwLength] = 0;
00299       Ptr++;
00300       wcscpy (szArguments, Ptr);
00301     }
00302   else
00303     {
00304       wcscpy (szCommand, lpArguments);
00305       szArguments[0] = 0;
00306     }
00307   DPRINT ("szCommand: '%S'\n", szCommand);
00308   DPRINT ("szArguments: '%S'\n", szArguments);
00309 
00310   /* Dynamically load ole32.dll */
00311   if (!LoadDynamicImports(&DynOle32, &Ole32))
00312     {
00313       DPRINT1("USERENV: Unable to load OLE32.DLL\n");
00314       return FALSE;
00315     }
00316 
00317   Ole32.fn.CoInitialize(NULL);
00318 
00319   hr = Ole32.fn.CoCreateInstance(&CLSID_ShellLink,
00320                                  NULL,
00321                                  CLSCTX_INPROC_SERVER,
00322                                  &IID_IShellLinkW,
00323                                  (LPVOID*)&psl);
00324   if (!SUCCEEDED(hr))
00325     {
00326       Ole32.fn.CoUninitialize();
00327       UnloadDynamicImports(&Ole32);
00328       return FALSE;
00329     }
00330 
00331   hr = psl->lpVtbl->QueryInterface(psl,
00332                                    &IID_IPersistFile,
00333                                    (LPVOID*)&ppf);
00334   if (SUCCEEDED(hr))
00335     {
00336       psl->lpVtbl->SetDescription(psl,
00337                                   lpItemName);
00338 
00339       psl->lpVtbl->SetPath(psl,
00340                            szCommand);
00341 
00342       psl->lpVtbl->SetArguments(psl,
00343                                 szArguments);
00344 
00345       psl->lpVtbl->SetIconLocation(psl,
00346                                    lpIconLocation,
00347                                    iIcon);
00348 
00349       if (lpWorkingDirectory != NULL)
00350         {
00351           psl->lpVtbl->SetWorkingDirectory(psl,
00352                                            lpWorkingDirectory);
00353         }
00354       else
00355         {
00356           psl->lpVtbl->SetWorkingDirectory(psl,
00357                                            L"%HOMEDRIVE%%HOMEPATH%");
00358         }
00359 
00360       psl->lpVtbl->SetHotkey(psl,
00361                              wHotKey);
00362 
00363       psl->lpVtbl->SetShowCmd(psl,
00364                               iShowCmd);
00365 
00366       hr = ppf->lpVtbl->Save(ppf,
00367                              szLinkPath,
00368                              TRUE);
00369       if (SUCCEEDED(hr))
00370         bResult = TRUE;
00371 
00372       ppf->lpVtbl->Release(ppf);
00373     }
00374 
00375   psl->lpVtbl->Release(psl);
00376 
00377   Ole32.fn.CoUninitialize();
00378 
00379   UnloadDynamicImports(&Ole32);
00380 
00381   DPRINT ("AddDesktopItemW() done\n");
00382 
00383   return bResult;
00384 }
00385 
00386 
00387 BOOL WINAPI
00388 DeleteDesktopItemA (BOOL bCommonItem,
00389             LPCSTR lpItemName)
00390 {
00391   UNICODE_STRING ItemName;
00392   BOOL bResult;
00393   NTSTATUS Status;
00394 
00395   Status = RtlCreateUnicodeStringFromAsciiz(&ItemName,
00396                         (LPSTR)lpItemName);
00397   if (!NT_SUCCESS(Status))
00398     {
00399       SetLastError (RtlNtStatusToDosError (Status));
00400       return FALSE;
00401     }
00402 
00403   bResult = DeleteDesktopItemW(bCommonItem,
00404                    ItemName.Buffer);
00405 
00406   RtlFreeUnicodeString(&ItemName);
00407 
00408   return bResult;
00409 }
00410 
00411 
00412 BOOL WINAPI
00413 DeleteDesktopItemW (BOOL bCommonItem,
00414             LPCWSTR lpItemName)
00415 {
00416   WCHAR szLinkPath[MAX_PATH];
00417 
00418   DPRINT ("DeleteDesktopItemW() called\n");
00419 
00420   if (!GetDesktopPath (bCommonItem, szLinkPath))
00421     {
00422       DPRINT1 ("GetDesktopPath() failed\n");
00423       return FALSE;
00424     }
00425 
00426   wcscat (szLinkPath, L"\\");
00427   wcscat (szLinkPath, lpItemName);
00428   wcscat (szLinkPath, L".lnk");
00429   DPRINT ("Link path: '%S'\n", szLinkPath);
00430 
00431   return DeleteFileW (szLinkPath);
00432 }
00433 
00434 
00435 BOOL WINAPI
00436 CreateGroupA (LPCSTR lpGroupName,
00437           BOOL bCommonGroup)
00438 {
00439   UNICODE_STRING GroupName;
00440   BOOL bResult;
00441   NTSTATUS Status;
00442 
00443   Status = RtlCreateUnicodeStringFromAsciiz(&GroupName,
00444                         (LPSTR)lpGroupName);
00445   if (!NT_SUCCESS(Status))
00446     {
00447       SetLastError (RtlNtStatusToDosError (Status));
00448       return FALSE;
00449     }
00450 
00451   bResult = CreateGroupW(GroupName.Buffer, bCommonGroup);
00452 
00453   RtlFreeUnicodeString(&GroupName);
00454 
00455   return bResult;
00456 }
00457 
00458 
00459 BOOL WINAPI
00460 CreateGroupW (LPCWSTR lpGroupName,
00461           BOOL bCommonGroup)
00462 {
00463   WCHAR szGroupPath[MAX_PATH];
00464 
00465   DPRINT1 ("CreateGroupW() called\n");
00466 
00467   if (lpGroupName == NULL || *lpGroupName == 0)
00468     return TRUE;
00469 
00470   if (!GetProgramsPath (bCommonGroup, szGroupPath))
00471     {
00472       DPRINT1 ("GetProgramsPath() failed\n");
00473       return FALSE;
00474     }
00475   DPRINT1 ("Programs path: '%S'\n", szGroupPath);
00476 
00477   wcscat (szGroupPath, L"\\");
00478   wcscat (szGroupPath, lpGroupName);
00479   DPRINT1 ("Group path: '%S'\n", szGroupPath);
00480 
00481   /* Create directory path */
00482   if (!CreateDirectoryPath (szGroupPath, NULL))
00483     return FALSE;
00484 
00485   /* FIXME: Notify the shell */
00486 
00487   DPRINT1 ("CreateGroupW() done\n");
00488 
00489   return TRUE;
00490 }
00491 
00492 
00493 BOOL WINAPI
00494 DeleteGroupA (LPCSTR lpGroupName,
00495           BOOL bCommonGroup)
00496 {
00497   UNICODE_STRING GroupName;
00498   BOOL bResult;
00499   NTSTATUS Status;
00500 
00501   Status = RtlCreateUnicodeStringFromAsciiz(&GroupName,
00502                         (LPSTR)lpGroupName);
00503   if (!NT_SUCCESS(Status))
00504     {
00505       SetLastError (RtlNtStatusToDosError (Status));
00506       return FALSE;
00507     }
00508 
00509   bResult = DeleteGroupW(GroupName.Buffer, bCommonGroup);
00510 
00511   RtlFreeUnicodeString(&GroupName);
00512 
00513   return bResult;
00514 }
00515 
00516 
00517 BOOL WINAPI
00518 DeleteGroupW (LPCWSTR lpGroupName,
00519           BOOL bCommonGroup)
00520 {
00521   WCHAR szGroupPath[MAX_PATH];
00522 
00523   DPRINT ("DeleteGroupW() called\n");
00524 
00525   if (lpGroupName == NULL || *lpGroupName == 0)
00526     return TRUE;
00527 
00528   if (!GetProgramsPath (bCommonGroup, szGroupPath))
00529     {
00530       DPRINT1 ("GetProgramsPath() failed\n");
00531       return FALSE;
00532     }
00533   DPRINT ("Programs path: '%S'\n", szGroupPath);
00534 
00535   wcscat (szGroupPath, L"\\");
00536   wcscat (szGroupPath, lpGroupName);
00537   DPRINT ("Group path: '%S'\n", szGroupPath);
00538 
00539   /* Remove directory path */
00540   if (!RemoveDirectoryPath (szGroupPath))
00541     return FALSE;
00542 
00543   /* FIXME: Notify the shell */
00544 
00545   DPRINT ("DeleteGroupW() done\n");
00546 
00547   return TRUE;
00548 }
00549 
00550 
00551 BOOL WINAPI
00552 AddItemA (LPCSTR lpGroupName,  /* Optional */
00553       BOOL bCommonGroup,
00554       LPCSTR lpItemName,
00555       LPCSTR lpArguments,
00556       LPCSTR lpIconLocation,
00557       INT iIcon,
00558       LPCSTR lpWorkingDirectory,  /* Optional */
00559       WORD wHotKey,
00560       INT iShowCmd)
00561 {
00562   UNICODE_STRING GroupName;
00563   UNICODE_STRING ItemName;
00564   UNICODE_STRING Arguments;
00565   UNICODE_STRING IconLocation;
00566   UNICODE_STRING WorkingDirectory;
00567   BOOL bResult;
00568   NTSTATUS Status;
00569 
00570   Status = RtlCreateUnicodeStringFromAsciiz(&ItemName,
00571                         (LPSTR)lpItemName);
00572   if (!NT_SUCCESS(Status))
00573     {
00574       SetLastError (RtlNtStatusToDosError (Status));
00575       return FALSE;
00576     }
00577 
00578   Status = RtlCreateUnicodeStringFromAsciiz(&Arguments,
00579                         (LPSTR)lpArguments);
00580   if (!NT_SUCCESS(Status))
00581     {
00582       RtlFreeUnicodeString(&ItemName);
00583       SetLastError (RtlNtStatusToDosError (Status));
00584       return FALSE;
00585     }
00586 
00587   Status = RtlCreateUnicodeStringFromAsciiz(&IconLocation,
00588                         (LPSTR)lpIconLocation);
00589   if (!NT_SUCCESS(Status))
00590     {
00591       RtlFreeUnicodeString(&Arguments);
00592       RtlFreeUnicodeString(&ItemName);
00593       SetLastError (RtlNtStatusToDosError (Status));
00594       return FALSE;
00595     }
00596 
00597   if (lpGroupName != NULL)
00598     {
00599       Status = RtlCreateUnicodeStringFromAsciiz(&GroupName,
00600                         (LPSTR)lpGroupName);
00601       if (!NT_SUCCESS(Status))
00602     {
00603       RtlFreeUnicodeString(&IconLocation);
00604       RtlFreeUnicodeString(&Arguments);
00605       RtlFreeUnicodeString(&ItemName);
00606       SetLastError (RtlNtStatusToDosError (Status));
00607       return FALSE;
00608     }
00609     }
00610 
00611   if (lpWorkingDirectory != NULL)
00612     {
00613       Status = RtlCreateUnicodeStringFromAsciiz(&WorkingDirectory,
00614                         (LPSTR)lpWorkingDirectory);
00615       if (!NT_SUCCESS(Status))
00616     {
00617       if (lpGroupName != NULL)
00618         {
00619           RtlFreeUnicodeString(&GroupName);
00620         }
00621       RtlFreeUnicodeString(&IconLocation);
00622       RtlFreeUnicodeString(&Arguments);
00623       RtlFreeUnicodeString(&ItemName);
00624       SetLastError (RtlNtStatusToDosError (Status));
00625       return FALSE;
00626     }
00627     }
00628 
00629   bResult = AddItemW((lpGroupName != NULL) ? GroupName.Buffer : NULL,
00630              bCommonGroup,
00631              ItemName.Buffer,
00632              Arguments.Buffer,
00633              IconLocation.Buffer,
00634              iIcon,
00635              (lpWorkingDirectory != NULL) ? WorkingDirectory.Buffer : NULL,
00636              wHotKey,
00637              iShowCmd);
00638 
00639   if (lpGroupName != NULL)
00640     {
00641       RtlFreeUnicodeString(&GroupName);
00642     }
00643 
00644   if (lpWorkingDirectory != NULL)
00645     {
00646       RtlFreeUnicodeString(&WorkingDirectory);
00647     }
00648 
00649   RtlFreeUnicodeString(&IconLocation);
00650   RtlFreeUnicodeString(&Arguments);
00651   RtlFreeUnicodeString(&ItemName);
00652 
00653   return bResult;
00654 }
00655 
00656 
00657 BOOL WINAPI
00658 AddItemW (LPCWSTR lpGroupName,  /* Optional */
00659       BOOL bCommonGroup,
00660       LPCWSTR lpItemName,
00661       LPCWSTR lpArguments,
00662       LPCWSTR lpIconLocation,
00663       INT iIcon,
00664       LPCWSTR lpWorkingDirectory,  /* Optional */
00665       WORD wHotKey,
00666       INT iShowCmd)
00667 {
00668   DYN_FUNCS Ole32;
00669   WCHAR szLinkPath[MAX_PATH];
00670   WCHAR szArguments[MAX_PATH];
00671   WCHAR szCommand[MAX_PATH];
00672   WIN32_FIND_DATAW FindData;
00673   HANDLE hFind;
00674   LPWSTR Ptr;
00675   DWORD dwLength;
00676   IShellLinkW* psl;
00677   IPersistFile* ppf;
00678   HRESULT hr;
00679   BOOL bResult;
00680 
00681   DPRINT ("AddItemW() called\n");
00682 
00683   bResult = FALSE;
00684 
00685   if (!GetProgramsPath (bCommonGroup, szLinkPath))
00686     {
00687       DPRINT1 ("GetProgramsPath() failed\n");
00688       return FALSE;
00689     }
00690 
00691   DPRINT ("Programs path: '%S'\n", szLinkPath);
00692 
00693   if (lpGroupName != NULL && *lpGroupName != 0)
00694     {
00695       wcscat (szLinkPath, L"\\");
00696       wcscat (szLinkPath, lpGroupName);
00697 
00698       /* Make sure the path exists */
00699       hFind = FindFirstFileW (szLinkPath,
00700                   &FindData);
00701       if (hFind == INVALID_HANDLE_VALUE)
00702     {
00703       DPRINT ("'%S' does not exist\n", szLinkPath);
00704       if (!CreateGroupW (lpGroupName,
00705                  bCommonGroup))
00706         return FALSE;
00707     }
00708       else
00709     {
00710       DPRINT ("'%S' exists\n", szLinkPath);
00711       FindClose (hFind);
00712     }
00713     }
00714 
00715   wcscat (szLinkPath, L"\\");
00716   wcscat (szLinkPath, lpItemName);
00717   wcscat (szLinkPath, L".lnk");
00718   DPRINT ("Link path: '%S'\n", szLinkPath);
00719 
00720   /* Split 'lpArguments' string into command and arguments */
00721   Ptr = wcschr (lpArguments, L' ');
00722   DPRINT ("Ptr %p  lpArguments %p\n", Ptr, lpArguments);
00723   if (Ptr != NULL)
00724     {
00725       dwLength = (DWORD)(Ptr - lpArguments);
00726       DPRINT ("dwLength %lu\n", dwLength);
00727       memcpy (szCommand, lpArguments, dwLength * sizeof(WCHAR));
00728       szCommand[dwLength] = 0;
00729       Ptr++;
00730       wcscpy (szArguments, Ptr);
00731     }
00732   else
00733     {
00734       wcscpy (szCommand, lpArguments);
00735       szArguments[0] = 0;
00736     }
00737   DPRINT ("szCommand: '%S'\n", szCommand);
00738   DPRINT ("szArguments: '%S'\n", szArguments);
00739 
00740   /* Dynamically load ole32.dll */
00741   if (!LoadDynamicImports(&DynOle32, &Ole32))
00742     {
00743       DPRINT1("USERENV: Unable to load OLE32.DLL\n");
00744       return FALSE;
00745     }
00746 
00747   Ole32.fn.CoInitialize(NULL);
00748 
00749   hr = Ole32.fn.CoCreateInstance(&CLSID_ShellLink,
00750                                  NULL,
00751                                  CLSCTX_INPROC_SERVER,
00752                                  &IID_IShellLinkW,
00753                                  (LPVOID*)&psl);
00754   if (!SUCCEEDED(hr))
00755     {
00756       Ole32.fn.CoUninitialize();
00757       UnloadDynamicImports(&Ole32);
00758       return FALSE;
00759     }
00760 
00761   hr = psl->lpVtbl->QueryInterface(psl,
00762                                    &IID_IPersistFile,
00763                                    (LPVOID*)&ppf);
00764   if (SUCCEEDED(hr))
00765     {
00766       psl->lpVtbl->SetDescription(psl,
00767                                   lpItemName);
00768 
00769       psl->lpVtbl->SetPath(psl,
00770                            szCommand);
00771 
00772       psl->lpVtbl->SetArguments(psl,
00773                                 szArguments);
00774 
00775       psl->lpVtbl->SetIconLocation(psl,
00776                                    lpIconLocation,
00777                                    iIcon);
00778 
00779       if (lpWorkingDirectory != NULL)
00780         {
00781           psl->lpVtbl->SetWorkingDirectory(psl,
00782                                            lpWorkingDirectory);
00783         }
00784       else
00785         {
00786           psl->lpVtbl->SetWorkingDirectory(psl,
00787                                            L"%HOMEDRIVE%%HOMEPATH%");
00788         }
00789 
00790       psl->lpVtbl->SetHotkey(psl,
00791                              wHotKey);
00792 
00793       psl->lpVtbl->SetShowCmd(psl,
00794                               iShowCmd);
00795 
00796       hr = ppf->lpVtbl->Save(ppf,
00797                              szLinkPath,
00798                              TRUE);
00799       if (SUCCEEDED(hr))
00800         bResult = TRUE;
00801 
00802       ppf->lpVtbl->Release(ppf);
00803     }
00804 
00805   psl->lpVtbl->Release(psl);
00806 
00807   Ole32.fn.CoUninitialize();
00808   UnloadDynamicImports(&Ole32);
00809 
00810   DPRINT ("AddItemW() done\n");
00811 
00812   return bResult;
00813 }
00814 
00815 
00816 BOOL WINAPI
00817 DeleteItemA (LPCSTR lpGroupName, /* Optional */
00818          BOOL bCommonGroup,
00819          LPCSTR lpItemName,
00820          BOOL bDeleteGroup)
00821 {
00822   UNICODE_STRING GroupName;
00823   UNICODE_STRING ItemName;
00824   BOOL bResult;
00825   NTSTATUS Status;
00826 
00827   if (lpGroupName != NULL)
00828     {
00829       Status = RtlCreateUnicodeStringFromAsciiz(&GroupName,
00830                         (LPSTR)lpGroupName);
00831       if (!NT_SUCCESS(Status))
00832     {
00833       SetLastError (RtlNtStatusToDosError (Status));
00834       return FALSE;
00835     }
00836     }
00837 
00838   Status = RtlCreateUnicodeStringFromAsciiz(&ItemName,
00839                         (LPSTR)lpItemName);
00840   if (!NT_SUCCESS(Status))
00841     {
00842       if (lpGroupName != NULL)
00843     {
00844       RtlFreeUnicodeString(&GroupName);
00845     }
00846 
00847       SetLastError (RtlNtStatusToDosError (Status));
00848       return FALSE;
00849     }
00850 
00851   bResult = DeleteItemW((lpGroupName != NULL) ? GroupName.Buffer : NULL,
00852             bCommonGroup,
00853             ItemName.Buffer,
00854             bDeleteGroup);
00855 
00856   RtlFreeUnicodeString(&ItemName);
00857   if (lpGroupName != NULL)
00858     {
00859       RtlFreeUnicodeString(&GroupName);
00860     }
00861 
00862   return bResult;
00863 }
00864 
00865 
00866 BOOL WINAPI
00867 DeleteItemW (LPCWSTR lpGroupName, /* Optional */
00868          BOOL bCommonGroup,
00869          LPCWSTR lpItemName,
00870          BOOL bDeleteGroup)
00871 {
00872   WCHAR szItemPath[MAX_PATH];
00873   LPWSTR Ptr;
00874 
00875   DPRINT ("DeleteItemW() called\n");
00876 
00877   if (!GetProgramsPath (bCommonGroup, szItemPath))
00878     {
00879       DPRINT1 ("GetProgramsPath() failed\n");
00880       return FALSE;
00881     }
00882   DPRINT ("Programs path: '%S'\n", szItemPath);
00883 
00884   if (lpGroupName != NULL && *lpGroupName != 0)
00885     {
00886       wcscat (szItemPath, L"\\");
00887       wcscat (szItemPath, lpGroupName);
00888     }
00889 
00890   wcscat (szItemPath, L"\\");
00891   wcscat (szItemPath, lpItemName);
00892   wcscat (szItemPath, L".lnk");
00893   DPRINT ("Item path: '%S'\n", szItemPath);
00894 
00895   if (!DeleteFileW (szItemPath))
00896     return FALSE;
00897 
00898   /* FIXME: Notify the shell */
00899 
00900   if (bDeleteGroup)
00901     {
00902       Ptr = wcsrchr (szItemPath, L'\\');
00903       if (Ptr == NULL)
00904     return TRUE;
00905 
00906       *Ptr = 0;
00907       DPRINT ("Item path: '%S'\n", szItemPath);
00908       if (RemoveDirectoryW (szItemPath))
00909     {
00910       /* FIXME: Notify the shell */
00911     }
00912     }
00913 
00914   DPRINT ("DeleteItemW() done\n");
00915 
00916   return TRUE;
00917 }
00918 
00919 /* EOF */

Generated on Sun May 27 2012 04:18:25 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.