From d6822c9c7dc3c8f9245eab1bf3b676b3b985c91e Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 10 Nov 2019 20:59:23 -0500 Subject: [PATCH] Possible IOS read fix --- gradle.properties | 2 +- ios/src/io/anuke/mindustry/IOSLauncher.java | 36 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9b5dd0832a..038ab7930d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=60e1edbc61f05c329019d0c5479672a298a9706c +archash=22534a12fc0d39eee77e1369c043444999a4e725 diff --git a/ios/src/io/anuke/mindustry/IOSLauncher.java b/ios/src/io/anuke/mindustry/IOSLauncher.java index 601964b384..624144291f 100644 --- a/ios/src/io/anuke/mindustry/IOSLauncher.java +++ b/ios/src/io/anuke/mindustry/IOSLauncher.java @@ -58,6 +58,40 @@ public class IOSLauncher extends IOSApplication.Delegate{ if(documentURLs.size() < 1) return; cont.dismissViewController(true, () -> {}); + NSFileCoordinator coord = new NSFileCoordinator(null); + try{ + coord.coordinateReadingItem(documentURLs.get(0), NSFileCoordinatorReadingOptions.None, url -> { + NSInputStream stream = new NSInputStream(NSData.read(url)); + + cons.get(new FileHandle(url.getPath()){ + @Override + public InputStream read(){ + return new InputStream(){ + byte[] tmp = {0}; + + @Override + public int read() throws IOException{ + read(tmp); + return tmp[0]; + } + + @Override + public int read(byte[] bytes, int offset, int length){ + return (int)stream.read(bytes, offset, length); + } + + @Override + public void close() throws IOException{ + stream.close(); + } + }; + } + }); + }); + }catch(Throwable t){ + ui.showException(t); + } + /* try{ controller.importDocument(documentURLs.get(0), new NSURL(getDocumentsDirectory() + "/document"), UIDocumentBrowserImportMode.Copy, (url, error) -> { @@ -73,7 +107,7 @@ public class IOSLauncher extends IOSApplication.Delegate{ }); }catch(Throwable t){ ui.showException(t); - } + }*/ } @Override