]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java
Missing changes to windows build scripts.
[simantics/fmil.git] / org.simantics.fmil.core / src / org / simantics / fmil / core / FMIL.java
index 7301caf4c8209883e9d77aaaa3fc3e5bc6a5aa17..1f1e098d7eade1d37c3edd6a2c5dec8c13acff83 100644 (file)
@@ -6,6 +6,7 @@ import java.io.RandomAccessFile;
 import java.net.URL;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -183,6 +184,11 @@ public class FMIL {
     private boolean fmuLoaded = false;
     public void loadFMUFile(String path) throws FMILException {
 
+        if (!Files.exists(Paths.get(path)))
+            throw new FMILException("File " + path + " does not exist");
+        if (!Files.isRegularFile(Paths.get(path)))
+            throw new FMILException("Path " + path + " is not a file");
+
         synchronized(syncObject) {
 
             if(fmuN % 2 == 0) {
@@ -193,21 +199,23 @@ public class FMIL {
                 fmuN = 0;
             }
 
-            File tempDir = new File(fmuDir);
-            if(tempDir.isDirectory()) {
+            java.nio.file.Path tempDir = Paths.get(fmuDir);
+            if(Files.exists(tempDir) && Files.isDirectory(tempDir)) {
                 try {
-                    FileUtils.deleteAll(tempDir);
+                       FileUtils.emptyDirectory(tempDir);
                 } catch (IOException e) {
-                    throw new FMILException("Could not create temp folder for fmu");
+                    throw new FMILException("Could not delete existing files from temp folder for fmu " + path, e);
                 }
-                tempDir.mkdir();
             } else {
-                tempDir.mkdir();
+                try {
+                       Files.createDirectory(tempDir);
+                } catch (IOException e) {
+                    throw new FMILException("Could not create temp folder for fmu " + path, e);
+                }
             }
 
-
             try {
-                String tmpPath = tempDir.getAbsolutePath();
+                String tmpPath = tempDir.toString();
                 if(!tmpPath.endsWith("\\") && !tmpPath.endsWith("/"))
                     tmpPath = tmpPath + "/";
                 id = loadFMUFile_(path, tmpPath);
@@ -229,7 +237,7 @@ public class FMIL {
         }
     }
 
-    private native int loadFMUFile_(String path, String toDir);
+    private native int loadFMUFile_(String path, String toDir) throws FMILException;
 
     /**
      * Set a step length for simulation