Exemple #1
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);
                }
            }
        }