]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/common/Tools.java
2 Java class Tools contains common use procedures.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.common
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.Calendar
;
18 import java
.util
.Date
;
19 import java
.util
.UUID
;
22 This class contains static methods for some common operations
24 @since PackageEditor 1.0
28 public static final String guidArrayPat
= "0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?";
29 public static final String guidRegistryPat
= "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}";
31 get current date and time, then return
34 public static String
getCurrentDateTime() {
35 Date now
= new Date(System
.currentTimeMillis());
36 SimpleDateFormat sdf
= new SimpleDateFormat("yyyy-MM-dd HH:mm");
37 return sdf
.format(now
);
41 Delete a folder and all its files
45 public static boolean deleteFolder(File fleFolderName
) {
46 boolean blnIsDeleted
= true;
47 File
[] aryAllFiles
= fleFolderName
.listFiles();
49 for (int indexI
= 0; indexI
< aryAllFiles
.length
; indexI
++) {
51 if (aryAllFiles
[indexI
].isDirectory()) {
52 blnIsDeleted
= deleteFolder(aryAllFiles
[indexI
]);
53 } else if (aryAllFiles
[indexI
].isFile()) {
54 if (!aryAllFiles
[indexI
].delete()) {
61 fleFolderName
.delete();
71 public static String
generateUuidString() {
72 return UUID
.randomUUID().toString();
75 public static String
formatGuidString (String guidNameConv
) {
80 .matches(Tools
.guidRegistryPat
)) {
81 strList
= guidNameConv
.split("-");
82 guid
= "0x" + strList
[0] + ", ";
83 guid
= guid
+ "0x" + strList
[1] + ", ";
84 guid
= guid
+ "0x" + strList
[2] + ", ";
86 guid
= guid
+ "0x" + strList
[3].substring(0, 2) + ", ";
87 guid
= guid
+ "0x" + strList
[3].substring(2, 4);
89 while (index
< strList
[4].length()) {
91 guid
= guid
+ "0x" + strList
[4].substring(index
, index
+ 2);
98 .matches(Tools
.guidArrayPat
)) {
99 strList
= guidNameConv
.split(",");
102 // chang ANSI c form to registry form
104 for (int i
= 0; i
< strList
.length
; i
++){
105 strList
[i
] = strList
[i
].substring(strList
[i
].lastIndexOf("x") + 1);
107 if (strList
[strList
.length
- 1].endsWith("}")) {
108 strList
[strList
.length
-1] = strList
[strList
.length
-1].substring(0, strList
[strList
.length
-1].length()-1);
111 //inserting necessary leading zeros
114 int segLen
= strList
[0].length();
116 for (int i
= 0; i
< 8 - segLen
; ++i
){
117 strList
[0] = "0" + strList
[0];
121 segLen
= strList
[1].length();
123 for (int i
= 0; i
< 4 - segLen
; ++i
){
124 strList
[1] = "0" + strList
[1];
127 segLen
= strList
[2].length();
129 for (int i
= 0; i
< 4 - segLen
; ++i
){
130 strList
[2] = "0" + strList
[2];
133 for (int i
= 3; i
< 11; ++i
) {
134 segLen
= strList
[i
].length();
136 strList
[i
] = "0" + strList
[i
];
140 for (int i
= 0; i
< 3; i
++){
141 guid
+= strList
[i
] + "-";
145 guid
+= strList
[4] + "-";
147 for (int i
= 5; i
< strList
.length
; ++i
){