PatchworkLauncher.LaunchManager.Command_Direct_AddPatch C# (CSharp) Méthode

Command_Direct_AddPatch() public méthode

public Command_Direct_AddPatch ( string path, bool isEnabled ) : PatchInstruction
path string
isEnabled bool
Résultat PatchInstruction
		public PatchInstruction Command_Direct_AddPatch(string path, bool isEnabled) {
			var targetPath = path;
			var fileName = Path.GetFileName(path);

			var hadToCopy = false;
			PatchingManifest manifest = null;
			try {
				Directory.CreateDirectory(_modFolder);
				var folder = Path.GetDirectoryName(path);
				var absoluteFolder = PathHelper.GetAbsolutePath(folder);
				var modsPath = PathHelper.GetAbsolutePath(_modFolder);

				if (!Preferences.DontCopyFiles
					&& !modsPath.Equals(absoluteFolder, StringComparison.InvariantCultureIgnoreCase)) {
					targetPath = Path.Combine(_modFolder, fileName);
					File.Copy(path, targetPath, true);
					hadToCopy = true;
				}
				manifest = ManifestMaker.CreateManifest(PathHelper.GetAbsolutePath(targetPath));
				if (manifest.PatchInfo == null) {
					throw new PatchDeclerationException("The patch did not have a PatchInfo class.");
				}
				var patchInstruction = new PatchInstruction {
					IsEnabled = isEnabled,
					Patch = manifest,
					PatchLocation = PathHelper.GetRelativePath(targetPath),
					AppInfo = AppInfo,
					PatchOriginalLocation = path
				};
				Instructions.Add(patchInstruction);
				return patchInstruction;
			}
			catch (Exception ex) {
				Logger.Error(ex, $"The patch located in {path} could not be loaded.");
				manifest?.Dispose();
				if (hadToCopy) {
					File.Delete(targetPath);
				}
				throw;
			}
		}