mirror of
https://github.com/xoureldeen/Vectras-VM-Android.git
synced 2026-04-29 14:59:50 +00:00
Bread
This commit is contained in:
parent
3381c503e4
commit
8ca54aa1f5
19 changed files with 455 additions and 143 deletions
|
|
@ -79,4 +79,6 @@ public class AppConfig {
|
|||
" libusb ncurses-libs curl libnfs sdl2 gtk+3.0 fuse libpulse libseccomp jack pipewire liburing" +
|
||||
" mesa-dri-gallium mesa-vulkan-swrast vulkan-loader mesa-utils mesa-egl mesa-gbm mesa-vulkan-ati mesa-vulkan-broadcom mesa-vulkan-freedreno mesa-vulkan-panfrost";
|
||||
|
||||
public static boolean needreinstallsystem = false;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1084,6 +1084,15 @@ public class CustomRomActivity extends AppCompatActivity {
|
|||
} else {
|
||||
JSONObject jObj = new JSONObject(FileUtils.readFromFile(MainActivity.activity, new File(AppConfig.vmFolder + vmID + "/rom-data.json")));
|
||||
|
||||
if (jObj.has("vmID")) {
|
||||
if (!jObj.isNull("vmID")) {
|
||||
if (!jObj.getString("vmID").isEmpty()) {
|
||||
VectrasApp.moveAFile(AppConfig.vmFolder + vmID, AppConfig.vmFolder + jObj.getString("vmID"));
|
||||
vmID = jObj.getString("vmID");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (jObj.has("title") && !jObj.isNull("title")) {
|
||||
title.setText(jObj.getString("title"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -550,108 +550,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
Intent w = new Intent(ACTION_VIEW);
|
||||
w.setData(Uri.parse(tw));
|
||||
startActivity(w);
|
||||
} else if (id== R.id.setup_sound) {
|
||||
if (VectrasApp.isAppInstalled("com.termux", getApplicationContext())) {
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.setup_sound));
|
||||
alertDialog.setMessage(getResources().getString(R.string.setup_sound_guide_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.start_setup), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("Setup", "curl -o setup.sh https://raw.githubusercontent.com/AnBui2004/termux/refs/heads/main/installpulseaudio.sh && chmod +rwx setup.sh && ./setup.sh && rm setup.sh");
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_VIEW);
|
||||
intent.setData(Uri.parse("android-app://com.termux"));
|
||||
startActivity(intent);
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.copied), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.termux_is_not_installed));
|
||||
alertDialog.setMessage(getResources().getString(R.string.you_need_to_install_termux));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.install), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_VIEW);
|
||||
intent.setData(Uri.parse("https://github.com/termux/termux-app/releases"));
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
alertDialog.show();
|
||||
} else if (id == R.id.deletealldata) {
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.delete_all_vm));
|
||||
alertDialog.setMessage(getResources().getString(R.string.delete_all_vm_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.delete_all), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VectrasApp.killallqemuprocesses(getApplicationContext());
|
||||
VectrasApp.deleteDirectory(AppConfig.vmFolder);
|
||||
VectrasApp.deleteDirectory(AppConfig.recyclebin);
|
||||
VectrasApp.deleteDirectory(AppConfig.romsdatajson);
|
||||
File vDir = new File(AppConfig.maindirpath);
|
||||
vDir.mkdirs();
|
||||
errorjsondialog();
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
} else if (id == R.id.navigation_item_get_rom) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(getApplicationContext(), RomsManagerActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.cleanup) {
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.clean_up));
|
||||
alertDialog.setMessage(getResources().getString(R.string.clean_up_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.clean_up), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VMManager.cleanUp();
|
||||
errorjsondialog();
|
||||
Toast.makeText(getApplicationContext(), activity.getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
} else if (id == R.id.restorevms) {
|
||||
alertDialog = new AlertDialog.Builder(activity, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.restore));
|
||||
alertDialog.setMessage(getResources().getString(R.string.restore_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.continuetext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VMManager.restoreVMs();
|
||||
errorjsondialog();
|
||||
VectrasApp.oneDialog(getResources().getString(R.string.done), getResources().getString(R.string.restored) + " " + String.valueOf(VMManager.restoredVMs) + ".", true, false, activity);
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
} else if (id == R.id.mini_tools) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(activity, Minitools.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1024,7 +930,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
if (VectrasApp.isThisVMRunning(itemExtra, itemPath)) {
|
||||
Toast.makeText(activity, "This VM is already running.", Toast.LENGTH_LONG).show();
|
||||
activity.startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
if (MainSettingsManager.getVmUi(activity).equals("VNC"))
|
||||
activity.startActivity(new Intent(activity, MainVNCActivity.class));
|
||||
else if (MainSettingsManager.getVmUi(activity).equals("X11"))
|
||||
activity.startActivity(new Intent(activity, X11Activity.class));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
209
app/src/main/java/com/vectras/vm/Minitools.java
Normal file
209
app/src/main/java/com/vectras/vm/Minitools.java
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
package com.vectras.vm;
|
||||
|
||||
import static android.content.Intent.ACTION_OPEN_DOCUMENT;
|
||||
import static android.content.Intent.ACTION_VIEW;
|
||||
import static android.view.View.GONE;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Minitools extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
EdgeToEdge.enable(this);
|
||||
setContentView(R.layout.activity_minitools);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
||||
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
toolbar.setTitle(getString(R.string.mini_tools));
|
||||
|
||||
LinearLayout setupsoundfortermux = findViewById(R.id.setupsoundfortermux);
|
||||
LinearLayout cleanup = findViewById(R.id.cleanup);
|
||||
LinearLayout restore = findViewById(R.id.restore);
|
||||
LinearLayout deleteallvm = findViewById(R.id.deleteallvm);
|
||||
LinearLayout reinstallsystem = findViewById(R.id.reinstallsystem);
|
||||
|
||||
setupsoundfortermux.setOnClickListener(v -> {
|
||||
if (VectrasApp.isAppInstalled("com.termux", getApplicationContext())) {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.setup_sound));
|
||||
alertDialog.setMessage(getResources().getString(R.string.setup_sound_guide_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.start_setup), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("Setup", "curl -o setup.sh https://raw.githubusercontent.com/AnBui2004/termux/refs/heads/main/installpulseaudio.sh && chmod +rwx setup.sh && ./setup.sh && rm setup.sh");
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_VIEW);
|
||||
intent.setData(Uri.parse("android-app://com.termux"));
|
||||
startActivity(intent);
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.copied), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
} else {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.termux_is_not_installed));
|
||||
alertDialog.setMessage(getResources().getString(R.string.you_need_to_install_termux));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.install), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ACTION_VIEW);
|
||||
intent.setData(Uri.parse("https://github.com/termux/termux-app/releases"));
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
cleanup.setOnClickListener(v -> {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.clean_up));
|
||||
alertDialog.setMessage(getResources().getString(R.string.clean_up_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.clean_up), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VMManager.cleanUp();
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
|
||||
restore.setVisibility(GONE);
|
||||
cleanup.setVisibility(GONE);
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
});
|
||||
|
||||
restore.setOnClickListener(v -> {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.restore));
|
||||
alertDialog.setMessage(getResources().getString(R.string.restore_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.continuetext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VMManager.restoreVMs();
|
||||
VectrasApp.oneDialog(getResources().getString(R.string.done), getResources().getString(R.string.restored) + " " + String.valueOf(VMManager.restoredVMs) + ".", true, false, Minitools.this);
|
||||
restore.setVisibility(GONE);
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
});
|
||||
|
||||
deleteallvm.setOnClickListener(v -> {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.delete_all_vm));
|
||||
alertDialog.setMessage(getResources().getString(R.string.delete_all_vm_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.delete_all), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
VectrasApp.killallqemuprocesses(getApplicationContext());
|
||||
VectrasApp.deleteDirectory(AppConfig.vmFolder);
|
||||
VectrasApp.deleteDirectory(AppConfig.recyclebin);
|
||||
VectrasApp.deleteDirectory(AppConfig.romsdatajson);
|
||||
File vDir = new File(AppConfig.maindirpath);
|
||||
vDir.mkdirs();
|
||||
VectrasApp.writeToFile(AppConfig.maindirpath, "roms-data.json", "[]");
|
||||
cleanup.setVisibility(GONE);
|
||||
restore.setVisibility(GONE);
|
||||
deleteallvm.setVisibility(GONE);
|
||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.done), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
});
|
||||
|
||||
reinstallsystem.setOnClickListener(v -> {
|
||||
AlertDialog alertDialog = new AlertDialog.Builder(Minitools.this, R.style.MainDialogTheme).create();
|
||||
alertDialog.setTitle(getResources().getString(R.string.reinstall_system));
|
||||
alertDialog.setMessage(getResources().getString(R.string.reinstall_system_content));
|
||||
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.continuetext), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MainActivity.isActivate = false;
|
||||
AppConfig.needreinstallsystem = true;
|
||||
VectrasApp.killallqemuprocesses(Minitools.this);
|
||||
VectrasApp.deleteDirectory(getFilesDir().getAbsolutePath() + "/data");
|
||||
VectrasApp.deleteDirectory(getFilesDir().getAbsolutePath() + "/distro");
|
||||
VectrasApp.deleteDirectory(getFilesDir().getAbsolutePath() + "/usr");
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(Minitools.this, SetupQemuActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -145,6 +145,16 @@ public class SetupQemuActivity extends AppCompatActivity implements View.OnClick
|
|||
}
|
||||
linearcannotconnecttoserver.setVisibility(View.GONE);
|
||||
}
|
||||
if (AppConfig.needreinstallsystem) {
|
||||
if (AppConfig.getSetupFiles().contains("arm64-v8a") || AppConfig.getSetupFiles().contains("x86_64")) {
|
||||
setupVectras64();
|
||||
} else {
|
||||
setupVectras32();
|
||||
}
|
||||
textviewsettingup.setText(getResources().getString(R.string.reinstalling));
|
||||
}
|
||||
} else {
|
||||
linearload.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -538,6 +538,12 @@ public class VectrasApp extends Application {
|
|||
File _dir = new File(_pathToDelete);
|
||||
if (_dir.isDirectory()) {
|
||||
String[] children = _dir.list();
|
||||
|
||||
if (children == null) {
|
||||
Log.e("ERROR", "Deletion failed. " + _dir);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
File temp = new File(_dir, children[i]);
|
||||
deleteDirectory(String.valueOf(temp));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue