aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/tier1/fileio.h
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/public/tier1/fileio.h
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/public/tier1/fileio.h')
-rw-r--r--mp/src/public/tier1/fileio.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/mp/src/public/tier1/fileio.h b/mp/src/public/tier1/fileio.h
new file mode 100644
index 00000000..f2f76e8d
--- /dev/null
+++ b/mp/src/public/tier1/fileio.h
@@ -0,0 +1,101 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: A collection of utility classes to simplify file I/O, and
+// as much as possible contain portability problems. Here avoiding
+// including windows.h.
+//
+//=============================================================================
+
+#ifndef FILEIO_H
+#define FILEIO_H
+
+#if defined (_WIN32)
+#else
+#include <sys/types.h>
+#include <sys/stat.h>
+#if !defined( _PS3 )
+#include <signal.h>
+#endif // _PS3
+#endif
+
+#include "tier0/platform.h"
+#include "tier1/utlstring.h"
+#include "tier1/utllinkedlist.h"
+
+const int64 k_nMillion = 1000000;
+const int64 k_nThousand = 1000;
+const int64 k_nKiloByte = 1024;
+const int64 k_nMegabyte = k_nKiloByte * k_nKiloByte;
+const int64 k_nGigabyte = k_nMegabyte * k_nKiloByte;
+
+class CPathString
+{
+public:
+
+ // Constructors: Automatically fixes slashes and removes double slashes when the object is
+ // constructed, and then knows how to append magic \\?\ on Windows for unicode paths
+ CPathString( const char *pchUTF8Path );
+ ~CPathString();
+
+ // Gets the path in UTF8
+ const char *GetUTF8Path();
+
+ // Gets wchar_t based path, with \\?\ pre-pended (allowing long paths on Win32, should only be used with unicode aware filesystem calls)
+ const wchar_t *GetWCharPathPrePended();
+
+private:
+
+ void PopulateWCharPath();
+
+ char *m_pchUTF8Path;
+ wchar_t *m_pwchWideCharPathPrepended;
+
+};
+
+#if !defined(_PS3)
+//-----------------------------------------------------------------------------
+// Purpose: Encapsulates watching a directory for file changes
+//-----------------------------------------------------------------------------
+class CDirWatcher
+{
+public:
+ CDirWatcher();
+ ~CDirWatcher();
+
+ // only one directory can be watched at a time
+ void SetDirToWatch( const char *pchDir );
+
+ // retrieve any changes
+ bool GetChangedFile( CUtlString *psFile );
+
+#ifdef DBGFLAG_VALIDATE
+ void Validate( CValidator &validator, const char *pchName );
+#endif
+
+private:
+ CUtlLinkedList<CUtlString> m_listChangedFiles;
+ void *m_hFile;
+ void *m_pOverlapped;
+ void *m_pFileInfo;
+#ifdef OSX
+public:
+ struct timespec m_modTime;
+ void AddFileToChangeList( const char *pchFile );
+ CUtlString m_BaseDir;
+private:
+ void *m_WatcherStream;
+#endif
+ friend class CDirWatcherFriend;
+
+#ifdef LINUX
+ void AddFileToChangeList( const char *pchFile );
+#endif
+#ifdef WIN32
+ // used by callback functions to push a file onto the list
+ void AddFileToChangeList( const char *pchFile );
+ void PostDirWatch();
+#endif
+};
+#endif // _PS3
+
+#endif // FILEIO_H