mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-10-31 19:44:20 +00:00
* i18n improving for Android [ci skip]
This commit is contained in:
parent
2a162d948f
commit
cd671cce48
|
@ -19,7 +19,7 @@ android {
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters 'x86', 'arm64-v8a', 'armeabi-v7a'
|
abiFilters 'arm64-v8a'
|
||||||
stl = "c++_shared"
|
stl = "c++_shared"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,15 @@ android {
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters 'x86', 'arm64-v8a', 'armeabi-v7a'
|
||||||
|
stl = "c++_shared"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug {
|
||||||
|
jniDebuggable true
|
||||||
|
renderscriptDebuggable true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,13 +89,7 @@ println("cargo target: ${project.buildDir.getAbsolutePath()}/rust-target")
|
||||||
println("ndk dir: ${android.ndkDirectory}")
|
println("ndk dir: ${android.ndkDirectory}")
|
||||||
|
|
||||||
cargoNdk {
|
cargoNdk {
|
||||||
targets = [
|
|
||||||
"x86",
|
|
||||||
"arm",
|
|
||||||
"arm64"
|
|
||||||
]
|
|
||||||
librariesNames = ["libdrsandroid.so"]
|
librariesNames = ["libdrsandroid.so"]
|
||||||
//targetDirectory = "${project.buildDir.getAbsolutePath()}/rust-target"
|
|
||||||
module = "../drsandroid/"
|
module = "../drsandroid/"
|
||||||
extraCargoEnv = ["ANDROID_NDK_HOME": android.ndkDirectory]
|
extraCargoEnv = ["ANDROID_NDK_HOME": android.ndkDirectory]
|
||||||
extraCargoBuildArguments = []
|
extraCargoBuildArguments = []
|
||||||
|
@ -95,9 +98,17 @@ cargoNdk {
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
buildType = "release"
|
buildType = "release"
|
||||||
|
targets = [
|
||||||
|
"x86",
|
||||||
|
"arm",
|
||||||
|
"arm64"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
buildType = "debug"
|
buildType = "debug"
|
||||||
|
targets = [
|
||||||
|
"arm64"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import android.widget.TextView;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Locale;
|
import java.util.ArrayList;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
@ -41,18 +41,32 @@ public class DownloadActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DownloadThread extends Thread {
|
private class DownloadThread extends Thread {
|
||||||
private static final String DOWNLOAD_URL = "https://www.cavestory.org/downloads/cavestoryen.zip";
|
private final ArrayList<DownloadEntry> urls = new ArrayList<>();
|
||||||
|
|
||||||
|
private final ArrayList<String> filesWhitelist = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
this.filesWhitelist.add("data/");
|
||||||
|
this.filesWhitelist.add("Doukutsu.exe");
|
||||||
|
|
||||||
|
//BE CAREFUL, DON'T SET `true` VALUE FOR TRANSLATIONS
|
||||||
|
this.urls.add(new DownloadEntry(R.string.download_entries_base, "https://www.cavestory.org/downloads/cavestoryen.zip", true));
|
||||||
|
|
||||||
|
for (DownloadEntry entry : this.urls) {
|
||||||
|
this.download(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void download(DownloadEntry downloadEntry) {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
URL url = new URL(DOWNLOAD_URL);
|
URL url = new URL(downloadEntry.url);
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
throw new IllegalStateException("Bad HTTP response code: " + connection.getResponseCode());
|
throw new IllegalStateException(getString(R.string.download_status_error_http, connection.getResponseCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileLength = connection.getContentLength();
|
int fileLength = connection.getContentLength();
|
||||||
|
@ -80,8 +94,8 @@ public class DownloadActivity extends AppCompatActivity {
|
||||||
if (last + 1000 >= now) {
|
if (last + 1000 >= now) {
|
||||||
int speed = (int) ((downloaded - downloadedLast) / 1024.0);
|
int speed = (int) ((downloaded - downloadedLast) / 1024.0);
|
||||||
String text = (fileLength > 0)
|
String text = (fileLength > 0)
|
||||||
? String.format(Locale.ENGLISH, "Downloading... %d%% (%d/%d KiB, %d KiB/s)", downloaded * 100 / fileLength, downloaded / 1024, fileLength / 1024, speed)
|
? getString(R.string.download_status_downloading, downloadEntry.name, downloaded * 100 / fileLength, downloaded / 1024, fileLength / 1024, speed)
|
||||||
: String.format(Locale.ENGLISH, "Downloading... --%% (%d KiB, %d KiB/s)", downloaded / 1024, speed);
|
: getString(R.string.download_status_downloading_null, downloadEntry.name, downloaded / 1024, speed);
|
||||||
|
|
||||||
handler.post(() -> txtProgress.setText(text));
|
handler.post(() -> txtProgress.setText(text));
|
||||||
|
|
||||||
|
@ -96,36 +110,9 @@ public class DownloadActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
new File(basePath).mkdirs();
|
new File(basePath).mkdirs();
|
||||||
try (ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(zipFile))) {
|
this.unpack(zipFile, downloadEntry.isBase);
|
||||||
ZipEntry entry;
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
while ((entry = in.getNextEntry()) != null) {
|
|
||||||
String entryName = entry.getName();
|
|
||||||
|
|
||||||
// strip prefix
|
handler.post(() -> txtProgress.setText(getString(R.string.download_status_done)));
|
||||||
if (entryName.startsWith("CaveStory/")) {
|
|
||||||
entryName = entryName.substring("CaveStory/".length());
|
|
||||||
}
|
|
||||||
|
|
||||||
final String s = entryName;
|
|
||||||
handler.post(() -> txtProgress.setText("Unpacking: " + s));
|
|
||||||
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
new File(basePath + entryName).mkdirs();
|
|
||||||
} else {
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(basePath + entryName)) {
|
|
||||||
int count;
|
|
||||||
while ((count = in.read(buffer)) != -1) {
|
|
||||||
fos.write(buffer, 0, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
in.closeEntry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handler.post(() -> txtProgress.setText("Done!"));
|
|
||||||
|
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
Intent intent = new Intent(DownloadActivity.this, GameActivity.class);
|
Intent intent = new Intent(DownloadActivity.this, GameActivity.class);
|
||||||
|
@ -143,5 +130,70 @@ public class DownloadActivity extends AppCompatActivity {
|
||||||
if (connection != null) connection.disconnect();
|
if (connection != null) connection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void unpack(byte[] zipFile, boolean isBase) throws IOException {
|
||||||
|
ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(zipFile));
|
||||||
|
ZipEntry entry;
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
while ((entry = in.getNextEntry()) != null) {
|
||||||
|
String entryName = entry.getName();
|
||||||
|
|
||||||
|
// strip prefix
|
||||||
|
if (entryName.startsWith("CaveStory/")) {
|
||||||
|
entryName = entryName.substring("CaveStory/".length());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.entryInWhitelist(entryName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final String s = entryName;
|
||||||
|
handler.post(() -> txtProgress.setText(
|
||||||
|
getString(R.string.download_status_unpacking, s)
|
||||||
|
));
|
||||||
|
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
new File(basePath + entryName).mkdirs();
|
||||||
|
} else {
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(basePath + entryName)) {
|
||||||
|
int count;
|
||||||
|
while ((count = in.read(buffer)) != -1) {
|
||||||
|
fos.write(buffer, 0, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
in.closeEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean entryInWhitelist(String entry) {
|
||||||
|
for (String file : this.filesWhitelist) {
|
||||||
|
if (entry.startsWith(file)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DownloadEntry {
|
||||||
|
public String name; //e.g. "Polish translation", "Base data files"
|
||||||
|
public String url;
|
||||||
|
public boolean isBase = false;
|
||||||
|
|
||||||
|
DownloadEntry(String name, String url, boolean isBase) {
|
||||||
|
this.name = name;
|
||||||
|
this.url = url;
|
||||||
|
this.isBase = isBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadEntry(int name, String url, boolean isBase) {
|
||||||
|
this.name = getString(name);
|
||||||
|
this.url = url;
|
||||||
|
this.isBase = isBase;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
File f = new File(getFilesDir().getAbsolutePath() + "/data/");
|
File f = new File(getFilesDir().getAbsolutePath() + "/data/");
|
||||||
String[] list = f.list();
|
String[] list = f.list();
|
||||||
if (!f.exists() || (list != null && list.length == 0)) {
|
if (!f.exists() || (list != null && list.length == 0)) {
|
||||||
messageBox("Missing data files", "No data files found, would you like to download them?", () -> {
|
messageBox(getString(R.string.download_title), getString(R.string.download_desc), () -> {
|
||||||
Intent intent = new Intent(this, DownloadActivity.class);
|
Intent intent = new Intent(this, DownloadActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -1,4 +1,17 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">doukutsu-rs</string>
|
<string name="app_name">doukutsu-rs</string>
|
||||||
<string name="document_provider_name">doukutsu-rs game data</string>
|
<string name="document_provider_name">doukutsu-rs game data</string>
|
||||||
|
|
||||||
|
<string name="download_title">Missing data files</string>
|
||||||
|
<string name="download_desc">No data files found, would you like to download them?</string>
|
||||||
|
|
||||||
|
<string name="download_status_error_http">Bad HTTP response code: %d</string>
|
||||||
|
<!-- Downloading {entry_name}... {percentage progress}% ({downloaded}/{from} KiB, {speed} KiB/s) -->
|
||||||
|
<string name="download_status_downloading">Downloading %s… %d%% (%d/%d KiB, %d KiB/s)</string>
|
||||||
|
<string name="download_status_downloading_null">Downloading %s… --%% (%d KiB, %d KiB/s)</string>
|
||||||
|
<string name="download_status_unpacking">Unpacking: %s</string>
|
||||||
|
<string name="download_status_done">Done!</string>
|
||||||
|
|
||||||
|
<!-- Look {entry_name} on 9th line -->
|
||||||
|
<string name="download_entries_base">base game files</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue