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 char[] jetPass(){ JPasswordField psf = new JPasswordField(); psf.grabFocus(); int opt = * JOptionPane.showConfirmDialog(frm, psf, "Password", JOptionPane.PLAIN_MESSAGE); if(opt == * JOptionPane.OK_OPTION) return psf.getPassword(); return null; } * * <p>public String jetString(String msg, String ttl){ return JOptionPane.showInputDialog(frm, * msg, ttl, JOptionPane.QUESTION_MESSAGE); }* */ public static String jobString(String job) { if (job.charAt(0) == IMPORT_FLAG) { String[] brk = job.split(",", 4); // 4 parts to an import string File inf = new File(brk[1]); return "import " + inf.getName(); } else { String[] brk = job.split(",", 3); // 3 parts to export string File plf = new File(brk[2]); return "export " + plf.getName(); } }
public void totalExport() { File expf = new File("export"); if (expf.exists()) rmrf(expf); expf.mkdirs(); for (int sto = 0; sto < storeLocs.size(); sto++) { try { String sl = storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-"); File estore = new File(expf, sl); estore.mkdir(); File log = new File(estore, LIBRARY_NAME); PrintWriter pw = new PrintWriter(log); for (int i = 0; i < store.getRowCount(); i++) if (store.curStore(i) == sto) { File enc = store.locate(i); File dec = sec.prepareMainFile(enc, estore, false); pw.println(dec.getName()); pw.println(store.getValueAt(i, Storage.COL_DATE)); pw.println(store.getValueAt(i, Storage.COL_TAGS)); synchronized (jobs) { jobs.addLast(expJob(enc, dec)); } } pw.close(); } catch (IOException exc) { exc.printStackTrace(); JOptionPane.showMessageDialog(frm, "Exporting Failed"); return; } } JOptionPane.showMessageDialog(frm, "Exporting to:\n " + expf.getAbsolutePath()); }
/** * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also * reset the display: just call loadFile(null). * * @param file The file to load. * @param type The type of file (see DarwinCSV's constants). */ private void loadFile(File file, short type) { // If the file was reset, reset the display and keep going. if (file == null) { mainFrame.setTitle(basicTitle); setCurrentCSV(null); return; } // Load up a new DarwinCSV and set current CSV. try { setCurrentCSV(new DarwinCSV(file, type)); } catch (IOException ex) { MessageBox.messageBox( mainFrame, "Could not read file '" + file + "'", "Unable to read file '" + file + "': " + ex); } // Set the main frame title, based on the filename and the index. mainFrame.setTitle( basicTitle + ": " + file.getName() + " (" + String.format("%,d", currentCSV.getRowIndex().getRowCount()) + " rows)"); }
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 run() { going = true; while (going) { String chose = null; synchronized (jobs) { chose = jobs.poll(); } if (chose != null) { cur = chose; updateStatus(); long time = System.currentTimeMillis(); String op = "export"; String targ = null; boolean success = false; if (chose.charAt(0) == IMPORT_FLAG) { String[] brk = chose.split(",", 4); // 4 parts to an import string File imp = new File(brk[1]); targ = imp.getName(); if (edtImport(imp, brk[2], brk[3])) { // import successful success = true; if (checkImports) op = "import & check"; else op = "import (fast)"; store.fireTableDataChanged(); } else { // no import } } else { String[] brk = chose.split(",", 3); // 3 parts to an export string File pla = new File(brk[2]); targ = pla.getName(); if (edtExport(new File(brk[1]), pla)) { // export succeeded success = true; // System.out.println(pla.getParentFile().getAbsolutePath() + ", " + // tempLoc.getAbsolutePath() + ", " + pla.getParentFile().equals(tempLoc)); try { if (pla.getParentFile().getCanonicalPath().equals(tempLoc.getCanonicalPath())) secureUse(pla); } catch (IOException exc) { System.err.println("Failed to retrieve canonical path?"); } } else { // export failed } } if (success) System.out.println( "Completed " + op + " in " + (System.currentTimeMillis() - time) + "ms - " + targ); cur = null; updateStatus(); } else { if (needsSave && idx == 0) { boolean alldone = true; for (int i = 0; i < numThreads; i++) { if (encryptDecryptThreads[i].getCur() != null) { alldone = false; break; } } if (alldone) { System.out.println("Automatically saving"); try { store.saveAll(tempLoc); } catch (IOException e) { System.err.println("Automatic save failed"); } needsSave = false; } } try { Thread.sleep(500); } catch (InterruptedException e) { // do nothing } } } }