Exemple #1
0
        private float DrawPlugin(float drawPosX, float drawPosY, float width, PluginToUpdate plug)
        {
            var pluginFrame = new RectangleF(drawPosX + 5, drawPosY, width - 10, 26);

            int frameBorderWidth = 2;

            if (plug.IsPoeHUD)
            {
                pluginFrame.Height += 50;
                frameBorderWidth    = 4;
            }

            Graphics.DrawBox(pluginFrame, Color.Black);
            Graphics.DrawFrame(pluginFrame, frameBorderWidth, Color.Gray);

            pluginFrame.X += 10;

            Graphics.DrawText(plug.PluginName, 20, new Vector2(pluginFrame.X, pluginFrame.Y));
            Graphics.DrawText(plug.LocalVersion + (plug.LocalTag.Length > 0 ? $" ({plug.LocalTag})" : ""), 15, new Vector2(pluginFrame.X + 200, pluginFrame.Y + 5), Color.Gray);

            var color = Color.Gray;

            if (plug.UpdateState == ePluginUpdateState.HasUpdate)
            {
                color = Color.Green;
            }
            else if (plug.UpdateState == ePluginUpdateState.HasLowerUpdate)
            {
                color = Color.Red;
            }

            Graphics.DrawText(plug.RemoteVersion + (plug.RemoteTag.Length > 0 ? $" ({plug.RemoteTag})" : ""), 15, new Vector2(pluginFrame.X + 400, pluginFrame.Y + 5), color);


            var buttonRect    = new RectangleF(pluginFrame.X + pluginFrame.Width - 75, drawPosY + 4, 60, 20);
            var buttonTextPos = buttonRect.TopRight;

            buttonTextPos.X -= 5;
            buttonTextPos.Y += 2;

            if (!string.IsNullOrEmpty(plug.InstallProgress))
            {
                Graphics.DrawText(plug.InstallProgress, 15, buttonTextPos, Color.White, FontDrawFlags.Right);
            }
            else if (!plug.bHasGitConfig)
            {
                Graphics.DrawText("No git config", 15, buttonTextPos, Color.Gray, FontDrawFlags.Right);
            }
            else if (plug.UpdateState == ePluginUpdateState.HasUpdate ||
                     plug.UpdateState == ePluginUpdateState.HasLowerUpdate ||
                     plug.UpdateState == ePluginUpdateState.UnknownUpdate)
            {
                if (UpdaterUtils.DrawButton(buttonRect, 1, new Color(50, 50, 50, 220), Color.White))
                {
                    plug.UpdatePlugin();
                }
                if (plug.UpdateState == ePluginUpdateState.UnknownUpdate)
                {
                    Graphics.DrawText("Unknown update", 15, buttonTextPos, Color.Gray, FontDrawFlags.Right);
                }
                else if (plug.UpdateState == ePluginUpdateState.HasLowerUpdate)
                {
                    Graphics.DrawText("Update", 15, buttonTextPos, Color.Red, FontDrawFlags.Right);
                }
                else
                {
                    Graphics.DrawText("Update", 15, buttonTextPos, Color.Yellow, FontDrawFlags.Right);
                }
            }
            else if (plug.UpdateState == ePluginUpdateState.NoUpdate)
            {
                Graphics.DrawText("Updated", 15, buttonTextPos, Color.Green, FontDrawFlags.Right);
            }
            else if (plug.UpdateState == ePluginUpdateState.ReadyToInstal)
            {
                Graphics.DrawText("(Restart PoeHUD)", 15, buttonTextPos, Color.Green, FontDrawFlags.Right);
            }
            else
            {
                Graphics.DrawText("Wrong git config", 15, buttonTextPos, Color.Gray, FontDrawFlags.Right);
            }


            if (plug.IsPoeHUD)
            {
                if (string.IsNullOrEmpty(plug.InstallProgress))
                {
                    var selectBranchRect = new RectangleF(pluginFrame.X + 10, drawPosY + 30, 150, 20);
                    selectBranchRect.Y += 2;
                    Graphics.DrawText("Select PoeHUD branch: ", 15, selectBranchRect.TopLeft);
                    selectBranchRect.Y -= 2;

                    selectBranchRect.X += 150;

                    for (int i = 0; i < PoeHUDBranches.Length; i++)
                    {
                        bool selected = Settings.PoeHUDBranch == PoeHUDBranches[i];

                        var selColor = selected ? Color.White : Color.Gray;

                        if (UpdaterUtils.DrawTextButton(selectBranchRect, PoeHUDBranches[i], 15, selected ? 3 : 1, new Color(50, 50, 50, 220), selColor, selColor))
                        {
                            if (Settings.PoeHUDBranch != PoeHUDBranches[i])
                            {
                                Settings.PoeHUDBranch = PoeHUDBranches[i];
                                plug.InstallProgress  = "Restart PoeHUD. It will check updates from " + Settings.PoeHUDBranch + " branch.";
                                plug.RemoteVersion    = "";
                                plug.LocalVersion     = "";
                            }
                        }
                        selectBranchRect.X += 170;
                    }

                    selectBranchRect = new RectangleF(pluginFrame.X + 10, drawPosY + 55, 150, 20);

                    Graphics.DrawText("Note: PoeHUD will be automatically restarted.", 15, selectBranchRect.TopLeft, Color.Gray);
                }

                drawPosY     += 55;
                WindowHeight += 55;
            }

            drawPosY += 30;
            return(drawPosY);
        }
Exemple #2
0
        public override void Render()
        {
            if (WinApi.IsKeyDown(Keys.Space))
            {
                Settings.Enable.Value = false;
            }

            var drawPosX = Settings.WindowPosX;
            var drawPosY = Settings.WindowPosY;

            DrawRect = new RectangleF(drawPosX, drawPosY, WindowWidth + 10, WindowHeight + 55);
            UpdaterUtils.DrawFrameBox(DrawRect, 2, Color.Black, Color.White);

            #region Close Button
            var closeRect = DrawRect;
            closeRect.X     += closeRect.Width - 25;
            closeRect.Y     += 5;
            closeRect.Width  = 20;
            closeRect.Height = 20;

            if (UpdaterUtils.DrawButton(closeRect, 1, new Color(20, 20, 20, 255), Color.White))
            {
                Settings.Enable.Value = false;
            }
            Graphics.DrawText("X", 20, new Vector2(closeRect.X + 4, closeRect.Y - 2), Color.White);
            #endregion

            #region Tabs buttons
            var installedButtonRect = new RectangleF(DrawRect.X + 5, DrawRect.Y + 5, 120, 25);

            if (UpdaterUtils.DrawTextButton(installedButtonRect, "Installed Plugins", 15, 1, CurrentWindowTab == UWindowTab.InstalledPlugins ? Color.Gray : new Color(60, 60, 60, 255),
                                            Color.White, Color.White))
            {
                CurrentWindowTab = UWindowTab.InstalledPlugins;
            }

            installedButtonRect.X += installedButtonRect.Width + 10;

            if (UpdaterUtils.DrawTextButton(installedButtonRect, "Available Plugins", 15, 1, CurrentWindowTab == UWindowTab.AvailablePlugins ? Color.Gray : new Color(60, 60, 60, 255),
                                            Color.White, Color.White))
            {
                CurrentWindowTab = UWindowTab.AvailablePlugins;
            }

            #endregion


            var subWindowRect = new RectangleF(drawPosX + 5, drawPosY + 30, WindowWidth, WindowHeight);
            UpdaterUtils.DrawFrameBox(subWindowRect, 2, Color.Black, Color.White);

            if (CurrentWindowTab == UWindowTab.InstalledPlugins)
            {
                DrawWindow_InstalledPlugins(subWindowRect.X, subWindowRect.Y, subWindowRect.Width);
            }
            else if (CurrentWindowTab == UWindowTab.AvailablePlugins)
            {
                DrawWindow_AllPlugins(subWindowRect.X, subWindowRect.Y, subWindowRect.Width);
            }

            Graphics.DrawText("Notes: Move window by mouse drag. Close window key: Space", 15,
                              new Vector2(subWindowRect.X + 10, subWindowRect.Y + subWindowRect.Height + 5), Color.Gray, FontDrawFlags.Left);


            bMouse_Click = false;
        }
Exemple #3
0
        private void DrawWindow_AllPlugins(float drawPosX, float drawPosY, float width)
        {
            drawPosY += 5;

            if (AllAvailablePlugins == null)
            {
                Graphics.DrawText($"File {AvailablePluginsConfigParser.AvailablePluginsConfigFile} is not found!", 20, new Vector2(drawPosX + 15, drawPosY + 5), Color.Red);
                WindowHeight = 40;
                return;
            }

            WindowHeight = AllAvailablePlugins.Count * 45 + 5;

            foreach (var availPlug in AllAvailablePlugins)
            {
                var pluginFrame = new RectangleF(drawPosX + 5, drawPosY, width - 10, 40);
                Graphics.DrawBox(pluginFrame, Color.Black);
                Graphics.DrawFrame(pluginFrame, 2, Color.Gray);

                Graphics.DrawText(availPlug.PluginName, 20, new Vector2(pluginFrame.X + 5, pluginFrame.Y));
                Graphics.DrawText($"Owner: {availPlug.GitOwner}", 14, new Vector2(pluginFrame.X + 300, pluginFrame.Y + 3), Color.Gray);

                Graphics.DrawText(availPlug.Description, 14, new Vector2(pluginFrame.X + 10, pluginFrame.Y + 23), Color.Gray);


                var buttonRect = new RectangleF((pluginFrame.X + pluginFrame.Width) - 240, drawPosY + 4, 100, 30);

                if (UpdaterUtils.DrawTextButton(buttonRect, "Open URL", 20, 1, new Color(50, 50, 50, 220), Color.White, Color.Yellow))
                {
                    System.Diagnostics.Process.Start($"https://github.com/{availPlug.GitOwner}/{availPlug.GitName}");
                }

                buttonRect.X     += 105;
                buttonRect.Width += 30;

                if (availPlug.bOwned)
                {
                    Graphics.DrawText("Owned", 20, buttonRect.Center, Color.Green, FontDrawFlags.VerticalCenter | FontDrawFlags.Center);
                }
                else if (availPlug.InstalledPlugin != null)
                {
                    if (availPlug.InstalledPlugin.InstallProgress.Length > 0)
                    {
                        Graphics.DrawText(availPlug.InstalledPlugin.InstallProgress, 15, buttonRect.Center, Color.Green, FontDrawFlags.VerticalCenter | FontDrawFlags.Center);
                    }
                    else if (availPlug.bInstaled)
                    {
                        Graphics.DrawText("Restart PoeHUD", 20, buttonRect.Center, Color.Green, FontDrawFlags.VerticalCenter | FontDrawFlags.Center);
                    }
                    else
                    {
                        Graphics.DrawText("Downloading...", 20, buttonRect.Center, Color.Yellow, FontDrawFlags.VerticalCenter | FontDrawFlags.Center);
                    }
                }
                else if (UpdaterUtils.DrawTextButton(buttonRect, "Install", 20, 1, new Color(50, 50, 50, 220), Color.White, Color.Yellow))
                {
                    var newPluginDir = Path.Combine(@"plugins\", availPlug.PluginName);
                    Directory.CreateDirectory(newPluginDir);

                    var newConfigPath = Path.Combine(newPluginDir, GitConfigParser.ConfigFileName);

                    DownloadConfigForPlugin(availPlug, newConfigPath);
                }

                drawPosY += 45;
            }
        }
Exemple #4
0
        private async Task CheckFiles(PluginToUpdate plugin, string branch, string path)
        {
            IReadOnlyList <RepositoryContent> allContent = null;

            try
            {
                if (!string.IsNullOrEmpty(branch))
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        allContent = await gitClient.Repository.Content.GetAllContentsByRef(plugin.RepoOwner, plugin.RepoName, path, branch);
                    }
                    else
                    {
                        allContent = await gitClient.Repository.Content.GetAllContentsByRef(plugin.RepoOwner, plugin.RepoName, branch);
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        allContent = await gitClient.Repository.Content.GetAllContents(plugin.RepoOwner, plugin.RepoName, path);
                    }
                    else
                    {
                        allContent = await gitClient.Repository.Content.GetAllContents(plugin.RepoOwner, plugin.RepoName);
                    }
                }
            }
            catch (Exception ex)
            {
                LogError($"Plugin '" + plugin.PluginName + "' check update unhandled error: " + ex.Message, 10);
                return;
            }


            foreach (var contentEntity in allContent)
            {
                if (plugin.IgnoredEntities.Contains(contentEntity.Path))
                {
                    continue;
                }

                if (contentEntity.Type == ContentType.File)
                {
                    RepoFilesCheckedCount++;
                    var download = false;


                    if (plugin.IsPoeHUD && contentEntity.Name.Contains("PoeHUD.exe"))
                    {
                        var localPath   = Path.Combine(plugin.PluginDirectory + @"\", plugin.PoehudExeRealName);
                        var poeHudFInfo = new FileInfo(localPath);

                        if (poeHudFInfo.Exists)
                        {
                            if (poeHudFInfo.Length != contentEntity.Size)
                            {
                                download = true;
                            }
                        }
                    }
                    else
                    {
                        var localPath = Path.Combine(plugin.PluginDirectory + @"\" + path, contentEntity.Name);
                        if (plugin.IsPoeHUD && path.Contains("Release"))
                        {
                            localPath = Path.Combine(plugin.PluginDirectory + @"\" + path.Remove(path.IndexOf("Release"), 7), contentEntity.Name);
                        }

                        if (File.Exists(localPath))
                        {
                            var fileSha = UpdaterUtils.GetGitObjectChecksum(localPath);

                            if (fileSha != contentEntity.Sha)
                            {
                                download = true;
                            }
                        }
                        else
                        {
                            download = true;
                        }
                    }

                    if (download)
                    {
                        var updateFilePath = Path.Combine(plugin.PluginDirectory + @"\" + UpdateTempDir + @"\" + path, contentEntity.Name);
                        if (plugin.IsPoeHUD && path.Contains("Release"))
                        {
                            updateFilePath = Path.Combine(plugin.PluginDirectory + @"\" + UpdateTempDir + @"\" + path.Remove(path.IndexOf("Release"), 7), contentEntity.Name);
                        }

                        plugin.FilesToDownload.Add(new FileToDownload
                        {
                            Name = contentEntity.Name,
                            Url  = contentEntity.DownloadUrl.AbsoluteUri,
                            Path = updateFilePath
                        });
                    }
                }
                else if (contentEntity.Type == ContentType.Dir)
                {
                    var newPath = Path.Combine(path, contentEntity.Name);
                    await CheckFiles(plugin, branch, newPath);
                }
                else
                {
                    LogMessage("Ignore update content type: " + contentEntity.Type, 10);
                }
            }
        }