예제 #1
0
        /// <summary>
        /// 获取文件(所有目录)(严格模式:从第一个.开始截取后缀)
        /// </summary>
        /// <param name="paths">路径(支持多个路径)</param>
        /// <param name="patterns">通配符(支持多个通配符)</param>
        /// <returns></returns>
        public static List <string> GetAllFileByExt(string[] paths, string[] patterns)
        {
            List <string> result = new List <string>();

            if (!ListTool.IsNullOrEmpty(paths))
            {
                foreach (var path in paths)
                {
                    List <string> temp = GetAllFile(path);
                    if (!ListTool.IsNullOrEmpty(temp))
                    {
                        result.AddRange(temp);
                    }
                }
            }
            if (!ListTool.IsNullOrEmpty(patterns) && !ListTool.IsNullOrEmpty(result))
            {
                for (int i = result.Count() - 1; i >= 0; i--)
                {
                    string ext = System.IO.Path.GetFileName(result[i]);
                    if (ext.IndexOf('.') >= 0)
                    {
                        ext = ext.Substring(ext.IndexOf('.'));
                    }
                    if (!patterns.Contains(ext))
                    {
                        result.RemoveAt(i);
                    }
                }
            }
            return(result);
        }
예제 #2
0
 private void BtBuild_Click(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() =>
     {
         this.Invoke(new Action(() => { LbResult.Text = "开始检索并生成目录文件,请稍候……"; }));
         beginTime            = DateTime.Now;
         string path          = TbPath.Text;
         string parentPath    = DirTool.Parent(path);
         FileCodeHelper fcode = new FileCodeHelper();
         if (Directory.Exists(path) && Directory.Exists(parentPath))
         {
             List <string> fileList = FileTool.GetAllFile(path);
             if (!ListTool.IsNullOrEmpty(fileList))
             {
                 VersionModel version = new VersionModel()
                 {
                     Number = DateTime.Now.Second, Path = path, FileList = new List <VersionFile>(),
                 };
                 foreach (var item in fileList)
                 {
                     version.FileList.Add(new VersionFile()
                     {
                         File = item.Replace(path, ""),
                         MD5  = fcode.GetMD5(item),
                     });
                 }
                 string file = string.Format(@"{0}\version.txt", parentPath);
                 string json = JsonTool.ToStr(version);
                 TxtTool.Create(file, json);
             }
         }
         endTime = DateTime.Now;
         this.Invoke(new Action(() => { LbResult.Text = string.Format("生成完成,用时:{0}秒。", (endTime - beginTime).TotalSeconds); }));
     });
 }
예제 #3
0
파일: TxtTool.cs 프로젝트: Crazyers/Fork
        public static long CountLine(string file, string[] filter)
        {
            long count = 0;

            try
            {
                using (StreamReader sr = new StreamReader(file, Encoding.UTF8))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        bool access = true;
                        if (!ListTool.IsNullOrEmpty(filter))
                        {
                            foreach (var f in filter)
                            {
                                if (line.Trim() == f)
                                {
                                    access = false;
                                }
                            }
                        }
                        if (access)
                        {
                            count++;
                        }
                    }
                }
            }
            catch (Exception e) { }
            return(count);
        }
예제 #4
0
        /// <summary>
        /// 获取文件(多个目录)
        /// </summary>
        /// <param name="paths">路径(支持多个路径)</param>
        /// <param name="patterns">通配符(支持多个通配符)</param>
        /// <returns></returns>
        public static List <string> GetAllFile(List <string> paths, string[] patterns = null)
        {
            List <string> result = new List <string>();

            if (!ListTool.IsNullOrEmpty(paths))
            {
                foreach (var path in paths)
                {
                    if (!ListTool.IsNullOrEmpty(patterns))
                    {
                        foreach (var pattern in patterns)
                        {
                            List <string> temp = GetFile(path, pattern);
                            if (ListTool.HasElements(temp))
                            {
                                result.AddRange(temp);
                            }
                        }
                    }
                    else
                    {
                        List <string> temp = GetFile(path);
                        if (!ListTool.IsNullOrEmpty(temp))
                        {
                            result.AddRange(temp);
                        }
                    }
                }
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// 删除文件(多个)
        /// </summary>
        /// <param name="files">文件路径(支持多个文件路径)</param>
        /// <returns></returns>
        public static bool Delete(string[] files)
        {
            bool result = true;

            if (!ListTool.IsNullOrEmpty(files))
            {
                foreach (var file in files)
                {
                    result = result || Delete(file);
                }
            }
            return(result);
        }
예제 #6
0
파일: Form1.cs 프로젝트: zyj0021/Fork
 /// <summary>
 /// 清理之前版本遗留文件及空文件夹
 /// </summary>
 /// <returns></returns>
 void CleanFile()
 {
     UIPbStatus(0);
     #region  除下载的更新文件和版本文件
     try
     {
         Directory.Delete(R.AppPath + @"Temp\Update\", true);
         File.Delete(R.VersionFile);
     }
     catch { }
     #endregion
     UIPbStatus(50);
     if (version.DoClean)
     {
         #region  除非当前版本文件
         List <string> file = FileTool.GetAllFile(R.AppPath);
         if (!ListTool.IsNullOrEmpty(file))
         {
             foreach (var f in file)
             {
                 int c = version.FileList.Where(x => x.File == "\\" + f.Replace(R.AppPath, "")).Count();
                 if (c == 0)
                 {
                     try { File.Delete(f); } catch { }
                 }
             }
             Thread.Sleep(R.cst.WAIT_TIME);
         }
         #endregion
         #region  除空文件夹
         List <string> path = DirTool.GetAllPath(R.AppPath);
         if (!ListTool.IsNullOrEmpty(path))
         {
             path = path.OrderByDescending(x => x).ToList();
             foreach (var p in path)
             {
                 if (Directory.GetFiles(p).Length == 0 && Directory.GetDirectories(p).Length == 0)
                 {
                     if (Directory.Exists(p))
                     {
                         try { Directory.Delete(p); } catch { }
                     }
                 }
                 Thread.Sleep(R.cst.WAIT_TIME);
             }
         }
         #endregion
     }
     UIPbStatus(100);
     Step = 5;
 }
예제 #7
0
        public static void ReadFromWeb()
        {
            Frisbee = HttpTool.Get <Frisbee[]>(ServerUrl);
            if (ListTool.IsNullOrEmpty(Frisbee))
            {
                R.Log.e("从服务器读取配置失败 准备第二次尝试");
                Frisbee = HttpTool.Get <Frisbee[]>(ServerUrl);

                if (ListTool.IsNullOrEmpty(Frisbee))
                {
                    R.Log.e("从服务器读取配置失败 准备第三次尝试");
                    Frisbee = HttpTool.Get <Frisbee[]>(ServerUrl);
                }
            }
        }
예제 #8
0
        public static bool ExistFile(string[] names)
        {
            bool flag = false;

            if (!ListTool.IsNullOrEmpty(names))
            {
                foreach (var n in names)
                {
                    if (ExistFile(n))
                    {
                        return(true);
                    }
                }
            }
            return(flag);
        }
예제 #9
0
        /// <summary>
        /// 获取文件(所有目录)
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="pattern">通配符(支持多个通配符)</param>
        /// <returns></returns>
        public static List <string> GetAllFile(string path, string[] pattern)
        {
            List <string> result = new List <string>();

            if (!ListTool.IsNullOrEmpty(pattern))
            {
                foreach (var p in pattern)
                {
                    List <string> temp = GetAllFile(path, p);
                    if (!ListTool.IsNullOrEmpty(temp))
                    {
                        result.AddRange(temp);
                    }
                }
            }
            return(result);
        }
예제 #10
0
파일: Form1.cs 프로젝트: zyj0021/Fork
        /// <summary>
        /// 更新结束启动程序
        /// </summary>
        void EndRunProcess()
        {
            int percent = 1;

            if (!ListTool.IsNullOrEmpty(version.EndRunProcess))
            {
                foreach (var p in version.EndRunProcess)
                {
                    Thread.Sleep(R.cst.WAIT_TIME);
                    UIPbStatus((int)((double)(percent++) / version.EndRunProcess.Count() * 100));
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        ProcessTool.Start(Path.Combine(R.AppPath, p));
                    }
                }
            }
        }
예제 #11
0
 public static void KillProcess(Frisbee f)
 {
     if (!ListTool.IsNullOrEmpty(f.KillProcess))
     {
         foreach (var r in f.KillProcess)
         {
             if (!string.IsNullOrWhiteSpace(r))
             {
                 ProcessTool.KillProcess(r);
             }
         }
         R.Log.i("结束进程完成 共" + f.KillProcess.Count() + "项");
     }
     else
     {
         R.Log.i("结束进程列表为空");
     }
 }
예제 #12
0
파일: Form1.cs 프로젝트: zyj0021/Fork
        /// <summary>
        /// 更新开始结束程序
        /// </summary>
        void BeginCloseProcess()
        {
            int percent = 1;

            if (!ListTool.IsNullOrEmpty(version.BeginCloseProcess))
            {
                foreach (var p in version.BeginCloseProcess)
                {
                    Thread.Sleep(R.cst.WAIT_TIME);
                    UIPbStatus((int)((double)(percent++) / version.BeginCloseProcess.Count() * 100));
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        ProcessTool.Kill(p);
                    }
                }
            }
            Step = 2;
        }
예제 #13
0
 public static void RunProcess(Frisbee f)
 {
     if (!ListTool.IsNullOrEmpty(f.RunProcess))
     {
         foreach (var r in f.RunProcess)
         {
             if (!string.IsNullOrWhiteSpace(r))
             {
                 ProcessTool.StartProcess(r);
             }
         }
         R.Log.i("进程已启动 共" + f.RunProcess.Count() + "项");
     }
     else
     {
         R.Log.i("启动进程列表为空");
     }
 }
예제 #14
0
        private void CheckRestart()
        {
            var rest = false;

            var instance = NetCardInfoTool.GetInstanceNames();

            if (ListTool.IsNullOrEmpty(NetFlow.Instances) && ListTool.HasElements(instance))
            {
                rest = true;
            }
            if (ListTool.HasElements(NetFlow.Instances) && ListTool.HasElements(instance) &&
                string.Join(@"-", NetFlow.Instances) != string.Join(@"-", instance))
            {
                rest = true;
            }

            if (rest)
            {
                //重启 系统性能计数器
                NetFlow.Restart();
                //重启 抓包监听
                var hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        if (NetPacketList.All(x => x.IP.ToString() != host.ToString()))
                        {
                            var p = new NetPacketTool(host);
                            p.NewPacket += NewPacketEvent;
                            p.Start();
                            NetPacketList.Add(p);
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
        }
예제 #15
0
        public static List <string> GetAllPath(string path)
        {
            List <string> result = GetPath(path);

            if (!ListTool.IsNullOrEmpty(result))
            {
                List <string> temp = new List <string>();
                foreach (var item in result)
                {
                    List <string> t = GetAllPath(item);
                    if (!ListTool.IsNullOrEmpty(t))
                    {
                        temp.AddRange(t);
                    }
                }
                result.AddRange(temp);
                return(result);
            }
            return(null);
        }
예제 #16
0
파일: TxtTool.cs 프로젝트: Crazyers/Fork
 public static bool Append(string file, List <string> txt)
 {
     try
     {
         DirTool.Create(Path.GetDirectoryName(file));
         using (StreamWriter sw = new StreamWriter(file, true))
         {
             if (!ListTool.IsNullOrEmpty(txt))
             {
                 foreach (var t in txt)
                 {
                     sw.WriteLine(t);
                 }
             }
         }
         return(true);
     }
     catch (Exception e) { }
     return(false);
 }
예제 #17
0
        private void CreateVersionMap()
        {
            string versionNumber = TbVersionNumber.Text;
            string ftpPath       = TbFtpPath.Text;

            string[] beginClose = TbBeginClose.Text.Split(';');
            string[] endRun     = TbEndRun.Text.Split(';');

            string       path       = TbPath.Text;
            string       parentPath = DirTool.Parent(path);
            FileCodeTool fcode      = new FileCodeTool();

            if (Directory.Exists(path) && Directory.Exists(parentPath))
            {
                List <string> fileList = FileTool.GetAllFile(path);
                if (!ListTool.IsNullOrEmpty(fileList))
                {
                    VersionModel version = new VersionModel()
                    {
                        Number            = versionNumber,
                        ServerPath        = ftpPath,
                        BeginCloseProcess = beginClose,
                        EndRunProcess     = endRun,
                        FileList          = new List <VersionFile>()
                    };

                    foreach (var item in fileList)
                    {
                        version.FileList.Add(new VersionFile()
                        {
                            File = item.Replace(path, ""),
                            MD5  = fcode.GetMD5(item),
                        });
                    }
                    string file = string.Format(@"{0}\update.version", parentPath, versionNumber);
                    string json = JsonTool.ToStr(version);
                    TxtTool.Create(file, json);
                }
            }
        }
예제 #18
0
        /// <summary>
        /// 创建打包文件列表信息
        /// </summary>
        /// <param name="files"></param>
        /// <param name="srcPath"></param>
        /// <returns></returns>
        private static List <FilePackageModel> CreateFilePackageModel(List <string> files, string srcPath)
        {
            if (ListTool.IsNullOrEmpty(files))
            {
                return(null);
            }

            List <FilePackageModel> result = new List <FilePackageModel>();

            //汇总所有文件
            files.ForEach(x =>
            {
                result.Add(new FilePackageModel()
                {
                    Name = Path.GetFileName(x),
                    Path = DirTool.GetFilePath(x).Substring(srcPath.Count()),
                    Size = FileTool.Size(x),
                    MD5  = FileTool.GetMD5(x),
                });
            });
            return(result);
        }
예제 #19
0
        private void CheckRestart()
        {
            bool rest = false;

            string[] ints = NetCardInfoTool.GetInstanceNames();
            if (ListTool.IsNullOrEmpty(NetFlow.Instances) && ListTool.HasElements(ints))
            {
                rest = true;
            }
            if (ListTool.HasElements(NetFlow.Instances) && ListTool.HasElements(ints) &&
                string.Join("-", NetFlow.Instances) != string.Join("-", ints))
            {
                rest = true;
            }

            if (rest)
            {
                //重启 系统性能计数器
                NetFlow.Restart();
                //重启 抓包监听
                List <IPAddress> hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        if (!NetPacketList.Any(x => x.IP.ToString() == host.ToString()))
                        {
                            NetPacketTool p = new NetPacketTool(host);
                            p.NewPacket += new NewPacketEventHandler(NewPacketEvent);
                            p.Start();
                            NetPacketList.Add(p);
                        }
                    }
                    catch { }
                }
            }
        }
예제 #20
0
        public static void StartNetCapture()
        {
            int span = 0;

            if (!NetCaptureRun)
            {
                NetCaptureRun = true;
                Task.Factory.StartNew(() =>
                {
                    //获取实时数据包
                    #region 设置IP
                    var networkInfo = NetCardInfoTool.GetNetworkCardInfo();
                    if (!ListTool.IsNullOrEmpty(networkInfo))
                    {
                        IP = networkInfo[0].Item3;
                    }
                    #endregion
                    GetNetBag();
                    GetNetProcess();//获取联网进程

                    while (NetCaptureLoop)
                    {
                        //if (span >= 1)
                        //{
                        //    GetNetProcess();//获取联网进程
                        //    span = 0;
                        //}
                        Thread.Sleep(1000);
                        CalcBagFlow();//计算进程流量
                        span++;
                    }
                    NS.IsStart    = false;
                    NetCaptureRun = false;
                });
            }
        }
예제 #21
0
 /// <summary>
 /// 清理之前版本遗留文件及空文件夹
 /// </summary>
 /// <returns></returns>
 void CleanFile()
 {
     #region  除非当前版本文件
     List <string> file = FileTool.GetAllFile(AppDir);
     if (!ListTool.IsNullOrEmpty(file))
     {
         foreach (var f in file)
         {
             int c = version.FileList.Where(x => x.File == "\\" + f.Replace(AppDir, "")).Count();
             if (c == 0)
             {
                 File.Delete(f);
             }
         }
         Thread.Sleep(WAIT_TIME);
     }
     #endregion
     #region  除空文件夹
     List <string> path = DirTool.GetAllPath(AppDir);
     if (!ListTool.IsNullOrEmpty(path))
     {
         path = path.OrderByDescending(x => x).ToList();
         foreach (var p in path)
         {
             if (Directory.GetFiles(p).Length == 0 && Directory.GetDirectories(p).Length == 0)
             {
                 if (Directory.Exists(p))
                 {
                     Directory.Delete(p);
                 }
             }
             Thread.Sleep(WAIT_TIME);
         }
     }
     #endregion
 }