Index: ScriptingUtils.java
===================================================================
--- ScriptingUtils.java	(revision 1083)
+++ ScriptingUtils.java	(revision 1084)
@@ -1,8 +1,3 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
 package org.gvsig.scripting.app.extension;
 
 import java.io.File;
@@ -24,10 +19,12 @@
 import java.util.List;
 import java.util.function.Predicate;
 import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.io.IOCase;
 import org.apache.commons.lang3.BooleanUtils;
+import org.gvsig.scripting.DataFolderFound;
 import org.gvsig.scripting.ScriptingBaseScript;
 import org.gvsig.scripting.ScriptingFolder;
 import org.gvsig.scripting.ScriptingLocator;
@@ -42,24 +39,30 @@
 import org.gvsig.tools.ToolsLocator;
 import org.gvsig.tools.exception.BaseException;
 import org.gvsig.tools.i18n.I18nManager;
+import org.gvsig.tools.packageutils.PackageManager;
+import org.gvsig.tools.packageutils.Version;
 import org.gvsig.tools.swing.api.ToolsSwingLocator;
 import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
+import org.gvsig.tools.swing.api.windowmanager.Dialog;
 import org.gvsig.tools.swing.api.windowmanager.WindowManager;
+import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2;
 import org.gvsig.tools.task.SimpleTaskStatus;
 import org.gvsig.tools.visitor.VisitCanceledException;
 import org.gvsig.tools.visitor.Visitor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
+import org.gvsig.tools.util.FolderSet;
+import org.gvsig.tools.util.impl.DefaultFolderSet;
 /**
  *
  * @author jjdelcerro
  */
+@SuppressWarnings("UseSpecificCatch")
 public class ScriptingUtils {
     
     public static final String SKIP_AUTORUNS = "skipAutoruns";
     
-    private static final Logger logger = LoggerFactory.getLogger(ScriptingExtension.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(ScriptingExtension.class);
 
     private boolean executingAutorunScripts = false;
     private static boolean composer_initialized = false;
@@ -84,20 +87,22 @@
     public static void log(int level, String message, Throwable th) {
         switch( level ) {
         case TRACE:
-            logger.trace(message, th);
+            LOGGER.trace(message, th);
             break;
         case ERROR:
-            logger.error(message, th);
+            LOGGER.error(message, th);
             break;
         case WARN:
-            logger.warn(message, th);
+            LOGGER.warn(message, th);
             break;
         default:
         case INFO:
-            logger.info(message, th);
+            LOGGER.info(message, th);
             break;
         }
     }
+    private String appversion;
+    private File pluginHomeFolder;
 
     public ScriptingUtils() {
         message = new MessageWait();
@@ -141,6 +146,8 @@
     
     public void initializaPaths(List<File> pluginsFolder, File installFolder, File pluginHoneFolder, String appversion) {
 
+        this.appversion = appversion;
+        this.pluginHomeFolder = pluginHoneFolder;
         ScriptingManager manager = ScriptingLocator.getManager();
         manager.setHomeFolder(getScriptsHomeFolder(pluginHoneFolder, appversion));
 
@@ -179,7 +186,7 @@
             try {
                 FileUtils.forceMkdir(localAddonRepositoryFolder);
             } catch (IOException ex) {
-                logger.info("Can't create addons folder in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
+                LOGGER.info("Can't create addons folder in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
             }
         }
         File initAddonFile = new File(localAddonRepositoryFolder, "__init__.py");
@@ -187,7 +194,7 @@
             try {
                 FileUtils.touch(initAddonFile);
             } catch (IOException ex) {
-                logger.info("Can't create addons __init__ file in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
+                LOGGER.info("Can't create addons __init__ file in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
             }
         }
     }
@@ -278,7 +285,7 @@
             status.add();
             final I18nManager i18nManager = ToolsLocator.getI18nManager();            
             try {
-                logger.info("Searching "+title+" scripts...");
+                LOGGER.info("Searching "+title+" scripts...");
                 dialogs.message(
                     i18nManager.getTranslation("_Searching_autorun_scripts_Xhorizontal_ellipsisX"),
                     JOptionPane.INFORMATION_MESSAGE
@@ -296,7 +303,7 @@
                             if( script.isEnabled() ) {
                                 scripts.add(script);
                             } else {
-                                logger.info("Skip "+title+" script '" + script.getFile().getAbsolutePath() + "'.");
+                                LOGGER.info("Skip "+title+" script '" + script.getFile().getAbsolutePath() + "'.");
                             }
                         }
                     }
@@ -318,7 +325,7 @@
                 
             } finally {
                 composer_initialized = true;
-                logger.info("Running "+title+" scripts terminated.");
+                LOGGER.info("Running "+title+" scripts terminated.");
                 dialogs.message("", JOptionPane.INFORMATION_MESSAGE);
                 status.terminate();
             }
@@ -421,7 +428,7 @@
                         status.setCurValue(n++);
                     }
                     try {
-                        logger.info("running " + title + " script '" + script.getFile().getAbsolutePath() + "' (" + getScriptOrderKey(script) + ", " + script.getIsolationGroup() + ").");
+                        LOGGER.info("running " + title + " script '" + script.getFile().getAbsolutePath() + "' (" + getScriptOrderKey(script) + ", " + script.getIsolationGroup() + ").");
                         dialogs.message(
                                 i18nManager.getTranslation(
                                         "_Running_autorun_script_from_XnameX",
@@ -436,7 +443,7 @@
                     try {
                         script.run();
                     } catch (Exception ex) {
-                        logger.warn("Can't execute " + title + " from '" + script.getFile().getAbsolutePath() + "'.", ex);
+                        LOGGER.warn("Can't execute " + title + " from '" + script.getFile().getAbsolutePath() + "'.", ex);
                     }
                 }
             }
@@ -488,7 +495,7 @@
                                 if (script.isEnabled()) {
                                     scripts.add(script);
                                 } else {
-                                    logger.info("Skip " + title + " script '" + file.getAbsolutePath() + "'.");
+                                    LOGGER.info("Skip " + title + " script '" + file.getAbsolutePath() + "'.");
                                 }
                             }
                         }
@@ -506,17 +513,59 @@
                         Files.walkFileTree(Paths.get(folder.getFile().toURI()), opts, Integer.MAX_VALUE, visitor);
                     }
                 } catch (Exception ex) {
-                    logger.warn("Can't execute " + title + " in home.", ex);
+                    LOGGER.warn("Can't execute " + title + " in home.", ex);
                 }
                 sortScripts(scripts);
                 executeScripts(scripts, null);
 
             } finally {
-                logger.info("Running " + title + " scripts terminated.");
+                LOGGER.info("Running " + title + " scripts terminated.");
                 dialogs.message("", JOptionPane.INFORMATION_MESSAGE);
                 executingAutorunScripts = false;
             }
+            checkDataFoldersVersions();
         }
 
     }
+    
+    private void checkDataFoldersVersions() {
+        final ScriptingManager manager = ScriptingLocator.getManager();
+        PackageManager versionFactory = ToolsLocator.getPackageManager();
+        Version currentVersion = versionFactory.createVersion(this.appversion);
+        FolderSet folders = new DefaultFolderSet();
+        folders.add(this.pluginHomeFolder);
+        final List<DataFolderFound> dataFoldersFound = manager.searchOldVersions(currentVersion, folders);
+        if( dataFoldersFound == null || dataFoldersFound.isEmpty() ) {
+            return;
+        }
+        Runnable askUser = new Runnable() {
+            @Override
+            public void run() {
+                WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
+                DataFoldersRecoverPanel panel = new DataFoldersRecoverPanel(dataFoldersFound);
+                Dialog dialog = winManager.createDialog(
+                        panel,
+                        "Recuperacion de preferencias",
+                        "Seleccione los complementos de los que recuperar las preferencias.",
+                        WindowManager_v2.BUTTONS_OK_CANCEL
+                );
+                dialog.show(WindowManager.MODE.DIALOG);
+                if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
+                    List<DataFolderFound> toRestore = panel.getSelectedDataFolders();
+                    for (DataFolderFound dataFolderFound : dataFoldersFound) {
+                        if (toRestore.contains(dataFolderFound)) {
+                            dataFolderFound.restore();
+                        } else {
+                            dataFolderFound.leave();
+                        }
+                    }
+                }
+            }
+        };
+        if( SwingUtilities.isEventDispatchThread() ) {
+            askUser.run();
+        } else {
+            SwingUtilities.invokeLater(askUser);
+        }
+    }
 }
