private static List <SelectionItem> GetSelectionItems(List <XmlNode> originalNodes, List <XmlNode> nodes, List <string> breadcrumbs)
        {
            var changeIds      = GetChangedIds(originalNodes, nodes);
            var selectionItems = new List <SelectionItem>();

            if (originalNodes.Count != 0)
            {
                var originalNode = originalNodes[originalNodes.Count - 1];
                selectionItems.Add(new SelectionItem()
                {
                    Name = "Original", Description = XmlTools.GetOuterXml(originalNode), Value = originalNode
                });
            }
            foreach (List <int> l in changeIds)
            {
                var item = new SelectionItem()
                {
                    Name = breadcrumbs[l[0]], Description = XmlTools.GetOuterXml(nodes[l[0]]), Value = nodes[l[0]]
                };
                for (var i = 1; i < l.Count; i++)
                {
                    item.Name += "\n" + breadcrumbs[l[i]];
                }
                selectionItems.Add(item);
            }
            return(selectionItems);
        }
Exemple #2
0
        private static void OverrideCombine(List <string> originalFiles, List <string> files, string outputPath, bool binaryCombine)
        {
            bool allSameSize = true;

            var originalHashes     = originalFiles.Select(file => SHA256.ComputeHash(file)).ToList();
            var modifiedFileHashes = new Dictionary <string, List <int> >();
            var size = new FileInfo(files[0]).Length;

            for (var i = 0; i < files.Count; i++)
            {
                var file = files[i];
                var hash = SHA256.ComputeHash(file);
                if (!originalHashes.Contains(hash))
                {
                    if (modifiedFileHashes.ContainsKey(hash))
                    {
                        modifiedFileHashes[hash].Add(i);
                    }
                    else
                    {
                        modifiedFileHashes.Add(hash, new List <int>()
                        {
                            i
                        });
                    }
                    if (new FileInfo(file).Length != size)
                    {
                        allSameSize = false;
                    }
                }
            }

            if (modifiedFileHashes.Count == 0)
            {
                return;
            }

            if (modifiedFileHashes.Count == 1)
            {
                if (File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                File.Copy(files[modifiedFileHashes.First().Value[0]], outputPath);
                return;
            }

            if (binaryCombine && allSameSize)
            {
                BinaryCombiner.Combine(originalFiles, files, outputPath, notifyCollissions);
            }
            else
            {
                var items = new List <SelectionItem>();
                items.Add(new SelectionItem()
                {
                    Name = "Original", Value = originalFiles[originalFiles.Count - 1] + "\\" + Path.GetFileName(originalFiles[0])
                });
                foreach (KeyValuePair <string, List <int> > pair in modifiedFileHashes)
                {
                    var item = new SelectionItem()
                    {
                        Name        = pair.Value.Count == 1 ? rootFiles[pair.Value[0]] + "\\" + Path.GetFileName(originalFiles[0]) : "",
                        Description = pair.Value.Count == 1 ? null : rootFiles[pair.Value[0]] + "\\" + Path.GetFileName(originalFiles[0]),
                        Value       = files[pair.Value[0]]
                    };
                    items.Add(item);
                }

                string replacingFile = (string)items[items.Count - 1].Value;
                object result        = null;
                if (notifyCollissions && SelectionDialog.Show("Select overriding file", items, out result, out notifyCollissions))
                {
                    replacingFile = (string)result;
                }
                if (outputPath == replacingFile)
                {
                    return;
                }
                if (File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                File.Copy(replacingFile, outputPath);
            }
        }