+/**\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