-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
199 lines (166 loc) · 6.48 KB
/
MainForm.cs
File metadata and controls
199 lines (166 loc) · 6.48 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
namespace Win10LockScreenImageExtractTool
{
public partial class MainForm : Form
{
private delegate void UpdateShowEventHandler(string str, int value);
private event UpdateShowEventHandler UpdateShow;
private delegate void UpdateProgressEventHandler(bool show);
private event UpdateProgressEventHandler UpdateProgress;
private Thread background;
private List<FileInfo> pathes = new List<FileInfo>();
public MainForm()
{
if (Environment.OSVersion.Version.Major != 10)
{
if (DialogResult.OK == MessageBox.Show("此工具仅支持Win10操作系统,其它系统不支持!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error))
{
Environment.Exit(0x00);
}
}
else
{
InitializeComponent();
}
}
private void OnUpdateShow(string str, int value)
{
this.Invoke(new Action(delegate
{
label_Info.Text = str;
progressBar.Value = value;
}));
}
private void OnUpdateProgress(bool show)
{
this.Invoke(new Action(delegate
{
if (show)//显示进度条,功能不可用
{
progressBar.Visible = true;
textBox_Target.Enabled = false;
OK.Enabled = false;
Browse.Enabled = false;
checkBox.Enabled = false;
}
else
{
progressBar.Visible = false;
textBox_Target.Enabled = true;
OK.Enabled = true;
Browse.Enabled = true;
checkBox.Enabled = true;
}
}));
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void MainForm_Shown(object sender, EventArgs e)
{
background = new Thread(CheckAndBuildList);
background.Start();
}
private void CheckAndBuildList()
{
UpdateShow += OnUpdateShow;
UpdateProgress += OnUpdateProgress;
UpdateProgress.Invoke(true);
// 设置锁屏文件的文件夹路径
string Folder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
Folder += @"\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets";
if (Directory.Exists(Folder))
{
DirectoryInfo folder = new DirectoryInfo(Folder);
FileInfo[] files = folder.GetFiles();
int AllFilesCount = files.Count();
UpdateShow.Invoke(string.Format("共检测到{0}个文件,准备开始分析", AllFilesCount), 0);
int index = 0;
foreach (FileInfo info in files)
{
index++;
UpdateShow.Invoke(string.Format("正在分析第{0}个文件...", index), (int)(((double)index * 100) / AllFilesCount));
if (info.Length > 100000)
{
pathes.Add(info);
}
}
UpdateShow.Invoke(string.Format("共检测到{0}个有效文件,请先选择导出文件夹,再点击“导出”进行导出", pathes.Count()), 100);
Thread.Sleep(500);
UpdateProgress.Invoke(false);
}
else
{
MessageBox.Show("无法检测到指定路径,可能您的系统尚未打开或不支持该功能,运行错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
UpdateShow -= OnUpdateShow;
UpdateProgress -= OnUpdateProgress;
}
private void Browse_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (DialogResult.OK == dlg.ShowDialog())
{
textBox_Target.Text = dlg.SelectedPath;
}
}
private void OK_Click(object sender, EventArgs e)
{
background = new Thread(ExtractFiles);
background.Start();
}
private void ExtractFiles()
{
UpdateShow += OnUpdateShow;
UpdateProgress += OnUpdateProgress;
UpdateProgress.Invoke(true);
if (Directory.Exists(textBox_Target.Text))
{
StreamReader sr;
StreamWriter sw;
UpdateShow.Invoke("开始导出文件", 0);
string Folder = textBox_Target.Text + "\\";
int index = 0;
int fail = 0;
string TargetPath;
foreach (FileInfo info in pathes)
{
index++;
UpdateShow.Invoke(string.Format("正在提取第{0}个文件,文件大小为:{1}KB", index, info.Length / 1024),
(int)(((double)index * 100) / pathes.Count()));
TargetPath = Folder + index.ToString("D8") + ".jpg";
try
{
File.Copy(info.FullName, TargetPath);
}
catch(IOException e)
{
fail++;
}
}
UpdateShow.Invoke(string.Format("成功导出{0}个文件,失败{1}个!", pathes.Count() - fail, fail), 100);
Thread.Sleep(500);
if (checkBox.Checked)
{
System.Diagnostics.Process.Start("explorer.exe", Folder);
}
}
else
{
MessageBox.Show("无法检测到目标路径,运行错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
UpdateProgress.Invoke(false);
UpdateShow += OnUpdateShow;
UpdateProgress += OnUpdateProgress;
}
}
}