deep-wine-runner/VM-source/vbox.cpp

114 lines
5.4 KiB
C++
Raw Normal View History

2023-04-05 16:09:58 +08:00
/*
2023-04-24 21:49:18 +08:00
* gfdgd xi
2023-04-05 16:09:58 +08:00
*/
2023-02-07 22:12:05 +08:00
#include "vbox.h"
#include "command.h"
2023-02-19 15:28:37 +08:00
#include <QMessageBox>
2023-02-07 22:12:05 +08:00
vbox::vbox(QString name, QString managerPath) {
this->name = name;
this->managerPath = managerPath;
2023-02-25 09:52:53 +08:00
//Command command = Command();
2023-02-07 22:12:05 +08:00
this->vboxVersion = Command().GetCommand("'" + managerPath + "' -v");
}
2023-02-19 14:09:18 +08:00
int vbox::Create(QString type){
2023-04-08 11:57:36 +08:00
system(("\"" + managerPath + "\" createvm --name \""
2023-02-19 14:09:18 +08:00
+ name + "\" --ostype \"" + type +
2023-02-19 15:28:37 +08:00
"\" --register").toLatin1());
2023-04-08 11:57:36 +08:00
return system(("\"" + managerPath + "\" modifyvm \""
+ name + "\" --ostype \"" + type +
"\" ").toLatin1());
//vboxmanage modifyvm testvm --ostype
2023-02-19 14:09:18 +08:00
}
int vbox::CreateDisk(QString path, int size){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" createvdi --filename \"" + path + "\" --size \"" + QString::number(size) + "\"").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::CreateDiskControl(QString controlName){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" storagectl \"" + name + "\" --name \"" + controlName + "\" --add ide").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::MountDisk(QString diskPath, QString controlName, int port, int device){
return system(("\"" + managerPath + "\" storageattach \"" + name +
"\" --storagectl \"" + controlName + "\" --type hdd --port "
2023-02-19 15:28:37 +08:00
+ QString::number(port) + " --device " + QString::number(device) + " --medium \"" + diskPath + "\"").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::MountISO(QString isoPath, QString controlName, int port, int device){
return system(("\"" + managerPath + "\" storageattach \"" + name + "\" --storagectl \"" +
2023-02-19 15:28:37 +08:00
controlName + "\" --type dvddrive --port " + QString::number(port) + " --device " + QString::number(device)
+ " --medium \"" + isoPath + "\"").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::BootFirst(QString bootDrive){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --boot1 " + bootDrive).toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetNetBridge(QString netDriver){
2023-02-19 14:32:24 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name +
2023-02-19 15:28:37 +08:00
"\" --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 \"" + netDriver + "\" --intnet1 brigh1 --macaddress1 auto").toLatin1());
2023-02-19 14:09:18 +08:00
}
2023-08-09 22:19:56 +08:00
int vbox::SetCPU(int number, int cpuNum, int coreNum){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --cpus " + QString::number(number)).toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetMemory(int memory){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --memory " + QString::number(memory)).toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetRemote(bool setting){
2023-02-19 14:32:24 +08:00
if(setting){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --vrde on").toLatin1());
2023-02-19 14:32:24 +08:00
}
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --vrde off").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetRemoteConnectSetting(int port){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --vrdeport " + QString::number(port) + " --vrdeaddress """).toLatin1());
2023-02-19 14:09:18 +08:00
}
2023-02-19 14:32:24 +08:00
int vbox::Start(bool unShown){
if(unShown){
return system(("\"" + managerPath + "\" > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1").toLatin1());
2023-02-19 14:32:24 +08:00
}
return system(("\"" + managerPath + "\" startvm \"" + name + "\" > /tmp/windows-virtual-machine-installer-for-wine-runner-install.log 2>&1").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::Stop(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" controlvm \"" + name + "\" poweroff").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::Delete(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" unregistervm --delete \"" + name + "\"").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetDisplayMemory(int memory){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --vram " + QString::number(memory)).toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::InstallGuessAdditions(QString controlName, int port, int device){
2023-02-19 14:32:24 +08:00
return MountISO("/usr/share/virtualbox/VBoxGuestAdditions.iso", controlName, port, device);
2023-02-19 14:09:18 +08:00
}
int vbox::EnabledAudio(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --audio-driver pulse --audiocontroller hda --audioin on --audioout on").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::EnabledClipboardMode(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --clipboard-mode bidirectional").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::EnabledDraganddrop(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --draganddrop bidirectional").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::ShareFile(QString name, QString path){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" sharedfolder add \"" + this->name + "\" -name \"" + name + "\" -hostpath \"" + path + "\"").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetVBoxSVGA(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --graphicscontroller vboxsvga").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetMousePS2(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --mouse usb").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::SetKeyboardPS2(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --keyboard usb").toLatin1());
2023-02-19 14:09:18 +08:00
}
int vbox::OpenUSB(){
2023-02-19 15:28:37 +08:00
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --usbohci on").toLatin1());
2023-02-19 14:09:18 +08:00
}
2023-08-09 22:19:56 +08:00
int vbox::EnabledUEFI(bool status){
if(status){
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --firmware=efi").toLatin1());
}
return system(("\"" + managerPath + "\" modifyvm \"" + name + "\" --firmware=bios").toLatin1());
}
2023-08-16 09:53:59 +08:00
int vbox::AutoInstall(QString iso){
return system(("vboxmanage unattended install '" + name + "' '--iso=" + iso + "'").toLatin1());
}