This repository has been archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
195 lines (156 loc) · 6.55 KB
/
MainWindow.xaml.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.IO;
using System.Text.Json.Nodes;
using System.Diagnostics;
namespace SkinInjector
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Boolean isPersonaSelected = false;
private Boolean isInjectSkinPackSelected = false;
public MainWindow()
{
InitializeComponent();
PackListView.ItemsSource = GetAllSkinPackData();
}
private void Choose_PersonaFolder(object sender, RoutedEventArgs e)
{
FolderBrowserDialog dialog = new()
{
Description = "personaフォルダを選択してください"
};
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.personaPath.Text = dialog.SelectedPath;
isPersonaSelected = true;
if (isPersonaSelected && isInjectSkinPackSelected)
{
inject.IsEnabled = true;
}
}
}
private List<PackInfo> GetAllSkinPackData()
{
string targetPath = Environment.ExpandEnvironmentVariables(this.minecraftPath.Text.ToString());
var packList = new List<PackInfo>();
var subFolders = Directory.GetDirectories(targetPath);
foreach (var subFolder in subFolders)
{
string manifestPath = System.IO.Path.Combine(subFolder, "manifest.json");
if (File.Exists(manifestPath))
{
try
{
string content = File.ReadAllText(manifestPath);
var json = JsonObject.Parse(content);
string? packName = json["header"]?["name"]?.ToString();
packList.Add(new PackInfo
{
FolderPath = subFolder,
PackName = packName
});
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"エラーが発生しました: {ex.Message}", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
Debug.WriteLine(ex.ToString());
}
}
}
return packList;
}
private void InjectClick(object sender, RoutedEventArgs e)
{
if (Directory.Exists(personaPath.Text))
{
List<PackInfo> PackList = GetAllSkinPackData();
string currentDirectory = Directory.GetCurrentDirectory();
string folderName = "persona";
string copyPath = System.IO.Path.Combine(currentDirectory, folderName);
DirectoryInfo directory = new(copyPath);
string sourcePath = personaPath.Text;
string? targetPath = PackList[PackListView.SelectedIndex].FolderPath;
if (Directory.Exists(copyPath))
{
directory.Delete(true);
}
Directory.CreateDirectory(copyPath);
foreach (var filePath in Directory.GetFiles(sourcePath))
{
string fileName = System.IO.Path.GetFileName(filePath);
if (fileName != "manifest.json")
{
string destFilePath = System.IO.Path.Combine(copyPath, fileName);
File.Copy(filePath, destFilePath);
}
}
if (targetPath != null)
{
foreach (var filePath in Directory.GetFiles(targetPath))
{
string fileName = System.IO.Path.GetFileName(filePath);
if (fileName != "manifest.json")
{
File.Delete(filePath);
}
}
foreach (var subDir in Directory.GetDirectories(targetPath))
{
Directory.Delete(subDir, true);
}
foreach (var filePath in Directory.GetFiles(copyPath))
{
string fileName = System.IO.Path.GetFileName(filePath);
string destFilePath = System.IO.Path.Combine(targetPath, fileName);
File.Copy(filePath, destFilePath);
}
if (isEncrypt.IsChecked == true)
{
Process encript = new();
string currentDir = AppDomain.CurrentDomain.BaseDirectory;
encript.StartInfo.FileName = System.IO.Path.Combine(currentDir, "MCEnc", "McEncryptor.exe");
encript.StartInfo.UseShellExecute = false;
encript.StartInfo.RedirectStandardInput = true;
encript.StartInfo.CreateNoWindow = true;
encript.Start();
encript.StandardInput.WriteLine(targetPath);
encript.StandardInput.Close();
encript.WaitForExit();
}
System.Windows.MessageBox.Show($"処理に成功しました。", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
}
} else
{
System.Windows.MessageBox.Show($"パスが無効です。確認してください。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void PackListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
isInjectSkinPackSelected = true;
if (isPersonaSelected && isInjectSkinPackSelected)
{
inject.IsEnabled = true;
}
}
}
public class PackInfo
{
public string? FolderPath { get; set; }
public string? PackName { get; set; }
}
}