Example #1
0
        private static DiffInstance GetTranslatedSettingDiff(
            string aSectionName, Func <string, string> aTranslateFunc,
            Setting aSetting, DiffInstance aDiff,
            Setting?anOtherSetting = null, DiffInstance anOtherDiff = null)
        {
            string key = aTranslateFunc != null?aTranslateFunc(aSetting.key) : aSetting.key;

            if (anOtherSetting == null || anOtherDiff == null)
            {
                if (aDiff.diffType == DiffType.Added)
                {
                    return(new DiffInstance(key + " was added and set to \"" + aSetting.value + "\".",
                                            aSectionName, DiffType.Added, new List <string>(), aDiff.snapshotCreationDate));
                }
                else
                {
                    return(new DiffInstance(key + " was removed and is no longer set to \"" + aSetting.value + "\".",
                                            aSectionName, DiffType.Removed, new List <string>(), aDiff.snapshotCreationDate));
                }
            }
            else
            {
                return(new DiffInstance(key + " was changed from \"" + anOtherSetting.GetValueOrDefault().value + "\" to \"" + aSetting.value + "\".",
                                        aSectionName, DiffType.Changed, new List <string>(), aDiff.snapshotCreationDate));
            }
        }
        public override IEnumerable <DiffInstance> Translate(IEnumerable <DiffInstance> aDiffs)
        {
            List <DiffInstance> added   = aDiffs.Where(aDiff => aDiff.diffType == DiffType.Added).ToList();
            List <DiffInstance> removed = aDiffs.Where(aDiff => aDiff.diffType == DiffType.Removed).ToList();

            foreach (DiffInstance addition in added)
            {
                Setting      setting = new Setting(addition.difference);
                DiffInstance removal = removed.FirstOrDefault(aDiff => new Setting(aDiff.difference).key == setting.key);

                if (removal != null && removal.difference != null)
                {
                    removed.Remove(removal);

                    yield return(new DiffInstance("\"" + setting.key + "\" was modified.",
                                                  Section, DiffType.Changed, new List <string>(), addition.snapshotCreationDate));
                }
                else
                {
                    yield return(new DiffInstance("\"" + setting.key + "\" was added.",
                                                  Section, DiffType.Added, new List <string>(), addition.snapshotCreationDate));
                }
            }

            foreach (DiffInstance removal in removed)
            {
                Setting setting = new Setting(removal.difference);

                yield return(new DiffInstance("\"" + setting.key + "\" was removed.",
                                              Section, DiffType.Removed, new List <string>(), removal.snapshotCreationDate));
            }
        }
 private static string GetIcon(DiffInstance aDiff)
 {
     return
         (aDiff.diffType == Snapshotter.DiffType.Changed ? "gear-blue" :
          aDiff.diffType == Snapshotter.DiffType.Added   ? "plus" :
          aDiff.diffType == Snapshotter.DiffType.Removed ? "minus" :
          "gear-gray");
 }
        private static string GetDiffCondition(DiffInstance aDiff, IEnumerable <Snapshotter.Snapshot> aSnapshots)
        {
            int myNextIndex =
                aSnapshots.ToList().FindLastIndex(aSnapshot =>
                                                  aSnapshot.creationTime == aDiff.snapshotCreationDate) + 1;

            DateTime myNextDate =
                myNextIndex >= aSnapshots.Count() ?
                aSnapshots.Last().creationTime :
                aSnapshots.ElementAt(myNextIndex).creationTime;

            List <int> indexes = new List <int>();

            for (int i = 0; i < snapshotDates.Count; ++i)
            {
                if (snapshotDates.ElementAt(i) < myNextDate &&
                    snapshotDates.ElementAt(i) >= aDiff.snapshotCreationDate)
                {
                    indexes.Add(i);
                }
            }

            return(String.Join(",", indexes));
        }
Example #5
0
        public static IEnumerable <DiffInstance> TranslateSettings(string aSectionName, IEnumerable <DiffInstance> aDiffs, Func <string, string> aTranslateFunc)
        {
            List <DiffInstance> added   = aDiffs.Where(aDiff => aDiff.diffType == DiffType.Added).ToList();
            List <DiffInstance> removed = aDiffs.Where(aDiff => aDiff.diffType == DiffType.Removed).ToList();

            foreach (DiffInstance addition in added)
            {
                Setting      setting = new Setting(addition.difference);
                DiffInstance removal = removed.FirstOrDefault(aDiff => new Setting(aDiff.difference).key == setting.key);

                if (removal != null && removal.difference != null)
                {
                    Setting removedSetting = new Setting(removal.difference);

                    removed.Remove(removal);

                    if (removedSetting.key == "Bookmarks")
                    {
                        IEnumerable <double> prevBookmarks =
                            removedSetting.value.Split(',').Select(aValue => double.Parse(aValue.Trim()));
                        IEnumerable <double> curBookmarks =
                            setting.value.Split(',').Select(aValue => double.Parse(aValue.Trim()));

                        IEnumerable <double> removedBookmarks = prevBookmarks.Except(curBookmarks);
                        IEnumerable <double> addedBookmarks   = curBookmarks.Except(prevBookmarks);

                        List <string> details = new List <string>();
                        if (addedBookmarks.Any())
                        {
                            details.Add("Added " + String.Join(", ", addedBookmarks.Select(aMark => Timestamp.Get(aMark))));
                        }
                        if (removedBookmarks.Any())
                        {
                            details.Add("Removed " + String.Join(", ", removedBookmarks.Select(aMark => Timestamp.Get(aMark))));
                        }

                        yield return(new DiffInstance(
                                         aTranslateFunc(setting.key) + " were changed.", aSectionName,
                                         DiffType.Changed, details, addition.snapshotCreationDate));
                    }
                    else if (removedSetting.key == "Tags")
                    {
                        IEnumerable <string> prevTags = removedSetting.value.Split(' ').Select(aValue => "\"" + aValue + "\"");
                        IEnumerable <string> curTags  = setting.value.Split(' ').Select(aValue => "\"" + aValue + "\"");

                        IEnumerable <string> removedTags = prevTags.Except(curTags);
                        IEnumerable <string> addedTags   = curTags.Except(prevTags);

                        List <string> details = new List <string>();
                        if (addedTags.Any())
                        {
                            details.Add("Added " + String.Join(", ", addedTags));
                        }
                        if (removedTags.Any())
                        {
                            details.Add("Removed " + String.Join(", ", removedTags));
                        }

                        yield return(new DiffInstance(
                                         aTranslateFunc(setting.key) + " were changed.", aSectionName,
                                         DiffType.Changed, details, addition.snapshotCreationDate));
                    }
                    else
                    {
                        yield return(GetTranslatedSettingDiff(
                                         aSectionName, aTranslateFunc,
                                         setting, addition,
                                         removedSetting, removal));
                    }
                }
                else
                {
                    yield return(GetTranslatedSettingDiff(
                                     aSectionName, aTranslateFunc, setting, addition));
                }
            }

            foreach (DiffInstance removal in removed)
            {
                Setting setting = new Setting(removal.difference);

                yield return(GetTranslatedSettingDiff(
                                 aSectionName, aTranslateFunc, setting, removal));
            }
        }
Example #6
0
        public override IEnumerable <DiffInstance> Translate(IEnumerable <DiffInstance> aDiffs)
        {
            List <Tuple <DiffInstance, TimingLine> > addedTimingLines   = new List <Tuple <DiffInstance, TimingLine> >();
            List <Tuple <DiffInstance, TimingLine> > removedTimingLines = new List <Tuple <DiffInstance, TimingLine> >();

            foreach (DiffInstance diff in aDiffs)
            {
                TimingLine timingLine = null;
                try
                {
                    timingLine = new TimingLine(diff.difference.Split(','), beatmap: null);
                }
                catch
                {
                    // Failing to parse a changed line shouldn't stop it from showing.
                }

                if (timingLine != null)
                {
                    if (diff.diffType == DiffType.Added)
                    {
                        addedTimingLines.Add(new Tuple <DiffInstance, TimingLine>(diff, timingLine));
                    }
                    else
                    {
                        removedTimingLines.Add(new Tuple <DiffInstance, TimingLine>(diff, timingLine));
                    }
                }
                else
                {
                    // Shows the raw .osu line change.
                    yield return(diff);
                }
            }

            foreach (Tuple <DiffInstance, TimingLine> addedTuple in addedTimingLines)
            {
                DiffInstance addedDiff = addedTuple.Item1;
                TimingLine   addedLine = addedTuple.Item2;

                string stamp = Timestamp.Get(addedLine.offset);
                string type  = addedLine.uninherited ? "Uninherited line" : "Inherited line";

                bool found = false;
                foreach (TimingLine removedLine in removedTimingLines.Select(aTuple => aTuple.Item2).ToList())
                {
                    if (!addedLine.offset.AlmostEqual(removedLine.offset))
                    {
                        continue;
                    }

                    string removedType = removedLine.uninherited ? "Uninherited line" : "Inherited line";
                    if (type != removedType)
                    {
                        continue;
                    }

                    List <string> changes = new List <string>();

                    if (addedLine.kiai != removedLine.kiai)
                    {
                        changes.Add("Kiai changed from " + (removedLine.kiai ? "enabled" : "disabled") +
                                    " to " + (addedLine.kiai ? "enabled" : "disabled") + ".");
                    }

                    if (addedLine.meter != removedLine.meter)
                    {
                        changes.Add("Timing signature changed from " + removedLine.meter + "/4" +
                                    " to " + addedLine.meter + "/4.");
                    }

                    if (addedLine.sampleset != removedLine.sampleset)
                    {
                        changes.Add("Sampleset changed from " +
                                    removedLine.sampleset.ToString().ToLower() + " to " +
                                    addedLine.sampleset.ToString().ToLower() + ".");
                    }

                    if (addedLine.customIndex != removedLine.customIndex)
                    {
                        changes.Add("Custom sampleset index changed from " +
                                    removedLine.customIndex.ToString().ToLower() + " to " +
                                    addedLine.customIndex.ToString().ToLower() + ".");
                    }

                    if (!addedLine.volume.AlmostEqual(removedLine.volume))
                    {
                        changes.Add("Volume changed from " + removedLine.volume +
                                    " to " + addedLine.volume + ".");
                    }

                    if (type == "Uninherited line")
                    {
                        UninheritedLine addedUninherited   = new UninheritedLine(addedLine.code.Split(','), beatmap: null);
                        UninheritedLine removedUninherited = new UninheritedLine(removedLine.code.Split(','), beatmap: null);

                        if (!addedUninherited.bpm.AlmostEqual(removedUninherited.bpm))
                        {
                            changes.Add("BPM changed from " + removedUninherited.bpm +
                                        " to " + addedUninherited.bpm + ".");
                        }
                    }
                    else if (!addedLine.svMult.AlmostEqual(removedLine.svMult))
                    {
                        changes.Add("Slider velocity multiplier changed from " + removedLine.svMult +
                                    " to " + addedLine.svMult + ".");
                    }

                    if (changes.Count == 1)
                    {
                        yield return(new DiffInstance(stamp + changes[0],
                                                      Section, DiffType.Changed, new List <string>(), addedDiff.snapshotCreationDate));
                    }
                    else if (changes.Count > 1)
                    {
                        yield return(new DiffInstance(stamp + type + " changed.",
                                                      Section, DiffType.Changed, changes, addedDiff.snapshotCreationDate));
                    }

                    found = true;
                    removedTimingLines.RemoveAll(aTuple => aTuple.Item2.code == removedLine.code);
                }

                if (!found)
                {
                    yield return(new DiffInstance(stamp + type + " added.",
                                                  Section, DiffType.Added, new List <string>(), addedDiff.snapshotCreationDate));
                }
            }

            foreach (Tuple <DiffInstance, TimingLine> removedTuple in removedTimingLines)
            {
                DiffInstance removedDiff = removedTuple.Item1;
                TimingLine   removedLine = removedTuple.Item2;

                string stamp = Timestamp.Get(removedLine.offset);
                string type  = removedLine.uninherited ? "Uninherited line" : "Inherited line";

                yield return(new DiffInstance(stamp + type + " removed.",
                                              Section, DiffType.Removed, new List <string>(), removedDiff.snapshotCreationDate));
            }
        }
        public override IEnumerable <DiffInstance> Translate(IEnumerable <DiffInstance> aDiffs)
        {
            List <Tuple <DiffInstance, HitObject> > addedHitObjects   = new List <Tuple <DiffInstance, HitObject> >();
            List <Tuple <DiffInstance, HitObject> > removedHitObjects = new List <Tuple <DiffInstance, HitObject> >();

            foreach (DiffInstance diff in aDiffs)
            {
                HitObject hitObject = null;
                try
                { hitObject = new HitObject(diff.difference.Split(','), beatmap: null); }
                catch
                {
                    // Cannot yield in a catch clause, so checks for null in the following statement instead.
                }

                if (hitObject != null)
                {
                    if (diff.diffType == DiffType.Added)
                    {
                        addedHitObjects.Add(new Tuple <DiffInstance, HitObject>(diff, hitObject));
                    }
                    else
                    {
                        removedHitObjects.Add(new Tuple <DiffInstance, HitObject>(diff, hitObject));
                    }
                }
                else
                {
                    // Failing to parse a changed line shouldn't stop it from showing.
                    yield return(diff);
                }
            }

            foreach (var(addedDiff, addedObject) in addedHitObjects)
            {
                string stamp = Timestamp.Get(addedObject.time);
                string type  = addedObject.GetObjectType();

                bool             found          = false;
                List <HitObject> removedObjects = removedHitObjects.Select(aTuple => aTuple.Item2).ToList();
                foreach (var removedObject in removedObjects)
                {
                    if (addedObject.time.AlmostEqual(removedObject.time))
                    {
                        string removedType = removedObject.GetObjectType();

                        if (type != removedType)
                        {
                            continue;
                        }

                        List <string> changes = GetChanges(addedObject, removedObject).ToList();

                        if (changes.Count == 1)
                        {
                            yield return(new DiffInstance(stamp + changes[0],
                                                          Section, DiffType.Changed, new List <string>(), addedDiff.snapshotCreationDate));
                        }
                        else if (changes.Count > 1)
                        {
                            yield return(new DiffInstance(stamp + type + " changed.",
                                                          Section, DiffType.Changed, changes, addedDiff.snapshotCreationDate));
                        }

                        found = true;
                        var o = removedObject;
                        removedHitObjects.RemoveAll(aTuple => aTuple.Item2.code == o.code);
                    }
                    else
                    {
                        // First check all following objects and see what happened to them. Once we get to a point where
                        // time and properties match up again, we can go back here and check these until that point.

                        // If the only difference is time, the object was most likely just offset.
                    }
                }

                if (!found)
                {
                    yield return(new DiffInstance(stamp + type + " added.",
                                                  Section, DiffType.Added, new List <string>(), addedDiff.snapshotCreationDate));
                }
            }

            foreach (Tuple <DiffInstance, HitObject> removedTuple in removedHitObjects)
            {
                DiffInstance removedDiff   = removedTuple.Item1;
                HitObject    removedObject = removedTuple.Item2;

                string stamp = Timestamp.Get(removedObject.time);
                string type  = removedObject.GetObjectType();

                yield return(new DiffInstance(stamp + type + " removed.",
                                              Section, DiffType.Removed, new List <string>(), removedDiff.snapshotCreationDate));
            }
        }