]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Restore question base on the fail info when submit fail
authorDandan Bi <dandan.bi@intel.com>
Fri, 22 Apr 2016 05:51:04 +0000 (13:51 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 6 May 2016 02:41:19 +0000 (10:41 +0800)
When RouteConfig function fail in SubmitForForm or SubmitForFormSet
function, we should restore the question value base on the failure
information, should not restore all the question.
This patch to fix this issue.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.h

index 5887e0f3be79a6856fcb74213195e24486598828..a437674bdc5c0f3e57b170d4f956e652d729315f 100644 (file)
@@ -2847,6 +2847,108 @@ FindQuestionFromProgress (
   return (BOOLEAN) (*RetForm != NULL);\r
 }\r
 \r
+/**\r
+  Base on the return Progress string to get the SyncConfigRequest and RestoreConfigRequest\r
+  for form and formset.\r
+\r
+  @param  Storage                 Storage which has this Progress string.\r
+  @param  ConfigRequest           The ConfigRequest string.\r
+  @param  Progress                The Progress string which has the first fail string.\r
+  @param  RestoreConfigRequest    Return the RestoreConfigRequest string.\r
+  @param  SyncConfigRequest       Return the SyncConfigRequest string.\r
+\r
+**/\r
+VOID\r
+GetSyncRestoreConfigRequest(\r
+  IN  BROWSER_STORAGE   *Storage,\r
+  IN  EFI_STRING        ConfigRequest,\r
+  IN  EFI_STRING        Progress,\r
+  OUT EFI_STRING        *RestoreConfigRequest,\r
+  OUT EFI_STRING        *SyncConfigRequest\r
+  )\r
+{\r
+  EFI_STRING    EndStr;\r
+  EFI_STRING    ConfigHdrEndStr;\r
+  EFI_STRING    ElementStr;\r
+  UINTN         TotalSize;\r
+  UINTN         RestoreEleSize;\r
+  UINTN         SyncSize;\r
+\r
+  ASSERT ((*Progress == L'&') || (*Progress == L'G'));\r
+  //\r
+  // If the Progress starts with ConfigHdr, means the failure is in the first name / value pair.\r
+  // Need to restore all the fields in the ConfigRequest.\r
+  //\r
+  if (*Progress == L'G') {\r
+    *RestoreConfigRequest = AllocateCopyPool (StrSize (ConfigRequest), ConfigRequest);\r
+    ASSERT (*RestoreConfigRequest != NULL);\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Find the first fail "NAME" or "OFFSET=0x####&WIDTH=0x####" string.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    //\r
+    // For Name/Value type, the data is "&Fred=16&George=16&Ron=12" formset,\r
+    // here, just keep the "Fred" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"PATH=");\r
+    ASSERT (ConfigHdrEndStr != NULL);\r
+    while (*ConfigHdrEndStr != L'&') {\r
+      ConfigHdrEndStr++;\r
+    }\r
+  } else {\r
+    //\r
+    // For Buffer type, the data is "OFFSET=0x####&WIDTH=0x####&VALUE=0x####",\r
+    // here, just keep the "OFFSET=0x####&WIDTH=0x####" string.\r
+    //\r
+    EndStr = StrStr (Progress, L"&VALUE=");\r
+    ASSERT (EndStr != NULL);\r
+    *EndStr = L'\0';\r
+    //\r
+    // Find the ConfigHdr in ConfigRequest.\r
+    //\r
+    ConfigHdrEndStr = StrStr (ConfigRequest, L"&OFFSET=");\r
+  }\r
+  //\r
+  // Find the first fail pair in the ConfigRequest.\r
+  //\r
+  ElementStr = StrStr (ConfigRequest, Progress);\r
+  ASSERT (ElementStr != NULL);\r
+  //\r
+  // To get the RestoreConfigRequest.\r
+  //\r
+  RestoreEleSize = StrSize (ElementStr);\r
+  TotalSize = (ConfigHdrEndStr - ConfigRequest) * sizeof (CHAR16) + RestoreEleSize + sizeof (CHAR16);\r
+  *RestoreConfigRequest = AllocateZeroPool (TotalSize);\r
+  ASSERT (*RestoreConfigRequest != NULL);\r
+  StrnCpyS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ConfigRequest, ConfigHdrEndStr - ConfigRequest);\r
+  StrCatS (*RestoreConfigRequest, TotalSize / sizeof (CHAR16), ElementStr);\r
+  //\r
+  // To get the SyncConfigRequest.\r
+  //\r
+  SyncSize = StrSize (ConfigRequest) - RestoreEleSize + sizeof (CHAR16);\r
+  *SyncConfigRequest = AllocateZeroPool (SyncSize);\r
+  ASSERT (*SyncConfigRequest != NULL);\r
+  StrnCpyS (*SyncConfigRequest, SyncSize / sizeof (CHAR16), ConfigRequest, SyncSize / sizeof (CHAR16) - 1);\r
+\r
+  //\r
+  // restore the Progress string to the original format.\r
+  //\r
+  if (Storage->Type == EFI_HII_VARSTORE_NAME_VALUE) {\r
+    *EndStr = L'=';\r
+  } else {\r
+    *EndStr = L'&';\r
+  }\r
+}\r
+\r
 /**\r
   Popup an save error info and get user input.\r
 \r
@@ -3126,6 +3228,10 @@ SubmitForForm (
     FreePool (ConfigResp);\r
 \r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      GetSyncRestoreConfigRequest (ConfigInfo->Storage, ConfigInfo->ConfigRequest, Progress, &ConfigInfo->RestoreConfigRequest, &ConfigInfo->SyncConfigRequest);\r
       InsertTailList (&gBrowserSaveFailFormSetList, &ConfigInfo->SaveFailLink);\r
       continue;\r
     }\r
@@ -3145,8 +3251,18 @@ SubmitForForm (
       while (!IsNull (&gBrowserSaveFailFormSetList, Link)) {\r
         ConfigInfo = FORM_BROWSER_CONFIG_REQUEST_FROM_SAVE_FAIL_LINK (Link);\r
         Link = GetNextNode (&gBrowserSaveFailFormSetList, Link);\r
-\r
-        SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->ConfigRequest, FALSE);\r
+        //\r
+        // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+        // base on the SyncConfigRequest to Sync the buffer.\r
+        //\r
+        SynchronizeStorage (ConfigInfo->Storage, ConfigInfo->RestoreConfigRequest, FALSE);\r
+        FreePool (ConfigInfo->RestoreConfigRequest);\r
+        ConfigInfo->RestoreConfigRequest = NULL;\r
+        if (ConfigInfo->SyncConfigRequest != NULL) {\r
+          SynchronizeStorage(ConfigInfo->Storage, ConfigInfo->SyncConfigRequest, TRUE);\r
+          FreePool (ConfigInfo->SyncConfigRequest);\r
+          ConfigInfo->SyncConfigRequest = NULL;\r
+        }\r
 \r
         Status = EFI_SUCCESS;\r
       }\r
@@ -3269,6 +3385,10 @@ SubmitForFormSet (
                                       &Progress\r
                                       );\r
     if (EFI_ERROR (Status)) {\r
+      //\r
+      // Submit fail, to get the RestoreConfigRequest and SyncConfigRequest.\r
+      //\r
+      GetSyncRestoreConfigRequest (FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, Progress, &FormSetStorage->RestoreConfigRequest, &FormSetStorage->SyncConfigRequest);\r
       InsertTailList (&FormSet->SaveFailStorageListHead, &FormSetStorage->SaveFailLink);\r
       if (!HasInserted) {\r
         //\r
@@ -3310,8 +3430,18 @@ SubmitForFormSet (
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (Link);\r
           Storage        = FormSetStorage->BrowserStorage;\r
           Link = GetNextNode (&FormSet->SaveFailStorageListHead, Link);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if (FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
 \r
           Status = EFI_SUCCESS;\r
         }\r
@@ -3445,8 +3575,18 @@ SubmitForSystem (
         while (!IsNull (&LocalFormSet->SaveFailStorageListHead, StorageLink)) {\r
           FormSetStorage = FORMSET_STORAGE_FROM_SAVE_FAIL_LINK (StorageLink);\r
           StorageLink = GetNextNode (&LocalFormSet->SaveFailStorageListHead, StorageLink);\r
-\r
-          SynchronizeStorage(FormSetStorage->BrowserStorage, FormSetStorage->ConfigRequest, FALSE);\r
+          //\r
+          // Process the submit fail question, base on the RestoreConfigRequest to restore the EditBuffer\r
+          // base on the SyncConfigRequest to Sync the buffer.\r
+          //\r
+          SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->RestoreConfigRequest, FALSE);\r
+          FreePool (FormSetStorage->RestoreConfigRequest);\r
+          FormSetStorage->RestoreConfigRequest = NULL;\r
+          if ( FormSetStorage->SyncConfigRequest != NULL) {\r
+            SynchronizeStorage (FormSetStorage->BrowserStorage, FormSetStorage->SyncConfigRequest, TRUE);\r
+            FreePool (FormSetStorage->SyncConfigRequest);\r
+            FormSetStorage->SyncConfigRequest = NULL;\r
+          }\r
         }\r
       }\r
 \r
index 0abb09cf87b57419ef615e1b5af50d865e5b2060..cbc5401323bbf3142cd8957f8894b3ff1541c429 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Private MACRO, structure and function definitions for Setup Browser module.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -178,6 +178,8 @@ typedef struct {
   BOOLEAN          HasCallAltCfg;  // Flag to show whether browser has call ExtractConfig to get Altcfg string.\r
   UINTN            ElementCount;   // Number of <RequestElement> in the <ConfigRequest>\r
   UINTN            SpareStrLen;    // Spare length of ConfigRequest string buffer\r
+  CHAR16           *RestoreConfigRequest; // When submit formset fail, the element need to be restored\r
+  CHAR16           *SyncConfigRequest;    // When submit formset fail, the element need to be synced\r
 } FORMSET_STORAGE;\r
 \r
 #define FORMSET_STORAGE_FROM_LINK(a)  CR (a, FORMSET_STORAGE, Link, FORMSET_STORAGE_SIGNATURE)\r
@@ -387,6 +389,8 @@ typedef struct {
   CHAR16                *ConfigAltResp; // Alt config response string for this ConfigRequest.\r
   UINTN                 ElementCount;   // Number of <RequestElement> in the <ConfigRequest>  \r
   UINTN                 SpareStrLen;\r
+  CHAR16                *RestoreConfigRequest; // When submit form fail, the element need to be restored\r
+  CHAR16                *SyncConfigRequest;    // When submit form fail, the element need to be synced\r
 \r
   BROWSER_STORAGE       *Storage;\r
 } FORM_BROWSER_CONFIG_REQUEST;\r