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 Jan 21, 2023
1 parent 0523e15 commit 48450f0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,5 @@ Others:
## 1.5

更新内容:
- [important] [feat] 支持拖拽xray文件加载 #140
- [bug] CPU占用较高问题RAD修复不完善 #139
35 changes: 35 additions & 0 deletions src/main/java/com/chaitin/xray/form/MainForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
import javax.swing.plaf.FontUIResource;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.*;
Expand Down Expand Up @@ -182,10 +186,41 @@ public class MainForm {
private SubdomainForm subdomainInstance;
private AJPScanForm ajpInstance;

@SuppressWarnings("unchecked")
public void init() {
checkBoxList = new ArrayList<>();
xrayCmd = new XrayCmd();

DropTarget dt = new DropTarget() {
public synchronized void drop(DropTargetDropEvent evt) {
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
Object obj = evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
List<File> droppedFiles = (List<File>) obj;
if (droppedFiles.size() != 1) {
return;
}
String absPath = droppedFiles.get(0).getAbsolutePath();
if (!CheckUtil.checkValid(absPath)) {
return;
}
new Thread(() -> loadXray(absPath)).start();
JOptionPane.showMessageDialog(SuperXray, "Loading...");
DB data = new DB();
data.setLastXrayPath(absPath);
try {
Files.write(Paths.get("super-xray.db"), data.getDB().getBytes());
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
};

SuperXray.setDropTarget(dt);

try {
Path dbPath = Paths.get("super-xray.db");
if (Files.exists(dbPath)) {
Expand Down
24 changes: 1 addition & 23 deletions src/main/java/com/chaitin/xray/model/DB.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.chaitin.xray.model;

import java.nio.file.Files;
import java.nio.file.Paths;

public class DB {
private String lastXrayPath;
private String skin;

public String getLastXrayPath() {
return lastXrayPath;
Expand All @@ -15,32 +11,14 @@ public void setLastXrayPath(String lastXrayPath) {
this.lastXrayPath = lastXrayPath;
}

public String getSkin() {
return skin;
}

public void setSkin(String skin) {
this.skin = skin;
}

public String getDB() {
return String.format("%s=%s;%s=%s", "last-xray-path",
getLastXrayPath(), "skin", getSkin());
return String.format("%s=%s;", "last-xray-path", getLastXrayPath());
}

public static DB parseDB(byte[] data) {
DB db = new DB();
String[] temp = new String(data).split(";");
db.setSkin(temp[1].split("=")[1]);
db.setLastXrayPath(temp[0].split("=")[1]);
return db;
}

public void saveDB() {
try {
Files.write(Paths.get("super-xray.db"), getDB().getBytes());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

0 comments on commit 48450f0

Please sign in to comment.