make more robust by calling GetSystemDirectory
[reactos.git] / reactos / lib / syssetup / install.c
index 547ff87..e3a8199 100644 (file)
 
 /* INCLUDES *****************************************************************/
 
-#include <ntos.h>
+#define WIN32_NO_STATUS
 #include <windows.h>
+#define NTOS_MODE_USER
+#include <ndk/ntndk.h>
+
 #include <commctrl.h>
 #include <stdio.h>
+#include <io.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>
 
@@ -82,11 +86,12 @@ RunVMWInstall(VOID)
 {
   PROCESS_INFORMATION ProcInfo;
   STARTUPINFO si;
-  
+  WCHAR InstallName[] = L"vmwinst.exe";
+
   ZeroMemory(&si, sizeof(STARTUPINFO));
   si.cb = sizeof(STARTUPINFO);
-  
-  if(CreateProcess(NULL, _T("vmwinst.exe"), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, 
+
+  if(CreateProcess(NULL, InstallName, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
                    NULL, NULL, &si, &ProcInfo))
   {
     WaitForSingleObject(ProcInfo.hProcess, INFINITE);
@@ -99,11 +104,13 @@ RunVMWInstall(VOID)
 #endif
 
 
-HRESULT CreateShellLink(LPCSTR linkPath, LPCSTR cmd, LPCSTR arg, LPCSTR dir, LPCSTR iconPath, int icon_nr, LPCSTR comment)
+HRESULT CreateShellLink(LPCTSTR linkPath, LPCTSTR cmd, LPCTSTR arg, LPCTSTR dir, LPCTSTR iconPath, int icon_nr, LPCTSTR comment)
 {
-  IShellLinkA* psl;
+  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);
 
@@ -135,9 +142,13 @@ HRESULT CreateShellLink(LPCSTR linkPath, LPCSTR cmd, LPCSTR arg, LPCSTR dir, LPC
 
       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);
         }
@@ -149,21 +160,48 @@ HRESULT CreateShellLink(LPCSTR linkPath, LPCSTR cmd, LPCSTR arg, LPCSTR dir, LPC
 }
 
 
-static VOID
-CreateCmdLink(VOID)
+static BOOL
+CreateShortcut(int csidl, LPCTSTR folder, LPCTSTR linkName, LPCTSTR command, UINT nIdTitle)
 {
-  char path[MAX_PATH];
-  LPSTR p;
+  TCHAR path[MAX_PATH];
+  TCHAR title[256];
+  LPTSTR p = path;
 
-  CoInitialize(NULL);
+  if (!SHGetSpecialFolderPath(0, path, csidl, TRUE))
+    return FALSE;
+
+  if (folder)
+    {
+      p = PathAddBackslash(p);
+      _tcscpy(p, folder);
+    }
 
-  SHGetSpecialFolderPathA(0, path, CSIDL_DESKTOP, TRUE);
-  p = PathAddBackslashA(path);
+  p = PathAddBackslash(p);
+  _tcscpy(p, linkName);
 
-  strcpy(p, "Command Prompt.lnk");
-  CreateShellLink(path, "cmd.exe", "", NULL, NULL, 0, "Open command prompt");
+  if (!LoadString(hDllInstance, nIdTitle, title, 256))
+    return FALSE;
 
-  CoUninitialize();
+  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;
 }
 
 
@@ -231,8 +269,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:
@@ -360,6 +398,11 @@ ProcessSysSetupInf(VOID)
 DWORD STDCALL
 InstallReactOS (HINSTANCE hInstance)
 {
+  TCHAR sAccessories[256];
+  TCHAR sGames[256];
+  TCHAR Sys[_MAX_PATH];
+    
+
 # if 0
   OutputDebugStringA ("InstallReactOS() called\n");
 
@@ -390,7 +433,36 @@ InstallReactOS (HINSTANCE hInstance)
       return 0;
     }
 
-  CreateCmdLink();
+  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("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);
+  }
+
+  if(!GetSystemDirectory(Sys, _MAX_PATH))
+    Sys[0] = L'\0';
+
+  /* create Games subfolder and fill if the exe is available */
+  if (CreateShortcutFolder(CSIDL_PROGRAMS, IDS_GAMES, sGames, 256)) {
+       if (Sys[0] != L'\0') {
+         if((_taccess(_tcscat(Sys, _T("\\sol.exe")), 0 )) != -1)
+        CreateShortcut(CSIDL_PROGRAMS, sGames, _T("Solitaire.lnk"), _T("sol.exe"), IDS_CMT_SOLITAIRE);
+         
+      /* winemine etc .... */
+       }
+  }
+
+  CoUninitialize();
 
   /* Create the semi-random Domain-SID */
   CreateRandomSid (&DomainSid);