Beispiel #1
0
        public static async Task CheckForUpdate()
        {
            if (File.Exists(TEMP_UPDATE_ZIP))
            {
                ExtractFiles();
            }
            else
            {
                using (var client = new WebClient())
                {
                    string releaseURL = Properties.Settings.Default["ReleaseURL"].ToString();
                    string releaseAPI = Properties.Settings.Default["ReleaseAPI"].ToString();
                    string userAgent  = Properties.Settings.Default["UserAgent"].ToString();
                    client.Headers["User-Agent"] = userAgent + Constants.VERSION;

                    string json = await client.DownloadStringTaskAsync(releaseAPI);

                    var serializer = new JavaScriptSerializer();

                    GithubReleaseModel model = serializer.Deserialize <GithubReleaseModel>(json);
                    if (model != null && model.tag_name != Constants.VERSION)
                    {
                        string text = $"An update is available.\r\n Click \"Yes\" to upgrade to {model.tag_name}. (This will restart the application)";

                        DialogResult dialogResult = MessageBox.Show(text, "Update Available", MessageBoxButtons.YesNo);
                        RestartOnComplete = (dialogResult == DialogResult.Yes);
                        await DoDownload(model.assets[0].browser_download_url);
                    }
                }
            }
        }
Beispiel #2
0
        public Downloader(GithubReleaseModel model)
        {
            _releaseModel = model;
            var match = Regex.Match(model.PatchNotes, @"SHA1: ([a-zA-Z0-9]*)");

            if (match.Success)
            {
                _sha1 = match.Value;
            }
        }
Beispiel #3
0
 private static bool ConfirmReleaseUpdate(GithubReleaseModel data)
 {
     if (new Version(data.VersionName).CompareTo(LastUpdate) <= 0)
     {
         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\nYour 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");
 }
Beispiel #4
0
        private static async Task Update(GithubReleaseModel data)
        {
            WriteLine("........................................");
            try
            {
                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 downloader = new Downloader(data);
                var arch       = await downloader.Download();

                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.VersionName);
                Directory.Delete(@"../NadekoBot_new", true);
                arch.Dispose();
                WriteLine("Done!");
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
 public GithubReleaseViewModel(GithubReleaseModel model, string version = "1.0")
 {
     _model            = model;
     _isCurrentVersion = _model.tag_name.Equals($"v{version}", StringComparison.OrdinalIgnoreCase);
 }