コード例 #1
0
        public static ModActionCollection GetModActions(GameModification[] mods)
        {
            var collection = new ModActionCollection();

            // We need to collate these steps, so we can minimize collision issues
            foreach (var mod in mods)
            {
                collection.AddActionsFromMod(mod);
            }

            return(collection);
        }
コード例 #2
0
        private async Task <InstallationStatus> QuickBMSExtract(ModAction <QuickBMSExtractAction> modAction, string tempFolder, bool autoUnpack)
        {
            foreach (var file in modAction.action.TargetFiles)
            {
                var physicalTargetPath = ResolvePath(file, modAction.mod, configuration);
                var fileInfo           = new FileInfo(physicalTargetPath);

                // Check if this has already been extracted
                if (extractedFiles.Contains(physicalTargetPath))
                {
                    continue;
                }

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

                await QuickBMSUtility.ExtractFiles(physicalTargetPath, tempFolder);

                // Move all extracted files into the root folder
                var newFolder = Path.Combine(tempFolder, Path.GetFileNameWithoutExtension(fileInfo.Name));
                var newFiles  = Directory.GetFiles(newFolder, "*", SearchOption.AllDirectories);

                extractedFiles.Add(physicalTargetPath);

                foreach (var newFile in newFiles)
                {
                    var targetPath = Path.Combine(fileInfo.Directory.FullName, newFile.Substring(newFolder.Length).TrimStart('\\').TrimStart('/'));
                    MoveFile_Internal(newFile, targetPath, modAction.mod);
                }

                if (autoUnpack && HasAutoMapping(physicalTargetPath, configuration, out var autoMapping))
                {
                    var autoUnpackActions = new ModActionCollection();
                    autoUnpackActions.AddActions(modAction.mod, autoMapping.Actions);

                    PerformActions(autoUnpackActions);
                }

                // Allow these files to be automatically deleted when finished with
                if (modAction.action.DeleteWhenComplete)
                {
                    DeleteFile_Internal(physicalTargetPath, modAction.mod);
                    deletedFiles.Add(physicalTargetPath);
                }
            }

            return(InstallationStatus.Success);
        }
コード例 #3
0
        private async Task <InstallationStatus> ApplyChangesInternal(GameModification[] mods, bool ignoreWarnings, bool reverting)
        {
            tempFolder    = CreateTempFolder();
            reservedFiles = GetReservedFiles();
            autoMappings  = GetAutoMappings();
            fileWriter    = new FileWriterUtility();

            // Start with a blank canvas
            RemoveAllChanges(configuration);

            if (mods.Length == 0)
            {
                return(InstallationStatus.Success);
            }

            try
            {
                modActions = GetModActions(mods);

                // Write any data as required to the virtualreader file, make sure to offset by bytesWritten if needed

                foreach (var action in modActions.extractActions)
                {
                    await QuickBMSExtract(action, tempFolder, action.action.UseAutoMapping);
                }

                foreach (var action in modActions.decompileActions)
                {
                    await UnluacDecompile(action, tempFolder);
                }

                var actionStatus = PerformActions(modActions);

                if (actionStatus != InstallationStatus.Success)
                {
                    return(actionStatus);
                }
            }
            catch (Exception ex)
            {
                Logging.LogMessage(ex.ToString(), Logging.LogSeverity.Error);

                if (Directory.Exists(tempFolder))
                {
                    Directory.Delete(tempFolder, true);
                }

                if (reverting)
                {
                    // If we error out during revert, delete everything (something has gone badly wrong)
                    RemoveAllChanges(configuration);
                    return(InstallationStatus.FatalError);
                }
                else
                {
                    // Revert back to the previous install state
                    await ApplyChangesInternal(mods.Take(mods.Count() - 1).ToArray(), true, true);

                    return(InstallationStatus.RolledBackError);
                }
            }
            finally
            {
                if (Directory.Exists(tempFolder))
                {
                    Directory.Delete(tempFolder, true);
                }
            }

            return(InstallationStatus.Success);
        }
コード例 #4
0
        private InstallationStatus PerformActions(ModActionCollection modActions)
        {
            foreach (var action in modActions.fileCopyActions)
            {
                var status = CopyFile(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.bulkFileCopyActions)
            {
                var status = BulkCopyFiles(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.fileReplaceActions)
            {
                var status = ReplaceFile(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.bulkFileReplaceActions)
            {
                var status = BulkReplaceFiles(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.fileWriteActions)
            {
                var status = WriteToFile(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.fileMoveActions)
            {
                var status = MoveFile(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.bulkFileMoveActions)
            {
                var status = BulkMoveFiles(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            foreach (var action in modActions.fileDeleteActions)
            {
                var status = DeleteFile(action);

                if (status != InstallationStatus.Success)
                {
                    return(status);
                }
            }

            return(InstallationStatus.Success);
        }