Skip to content

Commit

Permalink
Command line arguments and custom content support as well as changed …
Browse files Browse the repository at this point in the history
…target API level to 28 to avoid warnings on newer devicees
  • Loading branch information
h4mu committed Aug 17, 2019
1 parent 88b867d commit 24beda8
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 59 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 16
compileSdkVersion 28
defaultConfig {
applicationId "io.github.h4mu.rott94"
minSdkVersion 14
targetSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
externalNativeBuild {
Expand Down
2 changes: 2 additions & 0 deletions android/app/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ APP_ABI := all

# Min SDK level
APP_PLATFORM=android-14

APP_STL := c++_shared
21 changes: 19 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.h4mu.rott94"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">

<!-- OpenGL ES 2.0 -->
Expand Down Expand Up @@ -49,6 +47,25 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:host="*" />
<data android:pathPattern=".*\\.RTL" />
<data android:pathPattern=".*\\..*\\.RTL" />
<data android:pathPattern=".*\\..*\\..*\\.RTL" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.RTL" />
<data android:pathPattern=".*\\.RTC" />
<data android:pathPattern=".*\\..*\\.RTC" />
<data android:pathPattern=".*\\..*\\..*\\.RTC" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.RTC" />
<data android:pathPattern=".*\\.WAD" />
<data android:pathPattern=".*\\..*\\.WAD" />
<data android:pathPattern=".*\\..*\\..*\\.WAD" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.WAD" />
</intent-filter>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2014-2015 Tamas Hamor
Copyright (C) 2014-2019 Tamas Hamor
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand All @@ -19,7 +19,16 @@ of the License, or (at your option) any later version.
*/
package io.github.h4mu.rott94;

import io.github.h4mu.rott94.util.SfxFilteredInputStream;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;

import java.io.BufferedInputStream;
import java.io.File;
Expand All @@ -31,15 +40,7 @@ of the License, or (at your option) any later version.
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;
import io.github.h4mu.rott94.util.SfxFilteredInputStream;

/**
* @author hamu
Expand All @@ -59,7 +60,7 @@ public class ContentPrepareActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isGameContentInstalled()) {
startActivity(new Intent(this, rott94Activity.class));
startActivity(new Intent(getIntent().getAction(), getIntent().getData(), this, rott94Activity.class));
} else {
if (isShareware()) {
new AlertDialog
Expand Down Expand Up @@ -90,59 +91,65 @@ public void onClick(DialogInterface dialog, int which) {
}

private void downloadAndInstallGameContent() {
new AsyncTask<String, Void, Boolean>() {
private ProgressDialog dialog = new ProgressDialog(ContentPrepareActivity.this);

@Override
protected void onPreExecute() {
dialog.setTitle(R.string.contentDownloadingTitle);
dialog.show();
}
new BackgroundDownloadTask(this).execute(SHAREWARE_URL);
}

private class BackgroundDownloadTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog;

BackgroundDownloadTask(Context context) {
dialog = new ProgressDialog(context);
}

@Override
protected void onPreExecute() {
dialog.setTitle(R.string.contentDownloadingTitle);
dialog.show();
}

@Override
protected Boolean doInBackground(String... params) {
@Override
protected Boolean doInBackground(String... params) {
try {
ZipInputStream outerZip = new ZipInputStream(new BufferedInputStream(new URL(params[0]).openStream()));
try {
ZipInputStream outerZip = new ZipInputStream(new BufferedInputStream(new URL(params[0]).openStream()));
for (ZipEntry entry = outerZip.getNextEntry(); entry != null && !"ROTTSW13.SHR".equals(entry.getName()); entry = outerZip.getNextEntry()) {}
ZipInputStream innerZip = new ZipInputStream(new SfxFilteredInputStream(outerZip));
try {
for (ZipEntry entry = outerZip.getNextEntry(); entry != null && !"ROTTSW13.SHR".equals(entry.getName()); entry = outerZip.getNextEntry()) {}
ZipInputStream innerZip = new ZipInputStream(new SfxFilteredInputStream(outerZip));
try {
byte[] buffer = new byte[BUFFER_SIZE];
for (ZipEntry entry = innerZip.getNextEntry(); entry != null; entry = innerZip.getNextEntry()) {
FileOutputStream output = new FileOutputStream(getContentFolder().getAbsolutePath() + File.separator + entry.getName());
try {
for (int count = 0; (count = innerZip.read(buffer, 0, buffer.length)) >= 0; output.write(buffer, 0, count)) {}
} finally {
output.close();
}
byte[] buffer = new byte[BUFFER_SIZE];
for (ZipEntry entry = innerZip.getNextEntry(); entry != null; entry = innerZip.getNextEntry()) {
FileOutputStream output = new FileOutputStream(getContentFolder().getAbsolutePath() + File.separator + entry.getName());
try {
for (int count; (count = innerZip.read(buffer, 0, buffer.length)) >= 0; output.write(buffer, 0, count)) {}
} finally {
output.close();
}
} finally {
innerZip.close();
}
} finally {
outerZip.close();
innerZip.close();
}
} catch (MalformedURLException e) {
return false;
} catch (IOException e) {
return false;
} finally {
outerZip.close();
}
return true;
} catch (MalformedURLException e) {
return false;
} catch (IOException e) {
return false;
}

@Override
protected void onPostExecute(Boolean result) {
if (dialog.isShowing()) {
dialog.dismiss();
}
super.onPostExecute(result);
if (result) {
startActivity(new Intent(ContentPrepareActivity.this, rott94Activity.class));
} else {
finish();
}
return true;
}

@Override
protected void onPostExecute(Boolean result) {
if (dialog.isShowing()) {
dialog.dismiss();
}
}.execute(SHAREWARE_URL);
super.onPostExecute(result);
if (result) {
startActivity(new Intent(getIntent().getAction(), getIntent().getData(), ContentPrepareActivity.this, rott94Activity.class));
} else {
finish();
}
}
}

private boolean isGameContentInstalled() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,91 @@
/*
Copyright (C) 2014-2019 Tamas Hamor
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package io.github.h4mu.rott94;

import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import org.libsdl.app.SDLActivity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class rott94Activity extends SDLActivity
{
@Override
protected String[] getArguments() {
List<String> arguments = new ArrayList<>();
File filesDir = getExternalFilesDir(null);
if (filesDir == null) {
filesDir = getFilesDir();
}
File cmdLine = new File(filesDir.getAbsolutePath() + File.separator + "arguments.txt");
if (cmdLine.canRead()) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(cmdLine)));
try {
String line = reader.readLine();
if (line != null) {
arguments.addAll(Arrays.asList(line.split(" ")));
}
} finally {
reader.close();
}
} catch (java.io.IOException ignored) {
}
}
Uri data = getIntent().getData();
if (data != null) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(data, projection, null, null, null);
if (cursor != null) {
try {
int column_index = cursor.getColumnIndex(projection[0]);
if (column_index != -1 && cursor.moveToFirst()) {
String path = cursor.getString(column_index);
if (path != null && path.length() > 4) {
if (path.endsWith(".WAD")) {
arguments.add("FILE");
arguments.add(path);
}
else if (path.endsWith(".RTL")) {
arguments.add("FILERTL");
arguments.add(path);
}
else if (path.endsWith(".RTC")) {
arguments.add("FILERTC");
arguments.add(path);
}
}
}
} finally {
cursor.close();
}
}
}
return arguments.toArray(new String[0]);
}
}

0 comments on commit 24beda8

Please sign in to comment.