/// <summary>
        /// Load a CFG file from disk.
        /// </summary>
        /// <param name="filePath">Absolute path to CLASS*.CFG file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
        {
            // Validate filename
            string filename = Path.GetFileName(filePath);
            if (!filename.StartsWith("CLASS", StringComparison.InvariantCultureIgnoreCase) ||
                !filename.EndsWith(".CFG", StringComparison.InvariantCultureIgnoreCase))
            {
                return false;
            }

            // Load file
            if (!file.Load(filePath, usage, readOnly))
                return false;

            // Read file data
            BinaryReader reader = file.GetReader();
            ReadFile(reader);

            return true;
        }
        /// <summary>
        /// Loads an IMG file.
        /// </summary>
        /// <param name="filePath">Absolute path to *.IMG file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
            {
                return(true);
            }

            // Validate filename
            filePath = filePath.ToUpper();
            string fn = Path.GetFileName(filePath);

            if (!fn.EndsWith(".IMG"))
            {
                return(false);
            }

            // Handle unsupported files
            if (!IsFilenameSupported(fn))
            {
                Console.WriteLine(string.Format("{0} is unsupported.", fn));
                return(false);
            }

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
示例#3
0
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Ensure filename ends with .BSA or .SND
            if (!filePath.EndsWith(".BSA", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith(".SND", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        /// <summary>
        /// Load WOODS.WLD file.
        /// </summary>
        /// <param name="FilePath">Absolute path to WOODS.WLD file.</param>
        /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string FilePath, FileUsage Usage, bool ReadOnly)
        {
            // Validate filename
            FilePath = FilePath.ToUpper();
            if (!FilePath.EndsWith("WOODS.WLD"))
            {
                return(false);
            }

            // Load file into memory
            if (!ManagedFile.Load(FilePath, Usage, ReadOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Load WOODS.WLD file.
        /// </summary>
        /// <param name="filePath">Absolute path to WOODS.WLD file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            filePath = filePath.ToUpper();
            if (!filePath.EndsWith(Filename))
            {
                return(false);
            }

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="FilePath">Absolute path to BSA file.</param>
        /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string FilePath, FileUsage Usage, bool ReadOnly)
        {
            // Ensure filename ends with .BSA
            FilePath = FilePath.ToUpper();
            if (!FilePath.EndsWith(".BSA") &&
                !FilePath.EndsWith(".SND"))
            {
                return(false);
            }

            // Load file into memory
            if (!ManagedFile.Load(FilePath, Usage, ReadOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
示例#7
0
        /// <summary>
        /// Load a CFG file from disk.
        /// </summary>
        /// <param name="filePath">Absolute path to CLASS*.CFG file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(byte[] data, string Name = "NoName", FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
        {
            // Validate filename
            //string filename = Path.GetFileName(filePath);
            //if (!filename.EndsWith(".ITM", StringComparison.InvariantCultureIgnoreCase))
            //{
            //    return false;
            //}

            itemName = Name;

            // Load file
            if (!file.Load(data, "", usage, readOnly))
            {
                return(false);
            }

            // Read file data
            BinaryReader reader = file.GetReader();

            ReadFile(reader);

            return(true);
        }
示例#8
0
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Ensure filename ends with .BSA
            filePath = filePath.ToUpper();
            if (!filePath.EndsWith(".BSA") &&
                !filePath.EndsWith(".SND"))
            {
                return(false);
            }

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Load a CFG file from disk.
        /// </summary>
        /// <param name="filePath">Absolute path to CLASS*.CFG file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
        {
            // Validate filename
            string filename = Path.GetFileName(filePath);

            if (!filename.StartsWith("CLASS", StringComparison.InvariantCultureIgnoreCase) ||
                !filename.EndsWith(".CFG", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            // Load file
            if (!file.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file data
            BinaryReader reader = file.GetReader();

            ReadFile(reader);

            return(true);
        }
示例#10
0
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <param name="filePatch">An optional list of patches to apply to file memory buffer.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly, PatchList filePatch = null)
        {
            // Ensure filename ends with .BSA or .SND
            if (!filePath.EndsWith(".BSA", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith(".SND", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith(".SAV", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Patch the file
            if (usage == FileUsage.UseMemory && filePatch != null)
            {
                foreach (var patch in filePatch)
                {
                    for (int i = 0; i < patch.data.Length; i++)
                    {
                        managedFile.Buffer[patch.offset + i] = patch.data[i];
                    }
                }
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Loads a file into memory.
        /// </summary>
        /// <param name="FilePath">Absolute path of file to load.</param>
        /// <param name="FileAccess">Defines access to file.</param>
        /// <param name="FileShare">Defines shared access to file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        private bool LoadMemory(string FilePath, FileAccess FileAccess, FileShare FileShare)
        {
            // File must exist
            if (!File.Exists(FilePath))
            {
                return(false);
            }

            // Load file into memory buffer
            try
            {
                FileStream file = File.Open(FilePath, FileMode.Open, FileAccess, FileShare);
                fileBuffer = new byte[file.Length];
                if (file.Length != file.Read(fileBuffer, 0, (int)file.Length))
                {
                    return(false);
                }

                // Close file
                file.Close();
            }
            catch (Exception e)
            {
                MyLastException = e;
                Console.WriteLine(e.Message);
                return(false);
            }

            // Store filename
            ManagedFilePath = FilePath;

            // Set usage
            fileUsage = FileUsage.UseMemory;

            return(true);
        }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="FilePath">Absolute path to MAPS.BSA.</param>
 /// <param name="Usage">Determines if the BSA file will read from disk or memory.</param>
 /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
 public MapsFile(string FilePath, FileUsage Usage, bool ReadOnly)
 {
     Load(FilePath, Usage, ReadOnly);
 }
 /// <summary>
 /// Loads an image file.
 /// </summary>
 /// <param name="filePath">Absolute path to file</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 /// <returns>True if successful, otherwise false.</returns>
 public abstract bool Load(string filePath, FileUsage usage, bool readOnly);
示例#14
0
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Ensure filename ends with .BSA or .SND
            filePath = filePath.ToUpper();
            if (!filePath.EndsWith(".BSA") &&
                !filePath.EndsWith(".SND"))
                return false;

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
示例#15
0
 public MagicItemsFile(string filePath, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
 {
     Load(filePath, usage, readOnly);
 }
 /// <summary>
 /// Load constructor that also loads a palette.
 /// </summary>
 /// <param name="FilePath">Absolute path to *.CIF or *.RCI file.</param>
 /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="PaletteFilePath">Absolute path to Daggerfall palette file.</param>
 /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
 public CifRciFile(string FilePath, FileUsage Usage, string PaletteFilePath, bool ReadOnly)
 {
     LoadPalette(PaletteFilePath);
     Load(FilePath, Usage, ReadOnly);
 }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public FileProxy(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
示例#18
0
 /// <summary>
 /// Load constructor with palette assignment.
 /// Some IMG files contain palette information, this will overwrite the specified palette.
 /// </summary>
 /// <param name="filePath">Absolute path to *.IMG file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="palette">Palette to use when building images.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public ImgFile(string filePath, FileUsage usage, DFPalette palette, bool readOnly)
 {
     myPalette = palette;
     Load(filePath, usage, readOnly);
 }
        /// <summary>
        /// Loads a texture file.
        /// </summary>
        /// <param name="filePath">Absolute path to TEXTURE.* file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
            {
                return(true);
            }

            // Validate filename
            string fn = Path.GetFileName(filePath);

            if (!fn.StartsWith("TEXTURE.", StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            // Handle unsupported files
            if (!IsFilenameSupported(fn))
            {
                Console.WriteLine(string.Format("{0} is unsupported.", fn));
                return(false);
            }

            // Handle solid types
            if (fn == "TEXTURE.000")
            {
                solidType = SolidTypes.SolidColoursA;
            }
            else if (fn == "TEXTURE.001")
            {
                solidType = SolidTypes.SolidColoursB;
            }
            else
            {
                solidType = SolidTypes.None;
            }

            // Handle spectral types
            if (fn == "TEXTURE.273" || fn == "TEXTURE.278")
            {
                spectralType = SpectralTypes.Spectral;
            }
            else
            {
                spectralType = SpectralTypes.None;
            }

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Attempt to load palette file from same path
            string arena2Path = Path.GetDirectoryName(filePath);

            LoadPalette(Path.Combine(arena2Path, PaletteName));

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
示例#20
0
 /// <summary>
 /// Loads an image file.
 /// </summary>
 /// <param name="filePath">Absolute path to file</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 /// <returns>True if successful, otherwise false.</returns>
 public abstract bool Load(string filePath, FileUsage usage, bool readOnly);
示例#21
0
 /// <summary>
 /// Load constructor with palette assignment.
 /// Some IMG files contain palette information, this will overwrite the specified palette.
 /// </summary>
 /// <param name="filePath">Absolute path to *.IMG file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="palette">Palette to use when building images.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public ImgFile(string filePath, FileUsage usage, DFPalette palette, bool readOnly)
 {
     myPalette = palette;
     Load(filePath, usage, readOnly);
 }
示例#22
0
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to TEXTURE.* file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public TextureFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
示例#23
0
        /// <summary>
        /// Loads a texture file.
        /// </summary>
        /// <param name="filePath">Absolute path to TEXTURE.* file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
                return true;

            // Validate filename
            filePath = filePath.ToUpper();
            string fn = Path.GetFileName(filePath);
            if (!fn.StartsWith("TEXTURE."))
                return false;

            // Handle unsupported files
            if (!IsFilenameSupported(fn))
            {
                Console.WriteLine(string.Format("{0} is unsupported.", fn));
                return false;
            }

            // Handle solid types
            if (fn == "TEXTURE.000")
                solidType = SolidTypes.SolidColoursA;
            else if (fn == "TEXTURE.001")
                solidType = SolidTypes.SolidColoursB;
            else
                solidType = SolidTypes.None;

            // Handle spectral types
            if (fn == "TEXTURE.273" || fn == "TEXTURE.278")
                spectralType = SpectralTypes.Spectral;
            else
                spectralType = SpectralTypes.None;

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Attempt to load palette file from same path
            string arena2Path = Path.GetDirectoryName(filePath);
            LoadPalette(Path.Combine(arena2Path, PaletteName));

            // Read file
            if (!Read())
                return false;

            return true;
        }
        /// <summary>
        /// Load MAPS.BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to MAPS.BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            if (!filePath.EndsWith("MAPS.BSA", StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load PAK files
            string arena2Path = Path.GetDirectoryName(filePath);
            climatePak = new PakFile(Path.Combine(arena2Path, "CLIMATE.PAK"));
            politicPak = new PakFile(Path.Combine(arena2Path, "POLITIC.PAK"));

            // Load file
            isReady = false;
            if (!bsaFile.Load(filePath, usage, readOnly))
                return false;

            // Create records array
            regions = new RegionRecord[RegionCount];

            // Set ready flag
            isReady = true;

            return true;
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public FileProxy()
 {
     fileUsage = FileUsage.Undefined;
 }
 public TextFile(string arena2Path, string fileName, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
 {
     Load(arena2Path, fileName, usage, readOnly);
 }
        /// <summary>
        /// Load WOODS.WLD file.
        /// </summary>
        /// <param name="filePath">Absolute path to WOODS.WLD file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            if (!filePath.EndsWith(Filename, StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
示例#28
0
 /// <summary>
 /// Path constructor.
 /// </summary>
 /// <param name="fallExePath">Path to FALL.EXE.</param>
 public ItemsFile(byte[] data, string Name = "NoName", FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
     : base()
 {
     Load(data, Name, usage, readOnly);
 }
示例#29
0
 public TextFile(string arena2Path, string fileName, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
 {
     Load(arena2Path, fileName, usage, readOnly);
 }
示例#30
0
        /// <summary>
        /// Load WOODS.WLD file.
        /// </summary>
        /// <param name="filePath">Absolute path to WOODS.WLD file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            filePath = filePath.ToUpper();
            if (!filePath.EndsWith(Filename))
                return false;

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
示例#31
0
        /// <summary>
        /// Loads an IMG file.
        /// </summary>
        /// <param name="filePath">Absolute path to *.IMG file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
                return true;

            // Validate filename
            filePath = filePath.ToUpper();
            string fn = Path.GetFileName(filePath);
            if (!fn.EndsWith(".IMG"))
                return false;

            // Handle unsupported files
            if (!IsFilenameSupported(fn))
            {
                Console.WriteLine(string.Format("{0} is unsupported.", fn));
                return false;
            }

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
 /// <summary>
 /// Load constructor with palette assignment.
 /// </summary>
 /// <param name="FilePath">Absolute path to *.CIF or *.RCI file.</param>
 /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="Palette">Palette to use when building images.</param>
 /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
 public CifRciFile(string FilePath, FileUsage Usage, DFPalette Palette, bool ReadOnly)
 {
     MyPalette = Palette;
     Load(FilePath, Usage, ReadOnly);
 }
示例#33
0
 /// <summary>
 /// Load constructor that also loads a palette.
 /// Some IMG files contain palette information, this will overwrite the specified palette.
 /// </summary>
 /// <param name="filePath">Absolute path to *.IMG file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="paletteFilePath">Absolute path to Daggerfall palette file.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public ImgFile(string filePath, FileUsage usage, string paletteFilePath, bool readOnly)
 {
     LoadPalette(paletteFilePath);
     Load(filePath, usage, readOnly);
 }
示例#34
0
        internal static IChemFile LoadFromFile(string filename, ISettings settings, FileUsage usage,
                                               LoadingProgress progress, out MoleculeLoadingResults results)
        {
            IChemObjectReader reader;

            results          = new MoleculeLoadingResults();
            results.Filename = filename;

            MoleculeLoadingProgress molLoading = new MoleculeLoadingProgress(Path.GetFileName(filename), progress);

            progress.MoveToNextProcess(molLoading);

            try
            {
                molLoading.Log("Reading file", LogItem.ItemLevel.StageInfo);

                StreamReader  file          = new StreamReader(filename, System.Text.Encoding.Default);
                ReaderFactory readerFactory = new ReaderFactory();

                molLoading.Log("Creating Reader", LogItem.ItemLevel.DebugInfo);

                reader = readerFactory.createReader(filename, file);
                file.Close();

                if (reader != null)
                {
                    reader.setReader(new StreamReader(filename, System.Text.Encoding.Default));
                }
                else
                {
                    throw new UserLevelException("Format not recognised", UserLevelException.ExceptionType.FileLoading,
                                                 typeof(MoleculeLoader), null);
                }
                results.FileFormat = (IChemFormat)reader.Format;

                molLoading.Log("Found File Format: " + reader.Format.FormatName, LogItem.ItemLevel.UserInfo);
            }
            catch (FileNotFoundException fnfe)
            {
                throw new UserLevelException("Target file no found", UserLevelException.ExceptionType.FileLoading,
                                             typeof(MoleculeLoader), fnfe);
            }
            molLoading.Log("Loaded Molecule File", LogItem.ItemLevel.Success);

            //catch (IOException ioe)
            //{
            //    throw new UserLevelException("Problem reading from file", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), ioe);
            //}
            //catch (UserLevelException ule)
            //{
            //    results.Result = MoleculeLoadingResults.Results.Problems;
            //    throw ule;
            //}
            //catch (Exception e)
            //{
            //    results.Result = MoleculeLoadingResults.Results.Errors;
            //    throw new UserLevelException("Problem loading file", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), e);
            //}

            IChemFile chemFile;
            ChemModel chemModel;

            if (reader.accepts(typeof(IChemFile)))
            {
                // try to read a ChemFile
                //try
                //{
                chemFile = (IChemFile)reader.read((IChemObject) new ChemFile());
                molLoading.UpdateProgress(1);
                if (chemFile != null)
                {
                    ProcessChemFile(chemFile, settings, usage, results, progress);
                }
                return(chemFile);
                //}
                //catch (UserLevelException ule)
                //{
                //    throw ule;
                //}
                //catch (Exception e)
                //{
                //    results.Result = MoleculeLoadingResults.Results.Errors;

                //    throw new UserLevelException("Problem reading/processing file", UserLevelException.ExceptionType.FileLoading,
                //                                 typeof(MoleculeLoader), e);
                //}
            }
            if (reader.accepts(typeof(ChemModel)))
            {
                // try to read a ChemModel
                //try
                //{
                chemModel = (ChemModel)reader.read((IChemObject) new ChemModel());
                molLoading.UpdateProgress(1);
                if (chemModel != null)
                {
                    MoleculeProcessingProgress molProcessing = new MoleculeProcessingProgress(progress);
                    progress.MoveToNextProcess(molProcessing);
                    ProcessChemModel(chemModel, settings, usage, results, molProcessing, 1);
                }
                //}
                //catch (UserLevelException ule)
                //{
                //    throw ule;
                //}
                //catch (Exception e)
                //{
                //    throw new UserLevelException("Problem reading/processing file", UserLevelException.ExceptionType.FileLoading,
                //                                 typeof(MoleculeLoader), e);
                //}
            }
            else
            {
                throw new UserLevelException("Unable to process reading", UserLevelException.ExceptionType.FileLoading,
                                             typeof(MoleculeLoader), null);
            }
            return(null);
        }
示例#35
0
        private static void ProcessChemModel(IChemModel chemModel, ISettings settings, FileUsage usage,
                                             MoleculeLoadingResults results, MoleculeProcessingProgress progress,
                                             float sectionSz)
        {
            //if (ChemModelManipulator.getAllInOneContainer(chemModel).getBondCount() == 0)
            //{
            //    return;
            //}

            // check for coordinates
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))//
            {
                results.Num2DCoords++;
            }
            //    usage == FileUsage.TwoD)
            //{
            //    throw new UserLevelException("File has no 2D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))// &&
            {
                results.Num3DCoords++;
            }
            //    usage == FileUsage.ThreeD)
            //{
            //    throw new UserLevelException("File has no 3D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}

            ElementPTFactory elements = ElementPTFactory.Instance;

            // calc item sz
            int numItems = 0;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    numItems += chemModel.SetOfMolecules.Molecules[mol].Atoms.Length;
                    //numItems += chemModel.SetOfMolecules.Molecules[mol].Bonds.Length;
                }
            }
            float itemSz = sectionSz / (float)numItems;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    IMolecule molecule = chemModel.SetOfMolecules.Molecules[mol];
                    results.NumAtoms += molecule.Atoms.Length;
                    results.NumBonds += molecule.Bonds.Length;
                    foreach (IAtom atom in molecule.Atoms)
                    {
                        PeriodicTableElement pe = elements.getElement(atom.Symbol);
                        if (pe != null)
                        {
                            atom.AtomicNumber = pe.AtomicNumber;
                            atom.Properties["PeriodicTableElement"] = pe;
                            atom.Properties["Period"] = int.Parse(pe.Period);
                        }
                        else
                        {
                            progress.Log(string.Format("Failed to find periodic element: {0}", atom.Symbol), LogItem.ItemLevel.Failure);
                        }
                        progress.UpdateProgress(itemSz);
                    }
                    progress.Log(string.Format("Processed {0} atoms", molecule.Atoms.Length), LogItem.ItemLevel.Info);
                }
            }
            progress.Log("Processed Model", LogItem.ItemLevel.Success);
        }
 /// <summary>
 /// Load constructor.
 /// </summary>
 public ClassFile(string filePath, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
 {
     Load(filePath, usage, readOnly);
 }
 /// <summary>
 /// Assign byte array constructor.
 /// </summary>
 /// <param name="Data">Byte array to assign (usage will be set to FileUsage.useMemory).</param>
 /// <param name="Name">Name, filename, or path  to describe memory buffer.</param>
 public FileProxy(byte[] Data, string Name)
 {
     fileBuffer      = Data;
     ManagedFilePath = Name;
     fileUsage       = FileUsage.UseMemory;
 }
        /// <summary>
        /// Load a file.
        /// </summary>
        /// <param name="filePath">Absolute path to file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage = FileUsage.UseMemory, bool readOnly = true)
        {
            // Determine file access settings
            FileAccess fileAccess;
            FileShare fileShare;
            if (readOnly)
            {
                fileAccess = FileAccess.Read;
                fileShare = FileShare.ReadWrite;
                isReadOnly = true;
            }
            else
            {
                fileAccess = FileAccess.ReadWrite;
                fileShare = FileShare.Read;
                isReadOnly = false;
            }

            // Load based on usage
            switch (usage)
            {
                case FileUsage.UseMemory:
                    return LoadMemory(filePath, fileAccess, fileShare);
                case FileUsage.UseDisk:
                default:
                    return LoadDisk(filePath, fileAccess, fileShare);
            }
        }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="FilePath">Absolute path to file.</param>
 /// <param name="Usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="ReadOnly">File will be read-only if true, read-write if false.</param>
 public FileProxy(string FilePath, FileUsage Usage, bool ReadOnly)
 {
     Load(FilePath, Usage, ReadOnly);
 }
        /// <summary>
        /// Loads a file into memory.
        /// Will first check Unity Resources folder for specified filename with a .bytes extensions
        /// and load that instead if available.
        /// </summary>
        /// <param name="filePath">Absolute path of file to load.</param>
        /// <param name="fileAccess">Defines access to file.</param>
        /// <param name="fileShare">Defines shared access to file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        private bool LoadMemory(string filePath, FileAccess fileAccess, FileShare fileShare)
        {
            #if UNITY_WEBGL && !UNITY_EDITOR
            // Unity cannot use Resources.Load in WebGL
            // TODO: Implement WWW resource loading
            return false;
            #else

            // Attempt to locate in Unity Resources folder first
            string fileName = Path.GetFileName(filePath);
            TextAsset asset = Resources.Load<TextAsset>(fileName);
            if (asset != null)
            {
                fileBuffer = asset.bytes;
            }
            else
            {
                // File must exist
                if (!File.Exists(filePath))
                    return false;

                // Load file into memory buffer
                try
                {
                    FileStream file = File.Open(filePath, FileMode.Open, fileAccess, fileShare);
                    fileBuffer = new byte[file.Length];
                    if (file.Length != file.Read(fileBuffer, 0, (int)file.Length))
                        return false;

                    // Close file
                    file.Close();
                }
                catch (Exception e)
                {
                    myLastException = e;
                    Console.WriteLine(e.Message);
                    return false;
                }
            }

            // Store filename
            managedFilePath = filePath;

            // Set usage
            fileUsage = FileUsage.UseMemory;

            return true;
            #endif
        }
 /// <summary>
 /// Assign byte array constructor.
 /// </summary>
 /// <param name="data">Byte array to assign (usage will be set to FileUsage.useMemory).</param>
 /// <param name="name">Name, filename, or path  to describe memory buffer.</param>
 public FileProxy(byte[] data, string name)
 {
     fileBuffer = data;
     managedFilePath = name;
     fileUsage = FileUsage.UseMemory;
 }
示例#42
0
        /// <summary>
        /// Opens the specified book file.
        /// </summary>
        /// <param name="arena2">Arena2 path.</param>
        /// <param name="name">Name of book to open.</param>
        public bool OpenBook(string arena2, string name, FileUsage fileUsage = FileUsage.UseMemory, bool readOnly = true)
        {
            // Validate filename
            if (!name.StartsWith("BOK", StringComparison.InvariantCultureIgnoreCase) ||
                !name.EndsWith(".TXT", StringComparison.InvariantCultureIgnoreCase))
            {
                return false;
            }

            // Load book file
            string booksPath = Path.Combine(arena2, books);
            if (!bookFile.Load(Path.Combine(booksPath, name), fileUsage, readOnly))
                return false;

            // Read book
            ReadHeader();

            return true;
        }
        /// <summary>
        /// Opens a file from disk.
        /// </summary>
        /// <param name="filePath">Absolute path of file to load.</param>
        /// <param name="fileAccess">Defines access to file.</param>
        /// <param name="fileShare">Defines shared access to file.</param>
        /// <returns>True if successful, otherwise false.</returns>
        private bool LoadDisk(string filePath, FileAccess fileAccess, FileShare fileShare)
        {
            // File must exist
            if (!File.Exists(filePath))
                return false;

            // Open file
            try
            {
                fileStream = File.Open(filePath, FileMode.Open, fileAccess, fileShare);
                if (fileStream == null)
                    return false;
            }
            catch (Exception e)
            {
                myLastException = e;
                Console.WriteLine(e.Message);
                return false;
            }

            // Store filename
            managedFilePath = filePath;

            // Set usage
            fileUsage = FileUsage.UseDisk;

            return true;
        }
        /// <summary>
        /// Opens FALL.EXE file.
        /// </summary>
        /// <param name="fallExePath">Path to FALL.EXE file.</param>
        /// <param name="fileUsage">How to load file</param>
        /// <param name="readOnly">Open file read-only</param>
        /// <returns>True if successful.</returns>
        public bool OpenFallExeFile(string fallExePath, FileUsage fileUsage = FileUsage.UseMemory, bool readOnly = true)
        {
            isOpen = false;
            items.Clear();

            // Must be FALL.EXE
            if (string.Compare(Path.GetFileName(fallExePath), Filename, true) != 0)
                return false;

            // Open file
            if (!fallExeFile.Load(fallExePath, fileUsage, readOnly))
                return false;

            // Read file
            if (!ReadFallExeFile())
                return false;

            isOpen = true;

            return true;
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 public FileProxy()
 {
     fileUsage = FileUsage.Undefined;
 }
示例#46
0
 /// <summary>
 /// Implemented only to satisfy abstract base. Does nothing.
 /// </summary>
 /// <param name="FilePath">N/A</param>
 /// <param name="Usage">N/A</param>
 /// <param name="ReadOnly">N/A</param>
 /// <returns>Always true.</returns>
 public override bool Load(string FilePath, FileUsage Usage, bool ReadOnly)
 {
     return(true);
 }
示例#47
0
        /// <summary>
        /// Loads a texture file.
        /// </summary>
        /// <param name="filePath">Absolute path to TEXTURE.* file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
            {
                return(true);
            }

            // Validate filename
            filePath = filePath.ToUpper();
            string fn = Path.GetFileName(filePath);

            if (!fn.StartsWith("TEXTURE."))
            {
                return(false);
            }

            // Handle unsupported files
            if (!IsFilenameSupported(fn))
            {
                Console.WriteLine(string.Format("{0} is unsupported.", fn));
                return(false);
            }

            // Handle solid types
            if (fn == "TEXTURE.000")
            {
                solidType = SolidTypes.SolidColoursA;
            }
            else if (fn == "TEXTURE.001")
            {
                solidType = SolidTypes.SolidColoursB;
            }
            else
            {
                solidType = SolidTypes.None;
            }

            // Handle spectral types
            if (fn == "TEXTURE.273" || fn == "TEXTURE.278")
            {
                spectralType = SpectralTypes.Spectral;
            }
            else
            {
                spectralType = SpectralTypes.None;
            }

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
            {
                return(false);
            }

            // Read file
            if (!Read())
            {
                return(false);
            }

            return(true);
        }
示例#48
0
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to ARCH3D.BSA file.</param>
 /// <param name="usage">Determines if the BSA file will read from disk or memory.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public Arch3dFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
        /// <summary>
        /// Load BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Ensure filename ends with .BSA or .SND
            if (!filePath.EndsWith(".BSA", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith(".SND", StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load file into memory
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
        /// <summary>
        /// Loads a CIF or RCI file.
        /// </summary>
        /// <param name="filePath">Absolute path to *.CIF or *.RCI file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
                return true;

            // Validate filename
            if (!filePath.EndsWith(".CIF", StringComparison.InvariantCultureIgnoreCase) &&
                !filePath.EndsWith(".RCI", StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            // Read file
            if (!Read())
                return false;

            return true;
        }
 /// <summary>
 /// Assign byte array constructor.
 /// </summary>
 /// <param name="data">Byte array to assign (usage will be set to FileUsage.useMemory).</param>
 /// <param name="name">Name, filename, or path  to describe memory buffer.</param>
 public FileProxy(byte[] data, string name)
 {
     fileBuffer      = data;
     managedFilePath = name;
     fileUsage       = FileUsage.UseMemory;
 }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to *.CIF or *.RCI file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public CifRciFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public FileProxy(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
        /// <summary>
        /// Loads a SKY file.
        /// </summary>
        /// <param name="filePath">Absolute path to SKY??.DAT file</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Exit if this file already loaded
            if (managedFile.FilePath == filePath)
                return true;

            // Validate filename
            string fn = Path.GetFileName(filePath);
            if (!fn.StartsWith("SKY", StringComparison.InvariantCultureIgnoreCase) &&
                !fn.EndsWith(".DAT", StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            return true;
        }
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to WOODS.WLD.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public WoodsFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
        /// <summary>
        /// Load BLOCKS.BSA file.
        /// </summary>
        /// <param name="filePath">Absolute path to BLOCKS.BSA file.</param>
        /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
        /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
        /// <returns>True if successful, otherwise false.</returns>
        public bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            if (!filePath.EndsWith("BLOCKS.BSA", StringComparison.InvariantCultureIgnoreCase))
                return false;

            // Load file
            if (!bsaFile.Load(filePath, usage, readOnly))
                return false;

            // Create records array
            blocks = new BlockRecord[bsaFile.Count];

            return true;
        }
示例#57
0
 /// <summary>
 /// Load constructor that also loads a palette.
 /// Some IMG files contain palette information, this will overwrite the specified palette.
 /// </summary>
 /// <param name="filePath">Absolute path to *.IMG file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="paletteFilePath">Absolute path to Daggerfall palette file.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public ImgFile(string filePath, FileUsage usage, string paletteFilePath, bool readOnly)
 {
     LoadPalette(paletteFilePath);
     Load(filePath, usage, readOnly);
 }
示例#58
0
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to MONSTER.BSA.</param>
 /// <param name="usage">Determines if the BSA file will read from disk or memory.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public MonsterFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
示例#59
0
 /// <summary>
 /// Load constructor.
 /// </summary>
 /// <param name="filePath">Absolute path to *.CFA file.</param>
 /// <param name="usage">Specify if file will be accessed from disk, or loaded into RAM.</param>
 /// <param name="readOnly">File will be read-only if true, read-write if false.</param>
 public CfaFile(string filePath, FileUsage usage, bool readOnly)
 {
     Load(filePath, usage, readOnly);
 }
        public override bool Load(string filePath, FileUsage usage, bool readOnly)
        {
            // Validate filename
            string fn = Path.GetFileName(filePath);
            if (string.Compare(fn, Filename, true) != 0)
                return false;

            // Load file
            if (!managedFile.Load(filePath, usage, readOnly))
                return false;

            return true;
        }