[SETUP][SYSSETUP]: Export a 'InstallWindowsNt' function from syssetup.dll (with Windo...
[reactos.git] / reactos / base / setup / setup / setup.c
index 4c003fe..59e468d 100644 (file)
@@ -1,21 +1,3 @@
-/*
- *  ReactOS kernel
- *  Copyright (C) 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS GUI/console setup
 #include <stdarg.h>
 #include <windef.h>
 #include <winbase.h>
-#include <tchar.h>
 
 #define NDEBUG
 #include <debug.h>
 
-typedef DWORD (WINAPI *PINSTALL_REACTOS)(HINSTANCE hInstance);
+typedef INT (WINAPI *PINSTALL_REACTOS)(INT argc, WCHAR** argv);
 
 /* FUNCTIONS ****************************************************************/
 
-LPTSTR
-lstrchr(
-    LPCTSTR s,
-    TCHAR c)
-{
-    while (*s)
-    {
-        if (*s == c)
-            return (LPTSTR)s;
-        s++;
-    }
-
-    if (c == (TCHAR)0)
-        return (LPTSTR)s;
-
-    return (LPTSTR)NULL;
-}
-
-
 static
-VOID
-RunNewSetup(
-    HINSTANCE hInstance)
+INT
+RunInstallReactOS(INT argc, WCHAR* argv[])
 {
+    INT RetVal;
     HMODULE hDll;
     PINSTALL_REACTOS InstallReactOS;
 
-    hDll = LoadLibrary(TEXT("syssetup"));
+    hDll = LoadLibraryW(L"syssetup.dll");
     if (hDll == NULL)
     {
-        DPRINT("Failed to load 'syssetup'!\n");
-        return;
+        DPRINT("Failed to load 'syssetup.dll'!\n");
+        return GetLastError();
     }
+    DPRINT("Loaded 'syssetup.dll'!\n");
 
-    DPRINT("Loaded 'syssetup'!\n");
-    InstallReactOS = (PINSTALL_REACTOS)GetProcAddress(hDll, "InstallReactOS");
+    /* Call the standard Windows-compatible export */
+    InstallReactOS = (PINSTALL_REACTOS)GetProcAddress(hDll, "InstallWindowsNt");
     if (InstallReactOS == NULL)
     {
-        DPRINT("Failed to get address for 'InstallReactOS()'!\n");
-        FreeLibrary(hDll);
-        return;
-    }
-
-    InstallReactOS(hInstance);
-
-    FreeLibrary(hDll);
-}
-
-
-static
-VOID
-RunLiveCD(
-    HINSTANCE hInstance)
-{
-    HMODULE hDll;
-    PINSTALL_REACTOS InstallLiveCD;
-
-    hDll = LoadLibrary(TEXT("syssetup"));
-    if (hDll == NULL)
-    {
-        DPRINT("Failed to load 'syssetup'!\n");
-        return;
+        RetVal = GetLastError();
+        DPRINT("Failed to get address for 'InstallWindowsNt()'!\n");
     }
-
-    DPRINT("Loaded 'syssetup'!\n");
-    InstallLiveCD = (PINSTALL_REACTOS)GetProcAddress(hDll, "InstallLiveCD");
-    if (InstallLiveCD == NULL)
+    else
     {
-        DPRINT("Failed to get address for 'InstallReactOS()'!\n");
-        FreeLibrary(hDll);
-        return;
+        RetVal = InstallReactOS(argc, argv);
     }
 
-    InstallLiveCD(hInstance);
-
     FreeLibrary(hDll);
+    return RetVal;
 }
 
 
-int
-WINAPI
-_tWinMain(
-    HINSTANCE hInstance,
-    HINSTANCE hPrevInstance,
-    LPTSTR lpCmdLine,
-    int nShowCmd)
+/* Called from wmainCRTStartup */
+INT wmain(INT argc, WCHAR* argv[])
 {
-    LPTSTR CmdLine;
-    LPTSTR p;
+    LPWSTR CmdLine, p;
 
-    CmdLine = GetCommandLine();
+    // NOTE: Temporary, until we correctly use argc/argv.
+    CmdLine = GetCommandLineW();
+    DPRINT("CmdLine: <%S>\n", CmdLine);
 
-    DPRINT("CmdLine: <%s>\n",CmdLine);
-
-    p = lstrchr(CmdLine, TEXT('-'));
+    p = wcschr(CmdLine, L'-');
     if (p == NULL)
-        return 0;
+        return ERROR_INVALID_PARAMETER;
+    p++;
 
-    if (!lstrcmpi(p, TEXT("-newsetup")))
-    {
-        RunNewSetup(hInstance);
-    }
-    else if (!lstrcmpi(p, TEXT("-mini")))
+    // NOTE: On Windows, "mini" means "minimal UI", and can be used
+    // in addition to "newsetup"; these options are not exclusive.
+    if (_wcsicmp(p, L"newsetup") == 0 || _wcsicmp(p, L"mini") == 0)
     {
-        RunLiveCD(hInstance);
+        RunInstallReactOS(argc, argv);
     }
 
 #if 0
-  /* Add new setup types here */
+    /* Add new setup types here */
     else if (...)
     {