mirror of
https://github.com/hanetzer/sdraw_mods_cvr.git
synced 2025-09-04 10:59:22 +00:00
Desktop Head Tracking mod
This commit is contained in:
parent
0ebafccb33
commit
b116b14843
14 changed files with 847 additions and 0 deletions
55
ml_dht/MemoryMapReader.cs
Normal file
55
ml_dht/MemoryMapReader.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System.IO;
|
||||
using System.IO.MemoryMappedFiles;
|
||||
|
||||
namespace ml_dht
|
||||
{
|
||||
class MemoryMapReader
|
||||
{
|
||||
MemoryMappedFile m_file = null;
|
||||
MemoryMappedViewStream m_stream = null;
|
||||
int m_dataSize = 0;
|
||||
|
||||
public bool Open(string p_path, int p_dataSize = 1024)
|
||||
{
|
||||
if(m_file == null)
|
||||
{
|
||||
m_dataSize = p_dataSize;
|
||||
|
||||
m_file = MemoryMappedFile.CreateOrOpen(p_path, m_dataSize, MemoryMappedFileAccess.ReadWrite);
|
||||
m_stream = m_file.CreateViewStream(0, m_dataSize, MemoryMappedFileAccess.Read);
|
||||
}
|
||||
return (m_file != null);
|
||||
}
|
||||
|
||||
public bool Read(ref byte[] p_data)
|
||||
{
|
||||
bool l_result = false;
|
||||
if((m_stream != null) && m_stream.CanRead)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_stream.Seek(0, SeekOrigin.Begin);
|
||||
m_stream.Read(p_data, 0, (p_data.Length > m_dataSize) ? m_dataSize : p_data.Length);
|
||||
l_result = true;
|
||||
}
|
||||
catch(System.Exception) { }
|
||||
}
|
||||
return l_result;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if(m_file != null)
|
||||
{
|
||||
m_stream.Close();
|
||||
m_stream.Dispose();
|
||||
m_stream = null;
|
||||
|
||||
m_file.Dispose();
|
||||
m_file = null;
|
||||
|
||||
m_dataSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue