mirror of
https://github.com/izzy2lost/Shipwright-Android.git
synced 2026-07-05 15:19:26 -07:00
Generate OTR with app
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
|
||||
package com.dishii.soh;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -17,26 +15,45 @@ public class AssetCopyUtil {
|
||||
String[] assetFiles = assetManager.list(assetsFolderPath);
|
||||
|
||||
for (String assetFile : assetFiles) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
String assetPath = assetsFolderPath + File.separator + assetFile;
|
||||
String externalPath = externalFolderPath + File.separator + assetFile;
|
||||
|
||||
try {
|
||||
in = assetManager.open(assetsFolderPath + File.separator + assetFile);
|
||||
String externalFilePath = externalFolderPath + File.separator + assetFile;
|
||||
out = new FileOutputStream(externalFilePath);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
if (assetManager.list(assetPath).length > 0) {
|
||||
// It's a directory
|
||||
// Check if the directory exists in the external storage
|
||||
File externalDir = new File(externalPath);
|
||||
if (!externalDir.exists()) {
|
||||
externalDir.mkdirs(); // Create the directory if it doesn't exist
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
// Recursively copy contents of the directory
|
||||
copyAssetsToExternal(context, assetPath, externalPath);
|
||||
} else {
|
||||
// It's a file
|
||||
File externalFile = new File(externalPath);
|
||||
if (!externalFile.exists()) {
|
||||
// Check if the file exists in the external storage
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
in = assetManager.open(assetPath);
|
||||
out = new FileOutputStream(externalPath);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.provider.Settings;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -20,4 +21,40 @@ import android.util.Log;
|
||||
//This class is the main SDLActivity
|
||||
public class MainActivity extends SDLActivity{
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//Check if folder/file exists and if it doesn't, create it
|
||||
File externalAssetsDir = new File(getExternalFilesDir(null), "assets");
|
||||
if (!externalAssetsDir.exists()) {
|
||||
try {
|
||||
externalAssetsDir.mkdirs();
|
||||
AssetCopyUtil.copyAssetsToExternal(this, "assets", externalAssetsDir.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
File externalSohOtrFile = new File(getExternalFilesDir(null), "soh.otr");
|
||||
if (!externalSohOtrFile.exists()) {
|
||||
try {
|
||||
InputStream in = getAssets().open("soh.otr");
|
||||
OutputStream out = new FileOutputStream(externalSohOtrFile);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user