Пример #1
0
 public static bool VCDialog(string command, IEnumerable <string> assetPaths)
 {
     if (!assetPaths.Any())
     {
         return(false);
     }
     return(UserDialog.DisplayDialog(command + " following assest in Version Control?", "\n" + assetPaths.Aggregate((a, b) => a + "\n" + b), "Yes", "No"));
 }
Пример #2
0
        private static void HandleMixedRevision(VCMixedRevisionException e)
        {
            var answer = UserDialog.DisplayDialog("Mixed Revision", "Cannot merge into mixed-revision working copy, try updating first", "Update", "Cancel");

            if (answer)
            {
                VCCommands.Instance.UpdateTask();
            }
        }
Пример #3
0
        private static void HandleNewerVersion(VCNewerVersionException e)
        {
            var answer = UserDialog.DisplayDialog("Newer Version", "There is a newer version of the file on the server so you need to 'Update' first and then try again", "Update", "Cancel");

            if (answer)
            {
                VCCommands.Instance.UpdateTask();
            }
        }
Пример #4
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());
        }
Пример #5
0
        public static bool GetLock(string assetpath, OperationMode operationMode = OperationMode.Normal)
        {
            var status = VCCommands.Instance.GetAssetStatus(assetpath);

            if (operationMode == OperationMode.Normal || UserDialog.DisplayDialog("Force " + Terminology.getlock, "Are you sure you will steal the file from: [" + status.owner + "]", "Yes", "Cancel"))
            {
                return(VCCommands.Instance.GetLock(new[] { assetpath }, operationMode));
            }
            return(false);
        }
Пример #6
0
        private static void VCForceGetLockGameobjectContext(MenuCommand command)
        {
            string assetPath = command.context.GetAssetPath();
            VersionControlStatus assetStatus = VCCommands.Instance.GetAssetStatus(assetPath);

            if (assetStatus.lockStatus == VCLockStatus.LockedOther)
            {
                if (UserDialog.DisplayDialog("Force " + Terminology.getlock, "Are you sure you will steal the file from: [" + assetStatus.owner + "]", "Yes", "Cancel"))
                {
                    VCCommands.Instance.GetLock(new[] { assetPath }, OperationMode.Force);
                }
            }
        }
Пример #7
0
        private static bool DisplayConfirmationDialog(string command, string assetPath, VersionControlStatus assetStatus)
        {
            bool acceptOperation = true;

            if (assetStatus.lockStatus == VCLockStatus.LockedOther)
            {
                acceptOperation = UserDialog.DisplayDialog(command + " on repository?", assetPath + "\nis " + Terminology.getlock + " by [" + assetStatus.owner + "], are you sure you want to " + command + "?", command, "Cancel");
            }
            if (acceptOperation && assetStatus.fileStatus == VCFileStatus.Modified)
            {
                acceptOperation = UserDialog.DisplayDialog(command + " on repository?", assetPath + "\nFile is modified on repository, are you sure you want to " + command + "?", command, "Cancel");
            }
            return(acceptOperation);
        }
Пример #8
0
        public static void ValidateIgnoreFolders(bool forceValidate)
        {
            string workDirectory = Application.dataPath.Remove(Application.dataPath.LastIndexOf("/Assets", StringComparison.InvariantCultureIgnoreCase));
            var    ignores       = VCCommands.Instance.GetIgnore(workDirectory);

            if (ignores != null)
            {
                bool needSetIgnore = !ignores.Contains("Library") || !ignores.Contains("Temp");
                if (needSetIgnore || forceValidate)
                {
                    const string title   = "Fix ignores?";
                    const string message = "Do you want UVC to automatically fix file and folder ignores?";
                    if (UserDialog.DisplayDialog(title, message, "Fix it", "No"))
                    {
                        VCCommands.Instance.SetIgnore(workDirectory, defaultIgnores);
                    }
                }
            }
        }
Пример #9
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);
        }
Пример #10
0
        public static void ResolveConflict(string assetPath, string basepath, string theirs, string yours)
        {
            if (!string.IsNullOrEmpty(assetPath))
            {
                var workingDirectory = GetWorkingDirectory();
                var path             = Path.GetDirectoryName(assetPath);
                var file             = Path.GetFileName(assetPath);
                basepath = Path.GetFullPath(basepath);
                theirs   = Path.GetFullPath(theirs);
                yours    = Path.GetFullPath(yours);
                string   merge         = Path.GetFullPath(assetPath);
                DateTime lastWriteTime = File.GetLastWriteTime(assetPath);

                var(toolpath, args) = GetMergeCommandLine(basepath, theirs, yours, merge);
                var mergeCommand = new CommandLineExecution.CommandLine(toolpath, args, workingDirectory);
                Task.Run(() =>
                {
                    while (true)
                    {
                        Thread.Sleep(100);
                        if (File.GetLastWriteTime(assetPath) != lastWriteTime)
                        {
                            return(true);
                        }
                    }
                }).ContinueWithOnNextUpdate(modified =>
                {
                    VCCommands.Instance.Status(new[] { assetPath }, StatusLevel.Local);
                    if (VCCommands.Instance.GetAssetStatus(assetPath).fileStatus == VCFileStatus.Conflicted)
                    {
                        if (UserDialog.DisplayDialog("Merge Successful?", $"Did the merge complete successfully?\n'{assetPath}'", "Yes", "No"))
                        {
                            VCCommands.Instance.Resolve(new[] { assetPath }, ConflictResolution.Mine);
                            VCCommands.Instance.Status(StatusLevel.Previous, DetailLevel.Normal);
                        }
                    }
                }
                                            );
                Task.Run(() => mergeCommand.Execute());
            }
        }
Пример #11
0
        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);
            }
        }
Пример #12
0
        public static bool UserSelectedVersionControlSystem()
        {
            if (VCSettings.VersionControlBackend == VCSettings.EVersionControlBackend.None)
            {
                bool response = UserDialog.DisplayDialog("Version Control Selection", "Select which Version Control System you are using", "SVN", "None");
                if (response) // SVN
                {
                    VCSettings.VersionControlBackend = VCSettings.EVersionControlBackend.Svn;
                }

                /*P4_DISABLED
                 * int response = UserDialog.DisplayDialogComplex("Version Control Selection", "Select which Version Control System you are using", "SVN", "P4 Beta", "None");
                 * if (response == 0) // SVN
                 * {
                 *  VCSettings.VersionControlBackend = VCSettings.EVersionControlBackend.Svn;
                 * }
                 * else if (response == 1) // Perforce
                 * {
                 *  VCSettings.VersionControlBackend = VCSettings.EVersionControlBackend.P4_Beta;
                 * }*/
            }
            return(VCSettings.VersionControlBackend != VCSettings.EVersionControlBackend.None);
        }
Пример #13
0
        public bool CommitDialog(List <string> assets, bool includeDependencies = true, bool showUserConfirmation = false, string commitMessage = "")
        {
            int initialAssetCount = assets.Count;

            if (initialAssetCount == 0)
            {
                return(true);
            }

            UnityAssetpathsFilters.AddFilesInFolders(ref assets);
            AssetpathsFilters.AddFolders(ref assets, vcc);
            AssetpathsFilters.AddMoveMatches(ref assets, vcc);

            List <string> dependencies = new List <string>();

            if (includeDependencies)
            {
                dependencies = assets.GetDependencies().ToList();
                UnityAssetpathsFilters.AddFilesInFolders(ref dependencies);
                AssetpathsFilters.AddFolders(ref dependencies, vcc);
                dependencies.AddRange(assets.AddDeletedInFolders(vcc));
            }
            var allAssets     = assets.Concat(dependencies).Distinct().ToList();
            var localModified = allAssets.LocalModified(vcc);

            if (assets.Contains(SceneManagerUtilities.GetCurrentScenePath()))
            {
                SceneManagerUtilities.SaveCurrentModifiedScenesIfUserWantsTo();
            }

            var localOnly = allAssets.LocalOnly(vcc);

            if (localOnly.Any())
            {
                return(UserDialog.DisplayDialog(
                           title: "Commit Warning!",
                           message: "You have chosen your own content above content from the server, which have made the asset 'Local Only'\n" +
                           "To reduce the risk of removing someones work, you will have to verify you wish to 'commit anyway'\n\n" +
                           $"{localOnly.Aggregate((a, b) => a + "\n" + b)}",
                           ok: "Commit Anyway",
                           cancel: "Cancel"
                           ));
            }

            if (VCSettings.RequireLockBeforeCommit && localModified.Any())
            {
                string title   = $"{Terminology.getlock} '{Terminology.localModified}' files?";
                string message = $"You are trying to commit files which are '{Terminology.localModified}'.\nDo you want to '{Terminology.getlock}' these files first?";
                if (UserDialog.DisplayDialog(title, message, Terminology.getlock, "Abort"))
                {
                    GetLock(localModified);
                }
                else
                {
                    return(false);
                }
            }
            if (showUserConfirmation || initialAssetCount < (assets.Count() + dependencies.Count()))
            {
                return(OpenCommitDialogWindow(assets, dependencies));
            }
            return(Commit(assets, commitMessage));
        }
Пример #14
0
 private static bool PromptUserForBackend(VCSettings.EVersionControlBackend backend)
 {
     return(UserDialog.DisplayDialog("Use " + backend + " ?", "The only valid version control found is '" + backend + "'. \nUse " + backend + " as version control?", "Yes", "No"));
 }