-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISO.cs
396 lines (382 loc) · 18.5 KB
/
ISO.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text.RegularExpressions;
using System.Web;
using XkeyBrew.Utils.IsoGameReader;
namespace xk3yDVDMenu
{
[Serializable]
public class ISO
{
public string Filename;
public string GameBoxart;
public string GameDesc;
public string GameGenre;
public string Gameimage;
public string GameNameFromFilename;
public string GameTitle;
public FileInfo ISOFile;
public string JumpToSelectThisGame;
public int Page;
public string Path;
public string RedirectURL;
public string WorkingDirectory;
private string AddDiscDataToBanner(string bannerPath, int discNumber, int discCount)
{
int height;
if (discCount <= 1)
{
return bannerPath;
}
const int scale = 30;
byte[] bannerArray = File.ReadAllBytes(bannerPath);
var bannerMs = new MemoryStream(bannerArray);
Image banner = Image.FromStream(bannerMs);
byte[] discIconArray = File.ReadAllBytes(string.Concat(WorkingDirectory, "media\\disk.png"));
var discIconMs = new MemoryStream(discIconArray);
Image image = Image.FromStream(discIconMs);
if (banner.Height < scale)
{
height = banner.Height - 4;
}
else
{
height = scale;
}
Image discIcon = Resize(image, height);
byte[] discCurrentIconArray =
File.ReadAllBytes(string.Concat(WorkingDirectory, "media\\disc_current.png"));
var discCurrentIconMs = new MemoryStream(discCurrentIconArray);
Image discCurrentIcon = Resize(Image.FromStream(discCurrentIconMs), scale);
const int offset = 10;
var bitmapDisc = new Bitmap((discCount - 1)*10 + discIcon.Width, discIcon.Height);
Graphics g = Graphics.FromImage(bitmapDisc);
for (int i = 0; i < discCount; i++)
{
g.DrawImage(discNumber - 1 != i ? discIcon : discCurrentIcon, i*offset, 0, discIcon.Height,
discIcon.Width);
}
Graphics gr = Graphics.FromImage(banner);
gr.DrawImage(bitmapDisc, banner.Width - bitmapDisc.Width - 2, 2, bitmapDisc.Width, bitmapDisc.Height);
bannerPath = string.Concat(WorkingDirectory, "cache\\",
Filename.Replace(ISOFile.Extension, "-banner.png"));
banner.Save(bannerPath, ImageFormat.Png);
return bannerPath;
}
public string GetGameBanner(bool chkArtwork)
{
string banner;
string bannerPath = GetGameBannerBasic(chkArtwork);
try
{
var isoFile = new IsoGameInfo(Path);
banner = AddDiscDataToBanner(bannerPath, isoFile.XeXHeaderInfo.DiscNumber,
isoFile.XeXHeaderInfo.DiscCount);
}
catch (Exception)
{
banner = bannerPath;
}
return banner;
}
public string GetGameBannerBasic(bool chkArtwork)
{
//Log.Text = string.Concat(Log.Text, "Loading banner:", Path, Environment.NewLine);
if (!File.Exists(string.Concat(Path.Replace(ISOFile.Extension, ""), "-banner.png")))
{
var waffle = new WaffleXML(Path.Replace(ISOFile.Extension, ".xml"));
if (waffle.Banner == null)
{
if (chkArtwork)
{
try
{
var iso = new Iso(ISOFile.FullName, true);
if (iso.DefaultXeX != null)
{
//Log.Text = string.Concat(Log.Text, "Searching Xbox.com for banner:", Path, Environment.NewLine);
var wc = new WbClient();
byte[] data =
wc.DownloadData(
string.Concat(
"http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802",
iso.DefaultXeX.XeXHeader.TitleId.ToLower(), "/1033/banner.png"));
if (data == null)
{
throw new Exception("Download Failed");
}
{
waffle.Banner = data;
//TextBox textBox1 = Log;
//textBox1.Text = string.Concat(textBox1.Text, "Banner saved to XML File", Path, Environment.NewLine);
return GetGameBanner(true);
}
}
{
throw new Exception("Not a Game");
}
}
catch (Exception)
{
//Log.Text = string.Concat(Log.Text, "Banner Download Failed:", Path, Environment.NewLine);
//Log.Text = string.Concat(Log.Text, "No banner found:", Path, Environment.NewLine);
return "media\\blank-banner.png";
}
}
//Log.Text = string.Concat(Log.Text, "No banner found:", Path, Environment.NewLine);
return "media\\blank-banner.png";
}
else
{
var binWritter =
new StreamWriter(
string.Concat(WorkingDirectory, "cache\\",
Filename.Replace(ISOFile.Extension, "-banner.png")), false);
binWritter.BaseStream.Write(waffle.Banner, 0, waffle.Banner.Length);
binWritter.Flush();
binWritter.Close();
//Log.Text = string.Concat(Log.Text, "Banner found in XML:", Path, Environment.NewLine);
return string.Concat(WorkingDirectory, "cache\\",
Filename.Replace(ISOFile.Extension, "-banner.png"));
}
}
else
{
//Log.Text = string.Concat(Log.Text, "Local Banner Found:", Path, Environment.NewLine);
return string.Concat(Path.Replace(ISOFile.Extension, ""), "-banner.png");
}
}
public string GetGameBoxart(bool chkArtwork)
{
//Log.Text = string.Concat(Log.Text, "Finding cover for:", Path, Environment.NewLine);
if (
!(File.Exists(string.Concat(Path.Replace(ISOFile.Extension, ""), "-cover.jpg")) |
File.Exists(string.Concat(Path.Replace(ISOFile.Extension, ""), "-cover.png"))))
{
var waffle = new WaffleXML(Path.Replace(ISOFile.Extension, ".xml"));
if (waffle.BoxArt == null)
{
if (chkArtwork)
{
try
{
var iso = new Iso(ISOFile.FullName, true);
if (iso.DefaultXeX != null)
{
//Log.Text = string.Concat(Log.Text, "Searching Xbox.com for cover", Path, Environment.NewLine);
var wc = new WbClient();
byte[] data =
wc.DownloadData(string.Concat("http://tiles.xbox.com/consoleAssets/",
iso.DefaultXeX.XeXHeader.TitleId.ToLower(),
"/en-US/largeboxart.jpg"));
if (data != null)
{
waffle.BoxArt = data;
//Log.Text = string.Concat(Log.Text, "Cover saved to XML", Path, Environment.NewLine);
return GetGameBoxart(true);
}
{
throw new Exception("Download Failed");
}
}
{
throw new Exception("Not a Game");
}
}
catch (Exception)
{
//Log.Text = string.Concat(Log.Text, "Download Failed", Path, Environment.NewLine);
//Log.Text = string.Concat(Log.Text, "No Cover found", Path, Environment.NewLine);
return "media\\blank-cover.jpg";
}
}
//Log.Text = string.Concat(Log.Text, "No Cover found", Path, Environment.NewLine);
return "media\\blank-cover.jpg";
}
{
var binWritter =
new StreamWriter(
string.Concat(WorkingDirectory, "cache\\",
Filename.Replace(ISOFile.Extension, "-cover.jpg")), false);
binWritter.BaseStream.Write(waffle.BoxArt, 0, waffle.BoxArt.Length);
binWritter.Flush();
binWritter.Close();
//Log.Text = string.Concat(Log.Text, "Found in XML", Path, Environment.NewLine);
return string.Concat(WorkingDirectory, "cache\\",
Filename.Replace(ISOFile.Extension, "-cover.jpg"));
}
}
{
if (File.Exists(string.Concat(Path.Replace(ISOFile.Extension, ""), "-cover.png")))
{
return string.Concat(Path.Replace(ISOFile.Extension, ""), "-cover.png");
}
//Log.Text = string.Concat(Log.Text, "Local cover found", Path, Environment.NewLine);
return string.Concat(Path.Replace(ISOFile.Extension, ""), "-cover.jpg");
}
}
public string GetGameDesc(bool chkArtwork)
{
//Log.Text = string.Concat(Log.Text, "Finding Desc", Path, Environment.NewLine);
var waffleXMLFile = new WaffleXML(Path.Replace(ISOFile.Extension, ".xml"));
if (waffleXMLFile.Summary == "")
{
if (chkArtwork)
{
try
{
var iso = new Iso(ISOFile.FullName, true);
if (iso.DefaultXeX == null)
{
}
else
{
//Log.Text = string.Concat(Log.Text, "Xbox.com Desc", Path, Environment.NewLine);
var wc = new WbClient();
string page =
wc.DownloadString(wc.RedirectURL(this,
"http://marketplace.xbox.com/en-US/games/media/66acd000-77fe-1000-9115-d802" +
iso.DefaultXeX.XeXHeader.TitleId.ToLower() +
"?nosplash=1"));
var replacer = new Regex("<meta name=\"description\" content=\".*\" />");
Match results = replacer.Match(page);
string desc = results.Value.Substring(34);
desc = desc.Substring(0, desc.Length - 5).Trim();
waffleXMLFile.Summary = desc;
//Log.Text = string.Concat(Log.Text, "Found", Path, Environment.NewLine);
return desc;
}
}
catch (Exception)
{
return "";
}
}
//Log.Text = string.Concat(Log.Text, "Not Found", Path, Environment.NewLine);
return "";
}
{
//Log.Text = string.Concat(Log.Text, "In XML", Path, Environment.NewLine);
return waffleXMLFile.Summary;
}
}
public string GetGameGenre(bool chkArtwork)
{
//Log.Text = string.Concat(Log.Text, "Finding Genre", Path, Environment.NewLine);
var waffle = new WaffleXML(Path.Replace(ISOFile.Extension, ".xml"));
if (waffle.InfoItem("Genre") == "")
{
if (chkArtwork)
{
try
{
var iso = new Iso(ISOFile.FullName, true);
if (iso.DefaultXeX != null)
{
//Log.Text = string.Concat(Log.Text, "Xbox.com Search", Path, Environment.NewLine);
var wc = new WbClient();
string page =
wc.DownloadString(wc.RedirectURL(this,
"http://marketplace.xbox.com/en-US/games/media/66acd000-77fe-1000-9115-d802" +
iso.DefaultXeX.XeXHeader.TitleId.ToLower() +
"?nosplash=1"));
if (page.IndexOf("Genre:", StringComparison.Ordinal) != 0)
{
int startIndex = page.IndexOf("Genre:", StringComparison.Ordinal) + 6;
string genre = page.Substring(startIndex);
genre = genre.Substring(0, genre.IndexOf("</li>", StringComparison.Ordinal));
string htmlDecode = HttpUtility.HtmlDecode(genre.Trim().Replace("\n", ""));
if (htmlDecode != null)
genre = htmlDecode.Replace("<li>", "").Replace("</label>", "");
waffle.InfoItem("Genre", genre);
//Log.Text = string.Concat(Log.Text, "Found", Path, Environment.NewLine);
return genre;
}
}
else
{
throw new Exception("Not a Game");
}
}
catch (Exception)
{
return "";
}
}
//Log.Text = string.Concat(Log.Text, "No Genre Found", Path, Environment.NewLine);
return "";
}
{
//Log.Text = string.Concat(Log.Text, "Found in XML file", Path, Environment.NewLine);
return waffle.InfoItem("Genre");
}
}
public string GetGameTitle(bool chkArtwork)
{
//Log.Text = string.Concat(Log.Text, "Finding Title", Path, Environment.NewLine);
var waffle = new WaffleXML(Path.Replace(ISOFile.Extension, ".xml"));
if (waffle.Title == "")
{
if (chkArtwork)
{
try
{
var iso = new Iso(ISOFile.FullName, true);
if (iso.DefaultXeX != null)
{
//Log.Text = string.Concat(Log.Text, "Xbox.com search", Path, Environment.NewLine);
var wc = new WbClient();
string page =
wc.DownloadString(wc.RedirectURL(this,
"http://marketplace.xbox.com/en-US/games/media/66acd000-77fe-1000-9115-d802" +
iso.DefaultXeX.XeXHeader.TitleId.ToLower() +
"?nosplash=1"));
if (page.IndexOf("<title>", StringComparison.Ordinal) != 0)
{
int startIndex = page.IndexOf("<title>", StringComparison.Ordinal) + 7;
string title = page.Substring(startIndex);
title = title.Substring(0, title.IndexOf(" - Xbox.com", StringComparison.Ordinal));
title = title.Trim().Replace("\n", "");
title = HttpUtility.HtmlDecode(title);
if (title != null) title = title.Replace("&", "&");
waffle.Title = title;
return title;
}
}
else
{
throw new Exception("Not a Game");
}
}
catch (Exception)
{
return GameNameFromFilename;
}
}
//Log.Text = string.Concat(Log.Text, "Using filename", Path, Environment.NewLine);
return GameNameFromFilename;
}
else
{
//Log.Text = string.Concat(Log.Text, "Found in XML", Path, Environment.NewLine);
return waffle.Title;
}
}
public Image Resize(Image srcImage, int newSize)
{
var newImage = new Bitmap(newSize, newSize);
Graphics gr = Graphics.FromImage(newImage);
using (gr)
{
gr.SmoothingMode = SmoothingMode.AntiAlias;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(srcImage, new Rectangle(0, 0, newSize, newSize));
}
return newImage;
}
}
}