Example #1
0
        private static string[] OnWillSaveAssets(string[] assets)
        {
            if (UnityEditorInternal.InternalEditorUtility.inBatchMode ||
                !VCCommands.Active ||
                VCSettings.SaveStrategy == VCSettings.ESaveAssetsStrategy.Unity ||
                VCCommands.Instance.FlusingFiles ||
                EditorApplication.isCompiling)
            {
                return(assets);
            }


            if (assets.Any(a => VCCommands.Instance.GetAssetStatus(a).reflectionLevel == VCReflectionLevel.None))
            {
                VCCommands.Instance.Status(assets, StatusLevel.Previous);
            }

            var toBeSaved = new List <string>();
            var noControl = new List <string>();

            foreach (var asset in assets)
            {
                //D.Log(asset+ " has ignored parentfolder: " + VCCommands.Instance.InIgnoredParentFolder(asset));
                if (VCUtility.HaveAssetControl(asset) || !VCUtility.ManagedByRepository(asset) || asset.InUnversionedParentFolder(VCCommands.Instance) || asset.InIgnoredParentFolder(VCCommands.Instance))
                {
                    toBeSaved.Add(asset);
                }
                else
                {
                    noControl.Add(asset);
                }
            }

            if (noControl.Count > 0)
            {
                foreach (var asset in noControl)
                {
                    string message = string.Format("Unity is trying to save following file which is not under control on {1}.\n\n'{0}'", asset, VCSettings.VersionControlBackend, Terminology.getlock);
                    int    result  = UserDialog.DisplayDialogComplex("Save File?", message, Terminology.allowLocalEdit, Terminology.getlock, "Do not save");
                    if (result == 0 || result == 1)
                    {
                        toBeSaved.Add(asset);
                        if (result == 0)
                        {
                            VCCommands.Instance.AllowLocalEdit(new[] { asset });
                        }

                        if (result == 1)
                        {
                            VCCommands.Instance.GetLock(new[] { asset }, OperationMode.Normal);
                        }
                    }
                }
            }
            return(toBeSaved.ToArray());
        }
Example #2
0
        private static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (!UseTeamLicence)
            {
                return(AssetMoveResult.DidNotMove);
            }

            VersionControlStatus status = VCCommands.Instance.GetAssetStatus(from);

            if (VCUtility.ManagedByRepository(status))
            {
                if (DisplayConfirmationDialog("Move", from, status))
                {
                    string topUnversionedFolder;
                    if (InUnversionedParentFolder(to, out topUnversionedFolder))
                    {
                        int result = UserDialog.DisplayDialogComplex("Add Folder?", "Versioned files are moved into an unversioned folder. Add following unversioned folder first?\n\n" + topUnversionedFolder, "Yes", "No", "Cancel");
                        if (result == 0)
                        {
                            VCCommands.Instance.Add(new[] { topUnversionedFolder });
                            VCCommands.Instance.Status(new[] { topUnversionedFolder }, StatusLevel.Local);
                        }
                        if (result == 2)
                        {
                            return(AssetMoveResult.FailedMove);
                        }
                    }
                    if (InUnversionedParentFolder(from, out topUnversionedFolder))
                    {
                        return(AssetMoveResult.DidNotMove);
                    }
                    if (VCCommands.Instance.Move(from, to))
                    {
                        DebugLog.Log("Version Control Move: " + from + " => " + to);
                        return(AssetMoveResult.DidMove);
                    }
                    return(AssetMoveResult.DidNotMove);
                }
                return(AssetMoveResult.FailedMove);
            }
            return(AssetMoveResult.DidNotMove);
        }
        public static void HandleConflicts()
        {
            var conflicts = VCCommands.Instance.GetFilteredAssets(s => s.fileStatus == VCFileStatus.Conflicted || s.MetaStatus().fileStatus == VCFileStatus.Conflicted).Select(status => status.assetPath).ToArray();

            if (conflicts.Any())
            {
                foreach (var conflictIt in conflicts)
                {
                    if (ignoredConflicts.Contains(conflictIt))
                    {
                        continue;
                    }
                    bool         mergable          = MergeHandler.IsMergableAsset(conflictIt);
                    const string explanation       = "\nTheirs :\nUse the file from the server and discard local changes to the file\n\nMine :\nUse my version of the file and discard the changes someone else made on the server. File will become 'Local Only'";
                    const string mergeExplanation  = "\nMerge External :\nIgnore the conflict in UVC and handle the conflict in an external program";
                    const string ignoreExplanation = "\nIgnore :\nIgnore the conflict for now although the file will not be readable by Unity";
                    string       message           = $"There is a conflict in the file:\n '{conflictIt.Compose()}'\n\nUse 'Theirs' or 'Mine'?\n {explanation}\n{(mergable ? mergeExplanation : ignoreExplanation)}\n";
                    int          result            = UserDialog.DisplayDialogComplex("Conflict", message, "Theirs", "Mine", mergable ? "Merge External" : "Ignore");
                    if (result == 0 || result == 1)
                    {
                        VCCommands.Instance.Resolve(new[] { conflictIt.Compose() }, result == 0 ? ConflictResolution.Theirs : ConflictResolution.Mine);
                    }
                    else
                    {
                        ignoredConflicts.Add(conflictIt);
                        if (mergable)
                        {
                            string assetPath = conflictIt.Compose();
                            if (VCCommands.Instance.GetConflict(assetPath, out var basePath, out var yours, out var theirs))
                            {
                                MergeHandler.ResolveConflict(assetPath, basePath, theirs, yours);
                            }
                        }
                    }
                }
                OnNextUpdate.Do(AssetDatabase.Refresh);
            }
        }