home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.iavazip;
-
- import com.sfs.awt.treeview.Folder;
- import com.sfs.awt.treeview.Item;
- import com.sfs.debug.Debug;
- import com.sfs.os.OS;
- import com.sfs.util.SortableVector;
- import com.sfs.util.ZipEntrySorter;
- import java.awt.Dialog;
- import java.awt.Window;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Enumeration;
- import java.util.Vector;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
-
- class processImport extends processDlg {
- ImportDialog _import;
- ZipOutputStream tempZip;
- SortableVector importFiles;
- SortableVector copyEntries;
- Vector newZipEntries;
- String destinationPath;
- FileInputStream inFile;
- // $FF: renamed from: is java.io.InputStream
- InputStream field_0;
-
- void buildLists() {
- ZipEntrySorter2 var1 = new ZipEntrySorter2(this);
- this.importFiles = this._import.getSelection();
- this.newZipEntries = new Vector();
- Enumeration var2 = this.importFiles.elements();
-
- while(var2.hasMoreElements()) {
- this.newZipEntries.addElement(this.createZipEntryName((Item)var2.nextElement()));
- }
-
- this.copyEntries = new SortableVector(1, new ZipEntrySorter());
- if (!super.mainApp.ZipIsEmpty) {
- var2 = super.mainApp.zipFile.entries();
-
- while(var2.hasMoreElements()) {
- this.copyEntries.add(var2.nextElement());
- }
- }
-
- switch (this._import.getAction()) {
- case 0:
- case 2:
- for(int var10 = 0; var10 < this.newZipEntries.size(); ++var10) {
- int var8;
- if ((var8 = this.copyEntries.lookup(this.newZipEntries.elementAt(var10), var1)) != -1) {
- if (var10 % 20 == 0) {
- Thread.yield();
- }
-
- this.copyEntries.removeElementAt(var8);
- Debug.Info("remove from copyEntries: " + this.newZipEntries.elementAt(var10));
- }
- }
- break;
- case 1:
- for(int var9 = 0; var9 < this.importFiles.size(); ++var9) {
- int var7;
- if ((var7 = this.copyEntries.lookup(this.newZipEntries.elementAt(var9), var1)) != -1) {
- File var11 = new File(((Item)this.importFiles.elementAt(var9)).getAbsoluteName());
- if (var11.lastModified() > ((ZipEntry)this.copyEntries.elementAt(var7)).getTime()) {
- Debug.Info("remove from copyEntries: " + this.copyEntries.elementAt(var9));
- this.copyEntries.removeElementAt(var7);
- continue;
- }
-
- if (var9 % 10 == 0) {
- Thread.yield();
- }
- }
-
- Debug.Info("remove from importFiles: " + this.importFiles.elementAt(var9));
- this.importFiles.removeElementAt(var9);
- this.newZipEntries.removeElementAt(var9);
- --var9;
- }
- break;
- case 3:
- for(int var4 = 0; var4 < this.importFiles.size(); ++var4) {
- int var3;
- if ((var3 = this.copyEntries.lookup(this.newZipEntries.elementAt(var4), var1)) != -1) {
- File var5 = new File(((Item)this.importFiles.elementAt(var4)).getAbsoluteName());
- if (var5.lastModified() > ((ZipEntry)this.copyEntries.elementAt(var3)).getTime()) {
- this.copyEntries.removeElementAt(var3);
- Debug.Info("remove from copyEntries: " + this.newZipEntries.elementAt(var4));
- } else {
- Debug.Info("remove from importFiles: " + this.importFiles.elementAt(var4));
- this.importFiles.removeElementAt(var4);
- this.newZipEntries.removeElementAt(var4);
- --var4;
- }
-
- if (var4 % 10 == 0) {
- Thread.yield();
- }
- }
- }
- }
-
- Debug.Info(this.copyEntries.toString());
- Debug.Info(this.importFiles.toString());
- }
-
- public void processCanceled() {
- super.thread.stop();
-
- try {
- if (this.field_0 != null) {
- this.field_0.close();
- }
-
- if (this.inFile != null) {
- this.inFile.close();
- }
-
- if (this.tempZip != null) {
- this.tempZip.close();
- File var1 = new File("temp.zip");
- var1.delete();
- }
- } catch (IOException var2) {
- }
-
- this._import.mainApp.setDefaultCursor();
- super.mainApp.showStatus("Import Files canceled.");
- }
-
- protected void zip(Item var1, String var2) {
- try {
- String var3 = var1.getAbsoluteName();
- if (!OS.hasDrives()) {
- var3 = var3.replace('\\', File.separatorChar);
- var3 = var3.substring(1);
- }
-
- this.inFile = new FileInputStream(var3);
- var2 = var2.replace('\\', '/');
- ZipEntry var4 = new ZipEntry(var2);
- File var5 = new File(var1.getAbsoluteName());
- var4.setTime(var5.lastModified());
- int var6 = 0;
- byte[] var7 = new byte[256];
-
- try {
- this.tempZip.putNextEntry(var4);
-
- while((var6 = this.inFile.read(var7)) != -1) {
- this.tempZip.write(var7, 0, var6);
- Thread.yield();
- }
-
- this.inFile.close();
- this.tempZip.closeEntry();
- if (this._import.getAction() == 2 && !var5.delete()) {
- Debug.Info("delete on ACTION_MOVE failed.");
- return;
- }
- } catch (IOException var10) {
- this._import.mainApp.showStatus("IOException occured while reading " + var1.getAbsoluteName());
- Debug.Info("IOException occured: " + ((Throwable)var10).getMessage());
- ((Throwable)var10).printStackTrace(System.out);
- return;
- }
- } catch (FileNotFoundException var11) {
- this._import.mainApp.showStatus("File " + var1.getAbsoluteName() + " not found.");
- ((Throwable)var11).printStackTrace(System.out);
- }
-
- }
-
- public void run() {
- Item var1 = this._import.mainApp.tw.Root.getCaretItem();
- if (!(var1 instanceof Folder)) {
- var1 = var1.getParent();
- }
-
- if (var1 == this._import.mainApp.tw.Root) {
- this.destinationPath = "";
- } else {
- String var2 = var1.getAbsoluteName();
- this.destinationPath = var2.substring(var2.indexOf(92) + 1);
- if (this.destinationPath.length() != 0) {
- String var10001 = this.destinationPath;
- this.destinationPath = var10001 + File.separator;
- }
- }
-
- ((processDlg)this).showStatus("preparing lists");
- this.buildLists();
- System.runFinalization();
- System.gc();
- if (this.newZipEntries.size() > 0) {
- try {
- this.tempZip = new ZipOutputStream(new FileOutputStream("temp.zip"));
- } catch (IOException var14) {
- ((Throwable)var14).printStackTrace(System.out);
- }
- }
-
- if (this.importFiles.size() == 0) {
- super.mainApp.showStatus("Import 0 files completed.");
- ((Window)this).dispose();
- } else {
- ((processDlg)this).setMaximum(this.importFiles.size() + this.copyEntries.size());
- int var17 = 0;
- if (!this._import.mainApp.ZipIsEmpty) {
- ((processDlg)this).showHeading("Copy zip entries ...");
- this.tempZip.setMethod(this._import.getMethod());
- this.tempZip.setLevel(this._import.getCompression());
- byte[] var5 = new byte[256];
- Enumeration var6 = this.copyEntries.elements();
-
- try {
- while(var6.hasMoreElements()) {
- ZipEntry var3 = (ZipEntry)var6.nextElement();
- ZipEntry var4 = new ZipEntry(var3.getName());
- this.tempZip.putNextEntry(var4);
- this.field_0 = this._import.mainApp.zipFile.getInputStream(var3);
- String var7 = var3.getName();
- Debug.Info("copying " + var7);
- int var8;
- if ((var8 = var7.lastIndexOf(var7)) != -1) {
- var7 = var7.substring(var8 + 1);
- }
-
- ((processDlg)this).showStatus("copying " + var7);
-
- int var9;
- while((var9 = this.field_0.read(var5)) != -1) {
- this.tempZip.write(var5, 0, var9);
- Thread.yield();
- }
-
- this.tempZip.closeEntry();
- this.field_0.close();
-
- try {
- Thread.sleep(15L);
- } catch (InterruptedException var13) {
- }
- }
- } catch (IOException var15) {
- Debug.Info(((Throwable)var15).getMessage());
- ((Throwable)var15).printStackTrace(System.out);
- }
- }
-
- ((processDlg)this).showHeading("Importing files");
- Enumeration var18 = this.importFiles.elements();
- Enumeration var19 = this.newZipEntries.elements();
-
- while(super.notCanceled && var18.hasMoreElements()) {
- var19.hasMoreElements();
- var1 = (Item)var18.nextElement();
- Thread.yield();
- ((processDlg)this).showStatus("import " + var1.getName());
- this.zip(var1, (String)var19.nextElement());
- super.pb.setProgress((float)(var17++));
-
- try {
- Thread.sleep(15L);
- } catch (InterruptedException var12) {
- }
- }
-
- try {
- if (this.importFiles.size() > 0) {
- this.tempZip.finish();
- this.tempZip.close();
- this.tempZip = null;
- }
- } catch (IOException var11) {
- Debug.Info("sdfsfsdf" + ((Throwable)var11).getMessage());
- ((Throwable)var11).printStackTrace(System.out);
- }
-
- super.mainApp.cleanup();
- super.mainApp.showStatus("Import " + Integer.toString(this.importFiles.size()) + " files completed.");
- File var20 = new File("temp.zip");
- File var21 = new File(super.mainApp.zipFileName);
- if (!var21.delete()) {
- super.mainApp.showStatus("Deleting old zip file failed.");
- }
-
- if (!var20.renameTo(var21)) {
- super.mainApp.showStatus("Can't rename temp.zip. Opening temp.zip.");
- super.mainApp.Open("temp.zip");
- } else {
- super.mainApp.Open(super.mainApp.zipFileName);
- }
-
- ((Window)this).dispose();
- }
- }
-
- public processImport(ImportDialog var1) {
- super(var1.mainApp, "Import Files ...");
- this._import = var1;
- ((Dialog)this).setResizable(true);
- }
-
- String createZipEntryName(Item var1) {
- String var2 = var1.getAbsoluteName();
- if (OS.hasDrives()) {
- var2 = var2.substring(1);
- }
-
- var2 = var2.replace('\\', '/');
- switch (this._import.getFilenameHandling()) {
- case 1:
- int var3;
- if (OS.hasDrives() && (var3 = var2.indexOf(":")) != -1) {
- return this.destinationPath + var2.substring(var3 + 2);
- }
-
- return this.destinationPath + var2;
- case 2:
- return this.destinationPath + var1.getName();
- default:
- int var8 = var1.getSelectedDistance();
- if (var8 > 0) {
- ++var8;
-
- Object var4;
- for(var4 = var1; var8-- > 0; var4 = ((Item)var4).getParent()) {
- }
-
- int var5 = ((Item)var4).getAbsoluteName().length();
- var2 = var2.substring(var5);
- } else {
- var2 = var1.getName();
- }
-
- return this.destinationPath + var2;
- }
- }
- }
-