mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Expose directory listing functions to C#
This commit is contained in:
@@ -30,6 +30,18 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace renderdoc
|
||||
{
|
||||
[Flags]
|
||||
public enum DirectoryFileProperty
|
||||
{
|
||||
Directory = 0x1,
|
||||
Hidden = 0x2,
|
||||
Executable = 0x4,
|
||||
|
||||
ErrorUnknown = 0x2000,
|
||||
ErrorAccessDenied = 0x4000,
|
||||
ErrorInvalidPath = 0x8000,
|
||||
};
|
||||
|
||||
public enum VarType
|
||||
{
|
||||
Float = 0,
|
||||
|
||||
@@ -74,6 +74,34 @@ namespace renderdoc
|
||||
public float x, y, z, w;
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DirectoryFile : IComparable<DirectoryFile>
|
||||
{
|
||||
[CustomMarshalAs(CustomUnmanagedType.UTF8TemplatedString)]
|
||||
public string filename;
|
||||
public DirectoryFileProperty flags;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} ({1})", filename, flags);
|
||||
}
|
||||
|
||||
public int CompareTo(DirectoryFile o)
|
||||
{
|
||||
// sort directories first
|
||||
bool thisdir = flags.HasFlag(DirectoryFileProperty.Directory);
|
||||
bool odir = o.flags.HasFlag(DirectoryFileProperty.Directory);
|
||||
|
||||
if (thisdir && !odir)
|
||||
return -1;
|
||||
if (!thisdir && odir)
|
||||
return 1;
|
||||
|
||||
// can't have duplicates with same filename, so just compare filenames
|
||||
return filename.CompareTo(o.filename);
|
||||
}
|
||||
};
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class ResourceFormat
|
||||
{
|
||||
|
||||
@@ -858,6 +858,11 @@ namespace renderdoc
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern bool RemoteServer_RemoteSupportedReplays(IntPtr real, IntPtr outlist);
|
||||
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void RemoteServer_GetHomeFolder(IntPtr real, IntPtr outfolder);
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void RemoteServer_ListFolder(IntPtr real, IntPtr path, IntPtr outlist);
|
||||
|
||||
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern UInt32 RemoteServer_ExecuteAndInject(IntPtr real, IntPtr app, IntPtr workingDir, IntPtr cmdLine, CaptureOptions opts);
|
||||
|
||||
@@ -896,6 +901,41 @@ namespace renderdoc
|
||||
}
|
||||
}
|
||||
|
||||
public string GetHomeFolder()
|
||||
{
|
||||
IntPtr homepath_mem = CustomMarshal.Alloc(typeof(templated_array));
|
||||
|
||||
RemoteServer_GetHomeFolder(m_Real, homepath_mem);
|
||||
|
||||
string home = CustomMarshal.TemplatedArrayToString(homepath_mem, true);
|
||||
|
||||
CustomMarshal.Free(homepath_mem);
|
||||
|
||||
// normalise to /s and with no trailing /s
|
||||
home.Replace('\\', '/');
|
||||
if (home[home.Length - 1] == '/')
|
||||
home = home.Remove(0, home.Length - 1);
|
||||
|
||||
return home;
|
||||
}
|
||||
|
||||
public DirectoryFile[] ListFolder(string path)
|
||||
{
|
||||
IntPtr path_mem = CustomMarshal.MakeUTF8String(path);
|
||||
IntPtr out_mem = CustomMarshal.Alloc(typeof(templated_array));
|
||||
|
||||
RemoteServer_ListFolder(m_Real, path_mem, out_mem);
|
||||
|
||||
DirectoryFile[] ret = (DirectoryFile[])CustomMarshal.GetTemplatedArray(out_mem, typeof(DirectoryFile), true);
|
||||
|
||||
CustomMarshal.Free(out_mem);
|
||||
CustomMarshal.Free(path_mem);
|
||||
|
||||
Array.Sort(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public string[] LocalProxies()
|
||||
{
|
||||
IntPtr mem = CustomMarshal.Alloc(typeof(templated_array));
|
||||
|
||||
Reference in New Issue
Block a user