-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
166 lines (144 loc) · 6.1 KB
/
Program.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
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace UpdateZipmodManifest
{
class Program
{
const string MANIFEST_FILE_NAME = "manifest.xml";
const string ROOT_ELEMENT = "manifest";
const string GAME_ELEMENT = "game";
const string KK_GAME_NAME = "Koikatsu";
const string KKS_GAME_NAME = "Koikatsu Sunshine";
#if DEBUG
const string PATH = @"D:\KoikatsuSunshine\mods";
#else
const string PATH = @".\\mods";
#endif
static void Main(string[] args)
{
try
{
Console.WriteLine($@"<< zipmod game指定更新アプリ >>
※注意※
バグや実行途中の中断などでzipmodファイルが使えなくなることがあります。
バックアップを取ってから実行するようにして下さい。
[更新対象フォルダ]
{Path.GetFullPath(PATH)}
[実行オプション]
1) コイカツ用のzipmodを、コイカツサンシャイン用に更新する
2) コイカツ用のzipmodを、コイカツ・コイカツサンシャイン共用に更新する
3) コイカツサンシャイン用のzipmodを、コイカツ用に更新する
9) コイカツ用・コイカツサンシャイン用のzipmodを、どのゲームでも利用できるようにする
※ゲーム指定が削除されるため、指定を元に戻すことができません
実行したいオプションの数字を入力し、Enterキーを押して下さい。");
Console.Write("> ");
var selection = Console.ReadLine();
bool targetKK = false;
bool targetKKS = false;
bool convertKK = false;
bool convertKKS = false;
switch (selection)
{
case "1":
targetKK = true;
convertKKS = true;
break;
case "2":
targetKK = true;
convertKK = true;
convertKKS = true;
break;
case "3":
targetKKS = true;
convertKK = true;
break;
case "9":
targetKK = true;
targetKKS = true;
break;
default:
throw new Exception("範囲外の選択肢です");
}
Console.WriteLine("更新開始...");
var filePaths = Directory.GetFiles(PATH, "*.zipmod", SearchOption.AllDirectories);
foreach (var path in filePaths)
{
var toUpdate = false;
using (var archive = ZipFile.OpenRead(path))
{
var entry = archive.Entries.FirstOrDefault((e) => e.FullName.Equals(MANIFEST_FILE_NAME));
if (entry == null)
{
continue;
}
var xmlObj = XElement.Load(entry.Open());
if (!xmlObj.Name.LocalName.Equals(ROOT_ELEMENT))
{
continue;
}
var gameElements = xmlObj.Elements().Where(e => e.Name.LocalName.Equals(GAME_ELEMENT)).ToList();
if (gameElements.Count() == 0)
{
continue;
}
if (targetKK && gameElements.Exists(ge => ge.Value.Equals(KK_GAME_NAME)))
{
toUpdate = true;
}
else if (targetKKS && gameElements.Exists(ge => ge.Value.Equals(KKS_GAME_NAME)))
{
toUpdate = true;
}
}
if (toUpdate)
{
using (var archive = ZipFile.Open(path, ZipArchiveMode.Update))
{
var entry = archive.Entries.FirstOrDefault((e) => e.FullName.Equals(MANIFEST_FILE_NAME));
XElement xmlObj;
using (var stream = entry.Open())
{
xmlObj = XElement.Load(stream);
}
xmlObj.Elements().Where(e => e.Name.LocalName.Equals(GAME_ELEMENT)).ToList().ForEach(gameElement =>
{
gameElement.Remove();
});
if (convertKK)
{
xmlObj.Add(new XElement(GAME_ELEMENT, KK_GAME_NAME));
}
if (convertKKS)
{
xmlObj.Add(new XElement(GAME_ELEMENT, KKS_GAME_NAME));
}
entry.Delete();
var newEntry = archive.CreateEntry(MANIFEST_FILE_NAME);
using (var stream = newEntry.Open())
{
xmlObj.Save(stream);
}
Console.WriteLine($"Updated {path}");
}
}
}
Console.WriteLine("置換完了");
Console.WriteLine("");
Console.WriteLine("終了するにはキーを押してください...");
Console.Read();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("終了するにはキーを押してください...");
Console.Read();
}
}
}
}