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; }
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 OnUpdateShow() { UpdateShow?.Invoke(); }