Parcourir la source

loading finished

Teh-Hai Julian Zheng il y a 7 ans
Parent
commit
f8fbca5066

+ 0 - 2
src/ui/controller/ClipboardController.java

@@ -177,8 +177,6 @@ public class ClipboardController {
 
 	public void cut(CpsUpperNode upperNode) {
 		copy(upperNode);
-		ArrayList<AbstractCpsObject> found = (upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes());
-
 		for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
 			if (upperNode == null)
 				cvsC.deleteObjectOnCanvas(abs);

+ 50 - 25
src/ui/controller/LoadController.java

@@ -10,6 +10,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -114,9 +115,10 @@ public class LoadController {
 		File src = new File(path);
 		File folder = readArchive(path, src);
 		folder.deleteOnExit();
-		for (File file : Arrays.asList(folder.listFiles())) {
-			System.out.println(file.getName());
-		}
+		String trim = folder.getPath().substring(0,
+				folder.getPath().lastIndexOf(folder.getName()) + folder.getName().length());
+
+		forwardFiles(folder, trim);
 
 	}
 
@@ -135,29 +137,28 @@ public class LoadController {
 		forwardEdges(edges, json, objDispatch);
 
 	}
-
-	private File readArchive(String path, File src) throws IOException, ArchiveException {
-		File tmp = Files.createTempDirectory("tmpHolon").toFile();
-		tmp.deleteOnExit();
-		InputStream input = new FileInputStream(src);
-		ArchiveInputStream stream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
-				input);
-
-		ArchiveEntry entry = stream.getNextEntry();
-		while (entry != null) {
-			File file = new File(tmp, entry.getName());
-			file.getParentFile().mkdirs();
-			OutputStream output = new FileOutputStream(file);
-			IOUtils.copy(stream, output);
-			output.close();
-			// file.createNewFile();
-			entry = stream.getNextEntry();
+	
+	/**
+	 * Loads the Files from the Savefile
+	 * @param folder
+	 * @param trim
+	 * @throws IOException
+	 */
+	private void forwardFiles(File folder, String trim) throws IOException {
+		// TODO Auto-generated method stub
+		for (File file : folder.listFiles()) {
+			File dst = new File(System.getProperty("user.home") + "/HolonGUI/" + file.getPath().replace(trim, ""));
+			
+			if (file.getName().contains(".json"))
+				readJson(file.getPath());
+			else if (file.isDirectory())
+				forwardFiles(file, trim);
+			else {
+				dst.getParentFile().mkdirs();
+				Files.copy(file.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
+			}
+	
 		}
-		
-		stream.close();
-		input.close();
-
-		return tmp;
 	}
 
 	/**
@@ -448,6 +449,30 @@ public class LoadController {
 		this.parser = new JsonParser();
 	}
 
+	private File readArchive(String path, File src) throws IOException, ArchiveException {
+		File tmp = Files.createTempDirectory("tmpHolon").toFile();
+		tmp.deleteOnExit();
+		InputStream input = new FileInputStream(src);
+		ArchiveInputStream stream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP,
+				input);
+
+		ArchiveEntry entry = stream.getNextEntry();
+		while (entry != null) {
+			File file = new File(tmp, entry.getName());
+			file.getParentFile().mkdirs();
+			OutputStream output = new FileOutputStream(file);
+			IOUtils.copy(stream, output);
+			output.close();
+			// file.createNewFile();
+			entry = stream.getNextEntry();
+		}
+
+		stream.close();
+		input.close();
+
+		return tmp;
+	}
+
 	/**
 	 * Init new Arrays which havent been serialized along the object
 	 *