Exemplo n.º 1
0
    /// <summary>
    /// Reads and dumps a memcard to disc
    /// </summary>
    /// <param name="inCard">0/1</param>
    public static bool Command_MemcardDownload(UInt32 inCard, string fileName)
    {
        if (!TransferLogic.ChallengeResponse(CommandMode.MCDOWN))
        {
            return(Error("No response from Unirom. Are you using 8.0.E or higher?"));
        }

        // send the card number
        activeSerial.Write(BitConverter.GetBytes(inCard), 0, 4);

        Console.WriteLine("Reading card to ram...");

        // it'll send this when it's done dumping to ram
        if (!TransferLogic.WaitResponse("MCRD", false))
        {
            return(Error("Please see screen or SIO for error!"));
        }

        Console.WriteLine("Ready, reading....");

        UInt32 addr = TransferLogic.read32();

        Console.WriteLine("Data is 0x" + addr.ToString("x"));

        UInt32 size = TransferLogic.read32();

        Console.WriteLine("Size is 0x" + size.ToString("x"));


        Console.WriteLine("Dumping...");

        byte[] lastReadBytes = new byte[size];
        TransferLogic.ReadBytes(addr, size, lastReadBytes);


        if (System.IO.File.Exists(fileName))
        {
            string newFilename = fileName + GetSpan().TotalSeconds.ToString();

            Console.Write("\n\nWARNING: Filename " + fileName + " already exists! - Dumping to " + newFilename + " instead!\n\n");

            fileName = newFilename;
        }

        try
        {
            File.WriteAllBytes(fileName, lastReadBytes);
        }
        catch (Exception e)
        {
            return(Error("Couldn't write to the output file + " + fileName + " !\nThe error returned was: " + e, false));
        }

        Console.WriteLine("File written to: " + fileName);
        Console.WriteLine("It is raw .mcd format used by PCSX-redux, no$psx, etc");
        return(true);
    }