move the apps into the same position they are found in windows.
[reactos.git] / reactos / lib / syssetup / install.c
index 62241b2..38d29c8 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: install.c,v 1.18 2004/11/09 15:02:35 ion Exp $
+/* $Id$
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS system libraries
 
 /* INCLUDES *****************************************************************/
 
-#include <ntos.h>
 #include <windows.h>
+#define NTOS_MODE_USER
+#include <ndk/ntndk.h>
+
 #include <commctrl.h>
 #include <stdio.h>
 #include <tchar.h>
 #include <stdlib.h>
 
-#include <samlib.h>
-#include <syssetup.h>
+#include <samlib/samlib.h>
+#include <syssetup/syssetup.h>
 #include <userenv.h>
 #include <setupapi.h>
 
+#include <shlobj.h>
+#include <objidl.h>
+#include <shlwapi.h>
+
 #include "globals.h"
 #include "resource.h"
 
 #define VMWINST
 
-VOID WINAPI CreateCmdLink(VOID);
-
 
 /* GLOBALS ******************************************************************/
 
@@ -80,12 +84,13 @@ RunVMWInstall(VOID)
 {
   PROCESS_INFORMATION ProcInfo;
   STARTUPINFO si;
-  
+  WCHAR InstallName[] = L"vmwinst.exe";
+
   ZeroMemory(&si, sizeof(STARTUPINFO));
   si.cb = sizeof(STARTUPINFO);
-  
-  if(CreateProcessA(NULL, "vmwinst.exe", NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, 
-                    NULL, NULL, &si, &ProcInfo))
+
+  if(CreateProcess(NULL, InstallName, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
+                   NULL, NULL, &si, &ProcInfo))
   {
     WaitForSingleObject(ProcInfo.hProcess, INFINITE);
     CloseHandle(ProcInfo.hThread);
@@ -97,6 +102,107 @@ RunVMWInstall(VOID)
 #endif
 
 
+HRESULT CreateShellLink(LPCTSTR linkPath, LPCTSTR cmd, LPCTSTR arg, LPCTSTR dir, LPCTSTR iconPath, int icon_nr, LPCTSTR comment)
+{
+  IShellLink* psl;
+  IPersistFile* ppf;
+#ifndef _UNICODE
+  WCHAR buffer[MAX_PATH];
+#endif /* _UNICODE */
+
+  HRESULT hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (LPVOID*)&psl);
+
+  if (SUCCEEDED(hr))
+    {
+      hr = psl->lpVtbl->SetPath(psl, cmd);
+
+      if (arg)
+        {
+          hr = psl->lpVtbl->SetArguments(psl, arg);
+        }
+
+      if (dir)
+        {
+          hr = psl->lpVtbl->SetWorkingDirectory(psl, dir);
+        }
+
+      if (iconPath)
+        {
+          hr = psl->lpVtbl->SetIconLocation(psl, iconPath, icon_nr);
+        }
+
+      if (comment)
+        {
+          hr = psl->lpVtbl->SetDescription(psl, comment);
+        }
+
+      hr = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
+
+      if (SUCCEEDED(hr))
+        {
+#ifdef _UNICODE
+          hr = ppf->lpVtbl->Save(ppf, linkPath, TRUE);
+#else /* _UNICODE */
+          MultiByteToWideChar(CP_ACP, 0, linkPath, -1, buffer, MAX_PATH);
+
+          hr = ppf->lpVtbl->Save(ppf, buffer, TRUE);
+#endif /* _UNICODE */
+
+          ppf->lpVtbl->Release(ppf);
+        }
+
+      psl->lpVtbl->Release(psl);
+    }
+
+  return hr;
+}
+
+
+static BOOL
+CreateShortcut(int csidl, LPCTSTR folder, LPCTSTR linkName, LPCTSTR command, UINT nIdTitle)
+{
+  TCHAR path[MAX_PATH];
+  TCHAR title[256];
+  LPTSTR p = path;
+
+  if (!SHGetSpecialFolderPath(0, path, csidl, TRUE))
+    return FALSE;
+
+  if (folder)
+    {
+      p = PathAddBackslash(p);
+      _tcscpy(p, folder);
+    }
+
+  p = PathAddBackslash(p);
+  _tcscpy(p, linkName);
+
+  if (!LoadString(hDllInstance, nIdTitle, title, 256))
+    return FALSE;
+
+  return SUCCEEDED(CreateShellLink(path, command, _T(""), NULL, NULL, 0, title));
+}
+
+
+static BOOL
+CreateShortcutFolder(int csidl, UINT nID, LPTSTR name, int nameLen)
+{
+  TCHAR path[MAX_PATH];
+  LPTSTR p;
+
+  if (!SHGetSpecialFolderPath(0, path, csidl, TRUE))
+    return FALSE;
+
+  if (!LoadString(hDllInstance, nID, name, nameLen))
+    return FALSE;
+
+  p = PathAddBackslash(path);
+  _tcscpy(p, name);
+
+  return CreateDirectory(path, NULL) || GetLastError()==ERROR_ALREADY_EXISTS;
+}
+
+
 static VOID
 CreateRandomSid (PSID *Sid)
 {
@@ -161,8 +267,8 @@ RestartDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       case WM_INITDIALOG:
          SendDlgItemMessage(hWnd, IDC_RESTART_PROGRESS, PBM_SETRANGE, 0,
-            MAKELPARAM(0, 300)); 
-         SetTimer(hWnd, 0, 50, NULL);
+            MAKELPARAM(0, 300));
+         SetTimer(hWnd, 1, 50, NULL);
          return TRUE;
 
       case WM_TIMER:
@@ -196,57 +302,57 @@ RestartDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 static VOID
 CreateTempDir(LPCWSTR VarName)
 {
-  WCHAR szTempDir[MAX_PATH];
-  WCHAR szBuffer[MAX_PATH];
+  TCHAR szTempDir[MAX_PATH];
+  TCHAR szBuffer[MAX_PATH];
   DWORD dwLength;
   HKEY hKey;
 
-  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                    L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",
-                    0,
-                    KEY_ALL_ACCESS,
-                    &hKey))
+  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                  _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"),
+                  0,
+                  KEY_ALL_ACCESS,
+                  &hKey))
     {
       DebugPrint("Error: %lu\n", GetLastError());
       return;
     }
 
   /* Get temp dir */
-  dwLength = MAX_PATH * sizeof(WCHAR);
-  if (RegQueryValueEx(hKey,
-                       VarName,
-                       NULL,
-                       NULL,
-                       (LPBYTE)szBuffer,
-                       &dwLength))
+  dwLength = MAX_PATH * sizeof(TCHAR);
+  if (RegQueryValueEx(hKey,
+                     VarName,
+                     NULL,
+                     NULL,
+                     (LPBYTE)szBuffer,
+                     &dwLength))
     {
       DebugPrint("Error: %lu\n", GetLastError());
-      RegCloseKey (hKey);
+      RegCloseKey(hKey);
       return;
     }
 
   /* Expand it */
-  if (!ExpandEnvironmentStrings(szBuffer,
-                                 szTempDir,
-                                 MAX_PATH))
+  if (!ExpandEnvironmentStrings(szBuffer,
+                               szTempDir,
+                               MAX_PATH))
     {
       DebugPrint("Error: %lu\n", GetLastError());
-      RegCloseKey (hKey);
+      RegCloseKey(hKey);
       return;
     }
 
   /* Create profiles directory */
-  if (!CreateDirectory(szTempDir, NULL))
+  if (!CreateDirectory(szTempDir, NULL))
     {
-      if (GetLastError () != ERROR_ALREADY_EXISTS)
+      if (GetLastError() != ERROR_ALREADY_EXISTS)
        {
          DebugPrint("Error: %lu\n", GetLastError());
-         RegCloseKey (hKey);
+         RegCloseKey(hKey);
          return;
        }
     }
 
-  RegCloseKey (hKey);
+  RegCloseKey(hKey);
 }
 
 
@@ -290,6 +396,8 @@ ProcessSysSetupInf(VOID)
 DWORD STDCALL
 InstallReactOS (HINSTANCE hInstance)
 {
+  TCHAR sAccessories[256];
+
 # if 0
   OutputDebugStringA ("InstallReactOS() called\n");
 
@@ -320,6 +428,25 @@ InstallReactOS (HINSTANCE hInstance)
       return 0;
     }
 
+  CoInitialize(NULL);
+
+  /* create desktop shortcuts */
+  CreateShortcut(CSIDL_DESKTOP, NULL, _T("Command Prompt.lnk"), _T("cmd.exe"), IDS_CMT_CMD);
+
+  /* create program startmenu shortcuts */  
+  CreateShortcut(CSIDL_PROGRAMS, NULL, _T("winefile.lnk"), _T("winefile.exe"), IDS_CMT_WINEFILE);
+
+  /* create and fill Accessories subfolder */
+  if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_ACCESSORIES, sAccessories, 256)) {
+       //CreateShortcut(CSIDL_PROGRAMS, sAccessories, _T("Calculator.lnk"), _T("calc.exe"), IDS_CMT_CALC);
+       CreateShortcut(CSIDL_PROGRAMS, sAccessories, _T("Command Prompt.lnk"), _T("cmd.exe"), IDS_CMT_CMD);
+    CreateShortcut(CSIDL_PROGRAMS, sAccessories, _T("notepad.lnk"), _T("notepad.exe"), IDS_CMT_NOTEPAD);
+    CreateShortcut(CSIDL_PROGRAMS, sAccessories, _T("explorer.lnk"), _T("explorer.exe"), IDS_CMT_EXPLORER);
+    CreateShortcut(CSIDL_PROGRAMS, sAccessories, _T("regedit.lnk"), _T("regedit.exe"), IDS_CMT_REGEDIT);
+  }
+
+  CoUninitialize();
+
   /* Create the semi-random Domain-SID */
   CreateRandomSid (&DomainSid);
   if (DomainSid == NULL)
@@ -368,7 +495,8 @@ InstallReactOS (HINSTANCE hInstance)
      * and not completing it, let it restart instead
      */
     LastError = GetLastError();
-    if (LastError != ERROR_USER_EXISTS) {
+    if (LastError != ERROR_USER_EXISTS)
+    {
       DebugPrint("SamCreateUser() failed!\n");
       RtlFreeSid(AdminSid);
       RtlFreeSid(DomainSid);