From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- gfx/vr/service/openvr/src/dirtools_public.cpp | 101 ++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 gfx/vr/service/openvr/src/dirtools_public.cpp (limited to 'gfx/vr/service/openvr/src/dirtools_public.cpp') diff --git a/gfx/vr/service/openvr/src/dirtools_public.cpp b/gfx/vr/service/openvr/src/dirtools_public.cpp new file mode 100644 index 0000000000..e5cfc02e0c --- /dev/null +++ b/gfx/vr/service/openvr/src/dirtools_public.cpp @@ -0,0 +1,101 @@ +//========= Copyright Valve Corporation ============// +#include "dirtools_public.h" +#include "strtools_public.h" +#include "pathtools_public.h" + +#include +#include + +#ifdef _WIN32 +#include "windows.h" +#else +#include +#include +#include +#include +#endif + +#if defined( OSX ) +#include +#endif + + +//----------------------------------------------------------------------------- +// Purpose: utility function to create dirs & subdirs +//----------------------------------------------------------------------------- +bool BCreateDirectoryRecursive( const char *pchPath ) +{ + // Does it already exist? + if ( Path_IsDirectory( pchPath ) ) + return true; + + // copy the path into something we can munge + int len = (int)strlen( pchPath ); + char *path = (char *)malloc( len + 1 ); + strcpy( path, pchPath ); + + // Walk backwards to first non-existing dir that we find + char *s = path + len - 1; + + const char slash = Path_GetSlash(); + while ( s > path ) + { + if ( *s == slash ) + { + *s = '\0'; + bool bExists = Path_IsDirectory( path ); + *s = slash; + + if ( bExists ) + { + ++s; + break; + } + } + --s; + } + + // and then move forwards from there + + while ( *s ) + { + if ( *s == slash ) + { + *s = '\0'; + BCreateDirectory( path ); + *s = slash; + } + s++; + } + + bool bRetVal = BCreateDirectory( path ); + free( path ); + return bRetVal; +} + + +//----------------------------------------------------------------------------- +// Purpose: Creates the directory, returning true if it is created, or if it already existed +//----------------------------------------------------------------------------- +bool BCreateDirectory( const char *pchPath ) +{ +#ifdef WIN32 + std::wstring wPath = UTF8to16( pchPath ); + if ( ::CreateDirectoryW( wPath.c_str(), NULL ) ) + return true; + + if ( ::GetLastError() == ERROR_ALREADY_EXISTS ) + return true; + + return false; +#else + int i = mkdir( pchPath, S_IRWXU | S_IRWXG | S_IRWXO ); + if ( i == 0 ) + return true; + if ( errno == EEXIST ) + return true; + + return false; +#endif +} + -- cgit v1.2.3