-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.cs
198 lines (171 loc) · 6.41 KB
/
Main.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace SecureDesktop_GUI
{
public partial class Main : Form
{
BackgroundWorker bg = new BackgroundWorker();
Stopwatch stop = new Stopwatch();
public Main()
{
InitializeComponent();
this.Icon = Properties.Resources.icon;
this.AllowDrop = true;
this.DragEnter += delegate(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
LoadFile(((string[])e.Data.GetData(DataFormats.FileDrop))[0], true);
}
};
this.DragLeave += delegate { UnloadFile(); };
this.DragDrop += delegate(object sender, DragEventArgs e)
{
LoadFile(((string[])e.Data.GetData(DataFormats.FileDrop))[0]);
};
bg.DoWork += delegate
{
IntPtr hProc = IntPtr.Zero;
WinAPI.STARTUPINFO si = new WinAPI.STARTUPINFO();
WinAPI.PROCESS_INFORMATION pi = new WinAPI.PROCESS_INFORMATION();
WinAPI.CreateProcess(null, String.Format("\"{0}\" \"{1}\"", Program.location + "\\SecureDesktop.exe", fileloc), IntPtr.Zero, IntPtr.Zero, false, WinAPI.CREATE_NO_WINDOW, IntPtr.Zero, null, ref si, out pi);
hProc = pi.hProcess;
//if (!this.IsDisposed) this.Invoke((Action)delegate { this.Close(); });
try
{
uint code;
while (!this.IsDisposed)
{
Thread.Sleep(500);
if (!WinAPI.GetExitCodeProcess(hProc, out code) || code != 259) { break; }
}
}
catch { }
};
bg.RunWorkerCompleted += delegate
{
btnRun.Enabled = true;
stop.Stop();
labelTime.Text = String.Format("Secure Desktop ran for {0:0}m{1:0}s", stop.Elapsed.TotalMinutes, stop.Elapsed.Seconds);
};
labelFile.SizeChanged += delegate
{
if (labelFile.Width < 260) this.Width = 428;
else
this.Width = labelFile.Width + 168;
};
}
Image GetIcon(string file)
{
Icon ficon;
WinAPI.SHFILEINFO shinfo = new WinAPI.SHFILEINFO();
IntPtr ptr = WinAPI.SHGetFileInfo(file, WinAPI.FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), WinAPI.SHGFI_SYSICONINDEX);
if (ptr == IntPtr.Zero) ficon = Icon.ExtractAssociatedIcon(file);
else
{
int iconIndex = shinfo.iIcon;
Guid iImageListGuid = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
WinAPI.IImageList iml;
int hres = WinAPI.SHGetImageList(0x04, ref iImageListGuid, out iml);
IntPtr hIcon = IntPtr.Zero;
hres = iml.GetIcon(iconIndex, 1, ref hIcon);
ficon = System.Drawing.Icon.FromHandle(hIcon);
}
Image img;
Icon temp = new Icon(ficon, 128, 128);
img = temp.ToBitmap();
temp.Dispose();
ficon.Dispose();
return img;
}
Image oldicon = Properties.Resources.icon128_gray;
string oldfile = "Please select or drop a file", olddate = "2018-11-21";
string fileloc = "";
void LoadFile(string file, bool preview = false)
{
icon.Image = GetIcon(file);
labelFile.Text = Path.GetFileName(file);
FileInfo info = new FileInfo(file);
labelDate.Text = info.LastWriteTime.ToString("yyyy-MM-dd");
if (!preview)
{
labelTime.Text = "Waiting to run...";
oldicon = icon.Image;
oldfile = labelFile.Text;
olddate = labelDate.Text;
fileloc = file;
btnRun.Enabled = true;
}
}
void UnloadFile()
{
icon.Image = oldicon;
labelFile.Text = oldfile;
labelDate.Text = olddate;
//btnRun.Enabled = false;
}
private void btnRun_Click(object sender, EventArgs e)
{
if (!File.Exists(fileloc))
{
MessageBox.Show("The selected file no longer exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!Program.CheckValidity()) return;
btnRun.Enabled = false;
stop = new Stopwatch();
stop.Start();
bg.RunWorkerAsync();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void menuFileOpen_Click(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
if (ofd.ShowDialog() != DialogResult.OK)
return;
LoadFile(ofd.FileName);
}
}
private void menuFileExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Main_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
label1.AutoSize = true;
}
private void label1_Click_1(object sender, EventArgs e)
{
//label1.Font = new Font("Arial", 24, FontStyle.Bold);
}
private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
Form custom_form = new message_box_custom();
custom_form.Show();
}
private void menuHelpAbout_Click(object sender, EventArgs e)
{
using (var form = new About_this())
{
form.ShowDialog();
}
}
}
}