private void menuItemView_Click(object sender, EventArgs e) { if (!isLoaded()) { return; } if (lvFiles.SelectedItems.Count == 0) { return; } ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(lvFiles.SelectedItems[0].Text)); if (ent == null) { return; } ent.extractTo(Path.GetTempPath()); string file = String.Format("{0}\\{1}{2}", Path.GetTempPath(), ent.getName(), ent.getExtension()); Process p = Process.Start(file); if (p != null) { p.WaitForExit(); } File.Delete(file); }
/** * Generates a string containing the name, isDirectory setting and size of an entry. * <p> * For example:<br/> * <tt>- 2000 main.c</tt><br/> * <tt>d 100 testfiles</tt><br/> * * @return the representation of the entry */ public static String toString(ArchiveEntry entry) { StringBuilder sb = new StringBuilder(); sb.Append(entry.isDirectory()? 'd' : '-');// c.f. "ls -l" output String size = entry.getSize().toString(); sb.Append(' '); // Pad output to 7 places, leading spaces for (int i = 7; i > size.length(); i--) { sb.Append(' '); } sb.Append(size); sb.Append(' ').Append(entry.getName()); return(sb.toString()); }
private void lvFiles_ItemDrag(object sender, ItemDragEventArgs e) { List <string> selection = new List <string>(); foreach (ListViewItem item in lvFiles.SelectedItems) { ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(item.Text)); if (ent == null) { return; } ent.extractTo(Path.GetTempPath()); string file = String.Format("{0}\\{1}{2}", Path.GetTempPath(), ent.getName(), ent.getExtension()); selection.Add(file); } DataObject data = new DataObject(DataFormats.FileDrop, selection.ToArray()); DoDragDrop(data, DragDropEffects.Move); }
/** * Checks if an ArchiveEntry is deleted later in the ChangeSet. This is * necessary if an file is added with this ChangeSet, but later became * deleted in the same set. * * @param entry * the entry to check * @return true, if this entry has an deletion change later, false otherwise */ private bool isDeletedLater(java.util.Set <Change> workingSet, ArchiveEntry entry) { String source = entry.getName(); if (!workingSet.isEmpty()) { for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();) { Change change = it.next(); int type = change.type(); String target = change.targetFile(); if (type == Change.TYPE_DELETE && source.equals(target)) { return(true); } if (type == Change.TYPE_DELETE_DIR && source.startsWith(target + "/")) { return(true); } } } return(false); }
/** * Performs all changes collected in this ChangeSet on the input stream and * streams the result to the output stream. Perform may be called more than once. * * This method finishes the stream, no other entries should be added * after that. * * @param in * the InputStream to perform the changes on * @param out * the resulting OutputStream with all modifications * @throws IOException * if an read/write error occurs * @return the results of this operation */ public ChangeSetResults perform(ArchiveInputStream inJ, ArchiveOutputStream outJ) //throws IOException { ChangeSetResults results = new ChangeSetResults(); java.util.Set <Change> workingSet = new java.util.LinkedHashSet <Change>(changes); for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();) { Change change = it.next(); if (change.type() == Change.TYPE_ADD && change.isReplaceMode()) { copyStream(change.getInput(), outJ, change.getEntry()); it.remove(); results.addedFromChangeSet(change.getEntry().getName()); } } ArchiveEntry entry = null; while ((entry = inJ.getNextEntry()) != null) { bool copy = true; for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();) { Change change = it.next(); int type = change.type(); String name = entry.getName(); if (type == Change.TYPE_DELETE && name != null) { if (name.equals(change.targetFile())) { copy = false; it.remove(); results.deleted(name); break; } } else if (type == Change.TYPE_DELETE_DIR && name != null) { if (name.StartsWith(change.targetFile() + "/")) { copy = false; results.deleted(name); break; } } } if (copy) { if (!isDeletedLater(workingSet, entry) && !results.hasBeenAdded(entry.getName())) { copyStream(inJ, outJ, entry); results.addedFromStream(entry.getName()); } } } // Adds files which hasn't been added from the original and do not have replace mode on for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();) { Change change = it.next(); if (change.type() == Change.TYPE_ADD && !change.isReplaceMode() && !results.hasBeenAdded(change.getEntry().getName())) { copyStream(change.getInput(), outJ, change.getEntry()); it.remove(); results.addedFromChangeSet(change.getEntry().getName()); } } outJ.finish(); return(results); }