示例#1
0
        public static bool HasReplaceCollision(GameModification currentMod, string file, string replacementFile, List <FileModification> modifications, out ModCollision collision)
        {
            var actions = new ActionCollection(file, currentMod.Config.ModID, modifications);

            if (actions.moveAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Replace, FileModificationType.Moved, actions.moveAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (actions.replaceAction != null && MD5Utility.CalculateMD5Hash(file) != MD5Utility.CalculateMD5Hash(replacementFile))
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Replace, FileModificationType.Replaced, actions.replaceAction.ModID, ModCollisionSeverity.Clash, out collision, suffix: "(with different data)"));
            }

            if (actions.editAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Replace, FileModificationType.Edited, actions.editAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (actions.deleteAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Replace, FileModificationType.Deleted, actions.deleteAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            collision = null;
            return(false);
        }
示例#2
0
        public static bool HasCopyCollision(GameModification currentMod, string file, string destinationPath, List <FileModification> modifications, out ModCollision collision)
        {
            var actions            = new ActionCollection(file, currentMod.Config.ModID, modifications);
            var destinationActions = new ActionCollection(destinationPath, currentMod.Config.ModID, modifications);

            if (actions.moveAction != null && destinationPath != (actions.moveAction as MoveFileModification).DestinationPath)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Copy, FileModificationType.Moved, actions.moveAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (actions.replaceAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Copy, FileModificationType.Replaced, actions.replaceAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (actions.editAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Copy, FileModificationType.Edited, actions.editAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (actions.deleteAction != null)
            {
                return(AddModCollision(currentMod, ModInstallActionEnum.Copy, FileModificationType.Deleted, actions.deleteAction.ModID, ModCollisionSeverity.Clash, out collision));
            }

            if (destinationActions.lastAction != null && !(new[] { FileModificationType.Moved, FileModificationType.Deleted }).Contains(destinationActions.lastAction.Type))
            {
                if (MD5Utility.CalculateMD5Hash(file) != MD5Utility.CalculateMD5Hash(destinationPath))
                {
                    string modPrefix = $"Mod collision detected while installing mod ({currentMod.Config.ModID})";
                    collision = new ModCollision(currentMod.Config.ModID, ModCollisionSeverity.Clash, $"{modPrefix}: Attempting to copy a file to a destination that has been modified by another mod (with different data) (conflicting mod: {destinationActions.lastAction.ModID})");
                    return(true);
                }
            }

            collision = null;
            return(false);
        }