public static ModReference Parse(string spec)
            {
                string[] array = spec.Split(new char[]
                {
                    '@'
                });
                if (array.Length == 1)
                {
                    return(new ModReference(array[0], null));
                }
                if (array.Length > 2)
                {
                    throw new Exception("Invalid mod reference: " + spec);
                }
                ModReference result;

                try
                {
                    result = new ModReference(array[0], array[1]);
                }
                catch
                {
                    throw new Exception("Invalid mod reference: " + spec);
                }
                return(result);
            }
        private void ModpackListBoxDropHandler(object sender, DragEventArgs e)
        {
            ListBox listBox = sender as ListBox;

            if (listBox == null)
            {
                return;
            }

            ListBoxItem item = GetItem(listBox, e.GetPosition);

            if (item != null)
            {
                if (e.Data.GetDataPresent(typeof(List <Mod>)))
                {
                    var     mods   = (List <Mod>)e.Data.GetData(typeof(List <Mod>));
                    Modpack parent = (Modpack)listBox.ItemContainerGenerator.ItemFromContainer(item);
                    foreach (Mod mod in mods)
                    {
                        if (!parent.Contains(mod))
                        {
                            var reference = new ModReference(mod, parent);
                            parent.Mods.Add(reference);
                        }
                    }

                    ModpackTemplateList.Instance.Update(MainViewModel.Instance.Modpacks);
                    ModpackTemplateList.Instance.Save();
                }
                else if (e.Data.GetDataPresent(typeof(List <Modpack>)))
                {
                    var     modpacks = (List <Modpack>)e.Data.GetData(typeof(List <Modpack>));
                    Modpack parent   = (Modpack)listBox.ItemContainerGenerator.ItemFromContainer(item);
                    foreach (Modpack modpack in modpacks)
                    {
                        if (modpack != parent && !parent.Contains(modpack) && !modpack.Contains(parent, true))
                        {
                            var reference = new ModpackReference(modpack, parent);
                            reference.ParentView = parent.ModsView;
                            parent.Mods.Add(reference);
                        }
                    }

                    ModpackTemplateList.Instance.Update(MainViewModel.Instance.Modpacks);
                    ModpackTemplateList.Instance.Save();
                }
            }
            else
            {
                if (e.Data.GetDataPresent(typeof(List <Mod>)))
                {
                    var model = (MainViewModel)ViewModel;
                    var mods  = (List <Mod>)e.Data.GetData(typeof(List <Mod>));
                    model.CreateNewModpack(mods);
                }
            }
        }
 public void ParseTests(string data, string expectedCode, ModType expectedLevel, bool throws = false)
 {
     if (throws)
     {
         Assert.Throws <ModinfoParseException>(() => ModReference.Parse(data));
     }
     else
     {
         var modReference = ModReference.Parse(data);
         Assert.Equal(expectedCode, modReference.Identifier);
         Assert.Equal(expectedLevel, modReference.Type);
     }
 }
        public void EqualsCheck()
        {
            IModReference a = new ModReference {
                Type = ModType.Workshops, Identifier = "123213"
            };
            IModReference b = new ModReference {
                Type = ModType.Workshops, Identifier = "123213"
            };
            IModReference c = new ModReference {
                Type = ModType.Default, Identifier = "123213"
            };
            IModReference d = new ModReference {
                Type = ModType.Default, Identifier = "123213"
            };

            Assert.Equal(a, b);
            Assert.NotEqual(a, c);
            Assert.Equal(c, d);
        }
        public static ModpackExportTemplate FromModpack(Modpack modpack, bool includeVersionInfo)
        {
            var mods     = new List <ModExportTemplate>();
            var modpacks = new List <string>();

            foreach (var reference in modpack.Mods)
            {
                ModReference     modReference     = reference as ModReference;
                ModpackReference modpackReference = reference as ModpackReference;

                if (modReference != null)
                {
                    mods.Add(ModExportTemplate.FromMod(modReference.Mod, includeVersionInfo));
                }
                else if (modpackReference != null)
                {
                    modpacks.Add(modpackReference.Modpack.Name);
                }
            }

            return(new ModpackExportTemplate(modpack.Name, mods.ToArray(), modpacks.ToArray()));
        }
        public void VersionRangeTest(string data, Range?range)
        {
            var modReference = ModReference.Parse(data);

            Assert.Equal(range, modReference.VersionRange);
        }
        public void ModIdentityEqualCheck()
        {
            IModIdentity i1 = new ModinfoData("A");
            IModIdentity i2 = new ModIdentity("A");

            Assert.Equal(i1, i2);

            IModIdentity i3 = new ModinfoData("A")
            {
                Version = new Version(1, 1, 1)
            };
            IModIdentity i4 = new ModIdentity("A")
            {
                Version = new Version(1, 1, 1)
            };

            Assert.Equal(i3, i4);
            Assert.NotEqual(i3, i1);

            IModIdentity i5 = new ModinfoData("B");

            Assert.NotEqual(i1, i5);

            var d1 = new ModReference {
                Type = ModType.Default, Identifier = "A"
            };
            var d2 = new ModReference {
                Type = ModType.Default, Identifier = "A"
            };
            var d3 = new ModReference {
                Type = ModType.Default, Identifier = "B"
            };

            Assert.Equal(d1, d2);

            IModIdentity i6 = new ModinfoData("A")
            {
                Dependencies = new DependencyList(new IModReference[] { d1, d3 }, DependencyResolveLayout.FullResolved)
            };
            IModIdentity i7 = new ModIdentity("A")
            {
                Dependencies = new DependencyList(new IModReference[] { d2, d3 }, DependencyResolveLayout.FullResolved)
            };
            IModIdentity i8 = new ModIdentity("A")
            {
                Dependencies = new DependencyList(new IModReference[] { d2 }, DependencyResolveLayout.FullResolved)
            };
            IModIdentity i9 = new ModIdentity("A")
            {
                Dependencies = new DependencyList(new IModReference[] { d3, d1 }, DependencyResolveLayout.FullResolved)
            };
            IModIdentity i10 = new ModinfoData("A")
            {
                Dependencies = new DependencyList(new IModReference[] { d1 }, DependencyResolveLayout.FullResolved)
            };

            Assert.Equal(i6, i7);
            Assert.NotEqual(i6, i8);
            Assert.NotEqual(i6, i9);
            Assert.Equal(i8, i10);
        }