예제 #1
0
        public static List <GitHubApi.GitHubFileInfo> CheckForNewDefinitions([NotNull] IEnumerable <FirmwareDefinition> definitions)
        {
            if (definitions == null)
            {
                throw new ArgumentNullException("definitions");
            }

            s_logger.Info("Checking for definitions updates...");
            var definitionsInRepository = GitHubApi.GetFiles("Definitions");

            if (definitionsInRepository == null)
            {
                s_logger.Info("Definitions repository is not found.");
                return(null);
            }

            var entitiesForUpdate = GitHubApi.GetEntitiesForUpdate(definitionsInRepository, definitions.Select(x => new Updatable <FirmwareDefinition>
            {
                Entity   = x,
                FileName = x.FileName,
                Sha      = x.Sha
            })).ToList();

            if (entitiesForUpdate.Count == 0)
            {
                s_logger.Info("No new definitions were found.");
            }
            return(entitiesForUpdate);
        }
예제 #2
0
        public static List <GitHubApi.GitHubFileInfo> CheckForNewPatches([NotNull] FirmwareDefinition definition, [NotNull] IEnumerable <Patch> patches)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            if (patches == null)
            {
                throw new ArgumentNullException("patches");
            }

            var patchesInRepository = GitHubApi.GetFiles("Patches/" + definition.Name);

            if (patchesInRepository == null)
            {
                return(null);
            }

            return(GitHubApi.GetEntitiesForUpdate(patchesInRepository, patches.Select(x => new Updatable <Patch>
            {
                Entity = x,
                FileName = x.FileName,
                Sha = x.Sha
            })).ToList());
        }
예제 #3
0
        public IEnumerable <Patch> LoadPatchesForFirmware([NotNull] FirmwareDefinition definition)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            var result         = new List <Patch>();
            var pathesLocation = Path.Combine(Paths.PatchDirectory, definition.Name);

            if (!Directory.Exists(pathesLocation))
            {
                return(result);
            }

            var files = Directory.GetFiles(pathesLocation, Consts.PatchFileExtension, SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var serializer = new XmlSerializer(typeof(Patch));
                try
                {
                    Patch patch;
                    using (var fs = File.Open(file, FileMode.Open))
                    {
                        patch = serializer.Deserialize(fs) as Patch;
                    }

                    if (patch == null)
                    {
                        continue;
                    }
                    if (!string.Equals(patch.Definition, definition.Name))
                    {
                        continue;
                    }

                    patch.Data        = ParseDiff(patch.DataString);
                    patch.FilePath    = file;
                    patch.FileName    = Path.GetFileName(file);
                    patch.Description = patch.Description.SplitLines();
                    patch.Sha         = GitHubApi.GetGitSha(file);
                    result.Add(patch);
                }
                catch (Exception ex)
                {
                    s_logger.Warn(ex, "An error occurred during loading patch: " + file);
                }
            }
            return(result);
        }
예제 #4
0
        public static ReleaseInfo CheckForNewRelease(string applicationVersion)
        {
            s_logger.Info("Checking for application updates...");
            var latestRelease = GitHubApi.GetLatestRelease();

            if (latestRelease == null || latestRelease.Assets.Length == 0)
            {
                s_logger.Info("No application updates found.");
                return(null);
            }

            float currentVersionFloat;
            float newVersionFloat;

            var v1 = float.TryParse(applicationVersion, NumberStyles.Float, CultureInfo.InvariantCulture, out currentVersionFloat);
            var v2 = float.TryParse(latestRelease.Tag, NumberStyles.Float, CultureInfo.InvariantCulture, out newVersionFloat);

            if (v1 == false || v2 == false)
            {
                if (string.Equals(applicationVersion, latestRelease.Tag))
                {
                    s_logger.Info("Your are using latest version (string checking).");
                    return(null);
                }
            }
            else if (currentVersionFloat >= newVersionFloat)
            {
                s_logger.Info("Your are using latest version (float checking).");
                return(null);
            }

            s_logger.Info("New application version is available: " + latestRelease.Tag);
            return(new ReleaseInfo
            {
                Version = latestRelease.Tag,
                Description = latestRelease.Description,
                DownloadUrl = latestRelease.Assets[0].DownloadUrl
            });
        }
예제 #5
0
 private bool UpdatedFilePredicate(GitHubApi.GitHubFileInfo fileInfo)
 {
     var existedPatch = m_suitablePatches.FirstOrDefault(sp => string.Equals(fileInfo.Name, sp.FileName));
     return existedPatch == null || !string.Equals(existedPatch.Sha, fileInfo.Sha);
 }
예제 #6
0
 private static bool FileExtensionPredicate(GitHubApi.GitHubFileInfo fileInfo)
 {
     return new FileInfo(fileInfo.Name).Extension == Consts.PatchFileExtensionWoAsterisk;
 }