Exemplo n.º 1
0
        private MainFormInfo GetMainInfo()       //2017-01-24
        {
            MainFormInfo mfiTemp = new MainFormInfo
                                   (
                cboMode.SelectedIndex,
                cboOutputSize.SelectedIndex,
                txtSavePath.Text + txtInput.Text,       //2017-01-24
                txtSavePath.Text + txtOutput.Text,      //2017-01-24
                txtM3LongName.Text,
                txtM3ShortName.Text,
                dialogOpenROM.FileName,
                CardTypeInfo[cboMode.SelectedIndex][cboOutputFormat.SelectedIndex].CardIs,
                chkM3DatFile.Checked,
                chkPokemon.Checked
                                   );

            return(mfiTemp);
        }
Exemplo n.º 2
0
        private void StartChange()                                                // 判断源存档格式,选取不同的转换方式
        {
            MainFormInfo  mfiMainInfo = GetMainInfo();                            // 获取主界面信息
            InputFileInfo ifiFileMode = new InputFileInfo(mfiMainInfo.InputName); // 获取源存档信息

            if (ifiFileMode.ErrorCode == null)
            {
                myAllControl(false);
                if (mfiMainInfo.PokemonChecked)
                {
                    ShowMessage(MyLanguge.Message.Pokemon + "\n");    //口袋妖怪强制转换:
                    string[] temp = WriteData.PokemonChange(ifiFileMode, mfiMainInfo.OutputName);
                    if (temp[0] == null)
                    {
                        ShowPokemonMessage(temp);
                    }
                    else
                    {
                        ShowErrorMessage(temp[0]);
                    }
                }
                else
                {
                    string[] temp = WriteData.MainChange(ifiFileMode, mfiMainInfo, UsedSize);
                    if (temp[0] == null)
                    {
                        ShowMainMessage(temp);
                    }
                    else
                    {
                        ShowErrorMessage(temp[0]);
                    }
                }
                myAllControl(true);
            }
            else
            {
                ShowErrorMessage(ifiFileMode.ErrorCode); //读取源存档时出现错误
            }
        }
Exemplo n.º 3
0
        public static string[] MainChange(InputFileInfo ifiFileMode, MainFormInfo mfiMainInfo, int[] UsedSize)
        {
            //分析源文件,分情况转换
            string[] sReturnStr      = new string[6];
            int      iOutputLenghAdd = new int();                   // 转换后文件附加部分大小
            bool     IsM3Gba1MB      = false;                       // 标记:目标为1M byte大小的M3格式的GBA存档
            int      iOutputLengh    = UsedSize[mfiMainInfo.Size];  // 转换后文件大小(无附加部分)
            int      InputFileSize   = ifiFileMode.Buffer.Length;

            // M3 GBA 1M byte的三个条件:目标大小为1M byte;目标格式为M3;GBA模式。此时,只读取前128K数据
            if ((iOutputLengh == 1024 * 1024) && (mfiMainInfo.CardIs == 1) && (mfiMainInfo.Mode == 1))
            {
                iOutputLengh = 128 * 1024;
                IsM3Gba1MB   = true;
            }

            int CopyFileSize = InputFileSize > iOutputLengh ? iOutputLengh : InputFileSize;

            //将源文件数据写入目标文件
            try
            {
                FileStream   sro = new FileStream(mfiMainInfo.OutputName, FileMode.Create);
                BinaryWriter w   = new BinaryWriter(sro);

                // 写入正常部分
                w.Write(ifiFileMode.Buffer, 0, CopyFileSize);

                // 把目标文件用0xff补全到需要的大小
                for (int i = CopyFileSize; i < iOutputLengh; i++)
                {
                    sro.WriteByte(0xff);
                }

                //	写入M3和DSLINK的附加部分
                if (mfiMainInfo.CardIs == 1)           // 目标存档为M3格式(CardIs=1)时,附加1K
                {
                    iOutputLenghAdd = 1024;

                    if (mfiMainInfo.M3DatChecked)
                    {
                        sReturnStr[0] = WriteData.M3AddingDAT(mfiMainInfo.M3FileName, sro, mfiMainInfo.Mode, IsM3Gba1MB);
                    }
                    else
                    {
                        sReturnStr[0] = WriteData.M3Adding(mfiMainInfo.M3ShortName, mfiMainInfo.M3LongName, sro, mfiMainInfo.Mode, IsM3Gba1MB);
                    }
                }
                else if (mfiMainInfo.CardIs == 2)      // 目标存档为DSLink格式(CardIs=2)时,附加8K
                {
                    iOutputLenghAdd = 8 * 1024;
                    sReturnStr[0]   = WriteData.DSLinkAdding(ifiFileMode, sro);
                }
                else if (mfiMainInfo.CardIs == 3)      // 目标存档为DeSmuME模拟器的dsv格式(CardIs=3)时,附加122字节
                {
                    iOutputLenghAdd = 122;
                    sReturnStr[0]   = WriteData.DeSmuMEAdding(CopyFileSize, sro);
                }
                sro.Close();

                int iTemp = iOutputLengh + iOutputLenghAdd;

                sReturnStr[1] = ifiFileMode.InputFileMode;
                sReturnStr[2] = ifiFileMode.InputFileLength.ToString();
                sReturnStr[3] = ifiFileMode.Buffer.Length.ToString();
                sReturnStr[4] = iTemp.ToString();
                sReturnStr[5] = IsM3Gba1MB.ToString();
            }
            catch
            {
                sReturnStr[0] = "ED001";
            }

            if (ifiFileMode.InputFileMode == "UnKnown")
            {
                sReturnStr[0] = "ED002";
            }

            return(sReturnStr);
        }