Merge pull request #4 from username223/master
Refactor arg parsing and remove/install manifest logic
This commit is contained in:
+72
-59
@@ -110,58 +110,71 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
|
|
||||||
bool desktopMode = false;
|
|
||||||
bool noSound = false;
|
|
||||||
bool noManifest = false;
|
|
||||||
|
|
||||||
// Parse command line arguments
|
namespace argument {
|
||||||
for (int i = 1; i < argc; i++) {
|
// Checks whether a specific string was passed as a launch argument.
|
||||||
if (std::string(argv[i]).compare("-desktop") == 0) {
|
bool CheckCommandLineArgument(int argc, char *argv[], const std::string parameter) {
|
||||||
desktopMode = true;
|
// The old way was one giant loop that tested every single parameter.
|
||||||
} else if (std::string(argv[i]).compare("-nosound") == 0) {
|
// Having an individual loop for all args most likely has a very small performance
|
||||||
noSound = true;
|
// penalty compared to the original solution,
|
||||||
} else if (std::string(argv[i]).compare("-nomanifest") == 0) {
|
// but the gains in readability and ease of extension of not having a hundred line+ for loop are worth it.
|
||||||
noManifest = true;
|
for (int i = 0; i < argc; i++) {
|
||||||
} else if (std::string(argv[i]).compare("-installmanifest") == 0) {
|
if (std::string(argv[i]) == parameter) {
|
||||||
int exitcode = 0;
|
return true;
|
||||||
QCoreApplication coreApp(argc, argv);
|
}
|
||||||
auto initError = vr::VRInitError_None;
|
}
|
||||||
vr::VR_Init(&initError, vr::VRApplication_Utility);
|
return false;
|
||||||
if (initError == vr::VRInitError_None) {
|
}
|
||||||
try {
|
|
||||||
installManifest(true);
|
constexpr auto DESKTOP_MODE = "-desktop";
|
||||||
} catch (std::exception& e) {
|
constexpr auto NO_SOUND = "-nosound";
|
||||||
exitcode = -1;
|
constexpr auto NO_MANIFEST = "-nomanifest";
|
||||||
std::cerr << e.what() << std::endl;
|
constexpr auto INSTALL_MANIFEST= "-installmanifest";
|
||||||
}
|
constexpr auto REMOVE_MANIFEST= "-removemanifest";
|
||||||
} else {
|
}
|
||||||
exitcode = -2;
|
|
||||||
std::cerr << std::string("Failed to initialize OpenVR: " + std::string(vr::VR_GetVRInitErrorAsEnglishDescription(initError))) << std::endl;
|
enum ReturnErrorCode {
|
||||||
}
|
SUCCESS = 0,
|
||||||
vr::VR_Shutdown();
|
GENERAL_FAILURE = -1,
|
||||||
exit(exitcode);
|
OPENVR_INIT_ERROR = -2,
|
||||||
} else if (std::string(argv[i]).compare("-removemanifest") == 0) {
|
};
|
||||||
int exitcode = 0;
|
|
||||||
QCoreApplication coreApp(argc, argv);
|
int main(int argc, char *argv[]) {
|
||||||
auto initError = vr::VRInitError_None;
|
|
||||||
vr::VR_Init(&initError, vr::VRApplication_Utility);
|
const bool desktop_mode = argument::CheckCommandLineArgument(argc, argv, argument::DESKTOP_MODE);
|
||||||
if (initError == vr::VRInitError_None) {
|
const bool no_sound = argument::CheckCommandLineArgument(argc, argv, argument::NO_SOUND);
|
||||||
try {
|
const bool no_manifest = argument::CheckCommandLineArgument(argc, argv, argument::NO_MANIFEST);
|
||||||
removeManifest();
|
const bool install_manifest = argument::CheckCommandLineArgument(argc, argv, argument::INSTALL_MANIFEST);
|
||||||
} catch (std::exception& e) {
|
const bool remove_manifest = argument::CheckCommandLineArgument(argc, argv, argument::REMOVE_MANIFEST);
|
||||||
exitcode = -1;
|
|
||||||
std::cerr << e.what() << std::endl;
|
if (install_manifest || remove_manifest) {
|
||||||
}
|
int exit_code = ReturnErrorCode::SUCCESS;
|
||||||
} else {
|
QCoreApplication coreApp(argc, argv);
|
||||||
exitcode = -2;
|
auto openvr_init_status = vr::VRInitError_None;
|
||||||
std::cerr << std::string("Failed to initialize OpenVR: " + std::string(vr::VR_GetVRInitErrorAsEnglishDescription(initError))) << std::endl;
|
vr::VR_Init(&openvr_init_status, vr::VRApplication_Utility);
|
||||||
}
|
|
||||||
vr::VR_Shutdown();
|
if (openvr_init_status == vr::VRInitError_None) {
|
||||||
exit(exitcode);
|
try {
|
||||||
}
|
if (install_manifest) {
|
||||||
}
|
installManifest(true);
|
||||||
|
}
|
||||||
|
else if (remove_manifest) {
|
||||||
|
removeManifest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e) {
|
||||||
|
exit_code = ReturnErrorCode::GENERAL_FAILURE;
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
exit_code = ReturnErrorCode::OPENVR_INIT_ERROR;
|
||||||
|
std::cerr << std::string("Failed to initialize OpenVR: " + std::string(vr::VR_GetVRInitErrorAsEnglishDescription(openvr_init_status))) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
vr::VR_Shutdown();
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MyQApplication a(argc, argv);
|
MyQApplication a(argc, argv);
|
||||||
@@ -195,13 +208,13 @@ int main(int argc, char *argv[]) {
|
|||||||
LOG(INFO) << "Log File: " << logFilePath;
|
LOG(INFO) << "Log File: " << logFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desktopMode) {
|
if (desktop_mode) {
|
||||||
LOG(INFO) << "Desktop mode enabled.";
|
LOG(INFO) << "Desktop mode enabled.";
|
||||||
}
|
}
|
||||||
if (noSound) {
|
if (no_sound) {
|
||||||
LOG(INFO) << "Sound effects disabled.";
|
LOG(INFO) << "Sound effects disabled.";
|
||||||
}
|
}
|
||||||
if (noManifest) {
|
if (no_manifest) {
|
||||||
LOG(INFO) << "vrmanifest disabled.";
|
LOG(INFO) << "vrmanifest disabled.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +224,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
QQmlEngine qmlEngine;
|
QQmlEngine qmlEngine;
|
||||||
|
|
||||||
advsettings::OverlayController* controller = advsettings::OverlayController::createInstance(desktopMode, noSound);
|
advsettings::OverlayController* controller = advsettings::OverlayController::createInstance(desktop_mode, no_sound);
|
||||||
controller->Init(&qmlEngine);
|
controller->Init(&qmlEngine);
|
||||||
|
|
||||||
QQmlComponent component(&qmlEngine, QUrl::fromLocalFile("res/qml/mainwidget.qml"));
|
QQmlComponent component(&qmlEngine, QUrl::fromLocalFile("res/qml/mainwidget.qml"));
|
||||||
@@ -222,7 +235,7 @@ int main(int argc, char *argv[]) {
|
|||||||
auto quickObj = component.create();
|
auto quickObj = component.create();
|
||||||
controller->SetWidget(qobject_cast<QQuickItem*>(quickObj), advsettings::OverlayController::applicationName, advsettings::OverlayController::applicationKey);
|
controller->SetWidget(qobject_cast<QQuickItem*>(quickObj), advsettings::OverlayController::applicationName, advsettings::OverlayController::applicationKey);
|
||||||
|
|
||||||
if (!desktopMode && !noManifest) {
|
if (!desktop_mode && !no_manifest) {
|
||||||
try {
|
try {
|
||||||
installManifest();
|
installManifest();
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
@@ -230,7 +243,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desktopMode) {
|
if (desktop_mode) {
|
||||||
auto m_pWindow = new QQuickWindow();
|
auto m_pWindow = new QQuickWindow();
|
||||||
qobject_cast<QQuickItem*>(quickObj)->setParentItem(m_pWindow->contentItem());
|
qobject_cast<QQuickItem*>(quickObj)->setParentItem(m_pWindow->contentItem());
|
||||||
m_pWindow->setGeometry(0, 0, qobject_cast<QQuickItem*>(quickObj)->width(), qobject_cast<QQuickItem*>(quickObj)->height());
|
m_pWindow->setGeometry(0, 0, qobject_cast<QQuickItem*>(quickObj)->width(), qobject_cast<QQuickItem*>(quickObj)->height());
|
||||||
@@ -241,7 +254,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LOG(FATAL) << e.what();
|
LOG(FATAL) << e.what();
|
||||||
return -1;
|
return ReturnErrorCode::GENERAL_FAILURE;
|
||||||
}
|
}
|
||||||
return 0;
|
return ReturnErrorCode::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user