Skip to content

Commit

Permalink
Fixed Auto Updater to work with File URL
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehdd committed Aug 12, 2013
1 parent 21dd7c5 commit 92a1983
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand Down Expand Up @@ -81,28 +80,30 @@ 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();
}
}).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(){
LogManager.LogInfoMsg("AutoUpdater", "downloadUpdate().Thread.run()", "Downloading update...");
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);
Expand Down Expand Up @@ -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()");

Expand All @@ -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() {
Expand Down

0 comments on commit 92a1983

Please sign in to comment.