diff --git a/src/org/dclermonte/siba/cli/SibaCLI.java b/src/org/dclermonte/siba/cli/SibaCLI.java index 70cd072..9cf2383 100644 --- a/src/org/dclermonte/siba/cli/SibaCLI.java +++ b/src/org/dclermonte/siba/cli/SibaCLI.java @@ -44,7 +44,7 @@ public class SibaCLI File result; result = SibaManager.backup(directoryToSave); System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$ - return; + } /** @@ -60,7 +60,7 @@ public class SibaCLI File result; result = SibaManager.backup(directoryToSave, targetDirectory); System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$ - return; + } /** @@ -86,7 +86,6 @@ public class SibaCLI { System.out.println(yourFile + fileToCheck.getName() + bad); } - return; } /** diff --git a/src/org/dclermonte/siba/gui/AboutDialog.java b/src/org/dclermonte/siba/gui/AboutDialog.java index d2a9bd8..8740160 100644 --- a/src/org/dclermonte/siba/gui/AboutDialog.java +++ b/src/org/dclermonte/siba/gui/AboutDialog.java @@ -21,6 +21,7 @@ package org.dclermonte.siba.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Cursor; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; @@ -49,15 +50,18 @@ public class AboutDialog extends JDialog */ public AboutDialog() { - getContentPane().setBackground(new Color(154, 205, 50)); + setBackground(Color.GREEN); + getContentPane().setBackground(Color.GREEN); setBounds(100, 100, 450, 300); getContentPane().setLayout(new BorderLayout()); { JPanel buttonPane = new JPanel(); + buttonPane.setBackground(Color.GREEN); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); + okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); okButton.addActionListener(new ActionListener() { @Override @@ -74,11 +78,11 @@ public class AboutDialog extends JDialog } JPanel panel = new JPanel(); - panel.setBackground(new Color(0, 255, 255)); + panel.setBackground(Color.GREEN); getContentPane().add(panel, BorderLayout.CENTER); JTextPane txtpnSimpleBackupDveloppeur = new JTextPane(); - txtpnSimpleBackupDveloppeur.setBackground(new Color(0, 255, 255)); + txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN); txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14)); txtpnSimpleBackupDveloppeur.setText( "Simple Backup\n\nDéveloppeur Christian Pierre Momon et Didier Clermonté\n\nLicence GNU Affero General Public License 2016"); diff --git a/src/org/dclermonte/siba/gui/BackupPanel.java b/src/org/dclermonte/siba/gui/BackupPanel.java index 2d12d46..eec6b7c 100644 --- a/src/org/dclermonte/siba/gui/BackupPanel.java +++ b/src/org/dclermonte/siba/gui/BackupPanel.java @@ -106,11 +106,11 @@ public class BackupPanel extends JPanel public void actionPerformed(final ActionEvent e) { File file = SourceDirectorySelector.showSelectorDialog(null, null); - if (file == null) + if (!(file == null)) { - return; + BackupPanel.this.textField.setText(file.getPath()); } - BackupPanel.this.textField.setText(file.getPath()); + } }); panel.add(btnNewButton, "6, 2"); @@ -133,11 +133,10 @@ public class BackupPanel extends JPanel { File file = TargetDirectorySelector.showSelectorDialog(null, null); - if (file == null) + if (!(file == null)) { - return; + BackupPanel.this.textField_1.setText(file.getPath()); } - BackupPanel.this.textField_1.setText(file.getPath()); } }); diff --git a/src/org/dclermonte/siba/gui/SibaGUI.java b/src/org/dclermonte/siba/gui/SibaGUI.java index e3a3db1..31bd605 100644 --- a/src/org/dclermonte/siba/gui/SibaGUI.java +++ b/src/org/dclermonte/siba/gui/SibaGUI.java @@ -30,6 +30,7 @@ import java.awt.Point; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.io.File; import java.util.Locale; import java.util.ResourceBundle; @@ -40,15 +41,17 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JSeparator; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import org.apache.commons.lang3.StringUtils; -import org.dclermonte.siba.Siba; import org.dclermonte.siba.SibaException; import org.dclermonte.siba.gui.utils.GUIToolBox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The main class for GUI (Graphical User Interface ) @@ -59,7 +62,7 @@ import org.dclermonte.siba.gui.utils.GUIToolBox; public class SibaGUI { private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$ - + public static final Logger logger = LoggerFactory.getLogger(SibaGUI.class); /** * Launch the application. */ @@ -158,9 +161,10 @@ public class SibaGUI .getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/Cat-Box-32x32.png"))); this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400)); - this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47)); + this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.setBackground(Color.GREEN); tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER); @@ -182,14 +186,19 @@ public class SibaGUI this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); - menuBar.setBackground(new Color(152, 251, 152)); + menuBar.setBackground(Color.GREEN); this.frmSimpleBackup.setJMenuBar(menuBar); JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text")); //$NON-NLS-1$ + mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + mnFile.setBackground(Color.GREEN); + mnFile.setMnemonic('F'); mnFile.setForeground(Color.BLACK); menuBar.add(mnFile); JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text")); //$NON-NLS-1$ + mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + mntmBackup.setBackground(Color.GREEN); mntmBackup.addActionListener(new ActionListener() { @Override @@ -197,17 +206,19 @@ public class SibaGUI { tabbedPane.setSelectedIndex(0); File file = SourceDirectorySelector.showSelectorDialog(null, null); - if (file == null) + if (!(file == null)) { - return; + BackupPanel.textField.setText(file.getPath()); } - BackupPanel.textField.setText(file.getPath()); + // panel.setVisible(true); } }); mnFile.add(mntmBackup); JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text")); //$NON-NLS-1$ + mntmCheck.setBackground(Color.GREEN); + mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmCheck.addActionListener(new ActionListener() { @Override @@ -231,6 +242,9 @@ public class SibaGUI mnFile.add(mntmCheck); JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text")); //$NON-NLS-1$ + mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + mntmQuit.setBackground(Color.GREEN); + mntmQuit.setMnemonic(KeyEvent.VK_Q); mntmQuit.addActionListener(new ActionListener() { @Override @@ -239,19 +253,24 @@ public class SibaGUI SibaGUI.this.frmSimpleBackup.dispose(); } }); + + JSeparator separator = new JSeparator(); + mnFile.add(separator); mnFile.add(mntmQuit); JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$ + mnNewMenu.setMnemonic('H'); mnNewMenu.setLocation(new Point(500, 0)); mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT); mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT); mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mnNewMenu.setForeground(new Color(0, 0, 0)); - mnNewMenu.setBackground(new Color(127, 255, 212)); + mnNewMenu.setBackground(Color.GREEN); mnNewMenu.setOpaque(true); menuBar.add(mnNewMenu); JMenuItem mntmNewMenuItem_2 = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$ + mntmNewMenuItem_2.setBackground(Color.GREEN); mntmNewMenuItem_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); mntmNewMenuItem_2.addActionListener(new ActionListener() { @@ -303,7 +322,7 @@ public class SibaGUI String dataMissing = sibaException.getMessage(); if (!(sibaException.getCause() == null)) { - Siba.logger.info("SibaException chainée = " + sibaException.getCause().getMessage()); + logger.info("SibaException chainée = " + sibaException.getCause().getMessage()); // dataMissing.concat(sibaException.getCause().getMessage()); } diff --git a/src/org/dclermonte/siba/gui/messages.properties b/src/org/dclermonte/siba/gui/messages.properties index 9caf3f7..05cd299 100644 --- a/src/org/dclermonte/siba/gui/messages.properties +++ b/src/org/dclermonte/siba/gui/messages.properties @@ -25,8 +25,8 @@ CheckPanel.confirmDialogYourString.text=Your File CheckPanel.lblNewLabel.text=File to be Checked SibaGUI.mnFile.text=File SibaGUI.mnNewMenu.text=Help -SibaGUI.mntmBackup.text=Backup -SibaGUI.mntmCheck.text=Check +SibaGUI.mntmBackup.text=Backup... +SibaGUI.mntmCheck.text=Check... SibaGUI.mntmNewMenuItem_1.text=End SibaGUI.mntmNewMenuItem_2.text=About SibaGUI.mntmQuit.text=Quit diff --git a/src/org/dclermonte/siba/gui/messages_fr_FR.properties b/src/org/dclermonte/siba/gui/messages_fr_FR.properties index 6814f3f..c42ece1 100644 --- a/src/org/dclermonte/siba/gui/messages_fr_FR.properties +++ b/src/org/dclermonte/siba/gui/messages_fr_FR.properties @@ -28,6 +28,6 @@ CheckPanel.confirmDialogBad.text = comporte des erreurs BackupPanel.dataMissing.text = Données incomplètes BackupPanel.TitleWarning.text = Attention SibaGUI.mnFile.text=Fichier -SibaGUI.mntmBackup.text=Sauvegarde -SibaGUI.mntmQuit.text=Sortir -SibaGUI.mntmCheck.text=Vérification \ No newline at end of file +SibaGUI.mntmBackup.text=Sauvegarde... +SibaGUI.mntmQuit.text=Quitter +SibaGUI.mntmCheck.text=Vérification... \ No newline at end of file diff --git a/src/org/dclermonte/siba/model/SibaManager.java b/src/org/dclermonte/siba/model/SibaManager.java index cb8a9d0..2473429 100644 --- a/src/org/dclermonte/siba/model/SibaManager.java +++ b/src/org/dclermonte/siba/model/SibaManager.java @@ -20,6 +20,7 @@ package org.dclermonte.siba.model; import java.io.BufferedOutputStream; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -27,7 +28,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -78,6 +78,7 @@ public class SibaManager { File result; TarArchiveOutputStream out = null; + OutputStream gzipOutputStream = null; try { @@ -101,7 +102,7 @@ public class SibaManager String textDate = date.format(formatter); String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate; result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz"); - OutputStream gzipOutputStream = new GzipCompressorOutputStream( + gzipOutputStream = new GzipCompressorOutputStream( new BufferedOutputStream(new FileOutputStream(result))); out = new TarArchiveOutputStream(gzipOutputStream); directoryToSave(fileToSave, out, pathLength); @@ -121,6 +122,7 @@ public class SibaManager finally { IOUtils.closeQuietly(out); + IOUtils.closeQuietly(gzipOutputStream); } // @@ -140,9 +142,9 @@ public class SibaManager try { - String md5String = loadMD5Sum(choosenFile); + String md5String = SibaUtils.loadMD5Sum(choosenFile); File fileToCheck1 = loadFileToCheck(choosenFile); - if (StringUtils.equals(md5String, md5(fileToCheck1))) + if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1))) { result = true; } @@ -224,7 +226,7 @@ public class SibaManager result = new File(destination); FileWriter fileWriter = new FileWriter(result); - fileWriter.write(md5(directoryToSave)); + fileWriter.write(SibaUtils.md5(directoryToSave)); String newLine = System.getProperty("line.separator"); fileWriter.append(" " + directoryToSave.getName() + newLine); fileWriter.close(); @@ -245,7 +247,8 @@ public class SibaManager if (choosenFile.exists() && (choosenFile.length() > 32)) { FileReader fileReader = new FileReader(choosenFile); - + BufferedReader bufferedReader = new BufferedReader(fileReader); + String line = bufferedReader.readLine(); char[] fileToCheck = new char[(int) (choosenFile.length()) - 32]; fileReader.read(); fileReader.skip(32); @@ -271,76 +274,4 @@ public class SibaManager return result; } - /** - * - * @param choosenFile - * @return - * @throws IOException - */ - public static String loadMD5Sum(final File choosenFile) throws IOException - { - String result = ""; - - if (choosenFile.exists() && (choosenFile.length() > 32)) - { - FileReader fileReader = new FileReader(choosenFile); - char[] md5 = new char[32]; - byte[] md5byte = new byte[32]; - for (int index = 0; index < 32; index++) - { - md5[index] = (char) fileReader.read(); - md5byte[index] = (byte) md5[index]; - result = result + md5[index]; - } - fileReader.close(); - } - - // - // - return result; - } - - /** - * This method calculate the MD5 itself. - * - * @param input - * @return - * @throws IOException - * @throws NoSuchAlgorithmException - */ - public static String md5(final File input) throws IOException, NoSuchAlgorithmException - { - String result; - StringBuilder hashString = new StringBuilder(); - - byte[] byteInput = new byte[(int) input.length()]; - FileInputStream fileInputStream = new FileInputStream(input); - for (int index1 = 0; index1 < input.length(); index1++) - { - byteInput[index1] = (byte) fileInputStream.read(); - } - byte[] hash = null; - MessageDigest messageDigest = MessageDigest.getInstance("MD5"); - hash = messageDigest.digest(byteInput); - - for (int index = 0; index < hash.length; index++) - { - String hex = Integer.toHexString(hash[index]); - if (hex.length() == 1) - { - hashString.append('0'); - hashString.append(hex.charAt(hex.length() - 1)); - } - else - { - hashString.append(hex.substring(hex.length() - 2)); - } - } - fileInputStream.close(); - - result = hashString.toString(); - // - return result; - } - } diff --git a/src/org/dclermonte/siba/model/SibaUtils.java b/src/org/dclermonte/siba/model/SibaUtils.java new file mode 100644 index 0000000..75466ce --- /dev/null +++ b/src/org/dclermonte/siba/model/SibaUtils.java @@ -0,0 +1,92 @@ +package org.dclermonte.siba.model; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.commons.compress.utils.IOUtils; + +public class SibaUtils +{ + /** + * + * @param choosenFile + * @return + * @throws IOException + */ + public static String loadMD5Sum(final File choosenFile) throws IOException + { + String result = ""; + + if (choosenFile.exists() && (choosenFile.length() > 32)) + { + FileReader fileReader = new FileReader(choosenFile); + char[] md5 = new char[32]; + byte[] md5byte = new byte[32]; + for (int index = 0; index < 32; index++) + { + md5[index] = (char) fileReader.read(); + md5byte[index] = (byte) md5[index]; + result = result + md5[index]; + } + fileReader.close(); + } + + // + // + return result; + } + + /** + * This method calculate the MD5 itself. + * + * @param input + * @return + * @throws IOException + * @throws NoSuchAlgorithmException + */ + public static String md5(final File input) throws IOException, NoSuchAlgorithmException + { + String result; + StringBuilder hashString = new StringBuilder(); + FileInputStream fileInputStream = null; + try + { + byte[] byteInput = new byte[(int) input.length()]; + fileInputStream = new FileInputStream(input); + for (int index1 = 0; index1 < input.length(); index1++) + { + byteInput[index1] = (byte) fileInputStream.read(); + } + byte[] hash = null; + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + hash = messageDigest.digest(byteInput); + + for (int index = 0; index < hash.length; index++) + { + String hex = Integer.toHexString(hash[index]); + if (hex.length() == 1) + { + hashString.append('0'); + hashString.append(hex.charAt(hex.length() - 1)); + } + else + { + hashString.append(hex.substring(hex.length() - 2)); + } + } + fileInputStream.close(); + + result = hashString.toString(); + } + finally + { + IOUtils.closeQuietly(fileInputStream); + } + // + return result; + } +}