2008-07-30 18:37:01 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.ui.panel.sfv;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2008-10-06 15:13:58 -04:00
|
|
|
import java.io.PrintWriter;
|
2008-07-30 18:37:01 -04:00
|
|
|
import java.util.Date;
|
2009-02-09 15:56:20 -05:00
|
|
|
import java.util.Formatter;
|
2009-03-14 06:20:59 -04:00
|
|
|
|
2009-02-09 15:56:20 -05:00
|
|
|
import net.sourceforge.filebot.Settings;
|
2009-05-02 19:34:04 -04:00
|
|
|
import net.sourceforge.filebot.hash.HashType;
|
|
|
|
import net.sourceforge.filebot.hash.VerificationFilePrinter;
|
2008-10-06 15:13:58 -04:00
|
|
|
import net.sourceforge.filebot.ui.transfer.TextFileExportHandler;
|
2009-01-24 19:08:57 -05:00
|
|
|
import net.sourceforge.tuned.FileUtilities;
|
2008-07-30 18:37:01 -04:00
|
|
|
|
|
|
|
|
2009-02-11 13:42:29 -05:00
|
|
|
class ChecksumTableExportHandler extends TextFileExportHandler {
|
2008-07-30 18:37:01 -04:00
|
|
|
|
|
|
|
private final ChecksumTableModel model;
|
|
|
|
|
|
|
|
|
|
|
|
public ChecksumTableExportHandler(ChecksumTableModel model) {
|
|
|
|
this.model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExport() {
|
2009-02-15 07:20:43 -05:00
|
|
|
return model.getRowCount() > 0 && defaultColumn() != null;
|
2008-07-30 18:37:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2009-02-09 15:56:20 -05:00
|
|
|
public void export(Formatter out) {
|
2009-02-15 07:20:43 -05:00
|
|
|
export(out, defaultColumn());
|
2008-07-30 18:37:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDefaultFileName() {
|
2009-02-15 07:20:43 -05:00
|
|
|
return getDefaultFileName(defaultColumn());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected File defaultColumn() {
|
|
|
|
// select first column that is not a verification file column
|
|
|
|
for (File root : model.checksumColumns()) {
|
|
|
|
if (root.isDirectory())
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2008-07-30 18:37:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void export(File file, File column) throws IOException {
|
2008-10-06 15:13:58 -04:00
|
|
|
PrintWriter out = new PrintWriter(file, "UTF-8");
|
2008-07-30 18:37:01 -04:00
|
|
|
|
|
|
|
try {
|
2009-02-09 15:56:20 -05:00
|
|
|
export(new Formatter(out), column);
|
2008-07-30 18:37:01 -04:00
|
|
|
} finally {
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-09 15:56:20 -05:00
|
|
|
public void export(Formatter out, File column) {
|
2009-02-15 07:20:43 -05:00
|
|
|
HashType hashType = model.getHashType();
|
|
|
|
|
|
|
|
// print header
|
|
|
|
out.format("; Generated by %s %s on %tF at %<tT%n", Settings.getApplicationName(), Settings.getApplicationVersion(), new Date());
|
2009-02-09 15:56:20 -05:00
|
|
|
out.format(";%n");
|
|
|
|
out.format(";%n");
|
2008-07-30 18:37:01 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
// print data
|
|
|
|
VerificationFilePrinter printer = hashType.newPrinter(out);
|
|
|
|
|
|
|
|
for (ChecksumRow row : model.rows()) {
|
|
|
|
ChecksumCell cell = row.getChecksum(column);
|
|
|
|
|
|
|
|
if (cell != null) {
|
|
|
|
String hash = cell.getChecksum(hashType);
|
|
|
|
|
|
|
|
if (hash != null) {
|
|
|
|
printer.println(cell.getName(), hash);
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 18:37:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getDefaultFileName(File column) {
|
2009-02-15 07:20:43 -05:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2008-07-30 18:37:01 -04:00
|
|
|
|
|
|
|
if (column != null)
|
2009-02-15 07:20:43 -05:00
|
|
|
sb.append(FileUtilities.getName(column));
|
|
|
|
else
|
|
|
|
sb.append("name");
|
2008-07-30 18:37:01 -04:00
|
|
|
|
2009-02-15 07:20:43 -05:00
|
|
|
return sb.append(".").append(model.getHashType().getExtension()).toString();
|
2008-07-30 18:37:01 -04:00
|
|
|
}
|
|
|
|
}
|