diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 0609d4d..d4c4bbe 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -272,6 +272,7 @@ Others: 更新内容: - [important] 给RAD联动提供一种批量执行的办法 #155 - [important] RAD联动支持Cookie配置 #153 +- [feat] 第一次加载RAD后支持保存路径下次直接加载 #156 - [feat] RAD联动支持一键复制RAD命令 #154 - [bug] 备份xray目录原来的config.yaml文件 #152 - [feat] RAD 联动支持拖拽功能 #151 diff --git a/src/main/java/com/chaitin/xray/form/RadForm.java b/src/main/java/com/chaitin/xray/form/RadForm.java index 1e71fd6..de010b6 100644 --- a/src/main/java/com/chaitin/xray/form/RadForm.java +++ b/src/main/java/com/chaitin/xray/form/RadForm.java @@ -1,5 +1,6 @@ package com.chaitin.xray.form; +import com.chaitin.xray.model.DB; import com.chaitin.xray.model.RadCmd; import com.chaitin.xray.utils.*; import com.intellij.uiDesigner.core.GridConstraints; @@ -257,10 +258,31 @@ private void initExport() { } public RadForm(String inputPort) { + radCmd = new RadCmd(); initLang(); initCookie(); + DB db; + try { + Path dbPath = Paths.get("super-xray.db"); + if (Files.exists(dbPath)) { + byte[] data = Files.readAllBytes(dbPath); + db = DB.parseDB(data); + } else { + db = new DB(); + db.setLastRadPath(null); + } + } catch (Exception ex) { + ex.printStackTrace(); + return; + } + if (StringUtil.notEmpty(db.getLastRadPath())) { + if (!db.getLastRadPath().equalsIgnoreCase("null")) { + radCmd.setRad(db.getLastRadPath()); + radFileText.setText(db.getLastRadPath()); + } + } DropTarget dt = new DropTarget() { @SuppressWarnings("unchecked") public synchronized void drop(DropTargetDropEvent evt) { @@ -277,6 +299,8 @@ public synchronized void drop(DropTargetDropEvent evt) { } radCmd.setRad(absPath); radFileText.setText(absPath); + db.setLastRadPath(absPath); + Files.write(Paths.get("super-xray.db"), db.getDB().getBytes()); } catch (Exception ex) { ex.printStackTrace(); } @@ -285,7 +309,6 @@ public synchronized void drop(DropTargetDropEvent evt) { radPane.setDropTarget(dt); radPanel.setDropTarget(dt); - radCmd = new RadCmd(); radCmd.setTarget("-t"); radCmd.setProxy("-http-proxy"); radCmd.setProxyInfo(String.format("127.0.0.1:%s", inputPort)); @@ -304,6 +327,12 @@ public synchronized void drop(DropTargetDropEvent evt) { radCmd.setRad(absPath); radFileText.setText(absPath); + try { + db.setLastRadPath(absPath); + Files.write(Paths.get("super-xray.db"), db.getDB().getBytes()); + } catch (Exception ex) { + ex.printStackTrace(); + } } }); diff --git a/src/main/java/com/chaitin/xray/model/DB.java b/src/main/java/com/chaitin/xray/model/DB.java index ba20bec..986e482 100644 --- a/src/main/java/com/chaitin/xray/model/DB.java +++ b/src/main/java/com/chaitin/xray/model/DB.java @@ -3,22 +3,36 @@ public class DB { private String lastXrayPath; + private String lastRadPath; + public String getLastXrayPath() { return lastXrayPath; } + public String getLastRadPath() { + return lastRadPath; + } + public void setLastXrayPath(String lastXrayPath) { this.lastXrayPath = lastXrayPath; } + public void setLastRadPath(String lastRadPath) { + this.lastRadPath = lastRadPath; + } + public String getDB() { - return String.format("%s=%s;", "last-xray-path", getLastXrayPath()); + return String.format("%s=%s;%s=%s", "last-xray-path", + getLastXrayPath(), "last-rad-path", getLastRadPath()); } public static DB parseDB(byte[] data) { DB db = new DB(); String[] temp = new String(data).split(";"); db.setLastXrayPath(temp[0].split("=")[1]); + if (temp.length > 1) { + db.setLastRadPath(temp[1].split("=")[1]); + } return db; } }