示例#1
0
 private static bool ConfirmReleaseUpdate(GithubReleaseModel data)
 {
     if (data.PublishedAt <= LastUpdate)
     {
         WriteLine("You already have an up-to-date version!", ConsoleColor.Red);
         return(false);
     }
     WriteLine("Newer version found!\n\nAre you sure you want to update? (y or n)\n\n Your current version will be backed up to NadekoBot_old folder. Always check the github release page to see if credentials or config files need updating", ConsoleColor.Magenta);
     return(Console.ReadLine().ToLower() == "y" || Console.ReadLine().ToLower() == "yes");
 }
示例#2
0
        private static async Task Update(GithubReleaseModel data)
        {
            WriteLine("........................................");
            try
            {
                using (var httpClient = new HttpClient())
                    using (var cancelSource = new CancellationTokenSource())
                    {
                        var cancelToken = cancelSource.Token;
                        var waitTask    = Task.Run(async() => await Waiter(cancelToken));
                        Console.WriteLine("Downloading. Be patient. There is no need to open an issue if it takes long.");
                        var stream = await httpClient.GetStreamAsync(data.Assets[0].DownloadLink);

                        var arch = new ZipArchive(stream);
                        cancelSource.Cancel();
                        await waitTask;

                        if (Directory.Exists("../NadekoBot"))
                        {
                            WriteLine("Backing up old version...", ConsoleColor.DarkYellow);
                            if (Directory.Exists("../NadekobBot_old"))
                            {
                                Directory.Delete("../NadekoBot_old", true);
                            }
                            DirectoryCopy(@"../NadekoBot", @"../NadekoBot_old", true);
                        }
                        WriteLine("Saving...", ConsoleColor.Green);
                        arch.ExtractToDirectory(@"../NadekoBot_new");
                        DirectoryCopy(@"../NadekoBot_new", @"../NadekoBot", true);

                        File.WriteAllText("../version.txt", data.PublishedAt.ToString());
                        Directory.Delete(@"../NadekoBot_new", true);
                        WriteLine("Done!");
                    }
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }