mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 11:35:05 +08:00
48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package in.celest.xash3d;
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.util.Log;
|
|
import java.io.FileOutputStream;
|
|
import java.io.InputStream;
|
|
import android.content.SharedPreferences;
|
|
|
|
public class InstallReceiver extends BroadcastReceiver {
|
|
private static final String TAG = "XASH3D";
|
|
@Override
|
|
public void onReceive(Context context, Intent arg1) {
|
|
Log.d( TAG, "Install received, extracting PAK" );
|
|
if( context.getPackageName() == arg1.getData().getEncodedSchemeSpecificPart() )
|
|
extractPAK(context, true);
|
|
}
|
|
public static SharedPreferences mPref = null;
|
|
private static final int PAK_VERSION = 5;
|
|
public static void extractPAK(Context context, Boolean force) {
|
|
InputStream is = null;
|
|
FileOutputStream os = null;
|
|
try {
|
|
if( mPref == null )
|
|
mPref = context.getSharedPreferences("engine", 0);
|
|
if( mPref.getInt( "pakversion", 0 ) == PAK_VERSION && !force )
|
|
return;
|
|
String path = context.getFilesDir().getPath()+"/extras.pak";
|
|
|
|
is = context.getAssets().open("extras.pak");
|
|
os = new FileOutputStream(path);
|
|
byte[] buffer = new byte[1024];
|
|
int length;
|
|
while ((length = is.read(buffer)) > 0) {
|
|
os.write(buffer, 0, length);
|
|
}
|
|
os.close();
|
|
is.close();
|
|
SharedPreferences.Editor editor = mPref.edit();
|
|
editor.putInt( "pakversion", PAK_VERSION );
|
|
editor.commit();
|
|
} catch( Exception e )
|
|
{
|
|
Log.e( TAG, "Failed to extract PAK:" + e.toString() );
|
|
}
|
|
}
|
|
}
|