Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
66 lines (63 loc) · 2.11 KB
/
Copy pathProgram.cs
File metadata and controls
66 lines (63 loc) · 2.11 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace QQMhtToHtml
{
class Program
{
static void Main(string[] args)
{
Console.Title = "QQMht To Html";
string mht, html = string.Empty;
try
{
mht = File.ReadAllText(args[0]);
}
catch
{
return;
}
MHTMLParser parser = new MHTMLParser(mht);
List<string[]> nodes;
try
{
Console.WriteLine("Processing data...");
nodes= parser.DecompressString();
}
catch
{
return;
}
string path = Path.GetDirectoryName(args[0]);
string hFile = Path.GetFileNameWithoutExtension(args[0]);
string d = $@"{path}\{hFile}_images";
if (nodes.Count > 0)
{
int c = nodes.Count - 1;
if (nodes.Count > 1)
{
Directory.CreateDirectory(d);
Console.WriteLine($"{c} image(s) found.");
}
html = nodes[0][2];
for (int i = 1; i < nodes.Count; i++)
{
string ext = nodes[i][0].Split("/".ToArray())[1],
name = nodes[i][1].Split(".".ToArray())[0];
if (ext == "jpeg")
ext = "jpg";
string iFile = $@"{d}\{name}.{ext}";
byte[] bytes = Convert.FromBase64String(nodes[i][2]);
File.WriteAllBytes(iFile, bytes);
html = html.Replace($"{name}.dat", $@"{iFile}");
Console.WriteLine($"Processing image...({i}/{c})");
}
hFile = $@"{path}\{hFile}.html";
File.WriteAllText(hFile, html);
Console.Write("All done.");
Console.ReadKey();
}
}
}
}