Signed-off-by: pengzhile <pengzhile@gmail.com>
This commit is contained in:
pengzhile
2021-01-19 18:54:43 +08:00
parent d064971423
commit dee34a27f9
4 changed files with 56 additions and 6 deletions
@@ -12,10 +12,7 @@ import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowEP;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
import io.zhile.research.intellij.ier.helper.Constants;
import io.zhile.research.intellij.ier.helper.CustomRepository;
import io.zhile.research.intellij.ier.helper.NotificationHelper;
import io.zhile.research.intellij.ier.helper.PluginHelper;
import io.zhile.research.intellij.ier.helper.*;
import io.zhile.research.intellij.ier.listener.AppActivationListener;
import io.zhile.research.intellij.ier.listener.AppEventListener;
import io.zhile.research.intellij.ier.tw.MainToolWindowFactory;
@@ -26,6 +23,11 @@ public class ResetAction extends AnAction implements DumbAware {
static {
AppEventListener.getInstance().listen();
AppActivationListener.getInstance().listen();
try {
CustomProperties.checkAndUpdate();
} catch (Exception e) {
NotificationHelper.showError(null, "Set broken plugins failed!");
}
CustomRepository.checkAndAdd(CustomRepository.DEFAULT_HOST);
}
@@ -0,0 +1,46 @@
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 checkAndUpdate() throws Exception {
String key = "idea.ignore.disabled.plugins", value = "true";
System.setProperty(key, value);
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()) {
new FileOutputStream(file).close();
}
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(file)) {
props.load(fis);
}
props.setProperty(key, value);
try (FileOutputStream fos = new FileOutputStream(file)) {
props.store(fos, null);
}
}
}
}