]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/DpUtilities.c
PcAtChipsetPkg: Convert all .uni files to utf-8
[mirror_edk2.git] / PerformancePkg / Dp_App / DpUtilities.c
index 4daca0b853624539d27ab7ea45182f8ca7ca534d..ec5a524475795652f838cec1936b2e215eb19265 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Utility functions used by the Dp application.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -156,10 +156,10 @@ GetShortPdbFileName (
   UINTN StartIndex;\r
   UINTN EndIndex;\r
 \r
-  ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16));\r
+  ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16));\r
 \r
   if (PdbFileName == NULL) {\r
-    StrCpy (UnicodeBuffer, L" ");\r
+    StrCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ");\r
   } else {\r
     StartIndex = 0;\r
     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)\r
@@ -178,8 +178,8 @@ GetShortPdbFileName (
     for (IndexA = StartIndex; IndexA < EndIndex; IndexA++) {\r
       UnicodeBuffer[IndexU] = (CHAR16) PdbFileName[IndexA];\r
       IndexU++;\r
-      if (IndexU >= DXE_PERFORMANCE_STRING_LENGTH) {\r
-        UnicodeBuffer[DXE_PERFORMANCE_STRING_LENGTH] = 0;\r
+      if (IndexU >= DP_GAUGE_STRING_LENGTH) {\r
+        UnicodeBuffer[DP_GAUGE_STRING_LENGTH] = 0;\r
         break;\r
       }\r
     }\r
@@ -218,8 +218,12 @@ GetNameFromHandle (
   CHAR16                      *NameString;\r
   UINTN                       StringSize;\r
   CHAR8                       *PlatformLanguage;\r
+  CHAR8                       *BestLanguage;\r
   EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
 \r
+  BestLanguage     = NULL;\r
+  PlatformLanguage = NULL;\r
+\r
   //\r
   // Method 1: Get the name string from image PDB\r
   //\r
@@ -269,15 +273,29 @@ GetNameFromHandle (
     // Get the current platform language setting\r
     //\r
     GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
+\r
+    BestLanguage = GetBestLanguage(\r
+                     ComponentName2->SupportedLanguages,\r
+                     FALSE,\r
+                     PlatformLanguage,\r
+                     ComponentName2->SupportedLanguages,\r
+                     NULL\r
+                     );\r
+\r
+    SafeFreePool (PlatformLanguage);\r
     Status = ComponentName2->GetDriverName (\r
                                ComponentName2,\r
-                               PlatformLanguage != NULL ? PlatformLanguage : "en-US",\r
+                               BestLanguage,\r
                                &StringPtr\r
                                );\r
+    SafeFreePool (BestLanguage);\r
     if (!EFI_ERROR (Status)) {\r
-      SafeFreePool (PlatformLanguage);\r
-      StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
-      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      StrnCpyS (\r
+        mGaugeString,\r
+        DP_GAUGE_STRING_LENGTH + 1,\r
+        StringPtr,\r
+        DP_GAUGE_STRING_LENGTH\r
+        );\r
       return;\r
     }\r
   }\r
@@ -320,8 +338,12 @@ GetNameFromHandle (
         //\r
         // Method 3. Get the name string from FFS UI section\r
         //\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
-        mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+        StrnCpyS (\r
+          mGaugeString,\r
+          DP_GAUGE_STRING_LENGTH + 1,\r
+          NameString,\r
+          DP_GAUGE_STRING_LENGTH\r
+          );\r
         FreePool (NameString);\r
       } else {\r
         //\r
@@ -336,8 +358,12 @@ GetNameFromHandle (
       //\r
       NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);\r
       if (NameString != NULL) {\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
-        mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+        StrnCpyS (\r
+          mGaugeString,\r
+          DP_GAUGE_STRING_LENGTH + 1,\r
+          NameString,\r
+          DP_GAUGE_STRING_LENGTH\r
+          );\r
         FreePool (NameString);\r
         return;\r
       }\r
@@ -349,7 +375,7 @@ GetNameFromHandle (
   //\r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
   ASSERT (StringPtr != NULL);\r
-  StrCpy (mGaugeString, StringPtr);\r
+  StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);\r
   FreePool (StringPtr);\r
   return;\r
 }\r
@@ -388,6 +414,7 @@ DurationInMicroSeconds (
   \r
 **/\r
 UINTN\r
+EFIAPI\r
 PrintToken (\r
   IN UINT16           Token,\r
   ...\r