public Stream Open(SharpDX.D3DCompiler.IncludeType type, string fileName, Stream parentStream) { SlimDX.D3DCompiler.IncludeType slimType = (SlimDX.D3DCompiler.IncludeType)(int) type; Stream stream; this.slimInclude.Open(slimType, fileName, parentStream, out stream); return(stream); }
private static SharpDX.Result OpenImpl(IntPtr thisPtr, SharpDX.D3DCompiler.IncludeType includeType, IntPtr fileNameRef, IntPtr pParentData, ref IntPtr dataRef, ref int bytesRef) { unsafe { try { var shadow = ToShadow <IncludeShadow>(thisPtr); var callback = (Include)shadow.Callback; Stream stream = null; Stream parentStream = null; if (shadow.frames.ContainsKey(pParentData)) { parentStream = shadow.frames[pParentData].Stream; } stream = callback.Open(includeType, Marshal.PtrToStringAnsi(fileNameRef), parentStream); if (stream == null) { return(Result.Fail); } GCHandle handle; if (stream is DataStream) { // Magic shortcut if we happen to get a DataStream var data = (DataStream)stream; dataRef = data.PositionPointer; bytesRef = (int)(data.Length - data.Position); handle = new GCHandle(); } else { // Read the stream into a byte array and pin it byte[] data = SharpDX.Utilities.ReadStream(stream); handle = GCHandle.Alloc(data, GCHandleType.Pinned); dataRef = handle.AddrOfPinnedObject(); bytesRef = data.Length; } shadow.frames.Add(dataRef, new Frame(stream, handle)); return(Result.Ok); } catch (SharpDXException exception) { return(exception.ResultCode.Code); } catch (Exception) { return(Result.Fail); } } }
public Stream Open(SharpDX.D3DCompiler.IncludeType type, string fileName, Stream parentStream) { try { var resolvedFile = fileName; if (!Path.IsPathRooted(resolvedFile)) { // Search in the directory containing the calling file string parentPath; if (parentStream != null && _resolvedPaths.TryGetValue(parentStream, out parentPath)) { var subFilePath = Path.Combine(Path.GetDirectoryName(parentPath), fileName); if (File.Exists(subFilePath)) { resolvedFile = subFilePath; } } if (!File.Exists(resolvedFile)) { // Search in the root directory resolvedFile = Path.Combine(_rootPath, fileName); } if (!File.Exists(resolvedFile)) { // Use the current directory resolvedFile = fileName; } } var stream = new FileStream(resolvedFile, FileMode.Open, FileAccess.Read); var fullFileName = (new FileInfo(resolvedFile)).FullName; _resolvedPaths[stream] = fullFileName; if (!_dependencies.Contains(fullFileName)) { _dependencies.Add(fullFileName); } return(stream); } catch { return(null); } }
public Stream Open(SharpDX.D3DCompiler.IncludeType type, string fileName, Stream parentStream) { return(callback.Open((IncludeType)type, fileName, parentStream)); }
public System.IO.Stream Open(SharpDX.D3DCompiler.IncludeType type, string fileName, System.IO.Stream parentStream) { throw new NotImplementedException(); }