-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
140 lines (122 loc) · 4.74 KB
/
Form1.cs
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
using Microsoft.Data.Sqlite;
using Newtonsoft.Json.Linq;
namespace Wuthering_Waves_Fps_Unlocker
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void connect_db(string dbPath)
{
string connectionString = $"Data Source={dbPath};";
using (SqliteConnection conn = new SqliteConnection(connectionString))
{
conn.Open();
// 查询 Key 为 GameQualitySetting 的行
string query = "SELECT Value FROM LocalStorage WHERE Key = 'GameQualitySetting';";
using (SqliteCommand command = new SqliteCommand(query, conn))
{
using (SqliteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string jsonData = reader.GetString(0);
//解析JSON
JObject jsonObj = JObject.Parse(jsonData);
//提取KeyCustomFrameRate的值
int? KeyCustomFrameRate = jsonObj.Value<int?>("KeyCustomFrameRate");
if (KeyCustomFrameRate.HasValue)
{
textBox2.Text = KeyCustomFrameRate.Value.ToString();
}
}
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new()
{
Title = "请选择",
Filter = "数据库文件 (*.db)|*.db|所有文件 (*.*)|*.*"
};
//显示对话框并检查是否选择了文件
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//获取文件路径
string filePath = openFileDialog.FileName;
//将文件路径显示在文本框中
textBox1.Text = filePath;
connect_db(filePath);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("请先选择数据库文件");
return;
}
//如果帧率为空,提示用户输入
if (textBox2.Text == "")
{
MessageBox.Show("请输入帧率!");
return;
}
//如果帧率不是数字,提示用户输入数字
if (!int.TryParse(textBox2.Text, out _))
{
MessageBox.Show("请输入数字!");
return;
}
//如果帧率不在1-120之间,提示用户输入1-120之间的数字
if (int.Parse(textBox2.Text) < 1 || int.Parse(textBox2.Text) > 120)
{
MessageBox.Show("请输入1-120之间的数字!");
return;
}
//修改数据库的值,只修改KeyCustomFrameRate的值JSON别的不动
string connectionString = $"Data Source={textBox1.Text};";
using (SqliteConnection conn = new SqliteConnection(connectionString))
{
conn.Open();
string query = "SELECT Value FROM LocalStorage WHERE Key = 'GameQualitySetting';";
using (SqliteCommand command = new SqliteCommand(query, conn))
{
using (SqliteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
string jsonData = reader.GetString(0);
JObject jsonObj = JObject.Parse(jsonData);
jsonObj["KeyCustomFrameRate"] = int.Parse(textBox2.Text);
string newJsonData = jsonObj.ToString();
//更新数据库
string update = $"UPDATE LocalStorage SET Value = '{newJsonData}' WHERE Key = 'GameQualitySetting';";
using (SqliteCommand updateCommand = new SqliteCommand(update, conn))
{
updateCommand.ExecuteNonQuery();
}
MessageBox.Show("修改成功!请打开游戏查看!");
}
}
}
}
}
private void label4_Click(object sender, EventArgs e)
{
}
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
}
private void label4_Click_1(object sender, EventArgs e)
{
}
}
}