Beispiel #1
0
        public static void AddPassword(string dirPath, string password)
        {
            var fileList = Directory.GetFiles(dirPath, "*.*", SearchOption.TopDirectoryOnly).ToList();

            foreach (var filePath in fileList)
            {
                string fileName  = Path.GetFileNameWithoutExtension(filePath);
                string extension = Path.GetExtension(filePath);
                if (extension == ".txt")
                {
                    continue;
                }
                string newfileName = fileName + "[密码:{0}]".FormatStr(password);
                File.Move(filePath, dirPath + newfileName + extension);
            }
            CommonTools.Log("重命名完毕!");
        }
Beispiel #2
0
        /// <summary>
        /// 监听函数,不断调用计算新位置
        /// </summary>
        public void tick()
        {
            //重计算衰减值
            while (alpha > alphaMin)
            {
                alpha += (alphaTarget - alpha) * alphaDecay;
                //计算结点位置和速度
                forceLink();
                forceManyBody();
                forceCenter();

                for (int i = 0; i < Nodes.Count; i++)
                {
                    var node = Nodes[i];
                    node.x += node.vx *= velocityDecay;
                    node.y += node.vy *= velocityDecay;
                }
                CommonTools.Log("当前衰减率 - {0}".FormatStr(alpha));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 整理本子文件夹路径
        /// </summary>
        /// <param name="path"></param>
        public static void SortFile(string path)
        {
            string errfile = path + @"\error.txt";

            string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
            int      i     = 1;

            foreach (var file in files)
            {
                var name    = Path.GetFileName(file);
                var newPath = path + name;
                if (!File.Exists(newPath))
                {
                    File.Move(file, newPath);
                    CommonTools.Log("[{0}/{1}] - {2}".FormatStr(i, files.Length, name));
                }

                i++;
            }
            CommonTools.Log("处理完毕!");
        }
Beispiel #4
0
        /// <summary>
        /// 获取网页源代码
        /// </summary>
        /// <param name="url">网页链接</param>
        /// <returns></returns>
        public static string GetHtml(string url, string htmlCharset = "utf-8", int type = 0, IDictionary <string, object> parameters = null, CookieCollection cookies = null)
        {
            //Http请求
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            //设置用户代理,防止网站判定为用户代理
            req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; BOIE9;ZHCN)";
            //如果方法验证网页来源就加上这一句如果不验证那就可以不写了
            //req.Referer = "http://sufei.cnblogs.com";
            string html = "";

            try
            {
                switch (type)
                {
                case 0:
                {
                    //使用GET方法获取链接指向的网页
                    req.Method = "GET";
                    //添加Cookie,用来抓取需登陆可见的网页
                    CookieContainer objcok = new CookieContainer();
                    Cookie          cook1  = new Cookie();
                    //cook1.Name = "CNZZDATA1257708097";
                    //cook1.Value = "1167517418-1479817270-%7C1488717892";
                    //objcok.Add(cook1);
                    objcok.Add(new Cookie("LOGGED_USER", "2Gsu8lGqckigfryi4J%2BxqQ%3D%3D%3AEPYACL1Ic4QgUm9bW2hOXg%3D%3D", "/", ".bcy.net"));
                    req.CookieContainer = objcok;
                    //设置超时
                    req.Timeout = 5000;
                    //Http响应
                    HttpWebResponse resp;
                    resp = (HttpWebResponse)req.GetResponse();
                    Encoding htmlEncoding     = Encoding.GetEncoding(htmlCharset);
                    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream(), htmlEncoding);
                    //读取返回的网页
                    html = sr.ReadToEnd();
                    resp.Close();
                }
                break;

                case 1:
                {
                    HttpWebResponse        resp         = CreatePostHttpResponse(url, parameters, cookies);
                    Encoding               htmlEncoding = Encoding.GetEncoding(htmlCharset);
                    System.IO.StreamReader sr           = new System.IO.StreamReader(resp.GetResponseStream(), htmlEncoding);
                    //读取返回的网页
                    html = sr.ReadToEnd();
                    resp.Close();
                }
                break;

                default:
                    break;
                }

                return(html);
            }
            catch (Exception ex)
            {
                CommonTools.Log(ex.Message);
                return(null);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 整理本子文件夹路径
        /// </summary>
        /// <param name="path">文件夹路径</param>
        /// <param name="excludes">要排除的文件夹名称</param>
        public static void SortDir(string path, List <string> excludes)
        {
            string errfile = path + @"\error.txt";

            string[] dirs = Directory.GetDirectories(path);
            int      i    = 1;

            foreach (var x in dirs)
            {
                bool isEx = false;
                foreach (var y in excludes)
                {
                    if (x.Contains(y))
                    {
                        isEx = true;
                        break;
                    }
                }
                if (isEx)
                {
                    continue;
                }
                if (x.Contains("DearSexFriend"))
                {
                    int df = 324;
                }
                var   files = Directory.GetFiles(x).ToList();
                Regex reg   = new Regex(".txt|.url|.torrent");
                //Regex reg = new Regex(".rar|.txt|.zip|.url|.torrent");
                if (files.Count > 1)
                {
                    var errorFiles = files.FindAll(s => reg.IsMatch(s));
                    foreach (var item in errorFiles)
                    {
                        File.Delete(item);
                    }
                }
                else
                {
                    string[] temp = Directory.GetDirectories(x);
                    //if (temp.Length > 1)
                    //{
                    //    string name = Path.GetFileName(x);
                    //    File.AppendAllText(errfile, name + System.Environment.NewLine);
                    //    i++;
                    //    continue;
                    //}
                    if (temp.Length > 0)
                    {
                        int    j         = 0;
                        string childName = "";
                        foreach (var childDir in temp)
                        {
                            j++;
                            string name = Path.GetFileName(childDir);
                            if (temp.Length == 1)
                            {
                                childName = name;
                            }
                            string newDir = path + "\\" + name;
                            if (!Directory.Exists(newDir))
                            {
                                Directory.Move(childDir, newDir);
                            }
                            CommonTools.Log("[{0}/{1}] - [{2}/{3}]{4}".FormatStr(i, dirs.Length, j, temp.Length, name));
                        }
                        if (string.IsNullOrEmpty(childName))
                        {
                            Directory.Delete(x, true);
                        }
                        else
                        {
                            string name = Path.GetFileName(x);
                            if (name != childName)
                            {
                                Directory.Delete(x, true);
                            }
                        }
                    }
                }

                i++;
            }
            CommonTools.Log("处理完毕!");
        }