Commit e4d3f775 authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Roll OpenVR SDK 1.8.19

The OpenVR SDK has made some changes that we need since the last time it
was updated. Primarily, this is the addition of the method:
GetAppContainerFilePaths and a few other updates intended to allow the
SDK to work better in the AppContainer version of the WebXr device
process.

Some prototyping will still need to be done before this can actually be
achieved, but doing this first roll better enables that and sets up a
(hopefully) smaller diff if another roll is needed due to any issues
discovered during prototyping.

Fixed:845255

Change-Id: I6f9af21df282b3fe90cd9855aefd4b4ff9cc3c56
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1935411Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722658}
parent 14cb217e
......@@ -88,6 +88,10 @@ if (enable_vr) {
}
if (enable_openvr) {
if (!is_component_build) {
defines += ["OPENVR_BUILD_STATIC"]
}
deps += [ "//third_party/openvr:openvr" ]
sources += [
"openvr/openvr_api_wrapper.cc",
......
......@@ -51,6 +51,9 @@ device::mojom::XRHandedness ConvertToMojoHandedness(
case vr::TrackedControllerRole_RightHand:
return device::mojom::XRHandedness::RIGHT;
case vr::TrackedControllerRole_Invalid:
case vr::TrackedControllerRole_OptOut:
case vr::TrackedControllerRole_Treadmill:
case vr::TrackedControllerRole_Max:
return device::mojom::XRHandedness::NONE;
}
......
......@@ -48,6 +48,11 @@ class TestVRSystem : public IVRSystem {
return 0;
}
void GetDXGIOutputInfo(int32_t* adapter_index) override;
void GetOutputDevice(uint64_t* pnDevice,
ETextureType textureType,
VkInstance_T* pInstance = nullptr) override {
NOTIMPLEMENTED();
}
bool IsDisplayOnDesktop() override {
NOTIMPLEMENTED();
return false;
......@@ -127,6 +132,16 @@ class TestVRSystem : public IVRSystem {
NOTIMPLEMENTED();
return {};
}
uint32_t GetArrayTrackedDeviceProperty(
vr::TrackedDeviceIndex_t unDeviceIndex,
ETrackedDeviceProperty prop,
PropertyTypeTag_t propType,
void* pBuffer,
uint32_t unBufferSize,
ETrackedPropertyError* pError = 0L) override {
NOTIMPLEMENTED();
return 0;
}
uint32_t GetStringTrackedDeviceProperty(
TrackedDeviceIndex_t device_index,
ETrackedDeviceProperty prop,
......@@ -179,21 +194,21 @@ class TestVRSystem : public IVRSystem {
NOTIMPLEMENTED();
return nullptr;
}
bool CaptureInputFocus() override {
bool IsInputAvailable() override {
NOTIMPLEMENTED();
return false;
}
void ReleaseInputFocus() override { NOTIMPLEMENTED(); }
bool IsInputFocusCapturedByAnotherProcess() override {
bool IsSteamVRDrawingControllers() override {
NOTIMPLEMENTED();
return false;
}
uint32_t DriverDebugRequest(TrackedDeviceIndex_t device_index,
const char* request,
char* response_buffer,
uint32_t response_buffer_size) override {
bool ShouldApplicationPause() override {
NOTIMPLEMENTED();
return 0;
return false;
}
bool ShouldApplicationReduceRenderingWork() override {
NOTIMPLEMENTED();
return false;
}
EVRFirmwareError PerformFirmwareUpdate(
TrackedDeviceIndex_t device_index) override {
......@@ -201,7 +216,15 @@ class TestVRSystem : public IVRSystem {
return VRFirmwareError_None;
}
void AcknowledgeQuit_Exiting() override { NOTIMPLEMENTED(); }
void AcknowledgeQuit_UserPrompt() override { NOTIMPLEMENTED(); }
uint32_t GetAppContainerFilePaths(VR_OUT_STRING() char* pchBuffer,
uint32_t unBufferSize) override {
NOTIMPLEMENTED();
return 0;
}
const char* GetRuntimeVersion() override {
NOTIMPLEMENTED();
return "";
}
};
class TestVRCompositor : public IVRCompositor {
......@@ -357,11 +380,31 @@ class TestVRCompositor : public IVRCompositor {
NOTIMPLEMENTED();
return 0;
}
void SetExplicitTimingMode(EVRCompositorTimingMode eTimingMode) override {
NOTIMPLEMENTED();
}
EVRCompositorError SubmitExplicitTimingData() override {
NOTIMPLEMENTED();
return VRCompositorError_None;
}
bool IsMotionSmoothingEnabled() override {
NOTIMPLEMENTED();
return false;
}
bool IsMotionSmoothingSupported() override {
NOTIMPLEMENTED();
return false;
}
bool IsCurrentSceneFocusAppLoading() override {
NOTIMPLEMENTED();
return false;
}
};
class TestVRClientCore : public IVRClientCore {
public:
EVRInitError Init(EVRApplicationType application_type) override;
EVRInitError Init(EVRApplicationType application_type,
const char* pStartupInfo) override;
void Cleanup() override;
EVRInitError IsInterfaceVersionValid(const char* interface_version) override;
void* GetGenericInterface(const char* name_and_version,
......@@ -382,7 +425,8 @@ TestVRSystem g_system;
TestVRCompositor g_compositor;
TestVRClientCore g_loader;
EVRInitError TestVRClientCore::Init(EVRApplicationType application_type) {
EVRInitError TestVRClientCore::Init(EVRApplicationType application_type,
const char* pStartupInfo) {
return VRInitError_None;
}
......
Name: OpenVR SDK
Short Name: OpenVR
URL: https://github.com/ValveSoftware/openvr
Version: 1.0.4
Date: 2 Feb 2017
Revision: 7fa6470f2972970859f2395f1390f6d87d4b0fc3
Version: 1.8.19
Date: 5 Nov 2019
Revision: 176b58f6ccaaae3e9d14efaf612c50b72ec5da76
License: BSD 3-Clause
License File: src/LICENSE
Security Critical: yes
......@@ -12,15 +12,14 @@ Description:
The OpenVR API supports HTC Vive and other headsets for VR.
Local Modifications:
Only contains a subset of the git repo necessary to build Chromium.
openvr.h has been modified to remove dllimport/dllexport when building a
non-component build so this can be built as a static library.
Only contains a subset of the git repo necessary to build Chromium. (Note that
this includes removing jsoncpp as we use it from \\third_party).
Redefined VRLog to avoid logspam on startup.
We use jsoncpp from \\third_party.
merge https://github.com/ValveSoftware/openvr/pull/1048
Define alloca to map to _alloca on Windows
Use #defines to remove try/catch from vrpathregistry_public.cpp
Copy the correct files with these commands:
copy %openvrsdk%\README.md %chromium%\src\third_party\openvr\src
copy %openvrsdk%\LICENSE %chromium%\src\third_party\openvr\src
xcopy /S %openvrsdk%\src %chromium%\src\third_party\openvr\src\src
xcopy /S %openvrsdk%\headers %chromium%\src\third_party\openvr\src\headers
copy %openvrsdk%\README.md %chromiumopenvr%\src
copy %openvrsdk%\LICENSE %chromiumopenvr%\src
xcopy /S %openvrsdk%\src %chromiumopenvr%\src\src /EXCLUDE:%chromiumopenvr%\openvr_jsoncpp.txt
xcopy /S %openvrsdk%\headers %chromiumopenvr%\src\headers /EXCLUDE:%chromiumopenvr%\openvr_jsoncpp.txt
src\json
headers\openvr_api.json
headers\openvr_api.cs
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -2,18 +2,19 @@
project(openvr_api)
set( LIBNAME "openvr_api" )
set(OPENVR_HEADER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../headers)
# Set some properies for specific files.
if(APPLE)
set(CMAKE_MACOSX_RPATH 0)
set(CMAKE_MACOSX_RPATH 1)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set_source_files_properties(vrcommon/pathtools_public.cpp vrcommon/vrpathregistry_public.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++")
endif()
if(BUILD_SHARED)
if(BUILD_SHARED OR BUILD_FRAMEWORK)
find_library(FOUNDATION_FRAMEWORK Foundation)
mark_as_advanced(FOUNDATION_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${FOUNDATION_FRAMEWORK})
endif(BUILD_SHARED)
endif(BUILD_SHARED OR BUILD_FRAMEWORK)
elseif(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions( -DWIN64 )
......@@ -22,7 +23,7 @@ elseif(WIN32)
endif()
# Add include folders.
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/headers ${CMAKE_SOURCE_DIR}/src/vrcommon)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../headers ${CMAKE_CURRENT_SOURCE_DIR}/vrcommon)
if(USE_CUSTOM_LIBCXX)
link_directories(
......@@ -50,6 +51,12 @@ set(SOURCE_FILES
${VRCOMMON_FILES}
)
set(PUBLIC_HEADER_FILES
${OPENVR_HEADER_DIR}/openvr_driver.h
${OPENVR_HEADER_DIR}/openvr_capi.h
${OPENVR_HEADER_DIR}/openvr.h
)
source_group("Src" FILES
${CORE_FILES}
)
......@@ -61,6 +68,28 @@ source_group("VRCommon" FILES
# Build the library.
if(BUILD_SHARED)
add_library(${LIBNAME} SHARED ${SOURCE_FILES})
elseif(BUILD_FRAMEWORK)
set( LIBNAME "OpenVR" )
add_library( ${LIBNAME}
SHARED ${SOURCE_FILES}
${CMAKE_SOURCE_DIR}/headers/openvr.h
${CMAKE_SOURCE_DIR}/headers/openvr_api.cs
${CMAKE_SOURCE_DIR}/headers/openvr_api.json
${CMAKE_SOURCE_DIR}/headers/openvr_capi.h
${CMAKE_SOURCE_DIR}/headers/openvr_driver.h
)
set_target_properties(OpenVR PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION A
MACOSX_FRAMEWORK_IDENTIFIER com.valvesoftware.OpenVR.framework
MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_SOURCE_DIR}/src/Info.plist
# "current version" in semantic format in Mach-O binary file
VERSION 1.0.6
# "compatibility version" in semantic format in Mach-O binary file
SOVERSION 1.0.0
PUBLIC_HEADER "${CMAKE_SOURCE_DIR}/headers/openvr.h;${CMAKE_SOURCE_DIR}/headers/openvr_api.cs;${CMAKE_SOURCE_DIR}/headers/openvr_api.json;${CMAKE_SOURCE_DIR}/headers/openvr_capi.h;${CMAKE_SOURCE_DIR}/headers/openvr_driver.h"
LINKER_LANGUAGE CXX
)
else()
add_library(${LIBNAME} STATIC ${SOURCE_FILES})
endif()
......@@ -69,6 +98,19 @@ if(USE_CUSTOM_LIBCXX)
set(EXTRA_LIBS ${EXTRA_LIBS} c++ c++abi)
endif()
target_link_libraries(${LIBNAME} ${EXTRA_LIBS})
target_link_libraries(${LIBNAME} ${EXTRA_LIBS} ${CMAKE_DL_LIBS})
target_include_directories(${LIBNAME} PUBLIC ${OPENVR_HEADER_DIR})
install(TARGETS ${LIBNAME} DESTINATION lib)
install(FILES ${PUBLIC_HEADER_FILES} DESTINATION include/openvr)
# Generate a .pc file for linux environments
if(PLATFORM_NAME MATCHES "linux")
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
CONFIGURE_FILE("openvr.pc.in" "openvr.pc" @ONLY)
set(OPENVR_PC ${CMAKE_CURRENT_BINARY_DIR}/openvr.pc)
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
install(FILES ${OPENVR_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
endif()
endif()
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.valvesoftware.OpenVR.framework</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>OpenVR</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>
......@@ -3,9 +3,9 @@ OpenVR applications to the SteamVR runtime, taking into account the version
of the OpenVR interface they were compiled against.
The client binding library - openvr_api.dll on Windows, openvr_api.so on
Linux, and openvr_api.dylib on macOS - knows how to find and read the
SteamVR runtime installation information which allows it to find and
dynamically connect to the installed runtime. In combination with the
Linux, and openvr_api.dylib or OpenVR.framework on macOS - knows how to find
and read the SteamVR runtime installation information which allows it to
find and dynamically connect to the installed runtime. In combination with the
interface version identifiers from /include/openvr.h which are baked
into applications at the time they are built, the OpenVR API client
binding library captures and conveys to the SteamVR runtime the version
......@@ -32,4 +32,8 @@ for your platform. For example, to build on a POSIX system simply perform
cd src; mkdir _build; cd _build; cmake ..; make
and you will end up with the static library /src/_build/libopenvr_api.a
\ No newline at end of file
and you will end up with the static library /src/bin/<arch>/libopenvr_api.a
To build a shared library, pass -DBUILD_SHARED=1 to cmake.
To build as a framework on apple platforms, pass -DBUILD_FRAMEWORK=1 to cmake.
To see a complete list of configurable build options, use `cmake -LAH`
......@@ -8,7 +8,7 @@ class IVRClientCore
{
public:
/** Initializes the system */
virtual EVRInitError Init( vr::EVRApplicationType eApplicationType ) = 0;
virtual EVRInitError Init( vr::EVRApplicationType eApplicationType, const char *pStartupInfo ) = 0;
/** cleans up everything in vrclient.dll and prepares the DLL to be unloaded */
virtual void Cleanup() = 0;
......@@ -22,14 +22,14 @@ public:
/** Returns true if any driver has an HMD attached. Can be called outside of Init/Cleanup */
virtual bool BIsHmdPresent() = 0;
/** Returns an english error string from inside vrclient.dll which might be newer than the API DLL */
/** Returns an English error string from inside vrclient.dll which might be newer than the API DLL */
virtual const char *GetEnglishStringForHmdError( vr::EVRInitError eError ) = 0;
/** Returns an error symbol from inside vrclient.dll which might be newer than the API DLL */
virtual const char *GetIDForVRInitError( vr::EVRInitError eError ) = 0;
};
static const char * const IVRClientCore_Version = "IVRClientCore_002";
static const char * const IVRClientCore_Version = "IVRClientCore_003";
}
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include/openvr
Name: openvr
Description: OpenVR is an API and runtime that allos access to VR hardware.
Version: @OPENVR_VERSION@
Libs: -L${libdir} -lopenvr_api -ldl
Cflags: -I${includedir}
......@@ -6,18 +6,38 @@
#include "sharedlibtools_public.h"
#include "envvartools_public.h"
#include "hmderrors_public.h"
#include "strtools_public.h"
#include "vrpathregistry_public.h"
#include <mutex>
using vr::EVRInitError;
using vr::IVRSystem;
using vr::IVRClientCore;
using vr::VRInitError_None;
// figure out how to import from the VR API dll
#if defined(_WIN32)
#if !defined(OPENVR_BUILD_STATIC)
#define VR_EXPORT_INTERFACE extern "C" __declspec( dllexport )
#else
#define VR_EXPORT_INTERFACE extern "C"
#endif
#elif defined(__GNUC__) || defined(COMPILER_GCC) || defined(__APPLE__)
#define VR_EXPORT_INTERFACE extern "C" __attribute__((visibility("default")))
#else
#error "Unsupported Platform."
#endif
namespace vr
{
static void *g_pVRModule = NULL;
static IVRClientCore *g_pHmdSystem = NULL;
static std::recursive_mutex g_mutexSystem;
typedef void* (*VRClientCoreFactoryFn)(const char *pInterfaceName, int *pReturnCode);
......@@ -33,50 +53,50 @@ EVRInitError VR_LoadHmdSystemInternal();
void CleanupInternalInterfaces();
uint32_t VR_InitInternal( EVRInitError *peError, vr::EVRApplicationType eApplicationType )
uint32_t VR_InitInternal2( EVRInitError *peError, vr::EVRApplicationType eApplicationType, const char *pStartupInfo )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
EVRInitError err = VR_LoadHmdSystemInternal();
if (err != vr::VRInitError_None)
if ( err == vr::VRInitError_None )
{
SharedLib_Unload(g_pVRModule);
g_pHmdSystem = NULL;
g_pVRModule = NULL;
if (peError)
*peError = err;
return 0;
err = g_pHmdSystem->Init( eApplicationType, pStartupInfo );
}
err = g_pHmdSystem->Init(eApplicationType);
if (err != VRInitError_None)
if ( peError )
*peError = err;
if ( err != VRInitError_None )
{
SharedLib_Unload(g_pVRModule);
SharedLib_Unload( g_pVRModule );
g_pHmdSystem = NULL;
g_pVRModule = NULL;
if (peError)
*peError = err;
return 0;
}
if (peError)
*peError = VRInitError_None;
return ++g_nVRToken;
}
VR_INTERFACE uint32_t VR_CALLTYPE VR_InitInternal( EVRInitError *peError, EVRApplicationType eApplicationType );
uint32_t VR_InitInternal( EVRInitError *peError, vr::EVRApplicationType eApplicationType )
{
return VR_InitInternal2( peError, eApplicationType, nullptr );
}
void VR_ShutdownInternal()
{
if (g_pHmdSystem)
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if ( g_pHmdSystem )
{
g_pHmdSystem->Cleanup();
g_pHmdSystem = NULL;
}
if (g_pVRModule)
if ( g_pVRModule )
{
SharedLib_Unload(g_pVRModule);
SharedLib_Unload( g_pVRModule );
g_pVRModule = NULL;
}
......@@ -106,7 +126,7 @@ EVRInitError VR_LoadHmdSystemInternal()
// Because we don't have a way to select debug vs. release yet we'll just
// use debug if it's there
#if defined( LINUX64 )
#if defined( LINUX64 ) || defined( LINUXARM64 )
std::string sTestPath = Path_Join( sRuntimePath, "bin", PLATSUBDIR );
#else
std::string sTestPath = Path_Join( sRuntimePath, "bin" );
......@@ -152,6 +172,8 @@ EVRInitError VR_LoadHmdSystemInternal()
void *VR_GetGenericInterface(const char *pchInterfaceVersion, EVRInitError *peError)
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if (!g_pHmdSystem)
{
if (peError)
......@@ -164,6 +186,8 @@ void *VR_GetGenericInterface(const char *pchInterfaceVersion, EVRInitError *peEr
bool VR_IsInterfaceVersionValid(const char *pchInterfaceVersion)
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if (!g_pHmdSystem)
{
return false;
......@@ -174,6 +198,8 @@ bool VR_IsInterfaceVersionValid(const char *pchInterfaceVersion)
bool VR_IsHmdPresent()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if( g_pHmdSystem )
{
// if we're already initialized, just call through
......@@ -199,6 +225,8 @@ bool VR_IsHmdPresent()
/** Returns true if the OpenVR runtime is installed. */
bool VR_IsRuntimeInstalled()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if( g_pHmdSystem )
{
// if we're already initialized, OpenVR is obviously installed
......@@ -228,33 +256,71 @@ bool VR_IsRuntimeInstalled()
}
// -------------------------------------------------------------------------------
// Purpose: This is the old Runtime Path interface that is no longer exported in the
// latest header. We still want to export it from the DLL, though, so updating
// to a new DLL doesn't break old compiled code. This version was not thread
// safe and could change the buffer pointer to by a previous result on a
// subsequent call
// -------------------------------------------------------------------------------
VR_EXPORT_INTERFACE const char *VR_CALLTYPE VR_RuntimePath();
/** Returns where OpenVR runtime is installed. */
const char *VR_RuntimePath()
{
static char rchBuffer[1024];
uint32_t unRequiredSize;
if ( VR_GetRuntimePath( rchBuffer, sizeof( rchBuffer ), &unRequiredSize ) && unRequiredSize < sizeof( rchBuffer ) )
{
return rchBuffer;
}
else
{
return nullptr;
}
}
/** Returns where OpenVR runtime is installed. */
bool VR_GetRuntimePath( char *pchPathBuffer, uint32_t unBufferSize, uint32_t *punRequiredBufferSize )
{
// otherwise we need to do a bit more work
static std::string sRuntimePath;
std::string sConfigPath, sLogPath;
std::string sRuntimePath;
bool bReadPathRegistry = CVRPathRegistry_Public::GetPaths( &sRuntimePath, &sConfigPath, &sLogPath, NULL, NULL );
*punRequiredBufferSize = 0;
bool bReadPathRegistry = CVRPathRegistry_Public::GetPaths( &sRuntimePath, nullptr, nullptr, nullptr, nullptr );
if ( !bReadPathRegistry )
{
return nullptr;
return false;
}
// figure out where we're going to look for vrclient.dll
// see if the specified path actually exists.
if ( !Path_IsDirectory( sRuntimePath ) )
{
return nullptr;
return false;
}
*punRequiredBufferSize = (uint32_t)sRuntimePath.size() + 1;
if ( sRuntimePath.size() >= unBufferSize )
{
*pchPathBuffer = '\0';
}
else
{
strcpy_safe( pchPathBuffer, unBufferSize, sRuntimePath.c_str() );
}
return sRuntimePath.c_str();
return true;
}
/** Returns the symbol version of an HMD error. */
const char *VR_GetVRInitErrorAsSymbol( EVRInitError error )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if( g_pHmdSystem )
return g_pHmdSystem->GetIDForVRInitError( error );
else
......@@ -265,6 +331,8 @@ const char *VR_GetVRInitErrorAsSymbol( EVRInitError error )
/** Returns the english string version of an HMD error. */
const char *VR_GetVRInitErrorAsEnglishDescription( EVRInitError error )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if ( g_pHmdSystem )
return g_pHmdSystem->GetEnglishStringForHmdError( error );
else
......
//========= Copyright Valve Corporation ============//
#include "envvartools_public.h"
#include "strtools_public.h"
#include <stdlib.h>
#include <string>
#include <cctype>
#if defined(_WIN32)
#include <Windows.h>
#include <windows.h>
#undef GetEnvironmentVariable
#undef SetEnvironmentVariable
......@@ -30,6 +33,45 @@ std::string GetEnvironmentVariable( const char *pchVarName )
#endif
}
bool GetEnvironmentVariableAsBool( const char *pchVarName, bool bDefault )
{
std::string sValue = GetEnvironmentVariable( pchVarName );
if ( sValue.empty() )
{
return bDefault;
}
sValue = StringToLower( sValue );
std::string sYesValues[] = { "y", "yes", "true" };
std::string sNoValues[] = { "n", "no", "false" };
for ( std::string &sMatch : sYesValues )
{
if ( sMatch == sValue )
{
return true;
}
}
for ( std::string &sMatch : sNoValues )
{
if ( sMatch == sValue )
{
return false;
}
}
if ( std::isdigit( sValue.at(0) ) )
{
return atoi( sValue.c_str() ) != 0;
}
fprintf( stderr,
"GetEnvironmentVariableAsBool(%s): Unable to parse value '%s', using default %d\n",
pchVarName, sValue.c_str(), bDefault );
return bDefault;
}
bool SetEnvironmentVariable( const char *pchVarName, const char *pchVarValue )
{
......
......@@ -4,4 +4,5 @@
#include <string>
std::string GetEnvironmentVariable( const char *pchVarName );
bool GetEnvironmentVariableAsBool( const char *pchVarName, bool bDefault );
bool SetEnvironmentVariable( const char *pchVarName, const char *pchVarValue );
......@@ -3,19 +3,23 @@
#include "pathtools_public.h"
#if defined( _WIN32)
#include <Windows.h>
#include <windows.h>
#include <direct.h>
#include <Shobjidl.h>
#include <KnownFolders.h>
#include <Shlobj.h>
#include <shobjidl.h>
#include <knownfolders.h>
#include <shlobj.h>
#include <share.h>
#undef GetEnvironmentVariable
#define alloca _alloca
#else
#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <alloca.h>
#endif
#if defined OSX
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
......@@ -96,6 +100,24 @@ bool Path_SetWorkingDirectory( const std::string & sPath )
return bSuccess;
}
/** Gets the path to a temporary directory. */
std::string Path_GetTemporaryDirectory()
{
#if defined( _WIN32 )
wchar_t buf[MAX_UNICODE_PATH];
if ( GetTempPathW( MAX_UNICODE_PATH, buf ) == 0 )
return Path_GetWorkingDirectory();
return UTF16to8( buf );
#else
const char *pchTmpDir = getenv( "TMPDIR" );
if ( pchTmpDir == NULL )
{
return "";
}
return pchTmpDir;
#endif
}
/** Returns the specified path without its filename */
std::string Path_StripFilename( const std::string & sPath, char slash )
{
......@@ -122,7 +144,7 @@ std::string Path_StripDirectory( const std::string & sPath, char slash )
return std::string( sPath.begin() + n + 1, sPath.end() );
}
/** returns just the filename with no extension of the provided filename.
/** returns just the filename with no extension of the provided filename.
* If there is a path the path is left intact. */
std::string Path_StripExtension( const std::string & sPath )
{
......@@ -187,19 +209,16 @@ bool Path_IsAbsolute( const std::string & sPath )
/** Makes an absolute path from a relative path and a base path */
std::string Path_MakeAbsolute( const std::string & sRelativePath, const std::string & sBasePath, char slash )
std::string Path_MakeAbsolute( const std::string & sRelativePath, const std::string & sBasePath )
{
if( slash == 0 )
slash = Path_GetSlash();
if( Path_IsAbsolute( sRelativePath ) )
return sRelativePath;
return Path_Compact( sRelativePath );
else
{
if( !Path_IsAbsolute( sBasePath ) )
return "";
std::string sCompacted = Path_Compact( Path_Join( sBasePath, sRelativePath, slash ), slash );
std::string sCompacted = Path_Compact( Path_Join( sBasePath, sRelativePath ) );
if( Path_IsAbsolute( sCompacted ) )
return sCompacted;
else
......@@ -267,12 +286,12 @@ std::string Path_Join( const std::string & first, const std::string & second, co
return Path_Join( Path_Join( Path_Join( first, second, slash ), third, slash ), fourth, slash );
}
std::string Path_Join(
const std::string & first,
const std::string & second,
const std::string & third,
const std::string & fourth,
const std::string & fifth,
std::string Path_Join(
const std::string & first,
const std::string & second,
const std::string & third,
const std::string & fourth,
const std::string & fifth,
char slash )
{
return Path_Join( Path_Join( Path_Join( Path_Join( first, second, slash ), third, slash ), fourth, slash ), fifth, slash );
......@@ -303,17 +322,17 @@ std::string Path_RemoveTrailingSlash( const std::string & sRawPath, char slash )
break;
}
}
if ( nLastFound >= 0 )
{
sPath.erase( nLastFound, std::string::npos );
}
return sPath;
}
/** Removes redundant <dir>/.. elements in the path. Returns an empty path if the
/** Removes redundant <dir>/.. elements in the path. Returns an empty path if the
* specified path has a broken number of directories for its number of ..s */
std::string Path_Compact( const std::string & sRawPath, char slash )
{
......@@ -348,7 +367,7 @@ std::string Path_Compact( const std::string & sRawPath, char slash )
}
}
// get rid of leading ./
// get rid of leading ./
if( sPath.length() > 2 )
{
if( sPath[ 0 ] == '.' && sPath[ 1 ] == slash )
......@@ -362,7 +381,7 @@ std::string Path_Compact( const std::string & sRawPath, char slash )
std::string::size_type i = 0;
while( i < sPath.length() )
{
if( i > 0 && sPath.length() - i >= 2
if( i > 0 && sPath.length() - i >= 2
&& sPath[i] == '.'
&& sPath[i+1] == '.'
&& ( i + 2 == sPath.length() || sPath[ i+2 ] == slash )
......@@ -371,7 +390,7 @@ std::string Path_Compact( const std::string & sRawPath, char slash )
// check if we've hit the start of the string and have a bogus path
if( i == 1 )
return "";
// find the separator before i-1
std::string::size_type iDirStart = i-2;
while( iDirStart > 0 && sPath[ iDirStart - 1 ] != slash )
......@@ -393,6 +412,20 @@ std::string Path_Compact( const std::string & sRawPath, char slash )
}
/** Returns true if these two paths are the same without respect for internal . or ..
* sequences, slash type, or case (on case-insensitive platforms). */
bool Path_IsSamePath( const std::string & sPath1, const std::string & sPath2 )
{
std::string sCompact1 = Path_Compact( sPath1 );
std::string sCompact2 = Path_Compact( sPath2 );
#if defined(WIN32)
return !stricmp( sCompact1.c_str(), sCompact2.c_str() );
#else
return !strcmp( sCompact1.c_str(), sCompact2.c_str() );
#endif
}
/** Returns the path to the current DLL or exe */
std::string Path_GetThisModulePath()
{
......@@ -463,10 +496,11 @@ bool Path_IsDirectory( const std::string & sPath )
bool Path_IsAppBundle( const std::string & sPath )
{
#if defined(OSX)
NSBundle *bundle = [ NSBundle bundleWithPath: [ NSString stringWithUTF8String:sPath.c_str() ] ];
bool bisAppBundle = ( nullptr != bundle );
[ bundle release ];
return bisAppBundle;
@autoreleasepool {
NSBundle *bundle = [ NSBundle bundleWithPath: [ NSString stringWithUTF8String:sPath.c_str() ] ];
bool bisAppBundle = ( nullptr != bundle );
return bisAppBundle;
}
#else
return false;
#endif
......@@ -567,7 +601,7 @@ unsigned char * Path_ReadBinaryFile( const std::string &strFilename, int *pSize
// the open operation needs to be sharable, therefore use of _wfsopen instead of _wfopen_s
f = _wfsopen( wstrFilename.c_str(), L"rb", _SH_DENYNO );
#endif
unsigned char* buf = NULL;
if ( f != NULL )
......@@ -654,7 +688,7 @@ bool Path_WriteBinaryFile(const std::string &strFilename, unsigned char *pData,
fclose(f);
}
return written = nSize ? true : false;
return written == nSize ? true : false;
}
std::string Path_ReadTextFile( const std::string &strFilename )
......@@ -683,6 +717,28 @@ std::string Path_ReadTextFile( const std::string &strFilename )
}
bool Path_MakeWritable( const std::string &strFilename )
{
#if defined ( _WIN32 )
std::wstring wstrFilename = UTF8to16( strFilename.c_str() );
DWORD dwAttrs = GetFileAttributesW( wstrFilename.c_str() );
if ( dwAttrs != INVALID_FILE_ATTRIBUTES && ( dwAttrs & FILE_ATTRIBUTE_READONLY ) )
{
return SetFileAttributesW( wstrFilename.c_str(), dwAttrs & ~FILE_ATTRIBUTE_READONLY );
}
#else
struct stat sb;
if ( stat( strFilename.c_str(), &sb ) == 0 && !( sb.st_mode & S_IWUSR ) )
{
return ( chmod( strFilename.c_str(), sb.st_mode | S_IWUSR ) == 0 );
}
#endif
return true;
}
bool Path_WriteStringToTextFile( const std::string &strFilename, const char *pchData )
{
FILE *f;
......@@ -696,7 +752,7 @@ bool Path_WriteStringToTextFile( const std::string &strFilename, const char *pch
f = NULL;
}
#endif
bool ok = false;
if ( f != NULL )
......@@ -747,9 +803,11 @@ bool Path_WriteStringToTextFileAtomic( const std::string &strFilename, const cha
// ----------------------------------------------------------------------------------------------------------------------------
std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath )
{
if ( !strnicmp( sRelativePath.c_str(), "http://", 7 )
|| !strnicmp( sRelativePath.c_str(), "https://", 8 )
|| !strnicmp( sRelativePath.c_str(), "file://", 7 ) )
if ( StringHasPrefix( sRelativePath, "http://" )
|| StringHasPrefix( sRelativePath, "https://" )
|| StringHasPrefix( sRelativePath, "vr-input-workshop://" )
|| StringHasPrefix( sRelativePath, "file://" )
)
{
return sRelativePath;
}
......@@ -758,7 +816,13 @@ std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::st
std::string sAbsolute = Path_MakeAbsolute( sRelativePath, sBasePath );
if ( sAbsolute.empty() )
return sAbsolute;
return std::string( FILE_URL_PREFIX ) + sAbsolute;
sAbsolute = Path_FixSlashes( sAbsolute, '/' );
size_t unBufferSize = sAbsolute.length() * 3;
char *pchBuffer = (char *)alloca( unBufferSize );
V_URLEncodeNoPlusForSpace( pchBuffer, (int)unBufferSize, sAbsolute.c_str(), (int)sAbsolute.length() );
return std::string( FILE_URL_PREFIX ) + pchBuffer;
}
}
......@@ -769,7 +833,11 @@ std::string Path_UrlToFilePath( const std::string & sFileUrl )
{
if ( !strnicmp( sFileUrl.c_str(), FILE_URL_PREFIX, strlen( FILE_URL_PREFIX ) ) )
{
return sFileUrl.c_str() + strlen( FILE_URL_PREFIX );
char *pchBuffer = (char *)alloca( sFileUrl.length() );
V_URLDecodeNoPlusForSpace( pchBuffer, (int)sFileUrl.length(),
sFileUrl.c_str() + strlen( FILE_URL_PREFIX ), (int)( sFileUrl.length() - strlen( FILE_URL_PREFIX ) ) );
return Path_FixSlashes( pchBuffer );
}
else
{
......@@ -802,7 +870,7 @@ std::string GetUserDocumentsPath()
{
return "";
}
return [[paths objectAtIndex:0] UTF8String];
}
#elif defined( LINUX )
......@@ -816,3 +884,16 @@ std::string GetUserDocumentsPath()
#endif
}
// -----------------------------------------------------------------------------------------------------
// Purpose: deletes / unlinks a single file
// -----------------------------------------------------------------------------------------------------
bool Path_UnlinkFile( const std::string &strFilename )
{
#if defined( WIN32 )
std::wstring wsFilename = UTF8to16( strFilename.c_str() );
return ( 0 != DeleteFileW( wsFilename.c_str() ) );
#else
return ( 0 == unlink( strFilename.c_str() ) );
#endif
}
......@@ -13,6 +13,9 @@ std::string Path_GetWorkingDirectory();
/** Sets the path of the current working directory. Returns true if this was successful. */
bool Path_SetWorkingDirectory( const std::string & sPath );
/** Gets the path to a temporary directory. */
std::string Path_GetTemporaryDirectory();
/** returns the path (including filename) of the current shared lib or DLL */
std::string Path_GetThisModulePath();
......@@ -35,7 +38,7 @@ std::string Path_GetExtension( const std::string & sPath );
bool Path_IsAbsolute( const std::string & sPath );
/** Makes an absolute path from a relative path and a base path */
std::string Path_MakeAbsolute( const std::string & sRelativePath, const std::string & sBasePath, char slash = 0 );
std::string Path_MakeAbsolute( const std::string & sRelativePath, const std::string & sBasePath );
/** Fixes the directory separators for the current platform.
* If slash is unspecified the native path separator of the current platform
......@@ -64,6 +67,10 @@ std::string Path_Join(
* will be used. */
std::string Path_Compact( const std::string & sRawPath, char slash = 0 );
/** Returns true if these two paths are the same without respect for internal . or ..
* sequences, slash type, or case (on case-insensitive platforms). */
bool Path_IsSamePath( const std::string & sPath1, const std::string & sPath2 );
//** Removed trailing slashes */
std::string Path_RemoveTrailingSlash( const std::string & sRawPath, char slash = 0 );
......@@ -80,6 +87,9 @@ bool Path_Exists( const std::string & sPath );
std::string Path_FindParentDirectoryRecursively( const std::string &strStartDirectory, const std::string &strDirectoryName );
std::string Path_FindParentSubDirectoryRecursively( const std::string &strStartDirectory, const std::string &strDirectoryName );
/** Make a text file writable. */
bool Path_MakeWritable( const std::string &strFilename );
/** Path operations to read or write text/binary files */
unsigned char * Path_ReadBinaryFile( const std::string &strFilename, int *pSize );
uint32_t Path_ReadBinaryFile( const std::string &strFilename, unsigned char *pBuffer, uint32_t unSize );
......@@ -97,6 +107,9 @@ std::string Path_UrlToFilePath( const std::string & sFileUrl );
/** Returns the root of the directory the system wants us to store user documents in */
std::string GetUserDocumentsPath();
/** deletes / unlinks a single file */
bool Path_UnlinkFile( const std::string &strFilename );
#ifndef MAX_UNICODE_PATH
#define MAX_UNICODE_PATH 32767
#endif
......@@ -108,6 +121,7 @@ std::string GetUserDocumentsPath();
//-----------------------------------------------------------------------------
#if defined(WIN32)
#define DYNAMIC_LIB_EXT ".dll"
#define PROGRAM_EXT ".exe"
#ifdef _WIN64
#define PLATSUBDIR "win64"
#else
......@@ -116,10 +130,16 @@ std::string GetUserDocumentsPath();
#elif defined(OSX)
#define DYNAMIC_LIB_EXT ".dylib"
#define PLATSUBDIR "osx32"
#define PROGRAM_EXT ""
#elif defined(LINUX)
#define DYNAMIC_LIB_EXT ".so"
#define PROGRAM_EXT ""
#if defined( LINUX32 )
#define PLATSUBDIR "linux32"
#elif defined( ANDROIDARM64 )
#define PLATSUBDIR "androidarm64"
#elif defined( LINUXARM64 )
#define PLATSUBDIR "linuxarm64"
#else
#define PLATSUBDIR "linux64"
#endif
......
......@@ -3,7 +3,7 @@
#include <string.h>
#if defined(_WIN32)
#include <Windows.h>
#include <windows.h>
#endif
#if defined(POSIX)
......@@ -31,6 +31,8 @@ void *SharedLib_GetFunction( SharedLibHandle lib, const char *pchFunctionName)
void SharedLib_Unload( SharedLibHandle lib )
{
if ( !lib )
return;
#if defined( _WIN32)
FreeLibrary( (HMODULE)lib );
#elif defined(POSIX)
......
......@@ -3,6 +3,8 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <iostream>
//-----------------------------------------------------------------------------
// Purpose:
......@@ -142,8 +144,8 @@ std::wstring UTF8to16(const char * in)
void strcpy_safe( char *pchBuffer, size_t unBufferSizeBytes, const char *pchSource )
{
pchBuffer[ unBufferSizeBytes - 1 ] = '\0';
strncpy( pchBuffer, pchSource, unBufferSizeBytes - 1 );
pchBuffer[unBufferSizeBytes - 1] = '\0';
}
......@@ -197,12 +199,6 @@ uint32_t ReturnStdString( const std::string & sValue, char *pchBuffer, uint32_t
return unLen;
}
void BufferToStdString( std::string & sDest, const char *pchBuffer, uint32_t unBufferLen )
{
sDest.resize( unBufferLen + 1 );
memcpy( const_cast< char* >( sDest.c_str() ), pchBuffer, unBufferLen );
const_cast< char* >( sDest.c_str() )[ unBufferLen ] = '\0';
}
/** Returns a std::string from a uint64_t */
std::string Uint64ToString( uint64_t ulValue )
......@@ -405,6 +401,12 @@ void V_URLEncode( char *pchDest, int nDestLen, const char *pchSource, int nSourc
}
void V_URLEncodeNoPlusForSpace( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen )
{
return V_URLEncodeInternal( pchDest, nDestLen, pchSource, nSourceLen, false );
}
//-----------------------------------------------------------------------------
// Purpose: Decodes a string (or binary data) from URL encoding format, see rfc1738 section 2.2.
// This version of the call isn't a strict RFC implementation, but uses + for space as is
......@@ -418,6 +420,11 @@ size_t V_URLDecode( char *pchDecodeDest, int nDecodeDestLen, const char *pchEnco
return V_URLDecodeInternal( pchDecodeDest, nDecodeDestLen, pchEncodedSource, nEncodedSourceLen, true );
}
size_t V_URLDecodeNoPlusForSpace( char *pchDecodeDest, int nDecodeDestLen, const char *pchEncodedSource, int nEncodedSourceLen )
{
return V_URLDecodeInternal( pchDecodeDest, nDecodeDestLen, pchEncodedSource, nEncodedSourceLen, false );
}
//-----------------------------------------------------------------------------
void V_StripExtension( std::string &in )
{
......@@ -435,3 +442,19 @@ void V_StripExtension( std::string &in )
}
}
//-----------------------------------------------------------------------------
// Purpose: Tokenizes a string into a vector of strings
//-----------------------------------------------------------------------------
std::vector<std::string> TokenizeString( const std::string & sString, char cToken )
{
std::vector<std::string> vecStrings;
std::istringstream stream( sString );
std::string s;
while ( std::getline( stream, s, cToken ) )
{
vecStrings.push_back( s );
}
return vecStrings;
}
......@@ -4,6 +4,7 @@
#include <string>
#include <stdint.h>
#include <sys/types.h>
#include <vector>
/** returns true if the string has the prefix */
bool StringHasPrefix( const std::string & sString, const std::string & sPrefix );
......@@ -39,11 +40,17 @@ std::string StringToLower( const std::string & sString );
#if defined( OSX ) || defined( LINUX )
#include <strings.h>
inline int stricmp(const char *pStr1, const char *pStr2) { return strcasecmp(pStr1,pStr2); }
#ifndef _stricmp
#define _stricmp stricmp
#endif
inline int strnicmp( const char *pStr1, const char *pStr2, size_t unBufferLen ) { return strncasecmp( pStr1,pStr2, unBufferLen ); }
#ifndef _strnicmp
#define _strnicmp strnicmp
#endif
#ifndef _vsnprintf_s
#define _vsnprintf_s vsnprintf
#endif
#define _TRUNCATE ((size_t)-1)
......@@ -90,9 +97,6 @@ inline uint64_t strtoull(const char *str, char **endptr, int base) { return _str
/* Handles copying a std::string into a buffer as would be provided in an API */
uint32_t ReturnStdString( const std::string & sValue, char *pchBuffer, uint32_t unBufferLen );
/* Handles copying a buffer into an std::string and auto adds null terminator */
void BufferToStdString( std::string & sDest, const char *pchBuffer, uint32_t unBufferLen );
/** Returns a std::string from a uint64_t */
std::string Uint64ToString( uint64_t ulValue );
......@@ -108,6 +112,9 @@ uint64_t StringToUint64( const std::string & sValue );
//-----------------------------------------------------------------------------
void V_URLEncode( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen );
/** Same as V_URLEncode, but without plus for space. */
void V_URLEncodeNoPlusForSpace( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen );
//-----------------------------------------------------------------------------
// Purpose: Decodes a string (or binary data) from URL encoding format, see rfc1738 section 2.2.
// This version of the call isn't a strict RFC implementation, but uses + for space as is
......@@ -118,9 +125,14 @@ void V_URLEncode( char *pchDest, int nDestLen, const char *pchSource, int nSourc
//-----------------------------------------------------------------------------
size_t V_URLDecode( char *pchDecodeDest, int nDecodeDestLen, const char *pchEncodedSource, int nEncodedSourceLen );
/** Same as V_URLDecode, but without plus for space. */
size_t V_URLDecodeNoPlusForSpace( char *pchDecodeDest, int nDecodeDestLen, const char *pchEncodedSource, int nEncodedSourceLen );
//-----------------------------------------------------------------------------
// Purpose: strip extension from a path
//-----------------------------------------------------------------------------
void V_StripExtension( std::string &in );
/** Tokenizes a string into a vector of strings */
std::vector<std::string> TokenizeString( const std::string & sString, char cToken );
......@@ -9,7 +9,7 @@
#if defined( WIN32 )
#include <windows.h>
#include <Shlobj.h>
#include <shlobj.h>
#undef GetEnvironmentVariable
#elif defined OSX
......@@ -23,7 +23,7 @@
#include <algorithm>
#ifndef VRLog
#undef VRLog
#undef VRLog
#endif
#define VRLog(...)
......@@ -52,21 +52,21 @@ static std::string GetAppSettingsPath()
{
return "";
}
NSString *resolvedPath = [paths objectAtIndex:0];
resolvedPath = [resolvedPath stringByAppendingPathComponent: @"OpenVR"];
if ( ![[NSFileManager new] createDirectoryAtPath: resolvedPath withIntermediateDirectories:YES attributes:nil error:nil] )
if ( ![[NSFileManager defaultManager] createDirectoryAtPath: resolvedPath withIntermediateDirectories:YES attributes:nil error:nil] )
{
return "";
}
sSettingsDir.assign( [resolvedPath UTF8String] );
}
return sSettingsDir;
#elif defined( LINUX )
// As defined by XDG Base Directory Specification
// As defined by XDG Base Directory Specification
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
const char *pchHome = getenv("XDG_CONFIG_HOME");
......@@ -77,7 +77,7 @@ static std::string GetAppSettingsPath()
//
// XDG_CONFIG_HOME is not defined, use ~/.config instead
//
//
pchHome = getenv( "HOME" );
if ( pchHome == NULL )
{
......@@ -112,7 +112,7 @@ std::string CVRPathRegistry_Public::GetOpenVRConfigPath()
#if defined( _WIN32 ) || defined( LINUX )
sConfigPath = Path_Join( sConfigPath, "openvr" );
#elif defined ( OSX )
#elif defined ( OSX )
sConfigPath = Path_Join( sConfigPath, ".openvr" );
#else
#warning "Unsupported platform"
......@@ -128,13 +128,17 @@ std::string CVRPathRegistry_Public::GetOpenVRConfigPath()
//-----------------------------------------------------------------------------
std::string CVRPathRegistry_Public::GetVRPathRegistryFilename()
{
std::string sOverridePath = GetEnvironmentVariable( "VR_PATHREG_OVERRIDE" );
if ( !sOverridePath.empty() )
return sOverridePath;
std::string sPath = GetOpenVRConfigPath();
if ( sPath.empty() )
return "";
#if defined( _WIN32 )
sPath = Path_Join( sPath, "openvrpaths.vrpath" );
#elif defined ( POSIX )
#elif defined ( POSIX )
sPath = Path_Join( sPath, "openvrpaths.vrpath" );
#else
#error "Unsupported platform"
......@@ -190,7 +194,7 @@ bool CVRPathRegistry_Public::ToJsonString( std::string &sJsonString )
std::string sRegPath = GetVRPathRegistryFilename();
if( sRegPath.empty() )
return false;
std::string sRegistryContents = Path_ReadTextFile( sRegPath );
if( sRegistryContents.empty() )
return false;
......@@ -223,19 +227,30 @@ bool CVRPathRegistry_Public::BLoadFromFile()
Json::Value root;
Json::Reader reader;
if( !reader.parse( sRegistryContents, root ) )
{
VRLog( "Unable to parse %s: %s\n", sRegPath.c_str(), reader.getFormattedErrorMessages().c_str() );
return false;
}
#if JSON_USE_EXCEPTION
try {
#endif // JSON_USE_EXCEPTION
if ( !reader.parse( sRegistryContents, root ) )
{
VRLog( "Unable to parse %s: %s\n", sRegPath.c_str(), reader.getFormattedErrorMessages().c_str() );
return false;
}
ParseStringListFromJson( &m_vecRuntimePath, root, "runtime" );
ParseStringListFromJson( &m_vecConfigPath, root, "config" );
ParseStringListFromJson( &m_vecLogPath, root, "log" );
if (root.isMember( "external_drivers" ) && root[ "external_drivers" ].isArray() )
ParseStringListFromJson( &m_vecRuntimePath, root, "runtime" );
ParseStringListFromJson( &m_vecConfigPath, root, "config" );
ParseStringListFromJson( &m_vecLogPath, root, "log" );
if ( root.isMember( "external_drivers" ) && root["external_drivers"].isArray() )
{
ParseStringListFromJson( &m_vecExternalDrivers, root, "external_drivers" );
}
#if JSON_USE_EXCEPTION
}
catch ( ... )
{
ParseStringListFromJson( &m_vecExternalDrivers, root, "external_drivers" );
VRLog( "Unable to parse %s: %s\n", sRegPath.c_str(), "exception thrown in JSON library" );
return false;
}
#endif // JSON_USE_EXCEPTION
return true;
}
......@@ -252,9 +267,9 @@ bool CVRPathRegistry_Public::BSaveToFile() const
std::string sRegPath = GetVRPathRegistryFilename();
if( sRegPath.empty() )
return false;
Json::Value root;
root[ "version" ] = 1;
root[ "jsonid" ] = "vrpathreg";
......@@ -323,7 +338,7 @@ std::string CVRPathRegistry_Public::GetLogPath() const
// ---------------------------------------------------------------------------
// Purpose: Returns paths using the path registry and the provided override
// Purpose: Returns paths using the path registry and the provided override
// values. Pass NULL for any paths you don't care about.
// ---------------------------------------------------------------------------
bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *psConfigPath, std::string *psLogPath, const char *pchConfigPathOverride, const char *pchLogPathOverride, std::vector<std::string> *pvecExternalDrivers )
......@@ -398,7 +413,7 @@ bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *
if ( nCountEnvironmentVariables == 3 )
{
// all three environment variables where set, so we don't need the physical file
// all three environment variables were set, so we don't need the physical file
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment