Option to clean up SDL config left from the old app version
This commit is contained in:
@@ -52,6 +52,7 @@ class Globals {
|
||||
public static boolean AppHandlesJoystickSensitivity = false;
|
||||
public static boolean AppUsesMultitouch = false;
|
||||
public static boolean NonBlockingSwapBuffers = false;
|
||||
public static boolean ResetSdlConfigForThisVersion = false;
|
||||
public static int AppTouchscreenKeyboardKeysAmount = 4;
|
||||
public static int AppTouchscreenKeyboardKeysAmountAutoFire = 1;
|
||||
public static int StartupMenuButtonTimeout = 3000;
|
||||
|
||||
@@ -62,8 +62,8 @@ import java.io.BufferedReader;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
@Override
|
||||
@@ -664,6 +664,17 @@ public class MainActivity extends Activity {
|
||||
|
||||
};
|
||||
|
||||
public int getApplicationVersion()
|
||||
{
|
||||
try {
|
||||
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
return packageInfo.versionCode;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
System.out.println("libSDL: Cannot get the version of our own package: " + e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public FrameLayout getVideoLayout() { return _videoLayout; }
|
||||
|
||||
static int NOTIFY_ID = 12367098; // Random ID
|
||||
|
||||
@@ -56,6 +56,9 @@ import android.widget.TextView;
|
||||
import android.widget.EditText;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannedString;
|
||||
import android.content.Intent;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.AlarmManager;
|
||||
|
||||
|
||||
// TODO: too much code here, split into multiple files, possibly auto-generated menus?
|
||||
@@ -143,6 +146,7 @@ class Settings
|
||||
out.writeBoolean(Globals.OptionalDataDownload[i]);
|
||||
out.writeBoolean(Globals.BrokenLibCMessageShown);
|
||||
out.writeInt(Globals.TouchscreenKeyboardDrawSize);
|
||||
out.writeInt(p.getApplicationVersion());
|
||||
|
||||
out.close();
|
||||
settingsLoaded = true;
|
||||
@@ -279,11 +283,27 @@ class Settings
|
||||
Globals.OptionalDataDownload[i] = settingsFile.readBoolean();
|
||||
Globals.BrokenLibCMessageShown = settingsFile.readBoolean();
|
||||
Globals.TouchscreenKeyboardDrawSize = settingsFile.readInt();
|
||||
int cfgVersion = settingsFile.readInt();
|
||||
System.out.println("libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion());
|
||||
if( Globals.ResetSdlConfigForThisVersion && cfgVersion < p.getApplicationVersion() )
|
||||
{
|
||||
System.out.println("libSDL: old cfg version " + cfgVersion + ", our version " + p.getApplicationVersion() + " and we need to clean up config file");
|
||||
// Delete settings file, and restart the application
|
||||
settingsFile.close();
|
||||
ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE ));
|
||||
out.writeInt(-1);
|
||||
out.close();
|
||||
new File( p.getFilesDir() + "/" + SettingsFileName ).delete();
|
||||
PendingIntent intent = PendingIntent.getActivity(p, 0, new Intent(p.getIntent()), p.getIntent().getFlags());
|
||||
AlarmManager mgr = (AlarmManager) p.getSystemService(Context.ALARM_SERVICE);
|
||||
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, intent);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
settingsLoaded = true;
|
||||
|
||||
System.out.println("libSDL: Settings.Load(): loaded settings successfully");
|
||||
|
||||
settingsFile.close();
|
||||
return;
|
||||
|
||||
} catch( FileNotFoundException e ) {
|
||||
|
||||
Reference in New Issue
Block a user