]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/String.py
BaseTool/Upt: Avoid UNI file name conflict
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / String.py
index 37ce1418ae1bc500dd5adac0656090b2c2f91366..05b5fb17da18c989c7f36785ffeb8af2428bf89e 100644 (file)
@@ -2,7 +2,7 @@
 # This file is used to define common string related functions used in parsing\r
 # process\r
 #\r
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available\r
 # under the terms and conditions of the BSD License which accompanies this\r
@@ -957,3 +957,27 @@ def IsMatchArch(Arch1, Arch2):
                     return True\r
 \r
     return False\r
+\r
+# Search all files in FilePath to find the FileName with the largest index\r
+# Return the FileName with index +1 under the FilePath\r
+#\r
+def GetUniFileName(FilePath, FileName):\r
+    Files = os.listdir(FilePath)\r
+    LargestIndex = -1\r
+    for File in Files:\r
+        if File.upper().startswith(FileName.upper()) and File.upper().endswith('.UNI'):\r
+            Index = File.upper().replace(FileName.upper(), '').replace('.UNI', '')\r
+            if Index:\r
+                try:\r
+                    Index = int(Index)\r
+                except Exception:\r
+                    Index = -1\r
+            else:\r
+                Index = 0\r
+            if Index > LargestIndex:\r
+                LargestIndex = Index + 1\r
+\r
+    if LargestIndex > -1:\r
+        return os.path.normpath(os.path.join(FilePath, FileName + str(LargestIndex) + '.uni'))\r
+    else:\r
+        return os.path.normpath(os.path.join(FilePath, FileName + '.uni'))\r