Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GameGenieCodeForm.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6bccf9c02701c53a70a82db0fc227bda27ffebda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using com.clusterrr.hakchi_gui.Properties;
using com.clusterrr.Famicom;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.XPath;
using System.Xml;

namespace com.clusterrr.hakchi_gui
{
    public partial class GameGenieCodeForm : Form
    {
        private NesGame FGame;
        private string FDBName;
        private GameGenieDataBase FGameGenieDataBase;

        public GameGenieCodeForm(NesGame AGame)
        {
            InitializeComponent();
            FGame = AGame;
            FDBName = Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "data"), "GameGenieDB.xml");
            FGameGenieDataBase = new GameGenieDataBase(FDBName, FGame);
            this.Text = string.Format("Game Genie Code List : {0}", FGame.Name);
            LoadGameGenieCodes();
        }

        private void LoadGameGenieCodes()
        {
            checkedListBoxGameCode.Items.Clear();

            if (File.Exists(FDBName))
            {
                var lCodeSorted = FGameGenieDataBase.GameCodes.OrderBy(o => o.Description);
                var lSelectedCode = FGame.GameGenie.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var code in lCodeSorted)
                    checkedListBoxGameCode.Items.Add(code, lSelectedCode.Contains(code.Code));
            }
        }

        private void SaveSelectedCodes()
        {
            var selected = new List<string>();
            foreach (GameGenieCode code in checkedListBoxGameCode.CheckedItems)
                selected.Add(code.Code);
            FGame.GameGenie = string.Join(",", selected.ToArray());
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            SaveSelectedCodes();
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void GameGenieForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (FGameGenieDataBase.Modified)
                FGameGenieDataBase.Save();
        }

        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GameGenieCodeAddModForm lForm = new GameGenieCodeAddModForm();
            lForm.Game = FGame;

            if (lForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                GameGenieCode lCode = null;

                foreach(GameGenieCode Code in checkedListBoxGameCode.Items)
                {
                    if (Code.Code == lForm.Code)
                    {
                        lCode = Code;
                        break;
                    }
                }

                if (lCode != null)
                {
                    if (MessageBox.Show(this, "This code already exist do you want to edit it?", Resources.Warning, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        lCode.Description = lForm.Description;
                        FGameGenieDataBase.ModifyCode(lCode);
                    }
                }
                else
                {
                    GameGenieCode lNewCode = new GameGenieCode(lForm.Code, lForm.Description);
                    FGameGenieDataBase.AddCode(lNewCode);
                    LoadGameGenieCodes();
//                    checkedListBoxGameCode.Items.Add(lNewCode, false);
                }
            }
        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkedListBoxGameCode.SelectedItem != null)
            {
                GameGenieCode lCode = (GameGenieCode)checkedListBoxGameCode.SelectedItem;
                GameGenieCodeAddModForm lForm = new GameGenieCodeAddModForm();
                lForm.Code = lCode.Code;
                lForm.Description = lCode.Description;
                lForm.Game = FGame;

                if (lForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    lCode.Code = lForm.Code;
                    lCode.Description = lForm.Description;
                    FGameGenieDataBase.ModifyCode(lCode);
                }
            }
        }

        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((checkedListBoxGameCode.SelectedItem != null) &&
                (MessageBox.Show(this, "Do you want to delete this code?", Resources.AreYouSure, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes))
            {
                GameGenieCode lCode = (GameGenieCode)checkedListBoxGameCode.SelectedItem;
                FGameGenieDataBase.DeleteCode(lCode);
                checkedListBoxGameCode.Items.Remove(lCode);
            }
        }

        private void buttonImport_Click(object sender, EventArgs e)
        {
            if (ofdXmlFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                FGameGenieDataBase.ImportCodes(ofdXmlFile.FileName);
                LoadGameGenieCodes();
            }
        }
    }
}