Beispiel #1
0
        public void Run(bool ignore_sound)
        {
            Console.WriteLine("UPDATE FROM:" + Config.url_home);
            Console.WriteLine("DOWNLOAD TO:" + Config.workPath);
            Console.WriteLine("CONFIG FILE:" + Assembly.GetExecutingAssembly().Location + ".config");

            if (!File.Exists(Config.errorFile))
            {
                Console.WriteLine("Getting New Version ... ...");
                //version
                MyHttp.DownLoad(Config.url_version, Config.newVersionFile);
                //版本号一致
                string md5_1 = MyUtil.MD5_File(Config.versionFile);
                string md5_2 = MyUtil.MD5_File(Config.newVersionFile);
                if (md5_1 == md5_2 && md5_1.Length > 0)
                {
                    Console.WriteLine("Your files are already up-to-date.");
                    return;
                }
                Console.WriteLine("New Version Discovered... ...");
                //删除旧文件
                Delete();
                //重命名文件
                Rename();
            }
            Console.Clear();
            //filelist
            Update(ignore_sound);
            if (File.Exists(Config.newVersionFile))
            {
                File.Delete(Config.versionFile);
                File.Move(Config.newVersionFile, Config.versionFile);
            }
            Console.WriteLine("UPDATE COMPLETE!! You can safely close this window, press any key to quit.");
        }
Beispiel #2
0
        private static void Download(string path, string url)
        {
            //线程数
            MyHttp.init(Config.ThreadNum);
            Client client = new Client(path, url);

            MyHttp.SetListner(client);
            client.Run();            //开始更新
        }
Beispiel #3
0
 public void Download()
 {
     if (MyHttp.NUM >= MyHttp.MAX_NUM)
     {
         return;
     }
     NUM++;
     TASK++;
     MyHttp.DownLoad(_url, _filename, _ff);
     NTASK++;
     NUM--;
 }
Beispiel #4
0
 void Update(bool ignore_sound)
 {
     if (!File.Exists(Config.errorFile))            //上一次下载是否失败
     {
         Console.WriteLine("Downloading Filelist... ...");
         if (!MyHttp.DownLoad(Config.url_filelist, Config.filelistFile))
         {
             return;
         }
         Console.WriteLine("Starting Update... ...");
     }
     else
     {
         File.Delete(Config.filelistFile);
         File.Move(Config.errorFile, Config.filelistFile);
         Console.WriteLine("Continuing Update... ...");
     }
     if (ignore_sound)
     {
         Console.WriteLine("The sound files will be ignored.");
     }
     string[] lines = File.ReadAllLines(Config.filelistFile, Encoding.UTF8);
     all_num = lines.Length;
     num     = 0;
     showProcess(num++, all_num);
     foreach (string line in lines)
     {
         if (!line.StartsWith("#"))
         {
             string[] words = line.Split('\t');
             if (words.Length >= 2)
             {
                 Download(words[0], words[1], false, ignore_sound);
             }
         }
     }
     while (!MyHttp.isOK())
     {
     }
     if (errorlist.Count > 0)
     {
         Console.WriteLine("Some of files failed to update... ...");
         MyUtil.saveList(Config.errorFile, errorlist.ToArray());
     }
 }
Beispiel #5
0
 void Delete()
 {
     if (!MyHttp.DownLoad(Config.url_delete, Config.deleteFile))
     {
         return;
     }
     string[] lines = File.ReadAllLines(Config.deleteFile, Encoding.UTF8);
     foreach (string line in lines)
     {
         if (!line.StartsWith("#"))
         {
             string file = Config.GetPath(line);
             if (File.Exists(file))
             {
                 Console.WriteLine("DELETE FILE:" + line);
                 File.Delete(file);
             }
         }
     }
 }
Beispiel #6
0
 void Rename()
 {
     if (!MyHttp.DownLoad(Config.url_rename, Config.renameFile))
     {
         return;
     }
     string[] lines = File.ReadAllLines(Config.renameFile, Encoding.UTF8);
     foreach (string line in lines)
     {
         if (!line.StartsWith("#"))
         {
             string[] files = line.Split('\t');
             if (files.Length >= 2)
             {
                 string file1 = Config.GetPath(files[0]);
                 string file2 = Config.GetPath(files[1]);
                 Console.WriteLine("RENAME:" + files[0] + "=>" + files[1]);
                 File.Move(file1, file2);
             }
         }
     }
 }
Beispiel #7
0
        public Client(string path, string url)
        {
            if (string.IsNullOrEmpty(path))
            {
                Config.setWorkPath(ConfigurationManager.AppSettings["path"], url);
            }
            else
            {
                Config.setWorkPath(path, url);
            }

            errorlist = new List <fileinfo>();

            //代理设置
            if (Config.useProxy)
            {
                Console.WriteLine("USE PROXY:" + Config.proxyIP + ":" + Config.proxyPort);
                MyHttp.setProxy(true, Config.proxyIP, Config.proxyPort);
            }
            else
            {
                MyHttp.setProxy(false, "127.0.0.1", 80);
            }
        }