예제 #1
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());
        }
예제 #2
0
 public static string GetPatchDirectoryPath(FirmwareDefinition definition)
 {
     if (definition == null)
     {
         throw new ArgumentNullException("definition");
     }
     return(Path.Combine(Paths.PatchDirectory, definition.Name));
 }
예제 #3
0
        public static string GetPatchFilePath([NotNull] FirmwareDefinition definition, [NotNull] string fileName)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            return(Path.Combine(Paths.PatchDirectory, definition.Name, fileName));
        }
예제 #4
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);
        }
        public PatchUpdatesAvailableWindow([NotNull] FirmwareDefinition definition, [NotNull] IEnumerable <GitHubApi.GitHubFileInfo> newPatches)
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }
            if (newPatches == null)
            {
                throw new ArgumentNullException("newPatches");
            }

            m_definition = definition;
            m_newPatches = newPatches;

            InitializeComponent();
            InitializeControls();
        }