Siba/src/org/dclermonte/siba/cli/SibaCLI.java

133 lines
3.5 KiB
Java

/*
* Copyright (C) 2016 Didier Clermonté <dclermonte@april.org>
* Copyright (C) 2016 Christian Pierre Momon <christian.momon@devinsy.fr>
*
* This file is part of Siba.
*
* Siba is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.dclermonte.siba.cli;
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.ResourceBundle;
import org.apache.commons.compress.archivers.ArchiveException;
import org.dclermonte.siba.gui.SibaGUI;
import org.dclermonte.siba.model.SibaManager;
public class SibaCLI
{
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
public static void backup(final File directoryToSave, final String targetDirectory)
throws ArchiveException, IOException
{
File result;
result = SibaManager.backup(directoryToSave, targetDirectory);
System.out.println(BUNDLE.getString("BackupPanel.confirmDialogMessage.text") + result.getName());
return;
}
public static void check(final File fileToCheck) throws NoSuchAlgorithmException, IOException
{
boolean result;
result = SibaManager.check(fileToCheck);
String yourFile = BUNDLE.getString("CheckPanel.confirmDialogYourString.text");
String good = BUNDLE.getString("CheckPanel.confirmDialogGood.text");
String bad = BUNDLE.getString("CheckPanel.confirmDialogBad.text");
if (result)
{
System.out.println(yourFile + fileToCheck.getName() + good);
}
else
{
System.out.println(yourFile + fileToCheck.getName() + bad);
}
return;
}
public static void help()
{
System.out.println("usage : ");
System.out.println("Siba : ");
System.out.println("Siba [-h |-help| --help]");
System.out.println("siba -backup directoryToSave [-target]");
System.out.println("siba -check [filename | file.tgz | file.md5]");
}
public static void main(final String[] args) throws ArchiveException, IOException, NoSuchAlgorithmException
{
int numberParameter = args.length;
switch (numberParameter)
{
case 0:
SibaGUI.main(args);
break;
case 1:
help();
break;
case 2:
if (args[0].equals("-backup"))
{
File directoryToSave = new File(args[1]);
if (directoryToSave.exists())
{
backup(directoryToSave, directoryToSave.getParent());
System.out.println(BUNDLE.getString("BackupPanel.parentDirectory.text"));
return;
}
}
if (args[0].equals("-check"))
{
File fileToCheck = new File(args[1]);
if (fileToCheck.exists())
{
check(fileToCheck);
return;
}
}
else
{
help();
}
break;
case 3:
if (args[0].equals("-backup"))
{
File directoryToSave = new File(args[1]);
if (directoryToSave.exists())
{
backup(directoryToSave, args[2]);
return;
}
}
else
{
help();
}
break;
default:
help();
break;
}
}
}