Pārlūkot izejas kodu

fix for autosave after app crash

Jessey Widhalm 7 gadi atpakaļ
vecāks
revīzija
3163286fc4

+ 4 - 1
.checkstyle

@@ -1,7 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
-  <fileset name="all" enabled="true" check-config-name="BP Configuration" local="false">
+  <local-check-config name="Checkstyle_BP" location="/home/jessey/Downloads/Checkstyle_BP" type="external" description="">
+    <additional-data name="protect-config-file" value="false"/>
+  </local-check-config>
+  <fileset name="all" enabled="true" check-config-name="Checkstyle_BP" local="true">
     <file-match-pattern match-pattern="." include-pattern="true"/>
   </fileset>
 </fileset-config>

+ 6 - 0
.project

@@ -10,8 +10,14 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
 	</natures>
 </projectDescription>

+ 42 - 0
src/tests/praktikumHolonsTestAutoSaveController.java

@@ -1,5 +1,47 @@
 package tests;
 
+import java.io.File;
+
+import org.junit.Before;
+
+import ui.controller.CanvasController;
+import ui.controller.CategoryController;
+import ui.controller.LoadController;
+import ui.controller.MultiPurposeController;
+import ui.controller.ObjectController;
+import ui.controller.StoreController;
+import ui.model.Model;
+import ui.model.idCounter;
+
 public class praktikumHolonsTestAutoSaveController {
+	protected praktikumHolonsAdapter adapter;
+	protected Model model;
+	protected MultiPurposeController mp;
+	protected CategoryController cg;
+	protected CanvasController cvs;
+	protected ObjectController obj;
+	protected StoreController storeController;
+	protected LoadController loadController;
+	protected idCounter id;
+	protected String path = System.getProperty("user.home") + "/HolonGUI/Test/";
 
+	@Before
+	public void setUp() {
+		adapter = new praktikumHolonsAdapter();
+		model = new Model();
+		mp = new MultiPurposeController(model);
+		cg = new CategoryController(model, mp);
+		cvs = new CanvasController(model, mp);
+		obj = new ObjectController(model, mp);
+		storeController = new StoreController(model);
+		loadController = new LoadController(model, cg, cvs, obj, mp);
+		// cg.initCategories();
+		// obj.initHolonElements();
+		File file = new File(path);
+		file.mkdirs();
+	}
+	
+	public void autoSaveMinimal(){
+		
+	}
 }

+ 3 - 3
src/ui/controller/AutoSaveController.java

@@ -31,9 +31,9 @@ public class AutoSaveController {
 
 	public void decreaseAutoSaveNr() {
 		currentSave = MODEL.getAutoSaveNr() - 1;
-//		if (currentSave < 0) {
-//			currentSave = max;
-//		}
+		// if (currentSave < 0) {
+		// currentSave = max;
+		// }
 		MODEL.setAutoSaveNr(currentSave);
 	}
 

+ 18 - 3
src/ui/controller/Control.java

@@ -53,6 +53,7 @@ public class Control {
 		this.consoleController = new ConsoleController(MODEL);
 		autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		File dest = new File(autoPath);
+		deleteDirectory(dest);
 		dest.mkdirs();
 		try {
 			autoSave();
@@ -62,6 +63,20 @@ public class Control {
 		}
 	}
 
+	public void deleteDirectory(File path) {
+		if (path.exists()) {
+			File[] files = path.listFiles();
+			for (int i = 0; i < files.length; i++) {
+				if (files[i].isDirectory()) {
+					deleteDirectory(files[i]);
+				} else {
+					files[i].delete();
+				}
+			}
+			path.delete();
+		}
+	}
+
 	/* Operations for searching */
 
 	public CpsObject searchByID(int ID) {
@@ -313,7 +328,7 @@ public class Control {
 	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		consoleController.addTextToConsole(text, color, p, bold, italic, nl);
 	}
-	
+
 	/**
 	 * Print Text on the console in black and font size 12
 	 *
@@ -330,14 +345,14 @@ public class Control {
 	public void clearConsole() {
 		consoleController.clearConsole();
 	}
-	
+
 	/**
 	 * @return sets the timerSpeed
 	 */
 	public void setTimerSpeed(int t) {
 		globalController.setTimerSpeed(t);
 	}
-	
+
 	/**
 	 * @param isSimulation
 	 *            boolean for for isSimulation

+ 1 - 15
src/ui/view/GUI.java

@@ -256,24 +256,10 @@ public class GUI<E> implements CategoryListener {
 				if (JOptionPane.showConfirmDialog(frmCyberPhysical, "Are you sure you want to exit?",
 						"Cyber Physical Systems Model", JOptionPane.YES_NO_OPTION,
 						JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
-					deleteDirectory(new File(System.getProperty("user.home") + "/HolonGUI/Autosave"));
+					controller.deleteDirectory(new File(System.getProperty("user.home") + "/HolonGUI/Autosave"));
 					System.exit(0);
 				}
 			}
-
-			private void deleteDirectory(File path) {
-				if (path.exists()) {
-					File[] files = path.listFiles();
-					for (int i = 0; i < files.length; i++) {
-						if (files[i].isDirectory()) {
-							deleteDirectory(files[i]);
-						} else {
-							files[i].delete();
-						}
-					}
-					path.delete();
-				}
-			}
 		});
 
 		JPanel contentPane = (JPanel) frmCyberPhysical.getContentPane();