示例#1
0
        public static void ExportFiles(ICollection <FileEntry> entries)
        {
            string selectedFolder = GUI.FolderSelection();

            if (selectedFolder != null)
            {
                ProgressWindow progress = new ProgressWindow("Exporting", report =>
                {
                    int passed = 0;
                    report     = new SubProgressReport(report, entries.Sum(entry => entry.Data.GetSize()));
                    foreach (FileEntry entry in entries)
                    {
                        entry.Export(selectedFolder, new SubProgressReport(report, passed, entry.Data.GetSize()));
                        passed += entry.Data.GetSize();
                    }
                }, true);
                try
                {
                    progress.Run();
                }
                catch (OperationCanceledException)
                {
                    MessageBox.Show("Operation canceled.");
                }
            }
        }
示例#2
0
        public static void ExportAWCs(List <FileEntry> entries)
        {
            string selectedFolder = GUI.FolderSelection();

            if (selectedFolder != null)
            {
                ProgressWindow progress = new ProgressWindow("Exporting", report =>
                {
                    int passed = 0;
                    // Set the progress by the size of the file
                    report = new SubProgressReport(report, entries.Sum(entry => entry.Data.GetSize()));
                    foreach (FileEntry entry in entries)
                    {
                        using (AWCFile awc = new AWCFile(entry.Data.GetStream()))
                        {
                            awc.ExportWav(Path.Combine(selectedFolder, entry.Name), new SubProgressReport(report, passed, entry.Data.GetSize()));
                            passed += entry.Data.GetSize();
                        }
                    }
                }, true);
                try
                {
                    progress.Run();
                }
                catch (OperationCanceledException)
                {
                    MessageBox.Show("Operation canceled.");
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to open AWC, please report to the developer");
                }
            }
        }
示例#3
0
        public override void Export(String foldername, IProgressReport progress = null)
        {
            long passed = 0;

            if (progress != null)
            {
                progress = new SubProgressReport(progress, this.GetEntriesSize());
            }
            String subfolder = Path.Combine(foldername, this.Name);

            Directory.CreateDirectory(subfolder);
            foreach (Entry entry in this.Entries.Values)
            {
                entry.Export(subfolder, progress == null ? null : new SubProgressReport(progress, passed, entry is FileEntry ? ((FileEntry)entry).Data.GetSize() : ((DirectoryEntry)entry).GetEntriesSize()));
                if (progress != null)
                {
                    passed += entry is FileEntry ? ((FileEntry)entry).Data.GetSize() : ((DirectoryEntry)entry).GetEntriesSize();
                }
            }
        }
示例#4
0
        public void ExportWav(string baseName, IProgressReport progress = null)
        {
            int bytesWrote = 0;

            if (MultiChannel)
            {
                /*using (Stream file = File.Create(baseName + ".wav"))
                 * {
                 *  ExportWav(AudioStreams[0], file);
                 * }*/
                if (progress != null)
                {
                    // Calculate how many bytes are going to be written
                    progress = new SubProgressReport(progress, (((MultiChannelAudio)AudioStreams[0]).Channels.Sum(audio => audio.GetSize())));
                }
                for (int i = 0; i < ((MultiChannelAudio)AudioStreams[0]).Channels.Count; ++i)
                {
                    using (Stream file = File.Create(baseName + "." + AudioIds[i] + ".wav"))
                    {
                        if (progress != null)
                        {
                            progress.SetMessage("Decoding " + AudioIds[i]);
                        }
                        int audioSize = ((MultiChannelAudio)AudioStreams[0]).Channels[i].GetSize();
                        try
                        {
                            ExportWav(((MultiChannelAudio)AudioStreams[0]).Channels[i], file, progress == null ? null : new SubProgressReport(progress, bytesWrote, audioSize));
                        }
                        catch (Exception e)
                        {
                            file.Close();
                            // Delete uncompleted file
                            File.Delete(baseName + "." + AudioIds[i] + ".wav");
                            throw e;
                        }
                        bytesWrote += audioSize;
                    }
                }
            }
            else
            {
                for (int i = 0; i < AudioStreams.Count; ++i)
                {
                    if (progress != null)
                    {
                        // Calculate how many bytes are going to be written
                        progress = new SubProgressReport(progress, AudioStreams.Sum(audio => audio.GetSize()));
                    }
                    using (Stream file = File.Create(baseName + "." + AudioIds[i] + ".wav"))
                    {
                        if (progress != null)
                        {
                            progress.SetMessage("Decoding " + AudioIds[i]);
                        }
                        int audioSize = AudioStreams[i].GetSize();
                        try
                        {
                            ExportWav(AudioStreams[i], file, progress == null ? null : new SubProgressReport(progress, bytesWrote, audioSize));
                        }
                        catch (OperationCanceledException e)
                        {
                            file.Close();
                            // Delete uncompleted file
                            File.Delete(baseName + "." + AudioIds[i] + ".wav");
                            throw e;
                        }
                        bytesWrote += audioSize;
                    }
                }
            }
        }
示例#5
0
        public override void Export(String foldername, IProgressReport progress = null)
        {
            string filename;

            if (Directory.Exists(foldername))
            {
                filename = Path.Combine(foldername, this.Name);
            }
            else
            {
                filename = foldername;
            }

            if (progress != null)
            {
                progress.SetMessage("Extracting " + this.Name + ".");
            }

            switch (Properties.Settings.Default.ExportResourcesChoice)
            {
            case Settings.ExportResourcesChoice.RSC7:
            {
                using (FileStream file = File.Create(filename))
                {
                    using (BinaryWriter writer = new BinaryWriter(new StreamKeeper(file)))
                    {
                        // big endian resource 7 for now
                        writer.Write("RSC7".ToArray());
                        writer.Write(Structs.SwapEndian((uint)this.Version));
                        writer.Write(Structs.SwapEndian(this.SystemFlag));
                        writer.Write(Structs.SwapEndian(this.GraphicsFlag));
                    }

                    using (Stream stream = this.Data.GetStream())
                    {
                        stream.CopyToCount(file, this.Data.GetSize(), progress);
                    }
                }
                break;
            }

            case Settings.ExportResourcesChoice.SYSGFX:
            {
                if (progress != null)
                {
                    progress = new SubProgressReport(progress, (int)(this.SystemSize + this.GraphicsFlag));
                }
                using (Stream stream = this.Data.GetStream())
                {
                    // If there is no graphics information, no need to extract into two files
                    string sysExtension = this.GraphicSize == 0 ? "" : ".sys";
                    if (this.SystemSize != 0)
                    {
                        using (FileStream file = File.Create(filename + sysExtension))
                        {
                            stream.CopyToCount(file, this.SystemSize, progress == null ? null : new SubProgressReport(progress, 0, this.SystemSize));
                        }
                    }

                    if (this.GraphicSize != 0)
                    {
                        using (FileStream file = File.Create(filename + ".gfx"))
                        {
                            stream.CopyToCount(file, this.GraphicSize, progress == null ? null : new SubProgressReport(progress, this.SystemSize, (int)(this.SystemSize + this.GraphicsFlag)));
                        }
                    }
                }
                break;
            }

            case Settings.ExportResourcesChoice.RAW:
            {
                using (FileStream file = File.Create(filename))
                {
                    // Well, it isn't REALLY raw. We are rewriting it, so of the regular random-header, there are zeros,
                    //but it is close enough, that information is random anyway
                    this.Write(file);
                    if (progress != null)
                    {
                        progress.SetProgress(progress.GetFullValue());
                    }
                }
                break;
            }
            }
        }
示例#6
0
        private void WriteData(Stream stream, List <Entry> entries, Dictionary <Entry, Structs.RPF7EntryInfoTemplate> entriesInfo, IProgressReport progressReport = null)
        {
            if (progressReport != null)
            {
                progressReport = new SubProgressReport(progressReport, entries.Sum(entry => (entry is FileEntry ? ((FileEntry)entry).Data.GetSize() : 0L)));
            }

            long passed = 0;

            // Write data and fill entry info
            foreach (Entry entry in entries)
            {
                if (progressReport != null && progressReport.IsCanceled())
                {
                    throw new OperationCanceledException();
                }
                if (entry is FileEntry)
                {
                    if (progressReport != null)
                    {
                        progressReport.SetMessage(String.Format("Writing file {0}.", entry.Name));
                    }
                    long entryOffset = stream.Position;
                    (entry as FileEntry).Write(stream);
                    int entrySize = (int)(stream.Position - entryOffset);
                    // align to 0x200
                    if (stream.Position % (1 << 9) != 0)
                    {
                        stream.Write(new byte[(1 << 9) - ((int)stream.Position % (1 << 9))], 0, (1 << 9) - ((int)stream.Position % (1 << 9)));
                    }

                    // Update the entry offset and entry size
                    Structs.RPF7EntryInfoTemplate entryInfo = entriesInfo[entry];
                    entryInfo.Field2 = (uint)((entryOffset >> 9) & 0x7FFFFF);

                    if (entry is ResourceEntry)
                    {
                        entryInfo.Field3 = (uint)entrySize & 0xFFFFFF;
                        entryInfo.Field5 = (entry as ResourceEntry).SystemFlag;
                        entryInfo.Field6 = (entry as ResourceEntry).GraphicsFlag;
                    }
                    else if (entry is RegularFileEntry)
                    {
                        if ((entry as RegularFileEntry).Compressed)
                        {
                            // The compressed size
                            entryInfo.Field3 = (uint)entrySize & 0xFFFFFF;
                            // The uncompress size
                            entryInfo.Field5 = (uint)(entry as RegularFileEntry).Data.GetSize();
                            // The is encrypted flag
                            entryInfo.Field6 = 1;
                        }
                        else
                        {
                            entryInfo.Field3 = 0;
                            entryInfo.Field5 = (uint)entrySize;
                            // The is encrypted flag
                            entryInfo.Field6 = 0;
                        }
                    }

                    entriesInfo[entry] = entryInfo;

                    if (progressReport != null)
                    {
                        passed += (entry as FileEntry).Data.GetSize();
                        progressReport.SetProgress(passed);
                    }
                }
                else
                {
                    Structs.RPF7EntryInfoTemplate entryInfo = entriesInfo[entry];
                    // The offset is "-1" in case of file
                    entryInfo.Field2   = 0x7FFFFF;
                    entriesInfo[entry] = entryInfo;
                }
            }
        }