cache script info in script update class
This commit is contained in:
parent
06ac8b050e
commit
dcd6fce41e
@ -17,12 +17,14 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class UpdateScript extends AsyncTask<String, Void, Boolean> {
|
public class UpdateScript extends AsyncTask<String, Void, Boolean> {
|
||||||
|
|
||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private String mFilePath;
|
private String mFilePath;
|
||||||
private String mScript;
|
private String mScript;
|
||||||
|
private HashMap<String, String> mScriptInfo;
|
||||||
|
|
||||||
public UpdateScript(final Activity activity) {
|
public UpdateScript(final Activity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
@ -34,20 +36,22 @@ public class UpdateScript extends AsyncTask<String, Void, Boolean> {
|
|||||||
mFilePath = urls[0];
|
mFilePath = urls[0];
|
||||||
// get local script meta information
|
// get local script meta information
|
||||||
mScript = IITC_FileManager.readStream(new FileInputStream(new File(mFilePath)));
|
mScript = IITC_FileManager.readStream(new FileInputStream(new File(mFilePath)));
|
||||||
final String updateURL = IITC_FileManager.getScriptInfo(mScript).get("updateURL");
|
mScriptInfo = IITC_FileManager.getScriptInfo(mScript);
|
||||||
final String downloadURL = IITC_FileManager.getScriptInfo(mScript).get("downloadURL");
|
String updateURL = mScriptInfo.get("updateURL");
|
||||||
|
final String downloadURL = mScriptInfo.get("downloadURL");
|
||||||
|
if (updateURL == null) updateURL = downloadURL;
|
||||||
|
|
||||||
// get remote script meta information
|
// get remote script meta information
|
||||||
final File file_old = new File(mFilePath);
|
final File local_file = new File(mFilePath);
|
||||||
final InputStream is = new URL(updateURL).openStream();
|
final InputStream is = new URL(updateURL).openStream();
|
||||||
final String old_version = IITC_FileManager.getScriptInfo(mScript).get("version");
|
final String local_version = mScriptInfo.get("version");
|
||||||
final String new_version = IITC_FileManager.getScriptInfo(IITC_FileManager.readStream(is)).get("version");
|
final String remote_version = IITC_FileManager.getScriptInfo(IITC_FileManager.readStream(is)).get("version");
|
||||||
|
|
||||||
// update script if neccessary
|
// update script if neccessary
|
||||||
if (old_version.compareTo(new_version) < 0) {
|
if (local_version.compareTo(remote_version) < 0) {
|
||||||
Log.d("plugin " + mFilePath + " outdated\n" + old_version + " vs " + new_version);
|
Log.d("plugin " + mFilePath + " outdated\n" + local_version + " vs " + remote_version);
|
||||||
Log.d("updating file....");
|
Log.d("updating file....");
|
||||||
IITC_FileManager.copyStream(new URL(downloadURL).openStream(), new FileOutputStream(file_old), true);
|
IITC_FileManager.copyStream(new URL(downloadURL).openStream(), new FileOutputStream(local_file), true);
|
||||||
Log.d("...done");
|
Log.d("...done");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,6 @@ import android.util.AttributeSet;
|
|||||||
|
|
||||||
import com.cradle.iitc_mobile.R;
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
/**
|
|
||||||
* The OptionDialogPreference will display a dialog, and will persist the
|
|
||||||
* <code>true</code> when pressing the positive button and <code>false</code>
|
|
||||||
* otherwise. It will persist to the android:key specified in xml-preference.
|
|
||||||
*/
|
|
||||||
public class ForceUpdatePreference extends Preference {
|
public class ForceUpdatePreference extends Preference {
|
||||||
|
|
||||||
public ForceUpdatePreference(Context context, AttributeSet attrs) {
|
public ForceUpdatePreference(Context context, AttributeSet attrs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user