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