@@ -22,16 +22,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ResetAction extends AnAction implements DumbAware {
|
||||
static {
|
||||
CustomProperties.fix();
|
||||
BrokenPlugins.fix();
|
||||
BrokenPluginsListener.getInstance().listen();
|
||||
|
||||
AppEventListener.getInstance().listen();
|
||||
AppActivationListener.getInstance().listen();
|
||||
try {
|
||||
CustomProperties.fix();
|
||||
} catch (Exception e) {
|
||||
//
|
||||
}
|
||||
CustomRepository.checkAndAdd(CustomRepository.DEFAULT_HOST);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package io.zhile.research.intellij.ier.helper;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class BrokenPlugins {
|
||||
private static final Logger LOG = Logger.getInstance(BrokenPlugins.class);
|
||||
|
||||
public static void fix() {
|
||||
String content = "[]";
|
||||
String fileName = "brokenPlugins.json";
|
||||
@@ -19,12 +21,17 @@ public class BrokenPlugins {
|
||||
return;
|
||||
}
|
||||
|
||||
File tmp = null;
|
||||
try {
|
||||
Path bak = brokenPluginsPath.getParent().resolve(fileName + ".tmp");
|
||||
Files.write(bak, content.getBytes());
|
||||
Files.move(bak, brokenPluginsPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||
tmp = File.createTempFile(fileName, null);
|
||||
FileUtil.writeToFile(tmp, content);
|
||||
FileUtil.copy(tmp, brokenPluginsFile);
|
||||
} catch (IOException e) {
|
||||
NotificationHelper.showError(null, "Set broken plugins failed!");
|
||||
LOG.warn("Set broken plugins failed", e);
|
||||
} finally {
|
||||
if (null != tmp) {
|
||||
FileUtil.delete(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,8 @@
|
||||
package io.zhile.research.intellij.ier.helper;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.util.SystemProperties;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class CustomProperties {
|
||||
public static void fix() throws Exception {
|
||||
public static void fix() {
|
||||
String key = "idea.ignore.disabled.plugins";
|
||||
System.clearProperty(key);
|
||||
|
||||
List<Path> paths = new ArrayList<>();
|
||||
paths.add(Paths.get(SystemProperties.getUserHome(), PathManager.PROPERTIES_FILE_NAME));
|
||||
|
||||
String customOptionsDir = PathManager.getCustomOptionsDirectory();
|
||||
if (null != customOptionsDir) {
|
||||
paths.add(Paths.get(customOptionsDir, PathManager.PROPERTIES_FILE_NAME));
|
||||
}
|
||||
|
||||
for (Path path : paths) {
|
||||
File file = path.toFile();
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Properties props = new Properties();
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
props.load(fis);
|
||||
}
|
||||
|
||||
props.remove(key);
|
||||
|
||||
if (props.isEmpty()) {
|
||||
file.delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
props.store(fos, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user