private static boolean validateOldConfigDir( @Nullable File installationHome, @Nullable File oldConfigDir, @NotNull ConfigImportSettings settings) { if (oldConfigDir == null) { if (installationHome != null) { JOptionPane.showMessageDialog( JOptionPane.getRootFrame(), ApplicationBundle.message( "error.invalid.installation.home", installationHome.getAbsolutePath(), settings.getProductName(ThreeState.YES))); } return false; } if (!oldConfigDir.exists()) { JOptionPane.showMessageDialog( JOptionPane.getRootFrame(), ApplicationBundle.message("error.no.settings.path", oldConfigDir.getAbsolutePath()), ApplicationBundle.message("title.settings.import.failed"), JOptionPane.WARNING_MESSAGE); return false; } return true; }
private static void doImport( @NotNull File newConfigDir, @NotNull File oldConfigDir, ConfigImportSettings settings, File installationHome) { try { copy(oldConfigDir, newConfigDir, settings, installationHome); } catch (IOException e) { JOptionPane.showMessageDialog( JOptionPane.getRootFrame(), ApplicationBundle.message("error.unable.to.import.settings", e.getMessage()), ApplicationBundle.message("title.settings.import.failed"), JOptionPane.WARNING_MESSAGE); } }
private static void copy( @NotNull File src, @NotNull File dest, ConfigImportSettings settings, File oldInstallationHome) throws IOException { src = src.getCanonicalFile(); dest = dest.getCanonicalFile(); if (!src.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", src.getAbsolutePath())); } if (!dest.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", dest.getAbsolutePath())); } if (FileUtil.filesEqual(src, dest)) { return; } FileUtil.ensureExists(dest); File[] childFiles = src.listFiles( new FilenameFilter() { @Override public boolean accept(@NotNull File dir, @NotNull String name) { // Don't copy plugins just imported. They're most probably incompatible with newer // idea version. return !StringUtil.startsWithChar(name, '.') && !name.equals(PLUGINS_PATH); } }); if (childFiles == null || childFiles.length == 0) { return; } for (File from : childFiles) { File to = new File(dest, from.getName()); if (from.isDirectory()) { FileUtil.copyDir(from, to, false); } else { FileUtil.copy(from, to); } } File plugins = new File(src, PLUGINS_PATH); if (!loadOldPlugins(plugins, dest) && SystemInfo.isMac) { File oldPluginsDir = getOldPath( oldInstallationHome, settings, PathManager.PROPERTY_PLUGINS_PATH, new Function<String, String>() { @Override public String fun(String pathSelector) { return PathManager.getDefaultPluginPathFor(pathSelector); } }); if (oldPluginsDir == null) { // e.g. installation home referred to config home. Try with default selector, same as config // name oldPluginsDir = new File(PathManager.getDefaultPluginPathFor(src.getName())); } loadOldPlugins(oldPluginsDir, dest); } }