Exemplo n.º 1
0
    public DiscInfo[] GetDiscInfo(long gameId)
    {
        var ret        = new List <DiscInfo>();
        int discNumber = 1;

        foreach (string fname in GameManager.getInstance().GetDiscFileNames(gameId))
        {
            DiscInfo inf = new DiscInfo();
            inf.BASENAME    = fname;
            inf.DISC_NUMBER = discNumber;
            inf.GAME_ID     = gameId;
            discNumber++;
            ret.Add(inf);
        }

        return(ret.ToArray());
    }
Exemplo n.º 2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int maxdisc = Convert.ToInt32(comboBox1.Text);

            movecount = 0;
            algorithm_steps.Clear();
            for (int i = maxdisc; i >= 1; i--)
            {
                A.Push(i);
            }
            countA = A.Count;
            countB = B.Count;
            countC = C.Count;
            PrintStacks();
            LosTVHop(maxdisc, A, B, C);

            DiscInfo d1 = new DiscInfo(40, 25, Color.Green, 1);
            DiscInfo d2 = new DiscInfo(60, 30, Color.Blue, 2);
            DiscInfo d3 = new DiscInfo(80, 35, Color.YellowGreen, 3);
            DiscInfo d4 = new DiscInfo(100, 40, Color.Red, 4);
            DiscInfo d5 = new DiscInfo(120, 45, Color.Violet, 5);
            DiscInfo d6 = new DiscInfo(140, 50, Color.Purple, 6);
            DiscInfo d7 = new DiscInfo(160, 55, Color.OrangeRed, 7);
            DiscInfo d8 = new DiscInfo(180, 60, Color.Khaki, 8);
            DiscInfo d9 = new DiscInfo(200, 65, Color.Khaki, 9);

            DiscInfo[] arrDiscs = { d1, d2, d3, d4, d5, d6, d7, d8, d9 };

            towerA.Clear();
            towerB.Clear();
            towerC.Clear();
            for (int i = maxdisc - 1; i >= 0; i--)
            {
                towerA.Push(arrDiscs[i]);
            }
            currentStep   = 0;
            textBox1.Text = currentStep.ToString() + "Out of" + algorithm_steps.Count.ToString();
            Invalidate();
        }
Exemplo n.º 3
0
        protected void WriteDisc(Stream outputStream, DiscInfo disc, uint psarOffset, bool isMultiDisc, CancellationToken cancellationToken)
        {
            var isoPosition = outputStream.Position - psarOffset;

            var  t             = new FileInfo(disc.SourceIso);
            var  isoSize       = (uint)t.Length;
            var  actualIsoSize = isoSize;
            uint curSize;
            uint totSize;
            uint p1_offset = 0;
            uint p2_offset = 0;

            // align isoSize with block boundary
            if ((isoSize % BLOCK_SIZE) != 0)
            {
                isoSize = isoSize + (BLOCK_SIZE - (isoSize % BLOCK_SIZE));
            }

            uint x;

            Notify?.Invoke(PopstationEventEnum.WriteIsoHeader, null);

            // Write DATA.PSAR
            outputStream.Write("PSISOIMG0000", 0, 12);

            if (isMultiDisc)
            {
                outputStream.WriteInt32(0, 0xFD);
            }
            else
            {
                p1_offset = (uint)outputStream.Position;
                outputStream.WriteUInt32(isoSize + 0x100000, 1);
                outputStream.WriteInt32(0, 0xFC);
            }

            // Overlay the GameID onto the data1 template
            var titleBytes = Encoding.ASCII.GetBytes(disc.GameID);

            Array.Copy(titleBytes, 0, Popstation.data1, 1, 4);
            Array.Copy(titleBytes, 4, Popstation.data1, 6, 5);

            if (disc.TocData == null || disc.TocData.Length == 0)
            {
                throw new Exception("Invalid TOC");
            }

            Notify?.Invoke(PopstationEventEnum.WriteTOC, null);

            // Overlay the TOC data onto the data1 template
            Array.Copy(disc.TocData, 0, Popstation.data1, 1024, disc.TocData.Length);

            outputStream.Write(Popstation.data1, 0, Popstation.data1.Length);

            if (isMultiDisc)
            {
                outputStream.WriteInt32(0, 1);
            }
            else
            {
                p2_offset = (uint)outputStream.Position;
                outputStream.WriteUInt32(isoSize + 0x100000 + 0x2d31, 1);
            }

            // Overlay the title onto the data2 template
            titleBytes = Encoding.ASCII.GetBytes(disc.GameTitle);
            Array.Copy(titleBytes, 0, Popstation.data2, 8, disc.GameTitle.Length);
            outputStream.Write(Popstation.data2, 0, Popstation.data2.Length);

            var index_offset = (uint)outputStream.Position;

            //Notify?.Invoke(PopstationEventEnum.WriteIndex, null);

            //memset(dummy, 0, sizeof(dummy));

            uint offset = 0;


            if (convertInfo.CompressionLevel == 0)
            {
                x = BLOCK_SIZE;
            }
            else
            {
                x = 0;
            }

            var dummy = new uint[6];

            for (var i = 0; i < isoSize / BLOCK_SIZE; i++)
            {
                outputStream.WriteUInt32(offset, 1);
                outputStream.WriteUInt32(x, 1);
                outputStream.Write(dummy, 0, sizeof(uint) * dummy.Length);

                if (convertInfo.CompressionLevel == 0)
                {
                    offset += BLOCK_SIZE;
                }
            }

            offset = (uint)outputStream.Position;

            for (var i = 0; i < (isoPosition + psarOffset + 0x100000) - offset; i++)
            {
                outputStream.WriteByte(0);
            }

            //Console.WriteLine("Writing iso #%d (%s)...\n", ciso + 1, inputs[ciso]);
            curSize = 0;
            totSize = 0;

            Notify?.Invoke(PopstationEventEnum.WriteIso, null);
            Notify?.Invoke(PopstationEventEnum.WriteSize, disc.IsoSize);

            using (var inputStream = new FileStream(disc.SourceIso, FileMode.Open, FileAccess.Read))
            {
                if (convertInfo.CompressionLevel == 0)
                {
                    // 1MB buffer
                    byte[] buffer = new byte[BUFFER_SIZE];
                    uint   bytesRead;

                    while ((bytesRead = (uint)inputStream.Read(buffer, 0, BUFFER_SIZE)) > 0)
                    {
                        outputStream.Write(buffer, 0, (int)bytesRead);
                        totSize += bytesRead;
                        curSize += bytesRead;
                        // PostMessage(convertInfo.callback, WM_CONVERT_PROGRESS, 0, totSize);
                        Notify?.Invoke(PopstationEventEnum.ConvertProgress, curSize);

                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }
                    }

                    for (var i = 0; i < (isoSize - actualIsoSize); i++)
                    {
                        outputStream.WriteByte(0);
                    }
                }
                else
                {
                    var indexes = new IsoIndex[(isoSize / BLOCK_SIZE)];

                    var i = 0;
                    offset = 0;
                    uint   bytesRead;
                    byte[] buffer2 = new byte[BLOCK_SIZE];
                    byte[] buffer  = new byte[BUFFER_SIZE];

                    while ((bytesRead = (uint)inputStream.Read(buffer2, 0, BLOCK_SIZE)) > 0)
                    {
                        totSize += bytesRead;
                        curSize += bytesRead;

                        if (bytesRead < BLOCK_SIZE)
                        {
                            // Clear out the rest of the buffer if we didn't read enough
                            for (var j = 0; j < BLOCK_SIZE - bytesRead; j++)
                            {
                                buffer2[j + bytesRead] = 0;
                            }
                        }

                        var bufferSize = (uint)Compression.Compress(buffer2, buffer, convertInfo.CompressionLevel);

                        bytesRead = bufferSize;

                        indexes[i]        = new IsoIndex();
                        indexes[i].Offset = offset;

                        if (bytesRead >= BLOCK_SIZE) /* Block didn't compress */
                        {
                            indexes[i].Length = BLOCK_SIZE;
                            outputStream.Write(buffer2, 0, BLOCK_SIZE);
                            offset += BLOCK_SIZE;
                        }
                        else
                        {
                            indexes[i].Length = bytesRead;
                            outputStream.Write(buffer, 0, (int)bytesRead);
                            offset += bytesRead;
                        }

                        Notify?.Invoke(PopstationEventEnum.WriteProgress, curSize);

                        if (cancellationToken.IsCancellationRequested)
                        {
                            return;
                        }

                        i++;
                    }

                    if (i != (isoSize / BLOCK_SIZE))
                    {
                        throw new Exception("Some error happened.\n");
                    }

                    offset = (uint)outputStream.Position;

                    uint end_offset = 0;

                    if (!isMultiDisc)
                    {
                        if ((offset % 0x10) != 0)
                        {
                            end_offset = offset + (0x10 - (offset % 0x10));

                            for (var block = 0; block < (end_offset - offset); block++)
                            {
                                outputStream.Write('0');
                            }
                        }
                        else
                        {
                            end_offset = offset;
                        }

                        end_offset -= psarOffset;
                    }

                    offset = (uint)outputStream.Position;

                    //Console.WriteLine($"Updating compressed indexes (iso {ciso + 1})...");
                    Notify?.Invoke(PopstationEventEnum.UpdateIndex, null);


                    if (!isMultiDisc)
                    {
                        outputStream.Seek(p1_offset, SeekOrigin.Begin);
                        outputStream.WriteUInt32(end_offset, 1);

                        end_offset += 0x2d31;
                        outputStream.Seek(p2_offset, SeekOrigin.Begin);
                        outputStream.WriteUInt32(end_offset, 1);
                    }

                    outputStream.Seek(index_offset, SeekOrigin.Begin);
                    outputStream.Write(indexes, 0, (int)(4 + 4 + (6 * 4) * (isoSize / BLOCK_SIZE)));

                    outputStream.Seek(offset, SeekOrigin.Begin);
                }
            }
        }