private async Task CheckGithub(UpdaterComponent component)
        {
            try
            {
                var githubRelease = await GetGithubRelease(component);

                if (githubRelease != null && githubRelease.assets != null && githubRelease.assets.Count != 0)
                {
                    var localVersionString  = component.localVersion;
                    var onlineVersionString = githubRelease.name;
                    // fix for weird things like OpenParrotx64_1.0.0.30
                    if (onlineVersionString.Contains(component.name))
                    {
                        onlineVersionString = onlineVersionString.Split('_')[1];
                    }

                    bool needsUpdate = false;
                    // component not installed.
                    if (localVersionString == Properties.Resources.UpdaterNotInstalled)
                    {
                        needsUpdate = true;
                    }
                    else
                    {
                        switch (localVersionString)
                        {
                        // version number is weird / unable to be formatted
                        case "unknown":
                            Debug.WriteLine($"{component.name} version is weird! local: {localVersionString} | online: {onlineVersionString}");
                            needsUpdate = localVersionString != onlineVersionString;
                            break;

                        default:
                            int localNumber  = GetVersionNumber(localVersionString);
                            int onlineNumber = GetVersionNumber(onlineVersionString);

                            needsUpdate = localNumber < onlineNumber;
                            break;
                        }
                    }

                    Debug.WriteLine($"{component.name} - local: {localVersionString} | online: {onlineVersionString} | needs update? {needsUpdate}");

                    if (needsUpdate)
                    {
                        var gh = new GitHubUpdates(component, githubRelease, localVersionString, onlineVersionString);
                        if (!updates.Exists(x => x._componentUpdated.name == gh._componentUpdated.name))
                        {
                            updates.Add(gh);
                        }
                    }
                }
                else
                {
                    Debug.WriteLine($"release is null? component: {component.name}");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Example #2
0
        private async void CheckGitHub(string componentToCheck)
        {
            try
            {
                if (componentToCheck == "TeknoParrotUI")
                {
                    var releases = await GetGithubReleases(componentToCheck);

                    var latest = releases[0];
                    //Get the version number of TeknoParrotUi.exe
                    Assembly        assembly        = Assembly.GetExecutingAssembly();
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
                    string          version         = fileVersionInfo.ProductVersion;


                    if (latest.name != version)
                    {
                        GitHubUpdates windowGitHubUpdates =
                            new GitHubUpdates(componentToCheck, latest);
                        windowGitHubUpdates.Show();
                    }
                }
                else if (componentToCheck == "OpenParrot")
                {
                    //check openparrot32 first
                    var releases = await GetGithubReleases(componentToCheck);

                    FileVersionInfo fileVersionInfo32 = FileVersionInfo.GetVersionInfo("OpenParrotWin32\\OpenParrot.dll");
                    string          version32         = fileVersionInfo32.ProductVersion;
                    FileVersionInfo fileVersionInfo64 = FileVersionInfo.GetVersionInfo("OpenParrotx64\\OpenParrot64.dll");
                    string          version64         = fileVersionInfo64.ProductVersion;

                    for (int i = 0; i < releases.Count; i++)
                    {
                        var latest = releases[i];
                        if (latest.tag_name == "OpenParrotWin32")
                        {
                            string[] latestVer = latest.name.Split('_');
                            if (latestVer[1] != version32)
                            {
                                GitHubUpdates windowGitHubUpdates =
                                    new GitHubUpdates(componentToCheck + "Win32", latest);
                                windowGitHubUpdates.Show();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    //checking openparrot64
                    for (int i = 0; i < releases.Count; i++)
                    {
                        var latest = releases[i];
                        if (latest.tag_name == "OpenParrotx64")
                        {
                            string[] latestVer = latest.name.Split('_');
                            if (latestVer[1] != version64)
                            {
                                GitHubUpdates windowGitHubUpdates =
                                    new GitHubUpdates(componentToCheck + "x64", latest);
                                windowGitHubUpdates.Show();
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    var releases = await GetGithubReleases(componentToCheck);

                    //try
                    //{
                    //    using (RegistryKey key =
                    //        Registry.CurrentUser.OpenSubKey("Software\\TeknoGods\\TeknoParrot"))
                    //    {
                    //        if (key != null)
                    //        {
                    //            segaApiId = (int) key.GetValue("OpenSegaAPI");
                    //        }
                    //    }
                    //}
                    //catch
                    //{

                    //}
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo("TeknoParrot\\Opensegaapi.dll");
                    string          version         = fileVersionInfo.ProductVersion;

                    for (int i = 0; i < releases.Count; i++)
                    {
                        var latest = releases[i];
                        if (latest.name != version)
                        {
                            GitHubUpdates windowGitHubUpdates = new GitHubUpdates(componentToCheck, latest);
                            windowGitHubUpdates.Show();
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }