Example #1
0
        /// <summary>
        /// Load section descriptions from given file.
        /// </summary>
        public void Load(string fileName, BinaryLoadArgs e)
        {
            fullPath = Path.GetFullPath(fileName);
            name     = Path.GetFileName(fileName);

            if (File.Exists(fullPath))
            {
                if (e == null || e.UseMapping)
                {
                    // create readers:
                    UnmanagedDataReader s;
                    FileSharedMemory    fs = null;

                    try
                    {
                        fs = new FileSharedMemory(fullPath,
                                                  (e == null || e.IsReadOnlyMode
                                                       ? SharedMemory.AccessTypes.ReadOnly
                                                       : SharedMemory.AccessTypes.ReadWrite));
                        s = new UnmanagedDataReader(fs.Address, fs.Size);

                        // and parse the file:
                        Load(s, e);
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                }
                else
                {
                    // read brutally the whole file into memory and parse:
                    byte[] x = File.ReadAllBytes(fullPath);

                    // check if not empty:
                    if (x.Length > 0)
                    {
                        IntPtr p = Marshal.AllocHGlobal(x.Length);

                        if (p != IntPtr.Zero)
                        {
                            Marshal.Copy(x, 0, p, x.Length);
                            Load(new UnmanagedDataReader(p, (uint)x.Length), e);
                            Marshal.FreeHGlobal(p);
                        }
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Loads proper binary sections based on given source.
 /// </summary>
 protected abstract void Load(UnmanagedDataReader s, BinaryLoadArgs e);