Skip to content

Commit

Permalink
修正运行目录
Browse files Browse the repository at this point in the history
  • Loading branch information
二宁 committed Apr 27, 2023
1 parent 6dda914 commit c0b9bcf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manifest-Version: 1.0
Main-Class: cn.erning.aabinstaller.Main
Implementation-Version: 1.2.1
Implementation-Version: 1.2.2

17 changes: 17 additions & 0 deletions src/cn/erning/aabinstaller/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,21 @@ public static void delete(File file){
file.delete();
}
}

public static String getSelfPath(){
// 方法一:获取当前可执行jar包所在目录
String filePath = System.getProperty("java.class.path");
//得到当前操作系统的分隔符,windows下是";",linux下是":"
String pathSplit = System.getProperty("path.separator");
//若没有其他依赖,则filePath的结果应当是该可运行jar包的绝对路径,此时我们只需要经过字符串解析,便可得到jar所在目录
if(filePath.contains(pathSplit)){
filePath = filePath.substring(0,filePath.indexOf(pathSplit));
}else if (filePath.endsWith(".jar")) {

//截取路径中的jar包名,可执行jar包运行的结果里包含".jar"
filePath = filePath.substring(0, filePath.lastIndexOf(File.separator) + 1);
}
System.out.println("jar包所在目录:"+filePath);
return filePath;
}
}
6 changes: 4 additions & 2 deletions src/cn/erning/aabinstaller/util/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ private static Device[] parsingDevices(String content){
private static String getAdbPath(){
String adbPath;
if(System.getProperties().getProperty("os.name").toLowerCase().startsWith("windows")){
adbPath = new File("").getAbsolutePath()+"\\adb.exe";
adbPath = new File(FileUtil.getSelfPath()).getAbsolutePath()+"\\adb.exe";
}else{
adbPath = new File("").getAbsolutePath()+"/adb";
adbPath = new File(FileUtil.getSelfPath()).getAbsolutePath()+"/adb";
}
boolean hasAdb = new File(adbPath).exists();
System.out.println("ADB文件路径:"+adbPath);
Expand All @@ -338,4 +338,6 @@ private static String getAdbPath(){
}
return hasAdb ? adbPath : null;
}


}

0 comments on commit c0b9bcf

Please sign in to comment.