Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Mar 13, 2023
1 parent 6e1a08e commit 97bab6d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/com/chaitin/xray/form/RadForm.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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));
Expand All @@ -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();
}
}
});

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/chaitin/xray/model/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 97bab6d

Please sign in to comment.