forked from Terraonion-dev/GameDBManagerMD
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashes.cs
More file actions
120 lines (100 loc) · 2.86 KB
/
Copy pathHashes.cs
File metadata and controls
120 lines (100 loc) · 2.86 KB
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
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace GameDbManagerMega
{
public partial class Hashes : Form
{
public int gameID;
public GameDB gdb;
public Hashes()
{
InitializeComponent();
gameDB = gdb;
gameCkBindingSource.Filter = "GameID = " + gameID;
}
private void gameCkBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Hashes_Shown(object sender, EventArgs e)
{
gameDB = gdb;
gameCkBindingSource.DataSource = gdb;
gameCkBindingSource.Filter = "GameID = " + gameID;
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofn = new OpenFileDialog();
ofn.CheckPathExists = true;
ofn.Multiselect = false;
ofn.Filter = "ROM Files (*.bin,*.md,*.sms,*.32x,*.sg)|*.bin;*.md;*.sms;*.32x;*.sg|CDRom cuesheets (*.cue)|*.cue";
if (ofn.ShowDialog() == DialogResult.OK)
{
uint crc;
if (ofn.FileName.EndsWith(".bin", StringComparison.InvariantCultureIgnoreCase) ||
ofn.FileName.EndsWith(".md", StringComparison.InvariantCultureIgnoreCase) ||
ofn.FileName.EndsWith(".sms", StringComparison.InvariantCultureIgnoreCase) ||
ofn.FileName.EndsWith(".32x", StringComparison.InvariantCultureIgnoreCase) ||
ofn.FileName.EndsWith(".sg", StringComparison.InvariantCultureIgnoreCase)
)
{
byte[] data = File.ReadAllBytes(ofn.FileName);
if ((data.Length & 0xFFF) != 0)
{
uint l = (uint)data.Length & 0xFFFFF000;
byte[] dat = new byte[l];
Array.Copy(data, data.Length & 0xFFF, dat, 0, l);
data = dat;
crc = Crc32.Compute(data);
}
else
{
crc = Crc32.Compute(data);
}
}
else if (ofn.FileName.EndsWith(".cue", StringComparison.InvariantCultureIgnoreCase))
{
CueSheet cue = new CueSheet(ofn.FileName);
crc = GameDBMgr.ComputeCueCrc(cue);
}
else
{
MessageBox.Show("Invalid file extension");
return;
}
//Check if the crc already exists
string crcstr = crc.ToString("X8");
GameDB.GameCkRow ck = gameDB.GameCk.FirstOrDefault(x => x.Checksum == crcstr);
if (ck != null)
{
MessageBox.Show(ck.GameID == gameID
? "This checksum already exists for this game"
: "This checksum already exists for a different game!!");
}
else
{
ck = gameDB.GameCk.NewGameCkRow();
ck.GameID = gameID;
ck.Checksum = crcstr;
gameDB.GameCk.AddGameCkRow(ck);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewCell r in dataGridView1.SelectedCells)
{
string crc = (string)r.Value;
GameDB.GameCkRow ck = gameDB.GameCk.FirstOrDefault(x => x.Checksum == crc);
if (ck != null)
{
gameDB.GameCk.RemoveGameCkRow(ck);
}
}
}
}
}