private void BackupList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.BackupList.SelectedIndex < 0 || this.BackupList.SelectedIndex >= this.FindBackup.Files.Count)
     {
         return;
     }
     FindBackup.FileInfo fi = this.FindBackup.Files[this.BackupList.SelectedIndex];
     this.ThisFileInfo.Text = R._("ファイル名:\r\n{0}\r\n\r\n更新日付:\r\n{1}", fi.FilePath, fi.Date.ToLocalTime());
 }
 bool CopyToEmu(FindBackup.FileInfo fi, string emulator_filename)
 {
     byte[] bin = MainFormUtil.OpenROMToByte(fi.FilePath, this.OrignalFilename.Text);
     if (bin.Length <= 0)
     {
         return(false);
     }
     U.WriteAllBytes(emulator_filename, bin);
     return(true);
 }
        private void BackupList_DoubleClick(object sender, EventArgs e)
        {
            if (this.BackupList.SelectedIndex < 0 || this.BackupList.SelectedIndex >= this.FindBackup.Files.Count)
            {
                return;
            }
            FindBackup.FileInfo fi = this.FindBackup.Files[this.BackupList.SelectedIndex];
            if (!CheckOrignalROMIfUPS(fi))
            {
                return;
            }

            string run_name          = "emulator";
            string emulator_filename = U.MakeFilename(run_name);

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                bool r = CopyToEmu(fi, emulator_filename);
                if (!r)
                {
                    return;
                }
            }

            if (!File.Exists(emulator_filename))
            {
                R.ShowStopError("エミュレータにロードするROMを作れませんでした。\r\n{0}", emulator_filename);
                return;
            }

            //セーブファイルが壊されるかもしれないので保存しよう.
            string saveFile = MainFormUtil.FindCurrentSavFilename(Program.ROM.Filename);

            byte[] saveFileBin = null;
            if (File.Exists(saveFile))
            {
                saveFileBin = File.ReadAllBytes(saveFile);
            }

            Process process = MainFormUtil.RunAs(run_name, emulator_filename);

            if (process == null)
            {
                return;
            }
            process.Exited += (ss, ee) => {
                //エミュレータが終了したら、保存していたセーブファイルを書き戻す.
                if (saveFile != "" && saveFileBin != null)
                {
                    U.WriteAllBytes(saveFile, saveFileBin);
                }
            };
        }
        bool CheckOrignalROMIfUPS(FindBackup.FileInfo fi)
        {
            string ext = U.GetFilenameExt(fi.FilePath);

            if (ext == ".UPS")
            {
                string errorMessage = MainFormUtil.CheckOrignalROM(OrignalFilename.Text);
                if (errorMessage != "")
                {
                    R.ShowStopError(errorMessage);
                    OrignalFilename.ErrorMessage = R._(errorMessage);
                    return(false);
                }
                OrignalFilename.ErrorMessage = "";
            }
            return(true);
        }
        private void SelectROMButton_Click(object sender, EventArgs e)
        {
            if (this.BackupList.SelectedIndex < 0 || this.BackupList.SelectedIndex >= this.FindBackup.Files.Count)
            {
                return;
            }
            FindBackup.FileInfo ng_rom_info;
            FindBackup.FileInfo ok_rom_info;
            if (this.BackupList.SelectedIndex < 1)
            {
                //R.ShowOK("直前のバックアップだと、現在のROMとの2点DIFFだけとなり、精度が落ちます。");

                ng_rom_info          = new FindBackup.FileInfo();
                ng_rom_info.FilePath = Program.ROM.Filename;
                ng_rom_info.Date     = File.GetLastWriteTime(Program.ROM.Filename);
                if (!CheckOrignalROMIfUPS(ng_rom_info))
                {
                    return;
                }

                ok_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex];
                if (!CheckOrignalROMIfUPS(ok_rom_info))
                {
                    return;
                }
            }
            else
            {
                ng_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex - 1];
                if (!CheckOrignalROMIfUPS(ng_rom_info))
                {
                    return;
                }

                ok_rom_info = this.FindBackup.Files[this.BackupList.SelectedIndex];
                if (!CheckOrignalROMIfUPS(ok_rom_info))
                {
                    return;
                }
            }


            ToolDiffDebugSelectMethodPopup q = (ToolDiffDebugSelectMethodPopup)InputFormRef.JumpFormLow <ToolDiffDebugSelectMethodPopup>();

            q.Init(ng_rom_info.FilePath, ok_rom_info.FilePath);
            q.ShowDialog();
            if (q.DialogResult != System.Windows.Forms.DialogResult.Yes)
            {//ユーザーキャンセル.
                return;
            }
            ToolThreeMargeForm.DiffDebugMethod method = q.GetMethod();

            ToolThreeMargeForm f;

            using (InputFormRef.AutoPleaseWait wait = new InputFormRef.AutoPleaseWait(this))
            {
                byte[] ng_rom = MainFormUtil.OpenROMToByte(ng_rom_info.FilePath, this.OrignalFilename.Text);
                byte[] ok_rom = MainFormUtil.OpenROMToByte(ok_rom_info.FilePath, this.OrignalFilename.Text);

                if (ng_rom.Length <= 0)
                {
                    return;
                }
                if (ok_rom.Length <= 0)
                {
                    return;
                }

                f = (ToolThreeMargeForm)InputFormRef.JumpFormLow <ToolThreeMargeForm>();
                f.InitDiffDebug(wait, ok_rom, ng_rom, method);
            }
            if (!f.IsConflictData())
            {
                R.ShowWarning("相違点がありません。\r\n比較条件を変えてください。\r\n比較条件を変えても変わらない場合、比較対象のROMを見直してください。");
                return;
            }
            f.Show();
        }