mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-05-19 16:42:13 +00:00
Honey Cake
This commit is contained in:
parent
b7263434ad
commit
cdf19ab17d
15 changed files with 311 additions and 110 deletions
|
|
@ -1,14 +1,22 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static com.vectras.vm.VectrasApp.isFileExists;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
|
@ -77,11 +85,11 @@ public class VMManager {
|
|||
public static String idGenerator() {
|
||||
String _result = startRamdomVMID();
|
||||
|
||||
if (VectrasApp.isFileExists(AppConfig.maindirpath + "/roms/" + _result)) {
|
||||
if (isFileExists(AppConfig.maindirpath + "/roms/" + _result)) {
|
||||
_result = startRamdomVMID();
|
||||
}
|
||||
|
||||
if (VectrasApp.isFileExists(AppConfig.maindirpath + "/roms/" + _result)) {
|
||||
if (isFileExists(AppConfig.maindirpath + "/roms/" + _result)) {
|
||||
_result = startRamdomVMID();
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +148,7 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
_currentVMIDToScan = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.txt").replace("\n", "");
|
||||
if (!_currentVMIDToScan.isEmpty()) {
|
||||
if (_currentVMIDToScan.equals(pendingVMID)) {
|
||||
|
|
@ -169,7 +177,7 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
_currentVMIDToScan = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.txt").replace("\n", "");
|
||||
if (!_currentVMIDToScan.isEmpty()) {
|
||||
if (_currentVMIDToScan.equals(_vmID)) {
|
||||
|
|
@ -200,7 +208,7 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
_currentVMIDToScan = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.txt").replace("\n", "");
|
||||
if (!_currentVMIDToScan.isEmpty()) {
|
||||
if (_currentVMIDToScan.equals(pendingVMID)) {
|
||||
|
|
@ -224,7 +232,7 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (!VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (!isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (!finalJson.contains(_filelist.get((int) (_startRepeat)))) {
|
||||
VectrasApp.deleteDirectory(_filelist.get((int) (_startRepeat)));
|
||||
}
|
||||
|
|
@ -246,8 +254,8 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (!VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/rom-data.json")) {
|
||||
if (!isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/rom-data.json")) {
|
||||
if (VectrasApp.checkJSONMapIsNormalFromString(VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json"))) {
|
||||
if (_resulttemp.contains("}")) {
|
||||
_resulttemp += "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
|
|
@ -260,7 +268,7 @@ public class VMManager {
|
|||
} else {
|
||||
_result = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
}
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
enableVMID(VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt"));
|
||||
} else {
|
||||
VectrasApp.writeToFile(_filelist.get((int)(_startRepeat)), "/vmID.txt", VMManager.idGenerator());
|
||||
|
|
@ -272,7 +280,7 @@ public class VMManager {
|
|||
} else {
|
||||
_result = "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
}
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
enableVMID(VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt"));
|
||||
} else {
|
||||
VectrasApp.writeToFile(_filelist.get((int)(_startRepeat)), "/vmID.txt", VMManager.idGenerator());
|
||||
|
|
@ -289,7 +297,7 @@ public class VMManager {
|
|||
if (_startRepeat == _filelist.size()) {
|
||||
if (!_result.isEmpty()) {
|
||||
if (VectrasApp.checkJSONIsNormalFromString("[" + _result + "]")) {
|
||||
if (VectrasApp.isFileExists(AppConfig.romsdatajson)) {
|
||||
if (isFileExists(AppConfig.romsdatajson)) {
|
||||
if (VectrasApp.checkJSONIsNormal(AppConfig.romsdatajson)) {
|
||||
String _JSONcontent = VectrasApp.readFile(AppConfig.romsdatajson);
|
||||
String _JSONcontentnew = _JSONcontent.replaceAll("]", _result + "]");
|
||||
|
|
@ -317,6 +325,77 @@ public class VMManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static void startFixRomsDataJson() {
|
||||
int _startRepeat = 0;
|
||||
String _resulttemp ="";
|
||||
String _result ="";
|
||||
restoredVMs = 0;
|
||||
ArrayList<String> _filelist = new ArrayList<>();
|
||||
VectrasApp.listDir(AppConfig.vmFolder, _filelist);
|
||||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/rom-data.json")) {
|
||||
if (VectrasApp.checkJSONMapIsNormalFromString(VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json"))) {
|
||||
if (_resulttemp.contains("}")) {
|
||||
_resulttemp += "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
} else {
|
||||
_resulttemp = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
}
|
||||
if (VectrasApp.checkJSONIsNormalFromString(VectrasApp.readFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
} else {
|
||||
_result = VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
}
|
||||
restoredVMs++;
|
||||
} else if (VectrasApp.checkJSONIsNormalFromString(VectrasApp.readFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", "," + _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
} else {
|
||||
_result = "," + VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
}
|
||||
restoredVMs++;
|
||||
} else {
|
||||
Log.i("CqcmActivity", VectrasApp.readFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", _resulttemp + "]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_startRepeat++;
|
||||
if (_startRepeat == _filelist.size()) {
|
||||
if (!_result.isEmpty()) {
|
||||
if (VectrasApp.checkJSONIsNormalFromString("[" + _result + "]")) {
|
||||
if (isFileExists(AppConfig.romsdatajson)) {
|
||||
if (VectrasApp.checkJSONIsNormal(AppConfig.romsdatajson)) {
|
||||
String _JSONcontent = VectrasApp.readFile(AppConfig.romsdatajson);
|
||||
String _JSONcontentnew = _JSONcontent.replaceAll("]", _result + "]");
|
||||
if (VectrasApp.checkJSONIsNormalFromString(_JSONcontentnew.replaceAll("u003d", "="))) {
|
||||
VectrasApp.writeToFile(AppConfig.maindirpath, "roms-data.json", _JSONcontentnew.replaceAll("u003d", "="));
|
||||
} else {
|
||||
restoredVMs = 0;
|
||||
}
|
||||
} else {
|
||||
restoredVMs = 0;
|
||||
}
|
||||
} else {
|
||||
VectrasApp.writeToFile(AppConfig.maindirpath, "roms-data.json", "[" + _result + "]");
|
||||
}
|
||||
} else {
|
||||
restoredVMs = 0;
|
||||
}
|
||||
} else {
|
||||
restoredVMs = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void enableVMID(String _vmID) {
|
||||
if (_vmID.isEmpty())
|
||||
return;
|
||||
|
|
@ -326,7 +405,7 @@ public class VMManager {
|
|||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (VectrasApp.isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
if (VectrasApp.readFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt").equals(_vmID)) {
|
||||
VectrasApp.moveAFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt", _filelist.get((int)(_startRepeat)) + "/vmID.txt");
|
||||
}
|
||||
|
|
@ -337,6 +416,31 @@ public class VMManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static void movetoRecycleBin() {
|
||||
File vDir = new File(AppConfig.recyclebin);
|
||||
if (!vDir.exists()) {
|
||||
if (!vDir.mkdirs()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
finalJson = VectrasApp.readFile(AppConfig.romsdatajson);
|
||||
if (!finalJson.isEmpty()) {
|
||||
int _startRepeat = 0;
|
||||
ArrayList<String> _filelist = new ArrayList<>();
|
||||
VectrasApp.listDir(AppConfig.vmFolder, _filelist);
|
||||
if (!_filelist.isEmpty()) {
|
||||
for (int _repeat = 0; _repeat < (int)(_filelist.size()); _repeat++) {
|
||||
if (_startRepeat < _filelist.size()) {
|
||||
if (!finalJson.contains(Uri.parse(_filelist.get((int) (_startRepeat))).getLastPathSegment())) {
|
||||
VectrasApp.moveAFile(_filelist.get((int) (_startRepeat)), AppConfig.recyclebin + Uri.parse(_filelist.get((int) (_startRepeat))).getLastPathSegment());
|
||||
}
|
||||
}
|
||||
_startRepeat++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String quickScanDiskFileInFolder(String _foderpath) {
|
||||
if (!_foderpath.isEmpty()) {
|
||||
int _startRepeat = 0;
|
||||
|
|
@ -397,20 +501,117 @@ public class VMManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void setArch(String _arch, Context _context) {
|
||||
public static void setArch(String _arch, Activity _activity) {
|
||||
switch (_arch) {
|
||||
case "I386":
|
||||
MainSettingsManager.setArch(MainActivity.activity, "I386");
|
||||
MainSettingsManager.setArch(_activity, "I386");
|
||||
break;
|
||||
case "ARM64":
|
||||
MainSettingsManager.setArch(MainActivity.activity, "ARM64");
|
||||
MainSettingsManager.setArch(_activity, "ARM64");
|
||||
break;
|
||||
case "PPC":
|
||||
MainSettingsManager.setArch(MainActivity.activity, "PPC");
|
||||
MainSettingsManager.setArch(_activity, "PPC");
|
||||
break;
|
||||
default:
|
||||
MainSettingsManager.setArch(MainActivity.activity, "X86_64");
|
||||
MainSettingsManager.setArch(_activity, "X86_64");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isExecutedCommandError(String _command, String _result, Activity _activity) {
|
||||
if (!_command.contains("qemu-system") || _result.contains("Killed"))
|
||||
return false;
|
||||
//Error code: PROOT_IS_MISSING_0
|
||||
if (_result.contains("proot\": error=2,")) {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(_activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(_activity.getResources().getString(R.string.problem_has_been_detected));
|
||||
alertDialog.setMessage(_activity.getResources().getString(R.string.error_PROOT_IS_MISSING_0));
|
||||
alertDialog.setCancelable(false);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, _activity.getResources().getString(R.string.continuetext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MainActivity.isActivate = false;
|
||||
VectrasApp.deleteDirectory(_activity.getFilesDir().getAbsolutePath() + "/data");
|
||||
VectrasApp.deleteDirectory(_activity.getFilesDir().getAbsolutePath() + "/distro");
|
||||
VectrasApp.deleteDirectory(_activity.getFilesDir().getAbsolutePath() + "/usr");
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(_activity, SplashActivity.class);
|
||||
_activity.startActivity(intent);
|
||||
_activity.finish();
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, _activity.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
return true;
|
||||
} else if (_result.contains(") exists") && _result.contains("drive with bus")) {
|
||||
//Error code: DRIVE_INDEX_0_EXISTS
|
||||
VectrasApp.oneDialog(_activity.getResources().getString(R.string.problem_has_been_detected), _activity.getResources().getString(R.string.error_DRIVE_INDEX_0_EXISTS), true, false, _activity);
|
||||
return true;
|
||||
} else if (_result.contains("gtk initialization failed") || _result.contains("x11 not available")) {
|
||||
//Error code: X11_NOT_AVAILABLE
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(_activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(_activity.getResources().getString(R.string.problem_has_been_detected));
|
||||
alertDialog.setMessage(_activity.getResources().getString(R.string.error_X11_NOT_AVAILABLE));
|
||||
alertDialog.setCancelable(false);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, _activity.getResources().getString(R.string.continuetext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MainSettingsManager.setVmUi(_activity, "VNC");
|
||||
VectrasApp.oneDialog(_activity.getResources().getString(R.string.done), _activity.getResources().getString(R.string.switched_to_VNC), true, false, _activity);
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, _activity.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRomsDataJsonNormal(Boolean _needfix, Context _context) {
|
||||
if (isFileExists(AppConfig.romsdatajson)) {
|
||||
if (!VectrasApp.checkJSONIsNormal(AppConfig.romsdatajson)) {
|
||||
if (_needfix) {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(_context, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(_context.getResources().getString(R.string.oops));
|
||||
alertDialog.setMessage(_context.getResources().getString(R.string.need_fix_json_before_create));
|
||||
alertDialog.setCancelable(true);
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, _context.getResources().getString(R.string.continuetext), (dialog, which) -> {
|
||||
VectrasApp.moveAFile(AppConfig.maindirpath + "roms-data.json", AppConfig.maindirpath + "roms-data.old.json");
|
||||
VectrasApp.writeToFile(AppConfig.maindirpath, "roms-data.json", "[]");
|
||||
startFixRomsDataJson();
|
||||
fixRomsDataJsonResult(_context);
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, _context.getResources().getString(R.string.cancel), (dialog, which) -> {
|
||||
|
||||
});
|
||||
alertDialog.show();
|
||||
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
VectrasApp.writeToFile(AppConfig.maindirpath, "roms-data.json", "[]");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixRomsDataJsonResult(Context _context) {
|
||||
if (restoredVMs == 0) {
|
||||
VectrasApp.oneDialogWithContext(_context.getString(R.string.done), _context.getString(R.string.roms_data_json_fixed_unsuccessfully),true, _context);
|
||||
} else {
|
||||
VectrasApp.oneDialogWithContext(_context.getString(R.string.done), _context.getString(R.string.roms_data_json_fixed_successfully),true, _context);
|
||||
}
|
||||
MainActivity.loadDataVbi();
|
||||
MainActivity.mdatasize2();
|
||||
movetoRecycleBin();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue