From 92a19833cfe7e8e98948450d74124327615e9a56 Mon Sep 17 00:00:00 2001 From: George Haddad Date: Mon, 12 Aug 2013 23:34:33 +0300 Subject: [PATCH] Fixed Auto Updater to work with File URL --- .../sapguestconnect/autoupdate/AutoUpdater.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/WiFiConnect/src/com/wifi/sapguestconnect/autoupdate/AutoUpdater.java b/WiFiConnect/src/com/wifi/sapguestconnect/autoupdate/AutoUpdater.java index b1882a4..5691550 100644 --- a/WiFiConnect/src/com/wifi/sapguestconnect/autoupdate/AutoUpdater.java +++ b/WiFiConnect/src/com/wifi/sapguestconnect/autoupdate/AutoUpdater.java @@ -27,8 +27,7 @@ public class AutoUpdater { - private static final String APPLICATION_DATA_BASE_URL = "http://privatewificonnect.googlecode.com/files/"; - private static final String APPLICATION_PROPERTIES_URL = "https://privatewificonnect.googlecode.com/svn/trunk/WiFiConnect/application.properties"; + private static final String APPLICATION_PROPERTIES_URL = "https://raw.github.com/georgehdd/PrivateWifiConnect/master/application.properties"; private static final String DOWNLOAD_FILEPATH = "/sdcard/download"; @@ -81,12 +80,12 @@ public void run(){ int availableVersion = Integer.parseInt(updateProperties.getProperty("versionCode")); int installedVersion = CommonFacade.getVersionCode(mContext); - String fileName = updateProperties.getProperty("fileName", ""); + String fileURL = updateProperties.getProperty("fileURL", ""); String updateMessage = updateProperties.getProperty("message", ""); String updateTitle = updateProperties.getProperty("title", "Update available"); if (availableVersion > installedVersion) { - displayUpdateDialog(fileName, updateMessage, updateTitle); + displayUpdateDialog(fileURL, updateMessage, updateTitle); } } Looper.loop(); @@ -94,7 +93,7 @@ public void run(){ }).start(); } - private void downloadUpdate(final String downloadFileUrl, final String fileName) { + private void downloadUpdate(final String fileURL) { LogManager.LogFunctionCall("AutoUpdater", "downloadUpdate()"); new Thread(new Runnable(){ public void run(){ @@ -102,7 +101,9 @@ public void run(){ Message msg = Message.obtain(); msg.obj = DownloadStates.MESSAGE_DOWNLOAD_STARTING; mDownloadHandler.sendMessage(msg); - downloadUpdateFile(downloadFileUrl, fileName); + int slashIndex = fileURL.lastIndexOf('/'); + String fileName = fileURL.substring(slashIndex + 1); + downloadUpdateFile(fileURL, fileName); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(android.net.Uri.fromFile(new File(DOWNLOAD_FILEPATH+"/"+fileName)),"application/vnd.android.package-archive"); mContext.startActivity(intent); @@ -203,7 +204,7 @@ private boolean downloadFile(String url, String destinationDirectory, String des return filedownloaded; } - private void displayUpdateDialog(final String fileName, String updateTitle, String updateMessage) + private void displayUpdateDialog(final String fileURL, String updateTitle, String updateMessage) { LogManager.LogFunctionCall("AutoUpdater", "displayUpdateDialog()"); @@ -215,7 +216,7 @@ public void onClick(DialogInterface dialog, int id) { LogManager.LogFunctionCall("AutoUpdater", "displayUpdateDialog().AlertDialog.Builder.PositiveButton.onClick()"); dialog.cancel(); - downloadUpdate(APPLICATION_DATA_BASE_URL + fileName, fileName); + downloadUpdate(fileURL); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() {