public LoadOutsideRegionException(LoadRegion region, int fileIndex, uint offset)
     : base(string.Format("Attempted to load from file {0} to offset 0x{1:x} in region {2} of length 0x{3:x}", region.Files[fileIndex].Name, offset, region.Name, region.Length))
 {
     mRegion    = region;
     mFileIndex = fileIndex;
     mOffset    = offset;
 }
Ejemplo n.º 2
0
 public FillOutsideRegionException(LoadRegion region, int fillIndex, uint offset)
     : base(string.Format("Attempted to fill offset 0x{0:x} in region {1} of length 0x{2:x} with value 0x{3:x}", offset, region.Name, region.Length, region.Fills[fillIndex].Value))
 {
     mRegion    = region;
     mFillIndex = fillIndex;
     mOffset    = offset;
 }
Ejemplo n.º 3
0
        private void importButton_Click(object sender, EventArgs e)
        {
            Classes.CharLayout layout = Profile.CharLayouts[layoutBox.SelectedIndex];
            byte[]             data   = null;
            uint offset = ParseNumber(offsetBox.Text);
            uint count;

            try
            {
                if (regionBox.SelectedIndex == 0)                                       // "Flat file" selected
                {
                    data  = File.ReadAllBytes((string)fileGrid.Rows[0].Cells[3].Value); // Only one file to open.
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * data.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements((uint)data.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FileTooSmall,
                                displayCount,
                                offsetBox.Text,
                                data.Length,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FileTooSmall);
                        return;
                    }
                }
                else // Load from multiple ROMs
                {
                    Classes.LoadRegion region = Profile.LoadRegions[regionBox.SelectedIndex - 1];
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * region.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements(region.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_RegionTooSmall,
                                region.Name,
                                region.Length,
                                displayCount,
                                offsetBox.Text,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_RegionTooSmall);
                        return;
                    }
                    string[] paths = new string[fileGrid.Rows.Count];
                    for (int i = 0; i < paths.Length; i++)
                    {
                        paths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
                    }
                    data = region.LoadFiles(paths);
                }
            }
            catch (Classes.LoadPastEndOfFileException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_ReadPastFileEnd,
                        ex.File.Name,
                        ex.Instruction.Offset,
                        ex.Instruction.Size,
                        ex.Read),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_ReadPastFileEnd);
                return;
            }
            catch (Classes.LoadOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_LoadBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.File.Name),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_LoadBeyondRegionEnd);
                return;
            }
            catch (Classes.FillOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FillBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.Fill.Value),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FillBeyondRegionEnd);
                return;
            }
            catch
            {
                MessageBox.Show(Porno_Graphic.Properties.Resources.TileImporter_ErrorReadingFile);
                return;
            }

            Classes.GfxElement[] elements = new Classes.GfxElement[count];
            Parallel.For(0, count, index => { elements[index] = new Classes.GfxElement(data, layout, offset, (uint)index); });

            Classes.TileImportMetadata metadata = new Classes.TileImportMetadata();
            if (mProfilePath != null)
            {
                metadata.ProfileFile = mProfilePath;
            }
            //metadata.ProfileFile = Path.GetFileName(mProfilePath);
            metadata.ProfileName = mProfile.Name;
            //metadata.RegionName = (string)regionBox.SelectedItem;
            //metadata.LayoutName = (string)layoutBox.SelectedItem;
            if ((regionBox.SelectedIndex - 1) < 0)
            {
                metadata.RegionName = (string)regionBox.SelectedItem;
            }
            else
            {
                metadata.RegionName = mProfile.LoadRegions[regionBox.SelectedIndex - 1].Name;
            }
            metadata.LayoutName = mProfile.CharLayouts[layoutBox.SelectedIndex].Name;
            if (offsetBox.Text.StartsWith("0x"))
            {
                metadata.Offset = offsetBox.Text.Substring(2);
            }
            metadata.Planes = layout.Planes.ToString();

            string[] romPaths = new string[fileGrid.Rows.Count];
            for (int i = 0; i < romPaths.Length; i++)
            {
                romPaths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
            }
            metadata.RomFilenames = romPaths;
            Classes.GfxElementSet elementSet = new Classes.GfxElementSet();
            elementSet.Name           = "TestName";
            elementSet.ElementWidth   = layout.Width;
            elementSet.ElementHeight  = layout.Height;
            elementSet.Elements       = elements;
            elementSet.ImportMetadata = metadata;
            mParent.CreateImportProject(elementSet, (layout.Planes > 3) ? Classes.IndexedPalette.RGBI : Classes.IndexedPalette.RGB);
            Close();
        }