Option to clean up SDL config left from the old app version

This commit is contained in:
pelya
2011-11-16 17:30:29 +02:00
parent d5313cb08e
commit 90014495ee
5 changed files with 65 additions and 9 deletions

View File

@@ -405,8 +405,8 @@ fi
if [ -z "$MultiABI" -o -z "$AUTO" ]; then
echo
echo "Enable multi-ABI binary, with hardware FPU support - "
echo -n "it will also work on old devices, but .apk size is 2x bigger (y) or (n) ($MultiABI): "
echo "Enable multi-ABI binary, with hardware FPU support - it will also work on old devices,"
echo -n "but .apk size is 2x bigger (y) / (n) / (x86) / (all) ($MultiABI): "
read var
if [ -n "$var" ] ; then
MultiABI="$var"
@@ -434,6 +434,16 @@ if [ -n "$var" ] ; then
fi
fi
if [ -z "$ResetSdlConfigForThisVersion" -o -z "$AUTO" ]; then
echo
echo "Reset SDL config when updating application to the new version (y) / (n) ($ResetSdlConfigForThisVersion): "
read var
if [ -n "$var" ] ; then
ResetSdlConfigForThisVersion="$var"
CHANGED=1
fi
fi
if [ -z "$CustomBuildScript" -o -z "$AUTO" ]; then
echo
echo -n "Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n) ($CustomBuildScript): "
@@ -564,6 +574,7 @@ echo FirstStartMenuOptions=\'$FirstStartMenuOptions\' >> AndroidAppSettings.cfg
echo MultiABI=$MultiABI >> AndroidAppSettings.cfg
echo AppVersionCode=$AppVersionCode >> AndroidAppSettings.cfg
echo AppVersionName=\"$AppVersionName\" >> AndroidAppSettings.cfg
echo ResetSdlConfigForThisVersion=$ResetSdlConfigForThisVersion >> AndroidAppSettings.cfg
echo CompiledLibraries=\"$CompiledLibraries\" >> AndroidAppSettings.cfg
echo CustomBuildScript=$CustomBuildScript >> AndroidAppSettings.cfg
echo AppCflags=\'$AppCflags\' >> AndroidAppSettings.cfg
@@ -700,6 +711,12 @@ else
NonBlockingSwapBuffers=false
fi
if [ "$ResetSdlConfigForThisVersion" = "y" ] ; then
ResetSdlConfigForThisVersion=true
else
ResetSdlConfigForThisVersion=false
fi
KEY2=0
for KEY in $RedefinedKeys; do
RedefinedKeycodes="$RedefinedKeycodes -DSDL_ANDROID_KEYCODE_$KEY2=$KEY"
@@ -714,9 +731,14 @@ done
if [ "$MultiABI" = "y" ] ; then
MultiABI="armeabi armeabi-v7a"
elif [ "$MultiABI" = "x86" ] ; then
MultiABI="armeabi x86"
elif [ "$MultiABI" = "all" ] ; then
MultiABI="all" # Starting form NDK r7
else
MultiABI="armeabi"
fi
LibrariesToLoad="\\\"sdl-$LibSdlVersion\\\""
StaticLibraries=`grep 'APP_AVAILABLE_STATIC_LIBS' project/jni/SettingsTemplate.mk | sed 's/.*=\(.*\)/\1/'`
for lib in $CompiledLibraries; do
@@ -785,6 +807,7 @@ cat project/src/Globals.java | \
sed "s/public static boolean AppHandlesJoystickSensitivity = .*;/public static boolean AppHandlesJoystickSensitivity = $AppHandlesJoystickSensitivity;/" | \
sed "s/public static boolean AppUsesMultitouch = .*;/public static boolean AppUsesMultitouch = $AppUsesMultitouch;/" | \
sed "s/public static boolean NonBlockingSwapBuffers = .*;/public static boolean NonBlockingSwapBuffers = $NonBlockingSwapBuffers;/" | \
sed "s/public static boolean ResetSdlConfigForThisVersion = .*;/public static boolean ResetSdlConfigForThisVersion = $ResetSdlConfigForThisVersion;/" | \
sed "s/public static int AppTouchscreenKeyboardKeysAmount = .*;/public static int AppTouchscreenKeyboardKeysAmount = $AppTouchscreenKeyboardKeysAmount;/" | \
sed "s/public static int AppTouchscreenKeyboardKeysAmountAutoFire = .*;/public static int AppTouchscreenKeyboardKeysAmountAutoFire = $AppTouchscreenKeyboardKeysAmountAutoFire;/" | \
sed "s/public static int StartupMenuButtonTimeout = .*;/public static int StartupMenuButtonTimeout = $StartupMenuButtonTimeout;/" | \

View File

@@ -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;

View File

@@ -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

View File

@@ -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 ) {

View File

@@ -5,7 +5,7 @@ AppName="Free Heroes 2"
AppFullName=net.sourceforge.fheroes2
ScreenOrientation=h
InhibitSuspend=n
AppDataDownloadUrl="Heroes 2 DEMO (45 Mb) - required to play|http://downloads.pcworld.com/pub/new/fun_and_games/adventure_strategy/h2demo.zip|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/h2demo.zip/download^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download^Essential map pack (9 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/EssentialMapPack.zip/download^Additional map pack (95 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/AdditionalMapPack.zip/download^Mega map pack (280 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/MegaMapPack.zip/download^!Game data|data12.zip^!Game data 2|data-cfg-fonts.zip^Russian translation|:fheroes2.cfg:fheroes2-ru.cfg^Czech translation|:fheroes2.cfg:fheroes2-cs.cfg^Spanish translation|:fheroes2.cfg:fheroes2-es.cfg^French translation|:fheroes2.cfg:fheroes2-fr.cfg^Hungarian translation|:fheroes2.cfg:fheroes2-hu.cfg^Polish translation|:fheroes2.cfg:fheroes2-pl.cfg^Portugese translation|:fheroes2.cfg:fheroes2-pt_BR.cfg^Swedish translation|:fheroes2.cfg:fheroes2-sv.cfg"
AppDataDownloadUrl="Heroes 2 DEMO (45 Mb) - required if you don't own full version|http://downloads.pcworld.com/pub/new/fun_and_games/adventure_strategy/h2demo.zip|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/h2demo.zip/download^MIDI music support (18 Mb)|http://sourceforge.net/projects/libsdl-android/files/timidity.zip/download^Essential map pack (9 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/EssentialMapPack.zip/download^Additional map pack (95 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/AdditionalMapPack.zip/download^Mega map pack (280 Mb)|http://sourceforge.net/projects/libsdl-android/files/FreeHeroes2/MegaMapPack.zip/download^!Game data|data12.zip^!Game data 2|data-cfg-fonts.zip^Russian translation|:fheroes2.cfg:fheroes2-ru.cfg^Czech translation|:fheroes2.cfg:fheroes2-cs.cfg^Spanish translation|:fheroes2.cfg:fheroes2-es.cfg^French translation|:fheroes2.cfg:fheroes2-fr.cfg^Hungarian translation|:fheroes2.cfg:fheroes2-hu.cfg^Polish translation|:fheroes2.cfg:fheroes2-pl.cfg^Portugese translation|:fheroes2.cfg:fheroes2-pt_BR.cfg^Swedish translation|:fheroes2.cfg:fheroes2-sv.cfg"
VideoDepthBpp=16
NeedDepthBuffer=n
NeedStencilBuffer=n
@@ -27,13 +27,14 @@ NonBlockingSwapBuffers=n
RedefinedKeys="LCTRL M T H E"
AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="LCTRL M T H E C SPACE C S L"
RedefinedKeysScreenKb="LCTRL M NO_REMAP NO_REMAP E C SPACE C S L"
StartupMenuButtonTimeout=3000
HiddenMenuOptions='KeyboardConfigMainMenu ScreenKeyboardThemeConfig ScreenKeyboardTransparencyConfig'
FirstStartMenuOptions=''
MultiABI=n
AppVersionCode=269917
AppVersionName="2699.17"
AppVersionCode=269918
AppVersionName="2699.18"
ResetSdlConfigForThisVersion=y
CompiledLibraries="sdl_net sdl_mixer sdl_image sdl_ttf png intl"
CustomBuildScript=n
AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple -DWITH_NET'