]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/common/Tools.java
Initial import.
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / common / Tools.java
1 /** @file
2 Java class Tools contains common use procedures.
3
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
9
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.
12 **/
13 package org.tianocore.common;
14
15 import java.io.File;
16 import java.text.SimpleDateFormat;
17 import java.util.Calendar;
18 import java.util.Date;
19 import java.util.UUID;
20
21 /**
22 This class contains static methods for some common operations
23
24 @since PackageEditor 1.0
25 **/
26 public class Tools {
27
28 /**
29 get current date and time, then return
30 @return String
31 **/
32 public static String getCurrentDateTime() {
33 Date now = new Date(System.currentTimeMillis());
34 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
35 return sdf.format(now);
36 }
37
38 /**
39 Delete a folder and all its files
40 @param strFolderName
41 @return boolean
42 **/
43 public static boolean deleteFolder(File fleFolderName) {
44 boolean blnIsDeleted = true;
45 File[] aryAllFiles = fleFolderName.listFiles();
46
47 for (int indexI = 0; indexI < aryAllFiles.length; indexI++) {
48 if (blnIsDeleted) {
49 if (aryAllFiles[indexI].isDirectory()) {
50 blnIsDeleted = deleteFolder(aryAllFiles[indexI]);
51 } else if (aryAllFiles[indexI].isFile()) {
52 if (!aryAllFiles[indexI].delete()) {
53 blnIsDeleted = false;
54 }
55 }
56 }
57 }
58 if (blnIsDeleted) {
59 fleFolderName.delete();
60 }
61 return blnIsDeleted;
62 }
63
64 /**
65 Get a new GUID
66
67 @return String
68 **/
69 public static String generateUuidString() {
70 return UUID.randomUUID().toString();
71 }
72
73 }