diff -r 9dd921c0c7e7 -r 9df5a486f41e project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java --- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java Mon Nov 14 17:59:26 2011 +0100 +++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadAsyncTask.java Mon Nov 14 18:03:31 2011 +0100 @@ -32,7 +32,6 @@ import java.util.zip.ZipInputStream; import android.os.AsyncTask; -import android.util.Log; /** * This is an AsyncTask which will download a zip from an URL and unzip it to a specified path * @@ -40,13 +39,12 @@ * @author Xeli * */ -public class DownloadAsyncTask extends AsyncTask { +public class DownloadAsyncTask extends AsyncTask { - private final static String URL_WITHOUT_SUFFIX = "http://hedgewars.googlecode.com/files/data_5631."; //private final static String URL_WITHOUT_SUFFIX = "http://www.xelification.com/tmp/firebutton."; - private final static String URL_ZIP_SUFFIX = "zip"; - private final static String URL_HASH_SUFFIX = "hash"; - + private final static String URL_ZIP_SUFFIX = ".zip"; + private final static String URL_HASH_SUFFIX = ".hash"; + private DownloadService service; private long lastUpdateMillis = 0; @@ -56,18 +54,20 @@ /** * - * @param params - 2 Strings, first is the path where the unzipped files will be stored, second is the URL to download from + * @param params - A {@link}DownloadTask which gives information about where to download from and store the files to */ - protected Long doInBackground(String... params) { + protected Long doInBackground(DownloadTask...tasks) { + DownloadTask task = tasks[0];//just use one task per execute call for now + HttpURLConnection conn = null; MessageDigest digester = null; - String rootZipDest = params[0]; + String rootZipDest = task.getPathToStore(); File rootDest = new File(rootZipDest);//TODO check for nullpointer, it hints to the absence of an sdcard rootDest.mkdir(); try { - URL url = new URL(URL_WITHOUT_SUFFIX + URL_ZIP_SUFFIX); + URL url = new URL(task.getURL() + URL_ZIP_SUFFIX); conn = (HttpURLConnection)url.openConnection(); } catch (IOException e) { e.printStackTrace(); @@ -161,7 +161,7 @@ if(conn != null) conn.disconnect(); - if(checkMD5(digester))return 0l; + if(checkMD5(digester, task))return 0l; else return -1l; } @@ -174,12 +174,12 @@ service.update((Integer)objects[0], (Integer)objects[1], (String)objects[2]); } - private boolean checkMD5(MessageDigest digester){ + private boolean checkMD5(MessageDigest digester, DownloadTask task){ if(digester != null) { byte[] messageDigest = digester.digest(); try { - URL url = new URL(URL_WITHOUT_SUFFIX + URL_HASH_SUFFIX); + URL url = new URL(task.getURL() + URL_HASH_SUFFIX); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); byte[] buffer = new byte[1024];//size is large enough to hold the entire hash