/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of xAPI4Unity. */ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace xAPI4Unity.Editor { /// /// Represents the result type of a file merge operation. /// [Serializable] public enum MergeResultType { /// /// File was successfully copied. /// Copy, /// /// File was skipped because it already existed and matched. /// Skip, /// /// File resulted in a conflict during the merge operation. /// Conflict } /// /// Represents a single merge result for a specific file, including its path and result type. /// [Serializable] public class MergeResult { /// /// Path of the file involved in the merge operation. /// public string path; /// /// The result type of the merge operation for this file. /// public MergeResultType type; } /// /// Represents the overall merge report, summarizing the results of a merge operation. /// [Serializable] public class MergeReport { /// /// Source directory of the merge operation. /// [SerializeField] public string source; /// /// The timestamp when the merge operation was performed. /// [SerializeField] public DateTime MergeTime = DateTime.Now; /// /// The total number of conflicts encountered during the merge operation. /// [SerializeField] public int conflicts = 0; /// /// The total number of files copied during the merge operation. /// [SerializeField] public int copied = 0; /// /// The total number of files skipped during the merge operation. /// [SerializeField] public int skipped = 0; /// /// A collection of files successfully copied. /// public MergeResult[] CopyResults => results.Where(r => r.type == MergeResultType.Copy).ToArray(); /// /// A collection of files that encountered conflicts. /// public MergeResult[] ConflictResults => results.Where(r => r.type == MergeResultType.Conflict).ToArray(); /// /// A collection of files that were skipped. /// public MergeResult[] SkipResults => results.Where(r => r.type == MergeResultType.Skip).ToArray(); /// /// The list of all merge results. /// [SerializeField] public List results = new List(); /// /// Initializes a new instance with the specified source directory. /// /// The source directory used in the merge operation. public MergeReport(string source) { this.source = source; } /// /// Adds a result for a specific file to the merge report. /// /// The path of the file. /// The result type (Copy, Skip, Conflict). public void AddResult(string path, MergeResultType type) { if (type == MergeResultType.Conflict) conflicts++; else if (type == MergeResultType.Copy) copied++; else if (type == MergeResultType.Skip) skipped++; results.Add(new MergeResult { path = path, type = type }); } /// /// Adds a copy result to the merge report. /// /// The path of the file copied. public void AddCopy(string path) => AddResult(path, MergeResultType.Copy); /// /// Adds a skip result to the merge report. /// /// The path of the file skipped. public void AddSkip(string path) => AddResult(path, MergeResultType.Skip); /// /// Adds a conflict result to the merge report. /// /// The path of the file that caused a conflict. public void AddConflict(string path) => AddResult(path, MergeResultType.Conflict); } }