Esempio n. 1
0
        /// <summary>
        /// Imports the specified file
        /// </summary>
        /// <param name="filePath">The file path to import from</param>
        /// <returns>The import data</returns>
        public ArchiveImportData ImportFile(FileSystemPath filePath)
        {
            // Return the import data
            return(new ArchiveImportData(FileData.FileEntryData, file =>
            {
                Archive.SetDisplayStatus(String.Format(Resources.Archive_ImportingFileStatus, FileName));

                // Get the file format
                var format = filePath.FileExtension;

                byte[] importBytes;

                // Convert the file if the format is not the native one
                if (format != NativeFileExtension)
                {
                    // Get the file bytes
                    var bytes = FileData.GetDecodedFileBytes(ArchiveFileStream, Archive.ArchiveFileGenerator, false);

                    // Open the file to import from
                    using var importFileStream = File.Open(filePath, FileMode.Open, FileAccess.Read);

                    // Create a memory stream for the bytes to encode
                    using var importStream = new MemoryStream();

                    // Convert the file
                    FileData.ConvertImportData(bytes, importFileStream, importStream, format);

                    importBytes = importStream.ToArray();
                }
                else
                {
                    // Read the file bytes to import from
                    importBytes = File.ReadAllBytes(filePath);
                }

                // Return the encoded file
                return Archive.Manager.EncodeFile(importBytes, file);
            }));
        }