From 7d62604961bcfe0b9a8c3c18f0827906ac0d8ef9 Mon Sep 17 00:00:00 2001 From: Neo Date: Mon, 19 Feb 2024 00:12:50 +0000 Subject: [PATCH] Bug fix --- .../io/rayshift/translatefgo/NGFSService.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/nextgenfs/src/main/java/io/rayshift/translatefgo/NGFSService.java b/nextgenfs/src/main/java/io/rayshift/translatefgo/NGFSService.java index cd3b10c..42a0fab 100644 --- a/nextgenfs/src/main/java/io/rayshift/translatefgo/NGFSService.java +++ b/nextgenfs/src/main/java/io/rayshift/translatefgo/NGFSService.java @@ -1,5 +1,6 @@ package io.rayshift.translatefgo; +import android.os.Build; import android.os.FileUtils; import android.os.RemoteException; import android.system.Os; @@ -15,6 +16,7 @@ import java.io.RandomAccessFile; import java.nio.file.Files; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.List; @@ -64,8 +66,15 @@ public boolean RemoveFileIfExists(String filename, NGFSError error) throws Remot File file = new File(filename); try { error.IsSuccess = true; - Files.deleteIfExists(file.toPath()); - return true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Files.deleteIfExists(file.toPath()); + return true; + } + else { + error.IsSuccess = false; + error.Error = "Android version too low."; + return false; + } } catch (Exception ex) { error.IsSuccess = false; @@ -78,7 +87,14 @@ public boolean RemoveFileIfExists(String filename, NGFSError error) throws Remot public boolean GetFileExists(String filename, NGFSError error) throws RemoteException { File file = new File(filename); error.IsSuccess = true; - return Files.exists(file.toPath()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + return Files.exists(file.toPath()); + } + else { + error.IsSuccess = false; + error.Error = "Android version too low."; + return false; + } } @Override @@ -135,9 +151,17 @@ public boolean CopyFile(String source, String destination, NGFSError error) thro try { File input = new File(source); File output = new File(destination); - Files.copy(input.toPath(), output.toPath()); - error.IsSuccess = true; - return true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING); + + error.IsSuccess = true; + return true; + } + else { + error.IsSuccess = false; + error.Error = "Android version too low."; + return false; + } } catch (Exception ex) { error.IsSuccess = false;