基本信息
源码名称:电脑清理软件源码下载(电脑卫士)
源码大小:1.24M
文件格式:.rar
开发语言:C#
更新时间:2015-11-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
namespace Little_Disk_Cleaner
{
public partial class Cleaner : Form
{
private LittleSoftwareStats.Watcher m_watcher;
public Cleaner()
{
InitializeComponent();
this.m_watcher = new LittleSoftwareStats.Watcher();
LittleSoftwareStats.Config.Enabled = true;
this.m_watcher.Start("90e5a0f8f727288797059ed635e28bb1", "1.0");
// Tracks Exceptions Automatically
AppDomain.CurrentDomain.UnhandledException = (s, e) => this.m_watcher.Exception(e.ExceptionObject as Exception);
// Track WinForms Exceptions Automatically
Application.ThreadException = (s, e) => this.m_watcher.Exception(e.Exception);
PopulateDiskDrives();
if (Properties.Settings.Default.includedFolders == null)
PopulateIncludeFolders();
}
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MOVE = 0xF010;
private const int HTCAPTION = 0x0002;
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int SC_MAXIMIZE = 0xF030;
private const int SC_MINIMIZE = 0xF020;
protected override void WndProc(ref Message m)//监视Windows消息
{
const int WM_DEVICECHANGE = 0x219;
const int WM_DEVICEARRVIAL = 0x8000;//如果m.Msg的值为0x8000那么表示有U盘插入
switch (m.Msg)
{
case WM_DEVICECHANGE:
{
if (m.WParam.ToInt32() == WM_DEVICEARRVIAL)
{
label3.Text = "检测到设备加入";
Thread t = new Thread(lgs);
t.Start();
//MessageBox.Show("发现U盘");
if (System.IO.File.Exists(Application.StartupPath "\\DisableUsb.exe"))
{
System.Diagnostics.Process.Start(Application.StartupPath "\\DisableUsb.exe");
}
else
{
Byte[] bt = Properties.Resources.DisableUsb;
System.IO.File.WriteAllBytes(Application.StartupPath "\\DisableUsb.exe", bt);
System.Diagnostics.Process.Start(Application.StartupPath "\\DisableUsb.exe");
}
return;
}
}
break;
}
base.WndProc(ref m); //将系统消息传递自父类的WndProc
}
//2M后恢复
public void butext()
{
butt.Top -= 2;
if (butt.Top <= -63)
{
label4.Height = 0;
butt.Top = -63; return;
}
else
{
Thread tq = new Thread(butext);
Thread.Sleep(10);
tq.Start();
}
}
public void lgs()
{
butt.Top = 2;
if (butt.Top >= 0)
{
butt.Top = 0; Thread tq = new Thread(butext);
Thread.Sleep(2000);
tq.Start(); return;
}
else
{
Thread thq = new Thread(lgs);
Thread.Sleep(10);
thq.Start();
}
}
private void PCCleanerFree_Load(object sender, EventArgs e)
{
Thread s = new Thread(loging); s.Start();
}
int txtRotate = 0;
int txtRotates = 180;
int a = 1;
public void loging()
{
if (txtRotate >= 360) { txtRotate = 0; }
if (txtRotates <= -180) { txtRotates = 180; }
txtRotate = a 1;
txtRotates -= a;
try
{
Rotate(txtRotate); Rotatet(txtRotates);
}
catch (Exception) { }
Thread s = new Thread(loging); Thread.Sleep(10); s.Start();
}
#region 图片旋转函数
/// <summary>
/// 以逆时针为方向对图像进行旋转
/// </summary>
/// <param name="angle">旋转角度[0,360](前台给的)</param>
/// <returns></returns>
public void Rotate(int angle)
{
try
{
Image ing = Properties.Resources.run;
angle = angle % 360;
//弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = ing.Width;
int h = ing.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//计算偏移量
Point Offset = new Point((W - w) / 2, (H - h) / 2);
//构造图像显示区域:让图像的中心与窗口的中心点一致
Rectangle rect = new Rectangle(0, 0, w, h);
Point center = new Point(rect.X rect.Width / 2, rect.Y rect.Height / 2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(360 - angle);
//恢复图像在水平和垂直方向的平移
g.TranslateTransform(-center.X, -center.Y);
g.DrawImage(ing, rect);
//重至绘图的所有变换
g.ResetTransform();
g.Save();
g.Dispose();
//dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
pictureBox1.Image = dsImage;
}catch (Exception) { }
}
public void Rotatet(int angle)
{
try {
Image ing = Properties.Resources.run;
angle = angle % 360;
//弧度转换
double radian = angle * Math.PI / 180.0;
double cos = Math.Cos(radian);
double sin = Math.Sin(radian);
//原图的宽和高
int w = ing.Width;
int h = ing.Height;
int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos h * sin)));
int H = (int)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin h * cos)));
//目标位图
Bitmap dsImage = new Bitmap(W, H);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//计算偏移量
Point Offset = new Point((W - w) / 2, (H - h) / 2);
//构造图像显示区域:让图像的中心与窗口的中心点一致
Rectangle rect = new Rectangle(0, 0, w, h);
Point center = new Point(rect.X rect.Width / 2, rect.Y rect.Height / 2);
g.TranslateTransform(center.X, center.Y);
g.RotateTransform(360 - angle);
//恢复图像在水平和垂直方向的平移
g.TranslateTransform(-center.X, -center.Y);
g.DrawImage(ing, rect);
//重至绘图的所有变换
g.ResetTransform();
g.Save();
g.Dispose();
//dsImage.Save("yuancd.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
pictureBox1.BackgroundImage = dsImage;
}
catch (Exception) { }
}
#endregion 图片旋转函数
private void PopulateIncludeFolders()
{
Properties.Settings.Default.includedFolders = new System.Collections.Specialized.StringCollection();
Properties.Settings.Default.includedFolders.Add(Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.User));
Properties.Settings.Default.includedFolders.Add(Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.Machine));
Properties.Settings.Default.includedFolders.Add(Environment.GetFolderPath(Environment.SpecialFolder.Recent));
Properties.Settings.Default.includedFolders.Add(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));
}
private void PopulateDiskDrives()
{
if (Properties.Settings.Default.diskDrives == null)
Properties.Settings.Default.diskDrives = new System.Collections.ArrayList();
else
Properties.Settings.Default.diskDrives.Clear();
string winDir = Environment.GetFolderPath(Environment.SpecialFolder.System);
foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
{
if (!driveInfo.IsReady || driveInfo.DriveType != DriveType.Fixed)
continue;
string freeSpace = Utils.ConvertSizeToString(driveInfo.TotalFreeSpace);
string totalSpace = Utils.ConvertSizeToString(driveInfo.TotalSize);
ListViewItem listViewItem = new ListViewItem(new string[] { driveInfo.Name, driveInfo.DriveFormat, totalSpace, freeSpace });
if (winDir.Contains(driveInfo.Name))
listViewItem.Checked = true;
listViewItem.Tag = driveInfo;
// Store as listviewitem cause im too lazy
Properties.Settings.Default.diskDrives.Add(listViewItem);
}
}
bool jIa = false;
//系统设置
private void Options(object sender, EventArgs e)
{
Options options = new Options();
options.ShowDialog(this);
}
//扫描硬盘
private void ScanDisk(object sender, EventArgs e)
{
button1.Enabled = false;
label6.Text = "正在扫描"; pictureBox2.Image = Properties.Resources.av_scaning_warn;
myList.Height = 197; jIa = true; Thread j = new Thread(jias); j.Start();
Thread ts = new Thread(scan);
ts.IsBackground = true;
ts.Start();
}
static int ashu = 0; static int ass = 0;
//删除文件
private void CleanDisk(object sender, EventArgs e)
{
if (this.listViewProblems.Items.Count == 0)
{ }
else
{
ashu = 0; ass = 0;
this.BackColor = Color.FromArgb(70, 130, 180);
cano.Height = 0; Case.Height = 0;
pictureBox2.Height = 100;
label2.Height = 0;
label6.Text = "正在优化"; pictureBox2.Image = Properties.Resources.av_scaning_safe;
jIa = true; Thread j = new Thread(jias); j.Start(); Thread ts = new Thread(detete);
ts.IsBackground = true;
ts.Start();
}
}
public void scan()
{
try
{
this.myList.Items.Clear();
this.listViewProblems.Items.Clear();
DateTime timeStarted = DateTime.Now;
List<DriveInfo> selDrives = new List<DriveInfo>();
foreach (ListViewItem lvi in Properties.Settings.Default.diskDrives)
{
if (lvi.Checked)
selDrives.Add(lvi.Tag as DriveInfo);
}
if (selDrives.Count == 0)
{
MessageBox.Show(this, "没有选定驱动器", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Analyze analyze = new Analyze(selDrives);
DialogResult dlgResult = analyze.ShowDialog(this);
if (dlgResult == System.Windows.Forms.DialogResult.OK)
{
this.not.ShowBalloonTip(6000, "Tom", "分析了硬盘驱动器", ToolTipIcon.Info);
this.m_watcher.EventPeriod("Main", "Scan", (int)DateTime.Now.Subtract(timeStarted).TotalSeconds, true);
}
else
{
this.not.ShowBalloonTip(6000, "Tom", "中止对硬盘驱动器", ToolTipIcon.Info);
this.m_watcher.EventPeriod("Main", "Scan", (int)DateTime.Now.Subtract(timeStarted).TotalSeconds, false);
}
label6.Text = "分析结果";
pictureBox2.Height = 0;
label2.Height = 118;
MySkin.Controls.MyListBoxItem it = new MySkin.Controls.MyListBoxItem("待处理");
myList.Items.Add(it);
it.IsOpen = true;
int zosize = 0;
jIa = false; Thread j = new Thread(jias); j.Start();
foreach (FileInfo fileInfo in Analyze.fileList)
{
ashu = ashu = 1;
string fileName = fileInfo.Name;
string filePath = fileInfo.DirectoryName;
string fileSize = Utils.ConvertSizeToString(fileInfo.Length);
zosize = zosize System.Int32.Parse(Utils.CSize(fileInfo.Length)) / 1024;
MySkin.Controls.MyListBoxSubItem sub = new MySkin.Controls.MyListBoxSubItem();
it.SubItems.Add(sub);
sub.DisplayName = fileName;
sub.NicName = fileSize;
sub.PersonalMsg = filePath;
label2.Text = zosize.ToString();
ListViewItem listViewItem = new ListViewItem(new string[] { fileName, filePath, fileSize });
listViewItem.Checked = true;
listViewItem.Tag = fileInfo;
this.listViewProblems.Items.Add(listViewItem);
}
label6.Text = "KB";
if (zosize > 1024)
{ zosize = zosize / 1024; label2.Text = zosize.ToString(); label6.Text = "MB"; }
if (zosize > 1024)
{ zosize = zosize / 1024; label2.Text = zosize.ToString(); label6.Text = "GB"; }
this.listViewProblems.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
cano.Height = 12; Case.Height = 12;
if (Properties.Settings.Default.autoClean)
CleanDisk(this, new EventArgs());
}
catch (Exception)
{
button1.Enabled = true;
jIa = false; a = 1;
cano.Height = 0; Case.Height = 0;
label6.Text = "电脑很安全";
pictureBox2.Height = 100;
label2.Height = 0;
myList.Height = 0;
listViewProblems.Clear();
myList.Items.Clear(); pictureBox2.Image = Properties.Resources.av_scaning_safe;
}
}
public void jias() {
if (jIa)
{
a ;
if (a <= 15)
{ Thread j = new Thread(jias); Thread.Sleep(100); j.Start(); }
else {
return;
}
}
else {
a--;
if (a > 1) {
Thread j = new Thread(jias); Thread.Sleep(500); j.Start();
}
else
{
a = 1;
return;
}
}
}
public void detete()
{
long lSeqNum = 0;
SysRestore.StartRestore("Before Tom Cleaning", out lSeqNum);
foreach (ListViewItem lvi in this.listViewProblems.Items)
{
try
{
FileInfo fileInfo = lvi.Tag as FileInfo;
// Make sure file exists
if (!fileInfo.Exists)
continue;
if (Properties.Settings.Default.removeMode == 0)
{
// Remove permanately
fileInfo.Delete();
}
else if (Properties.Settings.Default.removeMode == 1)
{
// Recycle file
Utils.SendFileToRecycleBin(fileInfo.FullName);
}
else
{
// Move file to specified directory
if (!Directory.Exists(Properties.Settings.Default.moveFolder))
Directory.CreateDirectory(Properties.Settings.Default.moveFolder);
File.Move(fileInfo.FullName, string.Format(@"{0}\{1}", Properties.Settings.Default.moveFolder, fileInfo.Name));
}
}
catch (Exception ex)
{
this.m_watcher.Exception(ex);
}
if (lSeqNum != 0)
{
SysRestore.EndRestore(lSeqNum);
}
this.m_watcher.Event("Main", "Clean");
}
jIa = false; Thread j = new Thread(jias); j.Start();
// Clear problems
this.listViewProblems.Items.Clear();
Analyze.fileList.Clear();
// Disable clean disk
this.myList.Items.Clear(); label6.Text = "电脑很安全"; myList.Height = 0;
this.not.ShowBalloonTip(6000, "Tom", "成功清除文件从磁盘", ToolTipIcon.Info); button1.Enabled = true;
}
//全选
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.listViewProblems.Items.Count > 0)
{
foreach (ListViewItem lvi in this.listViewProblems.Items)
lvi.Checked = true;
}
}
//清空
private void selectNoneToolStripMenuItem_Click(object sender, EventArgs e)
{
ashu = 0; ass = 0;
this.BackColor = Color.FromArgb(70, 130, 180);
cano.Height = 0; Case.Height = 0;
label6.Text = "电脑很安全";
pictureBox2.Height = 100;
label2.Height = 0;
myList.Height = 0;
listViewProblems.Clear();
myList.Items.Clear(); pictureBox2.Image = Properties.Resources.av_scaning_safe; button1.Enabled = true;
}
//打开文件
private void toolStripButtonOpenFile_Click(object sender, EventArgs e)
{
if (this.listViewProblems.SelectedItems.Count > 0)
{
FileInfo fileInfo = this.listViewProblems.SelectedItems[0].Tag as FileInfo;
// Make sure file exists
if (!fileInfo.Exists)
return;
this.m_watcher.Event("Main", "Open File");
// Open file
try
{
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(fileInfo.FullName);
procStartInfo.ErrorDialog = true;
procStartInfo.ErrorDialogParentHandle = this.Handle;
System.Diagnostics.Process.Start(procStartInfo);
}
catch (Exception ex)
{
MessageBox.Show(this, "Error opening file: " ex.Message, "Tom", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
//文件属性
private void toolStripButtonProperties_Click(object sender, EventArgs e)
{
if (this.listViewProblems.SelectedItems.Count > 0)
{
FileInfo fileInfo = this.listViewProblems.SelectedItems[0].Tag as FileInfo;
// Make sure file exists
if (!fileInfo.Exists)
return;
Utils.ShowFileProperties(fileInfo.FullName);
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
this.m_watcher.Stop();
Application.Exit();
System.Environment.Exit(0);
this.Dispose();
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
// Dont close if not accepted
e.Cancel = !AskIfClose();
if (e.Cancel)
return; else
Application.Exit();
System.Environment.Exit(0);
this.Dispose();
}
this.m_watcher.Stop();
}
private void HideShow(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
else
{
this.Hide();
this.WindowState = FormWindowState.Minimized;
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
else
{
this.Hide();
this.WindowState = FormWindowState.Minimized;
}
}
//系统还原
private void restoreSystemToolStripMenuItem_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(Application.StartupPath "\\Acceleration.exe"))
{
System.Diagnostics.Process.Start(Application.StartupPath "\\Acceleration.exe");
}
else
{
Byte[] bt = Properties.Resources.Acceleration;
System.IO.File.WriteAllBytes(Application.StartupPath "\\Acceleration.exe", bt);
System.Diagnostics.Process.Start(Application.StartupPath "\\Acceleration.exe");
}
}
private bool AskIfClose()
{
bool blnClose = false;
//If asking disabled or user accepted
if (MessageBox.Show(this, "确定退出吗?", "退出", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
blnClose = true;
}
else
{
blnClose = false;
}
return blnClose;
}
//计划安排
private void schedulerToolStripMenuItem_Click(object sender, EventArgs e)
{
Scheduler scheduler = new Scheduler();
scheduler.ShowDialog(this);
}
private void Main_Shown(object sender, EventArgs e)
{
foreach (string arg in Environment.GetCommandLineArgs())
{
if (arg == "/scan")
{
ScanDisk(this, new EventArgs());
}
}
}
private void PicClose_MouseEnter(object sender, EventArgs e)
{
PicClose.Image = Properties.Resources.btn_close_highlight;
}
private void PicClose_MouseLeave(object sender, EventArgs e)
{
PicClose.Image = Properties.Resources.btn_close_disable;
}
private void PicClose_MouseDown(object sender, MouseEventArgs e)
{
PicClose.Image = Properties.Resources.btn_close_down;
}
private void MoveDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE HTCAPTION, 0);
}
private void linkLabel4_Click(object sender, EventArgs e)
{
if (System.IO.File.Exists(Application.StartupPath "\\FileKiller.exe"))
{
System.Diagnostics.Process.Start(Application.StartupPath "\\FileKiller.exe");
}
else
{
Byte[] bt = Properties.Resources.FileKiller;
System.IO.File.WriteAllBytes(Application.StartupPath "\\FileKiller.exe", bt);
bt = Properties.Resources.handle;
System.IO.File.WriteAllBytes(Application.StartupPath "\\handle.exe", bt);
System.Diagnostics.Process.Start(Application.StartupPath "\\FileKiller.exe");
}
AddFile("强力删除文件", Application.StartupPath "\\FileKiller.exe");
}
private void AddFile(string itemName, string associatedProgramFullPath)
{
//创建项:shell
RegistryKey shellKey = Registry.ClassesRoot.OpenSubKey(@"*\shell", true);
if (shellKey == null)
{
shellKey = Registry.ClassesRoot.CreateSubKey(@"*\shell");
}
//创建项:右键显示的菜单名称
RegistryKey rightCommondKey = shellKey.CreateSubKey(itemName);
RegistryKey associatedProgramKey = rightCommondKey.CreateSubKey("command");
//创建默认值:关联的程序
associatedProgramKey.SetValue(string.Empty, associatedProgramFullPath);
//刷新到磁盘并释放资源
associatedProgramKey.Close();
rightCommondKey.Close();
shellKey.Close();
}
private void picMin_MouseEnter(object sender, EventArgs e)
{
picMin.BackgroundImage = Properties.Resources.skin_click;
}
private void picMin_MouseLeave(object sender, EventArgs e)
{
picMin.BackgroundImage = Properties.Resources.skin;
}
private void toolStripMenuItemAbout_Click(object sender, EventArgs e)
{
About s = new About();s.Show();
}
private void label4_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Update = true; Properties.Settings.Default.Save();
}
}
}