/// <summary> /// Constructs a new IOStream. /// </summary> /// <param name="pathToFile">Path to file given by Assimp</param> /// <param name="fileMode">Desired file access mode</param> public IOStream(String pathToFile, FileIOMode fileMode) { m_pathToFile = pathToFile; m_fileMode = fileMode; m_writeProc = OnAiFileWriteProc; m_readProc = OnAiFileReadProc; m_tellProc = OnAiFileTellProc; m_fileSizeProc = OnAiFileSizeProc; m_seekProc = OnAiFileSeekProc; m_flushProc = OnAiFileFlushProc; AiFile file; file.WriteProc = Marshal.GetFunctionPointerForDelegate(m_writeProc); file.ReadProc = Marshal.GetFunctionPointerForDelegate(m_readProc); file.TellProc = Marshal.GetFunctionPointerForDelegate(m_tellProc); file.FileSizeProc = Marshal.GetFunctionPointerForDelegate(m_fileSizeProc); file.SeekProc = Marshal.GetFunctionPointerForDelegate(m_seekProc); file.FlushProc = Marshal.GetFunctionPointerForDelegate(m_flushProc); file.UserData = IntPtr.Zero; m_filePtr = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf <AiFile>()); Marshal.StructureToPtr(file, m_filePtr, false); }
public IOStreamWrapper(Stream s, string filePath, FileIOMode ioMode) : base(filePath, ioMode) { Contract.Requires<ArgumentNullException>(s != null); this.s = s; }
private IntPtr OnAiFileOpenProc(IntPtr fileIO, String pathToFile, String mode) { if (m_fileIOPtr != fileIO) { return(IntPtr.Zero); } FileIOMode fileMode = ConvertFileMode(mode); IOStream iostream = OpenFile(pathToFile, fileMode); IntPtr aiFilePtr = IntPtr.Zero; if (iostream != null) { if (iostream.IsValid) { aiFilePtr = iostream.AiFile; m_openedFiles.Add(aiFilePtr, iostream); } else { iostream.Dispose(); } } return(aiFilePtr); }
private FileIOMode ConvertFileMode(String mode) { FileIOMode fileMode = FileIOMode.Read; switch (mode) { case "w": fileMode = FileIOMode.Write; break; case "wb": fileMode = FileIOMode.WriteBinary; break; case "wt": fileMode = FileIOMode.WriteText; break; case "r": fileMode = FileIOMode.Read; break; case "rb": fileMode = FileIOMode.ReadBinary; break; case "rt": fileMode = FileIOMode.ReadText; break; } return(fileMode); }
} /* end Filename */ /* --------------------------------------------------------------------------- * method Mode () * --------------------------------------------------------------------------- * Passes the receiver's mode back in out parameter mode and returns a status. * * pre-conditions: * o receiver must be open * * post-conditions: * o mode is passed in mode, status Success is returned * * error-conditions: * o out parameter remains unchanged, status other than Success is returned * ------------------------------------------------------------------------ */ public FileIOStatus GetMode(ref FileIOMode mode) { if (!isOpen) { return(FileIOStatus.InvalidReference); } /* end if */ mode = this.mode; return(FileIOStatus.Success); } /* end GetMode */
private void OpenRead(String pathToFile, FileIOMode fileMode) { String fileName = Path.GetFileName(pathToFile); if (LumpManager.LumpExistsFullPath(pathToFile)) { lmp = LumpManager.GetLumpFullPath(pathToFile); stream = lmp.AsStream; } }
private void OpenRead(String pathToFile, FileIOMode fileMode) { String fileName = Path.GetFileName(pathToFile); String foundPath; if (_parent.FindFile(fileName, out foundPath)) { pathToFile = foundPath; } if (File.Exists(pathToFile)) { _fileStream = File.OpenRead(pathToFile); } }
public override IOStream OpenFile(string pathToFile, FileIOMode fileMode) { if (pathToFile == _originalResource.FileNameWithExtension) { var openedStream = _originalResource.OpenInputStream(); return(new AssimpIOStream(openedStream, pathToFile, fileMode)); } else { // Split all elements (directories and the file) form the given path string[] pathElements; if (Path.DirectorySeparatorChar == Path.AltDirectorySeparatorChar) { pathElements = pathToFile.Split(Path.DirectorySeparatorChar); } else { pathElements = pathToFile.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); } // Now get true directory path var pathDirectoryBuilder = new List <string>(pathElements.Length); for (var loop = 0; loop < pathElements.Length - 1; loop++) { var actDirectoryName = pathElements[loop]; if (string.IsNullOrEmpty(actDirectoryName)) { continue; } if (actDirectoryName == ".") { continue; } pathDirectoryBuilder.Add(actDirectoryName); } // Load the file var link = _originalResource.GetForAnotherFile( pathElements[pathElements.Length - 1], pathDirectoryBuilder.ToArray()); var openedStream = link.OpenInputStream(); return(new AssimpIOStream(openedStream, pathToFile, fileMode)); } }
public LumpIOStream(LumpIOSystem parent, String pathToFile, FileIOMode fileMode) : base(pathToFile, fileMode) { this.parent = parent; switch (fileMode) { case FileIOMode.Read: case FileIOMode.ReadBinary: case FileIOMode.ReadText: OpenRead(pathToFile, fileMode); break; case FileIOMode.Write: case FileIOMode.WriteBinary: case FileIOMode.WriteText: throw new NotImplementedException(); } }
public FileIOStream(FileIOSystem parent, String pathToFile, FileIOMode fileMode) : base(pathToFile, fileMode) { _parent = parent; switch (fileMode) { case FileIOMode.Read: case FileIOMode.ReadBinary: case FileIOMode.ReadText: OpenRead(pathToFile, fileMode); break; case FileIOMode.Write: case FileIOMode.WriteBinary: case FileIOMode.WriteText: OpenWrite(pathToFile, fileMode); break; } }
/// <summary> /// Constructs a new IOStream. /// </summary> /// <param name="pathToFile">Path to file given by Assimp</param> /// <param name="fileMode">Desired file access mode</param> public IOStream(String pathToFile, FileIOMode fileMode) { m_pathToFile = pathToFile; m_fileMode = fileMode; m_writeProc = OnAiFileWriteProc; m_readProc = OnAiFileReadProc; m_tellProc = OnAiFileTellProc; m_fileSizeProc = OnAiFileSizeProc; m_seekProc = OnAiFileSeekProc; m_flushProc = OnAiFileFlushProc; AiFile file; file.WriteProc = Marshal.GetFunctionPointerForDelegate(m_writeProc); file.ReadProc = Marshal.GetFunctionPointerForDelegate(m_readProc); file.TellProc = Marshal.GetFunctionPointerForDelegate(m_tellProc); file.FileSizeProc = Marshal.GetFunctionPointerForDelegate(m_fileSizeProc); file.SeekProc = Marshal.GetFunctionPointerForDelegate(m_seekProc); file.FlushProc = Marshal.GetFunctionPointerForDelegate(m_flushProc); file.UserData = IntPtr.Zero; m_filePtr = MemoryHelper.AllocateMemory(MemoryHelper.SizeOf<AiFile>()); Marshal.StructureToPtr(file, m_filePtr, false); }
private void OpenWrite(String pathToFile, FileIOMode fileMode) { m_fileStream = File.OpenWrite(pathToFile); }
/// <summary> /// Opens a stream to a file. /// </summary> /// <param name="pathToFile">Path to the file</param> /// <param name="fileMode">Desired file access mode</param> /// <returns>The IO stream</returns> public override IOStream OpenFile(String pathToFile, FileIOMode fileMode) { return new FileIOStream(this, pathToFile, fileMode); }
/// <summary> /// Opens a stream to a file. /// </summary> /// <param name="pathToFile">Path to the file</param> /// <param name="fileMode">Desired file access mode</param> /// <returns>The IO stream</returns> public abstract IOStream OpenFile(String pathToFile, FileIOMode fileMode);
private void OpenWrite(String pathToFile, FileIOMode fileMode) { _fileStream = File.OpenWrite(pathToFile); }
/// <summary> /// Opens a stream to a file. /// </summary> /// <param name="pathToFile">Path to the file</param> /// <param name="fileMode">Desired file access mode</param> /// <returns>The IO stream</returns> public override IOStream OpenFile(String pathToFile, FileIOMode fileMode) { return(new FileIOStream(this, pathToFile, fileMode)); }
public override IOStream OpenFile(string pathToFile, FileIOMode fileMode) { return new IOStreamWrapper(contentManager.GetStreamAsync(pathToFile).Result, pathToFile, fileMode); }
private void OpenRead(String pathToFile, FileIOMode fileMode) { String fileName = Path.GetFileName(pathToFile); String foundPath; if(m_parent.FindFile(fileName, out foundPath)) pathToFile = foundPath; if(File.Exists(pathToFile)) m_fileStream = File.OpenRead(pathToFile); }
public FileIOStream(FileIOSystem parent, String pathToFile, FileIOMode fileMode) : base(pathToFile, fileMode) { m_parent = parent; switch(fileMode) { case FileIOMode.Read: case FileIOMode.ReadBinary: case FileIOMode.ReadText: OpenRead(pathToFile, fileMode); break; case FileIOMode.Write: case FileIOMode.WriteBinary: case FileIOMode.WriteText: OpenWrite(pathToFile, fileMode); break; } }
Open(string filename, FileIOMode mode) { FileIO fio; FileStream fs; FileIOStatus status; if (string.IsNullOrEmpty(filename)) { return(new Result <IFileIO, FileIOStatus> (null, FileIOStatus.InvalidReference)); } /* end if */ fs = null; try { switch (mode) { case FileIOMode.Read: fs = new FileStream(filename, FileMode.Open, FileAccess.Read); break; case FileIOMode.Write: fs = new FileStream(filename, FileMode.Open, FileAccess.Write); break; case FileIOMode.Append: fs = new FileStream(filename, FileMode.Append, FileAccess.Write); break; } /* end switch */ if (fs != null) { status = FileIOStatus.Success; } else { status = FileIOStatus.IOSubsystemError; } /* end if */ } catch (FileNotFoundException) { status = FileIOStatus.FileNotFound; } catch (DirectoryNotFoundException) { status = FileIOStatus.FileNotFound; } catch (UnauthorizedAccessException) { status = FileIOStatus.FileAccessDenied; } catch (PathTooLongException) { status = FileIOStatus.InvalidReference; } catch (IOException) { status = FileIOStatus.IOSubsystemError; } /* end try */ if (status == FileIOStatus.Success) { fio = new FileIO(); fio.isOpen = true; fio.mode = mode; fio.file = fs; } else { fio = null; } /* end if */ return(new Result <IFileIO, FileIOStatus>(fio, status)); } /* end Open */
public AssimpIOStream(Stream stream, string pathToFile, FileIOMode fileMode) : base(pathToFile, fileMode) { _stream = stream; }