コード例 #1
0
        public ModLoadStatus TryAddMod(string fileName, byte[] fileBytes)
        {
            var modInstallPath = Path.Combine(ModLoaderUtility.GetModPath(), fileName);

            if (File.Exists(modInstallPath))
            {
                modInstallPath = FileWriterUtility.GetUniqueFilePath(modInstallPath);
            }

            var fileInfo = new FileInfo(modInstallPath);

            File.WriteAllBytes(modInstallPath, fileBytes);

            // Add this mod to the mod list, so it will attemp to be loaded
            Settings.AvailableMods.Add(fileInfo.Name);

            ReloadMods();

            var result  = ModLoadResults.First(r => r.modFileName == fileInfo.Name).status;
            var success = result == ModLoadStatus.Success;

            if (!success)
            {
                // If this mod failed to load,
                File.Delete(modInstallPath);
                Settings.AvailableMods.Remove(fileInfo.Name);
                ReloadMods();
            }
            else
            {
                SaveSettings();
            }

            return(result);
        }
コード例 #2
0
        public void CheckFileWriteWithMove()
        {
            var actions = new List <FileModification>()
            {
                new MoveFileModification(exampleFile1, exampleDestination1, false, "Test.Move")
            };

            var fileWriter = new FileWriterUtility();
            var content    = new WriteToFileAction.WriteContent()
            {
                Text = "Test", StartOffset = 12
            };
            var mod = new GameModification()
            {
                Config = new Data.BaseModConfiguration()
                {
                    ModID = "Test.Edit"
                }
            };

            bool hasCollision = ModCollisionTracker.HasEditCollision(mod, exampleFile1, content, fileWriter, actions, out var collision);

            Assert.AreEqual(true, hasCollision);
            Assert.AreEqual(collision.severity, ModCollisionSeverity.Clash);
            Assert.AreEqual(collision.modID, "Test.Move");
            Assert.IsTrue(collision.description.Contains("Attempting to write to a file that has been moved by another mod"), $"Actual: {collision.description}");
        }
コード例 #3
0
        public void Setup()
        {
            fileWriter = new FileWriterUtility();

            var executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            tempFile = Path.Combine(executionPath, "TEST_0526c915-4036-480b-90c5-3a8ef2088de6.txt");

            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }

            File.WriteAllText(tempFile, "abcdefghijklmnopqrstuvqxyz1234567890");
        }