This commit is contained in:
Jon Atkins 2014-05-17 21:11:33 +01:00
commit b73db4585f
5 changed files with 27 additions and 14 deletions

View File

@ -135,6 +135,8 @@
<string name="pref_update_plugins_interval_sum">How often IITCm should search for new plugin versions</string>
<string name="pref_force_plugin_update">Force plugin update</string>
<string name="pref_force_plugin_update_sum">Update all enabled user plugins</string>
<string name="pref_secure_updates">Require secure updates</string>
<string name="pref_secure_updates_sum">If enabled, only https updates are handled</string>
<string-array name="pref_hide_fullscreen">
<item>System Bar</item>

View File

@ -106,6 +106,11 @@
android:key="pref_force_plugin_update"
android:title="@string/pref_force_plugin_update"
android:summary="@string/pref_force_plugin_update_sum"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_secure_updates"
android:summary="@string/pref_secure_updates_sum"
android:title="@string/pref_secure_updates"/>
</PreferenceCategory>
<PreferenceCategory
android:key="pref_advanced_tweaks_cat"

View File

@ -205,6 +205,7 @@ public class IITC_Mobile extends Activity
} else if (key.equals("pref_press_twice_to_exit")
|| key.equals("pref_share_selected_tab")
|| key.equals("pref_messages")
|| key.equals("pref_secure_updates")
|| key.equals("pref_external_storage")) {
// no reload needed
return;

View File

@ -17,12 +17,14 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
public class UpdateScript extends AsyncTask<String, Void, Boolean> {
private final Activity mActivity;
private String mFilePath;
private String mScript;
private HashMap<String, String> mScriptInfo;
public UpdateScript(final Activity activity) {
mActivity = activity;
@ -34,20 +36,28 @@ public class UpdateScript extends AsyncTask<String, Void, Boolean> {
mFilePath = urls[0];
// get local script meta information
mScript = IITC_FileManager.readStream(new FileInputStream(new File(mFilePath)));
final String updateURL = IITC_FileManager.getScriptInfo(mScript).get("updateURL");
final String downloadURL = IITC_FileManager.getScriptInfo(mScript).get("downloadURL");
mScriptInfo = IITC_FileManager.getScriptInfo(mScript);
String updateURL = mScriptInfo.get("updateURL");
final String downloadURL = mScriptInfo.get("downloadURL");
if (updateURL == null) updateURL = downloadURL;
// check for https protocol
final URL url = new URL(updateURL);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
Boolean secureUpdates = prefs.getBoolean("pref_secure_updates", true);
if (!url.getProtocol().equals("https") && secureUpdates) return false;
// get remote script meta information
final File file_old = new File(mFilePath);
final InputStream is = new URL(updateURL).openStream();
final String old_version = IITC_FileManager.getScriptInfo(mScript).get("version");
final String new_version = IITC_FileManager.getScriptInfo(IITC_FileManager.readStream(is)).get("version");
final InputStream is = url.openStream();
final String remote_version = IITC_FileManager.getScriptInfo(IITC_FileManager.readStream(is)).get("version");
final File local_file = new File(mFilePath);
final String local_version = mScriptInfo.get("version");
// update script if neccessary
if (old_version.compareTo(new_version) < 0) {
Log.d("plugin " + mFilePath + " outdated\n" + old_version + " vs " + new_version);
if (local_version.compareTo(remote_version) < 0) {
Log.d("plugin " + mFilePath + " outdated\n" + local_version + " vs " + remote_version);
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");
return true;
}

View File

@ -9,11 +9,6 @@ import android.util.AttributeSet;
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 ForceUpdatePreference(Context context, AttributeSet attrs) {