Example #1
0
        public void TestModletListWithMalformedSteps()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                intValue = 10, boolValue = false
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition
            {
                guid       = "a",
                modletlist = new List <ModletStep> {
                    new ModletStep {
                        field = "intValue", value = 20
                    },
                    new ModletStep {
                        field = null, value = 20
                    },
                    new ModletStep {
                        field = "NoValue", value = null
                    },
                    new ModletStep {
                        field = null, value = null
                    },
                    new ModletStep {
                        field = "boolValue", value = true
                    }
                }
            };
            ModFile f = new ModFile("ModlietListWithMalformedSteps", repo, new MockLogger());

            f.ApplyMod(mod);
            Assert.AreEqual(obj.intValue, 20);
            Assert.IsTrue(obj.boolValue);
        }
Example #2
0
        public void ConversionTest()
        {
            ModDefinition mod = JsonToModDef(@"{
                guid: ""g"",
                cls: ""c"",
                field: ""f"",
                value: -43.21,
                comment: ""//"",
                flags: [""foo"",""bar""],
                modletlist : [
                    { ""field"": ""txt"", ""value"": ""mv1"" },
                    { ""field"": ""int"", ""value"": 1234 },
                    { ""field"": ""dec"", ""value"": 12.34 },
                    { ""field"": ""bol"", ""value"": true },
                ],
            }");

            Assert.AreEqual("g", mod.guid, "guid");
            Assert.AreEqual("c", mod.cls, "cls");
            Assert.AreEqual("f", mod.field, "field");
            Assert.AreEqual(-43.21, mod.value, "value");
            Assert.AreEqual("//", mod.comment, "comment");
            CollectionAssert.AreEqual(new string[] { "foo", "bar" }, mod.flags, "flags");
            Assert.AreEqual(4, mod.modletlist?.Count, "modletlist");
            Assert.AreEqual("txt", mod.modletlist[0].field, "modletlist[0].field");
            Assert.AreEqual("mv1", mod.modletlist[0].value, "modletlist[0].value");
            Assert.AreEqual("int", mod.modletlist[1].field, "modletlist[1].field");
            Assert.AreEqual(1234L, mod.modletlist[1].value, "modletlist[1].value");
            Assert.AreEqual("dec", mod.modletlist[2].field, "modletlist[2].field");
            Assert.AreEqual(12.34, mod.modletlist[2].value, "modletlist[2].value");
            Assert.AreEqual("bol", mod.modletlist[3].field, "modletlist[3].field");
            Assert.AreEqual(true, mod.modletlist[3].value, "modletlist[3].value");
        }
Example #3
0
        private void buttonMap_Click(object sender, EventArgs e)
        {
            string ecuid;

            if (SharpTuner.ActiveImage != null && SharpTuner.ActiveImage.Definition.CarInfo.ContainsKey("ecuid"))
            {
                ecuid = SharpTuner.ActiveImage.Definition.CarInfo["ecuid"].ToString();
            }
            else
            {
                ecuid = SimplePrompt.ShowDialog("Enter ECU Identifier (logger identifier)", "Enter EcuId");
            }
            ofd.Filter = "MAP Files (*.map)|*.map";
            DialogResult res = Utils.STAShowOFDialog(ofd);

            if (res == DialogResult.OK)
            {
                //try
                //{
                SharpTuner.ActiveImage.Definition.ImportMapFile(ofd.FileName, SharpTuner.ActiveImage); //TODO: clean up creation of XML whitespace sucks ass.
                SharpTuner.ActiveImage.Definition.ExportXML();
                ModDefinition.DefineRRLogEcuFromMap(ofd.FileName, ecuid);                              //TODO: import RR stuff to definnition class and deprecate this??
                MessageBox.Show("Success!");
                this.Close();
                return;
                //catch (Exception err)
                // {
                //     MessageBox.Show(err.Message);
                // }
            }
            this.Close();
            return;
        }
Example #4
0
        public void TestHasFlag()
        {
            ModDefinition def = new ModDefinition {
                flags = null
            };

            Assert.IsFalse(def.HasFlag("Foo"), "null flags");

            def = new ModDefinition {
                flags = new string[] { }
            };
            Assert.IsFalse(def.HasFlag("Foo"), "zero flags");

            def = new ModDefinition {
                flags = new string[] { "" }
            };
            Assert.IsFalse(def.HasFlag("Foo"), "empty flags");

            def = new ModDefinition {
                flags = new string[] { "bar", "foobar" }
            };
            Assert.IsFalse(def.HasFlag("Foo"), "no matching flag");

            def = new ModDefinition {
                flags = new string[] { "foo", "bar" }
            };
            Assert.IsTrue(def.HasFlag("Foo"), "matching flag");
        }
Example #5
0
        public void TestMultiArrayValues()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                arr = new ArrayTestClass.Nested[3] {
                    new ArrayTestClass.Nested {
                        nestedValues = new double[2] {
                            7.0, 8.0
                        }
                    },
                    new ArrayTestClass.Nested {
                        nestedValues = new double[3] {
                            17.0, 18.0, 19.0
                        }
                    },
                    new ArrayTestClass.Nested {
                        nestedValues = new double[4] {
                            27.0, 28.0, 29.0, 30.0
                        }
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "arr[0].nestedValues[1]", value = 10
            };

            new Mod("MultiArrayValues", mod, repo).Apply();
            Assert.AreEqual(obj.arr[0].nestedValues[1], 10.0);
        }
Example #6
0
        private void buttonText_Click(object sender, EventArgs e)
        {
            string ecuid;

            if (SharpTuner.ActiveImage != null && SharpTuner.ActiveImage.Definition.CarInfo.ContainsKey("ecuid"))
            {
                ecuid = SharpTuner.ActiveImage.Definition.CarInfo["ecuid"].ToString();
            }
            else
            {
                ecuid = SimplePrompt.ShowDialog("Enter ECU Identifier (logger identifier)", "Enter EcuId");
            }
            try
            {
                SharpTuner.ActiveImage.Definition.ImportMapText(textBox1.Text, SharpTuner.ActiveImage);//TODO: clean up creation of XML whitespace sucks ass.
                SharpTuner.ActiveImage.Definition.ExportXML();
                ModDefinition.DefineRRLogEcuFromText(textBox1.Text, ecuid);
                MessageBox.Show("Success!");
                this.Close();
                return;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
            this.Close();
            return;
        }
Example #7
0
        public void TestLastArrayObject()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                arr = new ArrayTestClass.Nested[3] {
                    new ArrayTestClass.Nested {
                        value = 7
                    }, new ArrayTestClass.Nested {
                        value = 8
                    }, new ArrayTestClass.Nested {
                        value = 9
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "arr[2].value", value = 10
            };

            new Mod("LastArray", mod, repo).Apply();
            Assert.AreEqual(obj.arr[0].value, 7);
            Assert.AreEqual(obj.arr[1].value, 8);
            Assert.AreEqual(obj.arr[2].value, 10);
        }
Example #8
0
 /// <summary>
 /// Installs a mod, or queues its operations.
 /// </summary>
 /// <param name="modPath">The mod path RELATIVE TO THE BEATONDATAROOT</param>
 private void QueueModInstall(ModDefinition modDefinition)
 {
     try
     {
         var ops = _getEngine().ModManager.GetInstallModOps(modDefinition);
         if (ops.Count > 0)
         {
             ops.Last().OpFinished += (s, e) =>
             {
                 if (e.Status == OpStatus.Complete)
                 {
                     _showToast($"Mod Installed", $"{modDefinition.Name} was installed and activated", ClientModels.ToastType.Success);
                 }
             };
         }
         ops.ForEach(x => _getEngine().OpManager.QueueOp(x));
         ops.WaitForFinish();
         var cfg = _getEngine().GetCurrentConfig();
         _getConfig().Config = cfg;
         _triggerConfigChanged();
     }
     catch (Exception ex)
     {
         Log.LogErr($"Exception in import manager installing mod ID {modDefinition.ID}", ex);
         throw new ImportException($"Exception in import manager installing mod ID {modDefinition.ID}", $"Unable to install mod ID {modDefinition.ID}!", ex);
     }
 }
Example #9
0
        private void buttonMap_Click(object sender, EventArgs e)
        {
            string ecuid;

            if (sharpTuner.activeImage != null && sharpTuner.activeImage.Definition.EcuId != null)
            {
                ecuid = sharpTuner.activeImage.Definition.EcuId.ToString();
            }
            else
            {
                ecuid = SimplePrompt.ShowDialog("Enter ECU Identifier (logger identifier)", "Enter EcuId");
            }
            ofd.Filter = "MAP Files (*.map)|*.map";
            DialogResult res = Utils.STAShowOFDialog(ofd);

            if (res == DialogResult.OK)
            {
                //try
                //{
                sharpTuner.activeImage.Definition.ImportMapFile(ofd.FileName, sharpTuner.activeImage); //TODO: clean up creation of XML whitespace sucks ass.
                sharpTuner.activeImage.Definition.ExportEcuFlashXML();
                ModDefinition md = new ModDefinition(sharpTuner.AvailableDevices, null);               //TODO: major KLUDGE
                md.DefineRRLogEcuFromMap(ofd.FileName, ecuid);                                         //TODO: import RR stuff to definnition class and deprecate this??
                MessageBox.Show("Success!");
                this.Close();
                return;
                //catch (Exception err)
                // {
                //     MessageBox.Show(err.Message);
                // }
            }
            this.Close();
            return;
        }
Example #10
0
 public ModPrototype(ModDefinition definition, ReadOnlyFileSystem fileSystem,
                     ModManifest manifest)
 {
     Definition = definition;
     FileSystem = fileSystem;
     Manifest = manifest;
 }
Example #11
0
        public void Modnix3ActionMod()
        {
            MockApi.mockApiVersion = new Version(3, 1);
            PPDefMod.api           = MockApi.Api;
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass();

            repo.AddDef("a", obj);

            ModDefinition mod = JsonToModDef("{flags:[\"Actions\"],guid:\"a\",field:\"boolValue\",value:true}");

            new ModFile("ActionMod.Simple", repo, new MockLogger()).ApplyMod(mod);
            Assert.AreEqual(true, obj.boolValue); // Modified

            mod = JsonToModDef("{flags:[\"Actions\"],guid:\"a\",modletlist:[" +
                               "{field:\"intValue\",value:1234}," +
                               "{field:\"doubleValue\",value:12.34}," +
                               "{field:\"boolValue\",value:false}," +
                               "{field:\"stringValue\",value:\"foobar\"}]}");
            new ModFile("ActionMod.Modlet", repo, new MockLogger()).ApplyMod(mod);
            Assert.AreEqual(1234, obj.intValue);
            Assert.AreEqual(12.34, obj.doubleValue);
            Assert.AreEqual(false, obj.boolValue);
            Assert.AreEqual("foobar", obj.stringValue);
        }
Example #12
0
        private void buttonText_Click(object sender, EventArgs e)
        {
            string ecuid;

            if (sharpTuner.activeImage != null && sharpTuner.activeImage.Definition.EcuId != null)
            {
                ecuid = sharpTuner.activeImage.Definition.EcuId;
            }
            else
            {
                ecuid = SimplePrompt.ShowDialog("Enter ECU Identifier (logger identifier)", "Enter EcuId");
            }
            try
            {
                sharpTuner.activeImage.Definition.ImportMapText(textBox1.Text, sharpTuner.activeImage);//TODO: clean up creation of XML whitespace sucks ass.
                sharpTuner.activeImage.Definition.ExportEcuFlashXML();
                ModDefinition md = new ModDefinition(sharpTuner.AvailableDevices, null);
                md.DefineRRLogEcuFromText(textBox1.Text, ecuid);
                MessageBox.Show("Success!");
                this.Close();
                return;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
            this.Close();
            return;
        }
Example #13
0
        public void BothGuidAndCls()
        {
            ModDefinition def = new ModDefinition {
                guid = "a", cls = "b", comment = null, value = 0, field = null
            };

            Assert.ThrowsException <ModException>(() => new Mod("BothGuidAndClass", def, null).Validate());
        }
Example #14
0
        public void NoField()
        {
            ModDefinition def = new ModDefinition {
                guid = "a", cls = null, comment = null, value = 0, field = null
            };

            Assert.ThrowsException <ModException>(() => new Mod("NoField", def, null).Validate());
        }
Example #15
0
        public void ValidCls()
        {
            ModDefinition def = new ModDefinition {
                guid = null, cls = "c", comment = null, value = 0, field = "foo"
            };

            new Mod("ValidCls", def, null).Validate();
        }
Example #16
0
        public void BothFieldAndModletlist()
        {
            ModDefinition def = new ModDefinition {
                guid = null, cls = "c", comment = null, value = 0, field = "foo", modletlist = new List <ModletStep>()
            };

            Assert.ThrowsException <ModException>(() => new Mod("BothFieldAndModletList", def, null).Validate());
        }
Example #17
0
        public ModDefinition JsonToModDef(string json)
        {
            ModDefinition mod    = new ModDefinition();
            ModnixAction  action = JsonConvert.DeserializeObject <ModnixAction>(json);

            PPDefMod.ConvertActionToMod(action, mod);
            return(mod);
        }
Example #18
0
        private static Task SaveModpacksAsync()
        {
            var factory = new ExporterFactory();

            int id          = 0;
            var modMappings = new Dictionary <Mod, int>();

            foreach (var modManager in Manager.ModManagers)
            {
                foreach (var mod in modManager)
                {
                    // Assign an ID to every mod (note we do actually want reference equality here)
                    modMappings.Add(mod, id);

                    var modDef = new ModDefinition(id, mod.Name, ExportMode.SpecificVersion, mod.Version);
                    factory.ModDefinitions.Add(modDef);

                    id++;
                }
            }

            var modpackMappings = _modpacks.Swap(); // Safe here since both directions are unique

            foreach (var modpack in Modpacks)
            {
                var modIds     = new List <int>();
                var modpackIds = new List <int>();

                foreach (var child in modpack)
                {
                    if (child is Mod mod)
                    {
                        int modId = modMappings[mod];
                        modIds.Add(modId);
                    }
                    else if (child is Modpack subPack)
                    {
                        int packId = modpackMappings[subPack];
                        modpackIds.Add(packId);
                    }
                }

                var packDef = new ModpackDefinition(modpackMappings[modpack], modpack.DisplayName, modIds, modpackIds);
                factory.ModpackDefinitions.Add(packDef);
            }

            var    exporter = factory.CreateExporter();
            string path     = Path.Combine(ApplicationDataDirectory.FullName, "modpacks.json");

            return(exporter.ExportAsync(path));
        }
Example #19
0
        public void TestStaticInt()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
            };

            TestClass.Nested.staticIntValue = 0;
            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                cls = "PPDefModifierTests.ApplyModTests+TestClass+Nested, PPDefModifierTests", field = "staticIntValue", value = 5
            };

            new Mod("StaticInt", mod, repo).Apply();
            Assert.AreEqual(TestClass.Nested.staticIntValue, 5);
        }
Example #20
0
        public void TestSimpleInt()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                intValue = 10
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "intValue", value = 5
            };

            new Mod("SimpleInt", mod, repo).Apply();
            Assert.AreEqual(obj.intValue, 5);
        }
Example #21
0
        public void TestSimpleString()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                stringValue = "foo"
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "stringValue", value = "bar"
            };

            new Mod("SimpleString", mod, repo).Apply();
            Assert.AreEqual(obj.stringValue, "bar");
        }
Example #22
0
        public void TestSimpleDouble()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                doubleValue = 20.0
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "doubleValue", value = 50.0
            };

            new Mod("SimpleDouble", mod, repo).Apply();
            Assert.AreEqual(obj.doubleValue, 50.0);
        }
Example #23
0
        public void TestSimpleBool()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                boolValue = false
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "boolValue", value = 1
            };

            new Mod("SimpleBool", mod, repo).Apply();
            Assert.IsTrue(obj.boolValue);
        }
Example #24
0
        public void TestStructMember()
        {
            MockRepo     repo = new MockRepo();
            NestedStruct obj  = new NestedStruct {
                nested = new NestedStruct.Nested {
                    Value = 0
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "nested.Value", value = 10
            };

            new Mod("NestedStruct", mod, repo).Apply();
            Assert.AreEqual(10, obj.nested.Value);
        }
Example #25
0
        public void TestNestedInt()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                nested = new TestClass.Nested {
                    intValue = 0
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "nested.intValue", value = 10
            };

            new Mod("NestedInt", mod, repo).Apply();
            Assert.AreEqual(obj.nested.intValue, 10);
        }
Example #26
0
        public void TestWrongGuid()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                nested = new TestClass.Nested {
                    anotherNest = new TestClass.Nested.AnotherNest {
                        intValue = 0
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "b", field = "nested.anotherNest.intValue", value = 10
            };

            Assert.ThrowsException <ArgumentException>(() => new Mod("WrongGuid", mod, repo).Apply());
        }
Example #27
0
        public void TestNonPrimitiveField()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                nested = new TestClass.Nested {
                    anotherNest = new TestClass.Nested.AnotherNest {
                        intValue = 0
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "nested", value = 10
            };

            Assert.ThrowsException <ModException>(() => new Mod("NonPrimitiveField", mod, repo).Apply());
        }
Example #28
0
        public String Locate(ModDefinition definition, Boolean allowZipMods)
        {
            // This method isn't quite as performance-friendly as it could be, but
            // given how often it's called I think it's never going to really be the
            // bottleneck.

            Debug.Assert(definition != null, "definition != null");

            foreach (Tuple<String, ModDefinition> child in this.SearchPathChildren)
            {
                if (definition.IsSatisfiedBy(child.Item2))
                {
                    if (allowZipMods && child.Item1.EndsWith(".zip", true, CultureInfo.CurrentCulture))
                        return child.Item1;
                }
            }

            return null;
        }
Example #29
0
        public void TestLastArrayValue()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                values = new double[3] {
                    7.0, 8.0, 9.0
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "values[2]", value = 10
            };

            new Mod("LastArrayValue", mod, repo).Apply();
            Assert.AreEqual(obj.values[0], 7.0);
            Assert.AreEqual(obj.values[1], 8.0);
            Assert.AreEqual(obj.values[2], 10.0);
        }
Example #30
0
        public void TestStructInStruct()
        {
            MockRepo     repo = new MockRepo();
            NestedStruct obj  = new NestedStruct {
                nested = new NestedStruct.Nested {
                    further = new NestedStruct.Nested.Further {
                        Value2 = 7
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "nested.further.Value2", value = 10
            };

            new Mod("StructInStruct", mod, repo).Apply();
            Assert.AreEqual(10, obj.nested.further.Value2);
        }
Example #31
0
        public void TestBadBracket()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                arr = new ArrayTestClass.Nested[3] {
                    new ArrayTestClass.Nested {
                        value = 7
                    }, new ArrayTestClass.Nested {
                        value = 8
                    }, new ArrayTestClass.Nested {
                        value = 9
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "arr[.value", value = 10
            };

            Assert.ThrowsException <ModException>(() => new Mod("BadBracket", mod, repo).Apply());
        }
Example #32
0
        public void TestStructList()
        {
            MockRepo     repo = new MockRepo();
            NestedStruct obj  = new NestedStruct {
                nestedList = new List <NestedStruct.Nested> {
                    new NestedStruct.Nested {
                        Value = 7
                    }, new NestedStruct.Nested {
                        Value = 8
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "nestedList[1].Value", value = 10
            };

            new Mod("NestedStructList", mod, repo).Apply();
            Assert.AreEqual(7, obj.nestedList[0].Value);
            Assert.AreEqual(10, obj.nestedList[1].Value);
        }
Example #33
0
        public ModManifest GetManifest(ModDefinition definition, ReadOnlyFileSystem fileSystem)
        {
            var manifestFile = FileSystemPath.Root.AppendFile("manifest.xml");

            if (fileSystem.Exists(manifestFile) == false)
            {
                throw new FileNotFoundException("Could not find manifest file for {0}.",
                    definition.ToString(false));
            }

            String input = fileSystem.OpenFile(manifestFile, FileAccess.Read).ReadAllText();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(input);

            XmlElement node = xmlDoc["mod"];

            if (node == null)
            {
                throw new InvalidDataException("No 'mod' element found in manifest.xml.");
            }

            return ModManifest.FromXml(node);
        }
Example #34
0
 public ModNotFoundException(ModDefinition definition)
     : base(String.Format("Mod not found: {0}", definition.ToString((true))))
 {
 }