Data downloader will check if the saved URL in libsdl-DownloadFinished.flag is not the same as compiled-in,

and re-download the data, tu support application self-updating.
This commit is contained in:
pelya
2010-07-06 13:55:29 +03:00
parent 45085c8641
commit 616cc0b5fd

View File

@@ -16,17 +16,12 @@ import org.apache.http.impl.*;
import org.apache.http.impl.client.*; import org.apache.http.impl.client.*;
import java.util.zip.*; import java.util.zip.*;
import java.io.*; import java.io.*;
import android.util.Log;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/**
* CountingInputStream
* @author $Author: jeffdrost $
* @version $Revision: 1.7 $
* @deprecated
*/
class CountingInputStream extends BufferedInputStream { class CountingInputStream extends BufferedInputStream {
private long bytesReadMark = 0; private long bytesReadMark = 0;
@@ -131,8 +126,8 @@ class DataDownloader extends Thread
@Override @Override
public void run() public void run()
{ {
final String DownloadFlagFileName = "libsdl-DownloadFinished.flag";
String path = getOutFilePath("DownloadFinished.flag"); String path = getOutFilePath(DownloadFlagFileName);
InputStream checkFile = null; InputStream checkFile = null;
try { try {
checkFile = new FileInputStream( path ); checkFile = new FileInputStream( path );
@@ -140,10 +135,20 @@ class DataDownloader extends Thread
} catch( SecurityException e ) { }; } catch( SecurityException e ) { };
if( checkFile != null ) if( checkFile != null )
{ {
Status.setText( "No need to download" ); try {
DownloadComplete = true; byte b[] = new byte[ Globals.DataDownloadUrl.getBytes("UTF-8").length + 1 ];
initParent(); int readed = checkFile.read(b);
return; String compare = new String( b, 0, b.length - 1, "UTF-8" );
//Log.i("libSDL", "Saved URL '" + compare + "' requested URL '" + Globals.DataDownloadUrl + "'");
if( readed != b.length - 1 )
throw new IOException();
if( compare.compareTo(Globals.DataDownloadUrl) != 0 )
throw new IOException();
Status.setText( "No need to download" );
DownloadComplete = true;
initParent();
return;
} catch ( IOException e ) {};
} }
checkFile = null; checkFile = null;
@@ -254,10 +259,10 @@ class DataDownloader extends Thread
} }
OutputStream out = null; OutputStream out = null;
path = getOutFilePath("DownloadFinished.flag"); path = getOutFilePath(DownloadFlagFileName);
try { try {
out = new FileOutputStream( path ); out = new FileOutputStream( path );
out.write(0); out.write(Globals.DataDownloadUrl.getBytes("UTF-8"));
out.flush(); out.flush();
out.close(); out.close();
} catch( FileNotFoundException e ) { } catch( FileNotFoundException e ) {