-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
183 lines (167 loc) · 5.7 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2007-2008 wqNotes Project
* License: BSD
* Windows: Program.cs, $Revision$
* $HeadURL$
* $Date$
*/
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace wqNotes
{
static class Program
{
[DllImport("shell32.dll")]
private static extern UInt32 ExtractIconEx(String lpszFile, Int32 nIconIndex, ref IntPtr phiconLarge, ref IntPtr phiconSmall, UInt32 nIcons);
[DllImport("user32.dll")]
private static extern Int32 DestroyIcon(IntPtr hIcon);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr LoadLibrary(String lpFileName);
public static string GetShortSize(Int32 qw) //UInt64
{
if (qw < 1024) return qw.ToString() + " ??
Int32 c = 0, t = 1024 * 1000 - 1;
while (qw > t) { qw /= 1024; c++; }
Int32 dw = qw / 1024;
StringBuilder ret = new StringBuilder(dw.ToString());
if (ret.Length < 3)
{
Int32 uDec = (qw - dw * 1024) * 1000 / 1024;
uDec /= 10; ret.Append(".");
if (ret.Length == 3) uDec /= 10;
ret.Append('0', 4 - ret.Length - uDec.ToString().Length);
ret.Append(uDec.ToString());
}
String[] use = { "?", "?", "?", "?" };
return ret + " " + use[c];
}
public static Image GetFileIcon(string FileName, bool IsIconContains, bool _16x16)
{
Image ret = null; Int32 DefIndex = 0;
try
{
if (IsIconContains == false)
{
RegistryKey hKey = null;
String skey = Path.GetExtension(FileName);
if ((hKey = Registry.ClassesRoot.OpenSubKey(skey)) != null)
{
skey = hKey.GetValue(null).ToString();
skey += "\\DefaultIcon"; hKey.Close();
if ((hKey = Registry.ClassesRoot.OpenSubKey(skey)) != null)
{
skey = hKey.GetValue(null).ToString();
String[] df = skey.Split(',');
hKey.Close();
if (df.Length == 2)
{
FileName = df[0];
Int32.TryParse(df[1], out DefIndex);
}
}
}
}
}
catch { }
finally
{
IntPtr hSmall = IntPtr.Zero, hLarge = IntPtr.Zero;
ExtractIconEx(FileName, DefIndex, ref hLarge, ref hSmall, 1);
if (hSmall == IntPtr.Zero)
ExtractIconEx("shell32.dll", 0, ref hLarge, ref hSmall, 1);
ret = (Image)Icon.FromHandle(_16x16 ? hSmall : hLarge).ToBitmap();
DestroyIcon(hLarge); DestroyIcon(hSmall);
}
return ret;
}
public static Image MergeImages(Image ImageBack, Image ImageFore)
{
Image ret = (Image)ImageBack.Clone();
Graphics res = Graphics.FromImage(ret);
res.DrawImageUnscaled(ImageBack, 0, 0);
res.DrawImageUnscaled(ImageFore, 0, 0);
res.Save();
return ret;
}
public static string GetTextFromRtf(string rtf)
{
RichTextBox rtb = new RichTextBox();
rtb.Rtf = rtf;
return rtb.Text;
}
public static string GetRtfFromClipboard()
{
RichTextBox rtb = new RichTextBox(); rtb.Text = "";
rtb.Paste(DataFormats.GetFormat(DataFormats.UnicodeText));
return rtb.Rtf;
}
public static string GetShorterPath(string path, int MaxN)
{
// TODO: Implement ? return path;
}
public static Options Opt = Options.Load();
public const string wqVersion = "0.9.3.53";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
public class CRC32
{
private UInt32[] crc32Table;
private const int BUFFER_SIZE = 1024;
public UInt32 GetCrc32(Stream stream)
{
unchecked
{
UInt32 crc32Result;
crc32Result = 0xFFFFFFFF;
byte[] buffer = new byte[BUFFER_SIZE];
int readSize = BUFFER_SIZE;
int count = stream.Read(buffer, 0, readSize);
while (count > 0)
{
for (int i = 0; i < count; i++)
{
crc32Result = ((crc32Result) >> 8) ^
crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)];
}
count = stream.Read(buffer, 0, readSize);
}
return ~crc32Result;
}
}
public CRC32()
{
unchecked
{
UInt32 dwPolynomial = 0xEDB88320, dwCrc;
crc32Table = new UInt32[256];
for (UInt32 i = 0; i < 256; i++)
{
dwCrc = i;
for (UInt32 j = 8; j > 0; j--)
{
if ((dwCrc & 1) == 1)
dwCrc = (dwCrc >> 1) ^ dwPolynomial;
else
dwCrc >>= 1;
}
crc32Table[i] = dwCrc;
}
}
}
}
}