diff --git a/Ganary/extensions/_olympus_extension/AndroidSource/Java/Olympus.java b/Ganary/extensions/_olympus_extension/AndroidSource/Java/Olympus.java index 84e1e53..dede865 100644 --- a/Ganary/extensions/_olympus_extension/AndroidSource/Java/Olympus.java +++ b/Ganary/extensions/_olympus_extension/AndroidSource/Java/Olympus.java @@ -14,6 +14,18 @@ import java.io.OutputStream; import java.io.IOException; +import android.os.Environment; +import java.io.File; + +import java.nio.file.StandardCopyOption.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.stream.Stream; +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + + + public class Olympus extends RunnerSocial { public static Activity activity = null; public static Intent launchIntent = null; @@ -71,4 +83,54 @@ public void _olympus_android_write_custom_output(String data) { } } } + + private void copyFolder(Path src, Path dest) throws IOException { + try (Stream stream = Files.walk(src)) { + stream.forEach(source -> copy(source, dest.resolve(src.relativize(source)))); + } + } + + private void copy(Path source, Path dest) { + try { + Files.copy(source, dest, REPLACE_EXISTING); + } catch (Exception e) { + throw new RuntimeException(e.getMessage(), e); + } + } + + // Function to copy all files from internal storage to SD card + public void _olympus_android_copy_files_to_SD_card() { + File sourceDir = activity.getFilesDir(); // Get internal files directory + Log.i("yoyo", "Source directory: " + sourceDir); + String externalStorageState = Environment.getExternalStorageState(); + if (!externalStorageState.equals(Environment.MEDIA_MOUNTED)) { + Log.e("yoyo", "External storage not mounted"); + return; + } + else{ + Log.i("yoyo", "External storage state: " + externalStorageState); + } + + File[] externalStorageVolumes = activity.getExternalFilesDirs(null); + File primaryExternalStorage = externalStorageVolumes[0]; + File secondaryExternalStorage = externalStorageVolumes[1]; + Log.i("yoyo", "Primary external storage: " + primaryExternalStorage); + Log.i("yoyo", "Secondary external storage: " + secondaryExternalStorage); + + + File targetDir = new File(secondaryExternalStorage, "MyAppFiles"); // Destination on SD card + Log.i("yoyo", "Target directory: " + targetDir); + if (!targetDir.exists()) { + if (!targetDir.mkdirs()) { + Log.i("yoyo", "Failed to create target directory"); + return; + } + } + + try { + copyFolder(sourceDir.toPath(), targetDir.toPath()); + } catch (IOException e) { + Log.e("yoyo", "Error copying files", e); + } + } } \ No newline at end of file diff --git a/Ganary/extensions/_olympus_extension/_olympus_extension.yy b/Ganary/extensions/_olympus_extension/_olympus_extension.yy index 352a491..1594fed 100644 --- a/Ganary/extensions/_olympus_extension/_olympus_extension.yy +++ b/Ganary/extensions/_olympus_extension/_olympus_extension.yy @@ -38,6 +38,7 @@ {"$GMExtensionFunction":"","%Name":"_olympus_ios_get_intent","argCount":0,"args":[],"documentation":"","externalName":"_olympus_ios_get_intent","help":"","hidden":false,"kind":4,"name":"_olympus_ios_get_intent","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"_olympus_android_write_custom_output","argCount":0,"args":[1,],"documentation":"","externalName":"_olympus_android_write_custom_output","help":"_olympus_android_write_custom_output(data)","hidden":false,"kind":4,"name":"_olympus_android_write_custom_output","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"_olympus_ios_get_available_ram","argCount":0,"args":[],"documentation":"","externalName":"_olympus_ios_get_available_ram","help":"","hidden":false,"kind":4,"name":"_olympus_ios_get_available_ram","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":2,}, + {"$GMExtensionFunction":"","%Name":"_olympus_android_copy_files_to_SD_card","argCount":0,"args":[],"documentation":"","externalName":"_olympus_android_copy_files_to_SD_card","help":"","hidden":false,"kind":4,"name":"_olympus_android_copy_files_to_SD_card","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, ],"init":"","kind":4,"name":"_olympus_extension.ext","order":[ {"name":"_olympus_android_init","path":"extensions/_olympus_extension/_olympus_extension.yy",}, {"name":"_olympus_android_game_end","path":"extensions/_olympus_extension/_olympus_extension.yy",},