指定一个M3U8文件,判断它包含的TS文件是不是都存在。指定一个Office生成的Swf文件,判断它包含的Swf文件是不是完整都存在。

static void Main(string[] args)
        {
            //检查M3u8文件
            var fiPath =
                @"D:\Work\CloudPlatformUtil\CloudPlatformUtil\DoM3u8\M3u8\D5\D5B31B29-02B0-E0B5-AAFC-3406695D5E93.m3u8";
            var count = 0;
            var result=CheckM3U8RealTs(fiPath,out count);
            Console.WriteLine(result+"  "+count);


            //检查Office生成的swf
            fiPath = @"D:\BaiduNetdiskDownload\18\18CB654D-FDAC-664D-FE74-F64F884C8F52_1.swf";
            result=CheckOfficeSwf(fiPath, out count);
            Console.WriteLine(result + "  " + count);

            Console.ReadKey();
        }

        /// <summary>
        /// 功能:给定个office生成的swf文档,查询它共生成了多少个swf文件
        /// 作者:黄海
        /// 时间:2018-06-11
        /// </summary>
        /// <param name="fiPath"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static bool CheckOfficeSwf(string fiPath,out int count)
        {
            //计算fiPath所在的目录
            var fi = new FileInfo(fiPath);
            var di = fi.Directory;

            var files = Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories)
               .Where(s => s.EndsWith(".swf") && s.StartsWith(di.FullName + "\\" + fi.Name.Substring(0, 36).ToUpper())).ToArray();

            var result = true;
            count = 0;
            var dict=new Dictionary<int,int>();
            foreach (var o in files)
            {
                dict[int.Parse(o.Replace(di.FullName + "\\" + fi.Name.Substring(0, 36) + "_", "").Replace(".swf",""))] = 1;
            }

            for (var i = 1; i < dict.Count; i++)
            {
                if (!dict.ContainsKey(i))
                {
                    result = false;
                    break;
                }
                else
                {
                    count = count + 1;
                }
            }
            return result;
        }

        /// <summary>
        /// 功能:给定一个M3U8文件,检查它所在的目录下是不是存在了指定的TS文件,如果缺少1个或多个,则返回False
        /// 作者: 黄海
        /// 时间:2018-06-11
        /// </summary>
        /// <param name="fiPath"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static bool CheckM3U8RealTs(string fiPath,out int count)
        {
            //计算fiPath所在的目录
            var fi=new FileInfo(fiPath);
            var di = fi.Directory;
            var result = true;
            count = 0;
            //找到M3u8文件列表中的所有ts文件
            foreach (var line in File.ReadLines(fiPath))
            {
                //如果是有用的数据,不是以#开头的
                if (!(string.IsNullOrWhiteSpace(line) || line.StartsWith("#")))
                {
                    //这个TS文件是不是存在呢?
                    var fiTs = new FileInfo(di.FullName + "\\" + line);
                    if (!(File.Exists(fiTs.FullName) && (fiTs.Length > 0)))
                    {
                        result = false;
                        count = 0;
                        break;
                    }
                    else
                    {
                        count = count + 1;
                    }
                }
            }
            return result;
        }

 

posted @ 2018-06-11 20:46  糖豆爸爸  阅读(554)  评论(0编辑  收藏  举报
Live2D