Skip to content

Commit

Permalink
Add installer
Browse files Browse the repository at this point in the history
  • Loading branch information
pushrax committed Aug 8, 2018
1 parent 35690d8 commit a93dac0
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 43 deletions.
88 changes: 48 additions & 40 deletions OpenVR-SpaceCalibrator/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ vr::HmdVector3d_t VRTranslationVec(Eigen::Vector3d transcm)
return vrTrans;
}

void ResetAndDisableOffsets(uint32_t id)
{
vr::HmdVector3d_t zeroV;
zeroV.v[0] = zeroV.v[1] = zeroV.v[2] = 0;

vr::HmdQuaternion_t zeroQ;
zeroQ.x = 0; zeroQ.y = 0; zeroQ.z = 0; zeroQ.w = 1;

protocol::Request req(protocol::RequestSetDeviceTransform);
req.setDeviceTransform = { id, false, zeroV, zeroQ };
Driver.SendBlocking(req);
}

void ScanAndApplyProfile(CalibrationContext &ctx)
{
char buffer[vr::k_unMaxPropertyStringSize];
Expand All @@ -292,55 +305,52 @@ void ScanAndApplyProfile(CalibrationContext &ctx)
vr::ETrackedPropertyError err = vr::TrackedProp_Success;
auto universeId = vr::VRSystem()->GetUint64TrackedDeviceProperty(id, vr::Prop_CurrentUniverseId_Uint64, &err);
printf("uid %d err %d\n", universeId, err);
ResetAndDisableOffsets(id);
continue;
}*/

if (!ctx.validProfile)
{
ResetAndDisableOffsets(id);
continue;
}

if (deviceClass == vr::TrackedDeviceClass_TrackingReference || deviceClass == vr::TrackedDeviceClass_HMD)
{
//auto p = ctx.devicePoses[id].mDeviceToAbsoluteTracking.m;
//printf("REF %d: %f %f %f\n", id, p[0][3], p[1][3], p[2][3]);
ResetAndDisableOffsets(id);
continue;
}

vr::ETrackedPropertyError err = vr::TrackedProp_Success;
vr::VRSystem()->GetStringTrackedDeviceProperty(id, vr::Prop_TrackingSystemName_String, buffer, vr::k_unMaxPropertyStringSize, &err);

if (err != vr::TrackedProp_Success)
{
ResetAndDisableOffsets(id);
continue;
}

std::string trackingSystem(buffer);

if (trackingSystem != ctx.targetTrackingSystem)
continue;

if (deviceClass == vr::TrackedDeviceClass_TrackingReference || deviceClass == vr::TrackedDeviceClass_HMD)
{
// TODO(pushrax): detect zero reference switches and adjust calibration automatically
//auto p = ctx.devicePoses[id].mDeviceToAbsoluteTracking.m;
//printf("REF %d: %f %f %f\n", id, p[0][3], p[1][3], p[2][3]);
ResetAndDisableOffsets(id);
continue;
}
else
{
//printf("setting calibration for %d (%s)\n", id, buffer);

protocol::Request req(protocol::RequestSetDeviceTransform);
req.setDeviceTransform = {
id,
true,
VRTranslationVec(ctx.calibratedTranslation),
VRRotationQuat(ctx.calibratedRotation)
};
Driver.SendBlocking(req);
}
protocol::Request req(protocol::RequestSetDeviceTransform);
req.setDeviceTransform = {
id,
true,
VRTranslationVec(ctx.calibratedTranslation),
VRRotationQuat(ctx.calibratedRotation)
};
Driver.SendBlocking(req);
}
}

void ResetAndDisableOffsets(uint32_t id)
{
vr::HmdVector3d_t zeroV;
zeroV.v[0] = zeroV.v[1] = zeroV.v[2] = 0;

vr::HmdQuaternion_t zeroQ;
zeroQ.x = 0; zeroQ.y = 0; zeroQ.z = 0; zeroQ.w = 1;

protocol::Request req(protocol::RequestSetDeviceTransform);
req.setDeviceTransform = { id, false, zeroV, zeroQ };
Driver.SendBlocking(req);
}

void StartCalibration()
{
CalCtx.state = CalibrationState::Begin;
Expand All @@ -364,10 +374,7 @@ void CalibrationTick(double time)
{
ctx.wantedUpdateInterval = 1.0;

if (!ctx.validProfile)
return;

if ((time - ctx.timeLastScan) >= 2.5)
if ((time - ctx.timeLastScan) >= 1.0)
{
ScanAndApplyProfile(ctx);
ctx.timeLastScan = time;
Expand All @@ -377,12 +384,13 @@ void CalibrationTick(double time)

if (ctx.state == CalibrationState::Editing)
{
ctx.wantedUpdateInterval = 0.0;
ctx.wantedUpdateInterval = 0.1;

if (!ctx.validProfile)
return;

ScanAndApplyProfile(ctx);
if ((time - ctx.timeLastScan) >= 0.1)
{
ScanAndApplyProfile(ctx);
ctx.timeLastScan = time;
}
return;
}

Expand Down
18 changes: 16 additions & 2 deletions OpenVR-SpaceCalibrator/OpenVR-SpaceCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,24 @@ void RunLoop()

int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
//CreateConsole();

if (lstrcmp(lpCmdLine, L"-openvrpath") == 0)
{
auto vrErr = vr::VRInitError_None;
vr::VR_Init(&vrErr, vr::VRApplication_Utility);
if (vrErr == vr::VRInitError_None)
{
printf("%s", vr::VR_RuntimePath());
vr::VR_Shutdown();
Sleep(2000);
return 0;
}
fprintf(stderr, "Failed to initialize OpenVR: %s\n", vr::VR_GetVRInitErrorAsEnglishDescription(vrErr));
vr::VR_Shutdown();
return -2;
}

if (!glfwInit())
{
MessageBox(nullptr, L"Failed to initialize GLFW", L"", 0);
Expand Down
2 changes: 1 addition & 1 deletion OpenVR-SpaceCalibrator/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void BuildMainWindow()

ImGui::SetNextWindowPos(ImVec2(ImGui::GetWindowWidth() - 60.0f, ImGui::GetWindowHeight() - ImGui::GetItemsLineHeightWithSpacing()));
ImGui::BeginChild("version stuff", ImVec2(60.0f, ImGui::GetItemsLineHeightWithSpacing() * 2), false);
ImGui::Text("v0.5");
ImGui::Text("v0.6a");
ImGui::EndChild();

ImGui::End();
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"alwaysActivate": true,
"name" : "000spacecalibrator",
"directory" : "",
"resourceOnly" : false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jsonid" : "vrresources",
"statusicons" : {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"driver_000spacecalibrator" : {
}
}
179 changes: 179 additions & 0 deletions install/installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@

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

!include "MUI2.nsh"

;--------------------------------
;General

!define OVERLAY_BASEDIR "..\client_overlay\bin\win64"
!define DRIVER_RESDIR "..\OpenVR-SpaceCalibratorDriver\000spacecalibrator"

;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

;--------------------------------
;Variables

VAR upgradeInstallation

;--------------------------------
;Interface Settings

!define MUI_ABORTWARNING

;--------------------------------
;Pages

!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
!define MUI_PAGE_CUSTOMFUNCTION_PRE dirPre
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"

;--------------------------------
;Macros

;--------------------------------
;Functions

Function dirPre
StrCmp $upgradeInstallation "true" 0 +2
Abort
FunctionEnd

Function .onInit
StrCpy $upgradeInstallation "false"

ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator" "UninstallString"
StrCmp $R0 "" done


; If SteamVR is already running, display a warning message and exit
FindWindow $0 "Qt5QWindowIcon" "SteamVR Status"
StrCmp $0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION \
"SteamVR is still running. Cannot install this software.$\nPlease close SteamVR and try again."
Abort


MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"OpenVR-SpaceCalibrator is already installed. $\n$\nClick `OK` to upgrade the \
existing installation or `Cancel` to cancel this upgrade." \
IDOK upgrade
Abort

upgrade:
StrCpy $upgradeInstallation "true"
done:
FunctionEnd

;--------------------------------
;Installer Sections

Section "Install" SecInstall

StrCmp $upgradeInstallation "true" 0 noupgrade
DetailPrint "Uninstall previous version..."
ExecWait '"$INSTDIR\Uninstall.exe" /S _?=$INSTDIR'
Delete $INSTDIR\Uninstall.exe
Goto afterupgrade

noupgrade:

afterupgrade:

SetOutPath "$INSTDIR"

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

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

Var /GLOBAL vrRuntimePath
nsExec::ExecToStack '"$INSTDIR\OpenVR-SpaceCalibrator.exe" -openvrpath'
Pop $0
Pop $vrRuntimePath
DetailPrint "VR runtime path: $vrRuntimePath"

SetOutPath "$vrRuntimePath\drivers\000spacecalibrator"
File "${DRIVER_RESDIR}\driver.vrdrivermanifest"
SetOutPath "$vrRuntimePath\drivers\000spacecalibrator\resources"
File "${DRIVER_RESDIR}\resources\driver.vrresources"
SetOutPath "$vrRuntimePath\drivers\000spacecalibrator\resources\settings"
File "${DRIVER_RESDIR}\resources\settings\default.vrsettings"
SetOutPath "$vrRuntimePath\drivers\000spacecalibrator\bin\win64"
File "..\x64\Release\driver_000spacecalibrator.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$\""

CreateShortCut "$SMPROGRAMS\OpenVR-SpaceCalibrator.lnk" "$INSTDIR\OpenVR-SpaceCalibrator.exe"

SectionEnd

;--------------------------------
;Uninstaller Section

Section "Uninstall"
; If SteamVR is already running, display a warning message and exit
FindWindow $0 "Qt5QWindowIcon" "SteamVR Status"
StrCmp $0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION \
"SteamVR is still running. Cannot uninstall this software.$\nPlease close SteamVR and try again."
Abort

; Delete installed files
Var /GLOBAL vrRuntimePath2
ReadRegStr $vrRuntimePath2 HKLM "Software\OpenVR-SpaceCalibrator\Driver" ""
DetailPrint "VR runtime path: $vrRuntimePath2"
Delete "$vrRuntimePath2\drivers\000spacecalibrator\driver.vrdrivermanifest"
Delete "$vrRuntimePath2\drivers\000spacecalibrator\resources\driver.vrresources"
Delete "$vrRuntimePath2\drivers\000spacecalibrator\resources\settings\default.vrsettings"
Delete "$vrRuntimePath2\drivers\000spacecalibrator\bin\win64\driver_000spacecalibrator.dll"
Delete "$vrRuntimePath2\drivers\000spacecalibrator\bin\win64\space_calibrator_driver.log"
RMdir "$vrRuntimePath2\drivers\000spacecalibrator\resources\settings"
RMdir "$vrRuntimePath2\drivers\000spacecalibrator\resources\"
RMdir "$vrRuntimePath2\drivers\000spacecalibrator\bin\win64\"
RMdir "$vrRuntimePath2\drivers\000spacecalibrator\bin\"
RMdir "$vrRuntimePath2\drivers\000spacecalibrator\"

Delete "$INSTDIR\LICENSE"
Delete "$INSTDIR\OpenVR-SpaceCalibrator.exe"
Delete "$INSTDIR\openvr_api.dll"

DeleteRegKey HKLM "Software\OpenVR-SpaceCalibrator\Main"
DeleteRegKey HKLM "Software\OpenVR-SpaceCalibrator\Driver"
DeleteRegKey HKLM "Software\OpenVR-SpaceCalibrator"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenVRSpaceCalibrator"

Delete "$SMPROGRAMS\OpenVR-SpaceCalibrator.lnk"
SectionEnd

0 comments on commit a93dac0

Please sign in to comment.