/
Program.cs
56 lines (55 loc) · 2.03 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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows.Forms;
namespace imgs2pdf
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length == 0)
{
var alertKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes", true).CreateSubKey("imgs2pdf");
alertKey.SetValue("", "URL:Pdf2imgs Protocol");
alertKey.SetValue("URL Protocol", "");
var shellKey = alertKey.CreateSubKey("shell");
var openKey = shellKey.CreateSubKey("open");
var commandKey = openKey.CreateSubKey("command");
commandKey.SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\"");
MessageBox.Show("imgs2pdf installed.", "imgs2pdf", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
var frags = args[0].Remove(0, "imgs2pdf:".Length).Split('|');
string[] imgs = null;
var filename = Uri.UnescapeDataString(frags[0]);
if (frags[2] == "url")
{
var wc = new WebClient();
wc.Headers["Cookie"] = frags[4];
imgs = wc.DownloadString(Uri.UnescapeDataString(frags[3])).Split(new []{"\r\n"},StringSplitOptions.RemoveEmptyEntries);
}
else
{
imgs = frags.Skip(2).ToArray();
}
var mainForm = new MainForm()
{
Filename = filename,
DPI = Convert.ToInt32(frags[1]),
Imgs = imgs
};
Application.Run(mainForm);
}
}
}
}