mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-02 20:33:50 +07:00
it's 3 am and ios file imports are finally fixed
This commit is contained in:
parent
dcdec7f55f
commit
44fdda09c6
@ -58,129 +58,31 @@ public class IOSLauncher extends IOSApplication.Delegate{
|
||||
public void didPickDocumentsAtURLs(UIDocumentBrowserViewController controller, NSArray<NSURL> documentURLs){
|
||||
if(documentURLs.size() < 1) return;
|
||||
|
||||
cont.dismissViewController(true, () -> {});
|
||||
NSURL url = documentURLs.first();
|
||||
NSFileCoordinator coord = new NSFileCoordinator(null);
|
||||
|
||||
url.startAccessingSecurityScopedResource();
|
||||
try{
|
||||
coord.coordinateReadingItem(documentURLs.get(0), NSFileCoordinatorReadingOptions.None, url -> {
|
||||
if(url.startAccessingSecurityScopedResource()){
|
||||
coord.coordinateReadingItem(url, NSFileCoordinatorReadingOptions.ForUploading, result -> {
|
||||
|
||||
FileHandle src = Core.files.absolute(result.getAbsoluteURL().getPath());
|
||||
FileHandle dst = Core.files.absolute(getDocumentsDirectory()).child(src.name());
|
||||
src.copyTo(dst);
|
||||
|
||||
Core.app.post(() -> {
|
||||
try{
|
||||
controller.importDocument(url, new NSURL(getDocumentsDirectory() + "/document"), UIDocumentBrowserImportMode.Copy, (result, error) -> {
|
||||
if(error != null){
|
||||
ui.showErrorMessage("Import error.\n" + error.getLocalizedFailureReason() + "\n" + error.getLocalizedDescription());
|
||||
}else{
|
||||
try{
|
||||
cons.get(Core.files.absolute(url.getPath()));
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}
|
||||
}
|
||||
});
|
||||
cons.get(dst);
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
try{
|
||||
int[] tread = {0};
|
||||
|
||||
cons.get(new FileHandle(url.getPath()){
|
||||
@Override
|
||||
public InputStream read(){
|
||||
NSInputStream stream = new NSInputStream(url);
|
||||
|
||||
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){
|
||||
int read = (int)stream.read(bytes, offset, length);
|
||||
tread[0] += read;
|
||||
return read;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Core.app.post(() -> Core.app.post(() -> Core.app.post(() -> ui.showInfo("Read " + tread[0]))));
|
||||
//cons.get(new FileHandle(url.getAbsoluteString()));
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
|
||||
try{
|
||||
cons.get(new FileHandle(url.getPath()));
|
||||
}catch(Throwable t2){
|
||||
ui.showException(t2);
|
||||
|
||||
try{
|
||||
cons.get(new FileHandle(url.getAbsoluteURL().getPath()));
|
||||
}catch(Throwable t3){
|
||||
ui.showException(t3);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}else{
|
||||
ui.showErrorMessage("Failed to access file.");
|
||||
}
|
||||
|
||||
/*
|
||||
try{
|
||||
int[] tread = {0};
|
||||
|
||||
cons.get(new FileHandle(url.getPath()){
|
||||
@Override
|
||||
public InputStream read(){
|
||||
NSInputStream stream = new NSInputStream(url);
|
||||
|
||||
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){
|
||||
int read = (int)stream.read(bytes, offset, length);
|
||||
tread[0] += read;
|
||||
return read;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Core.app.post(() -> Core.app.post(() -> Core.app.post(() -> ui.showInfo("Read " + tread[0]))));
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}*/
|
||||
});
|
||||
});
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}catch(Throwable e){
|
||||
ui.showException(e);
|
||||
}
|
||||
/*
|
||||
|
||||
try{
|
||||
controller.importDocument(documentURLs.get(0), new NSURL(getDocumentsDirectory() + "/document"), UIDocumentBrowserImportMode.Copy, (url, error) -> {
|
||||
if(error != null){
|
||||
ui.showErrorMessage("Import error.\n" + error.getLocalizedFailureReason() + "\n" + error.getLocalizedDescription());
|
||||
}else{
|
||||
try{
|
||||
cons.get(Core.files.absolute(url.getPath()));
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}
|
||||
}
|
||||
});
|
||||
}catch(Throwable t){
|
||||
ui.showException(t);
|
||||
}*/
|
||||
url.stopAccessingSecurityScopedResource();
|
||||
|
||||
cont.dismissViewController(true, () -> {});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -190,7 +92,6 @@ public class IOSLauncher extends IOSApplication.Delegate{
|
||||
|
||||
@Override
|
||||
public void didImportDocument(UIDocumentBrowserViewController controller, NSURL sourceURL, NSURL destinationURL){
|
||||
//cons.get(Core.files.absolute(destinationURL.getAbsoluteString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user