Skip to content

Commit dfa140d

Browse files
committed
Partially working auto installer.
1 parent 24d34b9 commit dfa140d

7 files changed

Lines changed: 173 additions & 35 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ project (OpenVR-SpaceCalibrator VERSION 1.0)
44
add_definitions(-D__linux__)
55

66
set(CMAKE_BUILD_TYPE Debug)
7+
set(DRIVER_LOG_FILE "/tmp/spaceCalDriverLog.txt" CACHE PATH "Driver Log Path" )
78

89
add_library(imgui
910
lib/imgui/imgui.cpp
@@ -63,14 +64,25 @@ set_target_properties(driver_01spacecalibrator PROPERTIES
6364
PREFIX ""
6465
)
6566

67+
#######################################################################################
68+
set( APP_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator/manifest.vrmanifest )
69+
set( DRIVER_INSTALLER_PATH ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator )
70+
set( DRIVER_MANIFEST_PATH ${CMAKE_INSTALL_PREFIX}/lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator )
71+
configure_file( StaticConfig.h.in StaticConfig.h )
72+
73+
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
6674

6775
configure_file( ./OpenVR-SpaceCalibrator/manifest.vrmanifest ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest )
6876
configure_file( ./OpenVR-SpaceCalibratorDriver/01spacecalibrator/driver.vrdrivermanifest ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest )
77+
configure_file( ./driverInstall.py ${CMAKE_CURRENT_BINARY_DIR}/driverInstall.py )
78+
6979

80+
#######################################################################################
7081
install(
7182
FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.vrmanifest
7283
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/openvr-spacecalibrator
7384
)
85+
7486
install(
7587
FILES ${CMAKE_CURRENT_BINARY_DIR}/driver.vrdrivermanifest
7688
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator
@@ -84,6 +96,11 @@ install(
8496
DESTINATION lib/steamvr/OpenVR-SpaceCalibrator/01spacecalibrator/bin/linux64/
8597
)
8698

99+
install(
100+
FILES driverInstall.py
101+
DESTINATION "${DRIVER_INSTALLER_PATH}"
102+
)
103+
87104
find_package(Git QUIET)
88105

89106
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")

OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <codecvt>
99
#include <locale>
10-
#include <GL/gl3w.h>
10+
#include "GL/gl3w.h"
1111

1212
#ifdef __linux__
1313
#include <unistd.h>
@@ -24,7 +24,7 @@
2424
#include <openvr.h>
2525

2626
#ifdef __linux__
27-
//NOP
27+
#include "StaticConfig.h"
2828
#else
2929
#pragma comment(linker,"\"/manifestdependency:type='win32' \
3030
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
@@ -40,9 +40,9 @@ extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x
4040
#endif
4141

4242
#ifdef __linux__
43-
#define MANIFEST_END_PATH "/manifest.vrmanifest"
43+
#define MANIFEST_PATH(CWD) (APP_MANIFEST_PATH)
4444
#else
45-
#define MANIFEST_END_PATH "\\manifest.vrmanifest"
45+
#define MANIFEST_PATH(CWD) (CWD + "\\manifest.vrmanifest")
4646
#endif
4747

4848

@@ -474,6 +474,10 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
474474
std::cout << "-installmanifest install the application vrmanifest" << std::endl;
475475
std::cout << "-removemanifest remove the application vrmanifest" << std::endl;
476476
std::cout << "-activatemultipledrivers enable multiple drivers in steamvr" << std::endl;
477+
#ifdef __linux__
478+
std::cout << "-installdriver install the steam vr driver." << std::endl;
479+
std::cout << "-uninstalldriver uninstall the steam vr driver." << std::endl;
480+
#endif
477481
std::cout << "-help -h print this message" << std::endl;
478482
exit(0);
479483
}
@@ -513,13 +517,14 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
513517
else
514518
{
515519
std::string manifestPath = oldWd;
516-
manifestPath += MANIFEST_END_PATH;
520+
manifestPath = MANIFEST_PATH(manifestPath);
517521
std::cout << "Removing old manifest path: " << manifestPath << std::endl;
518522
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
519523
}
520524
}
521525
std::string manifestPath = cwd;
522-
manifestPath += MANIFEST_END_PATH;
526+
manifestPath = MANIFEST_PATH(manifestPath);
527+
523528
std::cout << "Adding manifest path: " << manifestPath << std::endl;
524529
auto vrAppErr = vr::VRApplications()->AddApplicationManifest(manifestPath.c_str());
525530
if (vrAppErr != vr::VRApplicationError_None)
@@ -545,8 +550,9 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
545550
{
546551
if (vr::VRApplications()->IsApplicationInstalled(OPENVR_APPLICATION_KEY))
547552
{
548-
std::string manifestPath = cwd;
549-
manifestPath += MANIFEST_END_PATH;
553+
std::string manifestPath = cwd;
554+
manifestPath = MANIFEST_PATH(manifestPath);
555+
550556
std::cout << "Removing manifest path: " << manifestPath << std::endl;
551557
vr::VRApplications()->RemoveApplicationManifest(manifestPath.c_str());
552558
}
@@ -581,4 +587,56 @@ static void HandleCommandLine(LPWSTR lpCmdLine)
581587
vr::VR_Shutdown();
582588
exit(ret);
583589
}
590+
#ifdef __linux__
591+
else if (StringMatch(lpCmdLine, L"-installdriver"))
592+
{
593+
auto vrErr = vr::VRInitError_None;
594+
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
595+
if (vrErr != vr::VRInitError_None)
596+
{
597+
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
598+
vr::VR_Shutdown();
599+
exit(-2);
600+
}
601+
602+
char cruntimePath[MAX_PATH] = { 0 };
603+
unsigned int pathLen;
604+
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);
605+
606+
const int cmdLength = 8196;
607+
char cmd[cmdLength];
608+
609+
snprintf(cmd, cmdLength, "python " DRIVER_INSTALLER_PATH "/driverInstall.py --toInstall " DRIVER_MANIFEST_PATH " --vrpathreg %s/bin/vrpathreg.sh", cruntimePath);
610+
printf("cmd: %s\n", cmd);
611+
system(cmd);
612+
613+
vr::VR_Shutdown();
614+
exit(0);
615+
}
616+
else if (StringMatch(lpCmdLine, L"-uninstalldriver"))
617+
{
618+
auto vrErr = vr::VRInitError_None;
619+
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
620+
if (vrErr != vr::VRInitError_None)
621+
{
622+
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
623+
vr::VR_Shutdown();
624+
exit(-2);
625+
}
626+
627+
char cruntimePath[MAX_PATH] = { 0 };
628+
unsigned int pathLen;
629+
vr::VR_GetRuntimePath(cruntimePath, MAX_PATH, &pathLen);
630+
631+
const int cmdLength = 8196;
632+
char cmd[cmdLength];
633+
634+
snprintf(cmd, cmdLength, "\"%s/bin/vrpathreg.sh\" removedriverwithname 01spacecalibrator", cruntimePath);
635+
printf("cmd: %s\n", cmd);
636+
637+
vr::VR_Shutdown();
638+
exit(0);
639+
}
640+
#endif
641+
584642
}

OpenVR-SpaceCalibratorDriver/Comms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class UDPServerSocket{
3333
//TODO verify that 0 is valid for UDP.
3434
sock = socket(AF_INET, SOCK_DGRAM, 0);
3535
if(sock == -1){
36-
LOG("%s", "Failed to create socket");
36+
LOG("Failed to create socket: %s", strerror(errno));
3737
return false;
3838
}
3939

4040
int err = bind(sock, (sockaddr*)&my_addr, sizeof(my_addr));
4141
if(err){
42-
LOG("%s", "Failed to bind socket");
42+
LOG("Failed to bind socket: %s", strerror(errno));
4343
return false;
4444
}
4545
return true;

OpenVR-SpaceCalibratorDriver/Logging.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
#include <chrono>
44
#include <ctime>
55

6+
#ifdef __linux__
7+
#include "StaticConfig.h"
8+
#else
9+
#define DRIVER_LOG_FILE "space_calibrator_driver.log"
10+
#endif
11+
12+
613
FILE *LogFile;
714

815
void OpenLogFile()
916
{
10-
LogFile = fopen("/tmp/space_calibrator_driver.log", "w");
17+
LogFile = fopen(DRIVER_LOG_FILE, "w");
1118
if (LogFile == nullptr)
1219
{
1320
LogFile = stderr;

OpenVR-SpaceCalibratorDriver/build.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

StaticConfig.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#cmakedefine DRIVER_LOG_FILE "@DRIVER_LOG_FILE@"
2+
#cmakedefine APP_MANIFEST_PATH "@APP_MANIFEST_PATH@"
3+
#cmakedefine DRIVER_MANIFEST_PATH "@DRIVER_MANIFEST_PATH@"
4+
#cmakedefine DRIVER_INSTALLER_PATH "@DRIVER_INSTALLER_PATH@"

driverInstall.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
import os, sys
3+
import subprocess
4+
import re
5+
import argparse
6+
7+
#vrpathreg = "/home/zack/.local/share/Steam/steamapps/common/SteamVR/bin/vrpathreg.sh"
8+
9+
def GetDrivers(vrpathreg):
10+
proc = subprocess.Popen([vrpathreg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
11+
(stdout, _) = proc.communicate()
12+
13+
lineno = 0
14+
externalReg = re.compile('.*External Drivers:.*')
15+
lines = stdout.split('\n')
16+
for line in lines:
17+
lineno += 1
18+
if externalReg.match(line):
19+
break
20+
21+
lines = [ x.strip().split(':')[1].strip() for x in lines[lineno:] if len(x) > 0]
22+
return lines
23+
24+
def RemoveDriver(vrpathreg, driver):
25+
cmd = [vrpathreg, 'removedriver', driver]
26+
print(cmd)
27+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
28+
(stdout, _) = proc.communicate()
29+
30+
def AddDriver(vrpathreg, driver):
31+
cmd = [vrpathreg, 'adddriver', driver]
32+
print(cmd)
33+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8')
34+
(stdout, _) = proc.communicate()
35+
36+
def main():
37+
parser = argparse.ArgumentParser()
38+
39+
parser.add_argument('--toInstall', help="Driver to install (folder path)", required=True)
40+
parser.add_argument('--vrpathreg', help="Path to vrpathreg.sh", required=True)
41+
42+
args = parser.parse_args()
43+
44+
fail = False
45+
if not os.path.exists(args.toInstall):
46+
print("Driver path [{args.toInstall}] does not exist")
47+
fail = True
48+
49+
if not os.path.exists(args.vrpathreg):
50+
print("Path to vrpathreg.sh [{args.toInstall}] does not exist")
51+
fail = True
52+
53+
if fail:
54+
return
55+
56+
drivers = GetDrivers(args.vrpathreg)
57+
58+
spaceCalReg = re.compile('.*01spacecalibrator.*')
59+
60+
for driver in drivers:
61+
RemoveDriver(args.vrpathreg, driver)
62+
63+
AddDriver(args.vrpathreg, args.toInstall)
64+
65+
for driver in drivers[::-1]:
66+
if spaceCalReg.match(driver):
67+
continue
68+
69+
AddDriver(args.vrpathreg, driver)
70+
71+
pass
72+
73+
74+
if __name__ == "__main__":
75+
main()
76+

0 commit comments

Comments
 (0)