@return FrameworkWizardUI The instance of this class\r
\r
**/\r
- public static FrameworkWizardUI getInstance() {\r
+ public static FrameworkWizardUI getInstance(String[] args) {\r
if (fwui == null) {\r
- fwui = new FrameworkWizardUI();\r
+ fwui = new FrameworkWizardUI(args);\r
}\r
return fwui;\r
}\r
+ \r
+ /**\r
+ If the class hasn't an instnace, new one.\r
+ \r
+ @return FrameworkWizardUI The instance of this class\r
+ \r
+ **/\r
+ public static FrameworkWizardUI getInstance() {\r
+ return fwui;\r
+ }\r
\r
/**\r
This method initializes jMenuBar \r
* Main class, start the GUI\r
* \r
*/\r
- public static void main(String[] args) {\r
- FrameworkWizardUI module = FrameworkWizardUI.getInstance();\r
+ public static void main(String[] args) { \r
+ //\r
+ // Start Main UI\r
+ //\r
+ FrameworkWizardUI module = FrameworkWizardUI.getInstance(args);\r
module.setVisible(true);\r
}\r
\r
This is the default constructor\r
\r
**/\r
- public FrameworkWizardUI() {\r
+ public FrameworkWizardUI(String[] args) {\r
super();\r
- init();\r
+ init(args);\r
}\r
\r
/**\r
\r
\r
**/\r
- private void init() {\r
+ private void init(String[] args) {\r
//\r
// Set current workspace and check\r
// Check if exists WORKSPACE\r
//\r
SplashScreen ss = new SplashScreen();\r
ss.setVisible(true);\r
+ \r
+ //\r
+ // Go through args to check if enable log\r
+ //\r
+ for (int index = 0; index < args.length; index++) {\r
+ if (args[index].equals("--log") || args[index].equals("-l")) {\r
+ Log.setSaveLog(true);\r
+ }\r
+ }\r
\r
//\r
// Init Global Data\r
import javax.swing.JOptionPane;\r
\r
import org.tianocore.frameworkwizard.FrameworkWizardUI;\r
+import org.tianocore.frameworkwizard.workspace.Workspace;\r
\r
/**\r
The class is used to provides static interfaces to save log and error information\r
\r
**/\r
public class Log {\r
+ //\r
+ //Log file directory path\r
+ //\r
+ private static String strLogDir = Workspace.getCurrentWorkspace() + DataType.FILE_SEPARATOR + "Tools"\r
+ + DataType.FILE_SEPARATOR + "Logs";\r
\r
//\r
//Log file\r
//\r
//Log file name\r
//\r
- static String strLogFileName = "Log.log";\r
+ private static String strLogFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.log";\r
\r
//\r
//Wrn file name\r
//\r
- static String strWrnFileName = "Wrn.log";\r
+ private static String strWrnFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.wrn";\r
\r
//\r
//Err file name\r
//\r
- static String strErrFileName = "Err.log";\r
+ private static String strErrFileName = strLogDir + DataType.FILE_SEPARATOR + "frameworkwizard.err";\r
+\r
+ //\r
+ //Flag for create log or not\r
+ //\r
+ private static boolean isSaveLog = false;\r
\r
/**\r
Main class, used for test\r
public static void log(String strItem, String strLog) {\r
try {\r
writeToLogFile(strItem + ":" + strLog);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
public static void log(String strLog) {\r
try {\r
writeToLogFile(strLog);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
try {\r
writeToWrnFile("Warning when " + strItem + "::" + strWrn);\r
showWrnMessage(strWrn);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
try {\r
writeToWrnFile("Warning::" + strWrn);\r
showWrnMessage("Warning::" + strWrn);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
public static void err(String strItem, String strErr) {\r
try {\r
writeToErrFile("Error when " + strItem + "::" + strErr);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
public static void err(String strErr) {\r
try {\r
writeToErrFile("Error::" + strErr);\r
- } catch (IOException e) {\r
+ } catch (Exception e) {\r
e.printStackTrace();\r
}\r
}\r
**/\r
private static void showWrnMessage(String strErr) {\r
String strReturn = Tools.wrapStringByWord(strErr);\r
- JOptionPane\r
- .showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
+ JOptionPane.showConfirmDialog(FrameworkWizardUI.getInstance(), strReturn, "Warning",\r
+ JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);\r
}\r
\r
/**\r
@throws IOException\r
\r
**/\r
- private static void writeToLogFile(String strLog) throws IOException {\r
- try {\r
- if (fleLogFile == null) {\r
- fleLogFile = new File(strLogFileName);\r
- fleLogFile.createNewFile();\r
+ private static void writeToLogFile(String strLog) throws Exception {\r
+ if (isSaveLog) {\r
+ try {\r
+ createLogDir();\r
+ if (fleLogFile == null) {\r
+ fleLogFile = new File(strLogFileName);\r
+ fleLogFile.delete();\r
+ fleLogFile.createNewFile();\r
+ }\r
+ FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
+ fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.flush();\r
+ fos.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
}\r
- FileOutputStream fos = new FileOutputStream(fleLogFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
}\r
}\r
\r
Open wrn file and write wrn information\r
\r
@param strLog The log information\r
- @throws IOException\r
+ * @throws Exception \r
\r
**/\r
- private static void writeToWrnFile(String strLog) throws IOException {\r
- try {\r
- if (fleWrnFile == null) {\r
- fleWrnFile = new File(strWrnFileName);\r
- fleWrnFile.createNewFile();\r
+ private static void writeToWrnFile(String strLog) throws Exception {\r
+ if (isSaveLog) {\r
+ try {\r
+ createLogDir();\r
+ if (fleWrnFile == null) {\r
+ fleWrnFile = new File(strWrnFileName);\r
+ fleWrnFile.delete();\r
+ fleWrnFile.createNewFile();\r
+ }\r
+ FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
+ fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.flush();\r
+ fos.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
}\r
- FileOutputStream fos = new FileOutputStream(fleWrnFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
}\r
}\r
\r
@throws IOException\r
\r
**/\r
- private static void writeToErrFile(String strLog) throws IOException {\r
- try {\r
- if (fleErrFile == null) {\r
- fleErrFile = new File(strErrFileName);\r
- fleErrFile.createNewFile();\r
+ private static void writeToErrFile(String strLog) throws Exception {\r
+ if (isSaveLog) {\r
+ try {\r
+ createLogDir();\r
+ if (fleErrFile == null) {\r
+ fleErrFile = new File(strErrFileName);\r
+ fleErrFile.delete();\r
+ fleErrFile.createNewFile();\r
+ }\r
+ FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
+ fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
+ fos.flush();\r
+ fos.close();\r
+ } catch (FileNotFoundException e) {\r
+ e.printStackTrace();\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
}\r
- FileOutputStream fos = new FileOutputStream(fleErrFile, true);\r
- fos.write((Tools.getCurrentDateTime() + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.write((strLog + DataType.DOS_LINE_SEPARATOR).getBytes());\r
- fos.flush();\r
- fos.close();\r
- } catch (FileNotFoundException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
}\r
}\r
+\r
+ /**\r
+ Check if directory for Logs exists or not\r
+ Create the directory if it doesn't exist \r
+ * @throws Exception \r
+ \r
+ **/\r
+ private static void createLogDir() throws Exception {\r
+ File f = new File(strLogDir);\r
+ if (!f.exists()) {\r
+ FileOperation.newFolder(strLogDir);\r
+ }\r
+ }\r
+\r
+ public static boolean isSaveLog() {\r
+ return isSaveLog;\r
+ }\r
+\r
+ public static void setSaveLog(boolean isSaveLog) {\r
+ Log.isSaveLog = isSaveLog;\r
+ }\r
}\r