set one timestamp when saving game, and another on game creation.

This commit is contained in:
Andy2 2011-01-19 06:54:23 -08:00
parent 7d6e136ca3
commit a8f4d772f8
4 changed files with 22 additions and 12 deletions

View file

@ -27,6 +27,7 @@ import android.database.Cursor;
import java.util.StringTokenizer;
import android.content.ContentValues;
import java.util.ArrayList;
import java.util.Date;
import junit.framework.Assert;
import org.eehouse.android.xw4.jni.*;
@ -356,7 +357,8 @@ public class DBUtils {
}
}
public static void saveGame( Context context, String path, byte[] bytes )
public static void saveGame( Context context, String path, byte[] bytes,
boolean setCreate )
{
initDB( context );
synchronized( s_dbHelper ) {
@ -366,6 +368,12 @@ public class DBUtils {
ContentValues values = new ContentValues();
values.put( DBHelper.SNAPSHOT, bytes );
long timestamp = new Date().getTime();
if ( setCreate ) {
values.put( DBHelper.CREATE_TIME, timestamp );
}
values.put( DBHelper.LASTPLAY_TIME, timestamp );
int result = db.update( DBHelper.TABLE_NAME_SUM,
values, selection, null );
if ( 0 == result ) {

View file

@ -37,7 +37,7 @@ public class GameConverter {
Utils.logf( "GameConverter::convert() converting %s",
game );
byte[] bytes = savedGame( context, game );
DBUtils.saveGame( context, game, bytes );
DBUtils.saveGame( context, game, bytes, true );
context.deleteFile( game );
}
}

View file

@ -79,7 +79,7 @@ public class GameUtils {
if ( null != addr ) {
XwJNI.comms_setAddr( gamePtr, addr );
}
saveGame( context, gamePtr, gi, pathOut );
saveGame( context, gamePtr, gi, pathOut, true );
GameSummary summary = new GameSummary( gi );
XwJNI.game_summarize( gamePtr, summary );
@ -142,27 +142,29 @@ public class GameUtils {
}
public static void saveGame( Context context, int gamePtr,
CurGameInfo gi, String path )
CurGameInfo gi, String path,
boolean setCreate )
{
byte[] stream = XwJNI.game_saveToStream( gamePtr, gi );
saveGame( context, stream, path );
saveGame( context, stream, path, setCreate );
}
public static void saveGame( Context context, int gamePtr,
CurGameInfo gi )
{
saveGame( context, gamePtr, gi, newName( context ) );
saveGame( context, gamePtr, gi, newName( context ), false );
}
public static void saveGame( Context context, byte[] bytes, String path )
public static void saveGame( Context context, byte[] bytes,
String path, boolean setCreate )
{
DBUtils.saveGame( context, path, bytes );
DBUtils.saveGame( context, path, bytes, setCreate );
}
public static String saveGame( Context context, byte[] bytes )
{
String name = newName( context );
saveGame( context, bytes, name );
saveGame( context, bytes, name, false );
return name;
}
@ -372,7 +374,7 @@ public class GameUtils {
CommonPrefs.get( context ) );
gi.dictName = dict;
saveGame( context, gamePtr, gi, path );
saveGame( context, gamePtr, gi, path, false );
GameSummary summary = new GameSummary( gi );
XwJNI.game_summarize( gamePtr, summary );
@ -415,7 +417,7 @@ public class GameUtils {
XwJNI.comms_setAddr( gamePtr, car );
}
GameUtils.saveGame( context, gamePtr, gi, path );
saveGame( context, gamePtr, gi, path, false );
GameSummary summary = new GameSummary( gi );
XwJNI.game_summarize( gamePtr, summary );

View file

@ -262,7 +262,7 @@ public class JNIThread extends Thread {
GameSummary summary = new GameSummary( m_gi );
XwJNI.game_summarize( m_jniGamePtr, summary );
byte[] state = XwJNI.game_saveToStream( m_jniGamePtr, null );
GameUtils.saveGame( m_context, state, m_path );
GameUtils.saveGame( m_context, state, m_path, false );
DBUtils.saveSummary( m_context, m_path, summary );
break;