[USETUP]
[reactos.git] / reactos / base / setup / usetup / settings.c
index ce9ede1..90fd263 100644 (file)
@@ -12,9 +12,9 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  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 text-mode setup
@@ -241,7 +241,7 @@ GetDisplayIdentifier(PWSTR Identifier,
                                NULL);
 
     Status = NtOpenKey(&BusKey,
-                       KEY_ALL_ACCESS,
+                       KEY_ENUMERATE_SUB_KEYS,
                        &ObjectAttributes);
     if (!NT_SUCCESS(Status))
     {
@@ -262,7 +262,7 @@ GetDisplayIdentifier(PWSTR Identifier,
                                    NULL);
 
         Status = NtOpenKey(&BusInstanceKey,
-                           KEY_ALL_ACCESS,
+                           KEY_ENUMERATE_SUB_KEYS,
                            &ObjectAttributes);
         if (!NT_SUCCESS(Status))
         {
@@ -281,7 +281,7 @@ GetDisplayIdentifier(PWSTR Identifier,
                                    NULL);
 
         Status = NtOpenKey(&ControllerKey,
-                           KEY_ALL_ACCESS,
+                           KEY_ENUMERATE_SUB_KEYS,
                            &ObjectAttributes);
         if (NT_SUCCESS(Status))
         {
@@ -300,7 +300,7 @@ GetDisplayIdentifier(PWSTR Identifier,
                                            NULL);
 
                 Status = NtOpenKey(&ControllerInstanceKey,
-                                   KEY_ALL_ACCESS,
+                                   KEY_QUERY_VALUE,
                                    &ObjectAttributes);
                 if (!NT_SUCCESS(Status))
                 {
@@ -637,6 +637,10 @@ ProcessLocaleRegistry(PGENERIC_LIST List)
     if (LanguageId == NULL)
         return FALSE;
 
+    /* Skip first 4 zeroes */
+    if (wcslen(LanguageId) >= 4)
+        LanguageId += 4;
+
     /* Open the NLS language key */
     RtlInitUnicodeString(&KeyName,
                          L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language");
@@ -648,7 +652,7 @@ ProcessLocaleRegistry(PGENERIC_LIST List)
                                NULL);
 
     Status =  NtOpenKey(&KeyHandle,
-                        KEY_ALL_ACCESS,
+                        KEY_SET_VALUE,
                         &ObjectAttributes);
 
     if (!NT_SUCCESS(Status))
@@ -660,13 +664,12 @@ ProcessLocaleRegistry(PGENERIC_LIST List)
     /* Set default language */
     RtlInitUnicodeString(&ValueName,
                          L"Default");
-
     Status = NtSetValueKey(KeyHandle,
                            &ValueName,
                            0,
                            REG_SZ,
-                           (PVOID)(LanguageId + 4),
-                           8 * sizeof(PWCHAR));
+                           (PVOID)LanguageId,
+                           (wcslen(LanguageId) + 1) * sizeof(WCHAR));
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
@@ -681,17 +684,15 @@ ProcessLocaleRegistry(PGENERIC_LIST List)
                             &ValueName,
                             0,
                             REG_SZ,
-                            (PVOID)(LanguageId + 4),
-                            8 * sizeof(PWCHAR));
+                            (PVOID)LanguageId,
+                            (wcslen(LanguageId) + 1) * sizeof(WCHAR));
+    NtClose(KeyHandle);
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
-        NtClose(KeyHandle);
         return FALSE;
     }
 
-    NtClose(KeyHandle);
-
     return TRUE;
 }
 
@@ -825,6 +826,7 @@ CreateKeyboardLayoutList(HINF InfFile, WCHAR * DefaultKBLayout)
     PWCHAR UserData;
     const MUI_LAYOUTS * LayoutsList;
     ULONG uIndex = 0;
+    BOOL KeyboardLayoutsFound = FALSE;
 
     /* Get default layout id */
     if (!SetupFindFirstLineW (InfFile, L"NLS", L"DefaultLayout", &Context))
@@ -856,7 +858,7 @@ CreateKeyboardLayoutList(HINF InfFile, WCHAR * DefaultKBLayout)
                 /* FIXME: Handle error! */
                 DPRINT("INF_GetData() failed\n");
                 DestroyGenericList(List, FALSE);
-                break;
+                return NULL;
             }
 
             if (_wcsicmp(LayoutsList[uIndex].LayoutID, KeyName) == 0)
@@ -868,6 +870,9 @@ CreateKeyboardLayoutList(HINF InfFile, WCHAR * DefaultKBLayout)
                 if (UserData == NULL)
                 {
                     /* FIXME: Handle error! */
+                    DPRINT("RtlAllocateHeap() failed\n");
+                    DestroyGenericList(List, FALSE);
+                    return NULL;
                 }
 
                 wcscpy(UserData, KeyName);
@@ -877,14 +882,23 @@ CreateKeyboardLayoutList(HINF InfFile, WCHAR * DefaultKBLayout)
                                        Buffer,
                                        UserData,
                                        _wcsicmp(KeyName, DefaultKBLayout) ? FALSE : TRUE);
+                KeyboardLayoutsFound = TRUE;
             }
-            
+
         } while (SetupFindNextLine(&Context, &Context));
 
         uIndex++;
 
     } while (LayoutsList[uIndex].LangID != NULL);
 
+    /* FIXME: Handle this case */
+    if (!KeyboardLayoutsFound)
+    {
+        DPRINT1("No keyboard layouts have been found\n");
+        DestroyGenericList(List, FALSE);
+        return NULL;
+    }
+
     return List;
 }
 
@@ -963,7 +977,7 @@ SetGeoID(PWCHAR Id)
                                NULL);
 
     Status =  NtOpenKey(&KeyHandle,
-                          KEY_ALL_ACCESS,
+                        KEY_SET_VALUE,
                          &ObjectAttributes);
     if(!NT_SUCCESS(Status))
     {
@@ -976,11 +990,11 @@ SetGeoID(PWCHAR Id)
                                    0,
                                    REG_SZ,
                                    (PVOID)Id,
-                                   (wcslen(Id) * sizeof(WCHAR)));
+                                   (wcslen(Id) + 1) * sizeof(WCHAR));
+    NtClose(KeyHandle);
     if (!NT_SUCCESS(Status))
     {
          DPRINT1("NtSetValueKey() failed (Status = %lx)\n", Status);
-         NtClose(KeyHandle);
          return FALSE;
     }