From 8ecb9c5f28e39afee9d1f4b7856389195ea0d375 Mon Sep 17 00:00:00 2001 From: pelya Date: Mon, 10 Nov 2014 12:40:26 +0200 Subject: [PATCH] Fixed bug with downloading expansion files --- project/java/DataDownloader.java | 29 +++++++++++-------- .../supertux/AndroidAppSettings.cfg | 4 +-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/project/java/DataDownloader.java b/project/java/DataDownloader.java index e47fcffc9..82b28dd78 100644 --- a/project/java/DataDownloader.java +++ b/project/java/DataDownloader.java @@ -319,15 +319,17 @@ class DataDownloader extends Thread Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.connecting_to, url) ); if( url.indexOf("obb:") == 0 ) // APK expansion file provided by Google Play { - FileInExpansion = true; url = url.substring("obb:".length()); url = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/obb/" + Parent.getPackageName() + "/" + url + "." + Parent.getPackageName() + ".obb"; - Log.i("SDL", "Fetching file from OBB: " + url); InputStream stream1 = null; try { stream1 = new FileInputStream(url); + stream1.read(); stream1.close(); + Log.i("SDL", "Fetching file from expansion: " + url); + FileInExpansion = true; + break; } catch( Exception e ) { Log.i("SDL", "Failed to open file: " + url); downloadUrlIndex++; @@ -369,7 +371,6 @@ class DataDownloader extends Thread response = client.execute(request); } catch (IOException e) { Log.i("SDL", "Failed to connect to " + url); - downloadUrlIndex++; }; if( response != null ) { @@ -379,21 +380,25 @@ class DataDownloader extends Thread responseError = response; response = null; downloadUrlIndex++; + continue; } - else - break; + break; + } + else + { + downloadUrlIndex++; + continue; } } } if( FileInExpansion ) { + Log.i("SDL", "Count file size: '" + url); try { + totalLen = new File(url).length(); stream = new CountingInputStream(new FileInputStream(url), 8192); - while( stream.skip(65536) > 0 ) { }; - totalLen = stream.getBytesRead(); - stream.close(); - stream = new CountingInputStream(new FileInputStream(url), 8192); + Log.i("SDL", "Count file size: '" + url + " = " + totalLen); } catch( IOException e ) { Log.i("SDL", "Unpacking from filesystem '" + url + "' - error: " + e.toString()); Status.setText( res.getString(R.string.error_dl_from, url) ); @@ -470,8 +475,6 @@ class DataDownloader extends Thread out.write(downloadUrls[downloadUrlIndex].getBytes("UTF-8")); out.flush(); out.close(); - } catch( FileNotFoundException e ) { - } catch( SecurityException e ) { } catch( java.io.IOException e ) { Status.setText( res.getString(R.string.error_write, path) + ": " + e.getMessage() ); return false; @@ -483,10 +486,12 @@ class DataDownloader extends Thread if( FileInExpansion ) { Writer writer = new OutputStreamWriter(new FileOutputStream(url), "UTF-8"); - writer.write("Extracted and cleared\n"); + writer.write("Extracted and truncated\n"); writer.close(); + Log.i("SDL", "Truncated file from expansion: " + url); } } catch( java.io.IOException e ) { + Log.i("SDL", "Error truncating file from expansion: " + url); }; return true; diff --git a/project/jni/application/supertux/AndroidAppSettings.cfg b/project/jni/application/supertux/AndroidAppSettings.cfg index 86d4f167b..d195b3426 100644 --- a/project/jni/application/supertux/AndroidAppSettings.cfg +++ b/project/jni/application/supertux/AndroidAppSettings.cfg @@ -7,10 +7,10 @@ AppName="SuperTux" AppFullName=org.lethargik.supertux2 # Application version code (integer) -AppVersionCode=3406 +AppVersionCode=3407 # Application user-visible version name (string) -AppVersionName="0.3.4.06" +AppVersionName="0.3.4.07" # Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...' # If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu