-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
103 lines (89 loc) · 2.73 KB
/
Form1.cs
File metadata and controls
103 lines (89 loc) · 2.73 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
namespace Nintenlord.UPSpatcher
{
public partial class PatchApplier
{
public PromptStyle prompt_style = PromptStyle.Notify;
// select rom
private void button3_Click()
{
}
// select .ups patch
private void button5_Click()
{
}
// patch file
public void button2_Click(string rom_path, string patch_path, string patched_rom_path)
{
UPSfile upsFile = new UPSfile(patch_path);
byte[] file = null;
try
{
BinaryReader br = new BinaryReader(File.Open(rom_path, FileMode.OpenOrCreate));
file = br.ReadBytes((int)br.BaseStream.Length);
br.Close();
}
catch (Exception)
{
throw new Exception("Error opening file\n" + rom_path);
}
if (!upsFile.ValidPatch)
{
throw new Exception("The patch is corrupt.");
}
bool validToApply = upsFile.ValidToApply(file);
if (prompt_style == PromptStyle.Abort)
{
if (!validToApply)
{
throw new Exception("The patch doesn't match the file.\nPatching canceled.");
}
}
else if (prompt_style == PromptStyle.Ask)
{
if (!validToApply)
{
throw new Exception("The patch doesn't match the file.\nPatching canceled.");
}
}
else if (prompt_style == PromptStyle.Notify)
{
if (!validToApply)
{
Console.WriteLine("The patch doesn't match the file.\nPatching anyway.");
}
}
else if (prompt_style != PromptStyle.Ignore)
{
throw new Exception("What do you want me to do!?!?!?");
}
byte[] newFile = upsFile.Apply(file);
try
{
File.WriteAllBytes(patched_rom_path, newFile);
}
catch (Exception)
{
throw new Exception("Error writing patch");
}
Console.WriteLine("Patching has been done.");
}
// close window
private void button1_Click()
{
}
}
public enum PromptStyle
{
Abort,
Ask,
Notify,
Ignore
}
}