mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-29 14:59:50 +00:00
v2.9.5.3-3dfx
- Added change or eject of CD ROM, floppy disk and memory card. - Home screen no longer reloads when rotating screen.
This commit is contained in:
parent
cd42e2aa05
commit
ef7ec90817
16 changed files with 657 additions and 270 deletions
|
|
@ -653,6 +653,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
int spanCount = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2;
|
||||
mRVMainRoms.setLayoutManager(new GridLayoutManager(this, spanCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
isActivate = false;
|
||||
|
|
@ -765,7 +773,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
VectrasStatus.logInfo(String.format(error));
|
||||
}
|
||||
|
||||
public static void loadDataVbi() {
|
||||
private void loadDataVbi() {
|
||||
data = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
|
@ -815,11 +823,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
// Setup and Handover data to recyclerview
|
||||
mRVMainRoms = (RecyclerView) activity.findViewById(R.id.mRVMainRoms);
|
||||
mMainAdapter = new AdapterMainRoms(MainActivity.activity, data);
|
||||
mRVMainRoms = findViewById(R.id.mRVMainRoms);
|
||||
mMainAdapter = new AdapterMainRoms(this, data);
|
||||
mRVMainRoms.setAdapter(mMainAdapter);
|
||||
int spanCount = activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2;
|
||||
mRVMainRoms.setLayoutManager(new GridLayoutManager(MainActivity.activity, spanCount));
|
||||
int spanCount = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 3 : 2;
|
||||
mRVMainRoms.setLayoutManager(new GridLayoutManager(this, spanCount));
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
|
@ -945,6 +953,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
return;
|
||||
}
|
||||
|
||||
VMManager.lastQemuCommand = env;
|
||||
|
||||
if (VMManager.isThisVMRunning(itemExtra, itemPath)) {
|
||||
Toast.makeText(activity, "This VM is already running.", Toast.LENGTH_LONG).show();
|
||||
if (MainSettingsManager.getVmUi(activity).equals("VNC"))
|
||||
|
|
@ -1138,6 +1148,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
StartVM.cdrompath = "";
|
||||
String env = StartVM.env(MainActivity.activity, AppConfig.pendingCommand, "", "1");
|
||||
MainActivity.startVM("Quick run", env, AppConfig.pendingCommand, "");
|
||||
VMManager.lastQemuCommand = AppConfig.pendingCommand;
|
||||
}
|
||||
}
|
||||
AppConfig.pendingCommand = "";
|
||||
|
|
|
|||
|
|
@ -1,81 +1,38 @@
|
|||
package com.vectras.vm.MainRoms;
|
||||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.vectras.qemu.Config;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.qemu.MainVNCActivity;
|
||||
import com.vectras.vm.AppConfig;
|
||||
import com.vectras.vm.CustomRomActivity;
|
||||
import com.vectras.vm.ExportRomActivity;
|
||||
import com.vectras.vm.MainActivity;
|
||||
import com.vectras.vm.MainService;
|
||||
import com.vectras.vm.R;
|
||||
import com.vectras.vm.StartVM;
|
||||
import com.vectras.vm.VMManager;
|
||||
import com.vectras.vm.VectrasApp;
|
||||
import com.vectras.vm.logger.VectrasStatus;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
import com.vectras.vm.utils.UIUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.zeroturnaround.zip.FileSource;
|
||||
import org.zeroturnaround.zip.ZipEntrySource;
|
||||
import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private LayoutInflater inflater;
|
||||
private final Context context;
|
||||
private final LayoutInflater inflater;
|
||||
public List<DataMainRoms> data = Collections.emptyList();
|
||||
int currentPos = 0;
|
||||
private int mSelectedItem = -1;
|
||||
public static boolean isKeptSomeFiles = false;
|
||||
|
||||
// create constructor to innitilize context and data sent from MainActivity
|
||||
public AdapterMainRoms(Context context, List<DataMainRoms> data) {
|
||||
|
|
@ -85,18 +42,19 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
}
|
||||
|
||||
// Inflate the layout when viewholder created
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = inflater.inflate(R.layout.container_main_roms, parent, false);
|
||||
MyHolder holder = new MyHolder(view);
|
||||
return holder;
|
||||
return new MyHolder(view);
|
||||
}
|
||||
|
||||
public static final String CREDENTIAL_SHARED_PREF = "settings_prefs";
|
||||
|
||||
// Bind data
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int _position) {
|
||||
|
||||
int position = holder.getBindingAdapterPosition();
|
||||
if (position == RecyclerView.NO_POSITION) return;
|
||||
|
||||
// Get current position of item in recyclerview to bind data and assign values from list
|
||||
final MyHolder myHolder = (MyHolder) holder;
|
||||
|
|
@ -109,150 +67,54 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
Bitmap bmImg = BitmapFactory.decodeFile(current.itemIcon);
|
||||
myHolder.ivIcon.setImageBitmap(bmImg);
|
||||
}
|
||||
myHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.activity);
|
||||
View v = MainActivity.activity.getLayoutInflater().inflate(R.layout.rom_options_dialog, null);
|
||||
bottomSheetDialog.setContentView(v);
|
||||
myHolder.optionsBtn.setOnClickListener(view -> {
|
||||
|
||||
Button modifyRomBtn = v.findViewById(R.id.modifyRomBtn);
|
||||
modifyRomBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
com.vectras.vm.CustomRomActivity.current = data.get(position);
|
||||
VMManager.setArch(current.itemArch, MainActivity.activity);
|
||||
MainActivity.activity.startActivity(new Intent(MainActivity.activity, CustomRomActivity.class).putExtra("POS", position).putExtra("MODIFY", true).putExtra("VMID", current.vmID));
|
||||
bottomSheetDialog.cancel();
|
||||
}
|
||||
});
|
||||
Button exportRomBtn = v.findViewById(R.id.exportRomBtn);
|
||||
exportRomBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ExportRomActivity.pendingPosition = position;
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context.getApplicationContext(), ExportRomActivity.class);
|
||||
context.startActivity(intent);
|
||||
bottomSheetDialog.cancel();
|
||||
}
|
||||
});
|
||||
Button removeRomBtn = v.findViewById(R.id.removeRomBtn);
|
||||
removeRomBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
VMManager.deleteVMDialog(current.itemName, position, MainActivity.activity);
|
||||
bottomSheetDialog.cancel();
|
||||
}
|
||||
});
|
||||
bottomSheetDialog.show();
|
||||
}
|
||||
});
|
||||
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.activity);
|
||||
View v = MainActivity.activity.getLayoutInflater().inflate(R.layout.rom_options_dialog, null);
|
||||
bottomSheetDialog.setContentView(v);
|
||||
|
||||
myHolder.cdRoms.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
Button modifyRomBtn = v.findViewById(R.id.modifyRomBtn);
|
||||
modifyRomBtn.setOnClickListener(v3 -> {
|
||||
CustomRomActivity.current = data.get(position);
|
||||
VMManager.setArch(current.itemArch, MainActivity.activity);
|
||||
StartVM.cdrompath = current.imgCdrom;
|
||||
if (current.qmpPort == 0) {
|
||||
Config.setDefault();
|
||||
} else {
|
||||
Config.QMPPort = current.qmpPort;
|
||||
}
|
||||
Config.vmID = current.vmID;
|
||||
String env = StartVM.env(MainActivity.activity, current.itemExtra, current.itemPath, "");
|
||||
MainActivity.startVM(current.itemName, env, current.itemExtra, current.itemPath);
|
||||
}
|
||||
});
|
||||
myHolder.cdRoms.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
MainActivity.activity.startActivity(new Intent(MainActivity.activity, CustomRomActivity.class).putExtra("POS", position).putExtra("MODIFY", true).putExtra("VMID", current.vmID));
|
||||
bottomSheetDialog.cancel();
|
||||
});
|
||||
|
||||
Button exportRomBtn = v.findViewById(R.id.exportRomBtn);
|
||||
exportRomBtn.setOnClickListener(v2 -> {
|
||||
ExportRomActivity.pendingPosition = position;
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(context.getApplicationContext(), ExportRomActivity.class);
|
||||
context.startActivity(intent);
|
||||
bottomSheetDialog.cancel();
|
||||
});
|
||||
|
||||
Button removeRomBtn = v.findViewById(R.id.removeRomBtn);
|
||||
removeRomBtn.setOnClickListener(v1 -> {
|
||||
VMManager.deleteVMDialog(current.itemName, position, MainActivity.activity);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public class RomJson extends JSONObject {
|
||||
|
||||
public JSONObject makeJSONObject(String imgName, String imgArch, String imgAuthor, String imgDesc, String imgIcon, String imgDrive, String imgQemu) {
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
obj.put("title", imgName);
|
||||
obj.put("arch", imgArch);
|
||||
obj.put("author", imgAuthor);
|
||||
obj.put("desc", imgDesc);
|
||||
obj.put("kernel", "windows");
|
||||
obj.put("icon", imgIcon);
|
||||
obj.put("drive", imgDrive);
|
||||
obj.put("qemu", imgQemu);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
private void showDialog(String title, String path, String pathIcon) {
|
||||
|
||||
final Dialog dialog = new Dialog(MainActivity.activity, R.style.MainDialogTheme);
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(R.layout.rom_options_layout);
|
||||
|
||||
LinearLayout removeLayout = dialog.findViewById(R.id.layoutRemove);
|
||||
|
||||
removeLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog ad;
|
||||
ad = new AlertDialog.Builder(MainActivity.activity, R.style.MainDialogTheme).create();
|
||||
ad.setTitle(MainActivity.activity.getString(R.string.remove) + " " + title);
|
||||
ad.setMessage(MainActivity.activity.getString(R.string.are_you_sure));
|
||||
ad.setButton(Dialog.BUTTON_NEGATIVE, MainActivity.activity.getString(R.string.remove) + " " + title, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
File file = new File(path);
|
||||
try {
|
||||
file.delete();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
MainActivity.mMainAdapter = new AdapterMainRoms(MainActivity.activity, MainActivity.data);
|
||||
MainActivity.data.remove(currentPos);
|
||||
MainActivity.mRVMainRoms.setAdapter(MainActivity.mMainAdapter);
|
||||
MainActivity.mRVMainRoms.setLayoutManager(new GridLayoutManager(MainActivity.activity, 2));
|
||||
MainActivity.jArray.remove(currentPos);
|
||||
try {
|
||||
Writer output = null;
|
||||
File jsonFile = new File(AppConfig.maindirpath + "roms-data" + ".json");
|
||||
output = new BufferedWriter(new FileWriter(jsonFile));
|
||||
output.write(MainActivity.jArray.toString().replace("\\", "").replace("//", "/"));
|
||||
output.close();
|
||||
MainActivity.loadDataVbi();
|
||||
} catch (Exception e) {
|
||||
UIUtils.toastLong(MainActivity.activity, e.toString());
|
||||
}
|
||||
UIUtils.toastLong(MainActivity.activity, title + MainActivity.activity.getString(R.string.are_removed_successfully));
|
||||
return;
|
||||
}
|
||||
});
|
||||
ad.setButton(Dialog.BUTTON_POSITIVE, MainActivity.activity.getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
ad.show();
|
||||
dialog.dismiss();
|
||||
}
|
||||
bottomSheetDialog.cancel();
|
||||
});
|
||||
bottomSheetDialog.show();
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
|
||||
dialog.getWindow().setGravity(Gravity.BOTTOM);
|
||||
myHolder.cdRoms.setOnClickListener(view -> {
|
||||
VMManager.setArch(current.itemArch, MainActivity.activity);
|
||||
StartVM.cdrompath = current.imgCdrom;
|
||||
if (current.qmpPort == 0) {
|
||||
Config.setDefault();
|
||||
} else {
|
||||
Config.QMPPort = current.qmpPort;
|
||||
}
|
||||
Config.vmID = current.vmID;
|
||||
String env = StartVM.env(MainActivity.activity, current.itemExtra, current.itemPath, "");
|
||||
MainActivity.startVM(current.itemName, env, current.itemExtra, current.itemPath);
|
||||
});
|
||||
|
||||
myHolder.cdRoms.setOnLongClickListener(v -> {
|
||||
VMManager.deleteVMDialog(current.itemName, position, MainActivity.activity);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
// return total item from List
|
||||
|
|
@ -261,7 +123,7 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
return data.size();
|
||||
}
|
||||
|
||||
class MyHolder extends RecyclerView.ViewHolder {
|
||||
static class MyHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
CardView cdRoms;
|
||||
TextView textName, textArch;
|
||||
|
|
@ -271,11 +133,11 @@ public class AdapterMainRoms extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
// create constructor to get widget reference
|
||||
public MyHolder(View itemView) {
|
||||
super(itemView);
|
||||
cdRoms = (CardView) itemView.findViewById(R.id.cdItem);
|
||||
textName = (TextView) itemView.findViewById(R.id.textName);
|
||||
textArch = (TextView) itemView.findViewById(R.id.textArch);
|
||||
ivIcon = (ImageView) itemView.findViewById(R.id.ivIcon);
|
||||
optionsBtn = (ImageButton) itemView.findViewById(R.id.optionsButton);
|
||||
cdRoms = itemView.findViewById(R.id.cdItem);
|
||||
textName = itemView.findViewById(R.id.textName);
|
||||
textArch = itemView.findViewById(R.id.textArch);
|
||||
ivIcon = itemView.findViewById(R.id.ivIcon);
|
||||
optionsBtn = itemView.findViewById(R.id.optionsButton);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,31 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
import static com.vectras.vm.utils.FileUtils.isFileExists;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.vectras.qemu.Config;
|
||||
import com.vectras.qemu.MainSettingsManager;
|
||||
import com.vectras.qemu.utils.QmpClient;
|
||||
import com.vectras.vm.MainRoms.AdapterMainRoms;
|
||||
import com.vectras.vm.utils.DialogUtils;
|
||||
import com.vectras.vm.utils.FileUtils;
|
||||
|
|
@ -33,11 +41,10 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class VMManager {
|
||||
|
||||
public static final String TAG = "VMManager";
|
||||
public static HashMap<String, Object> mapForCreateNewVM = new HashMap<>();
|
||||
public static ArrayList<HashMap<String, Object>> listmapForCreateNewVM = new ArrayList<>();
|
||||
public static ArrayList<HashMap<String, Object>> listmapForRemoveVM = new ArrayList<>();
|
||||
|
|
@ -50,6 +57,7 @@ public class VMManager {
|
|||
public static boolean isKeptSomeFiles = false;
|
||||
|
||||
public static String latestUnsafeCommandReason = "";
|
||||
public static String lastQemuCommand = "";
|
||||
|
||||
public static void createNewVM(String name, String thumbnail, String drive, String arch, String cdrom, String params, String vmID, int port) {
|
||||
mapForCreateNewVM.clear();
|
||||
|
|
@ -330,8 +338,8 @@ public class VMManager {
|
|||
|
||||
public static void restoreVMs() {
|
||||
int _startRepeat = 0;
|
||||
String _resulttemp ="";
|
||||
String _result ="";
|
||||
StringBuilder _resulttemp = new StringBuilder();
|
||||
StringBuilder _result = new StringBuilder();
|
||||
restoredVMs = 0;
|
||||
ArrayList<String> _filelist = new ArrayList<>();
|
||||
FileUtils.getAListOfAllFilesAndFoldersInADirectory(AppConfig.vmFolder, _filelist);
|
||||
|
|
@ -341,16 +349,16 @@ public class VMManager {
|
|||
if (!isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/rom-data.json")) {
|
||||
if (JSONUtils.isMapValidFromString(FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json"))) {
|
||||
if (_resulttemp.contains("}")) {
|
||||
_resulttemp += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_resulttemp.toString().contains("}")) {
|
||||
_resulttemp.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_resulttemp = FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_resulttemp = new StringBuilder(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
if (JSONUtils.isValidFromString(FileUtils.readAFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_result.toString().contains("}")) {
|
||||
_result.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_result = FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_result = new StringBuilder(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
enableVMID(FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt"));
|
||||
|
|
@ -359,10 +367,10 @@ public class VMManager {
|
|||
}
|
||||
restoredVMs++;
|
||||
} else if (JSONUtils.isValidFromString(FileUtils.readAFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", "," + _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_result.toString().contains("}")) {
|
||||
_result.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_result = "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_result = new StringBuilder("," + FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt")) {
|
||||
enableVMID(FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/vmID.old.txt"));
|
||||
|
|
@ -379,7 +387,7 @@ public class VMManager {
|
|||
|
||||
_startRepeat++;
|
||||
if (_startRepeat == _filelist.size()) {
|
||||
if (!_result.isEmpty()) {
|
||||
if (_result.length() > 0) {
|
||||
if (JSONUtils.isValidFromString("[" + _result + "]")) {
|
||||
if (isFileExists(AppConfig.romsdatajson)) {
|
||||
if (JSONUtils.isValidFromFile(AppConfig.romsdatajson)) {
|
||||
|
|
@ -411,8 +419,8 @@ public class VMManager {
|
|||
|
||||
public static void startFixRomsDataJson() {
|
||||
int _startRepeat = 0;
|
||||
String _resulttemp ="";
|
||||
String _result ="";
|
||||
StringBuilder _resulttemp = new StringBuilder();
|
||||
StringBuilder _result = new StringBuilder();
|
||||
restoredVMs = 0;
|
||||
ArrayList<String> _filelist = new ArrayList<>();
|
||||
FileUtils.getAListOfAllFilesAndFoldersInADirectory(AppConfig.vmFolder, _filelist);
|
||||
|
|
@ -422,23 +430,23 @@ public class VMManager {
|
|||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/vmID.txt")) {
|
||||
if (isFileExists(_filelist.get((int)(_startRepeat)) + "/rom-data.json")) {
|
||||
if (JSONUtils.isMapValidFromString(FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json"))) {
|
||||
if (_resulttemp.contains("}")) {
|
||||
_resulttemp += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_resulttemp.toString().contains("}")) {
|
||||
_resulttemp.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_resulttemp = FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_resulttemp = new StringBuilder(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
if (JSONUtils.isValidFromString(FileUtils.readAFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_result.toString().contains("}")) {
|
||||
_result.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_result = FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_result = new StringBuilder(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
restoredVMs++;
|
||||
} else if (JSONUtils.isValidFromString(FileUtils.readAFile(AppConfig.maindirpath + "/roms-data.json").replaceAll("]", "," + _resulttemp + "]"))) {
|
||||
if (_result.contains("}")) {
|
||||
_result += "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
if (_result.toString().contains("}")) {
|
||||
_result.append(",").append(FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
} else {
|
||||
_result = "," + FileUtils.readAFile(_filelist.get((int)(_startRepeat)) + "/rom-data.json");
|
||||
_result = new StringBuilder("," + FileUtils.readAFile(_filelist.get((int) (_startRepeat)) + "/rom-data.json"));
|
||||
}
|
||||
restoredVMs++;
|
||||
} else {
|
||||
|
|
@ -450,7 +458,7 @@ public class VMManager {
|
|||
|
||||
_startRepeat++;
|
||||
if (_startRepeat == _filelist.size()) {
|
||||
if (!_result.isEmpty()) {
|
||||
if (_result.length() > 0) {
|
||||
if (JSONUtils.isValidFromString("[" + _result + "]")) {
|
||||
if (isFileExists(AppConfig.romsdatajson)) {
|
||||
if (JSONUtils.isValidFromFile(AppConfig.romsdatajson)) {
|
||||
|
|
@ -670,7 +678,7 @@ public class VMManager {
|
|||
} else {
|
||||
DialogUtils.oneDialog(_context, _context.getString(R.string.done), _context.getString(R.string.roms_data_json_fixed_successfully), _context.getString(R.string.ok),true, R.drawable.check_24px, true,null, null);
|
||||
}
|
||||
MainActivity.loadDataVbi();
|
||||
MainActivity.mMainAdapter.notifyDataSetChanged();
|
||||
MainActivity.mdatasize2();
|
||||
movetoRecycleBin();
|
||||
}
|
||||
|
|
@ -760,9 +768,7 @@ public class VMManager {
|
|||
}
|
||||
|
||||
public static boolean isHaveADisk(String env) {
|
||||
if (env.contains("-drive") || env.contains("-hda") || env.contains("-hdb") || env.contains("-cdrom") || env.contains("-fda") || env.contains("-fdb"))
|
||||
return true;
|
||||
return false;
|
||||
return env.contains("-drive") || env.contains("-hda") || env.contains("-hdb") || env.contains("-cdrom") || env.contains("-fda") || env.contains("-fdb");
|
||||
}
|
||||
|
||||
public static void setIconWithName(ImageView imageview, String name) {
|
||||
|
|
@ -812,4 +818,261 @@ public class VMManager {
|
|||
vterm.executeShellCommand2("killall -9 qemu-system-aarch64", false, MainActivity.activity);
|
||||
vterm.executeShellCommand2("killall -9 qemu-system-ppc", false, MainActivity.activity);
|
||||
}
|
||||
|
||||
public static void shutdownCurrentVM() {
|
||||
QmpClient.sendCommand("quit");
|
||||
}
|
||||
|
||||
public static void showChangeRemovableDevicesDialog(Activity _activity, boolean isMainVNCActivity) {
|
||||
|
||||
View _view = LayoutInflater.from(_activity).inflate(R.layout.dialog_change_removable_devices, null);
|
||||
AlertDialog _dialog = new MaterialAlertDialogBuilder(_activity, R.style.CenteredDialogTheme)
|
||||
.setView(_view)
|
||||
.create();
|
||||
|
||||
if (getAllDevicesInQemu().contains("ide1-cd0")
|
||||
|| getAllDevicesInQemu().contains("ide2-cd0")
|
||||
|| getAllDevicesInQemu().contains("floppy0")
|
||||
|| getAllDevicesInQemu().contains("floppy1")
|
||||
|| getAllDevicesInQemu().contains("sd0")) {
|
||||
|
||||
if (getAllDevicesInQemu().contains("ide1-cd0")
|
||||
|| getAllDevicesInQemu().contains("ide2-cd0")) {
|
||||
|
||||
_view.findViewById(R.id.ln_cdrom).setOnClickListener(v -> {
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
_activity.startActivityForResult(intent, 120);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
_view.findViewById(R.id.iv_ejectcdrom).setOnClickListener(v -> {
|
||||
ejectCDROM(_activity);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_cdrom).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (getAllDevicesInQemu().contains("floppy0")) {
|
||||
_view.findViewById(R.id.ln_fda).setOnClickListener(v -> {
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
_activity.startActivityForResult(intent, 889);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
_view.findViewById(R.id.iv_ejectfda).setOnClickListener(v -> {
|
||||
ejectFloppyDriveA(_activity);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
if (!getAllDevicesInQemu().contains("floppy1")) {
|
||||
TextView tvFda = _view.findViewById(R.id.tv_fda);
|
||||
tvFda.setText(R.string.floppy_drive);
|
||||
}
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_fda).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (getAllDevicesInQemu().contains("floppy1")) {
|
||||
_view.findViewById(R.id.ln_fdb).setOnClickListener(v -> {
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
_activity.startActivityForResult(intent, 13335);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
_view.findViewById(R.id.iv_ejectfdb).setOnClickListener(v -> {
|
||||
ejectFloppyDriveB(_activity);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
if (!getAllDevicesInQemu().contains("floppy0")) {
|
||||
TextView tvFdb = _view.findViewById(R.id.tv_fdb);
|
||||
tvFdb.setText(R.string.floppy_drive);
|
||||
}
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_fdb).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (getAllDevicesInQemu().contains("sd0")) {
|
||||
_view.findViewById(R.id.ln_sd).setOnClickListener(v -> {
|
||||
Intent intent = new Intent(ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
_activity.startActivityForResult(intent, 32);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
|
||||
_view.findViewById(R.id.iv_ejectsd).setOnClickListener(v -> {
|
||||
ejectSDCard(_activity);
|
||||
_dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_sd).setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_removable_devices).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (isMainVNCActivity) {
|
||||
_view.findViewById(R.id.ln_mouse).setOnClickListener(v -> {
|
||||
final Dialog alertDialog = new Dialog(_activity, R.style.MainDialogTheme);
|
||||
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
Objects.requireNonNull(alertDialog.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
|
||||
alertDialog.setContentView(R.layout.dialog_setting);
|
||||
alertDialog.show();
|
||||
_dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
_view.findViewById(R.id.ln_user_interface).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
_dialog.show();
|
||||
}
|
||||
|
||||
public static void changeCDROM(String _path, Activity _activity) {
|
||||
if (isUsingQ35(lastQemuCommand)) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(changeRemovableDevicesQMPCommand("ide2-cd0", _path)))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.changed), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.change_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(changeRemovableDevicesQMPCommand("ide1-cd0", _path)))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.changed), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.change_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeFloppyDriveA(String _path, Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(changeRemovableDevicesQMPCommand("floppy0", _path)))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.changed), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.change_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeFloppyDriveB(String _path, Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(changeRemovableDevicesQMPCommand("floppy1", _path)))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.changed), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.change_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void changeSDCard(String _path, Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(changeRemovableDevicesQMPCommand("sd0", _path)))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.changed), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.change_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ejectCDROM(Activity _activity) {
|
||||
if (isUsingQ35(lastQemuCommand)) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(ejectRemovableDevicesQMPCommand("ide2-cd0")))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.ejected), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.eject_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(ejectRemovableDevicesQMPCommand("ide1-cd0")))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.ejected), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.eject_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ejectFloppyDriveA(Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(ejectRemovableDevicesQMPCommand("floppy0")))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.ejected), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.eject_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ejectFloppyDriveB(Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(ejectRemovableDevicesQMPCommand("floppy1")))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.ejected), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.eject_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ejectSDCard(Activity _activity) {
|
||||
if (isQMPCommandSuccess(QmpClient.sendCommand(ejectRemovableDevicesQMPCommand("sd0")))) {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.ejected), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (_activity != null && !_activity.isFinishing())
|
||||
Toast.makeText(_activity, _activity.getString(R.string.eject_failed), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public static String changeRemovableDevicesQMPCommand(String device, String filePath) {
|
||||
return "{ \n" +
|
||||
" \"execute\": \"blockdev-change-medium\", \n" +
|
||||
" \"arguments\": { \n" +
|
||||
" \"device\": \"" + device + "\", \n" +
|
||||
" \"filename\": \"" + filePath + "\", \n" +
|
||||
" \"format\": \"raw\" \n" +
|
||||
" } \n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
||||
public static String ejectRemovableDevicesQMPCommand(String device) {
|
||||
return "{ \"execute\": \"eject\", \"arguments\": { \"device\": \""+ device +"\" } }";
|
||||
}
|
||||
|
||||
public static String getAllDevicesInQemu() {
|
||||
return QmpClient.sendCommand("{ \"execute\": \"query-block\" }");
|
||||
}
|
||||
|
||||
public static boolean isQMPCommandSuccess(String _result) {
|
||||
Log.d("VMManager", "isQMPCommandSuccess: " + _result);
|
||||
return _result.contains("\"return\": {}");
|
||||
}
|
||||
|
||||
|
||||
public static boolean isUsingQemuARM(String _qemuCommand) {
|
||||
return _qemuCommand.contains("qemu-system-a");
|
||||
}
|
||||
|
||||
public static boolean isUsingQemuPowerPC(String _qemuCommand) {
|
||||
return _qemuCommand.contains("qemu-system-p");
|
||||
}
|
||||
|
||||
public static boolean isUsingQ35(String _qemuCommand) {
|
||||
return _qemuCommand.contains("-M q35")
|
||||
|| _qemuCommand.contains("-machine q35")
|
||||
|| _qemuCommand.contains("-M pc-q35")
|
||||
|| _qemuCommand.contains("-machine pc-q35");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue