Compare commits
No commits in common. "fa7c35503e2d107e558626e68a820711727d8f0c" and "89e79bdaff74c2c1a8032da85fb995a4fdc6785e" have entirely different histories.
fa7c35503e
...
89e79bdaff
|
|
@ -4,10 +4,10 @@
|
||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2026-03-11T06:38:33.168759600Z">
|
<DropdownSelection timestamp="2026-03-10T06:53:45.140671700Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=Y5DELZR46DZTCI9D" />
|
<DeviceId pluginId="PhysicalDevice" identifier="serial=d927cac5" />
|
||||||
</handle>
|
</handle>
|
||||||
</Target>
|
</Target>
|
||||||
</DropdownSelection>
|
</DropdownSelection>
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ android {
|
||||||
applicationId = "com.img.rabbit"
|
applicationId = "com.img.rabbit"
|
||||||
minSdk = 24
|
minSdk = 24
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 1
|
versionCode = 3
|
||||||
versionName = "1.0.0"
|
versionName = "1.0.3"
|
||||||
multiDexEnabled = true
|
multiDexEnabled = true
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ class MainActivity : ComponentActivity(), LoadingCallback {
|
||||||
UpdateUtils.download(
|
UpdateUtils.download(
|
||||||
scope = coroutineScope,
|
scope = coroutineScope,
|
||||||
url = url,
|
url = url,
|
||||||
filePath = FileUtils.instance?.cacheDownLoadDir?.absolutePath?:"",
|
filePath = FileUtils.getInstance().cacheDownLoadDir.absolutePath,
|
||||||
fileName = AppUpdate.getFileNameFromUrl(url),
|
fileName = AppUpdate.getFileNameFromUrl(url),
|
||||||
onProgress = {progress->
|
onProgress = {progress->
|
||||||
progressState.floatValue = progress.toFloat()/100f
|
progressState.floatValue = progress.toFloat()/100f
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,337 @@
|
||||||
|
package com.img.rabbit.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.os.StatFs;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.img.rabbit.provider.utils.HeadParamUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@SuppressWarnings({"ResultOfMethodCallIgnored", "CallToPrintStackTrace"})
|
||||||
|
public class FileUtils {
|
||||||
|
|
||||||
|
private static FileUtils instance;
|
||||||
|
private static String packageName = "dev";
|
||||||
|
|
||||||
|
// 文件缓存路径
|
||||||
|
private String CACHE_DIR;
|
||||||
|
|
||||||
|
// 下载目录
|
||||||
|
private File downloadDir;
|
||||||
|
// 缓存目录
|
||||||
|
private File cacheDir;
|
||||||
|
// 图片缓存目录
|
||||||
|
private File cacheImageDir;
|
||||||
|
|
||||||
|
private File cacheOriginalImageDir;
|
||||||
|
|
||||||
|
private File cacheEditImageDir;
|
||||||
|
|
||||||
|
private File cachePuzzleImageDir;
|
||||||
|
// 下载Uni小程序WGTD文件存放目录
|
||||||
|
private File uniWGTDir;
|
||||||
|
|
||||||
|
public static FileUtils getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized (FileUtils.class) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new FileUtils(Objects.requireNonNull(HeadParamUtils.INSTANCE.getApplicationContext()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileUtils(Context context) {
|
||||||
|
CACHE_DIR = Objects.requireNonNull(context.getExternalFilesDir(null)).getAbsolutePath() + File.separator + packageName + File.separator;
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
cacheDir = new File(CACHE_DIR, "/cache");
|
||||||
|
} else {
|
||||||
|
cacheDir = context.getCacheDir();
|
||||||
|
}
|
||||||
|
if (!cacheDir.exists())
|
||||||
|
cacheDir.mkdirs();
|
||||||
|
cacheImageDir = new File(cacheDir, "/image/");
|
||||||
|
if (!cacheImageDir.exists())
|
||||||
|
cacheImageDir.mkdirs();
|
||||||
|
|
||||||
|
cacheOriginalImageDir = new File(cacheDir, "/originalImage/");
|
||||||
|
if (!cacheOriginalImageDir.exists())
|
||||||
|
cacheOriginalImageDir.mkdirs();
|
||||||
|
|
||||||
|
cacheEditImageDir = new File(cacheDir, "/cacheEditImage/");
|
||||||
|
if (!cacheEditImageDir.exists())
|
||||||
|
cacheEditImageDir.mkdirs();
|
||||||
|
|
||||||
|
cachePuzzleImageDir = new File(cacheDir, "/cachePuzzleImage/");
|
||||||
|
if (!cachePuzzleImageDir.exists())
|
||||||
|
cachePuzzleImageDir.mkdirs();
|
||||||
|
|
||||||
|
downloadDir = new File(cacheDir, "/download/");
|
||||||
|
if (!downloadDir.exists())
|
||||||
|
downloadDir.mkdirs();
|
||||||
|
|
||||||
|
uniWGTDir = new File(cacheDir, "/uniApp/");
|
||||||
|
if (!uniWGTDir.exists())
|
||||||
|
uniWGTDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCACHE_DIR() {
|
||||||
|
return CACHE_DIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存目录
|
||||||
|
*/
|
||||||
|
public File getCacheDir() {
|
||||||
|
return cacheDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下载目录
|
||||||
|
*/
|
||||||
|
public File getCacheDownLoadDir() {
|
||||||
|
return downloadDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取UniApp目录
|
||||||
|
*/
|
||||||
|
public File getCacheUniAppDir() {
|
||||||
|
return uniWGTDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存图片目录
|
||||||
|
*/
|
||||||
|
public File getCacheImageDir() {
|
||||||
|
return cacheImageDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 水印照片编辑后的路径
|
||||||
|
*/
|
||||||
|
public File getCacheEditImageDir() {
|
||||||
|
return cacheEditImageDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getCacheOriginalImageDir() {
|
||||||
|
return cacheOriginalImageDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拼图路径
|
||||||
|
*/
|
||||||
|
public File getCachePuzzleImageDir() {
|
||||||
|
return cachePuzzleImageDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个临时图片文件
|
||||||
|
*/
|
||||||
|
public File newTempImageFile() {
|
||||||
|
return new File(cacheImageDir, System.currentTimeMillis() + ".jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否安装SD卡
|
||||||
|
*/
|
||||||
|
public static boolean checkSaveLocationExists() {
|
||||||
|
String sDCardStatus = Environment.getExternalStorageState();
|
||||||
|
boolean status;
|
||||||
|
status = sDCardStatus.equals(Environment.MEDIA_MOUNTED);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除指定目录下文件及目录
|
||||||
|
*/
|
||||||
|
public static void deleteFolderFile(String filePath) {
|
||||||
|
if (!TextUtils.isEmpty(filePath)) {
|
||||||
|
try {
|
||||||
|
File file = new File(filePath);
|
||||||
|
if (file.isDirectory()) {// 处理目录
|
||||||
|
File[] files = file.listFiles();
|
||||||
|
for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
|
||||||
|
deleteFolderFile(files[i].getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!file.isDirectory()) {// 如果是文件,删除
|
||||||
|
file.delete();
|
||||||
|
} else {// 目录
|
||||||
|
if (Objects.requireNonNull(file.listFiles()).length == 0) {// 目录下没有文件或者目录,删除
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("FileUtils", Objects.requireNonNull(e.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文件
|
||||||
|
*/
|
||||||
|
public boolean deleteFile(String path) {
|
||||||
|
boolean status;
|
||||||
|
SecurityManager checker = new SecurityManager();
|
||||||
|
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
File newPath = new File(path);
|
||||||
|
checker.checkDelete(newPath.toString());
|
||||||
|
if (newPath.isFile()) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
newPath.delete();
|
||||||
|
status = true;
|
||||||
|
} catch (SecurityException se) {
|
||||||
|
Log.e("FileUtils", Objects.requireNonNull(se.getMessage()));
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
status = false;
|
||||||
|
} else
|
||||||
|
status = false;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取目录文件大小
|
||||||
|
*/
|
||||||
|
public static long getDirSize(File dir) {
|
||||||
|
if (dir == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!dir.isDirectory()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long dirSize = 0;
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
for (File file : Objects.requireNonNull(files)) {
|
||||||
|
if (file.isFile()) {
|
||||||
|
dirSize += file.length();
|
||||||
|
} else if (file.isDirectory()) {
|
||||||
|
dirSize += file.length();
|
||||||
|
dirSize += getDirSize(file); // 递归调用继续统计
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dirSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定文件大小
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public static long getFileSize(File file) throws Exception {
|
||||||
|
long size = 0;
|
||||||
|
if (file.exists()) {
|
||||||
|
FileInputStream fis = null;
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
size = fis.available();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Log.e("获取文件大小", "文件不存在!");
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定文件夹
|
||||||
|
*/
|
||||||
|
public static long getFileSizes(File f) throws Exception {
|
||||||
|
long size = 0;
|
||||||
|
File[] flist = f.listFiles();
|
||||||
|
for (int i = 0; i < Objects.requireNonNull(flist).length; i++) {
|
||||||
|
if (flist[i].isDirectory()) {
|
||||||
|
size = size + getFileSizes(flist[i]);
|
||||||
|
} else {
|
||||||
|
size = size + getFileSize(flist[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换文件大小
|
||||||
|
*/
|
||||||
|
public static String toFileSize(long fileS) {
|
||||||
|
DecimalFormat df = new DecimalFormat("#.00");
|
||||||
|
String fileSizeString;
|
||||||
|
String wrongSize = "0M";
|
||||||
|
if (fileS == 0) {
|
||||||
|
return wrongSize;
|
||||||
|
}
|
||||||
|
if (fileS < 1024) {
|
||||||
|
fileSizeString = df.format((double) fileS) + "B";
|
||||||
|
} else if (fileS < 1048576) {
|
||||||
|
fileSizeString = df.format((double) fileS / 1024) + "K";
|
||||||
|
} else if (fileS < 1073741824) {
|
||||||
|
fileSizeString = df.format((double) fileS / 1048576) + "M";
|
||||||
|
} else {
|
||||||
|
fileSizeString = df.format((double) fileS / 1073741824) + "G";
|
||||||
|
}
|
||||||
|
return fileSizeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断文件是否存在
|
||||||
|
public boolean fileIsExists(File strFile) {
|
||||||
|
try {
|
||||||
|
if (!strFile.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//判断文件是否存在
|
||||||
|
public boolean fileIsExists(String strFile) {
|
||||||
|
try {
|
||||||
|
File f = new File(strFile);
|
||||||
|
if (!f.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//外部存储空间
|
||||||
|
public static long getExternalStorageSpace() {
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
StatFs externalStatFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||||
|
long externalBlockSize = externalStatFs.getBlockSizeLong();
|
||||||
|
long externalTotalSize = externalStatFs.getBlockCountLong() * externalBlockSize;
|
||||||
|
long externalAvailableSize = externalStatFs.getAvailableBlocksLong() * externalBlockSize;
|
||||||
|
Log.d("FileUtils", "当前外部空间总大小----" + externalTotalSize);
|
||||||
|
Log.d("FileUtils", "当前外部空间可用大小----" + externalAvailableSize);
|
||||||
|
return externalAvailableSize;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开图库
|
||||||
|
*/
|
||||||
|
public void openGallery(Context context) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.addCategory(Intent.CATEGORY_APP_GALLERY);
|
||||||
|
context.startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,239 +0,0 @@
|
||||||
package com.img.rabbit.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Environment
|
|
||||||
import android.os.StatFs
|
|
||||||
import android.util.Log
|
|
||||||
import com.img.rabbit.provider.utils.HeadParamUtils.applicationContext
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.text.DecimalFormat
|
|
||||||
import java.util.Objects
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件工具类
|
|
||||||
* 注意:处理路径(android/data/xxx.xxx.xxx/files/cache/)
|
|
||||||
*/
|
|
||||||
class FileUtils private constructor(context: Context) {
|
|
||||||
// 文件缓存路径(android/data/xxx.xxx.xxx/files/)
|
|
||||||
var cacheParentDir: String?
|
|
||||||
private set
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存目录(/cache/)
|
|
||||||
*/
|
|
||||||
private var cacheDir: File? = null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载目录(/cache/download/)
|
|
||||||
*/
|
|
||||||
var cacheDownLoadDir: File
|
|
||||||
private set
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存图片目录(/cache/image/)
|
|
||||||
*/
|
|
||||||
var cacheImageDir: File
|
|
||||||
private set
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取UniApp目录
|
|
||||||
* 下载Uni小程序wgt文件存放目录(/cache/uniApp/)
|
|
||||||
*/
|
|
||||||
var cacheUniAppDir: File
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
|
||||||
this.cacheParentDir = context.getExternalFilesDir(null)?.absolutePath + File.separator
|
|
||||||
cacheDir = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
|
||||||
File(this.cacheParentDir, "/cache")
|
|
||||||
} else {
|
|
||||||
context.cacheDir
|
|
||||||
}
|
|
||||||
if (cacheDir?.exists() != true) cacheDir?.mkdirs()
|
|
||||||
|
|
||||||
cacheImageDir = File(cacheDir, "/image/")
|
|
||||||
if (!cacheImageDir.exists()) cacheImageDir.mkdirs()
|
|
||||||
|
|
||||||
this.cacheDownLoadDir = File(cacheDir, "/download/")
|
|
||||||
if (!cacheDownLoadDir.exists()) cacheDownLoadDir.mkdirs()
|
|
||||||
|
|
||||||
this.cacheUniAppDir = File(cacheDir, "/uniApp/")
|
|
||||||
if (!cacheUniAppDir.exists()) cacheUniAppDir.mkdirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取缓存目录(android/data/xxx.xxx.xxx/files/cache/)
|
|
||||||
*/
|
|
||||||
fun getCacheDir(): File {
|
|
||||||
cacheDir = if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
|
||||||
File(this.cacheParentDir, "/cache")
|
|
||||||
} else {
|
|
||||||
applicationContext?.cacheDir
|
|
||||||
}
|
|
||||||
return cacheDir!!
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建一个临时图片文件((android/data/xxx.xxx.xxx/files/cache/image/系统当前时间.jpg)
|
|
||||||
*/
|
|
||||||
fun newTempImageFile(): File {
|
|
||||||
return File(cacheImageDir, System.currentTimeMillis().toString() + ".jpg")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除文件
|
|
||||||
*/
|
|
||||||
fun deleteFile(path: String): Boolean = File(path).takeIf { it.isFile }?.delete() ?: false
|
|
||||||
|
|
||||||
|
|
||||||
fun fileIsExists(file: File): Boolean = file.exists()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打开图库
|
|
||||||
*/
|
|
||||||
fun openGallery(context: Context) {
|
|
||||||
try {
|
|
||||||
val intent = Intent(Intent.ACTION_MAIN)
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
intent.addCategory(Intent.CATEGORY_APP_GALLERY)
|
|
||||||
context.startActivity(intent)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
var instance: FileUtils? = null
|
|
||||||
get() {
|
|
||||||
if (field == null) {
|
|
||||||
synchronized(FileUtils::class.java) {
|
|
||||||
if (field == null) {
|
|
||||||
field = applicationContext?.let { FileUtils(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return field
|
|
||||||
}
|
|
||||||
private set
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否安装SD卡
|
|
||||||
*/
|
|
||||||
fun checkSaveLocationExists(): Boolean {
|
|
||||||
val sDCardStatus = Environment.getExternalStorageState()
|
|
||||||
val status = sDCardStatus == Environment.MEDIA_MOUNTED
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除指定目录下文件及目录
|
|
||||||
*/
|
|
||||||
fun deleteFolderFile(filePath: String?) {
|
|
||||||
filePath?.let { File(filePath).deleteRecursively() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取目录文件大小
|
|
||||||
*/
|
|
||||||
fun getDirSize(dir: File?): Long {
|
|
||||||
if (dir == null) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
if (!dir.isDirectory()) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
var dirSize: Long = 0
|
|
||||||
val files = dir.listFiles()
|
|
||||||
for (file in Objects.requireNonNull(files)) {
|
|
||||||
if (file.isFile()) {
|
|
||||||
dirSize += file.length()
|
|
||||||
} else if (file.isDirectory()) {
|
|
||||||
dirSize += file.length()
|
|
||||||
dirSize += getDirSize(file) // 递归调用继续统计
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dirSize
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定文件大小
|
|
||||||
*/
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun getFileSize(file: File): Long {
|
|
||||||
var size: Long = 0
|
|
||||||
if (file.exists()) {
|
|
||||||
var fis: FileInputStream? = null
|
|
||||||
fis = FileInputStream(file)
|
|
||||||
size = fis.available().toLong()
|
|
||||||
} else {
|
|
||||||
Log.e("获取文件大小", "文件不存在!")
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定文件夹
|
|
||||||
*/
|
|
||||||
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
|
||||||
@Throws(Exception::class)
|
|
||||||
fun getFileSizes(f: File): Long {
|
|
||||||
var size: Long = 0
|
|
||||||
val fileList = f.listFiles()
|
|
||||||
for (i in Objects.requireNonNull(fileList).indices) {
|
|
||||||
size += if (fileList[i].isDirectory()) {
|
|
||||||
getFileSizes(fileList[i])
|
|
||||||
} else {
|
|
||||||
getFileSize(fileList[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return size
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换文件大小
|
|
||||||
*/
|
|
||||||
fun toFileSize(fileS: Long): String {
|
|
||||||
val df = DecimalFormat("#.00")
|
|
||||||
val fileSizeString: String
|
|
||||||
val wrongSize = "0M"
|
|
||||||
if (fileS == 0L) {
|
|
||||||
return wrongSize
|
|
||||||
}
|
|
||||||
if (fileS < 1024) {
|
|
||||||
fileSizeString = df.format(fileS.toDouble()) + "B"
|
|
||||||
} else if (fileS < 1048576) {
|
|
||||||
fileSizeString = df.format(fileS.toDouble() / 1024) + "K"
|
|
||||||
} else if (fileS < 1073741824) {
|
|
||||||
fileSizeString = df.format(fileS.toDouble() / 1048576) + "M"
|
|
||||||
} else {
|
|
||||||
fileSizeString = df.format(fileS.toDouble() / 1073741824) + "G"
|
|
||||||
}
|
|
||||||
return fileSizeString
|
|
||||||
}
|
|
||||||
|
|
||||||
val externalStorageSpace: Long
|
|
||||||
//外部存储空间
|
|
||||||
get() {
|
|
||||||
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
|
||||||
val externalStatFs = StatFs(
|
|
||||||
Environment.getExternalStorageDirectory().absolutePath
|
|
||||||
)
|
|
||||||
val externalBlockSize = externalStatFs.blockSizeLong
|
|
||||||
val externalTotalSize =
|
|
||||||
externalStatFs.blockCountLong * externalBlockSize
|
|
||||||
val externalAvailableSize =
|
|
||||||
externalStatFs.availableBlocksLong * externalBlockSize
|
|
||||||
Log.d("FileUtils", "当前外部空间总大小----$externalTotalSize")
|
|
||||||
Log.d(
|
|
||||||
"FileUtils",
|
|
||||||
"当前外部空间可用大小----$externalAvailableSize"
|
|
||||||
)
|
|
||||||
return externalAvailableSize
|
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -34,15 +34,13 @@ import okhttp3.Request
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.jvm.java
|
import kotlin.jvm.java
|
||||||
|
|
||||||
/**
|
|
||||||
* UniApp工具类
|
|
||||||
* 小程序运行路径:/data/user/0/com.img.rabbit/files/apps/(一般/data/data/com.img.rabbit/files/apps/)
|
|
||||||
*/
|
|
||||||
object UniAppUtils {
|
object UniAppUtils {
|
||||||
private const val TAG = "UniAppUtils"
|
private const val TAG = "UniAppUtils"
|
||||||
/**
|
/**
|
||||||
* 所有运行的UniMp小程序实体
|
* 所有运行的UniMp小程序实体
|
||||||
*/
|
*/
|
||||||
|
// val uniMpPair = mutableMapOf<String?, IUniMP?>()
|
||||||
private val _uniMpFlow = MutableStateFlow<Map<String?, IUniMP?>>(emptyMap())
|
private val _uniMpFlow = MutableStateFlow<Map<String?, IUniMP?>>(emptyMap())
|
||||||
val uniMpFlow = _uniMpFlow.asStateFlow()
|
val uniMpFlow = _uniMpFlow.asStateFlow()
|
||||||
fun updateUniMp(id: String?, mp: IUniMP?) {
|
fun updateUniMp(id: String?, mp: IUniMP?) {
|
||||||
|
|
@ -62,11 +60,6 @@ object UniAppUtils {
|
||||||
return String.format("%s.wgt", uniMpId)
|
return String.format("%s.wgt", uniMpId)
|
||||||
//return String.format("%s.zip", uniMpId)
|
//return String.format("%s.zip", uniMpId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getWgtFile(uniMpId: String): File{
|
|
||||||
val wgtName = getWgtName(uniMpId)
|
|
||||||
return File(FileUtils.instance?.cacheUniAppDir?.absolutePath?:"", wgtName)
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
*获取当前前台运行的UniMp小程序实体
|
*获取当前前台运行的UniMp小程序实体
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,14 +85,16 @@ object UniAppUtils {
|
||||||
* 是否需要下载(强制更新或者不存在wgt文件)
|
* 是否需要下载(强制更新或者不存在wgt文件)
|
||||||
*/
|
*/
|
||||||
fun isDownloadUniMp(uniVersion: UniVersionEntity): Boolean{
|
fun isDownloadUniMp(uniVersion: UniVersionEntity): Boolean{
|
||||||
val wgtFile = getWgtFile(uniVersion.unimp_id)
|
val wgtName = getWgtName(uniVersion.unimp_id)
|
||||||
return isUpdateForce(uniVersion) || !(FileUtils.instance?.fileIsExists(wgtFile) == true && FileUtils.getFileSize(wgtFile) > 0)
|
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
||||||
|
return isUpdateForce(uniVersion) || !(FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun wgtIsExists(uniMpId: String): Boolean{
|
fun wgtIsExists(uniMpId: String): Boolean{
|
||||||
val wgtFile = getWgtFile(uniMpId)
|
val wgtName = getWgtName(uniMpId)
|
||||||
|
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
||||||
//判断wgt是否下载
|
//判断wgt是否下载
|
||||||
return FileUtils.instance?.fileIsExists(wgtFile) == true && FileUtils.getFileSize(wgtFile) > 0
|
return FileUtils.getInstance().fileIsExists(wgtFile) && FileUtils.getFileSize(wgtFile) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isRelease(uniMpId: String): Boolean{
|
private fun isRelease(uniMpId: String): Boolean{
|
||||||
|
|
@ -220,7 +215,8 @@ object UniAppUtils {
|
||||||
val appBasePath = DCUniMPSDK.getInstance().getAppBasePath(applicationContext)
|
val appBasePath = DCUniMPSDK.getInstance().getAppBasePath(applicationContext)
|
||||||
val deleteSuccess = File(appBasePath, uniMpId).deleteRecursively()
|
val deleteSuccess = File(appBasePath, uniMpId).deleteRecursively()
|
||||||
if(deleteSuccess){
|
if(deleteSuccess){
|
||||||
val wgtFile = getWgtFile(uniMpId)
|
val wgtName = getWgtName(uniMpId)
|
||||||
|
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
||||||
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
val uniMPReleaseConfiguration = UniMPReleaseConfiguration().apply {
|
||||||
wgtPath = wgtFile.path
|
wgtPath = wgtFile.path
|
||||||
password = PreferenceUtil.getUserConfig()?.config?.wgtPassword//"6462"////没有密码可以不写
|
password = PreferenceUtil.getUserConfig()?.config?.wgtPassword//"6462"////没有密码可以不写
|
||||||
|
|
@ -255,7 +251,9 @@ object UniAppUtils {
|
||||||
* 下载wgt文件
|
* 下载wgt文件
|
||||||
*/
|
*/
|
||||||
fun downloadWGT(context: Context,scope: CoroutineScope, uniVersion: UniVersionEntity, reportViewModel: ReportViewModel = ReportViewModel(), onProgress:(state: UniMpUpdate, filePath: String?, progress: Float?) -> Unit) {
|
fun downloadWGT(context: Context,scope: CoroutineScope, uniVersion: UniVersionEntity, reportViewModel: ReportViewModel = ReportViewModel(), onProgress:(state: UniMpUpdate, filePath: String?, progress: Float?) -> Unit) {
|
||||||
val wgtFile = getWgtFile(uniVersion.unimp_id)
|
val uniMpId = uniVersion.unimp_id
|
||||||
|
val wgtName = getWgtName(uniMpId)
|
||||||
|
val wgtFile = File(FileUtils.getInstance().cacheUniAppDir.absolutePath, wgtName)
|
||||||
onProgress(UniMpUpdate.DOWNLOAD_START, wgtFile.path, 0f)
|
onProgress(UniMpUpdate.DOWNLOAD_START, wgtFile.path, 0f)
|
||||||
|
|
||||||
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
downloadUniMp(scope, uniVersion){uniState, filePath, progress ->
|
||||||
|
|
@ -306,7 +304,7 @@ object UniAppUtils {
|
||||||
|
|
||||||
val uniMpId = uniVersion.unimp_id
|
val uniMpId = uniVersion.unimp_id
|
||||||
val wgtName = getWgtName(uniMpId)
|
val wgtName = getWgtName(uniMpId)
|
||||||
val path = FileUtils.instance?.cacheUniAppDir?.absolutePath?:""
|
val path = FileUtils.getInstance().cacheUniAppDir.absolutePath
|
||||||
//先删除旧文件
|
//先删除旧文件
|
||||||
val oldFile = File(path, wgtName)
|
val oldFile = File(path, wgtName)
|
||||||
if(oldFile.exists()){
|
if(oldFile.exists()){
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ object UpdateUtils {
|
||||||
|
|
||||||
fun install(context: Context, apkFilePath: String) {
|
fun install(context: Context, apkFilePath: String) {
|
||||||
try {
|
try {
|
||||||
val apkFile = File(FileUtils.instance?.cacheDownLoadDir, AppUpdate.getFileNameFromUrl(apkFilePath))
|
val apkFile = File(FileUtils.getInstance().cacheDownLoadDir, AppUpdate.getFileNameFromUrl(apkFilePath))
|
||||||
if (!apkFile.exists()) {
|
if (!apkFile.exists()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ public final class ChannelReader {
|
||||||
/**
|
/**
|
||||||
* 读取注入的内容
|
* 读取注入的内容
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("CallToPrintStackTrace")
|
|
||||||
public static String get(@NonNull Context context) {
|
public static String get(@NonNull Context context) {
|
||||||
String apkPath = getApkPath(context);
|
String apkPath = getApkPath(context);
|
||||||
String raw = TextUtils.isEmpty(apkPath) ? null : getRaw(new File(apkPath));
|
String raw = TextUtils.isEmpty(apkPath) ? null : getRaw(new File(apkPath));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue