Ejemplo n.º 1
0
        private static void Update()
        {
            if (File.Exists(path: Config.SHAFile))
            {
                oldFileList = new ConcurrentDictionary <string, string>();
                MyUtil.MakeFileinfo(SHA: Config.oldSHA, fileinfo: oldFileList);
            }
            errorList = new ConcurrentDictionary <string, string>();
            All_num   = fileList.Count;
            Num       = 0;

            Download(); // 开始下载
            if (errorList.Count > 0)
            {
                Console.WriteLine(value: "Some of files failed to update ... ...");
                Console.WriteLine(value: "Please retry the update later.");
                MyUtil.SaveList(path: Config.errorFile, fileinfo: errorList);
            }
            else
            {
                // Save SHA Value
                MyUtil.CreateDir(path: Config.SHAFile);
                File.WriteAllText(path: Config.SHAFile, contents: Config.newSHA, encoding: Encoding.UTF8);
                Console.WriteLine(value: "Update success! Though keep this windows until [Press Any Key to continue ... ... ].");
            }
        }
Ejemplo n.º 2
0
        public static void Run()
        {
            Console.WriteLine(value: "");
            Console.WriteLine(value: $"DOWNLOAD NUMBER : {Config.count}");
            Console.WriteLine(value: $"UPDATE FROM : {Config.name}'s {Config.repo}");
            Console.WriteLine(value: $"DOWNLOAD TO : {Config.workPath}");
            Console.WriteLine(value: $"CONFIG FILE : {Assembly.GetExecutingAssembly().Location}.config");
            if (Config.ignoreSound)
            {
                Console.WriteLine(value: "ENABLE OPTION : IGNORE THE SOUND FILES");
            }
            Console.WriteLine(value: "");

            fileList = new ConcurrentDictionary <string, string>();
            if (File.Exists(path: Config.errorFile))
            {
                Console.WriteLine(value: "Failed to update previous time ... ...");
                Console.WriteLine(value: "Restarting Update ... ...");

                Parallel.ForEach(File.ReadAllLines(path: Config.errorFile, encoding: Encoding.UTF8), line =>
                {
                    if (line.Split(separator: '\t').Length >= 2)
                    {
                        fileList.TryAdd(key: line.Split(separator: '\t')[0], value: line.Split(separator: '\t')[1]);
                    }
                });
                Update(); // 开始更新
            }
            else if (File.Exists(path: Config.SHAFile) && Config.newSHA == Config.oldSHA)
            {
                // Match the SHA Key
                Console.WriteLine(value: $"{Config.name}'s {Config.repo} is already up-to-date!");
            }
            else
            {
                // 上一次下载是否失败
                Console.WriteLine(value: "Discovered New Version ... ...");
                Console.WriteLine(value: "Download Filelist ... ...");
                MyUtil.MakeFileinfo(SHA: Config.newSHA, fileinfo: fileList);
                Console.WriteLine(value: "Start Update and Download ... ...");
                Update(); // 开始更新
            }
        }