zoukankan      html  css  js  c++  java
  • FreeEverything基于everything的一个简易磁盘清理工具

    用Visual Studiode attach to process调试时,无论你有没有设置symbol path,Visual Studio都会把下载的symbol乱放,特别是会放到solution下面,导致文件夹很乱,所以写了一个小工具来删除这些symbol文件夹。同时也能删除resharper和mstest的临时文件。

    Everything是一个非常快的磁盘搜索,正好基于他的SDK来做这个小工具。

    界面如下:

    image

    搜索因为是基于Everything的,所以很快。可以增加新的过滤,用正则表达式搜索,这些过滤存放在启动目录下的GarbageCan.xml里面。还能对搜索到的结果计算大小(如果文件很多会比较慢)。

    源代码放在Github上,可执行文件在这里下载。

    1. 使用MVVMLight这个mvvm的框架,这个框架很容易上手。

    2. 使用XmlSerializer存储filter配置文件。

    3. 检查everything是否启动。

    public static void StartEverything()
            {
                Regex regex = new Regex(@"Everything([-.0-9])");
                bool found = false;
                foreach (var process in Process.GetProcesses())
                {
                    if (regex.Match(process.ProcessName).Success)
                    {
                        found = true;
                        break;
                    }
    
                }
                if (!found)
                {
                    ProcessStartInfo processStartInfo = new ProcessStartInfo(@"ThirdParty\Everything.exe");
                    processStartInfo.CreateNoWindow = true;
                    processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    Process.Start(processStartInfo);
                    m_EverythingLaunch = true;
                }
            }

    4. 调用Everything SDK. Everything SDK上面就有C#的示例project,非常简单。

    5. 删除文件。需要处理readonly的问题。

    private static void deletePath(string path)
            {
                FileSystemInfo fsi;
                if (File.Exists(path))
                {
                    fsi = new FileInfo(path);
                }
                else if (Directory.Exists(path))
                {
                    fsi = new DirectoryInfo(path);
    
                }
                else
                {
                    return;
                }
                deleteFileSystemInfo(fsi);
            }
            private static void deleteFileSystemInfo(FileSystemInfo fsi)
            {
    
                fsi.Attributes = FileAttributes.Normal;
                var di = fsi as DirectoryInfo;
    
                if (di != null)
                {
                    foreach (var dirInfo in di.GetFileSystemInfos())
                    {
                        deleteFileSystemInfo(dirInfo);
                    }
                }
                fsi.Delete();
            }

    6. 计算文件大小。

    public void CalculateSize()
            {
                if(Directory.Exists(Path))
                {
                    double result = 0;
                    foreach (FileInfo file in new DirectoryInfo(Path).GetFiles("*", SearchOption.AllDirectories))
                        result = result + file.Length;
                    Size = result;
                }
                else if (File.Exists(Path))
                {
                    Size = new FileInfo(Path).Length;
                }
            }
  • 相关阅读:
    大型网站调试工具之一(php性能优化分析工具XDebug)
    2.0控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox
    C#程序开发范例_IC卡读写
    数据库连接池技术
    控件之DataGrid, DatePicker, Grid, GridSplitter, HyperlinkButton, Image
    软件工程师职业总结
    "EMQ Meetup北京"技术沙龙分享会
    EMQ X Enterprise 新功能 Rule Engine 介绍
    基于 MySQL 的 EMQ X Auth & ACL
    MQTT 5.0 新特性(三)— 有效载荷标识与内容类型
  • 原文地址:https://www.cnblogs.com/fresky/p/2678502.html
Copyright © 2011-2022 走看看