Skip to content

Commit

Permalink
Automatically set activateMultipleDrivers to true
Browse files Browse the repository at this point in the history
  • Loading branch information
pushrax committed Mar 3, 2019
1 parent 5c36f6e commit dda68d4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 40 deletions.
39 changes: 39 additions & 0 deletions OpenVR-SpaceCalibrator/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

static void UpgradeProfileV1(CalibrationContext &ctx);
static void ParseProfileV2(CalibrationContext &ctx, std::istream &stream);

static std::string ConfigFileName()
{
std::string vrRuntimeConfigName = vr::VR_RuntimePath();
Expand Down Expand Up @@ -127,3 +128,41 @@ static void UpgradeProfileV1(CalibrationContext &ctx)
file.close();
std::remove("openvr_space_calibration.txt");
}

void WriteActivateMultipleDriversToConfig()
{
std::string configPath = vr::VR_RuntimePath();
configPath += "\\..\\..\\..\\config\\steamvr.vrsettings";

std::ifstream ifile(configPath);
if (!ifile.good())
throw std::runtime_error("failed to read steamvr.vrsettings");

picojson::value v;
std::string err = picojson::parse(v, ifile);
if (!err.empty())
throw std::runtime_error(err);

ifile.close();

if (!v.is<picojson::object>())
throw std::runtime_error("steamvr.vrsettings is empty");

auto &root = v.get<picojson::object>();

if (!root["steamvr"].is<picojson::object>())
throw std::runtime_error("steamvr.vrsettings is missing \"steamvr\" key");

auto &steamvr = root["steamvr"].get<picojson::object>();

const bool tru = true; // MSVC picks the wrong specialization when passing a literal...
steamvr["activateMultipleDrivers"].set<bool>(tru);

std::ofstream ofile(configPath);
if (!ofile.good())
throw std::runtime_error("failed to write steamvr.vrsettings");

v.serialize(std::ostream_iterator<char>(ofile), true);

std::cout << "Successfully set activateMultipleDrivers to true" << std::endl;
}
1 change: 1 addition & 0 deletions OpenVR-SpaceCalibrator/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

void LoadProfile(CalibrationContext &ctx);
void SaveProfile(CalibrationContext &ctx);
void WriteActivateMultipleDriversToConfig();
66 changes: 40 additions & 26 deletions OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ void GLFWErrorCallback(int error, const char* description)
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
}

GLFWwindow *glfwWindow = nullptr;
vr::VROverlayHandle_t overlayMainHandle = 0, overlayThumbnailHandle = 0;
GLuint fboHandle = 0, fboTextureHandle = 0;
int fboTextureWidth = 0, fboTextureHeight = 0;

static void HandleCommandLine(LPWSTR lpCmdLine);

static GLFWwindow *glfwWindow = nullptr;
static vr::VROverlayHandle_t overlayMainHandle = 0, overlayThumbnailHandle = 0;
static GLuint fboHandle = 0, fboTextureHandle = 0;
static int fboTextureWidth = 0, fboTextureHeight = 0;

static char cwd[MAX_PATH];

Expand All @@ -62,6 +65,8 @@ void CreateGLFWWindow()
glfwSwapInterval(1);
gl3wInit();

glfwIconifyWindow(glfwWindow);

ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
Expand Down Expand Up @@ -165,10 +170,12 @@ void RunLoop()

static bool keyboardOpen = false, keyboardJustClosed = false;

// After closing the keyboard, this code waits one frame for ImGui to pick up the new text from SetActiveText
// before clearing the active widget. Then it waits another frame before allowing the keyboard to open again,
// otherwise it will do so instantly since WantTextInput is still true on the second frame.
if (keyboardJustClosed && keyboardOpen)
{
ImGui::ClearActiveID();
io.WantTextInput = false;
keyboardOpen = false;
}
else if (keyboardJustClosed)
Expand All @@ -177,6 +184,7 @@ void RunLoop()
}
else if (!io.WantTextInput)
{
// User might close the keyboard without hitting Done, so we unset the flag to allow it to open again.
keyboardOpen = false;
}
else if (io.WantTextInput && !keyboardOpen && !keyboardJustClosed)
Expand Down Expand Up @@ -223,19 +231,6 @@ void RunLoop()
}
}

/*if (width != fboTextureWidth || height != fboTextureHeight)
{
if (overlayMainHandle)
{
vr::VROverlay()->ClearOverlayTexture(overlayMainHandle);
}
fboTextureWidth = width;
fboTextureHeight = height;
glBindTexture(GL_TEXTURE_2D, fboTextureHandle);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fboTextureWidth, fboTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// OpenVR stops rendering the overlay if we recreate the texture storage smaller than it was originally.
}*/

ImGui_ImplGlfw_SetReadMouseFromGlfw(!dashboardVisible);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
Expand Down Expand Up @@ -279,13 +274,11 @@ void RunLoop()
}
}

static void handleCommandLine(LPWSTR lpCmdLine);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
_getcwd(cwd, MAX_PATH);
//CreateConsole();
handleCommandLine(lpCmdLine);
HandleCommandLine(lpCmdLine);

if (!glfwInit())
{
Expand Down Expand Up @@ -329,7 +322,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
return 0;
}

static void handleCommandLine(LPWSTR lpCmdLine)
static void HandleCommandLine(LPWSTR lpCmdLine)
{
if (lstrcmp(lpCmdLine, L"-openvrpath") == 0)
{
Expand All @@ -339,7 +332,6 @@ static void handleCommandLine(LPWSTR lpCmdLine)
{
printf("%s", vr::VR_RuntimePath());
vr::VR_Shutdown();
Sleep(2000);
exit(0);
}
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
Expand Down Expand Up @@ -382,8 +374,7 @@ static void handleCommandLine(LPWSTR lpCmdLine)
vr::VRApplications()->SetApplicationAutoLaunch(OPENVR_APPLICATION_KEY, true);
}
vr::VR_Shutdown();
Sleep(2000);
exit(0);
exit(-2);
}
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
vr::VR_Shutdown();
Expand All @@ -403,11 +394,34 @@ static void handleCommandLine(LPWSTR lpCmdLine)
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
}
vr::VR_Shutdown();
Sleep(2000);
exit(0);
}
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
vr::VR_Shutdown();
exit(-2);
}
else if (lstrcmp(lpCmdLine, L"-activatemultipledrivers") == 0)
{
int ret = -2;
auto vrErr = vr::VRInitError_None;
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
if (vrErr == vr::VRInitError_None)
{
try
{
WriteActivateMultipleDriversToConfig();
ret = 0;
}
catch (std::runtime_error &e)
{
std::cerr << "Failed to set activateMultipleDrivers: " << e.what() << std::endl;
}
}
else
{
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
}
vr::VR_Shutdown();
exit(ret);
}
}
2 changes: 1 addition & 1 deletion OpenVR-SpaceCalibratorDriver/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void LogFlush();
} while (0)
#endif

//#define TRACE(...) {}
#define TRACE(...) {}

#ifndef TRACE
#define TRACE LOG
Expand Down
16 changes: 3 additions & 13 deletions install/installer.nsi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

;--------------------------------
;Include Modern UI

Expand All @@ -10,18 +9,12 @@
!define OVERLAY_BASEDIR "..\client_overlay\bin\win64"
!define DRIVER_RESDIR "..\OpenVR-SpaceCalibratorDriver\01spacecalibrator"

;Name and file
Name "OpenVR-SpaceCalibrator"
OutFile "OpenVR-SpaceCalibrator.exe"

;Default installation folder
InstallDir "$PROGRAMFILES64\OpenVR-SpaceCalibrator"

;Get installation folder from registry if available
InstallDirRegKey HKLM "Software\OpenVR-SpaceCalibrator\Main" ""

;Request application privileges for Windows Vista
RequestExecutionLevel admin
ShowInstDetails show

;--------------------------------
;Variables
Expand Down Expand Up @@ -103,14 +96,12 @@ Section "Install" SecInstall

SetOutPath "$INSTDIR"

;ADD YOUR OWN FILES HERE...
File "..\LICENSE"
File "..\x64\Release\OpenVR-SpaceCalibrator.exe"
File "..\x64\Release\openvr_api.dll"
File "..\OpenVR-SpaceCalibrator\manifest.vrmanifest"
File "..\OpenVR-SpaceCalibrator\icon.png"

; Install redistributable
ExecWait '"$INSTDIR\vcredist_x64.exe" /install /quiet'

Var /GLOBAL vrRuntimePath
Expand Down Expand Up @@ -142,11 +133,9 @@ Section "Install" SecInstall
SetOutPath "$vrRuntimePath\drivers\01spacecalibrator\bin\win64"
File "..\x64\Release\driver_01spacecalibrator.dll"

;Store installation folder
WriteRegStr HKLM "Software\OpenVR-SpaceCalibrator\Main" "" $INSTDIR
WriteRegStr HKLM "Software\OpenVR-SpaceCalibrator\Driver" "" $vrRuntimePath

;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator" "DisplayName" "OpenVR-SpaceCalibrator"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
Expand All @@ -155,6 +144,7 @@ Section "Install" SecInstall

SetOutPath "$INSTDIR"
nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -installmanifest'
nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -activatemultipledrivers'

SectionEnd

Expand All @@ -169,9 +159,9 @@ Section "Uninstall"
"SteamVR is still running. Cannot uninstall this software.$\nPlease close SteamVR and try again."
Abort

SetOutPath "$INSTDIR"
nsExec::ExecToLog '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -removemanifest'

; Delete installed files
Var /GLOBAL vrRuntimePath2
ReadRegStr $vrRuntimePath2 HKLM "Software\OpenVR-SpaceCalibrator\Driver" ""
DetailPrint "VR runtime path: $vrRuntimePath2"
Expand Down

0 comments on commit dda68d4

Please sign in to comment.