Exemplo n.º 1
0
        private InstallationStatus ReplaceFile(string replacementFile, string targetFile, GameModification mod)
        {
            if (ModCollisionTracker.HasReplaceCollision(mod, targetFile, replacementFile, modifications, out var collision))
            {
                return(HandleCollision(collision));
            }

            if (!File.Exists(targetFile))
            {
                throw new Exception($"Unable to find target path: {targetFile}");
            }

            CopyFile_Internal(replacementFile, targetFile, mod);
            return(InstallationStatus.Success);
        }
Exemplo n.º 2
0
        private InstallationStatus WriteToFile(ModAction <WriteToFileAction> modAction)
        {
            foreach (var content in modAction.action.Content)
            {
                var    physicalTargetPath = ResolvePath(modAction.action.TargetFile, modAction.mod, configuration);
                string filePath           = null;

                if (!File.Exists(physicalTargetPath))
                {
                    throw new Exception($"Unable to find target path: {physicalTargetPath}");
                }

                if (!string.IsNullOrEmpty(content.DataFilePath))
                {
                    filePath = ResolvePath(content.DataFilePath, modAction.mod, configuration);
                }

                var dataToWrite = content.Text ?? File.ReadAllText(filePath);

                if (ModCollisionTracker.HasEditCollision(modAction.mod, physicalTargetPath, content, fileWriter, modifications, out var collision))
                {
                    return(HandleCollision(collision));
                }

                if (IsReservedFile(physicalTargetPath))
                {
                    modifications.Add(new EditFileModification(physicalTargetPath, true, modAction.mod.Config.ModID));
                    BackupFile(physicalTargetPath);
                }
                else
                {
                    modifications.Add(new EditFileModification(physicalTargetPath, false, modAction.mod.Config.ModID));
                }

                if (content.EndOffset.HasValue)
                {
                    fileWriter.WriteToFileRange(physicalTargetPath, dataToWrite, content.StartOffset, content.EndOffset.Value, false);
                }
                else
                {
                    fileWriter.WriteToFile(physicalTargetPath, dataToWrite, content.StartOffset, !content.Replace, false);
                }
            }

            return(InstallationStatus.Success);
        }
Exemplo n.º 3
0
        private InstallationStatus CopyFile(string targetFile, string destinationPath, GameModification mod)
        {
            if (ModCollisionTracker.HasCopyCollision(mod, targetFile, destinationPath, modifications, out var collision))
            {
                return(HandleCollision(collision));
            }

            if (!File.Exists(targetFile))
            {
                throw new Exception($"Unable to find target path: {targetFile}");
            }

            // Copying files occurs near the start, and should not cause conflicts

            CopyFile_Internal(targetFile, destinationPath, mod);
            return(InstallationStatus.Success);
        }
Exemplo n.º 4
0
        private InstallationStatus MoveFile(string targetFile, string destinationPath, GameModification mod)
        {
            // Have we already moved this file to the exact same destination?
            if (HasMovedFileToSameDestination(targetFile, destinationPath))
            {
                return(InstallationStatus.Success);
            }

            if (ModCollisionTracker.HasMoveCollision(mod, targetFile, destinationPath, modifications, out var collision))
            {
                return(HandleCollision(collision));
            }

            if (!File.Exists(targetFile))
            {
                throw new Exception($"Unable to find target path: {targetFile}");
            }

            MoveFile_Internal(targetFile, destinationPath, mod);
            return(InstallationStatus.Success);
        }