Ejemplo n.º 1
0
 private void LoadFiles(string dir, FileHash.Class.FileHash root)
 {
     if (Directory.Exists(dir))
     {
         string[] files = Directory.GetFiles(dir);
         foreach (var f in files)
         {
             FileInfo finfo = new FileInfo(f);
             FileHash.Class.FileHash sub = new FileHash.Class.FileHash()
             {
                 Name = finfo.Name, Type = 1, ParentDir = root.Name
             };
             sub.Hash256V = ReadFileHash256(f);
             root.ChildList.Add(sub);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载目录
        /// </summary>
        private void LoadDirectory(string dir, FileHash.Class.FileHash root)
        {
            if (Directory.Exists(dir))
            {
                LoadFiles(dir, root);

                string[] subDirs = Directory.GetDirectories(dir);
                foreach (var d in subDirs)
                {
                    DirectoryInfo           sdinfo = new DirectoryInfo(d);
                    FileHash.Class.FileHash sbhash = new FileHash.Class.FileHash()
                    {
                        Name = sdinfo.Name, Type = 2, ParentDir = root.Name
                    };
                    LoadDirectory(d, sbhash);
                    root.ChildList.Add(sbhash);
                }
            }
        }
Ejemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.AppendHeader("Content-Disposition", "attachment; filename=json.txt");
            //string user = this.User.Identity.UserName;
            string downpath = filePath.Replace(@"\", @"/");

            downpath = @"/" + downpath;
            downpath = context.Request.Url.Scheme + "://" + context.Request.Url.Host + ":" + context.Request.Url.Port + downpath + "/json.txt";

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                string directory = AppDomain.CurrentDomain.BaseDirectory;

                if (Directory.Exists(directory))
                {
                    DirectoryInfo dirinfo        = new DirectoryInfo(directory);
                    FileHash.Class.FileHash root = new FileHash.Class.FileHash()
                    {
                        Name = dirinfo.Name, Type = 2
                    };

                    LoadDirectory(directory, root);
                    string json = Newtonsoft.Json.JsonConvert.SerializeObject(root, Newtonsoft.Json.Formatting.Indented);
                    SaveFile(json);
                    //context.Response.Write(json);
                }
            }).ContinueWith(refTak =>
            {
            });

            context.Response.Write("正在生成hash JSON文件,生成完成后,请收到站内查看,链接地址:" + downpath);
        }