8000 新增了Replay重命名工具(注意需要对应修改PYHHelper中P1名的Index · hxdnshx/PYHHelper@cf0af33 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf0af33

Browse files
committed
新增了Replay重命名工具(注意需要对应修改PYHHelper中P1名的Index
1 parent c68d0ec commit cf0af33

13 files changed

+756
-1
lines changed

PYHHelper.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Haushaltsbuch", "Haushaltsb
2222
EndProject
2323
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProfileUploader", "ProfileUploader\ProfileUploader.csproj", "{A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}"
2424
EndProject
25+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReplayRename", "ReplayRename\ReplayRename.csproj", "{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}"
26+
EndProject
2527
Global
2628
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2729
Debug|Any CPU = Debug|Any CPU
@@ -118,6 +120,18 @@ Global
118120
{A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x64.Build.0 = Release|Any CPU
119121
{A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x86.ActiveCfg = Release|Any CPU
120122
{A6630778-503C-4BEE-9BEC-F1B9FBFF1B9C}.Release|x86.Build.0 = Release|Any CPU
123+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|Any CPU.Build.0 = Debug|Any CPU
125+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|x64.ActiveCfg = Debug|Any CPU
126+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|x64.Build.0 = Debug|Any CPU
127+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|x86.ActiveCfg = Debug|Any CPU
128+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Debug|x86.Build.0 = Debug|Any CPU
129+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|Any CPU.ActiveCfg = Release|Any CPU
130+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|Any CPU.Build.0 = Release|Any CPU
131+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|x64.ActiveCfg = Release|Any CPU
132+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|x64.Build.0 = Release|Any CPU
133+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|x86.ActiveCfg = Release|Any CPU
134+
{7E223B9B-19E3-4C95-A035-2A1E2E2C0183}.Release|x86.Build.0 = Release|Any CPU
121135
EndGlobalSection
122136
GlobalSection(SolutionProperties) = preSolution
123137
HideSolutionNode = FALSE

PYHHelper/ReplayReader.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace PYHHelper
1111
class ReplayReader
1212
{
1313
private static byte[] PacketBegin = new byte[] {0x10, 0x00, 0x00, 0x08};
14+
private static byte[] IntBegin = new byte[] {0x02, 0x00, 0x00, 0x05};
1415
static byte[] Slice(byte[] arr, int offset, int length)
1516
{
1617
return arr.Skip(offset).Take(length).ToArray();
@@ -22,7 +23,7 @@ public static List<string> Open(string fileName)
2223

2324
byte[] CompressedMetaData = Slice(rep, 21, metaLength);
2425
byte[] RestData = Slice(rep, 21 + metaLength, rep.Length - 21 + metaLength);
25-
File.WriteAllBytes("E:\\restData.txt", RestData);
26+
//File.WriteAllBytes("E:\\restData.txt", RestData);
2627

2728
byte[] MetaData = Inflate(CompressedMetaData);
2829

@@ -35,6 +36,16 @@ public static List<string> Open(string fileName)
3536
byte[] packetNameArray = Slice(MetaData, i + 8, nameLength);
3637
string packetName = Encoding.GetEncoding("Shift_JIS").GetString(packetNameArray);
3738
Names.Add(packetName);
39+
i += 8;
40+
i += nameLength;
41+
i--;
42+
}
43+
else if(Slice(MetaData, i, 4).SequenceEqual(IntBegin))// Int
44+
{
45+
int value = BitConverter.ToInt32(Slice(MetaData, i + 4, 4), 0);
46+
Names.Add(value.ToString());
47+
i += 8;
48+
i--;
3849
}
3950
}
4051

ReplayRename/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
5+
</startup>
6+
</configuration>

ReplayRename/Form1.Designer.cs

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReplayRename/Form1.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Text.RegularExpressions;
10+
using System.Threading.Tasks;
11+
using System.Windows.Forms;
12+
using PYHHelper;
13+
14+
namespace ReplayRename
15+
{
16+
public partial class Form1 : Form
17+
{
18+
private const string SettingFile = "setting.txt";
19+
public Form1()
20+
{
21+
InitializeComponent();
22+
if (File.Exists(SettingFile))
23+
{
24+
var data = File.ReadAllLines(SettingFile);
25+
textBox1.Text = data[0];
26+
folderBrowserDialog1.SelectedPath = data[0];
27+
textBox2.Text = data[1];
28+
}
29+
}
30+
31+
private Dictionary<string, int> propIndex = new Dictionary<string, int>()
32+
{
33+
{"分", 1},
34+
{"P1副机", 9},
35+
{"P2副机", 11},
36+
{"P1", 14},
37+
{"P2", 16},
38+
{"时", 37},
39+
{"P1主机", 40},
40+
{"P2主机", 42},
41+
{"日", 44},
42+
{"年", 46},
43+
{"秒", 52},
44+
{"月", 57},
45+
};
46+
private void button1_Click(object sender, EventArgs e)
47+
{
48+
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
49+
textBox1.Text = folderBrowserDialog1.SelectedPath;
50+
}
51+
Regex pattern = new Regex("\\{([^\\}]+)\\}");
52+
53+
private void Log(string txt)
54+
{
55+
listBox1.Items.Insert(0,txt);
56+
}
57+
58+
private void button2_Click(object sender, EventArgs e)
59+
{
60+
listBox1.Items.Clear();
61+
var settingstr = $"{textBox1.Text}\n{textBox2.Text}";
62+
File.WriteAllText(SettingFile,settingstr);
63+
var task = new Task(() =>
64+
{
65+
foreach (var file in Directory.EnumerateFiles(textBox1.Text, "*.rep"))
66+
{
67+
var prop = ReplayReader.Open(file);
68+
this.Invoke((Action<string>)Log, $"--{file}");
69+
var fi = new FileInfo(file);
70+
var result = fi.DirectoryName + "\\" + textBox2.Text;
71+
var results = pattern.Matches(result);
72+
if (results.Count > 0)
73+
{
74+
foreach (Match mat in results)
75+
{
76+
if (!propIndex.ContainsKey(mat.Groups[1].Value))
77+
{
78+
this.Invoke((Action<string>)Log, $"无效的匹配字段{mat.Groups[1].Value},结束重命名过程");
79+
return;
80+
}
81+
82+
int index = propIndex[mat.Groups[1].Value];
83+
string val = prop[index].Replace("\\", "");
84+
if (index == 14 || index == 16)
85+
{
86+
var bytes = Encoding.GetEncoding("Shift_JIS").GetBytes(val);
87+
val = Encoding.Default.GetString(bytes);
88+
}
89+
90+
result = result.Replace(mat.Groups[0].Value, val);
91+
}
92+
93+
try
94+
{
95+
File.Move(file, result);
96+
this.Invoke((Action<string>)Log, $"重命名为{result}");
97+
}
98+
catch (Exception ex)
99+
{
100+
this.Invoke((Action<string>)Log, "重命名失败!");
101+
foreach (var str in ex.ToString().Split('\n'))
102+
{
103+
this.Invoke((Action<string>) Log, str);
104+
}
105+
}
106+
}
107+
else
108+
{
109+
this.Invoke((Action<string>)Log, $"未找到匹配字段,结束重命名过程");
110+
return;
111+
}
112+
}
113+
114+
this.Invoke((Action<string>)Log, "----重命名结束!");
115+
});
116+
task.Start();
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)
0