feat: #266
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
|
||||
module.exports = function(__runtime__, scope){
|
||||
var files = Object.create(com.stardust.autojs.runtime.api);
|
||||
files.cwd = function(){
|
||||
return scope.engines.myEngine().cwd();
|
||||
var fs = __runtime__.files;
|
||||
var files = Object.create(fs);
|
||||
files.join = function(base){
|
||||
var paths = Array.prototype.slice.call(arguments, 0);
|
||||
return fs.join(base, paths);
|
||||
}
|
||||
scope.files = files;
|
||||
scope.open = function(path, mode, encoding, bufferSize){
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.stardust.autojs.runtime.api.Console;
|
||||
import com.stardust.autojs.runtime.api.Device;
|
||||
import com.stardust.autojs.runtime.api.Engines;
|
||||
import com.stardust.autojs.runtime.api.Events;
|
||||
import com.stardust.autojs.runtime.api.Files;
|
||||
import com.stardust.autojs.runtime.api.Floaty;
|
||||
import com.stardust.autojs.core.looper.Loopers;
|
||||
import com.stardust.autojs.runtime.api.Threads;
|
||||
@@ -169,6 +170,9 @@ public class ScriptRuntime {
|
||||
@ScriptVariable
|
||||
public final Colors colors = new Colors();
|
||||
|
||||
@ScriptVariable
|
||||
public final Files files;
|
||||
|
||||
private Images images;
|
||||
|
||||
private static WeakReference<Context> applicationContext;
|
||||
@@ -197,6 +201,7 @@ public class ScriptRuntime {
|
||||
dialogs = new Dialogs(app, uiHandler, bridges);
|
||||
device = new Device(uiHandler.getContext());
|
||||
floaty = new Floaty(uiHandler, ui, this);
|
||||
files = new Files(this);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.stardust.autojs.runtime.api;
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import com.stardust.autojs.engine.ScriptEngine;
|
||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||
import com.stardust.autojs.script.JavaScriptSource;
|
||||
import com.stardust.pio.PFileInterface;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.util.Func1;
|
||||
@@ -18,6 +21,16 @@ import java.io.OutputStream;
|
||||
|
||||
public class Files {
|
||||
|
||||
private final ScriptRuntime mRuntime;
|
||||
|
||||
public Files(ScriptRuntime runtime) {
|
||||
mRuntime = runtime;
|
||||
}
|
||||
|
||||
public String cwd() {
|
||||
return ((ScriptEngine.AbstractScriptEngine) mRuntime.engines.myEngine()).cwd();
|
||||
}
|
||||
|
||||
public static PFileInterface open(String path, String mode, String encoding, int bufferSize) {
|
||||
return PFiles.open(path, mode, encoding, bufferSize);
|
||||
}
|
||||
@@ -218,7 +231,7 @@ public class Files {
|
||||
return PFiles.isEmptyDir(path);
|
||||
}
|
||||
|
||||
public static String join(String parent, String child) {
|
||||
public static String join(String parent, String... child) {
|
||||
return PFiles.join(parent, child);
|
||||
}
|
||||
|
||||
|
||||
@@ -409,8 +409,12 @@ public class PFiles {
|
||||
return file.isDirectory() && file.list().length == 0;
|
||||
}
|
||||
|
||||
public static String join(String parent, String child) {
|
||||
return new File(parent, child).getPath();
|
||||
public static String join(String base, String... paths) {
|
||||
File file = new File(base);
|
||||
for (String path : paths) {
|
||||
file = new File(file, path);
|
||||
}
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
public static String getHumanReadableSize(long bytes) {
|
||||
|
||||
Reference in New Issue
Block a user