ravibpatel / AutoUpdater.NET

AutoUpdater.NET is a class library that allows .NET developers to easily add auto update functionality to their classic desktop application projects.
MIT License
3.05k stars 771 forks source link

ParseUpdateInfoEvent never triggered? #645

Closed OssieFromDK closed 11 months ago

OssieFromDK commented 11 months ago
        internal void CheckForUpdates()
        {
            AutoUpdater.InstalledVersion = new Version(MainWindow.CurrVersion);
            AutoUpdater.Mandatory = true;
            AutoUpdater.UpdateMode = Mode.ForcedDownload;
            AutoUpdater.HttpUserAgent = "OssieFromDK";
            AutoUpdater.RunUpdateAsAdmin = true;
            AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent;

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                AutoUpdater.Start("https://api.github.com/repos/OssieFromDK/DeadByDaylight-Unlocker/releases/latest");
            }));
        }

        private void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args)
        {
            dynamic json = JsonConvert.DeserializeObject(args.RemoteData);

            args.UpdateInfo = new UpdateInfoEventArgs
            {
                CurrentVersion = json.tag_name,
                DownloadURL = json.assets.browser_download_url,
            };
        }

I have the following code, but the event is never triggered, and nothing happens, I read online the UserAgent had to be the username of the github user or smth, but I also tried just taking the ones from google, but still nothing.

Any ideas? I looked at this: https://github.com/ravibpatel/AutoUpdater.NET/issues/296 but, I still can't seem to get it working.

ravibpatel commented 11 months ago

Following User Agent worked for me.

AutoUpdater.HttpUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36";

Also, I have to change following code because assets is an array.

args.UpdateInfo = new UpdateInfoEventArgs
{
    CurrentVersion = json.tag_name,
    DownloadURL = json.assets[0].browser_download_url,
};
OssieFromDK commented 11 months ago

Works, thanks :)