Bug 1637410 - Update OpenVR to 1.11.11 r=kip,daoshengmu

This change updates mozilla-central's copy of the files for the OpenVR lib built into xul.dll from
  https://github.com/ValveSoftware/openvr
from version 1.0.17 to 1.11.11.

Differential Revision: https://phabricator.services.mozilla.com/D74965
This commit is contained in:
thomasmo 2020-05-27 21:16:57 +00:00
Родитель 21053c0624
Коммит 76400f97fe
13 изменённых файлов: 1948 добавлений и 591 удалений

Просмотреть файл

@ -1066,7 +1066,7 @@ void OpenVRSession::UpdateControllerPoses(VRSystemState& aState) {
}
VRControllerState& controllerState = aState.controllerState[stateIndex];
vr::InputPoseActionData_t poseData;
if (vr::VRInput()->GetPoseActionData(
if (vr::VRInput()->GetPoseActionDataRelativeToNow(
mControllerHand[role].mActionPose.handle,
vr::TrackingUniverseSeated, 0, &poseData, sizeof(poseData),
vr::k_ulInvalidInputValueHandle) != vr::VRInputError_None ||
@ -1256,7 +1256,6 @@ void OpenVRSession::ProcessEvents(mozilla::gfx::VRSystemState& aSystemState) {
// process to shutdown the VR process, and we need to avoid it.
// case ::vr::EVREventType::VREvent_ProcessQuit:
case ::vr::EVREventType::VREvent_QuitAcknowledged:
case ::vr::EVREventType::VREvent_QuitAborted_UserPrompt:
mShouldQuit = true;
break;
default:

Просмотреть файл

@ -1,4 +1,4 @@
This directory contains files from the OpenVR SDK, version 1.0.17.
This directory contains files from the OpenVR SDK, version 1.11.11.
This SDK contains the OpenVR API interface headers and functions to load the
OpenVR runtime libraries which actually implement the functionality. The
@ -53,6 +53,26 @@ Steps to update the library:
- Add explicit in CVRSettingHelper constructor.
- In strtools_public.cpp/.h, ensure that UTF16to8 and UTF8to16 are only
compiled under
#if defined( _WIN32 )
and redefine those functions to use ::WideCharToMultiByte and
MultiByteToWideChar, respectively. These are modified because the original
implementations contain unsupported try-catch.
- In strtools_public.cpp, remove the definition of convert_type.
- In strtools_public.cpp, remove the include of <codecvt>, as this causes
problems in compiling on Linux.
- In pathtools_public.cpp/.h, comment out Path_UrlToFilePath and
Path_FilePathToUrl to avoid a compile error because 'alloca' isn't defined.
- In vrpathregistry_public.cpp, CVRPathRegistry_Public::BLoadFromFile contains
a try-catch, which is not permitted. This code is simply commented out, but
Bug 1640068 - OpenVR code can fail JSON parsing and raise exceptions
is filed to address a safe fallback in the error condition.
- Update this README.mozilla file with the new OpenVR SDK version and any
additional steps needed for newer versions.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,6 +1,9 @@
//========= Copyright Valve Corporation ============//
#include "envvartools_public.h"
#include "strtools_public.h"
#include <stdlib.h>
#include <string>
#include <cctype>
#if defined(_WIN32)
#include <windows.h>
@ -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 );

Просмотреть файл

@ -70,6 +70,7 @@ const char *GetEnglishStringForHmdError( vr::EVRInitError eError )
// case VRInitError_Driver_HmdDisplayNotFoundAfterFix: return "HMD detected over USB, but Monitor not found after attempt to fix (210)"; // taken out upon Ben's request: He thinks that there is no need to separate that error from 208
case VRInitError_Driver_HmdDriverIdOutOfBounds: return "Hmd DriverId is our of bounds (211)";
case VRInitError_Driver_HmdDisplayMirrored: return "HMD detected over USB, but Monitor may be mirrored instead of extended (212)";
case VRInitError_Driver_HmdDisplayNotFoundLaptop: return "On laptop, HMD detected over USB, but Monitor not found (213)";
case VRInitError_IPC_ServerInitFailed: return "VR Server Init Failed (300)";
case VRInitError_IPC_ConnectFailed: return "Connect to VR Server Failed (301)";
@ -80,6 +81,8 @@ const char *GetEnglishStringForHmdError( vr::EVRInitError eError )
case VRInitError_IPC_CompositorConnectFailed: return "Shared IPC Compositor Connect Failed (306)";
case VRInitError_IPC_CompositorInvalidConnectResponse: return "Shared IPC Compositor Invalid Connect Response (307)";
case VRInitError_IPC_ConnectFailedAfterMultipleAttempts: return "Shared IPC Connect Failed After Multiple Attempts (308)";
case VRInitError_IPC_ConnectFailedAfterTargetExited: return "Shared IPC Connect Failed After Target Exited (309)";
case VRInitError_IPC_NamespaceUnavailable: return "Shared IPC Namespace Unavailable (310)";
case VRInitError_Compositor_Failed: return "Compositor failed to initialize (400)";
case VRInitError_Compositor_D3D11HardwareRequired: return "Compositor failed to find DX11 hardware (401)";
@ -90,6 +93,7 @@ const char *GetEnglishStringForHmdError( vr::EVRInitError eError )
// Oculus
case VRInitError_VendorSpecific_UnableToConnectToOculusRuntime: return "Unable to connect to Oculus Runtime (1000)";
case VRInitError_VendorSpecific_OculusRuntimeBadInstall: return "Unable to connect to Oculus Runtime, possible bad install (1114)";
// Lighthouse
case VRInitError_VendorSpecific_HmdFound_CantOpenDevice: return "HMD found, but can not open device (1101)";
@ -165,7 +169,11 @@ const char *GetIDForVRInitError( vr::EVRInitError eError )
RETURN_ENUM_AS_STRING( VRInitError_Init_USBServiceBusy );
RETURN_ENUM_AS_STRING( VRInitError_Init_VRWebHelperStartupFailed );
RETURN_ENUM_AS_STRING( VRInitError_Init_TrackerManagerInitFailed );
RETURN_ENUM_AS_STRING( VRInitError_Init_AlreadyRunning );
RETURN_ENUM_AS_STRING( VRInitError_Init_FailedForVrMonitor);
RETURN_ENUM_AS_STRING( VRInitError_Init_PropertyManagerInitFailed );
RETURN_ENUM_AS_STRING( VRInitError_Init_WebServerFailed );
RETURN_ENUM_AS_STRING( VRInitError_Driver_Failed );
RETURN_ENUM_AS_STRING( VRInitError_Driver_Unknown );
RETURN_ENUM_AS_STRING( VRInitError_Driver_HmdUnknown);
@ -179,6 +187,7 @@ const char *GetIDForVRInitError( vr::EVRInitError eError )
// RETURN_ENUM_AS_STRING( VRInitError_Driver_HmdDisplayNotFoundAfterFix );
RETURN_ENUM_AS_STRING( VRInitError_Driver_HmdDriverIdOutOfBounds );
RETURN_ENUM_AS_STRING( VRInitError_Driver_HmdDisplayMirrored );
RETURN_ENUM_AS_STRING( VRInitError_Driver_HmdDisplayNotFoundLaptop );
RETURN_ENUM_AS_STRING( VRInitError_IPC_ServerInitFailed);
RETURN_ENUM_AS_STRING( VRInitError_IPC_ConnectFailed);
@ -188,7 +197,9 @@ const char *GetIDForVRInitError( vr::EVRInitError eError )
RETURN_ENUM_AS_STRING( VRInitError_IPC_Failed);
RETURN_ENUM_AS_STRING( VRInitError_IPC_CompositorConnectFailed);
RETURN_ENUM_AS_STRING( VRInitError_IPC_CompositorInvalidConnectResponse);
RETURN_ENUM_AS_STRING( VRInitError_IPC_ConnectFailedAfterMultipleAttempts);
RETURN_ENUM_AS_STRING( VRInitError_IPC_ConnectFailedAfterMultipleAttempts );
RETURN_ENUM_AS_STRING( VRInitError_IPC_ConnectFailedAfterTargetExited );
RETURN_ENUM_AS_STRING( VRInitError_IPC_NamespaceUnavailable );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_Failed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_D3D11HardwareRequired );
@ -196,10 +207,96 @@ const char *GetIDForVRInitError( vr::EVRInitError eError )
RETURN_ENUM_AS_STRING( VRInitError_Compositor_OverlayInitFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_ScreenshotsInitFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_UnableToCreateDevice );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_SharedStateIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_NotificationManagerIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_ResourceManagerClientIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_MessageOverlaySharedStateInitFailure );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_PropertiesInterfaceIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateFullscreenWindowFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_SettingsInterfaceIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToShowWindow );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DistortInterfaceIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DisplayFrequencyFailure );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_RendererInitializationFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DXGIFactoryInterfaceIsNull );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DXGIFactoryCreateFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DXGIFactoryQueryFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_InvalidAdapterDesktop );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_InvalidHmdAttachment );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_InvalidOutputDesktop );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_InvalidDeviceProvided );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_D3D11RendererInitializationFailed );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToFindDisplayMode );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateSwapChain );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToGetBackBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateRenderTarget );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateDXGI2SwapChain );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedtoGetDXGI2BackBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateDXGI2RenderTarget );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToGetDXGIDeviceInterface );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_SelectDisplayMode );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateNvAPIRenderTargets );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_NvAPISetDisplayMode );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateDirectModeDisplay );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_InvalidHmdPropertyContainer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_UpdateDisplayFrequency );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateRasterizerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateWireframeRasterizerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateSamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateClampToBorderSamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateAnisoSamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlaySamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreatePanoramaSamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateFontSamplerState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateNoBlendState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateBlendState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateAlphaBlendState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateBlendStateMaskR );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateBlendStateMaskG );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateBlendStateMaskB );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateDepthStencilState );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateDepthStencilStateNoWrite );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateDepthStencilStateNoDepth );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateFlushTexture );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateDistortionSurfaces );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateHmdPoseConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateHmdPoseStagingConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateSharedFrameInfoConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlayConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateSceneTextureIndexConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateReadableSceneTextureIndexConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateLayerGraphicsTextureIndexConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateLayerComputeTextureIndexConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateLayerComputeSceneTextureIndexConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateComputeHmdPoseConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateGeomConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreatePanelMaskConstantBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreatePixelSimUBO );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateMSAARenderTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateResolveRenderTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateComputeResolveRenderTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateDriverDirectModeResolveTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_OpenDriverDirectModeResolveTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateFallbackSyncTexture );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_ShareFallbackSyncTexture );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlayIndexBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlayVertexBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateTextVertexBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateTextIndexBuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateMirrorTextures );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateLastFrameRenderTexture );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateMirrorOverlay );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateVirtualDisplayBackbuffer );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_DisplayModeNotSupported );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlayInvalidCall );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_CreateOverlayAlreadyInitialized );
RETURN_ENUM_AS_STRING( VRInitError_Compositor_FailedToCreateMailbox );
// Vendor-specific errors
RETURN_ENUM_AS_STRING( VRInitError_VendorSpecific_UnableToConnectToOculusRuntime);
RETURN_ENUM_AS_STRING( VRInitError_VendorSpecific_WindowsNotInDevMode );
RETURN_ENUM_AS_STRING( VRInitError_VendorSpecific_OculusRuntimeBadInstall );
// Lighthouse
RETURN_ENUM_AS_STRING( VRInitError_VendorSpecific_HmdFound_CantOpenDevice);

Просмотреть файл

@ -6,6 +6,7 @@
#include "sharedlibtools_public.h"
#include "envvartools_public.h"
#include "hmderrors_public.h"
#include "strtools_public.h"
#include "vrpathregistry_public.h"
#include <mutex>
@ -14,6 +15,23 @@ 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
{
@ -108,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" );
@ -238,27 +256,63 @@ 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()
{
// otherwise we need to do a bit more work
static std::string sRuntimePath;
std::string sConfigPath, sLogPath;
bool bReadPathRegistry = CVRPathRegistry_Public::GetPaths( &sRuntimePath, &sConfigPath, &sLogPath, NULL, NULL );
if ( !bReadPathRegistry )
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
std::string sRuntimePath;
*punRequiredBufferSize = 0;
bool bReadPathRegistry = CVRPathRegistry_Public::GetPaths( &sRuntimePath, nullptr, nullptr, nullptr, nullptr );
if ( !bReadPathRegistry )
{
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;
}
return sRuntimePath.c_str();
*punRequiredBufferSize = (uint32_t)sRuntimePath.size() + 1;
if ( sRuntimePath.size() >= unBufferSize )
{
*pchPathBuffer = '\0';
}
else
{
strcpy_safe( pchPathBuffer, unBufferSize, sRuntimePath.c_str() );
}
return true;
}

Просмотреть файл

@ -16,7 +16,9 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <alloca.h>
#endif
#if defined OSX
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
@ -97,6 +99,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 )
{
@ -191,7 +211,7 @@ bool Path_IsAbsolute( const std::string & sPath )
std::string Path_MakeAbsolute( const std::string & sRelativePath, const std::string & sBasePath )
{
if( Path_IsAbsolute( sRelativePath ) )
return sRelativePath;
return Path_Compact( sRelativePath );
else
{
if( !Path_IsAbsolute( sBasePath ) )
@ -341,8 +361,9 @@ std::string Path_Compact( const std::string & sRawPath, char slash )
std::string::size_type len = sPath.length();
if( sPath[ len-1 ] == '.' && sPath[ len-2 ] == slash )
{
// sPath.pop_back();
sPath[len-1] = 0; // for now, at least
sPath.pop_back();
//Not sure why the following line of code was used for a while. It causes problems with strlen.
//sPath[len-1] = 0; // for now, at least
}
}
@ -391,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()
{
@ -682,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;
@ -741,45 +798,54 @@ bool Path_WriteStringToTextFileAtomic( const std::string &strFilename, const cha
#define FILE_URL_PREFIX "file://"
#endif
// Mozilla: see README.mozilla for more details
// ----------------------------------------------------------------------------------------------------------------------------
// Purpose: Turns a path to a file on disk into a URL (or just returns the value if it's already a URL)
// ----------------------------------------------------------------------------------------------------------------------------
std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath )
{
if ( StringHasPrefix( sRelativePath, "http://" )
|| StringHasPrefix( sRelativePath, "https://" )
|| StringHasPrefix( sRelativePath, "vr-input-workshop://" )
|| StringHasPrefix( sRelativePath, "file://" )
)
{
return sRelativePath;
}
else
{
std::string sAbsolute = Path_MakeAbsolute( sRelativePath, sBasePath );
if ( sAbsolute.empty() )
return sAbsolute;
sAbsolute = Path_FixSlashes( sAbsolute, '/' );
return std::string( FILE_URL_PREFIX ) + sAbsolute;
}
}
// std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath )
// {
// if ( StringHasPrefix( sRelativePath, "http://" )
// || StringHasPrefix( sRelativePath, "https://" )
// || StringHasPrefix( sRelativePath, "vr-input-workshop://" )
// || StringHasPrefix( sRelativePath, "file://" )
// )
// {
// return sRelativePath;
// }
// else
// {
// std::string sAbsolute = Path_MakeAbsolute( sRelativePath, sBasePath );
// if ( sAbsolute.empty() )
// return sAbsolute;
// sAbsolute = Path_FixSlashes( sAbsolute, '/' );
// size_t unBufferSize = sAbsolute.length() * 3;
// char *pchBuffer = (char *)alloca( unBufferSize );
// V_URLEncodeFullPath( pchBuffer, (int)unBufferSize, sAbsolute.c_str(), (int)sAbsolute.length() );
// return std::string( FILE_URL_PREFIX ) + pchBuffer;
// }
// }
// Mozilla: see README.mozilla for more details
// -----------------------------------------------------------------------------------------------------
// Purpose: Strips off file:// off a URL and returns the path. For other kinds of URLs an empty string is returned
// -----------------------------------------------------------------------------------------------------
std::string Path_UrlToFilePath( const std::string & sFileUrl )
{
if ( !strnicmp( sFileUrl.c_str(), FILE_URL_PREFIX, strlen( FILE_URL_PREFIX ) ) )
{
std::string sRet = sFileUrl.c_str() + strlen( FILE_URL_PREFIX );
sRet = Path_FixSlashes( sRet );
return sRet;
}
else
{
return "";
}
}
// std::string Path_UrlToFilePath( const std::string & sFileUrl )
// {
// if ( !strnicmp( sFileUrl.c_str(), FILE_URL_PREFIX, 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
// {
// return "";
// }
// }
// -----------------------------------------------------------------------------------------------------
@ -820,3 +886,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();
@ -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 );
@ -88,8 +98,9 @@ std::string Path_ReadTextFile( const std::string &strFilename );
bool Path_WriteStringToTextFile( const std::string &strFilename, const char *pchData );
bool Path_WriteStringToTextFileAtomic( const std::string &strFilename, const char *pchData );
// Mozilla: see README.mozilla for more details
/** Returns a file:// url for paths, or an http or https url if that's what was provided */
std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath );
// std::string Path_FilePathToUrl( const std::string & sRelativePath, const std::string & sBasePath );
/** Strips off file:// off a URL and returns the path. For other kinds of URLs an empty string is returned */
std::string Path_UrlToFilePath( const std::string & sFileUrl );
@ -97,6 +108,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
@ -123,6 +137,10 @@ std::string GetUserDocumentsPath();
#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

Просмотреть файл

@ -4,7 +4,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
// Mozilla: see README.mozilla for more details
// #include <codecvt>
#include <iostream>
#include <functional>
#include <locale>
// #include <codecvt>
#if defined( _WIN32 )
#include <windows.h>
#endif
//-----------------------------------------------------------------------------
// Purpose:
@ -49,106 +58,104 @@ bool StringHasSuffixCaseSensitive( const std::string &sString, const std::string
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
// Mozilla: see README.mozilla for more details
//typedef std::codecvt_utf8< wchar_t > convert_type;
// Mozilla: see README.mozilla for more details
#if defined( _WIN32 )
std::string UTF16to8(const wchar_t * in)
{
std::string out;
unsigned int codepoint = 0;
for ( ; in && *in != 0; ++in )
int retLength = ::WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr);
if (retLength == 0)
{
if (*in >= 0xd800 && *in <= 0xdbff)
codepoint = ((*in - 0xd800) << 10) + 0x10000;
else
{
if (*in >= 0xdc00 && *in <= 0xdfff)
codepoint |= *in - 0xdc00;
else
codepoint = *in;
if (codepoint <= 0x7f)
out.append(1, static_cast<char>(codepoint));
else if (codepoint <= 0x7ff)
{
out.append(1, static_cast<char>(0xc0 | ((codepoint >> 6) & 0x1f)));
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
}
else if (codepoint <= 0xffff)
{
out.append(1, static_cast<char>(0xe0 | ((codepoint >> 12) & 0x0f)));
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
}
else
{
out.append(1, static_cast<char>(0xf0 | ((codepoint >> 18) & 0x07)));
out.append(1, static_cast<char>(0x80 | ((codepoint >> 12) & 0x3f)));
out.append(1, static_cast<char>(0x80 | ((codepoint >> 6) & 0x3f)));
out.append(1, static_cast<char>(0x80 | (codepoint & 0x3f)));
}
codepoint = 0;
}
return std::string();
}
return out;
char* retString = new char[retLength];
::WideCharToMultiByte(CP_UTF8, 0, in, -1, retString, retLength, nullptr, nullptr);
std::string retStringValue(retString);
delete[] retString;
return retStringValue;
// static std::wstring_convert< convert_type, wchar_t > s_converter; // construction of this can be expensive (or even serialized) depending on locale
// try
// {
// return s_converter.to_bytes( in );
// }
// catch ( ... )
// {
// return std::string();
// }
}
std::string UTF16to8( const std::wstring & in ) { return UTF16to8( in.c_str() ); }
// Mozilla: see README.mozilla for more details
std::wstring UTF8to16(const char * in)
{
std::wstring out;
unsigned int codepoint = 0;
int following = 0;
for ( ; in && *in != 0; ++in )
int retLength = ::MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0);
if (retLength == 0)
{
unsigned char ch = *in;
if (ch <= 0x7f)
{
codepoint = ch;
following = 0;
}
else if (ch <= 0xbf)
{
if (following > 0)
{
codepoint = (codepoint << 6) | (ch & 0x3f);
--following;
}
}
else if (ch <= 0xdf)
{
codepoint = ch & 0x1f;
following = 1;
}
else if (ch <= 0xef)
{
codepoint = ch & 0x0f;
following = 2;
}
else
{
codepoint = ch & 0x07;
following = 3;
}
if (following == 0)
{
if (codepoint > 0xffff)
{
out.append(1, static_cast<wchar_t>(0xd800 + (codepoint >> 10)));
out.append(1, static_cast<wchar_t>(0xdc00 + (codepoint & 0x03ff)));
}
else
out.append(1, static_cast<wchar_t>(codepoint));
codepoint = 0;
}
return std::wstring();
}
return out;
wchar_t* retString = new wchar_t[retLength];
::MultiByteToWideChar(CP_UTF8, 0, in, -1, retString, retLength);
std::wstring retStringValue(retString);
delete[] retString;
return retStringValue;
//static std::wstring_convert< convert_type, wchar_t > s_converter; // construction of this can be expensive (or even serialized) depending on locale
//try
//{
// return s_converter.from_bytes( in );
//}
//catch ( ... )
//{
// return std::wstring();
//}
}
std::wstring UTF8to16( const std::string & in ) { return UTF8to16( in.c_str() ); }
#endif
#if defined( _WIN32 )
//-----------------------------------------------------------------------------
// Purpose: Convert LPSTR in the default CodePage to UTF8
//-----------------------------------------------------------------------------
std::string DefaultACPtoUTF8( const char *pszStr )
{
if ( GetACP() == CP_UTF8 )
{
return pszStr;
}
else
{
std::vector<wchar_t> vecBuf( strlen( pszStr ) + 1 ); // should be guaranteed to be enough
MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszStr, -1, vecBuf.data(), (int) vecBuf.size() );
return UTF16to8( vecBuf.data() );
}
}
#endif
// --------------------------------------------------------------------
// Purpose:
// --------------------------------------------------------------------
void strcpy_safe( char *pchBuffer, size_t unBufferSizeBytes, const char *pchSource )
{
strncpy( pchBuffer, pchSource, unBufferSizeBytes - 1 );
pchBuffer[unBufferSizeBytes - 1] = '\0';
}
// --------------------------------------------------------------------
// Purpose: converts a string to upper case
// --------------------------------------------------------------------
@ -201,6 +208,7 @@ uint32_t ReturnStdString( const std::string & sValue, char *pchBuffer, uint32_t
/** Returns a std::string from a uint64_t */
// Mozilla: see README.mozilla for more details
// std::string Uint64ToString( uint64_t ulValue )
// {
// char buf[ 22 ];
@ -245,11 +253,30 @@ int iHexCharToInt( char cValue )
return -1;
}
//-----------------------------------------------------------------------------
// Purpose: These define the set of characters to filter for components (which
// need all the escaping we can muster) vs. paths (which don't want
// / and : escaped so we don't break less compliant URL handling code.
//-----------------------------------------------------------------------------
static bool CharNeedsEscape_Component( const char c )
{
return (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9')
&& c != '-' && c != '_' && c != '.');
}
static bool CharNeedsEscape_FullPath( const char c )
{
return (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9')
&& c != '-' && c != '_' && c != '.' && c != '/' && c != ':' );
}
//-----------------------------------------------------------------------------
// Purpose: Internal implementation of encode, works in the strict RFC manner, or
// with spaces turned to + like HTML form encoding.
//-----------------------------------------------------------------------------
void V_URLEncodeInternal( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen, bool bUsePlusForSpace )
void V_URLEncodeInternal( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen,
bool bUsePlusForSpace, std::function< bool(const char)> fnNeedsEscape )
{
//AssertMsg( nDestLen > 3*nSourceLen, "Target buffer for V_URLEncode should be 3x source length, plus one for terminating null\n" );
@ -267,9 +294,7 @@ void V_URLEncodeInternal( char *pchDest, int nDestLen, const char *pchSource, in
// We allow only a-z, A-Z, 0-9, period, underscore, and hyphen to pass through unescaped.
// These are the characters allowed by both the original RFC 1738 and the latest RFC 3986.
// Current specs also allow '~', but that is forbidden under original RFC 1738.
if ( !( pchSource[i] >= 'a' && pchSource[i] <= 'z' ) && !( pchSource[i] >= 'A' && pchSource[i] <= 'Z' ) && !(pchSource[i] >= '0' && pchSource[i] <= '9' )
&& pchSource[i] != '-' && pchSource[i] != '_' && pchSource[i] != '.'
)
if ( fnNeedsEscape( pchSource[i] ) )
{
if ( bUsePlusForSpace && pchSource[i] == ' ' )
{
@ -397,10 +422,20 @@ size_t V_URLDecodeInternal( char *pchDecodeDest, int nDecodeDestLen, const char
//-----------------------------------------------------------------------------
void V_URLEncode( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen )
{
return V_URLEncodeInternal( pchDest, nDestLen, pchSource, nSourceLen, true );
return V_URLEncodeInternal( pchDest, nDestLen, pchSource, nSourceLen, true, CharNeedsEscape_Component );
}
void V_URLEncodeNoPlusForSpace( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen )
{
return V_URLEncodeInternal( pchDest, nDestLen, pchSource, nSourceLen, false, CharNeedsEscape_Component );
}
void V_URLEncodeFullPath( char *pchDest, int nDestLen, const char *pchSource, int nSourceLen )
{
return V_URLEncodeInternal( pchDest, nDestLen, pchSource, nSourceLen, false, CharNeedsEscape_FullPath );
}
//-----------------------------------------------------------------------------
// 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
@ -414,6 +449,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 )
{
@ -447,3 +487,85 @@ std::vector<std::string> TokenizeString( const std::string & sString, char cToke
return vecStrings;
}
// Mozilla: see README.mozilla for more details
//-----------------------------------------------------------------------------
// Purpose: Repairs a should-be-UTF-8 string to a for-sure-is-UTF-8 string, plus return boolean if we subbed in '?' somewhere
//-----------------------------------------------------------------------------
// bool RepairUTF8( const char *pbegin, const char *pend, std::string & sOutputUtf8 )
// {
// typedef std::codecvt_utf8<char32_t> facet_type;
// facet_type myfacet;
// std::mbstate_t mystate = std::mbstate_t();
// sOutputUtf8.clear();
// sOutputUtf8.reserve( pend - pbegin );
// bool bSqueakyClean = true;
// const char *pmid = pbegin;
// while ( pmid != pend )
// {
// bool bHasError = false;
// bool bHasValidData = false;
// char32_t out = 0xdeadbeef, *pout;
// pbegin = pmid;
// switch ( myfacet.in( mystate, pbegin, pend, pmid, &out, &out + 1, pout ) )
// {
// case facet_type::ok:
// bHasValidData = true;
// break;
// case facet_type::noconv:
// // unexpected! always converting type
// bSqueakyClean = false;
// break;
// case facet_type::partial:
// bHasError = pbegin == pmid;
// if ( bHasError )
// {
// bSqueakyClean = false;
// }
// else
// {
// bHasValidData = true;
// }
// break;
// case facet_type::error:
// bHasError = true;
// bSqueakyClean = false;
// break;
// }
// if ( bHasValidData )
// {
// // could convert back, but no need
// for ( const char *p = pbegin; p != pmid; ++p )
// {
// sOutputUtf8 += *p;
// }
// }
// if ( bHasError )
// {
// sOutputUtf8 += '?';
// }
// if ( pmid == pbegin )
// {
// pmid++;
// }
// }
// return bSqueakyClean;
// }
// //-----------------------------------------------------------------------------
// // Purpose: Repairs a should-be-UTF-8 string to a for-sure-is-UTF-8 string, plus return boolean if we subbed in '?' somewhere
// //-----------------------------------------------------------------------------
// bool RepairUTF8( const std::string & sInputUtf8, std::string & sOutputUtf8 )
// {
// return RepairUTF8( sInputUtf8.data(), sInputUtf8.data() + sInputUtf8.size(), sOutputUtf8 );
// }

Просмотреть файл

@ -14,12 +14,25 @@ bool StringHasPrefixCaseSensitive( const std::string & sString, const std::strin
bool StringHasSuffix( const std::string &sString, const std::string &sSuffix );
bool StringHasSuffixCaseSensitive( const std::string &sString, const std::string &sSuffix );
// Mozilla: see README.mozilla for more details
#if defined( _WIN32 )
/** converts a UTF-16 string to a UTF-8 string */
std::string UTF16to8(const wchar_t * in);
std::string UTF16to8( const wchar_t * in );
std::string UTF16to8( const std::wstring & in );
/** converts a UTF-8 string to a UTF-16 string */
std::wstring UTF8to16(const char * in);
std::wstring UTF8to16( const std::string & in );
#define Utf16FromUtf8 UTF8to16
#endif
#if defined( _WIN32 )
std::string DefaultACPtoUTF8( const char *pszStr );
#endif
/** Repairs a should-be-UTF-8 string to a for-sure-is-UTF-8 string, plus return boolean if we subbed in '?' somewhere */
bool RepairUTF8( const char *begin, const char *end, std::string & sOutputUtf8 );
bool RepairUTF8( const std::string & sInputUtf8, std::string & sOutputUtf8 );
/** safely copy a string into a buffer */
void strcpy_safe( char *pchBuffer, size_t unBufferSizeBytes, const char *pchSource );
@ -98,6 +111,7 @@ inline uint64_t strtoull(const char *str, char **endptr, int base) { return _str
uint32_t ReturnStdString( const std::string & sValue, char *pchBuffer, uint32_t unBufferLen );
/** Returns a std::string from a uint64_t */
// Mozilla: see README.mozilla for more details
//std::string Uint64ToString( uint64_t ulValue );
/** returns a uint64_t from a string */
@ -112,6 +126,13 @@ 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 );
/** Same as V_URLEncodeNoPlusForSpace, but without escaping / and : */
void V_URLEncodeFullPath( 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
@ -122,6 +143,9 @@ 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
//-----------------------------------------------------------------------------

Просмотреть файл

@ -132,6 +132,10 @@ 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 "";
@ -204,44 +208,64 @@ bool CVRPathRegistry_Public::ToJsonString( std::string &sJsonString )
return true;
}
// Mozilla: see README.mozilla for more details
// ---------------------------------------------------------------------------
// Purpose: Loads the config file from its well known location
// ---------------------------------------------------------------------------
bool CVRPathRegistry_Public::BLoadFromFile()
bool CVRPathRegistry_Public::BLoadFromFile( std::string *psLoadError )
{
std::string sRegPath = GetVRPathRegistryFilename();
if( sRegPath.empty() )
{
VRLog( "Unable to determine VR Path Registry filename\n" );
if ( psLoadError )
{
*psLoadError = "Unable to determine VR Path Registry filename";
}
return false;
}
std::string sRegistryContents = Path_ReadTextFile( sRegPath );
if( sRegistryContents.empty() )
{
VRLog( "Unable to read VR Path Registry from %s\n", sRegPath.c_str() );
if ( psLoadError )
{
*psLoadError = "Unable to read VR Path Registry from " + sRegPath;
}
return false;
}
Json::Value root;
Json::CharReaderBuilder builder;
std::istringstream istream(sRegistryContents);
std::string errors;
std::istringstream istream( sRegistryContents );
std::string sErrors;
if( !parseFromStream( builder, istream, &root, &errors ) )
// try
{
VRLog( "Unable to parse %s: %s\n", sRegPath.c_str(), errors.c_str() );
return false;
}
if ( !parseFromStream( builder, istream, &root, &sErrors ) )
{
if ( psLoadError )
{
*psLoadError = "Unable to parse " + sRegPath + ": " + sErrors;
}
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_vecExternalDrivers, root, "external_drivers" );
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" );
}
}
// catch ( ... )
// {
// if ( psLoadError )
// {
// *psLoadError = "Unable to parse " + sRegPath + ": exception thrown in JSON library";
// }
// return false;
// }
return true;
}
@ -252,9 +276,6 @@ bool CVRPathRegistry_Public::BLoadFromFile()
// ---------------------------------------------------------------------------
bool CVRPathRegistry_Public::BSaveToFile() const
{
#if defined( DASHBOARD_BUILD_MODE )
return false;
#else
std::string sRegPath = GetVRPathRegistryFilename();
if( sRegPath.empty() )
return false;
@ -287,7 +308,6 @@ bool CVRPathRegistry_Public::BSaveToFile() const
}
return true;
#endif
}
@ -334,12 +354,15 @@ std::string CVRPathRegistry_Public::GetLogPath() const
// ---------------------------------------------------------------------------
bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *psConfigPath, std::string *psLogPath, const char *pchConfigPathOverride, const char *pchLogPathOverride, std::vector<std::string> *pvecExternalDrivers )
{
std::string sLoadError;
CVRPathRegistry_Public pathReg;
bool bLoadedRegistry = pathReg.BLoadFromFile();
bool bLoadedRegistry = pathReg.BLoadFromFile( &sLoadError );
int nCountEnvironmentVariables = 0;
int nRequestedPaths = 0;
if( psRuntimePath )
{
nRequestedPaths++;
if ( GetEnvironmentVariable( k_pchRuntimeOverrideVar ).length() != 0 )
{
*psRuntimePath = GetEnvironmentVariable( k_pchRuntimeOverrideVar );
@ -357,6 +380,7 @@ bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *
if( psConfigPath )
{
nRequestedPaths++;
if ( GetEnvironmentVariable( k_pchConfigOverrideVar ).length() != 0 )
{
*psConfigPath = GetEnvironmentVariable( k_pchConfigOverrideVar );
@ -378,6 +402,7 @@ bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *
if( psLogPath )
{
nRequestedPaths++;
if ( GetEnvironmentVariable( k_pchLogOverrideVar ).length() != 0 )
{
*psLogPath = GetEnvironmentVariable( k_pchLogOverrideVar );
@ -402,11 +427,15 @@ bool CVRPathRegistry_Public::GetPaths( std::string *psRuntimePath, std::string *
*pvecExternalDrivers = pathReg.m_vecExternalDrivers;
}
if ( nCountEnvironmentVariables == 3 )
if ( nCountEnvironmentVariables == nRequestedPaths )
{
// 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;
}
else if( !bLoadedRegistry )
{
VRLog( "%s\n", sLoadError.c_str() );
}
return bLoadedRegistry;
}

Просмотреть файл

@ -22,7 +22,7 @@ public:
* Returns false if the path registry could not be read. Valid paths might still be returned based on environment variables. */
static bool GetPaths( std::string *psRuntimePath, std::string *psConfigPath, std::string *psLogPath, const char *pchConfigPathOverride, const char *pchLogPathOverride, std::vector<std::string> *pvecExternalDrivers = NULL );
bool BLoadFromFile();
bool BLoadFromFile( std::string *psError = nullptr );
bool BSaveToFile() const;
bool ToJsonString( std::string &sJsonString );