1. PM3 flasher gui add. (on tools)

2. dump merge bug fixed.
This commit is contained in:
dxl
2020-05-22 15:10:09 +08:00
parent de462133cc
commit b29c6d77a3
14 changed files with 690 additions and 95 deletions
@@ -34,7 +34,6 @@ import java.text.DecimalFormat;
import java.util.ArrayList;
import cn.dxl.common.R;
import cn.dxl.common.util.IOUtils;
/*
* 一系列文件操作的封装!
@@ -202,6 +201,10 @@ public class FileUtils {
return mime;
}
public static boolean isFile(String file) {
return new File(file).isFile();
}
//删除文件夹目录下所有的文件
public static boolean delete(File dir) {
if (dir.isDirectory()) {
@@ -222,6 +225,83 @@ public class FileUtils {
}
}
public static boolean move(File file, File path) {
String pathStr = path.getAbsolutePath();
pathStr = pathStr.endsWith(File.separator) ? pathStr : pathStr + File.separator;
String targetFile = pathStr + file.getName();
File tmp = new File(targetFile);
createFile(tmp);
if (tmp.exists() && tmp.isFile()) {
// 开始写入!
return file.renameTo(new File(targetFile));
}
return true;
}
public static boolean copy(Uri source, File target) {
return copy(source, Uri.fromFile(target));
}
public static boolean copy(Uri source, Uri target) {
try {
byte[] data = readBytes(source);
writeBytes(data, target);
return true;
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
public static boolean copy(File source, File target) {
if (target == null || source == null) return false;
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
File parentFile = target.getParentFile();
if (parentFile != null) {
createPaths(parentFile);
}
createFile(target);
inputChannel = new FileInputStream(source).getChannel();
outputChannel = new FileOutputStream(target).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.close(inputChannel);
IOUtils.close(outputChannel);
}
return true;
}
public static boolean copy(FileDescriptor descriptor, FileDescriptor target) {
if (target == null || descriptor == null) return false;
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
inputChannel = new FileInputStream(descriptor).getChannel();
outputChannel = new FileOutputStream(target).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.close(inputChannel);
IOUtils.close(outputChannel);
}
return true;
}
public static boolean copy(byte[] rawData, File target) {
try {
writeBytes(rawData, target, false);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
// 調用系統方法分享文件
public static void shareFile(File file) {
LogUtils.d("shareFile path: " + (file != null ? file.toString() : null));
@@ -513,12 +593,10 @@ public class FileUtils {
return ret;
}
//判断文件名是否有效!
public static boolean isValidFileName(String name) {
return !StringUtil.isEmpty(name) && !name.contains("/");
}
//获得so库的地址!
public static String getNativePath() {
String ss = context.getApplicationInfo().nativeLibraryDir;
if (ss == null)
@@ -526,64 +604,6 @@ public class FileUtils {
return ss;
}
public static boolean moveFile(File file, File path) {
String pathStr = path.getAbsolutePath();
pathStr = pathStr.endsWith(File.separator) ? pathStr : pathStr + File.separator;
String targetFile = pathStr + file.getName();
File tmp = new File(targetFile);
createFile(tmp);
if (tmp.exists() && tmp.isFile()) {
// 开始写入!
return file.renameTo(new File(targetFile));
}
return true;
}
public static boolean copy(File source, File target) throws IOException {
if (target == null || source == null) return false;
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
File parentFile = target.getParentFile();
if (parentFile != null) {
createPaths(parentFile);
}
createFile(target);
inputChannel = new FileInputStream(source).getChannel();
outputChannel = new FileOutputStream(target).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
IOUtils.close(inputChannel);
IOUtils.close(outputChannel);
}
return true;
}
public static boolean copy(FileDescriptor descriptor, FileDescriptor target) throws IOException {
if (target == null || descriptor == null) return false;
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
inputChannel = new FileInputStream(descriptor).getChannel();
outputChannel = new FileOutputStream(target).getChannel();
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
} finally {
IOUtils.close(inputChannel);
IOUtils.close(outputChannel);
}
return true;
}
public static boolean copy(byte[] rawData, File target) {
try {
writeBytes(rawData, target, false);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static String getFileCountIfFolder(File[] files) {
if (files == null) files = new File[0];
return files.length + " " + context.getString(R.string.item);