IntelFrameworkModulePkg/LegacyUi: Get legacy options when open legacy form

The LegacyBootMaintUiLib depends on the LegacyBootManagerLib to realize its
functionality, the LegacyBootManagerLib may initialize after
LegacyBootMaintUiLib, so the functionality of LegacyBootMaintUiLib may
be incorrect. Now we fix this issue by executing the related codes when
opening the legacy forminstead in its the constructor function. Because
when opening the legacy form, the LegacyBootManagerLib must have been
initialized.

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>
diff --git a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
index 3a3eeed..740c95c 100644
--- a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
+++ b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
@@ -19,6 +19,7 @@
 EFI_GUID  mLegacyBootOptionGuid     = LEGACY_BOOT_OPTION_FORMSET_GUID;

 CHAR16    mLegacyBootStorageName[]  = L"LegacyBootData";

 BBS_TYPE  mBbsType[] = {BBS_FLOPPY, BBS_HARDDISK, BBS_CDROM, BBS_EMBED_NETWORK, BBS_BEV_DEVICE, BBS_UNKNOWN};

+BOOLEAN   mFirstEnterLegacyForm = FALSE;

 

 

 ///

@@ -95,6 +96,26 @@
   }

 };

 

+/**

+

+  Build the LegacyFDMenu LegacyHDMenu LegacyCDMenu according to LegacyBios.GetBbsInfo().

+

+**/

+VOID

+GetLegacyOptions (

+  VOID

+  );

+

+

+/**

+

+  Base on the L"LegacyDevOrder" variable to build the current order data.

+

+**/

+VOID

+GetLegacyOptionsOrder (

+  VOID

+  );

 

 /**

   Re-order the Boot Option according to the DevOrder.

@@ -1094,9 +1115,9 @@
   OUT EFI_BROWSER_ACTION_REQUEST             *ActionRequest

   )

 {

-  if (Action != EFI_BROWSER_ACTION_CHANGED && Action != EFI_BROWSER_ACTION_CHANGING) {

+  if (Action != EFI_BROWSER_ACTION_CHANGED && Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_FORM_OPEN) {

     //

-    // Do nothing for other UEFI Action. Only do call back when data is changed.

+    // Do nothing for other UEFI Action. Only do call back when data is changed or the form is open.

     //

     return EFI_UNSUPPORTED;

   }

@@ -1105,6 +1126,21 @@
     return EFI_INVALID_PARAMETER;

   }

 

+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {

+    if (QuestionId == FORM_FLOPPY_BOOT_ID) {

+      if (!mFirstEnterLegacyForm) {

+        //

+        // The leagcyBootMaintUiLib depends on the LegacyBootManagerLib to realize its functionality.

+        // We need to do the leagcy boot options related actions after the LegacyBootManagerLib has been initialized.

+        // Opening the legacy menus is the appropriate time that the LegacyBootManagerLib has already been initialized.

+        //

+        mFirstEnterLegacyForm = TRUE;

+        GetLegacyOptions ();

+        GetLegacyOptionsOrder ();

+      }

+    }

+  }

+

   if (Action == EFI_BROWSER_ACTION_CHANGING) {

     switch (QuestionId) {

     case FORM_FLOPPY_BOOT_ID:

@@ -1426,10 +1462,6 @@
     ASSERT (LegacyBootOptionData->HiiHandle != NULL);

 

     mLegacyBootOptionPrivate = LegacyBootOptionData;

-

-    GetLegacyOptions ();

-

-    GetLegacyOptionsOrder();

   }

 

   return EFI_SUCCESS;