public boolean edtImport(File fi, String date, String tags) { if (!fi.exists()) { System.err.println("import: file " + fi.getAbsolutePath() + " doesnt exist"); return false; } String pname = fi.getName(); if (store.containsEntry(pname)) { System.err.println("import: already have a file named " + pname); return false; } long size = fi.length() / KILOBYTE; File save = sec.encryptMainFile(fi, storeLocs.get(0), true); if (save == null) { System.err.println("import: Encryption failure"); return false; } if (checkImports) { boolean success = true; File checkfi = new File(idx + ".check"); File checkOut = sec.encryptSpecialFile(save, checkfi, false); if (checkOut == null) success = false; else { String fiHash = sec.digest(fi); String outHash = sec.digest(checkOut); if (fiHash == null || outHash == null || fiHash.length() < 1 || !fiHash.equals(outHash)) success = false; } checkfi.delete(); if (!success) { save.delete(); if (JOptionPane.showConfirmDialog( frm, "Confirming " + fi.getName() + "failed\n\n - Would you like to re-import the file?", "Import failed", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { String j = impJob(fi, date, tags); synchronized (jobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } return false; } } if (!fi.delete()) { System.err.println("import: Couldnt delete old file - continuing"); } store.add(save.getName(), pname, date, size, tags, 0); needsSave = true; return true; }
public boolean edtExport(File cip, File pla) { if (!cip.exists()) { System.err.println( "export: file " + cip.getAbsolutePath() + " doesnt exist for " + pla.getName()); pla.delete(); return false; } File save = sec.encryptSpecialFile(cip, pla, false); if (save == null) { System.err.println("export: Encryption failure"); pla.delete(); return false; } return true; }
public void secureDelete() { int rw = tblItems.getSelectedRow(); if (rw == -1) { JOptionPane.showMessageDialog(frm, "No item selected", "Error", JOptionPane.ERROR_MESSAGE); return; } int idx = tblItems.convertRowIndexToModel(rw); if (JOptionPane.showConfirmDialog( frm, "Delete " + store.plainName(idx) + "?", "Confirm Delete", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; File del = store.delete(idx); store.fireTableDataChanged(); if (del != null) { if (del.delete()) { // successful needsSave = true; } else { System.err.println("Delete " + del.getAbsolutePath() + " failed"); } } updateStatus(); }
public static boolean rmrf(File fi) { if (fi.isDirectory()) { boolean done = true; for (File subfi : fi.listFiles()) { if (!rmrf(subfi)) { done = false; } } if (!done) return false; return fi.delete(); } else { boolean done = true; for (int i = 0; i < 10; i++) { done = fi.delete(); if (done) break; try { Thread.sleep(100); } catch (InterruptedException e) { // do nothing } } return done; } }
/** * Save the document to a file. * * @see #write */ public boolean save(String filename) { try { setFilename(filename); // write to tmp file File tmpfile = File.createTempFile("gwb", null); write(new FileOutputStream(tmpfile)); // copy to dest file and delete tmp file FileUtils.copy(tmpfile, new File(filename)); tmpfile.delete(); // // fireDocumentInit(); return true; } catch (Exception e) { LogUtils.report(e); return false; } }