示例#1
0
        private PatchOperation GetOperation(UpdaterDefinitionEntry current, UpdaterDefinition oldDefinition)
        {
            if (oldDefinition.Entries.All(e => e.RelativePath != current.RelativePath))
            {
                return(PatchOperation.Added);
            }

            var oldEntry = oldDefinition.Entries.FirstOrDefault(e => e.RelativePath == current.RelativePath);

            if (oldEntry.Size == current.Size)
            {
                if (oldEntry.Attributes == current.Attributes)
                {
                    return(PatchOperation.Unchanged);
                }

                return(PatchOperation.ChangedAttributes);
            }

            return(PatchOperation.Updated);
        }
示例#2
0
        private UpdaterDefinition BuildDefinition(LocalFileInfo[] files, UpdaterDefinition oldDefinition)
        {
            var definition = new UpdaterDefinition();
            var entries    = new List <UpdaterDefinitionEntry>();

            for (var i = 0; i < files.Length; i++)
            {
                var currentInfo = files[i];

                var entry = new UpdaterDefinitionEntry();
                entry.RelativePath = currentInfo.RelativePath;
                entry.Attributes   = currentInfo.Attributes;
                entry.LastWriting  = currentInfo.LastWriting;
                entry.Size         = currentInfo.Size;
                entry.Operation    = GetOperation(entry, oldDefinition);

                entries.Add(entry);

                _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdaterProcessedFile, currentInfo.RelativePath));
            }

            foreach (var oldDefinitionEntry in oldDefinition.Entries)
            {
                if (entries.All(e => e.RelativePath != oldDefinitionEntry.RelativePath))
                {
                    entries.Add(new UpdaterDefinitionEntry()
                    {
                        RelativePath = oldDefinitionEntry.RelativePath,
                        Operation    = PatchOperation.Deleted
                    });
                }

                _context.ReportProgress(string.Format(_context.LocalizedMessages.UpdaterProcessedFile, oldDefinitionEntry.RelativePath));
            }

            definition.Entries = entries.ToArray();
            return(definition);
        }