initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,99 @@
|
|||
using UnityEditor;
|
||||
|
||||
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using AssetOverlays = Unity.PlasticSCM.Editor.AssetsOverlays;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.AssetUtils.Processor
|
||||
{
|
||||
class AssetModificationProcessor : UnityEditor.AssetModificationProcessor
|
||||
{
|
||||
internal static bool ForceCheckout { get; private set; }
|
||||
|
||||
/* We need to do a checkout, verifying that the content/date or size has changed.
|
||||
* In order to do this checkout we need the changes to have reached the disk.
|
||||
* That's why we save the changed files in this array, and when they are reloaded
|
||||
* in AssetPostprocessor.OnPostprocessAllAssets we process them. */
|
||||
internal static string[] ModifiedAssets { get; set; }
|
||||
|
||||
static AssetModificationProcessor()
|
||||
{
|
||||
ForceCheckout = EditorPrefs.GetBool(
|
||||
UnityConstants.FORCE_CHECKOUT_KEY_NAME);
|
||||
}
|
||||
|
||||
internal static void Enable(
|
||||
string wkPath,
|
||||
IAssetStatusCache assetStatusCache)
|
||||
{
|
||||
mWkPath = wkPath;
|
||||
mAssetStatusCache = assetStatusCache;
|
||||
|
||||
mIsEnabled = true;
|
||||
}
|
||||
|
||||
internal static void Disable()
|
||||
{
|
||||
mIsEnabled = false;
|
||||
|
||||
mWkPath = null;
|
||||
mAssetStatusCache = null;
|
||||
}
|
||||
|
||||
internal static void SetForceCheckoutOption(bool isEnabled)
|
||||
{
|
||||
ForceCheckout = isEnabled;
|
||||
|
||||
EditorPrefs.SetBool(
|
||||
UnityConstants.FORCE_CHECKOUT_KEY_NAME,
|
||||
isEnabled);
|
||||
}
|
||||
|
||||
static string[] OnWillSaveAssets(string[] paths)
|
||||
{
|
||||
if (!mIsEnabled)
|
||||
return paths;
|
||||
|
||||
ModifiedAssets = (string[])paths.Clone();
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
static bool IsOpenForEdit(string assetPath, out string message)
|
||||
{
|
||||
message = string.Empty;
|
||||
|
||||
if (!mIsEnabled)
|
||||
return true;
|
||||
|
||||
if (!ForceCheckout)
|
||||
return true;
|
||||
|
||||
if (assetPath.StartsWith("ProjectSettings/"))
|
||||
return true;
|
||||
|
||||
string assetFullPath = AssetsPath.GetFullPathUnderWorkspace.
|
||||
ForAsset(mWkPath, assetPath);
|
||||
|
||||
if (assetFullPath == null)
|
||||
return true;
|
||||
|
||||
if (MetaPath.IsMetaPath(assetFullPath))
|
||||
assetFullPath = MetaPath.GetPathFromMetaPath(assetFullPath);
|
||||
|
||||
AssetOverlays.AssetStatus status = mAssetStatusCache.
|
||||
GetStatus(assetFullPath);
|
||||
|
||||
if (AssetOverlays.ClassifyAssetStatus.IsAdded(status) ||
|
||||
AssetOverlays.ClassifyAssetStatus.IsCheckedOut(status))
|
||||
return true;
|
||||
|
||||
return !AssetOverlays.ClassifyAssetStatus.IsControlled(status);
|
||||
}
|
||||
|
||||
static bool mIsEnabled;
|
||||
|
||||
static IAssetStatusCache mAssetStatusCache;
|
||||
static string mWkPath;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c53c624438663f74ab67fbdf8869ae18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,141 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Codice.Client.Common.FsNodeReaders.Watcher;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.AssetUtils.Processor
|
||||
{
|
||||
class AssetPostprocessor : UnityEditor.AssetPostprocessor
|
||||
{
|
||||
internal struct PathToMove
|
||||
{
|
||||
internal readonly string SrcPath;
|
||||
internal readonly string DstPath;
|
||||
|
||||
internal PathToMove(string srcPath, string dstPath)
|
||||
{
|
||||
SrcPath = srcPath;
|
||||
DstPath = dstPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Enable(
|
||||
string wkPath,
|
||||
PlasticAssetsProcessor plasticAssetsProcessor)
|
||||
{
|
||||
mWkPath = wkPath;
|
||||
mPlasticAssetsProcessor = plasticAssetsProcessor;
|
||||
|
||||
mIsEnabled = true;
|
||||
}
|
||||
|
||||
internal static void Disable()
|
||||
{
|
||||
mIsEnabled = false;
|
||||
|
||||
mWkPath = null;
|
||||
mPlasticAssetsProcessor = null;
|
||||
}
|
||||
|
||||
internal static void SetIsRepaintInspectorNeededAfterAssetDatabaseRefresh()
|
||||
{
|
||||
mIsRepaintInspectorNeededAfterAssetDatabaseRefresh = true;
|
||||
}
|
||||
|
||||
static void OnPostprocessAllAssets(
|
||||
string[] importedAssets,
|
||||
string[] deletedAssets,
|
||||
string[] movedAssets,
|
||||
string[] movedFromAssetPaths)
|
||||
{
|
||||
if (!mIsEnabled)
|
||||
return;
|
||||
|
||||
if (mIsRepaintInspectorNeededAfterAssetDatabaseRefresh)
|
||||
{
|
||||
mIsRepaintInspectorNeededAfterAssetDatabaseRefresh = false;
|
||||
RepaintInspector.All();
|
||||
}
|
||||
|
||||
// We need to ensure that the FSWatcher is enabled before processing Plastic operations
|
||||
// It fixes the following scenario:
|
||||
// 1. Close PlasticSCM window
|
||||
// 2. Create an asset, it appears with the added overlay
|
||||
// 3. Open PlasticSCM window, the asset should appear as added instead of deleted locally
|
||||
MonoFileSystemWatcher.IsEnabled = true;
|
||||
|
||||
mPlasticAssetsProcessor.MoveOnSourceControl(
|
||||
GetPathsToMoveContainedOnWorkspace(
|
||||
mWkPath, movedAssets, movedFromAssetPaths));
|
||||
|
||||
mPlasticAssetsProcessor.DeleteFromSourceControl(
|
||||
GetPathsContainedOnWorkspace(mWkPath, deletedAssets));
|
||||
|
||||
mPlasticAssetsProcessor.AddToSourceControl(
|
||||
GetPathsContainedOnWorkspace(mWkPath, importedAssets));
|
||||
|
||||
if (AssetModificationProcessor.ModifiedAssets == null)
|
||||
return;
|
||||
|
||||
mPlasticAssetsProcessor.CheckoutOnSourceControl(
|
||||
GetPathsContainedOnWorkspace(
|
||||
mWkPath, AssetModificationProcessor.ModifiedAssets));
|
||||
|
||||
AssetModificationProcessor.ModifiedAssets = null;
|
||||
}
|
||||
|
||||
static List<PathToMove> GetPathsToMoveContainedOnWorkspace(
|
||||
string wkPath,
|
||||
string[] movedAssets,
|
||||
string[] movedFromAssetPaths)
|
||||
{
|
||||
List<PathToMove> result = new List<PathToMove>(
|
||||
movedAssets.Length);
|
||||
|
||||
for (int i = 0; i < movedAssets.Length; i++)
|
||||
{
|
||||
string fullSrcPath = AssetsPath.GetFullPathUnderWorkspace.
|
||||
ForAsset(wkPath, movedFromAssetPaths[i]);
|
||||
|
||||
if (fullSrcPath == null)
|
||||
continue;
|
||||
|
||||
string fullDstPath = AssetsPath.GetFullPathUnderWorkspace.
|
||||
ForAsset(wkPath, movedAssets[i]);
|
||||
|
||||
if (fullDstPath == null)
|
||||
continue;
|
||||
|
||||
result.Add(new PathToMove(
|
||||
fullSrcPath, fullDstPath));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<string> GetPathsContainedOnWorkspace(
|
||||
string wkPath, string[] assets)
|
||||
{
|
||||
List<string> result = new List<string>(
|
||||
assets.Length);
|
||||
|
||||
foreach (string asset in assets)
|
||||
{
|
||||
string fullPath = AssetsPath.GetFullPathUnderWorkspace.
|
||||
ForAsset(wkPath, asset);
|
||||
|
||||
if (fullPath == null)
|
||||
continue;
|
||||
|
||||
result.Add(fullPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool mIsEnabled;
|
||||
static bool mIsRepaintInspectorNeededAfterAssetDatabaseRefresh;
|
||||
|
||||
static PlasticAssetsProcessor mPlasticAssetsProcessor;
|
||||
static string mWkPath;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9ffdef169b1cbb4e9910671a9ee83bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,22 @@
|
|||
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.AssetUtils.Processor
|
||||
{
|
||||
internal static class AssetsProcessors
|
||||
{
|
||||
internal static void Enable(
|
||||
string wkPath,
|
||||
PlasticAssetsProcessor plasticAssetsProcessor,
|
||||
IAssetStatusCache assetStatusCache)
|
||||
{
|
||||
AssetPostprocessor.Enable(wkPath, plasticAssetsProcessor);
|
||||
AssetModificationProcessor.Enable(wkPath, assetStatusCache);
|
||||
}
|
||||
|
||||
internal static void Disable()
|
||||
{
|
||||
AssetPostprocessor.Disable();
|
||||
AssetModificationProcessor.Disable();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 71cb30384b5f8d64ea7df220cff88d0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Codice.LogWrapper;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.AssetUtils.Processor
|
||||
{
|
||||
internal class PlasticAssetsProcessor : WorkspaceOperationsMonitor.IDisableAssetsProcessor
|
||||
{
|
||||
internal void SetWorkspaceOperationsMonitor(
|
||||
WorkspaceOperationsMonitor workspaceOperationsMonitor)
|
||||
{
|
||||
mWorkspaceOperationsMonitor = workspaceOperationsMonitor;
|
||||
}
|
||||
|
||||
internal void AddToSourceControl(List<string> paths)
|
||||
{
|
||||
if (paths.Count == 0)
|
||||
return;
|
||||
|
||||
if (IsDisableBecauseExceptionHappened(DateTime.Now))
|
||||
{
|
||||
mLog.Warn(
|
||||
"PlasticAssetsProcessor skipping AddToSourceControl operation " +
|
||||
"because an exception happened in the last 60 seconds");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
mLog.DebugFormat("AddToSourceControl: {0}", path);
|
||||
|
||||
mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToAdd(paths);
|
||||
}
|
||||
|
||||
internal void DeleteFromSourceControl(List<string> paths)
|
||||
{
|
||||
if (paths.Count == 0)
|
||||
return;
|
||||
|
||||
if (IsDisableBecauseExceptionHappened(DateTime.Now))
|
||||
{
|
||||
mLog.Warn(
|
||||
"PlasticAssetsProcessor skipping DeleteFromSourceControl operation " +
|
||||
"because an exception happened in the last 60 seconds");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
mLog.DebugFormat("DeleteFromSourceControl: {0}", path);
|
||||
|
||||
mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToDelete(paths);
|
||||
}
|
||||
|
||||
internal void MoveOnSourceControl(List<AssetPostprocessor.PathToMove> paths)
|
||||
{
|
||||
if (paths.Count == 0)
|
||||
return;
|
||||
|
||||
if (IsDisableBecauseExceptionHappened(DateTime.Now))
|
||||
{
|
||||
mLog.Warn(
|
||||
"PlasticAssetsProcessor skipping MoveOnSourceControl operation " +
|
||||
"because an exception happened in the last 60 seconds");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AssetPostprocessor.PathToMove path in paths)
|
||||
mLog.DebugFormat("MoveOnSourceControl: {0} to {1}", path.SrcPath, path.DstPath);
|
||||
|
||||
mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToMove(paths);
|
||||
}
|
||||
|
||||
internal void CheckoutOnSourceControl(List<string> paths)
|
||||
{
|
||||
if (paths.Count == 0)
|
||||
return;
|
||||
|
||||
if (IsDisableBecauseExceptionHappened(DateTime.Now))
|
||||
{
|
||||
mLog.Warn(
|
||||
"PlasticAssetsProcessor skipping CheckoutOnSourceControl operation " +
|
||||
"because an exception happened in the last 60 seconds");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
mLog.DebugFormat("CheckoutOnSourceControl: {0}", path);
|
||||
|
||||
mWorkspaceOperationsMonitor.AddAssetsProcessorPathsToCheckout(paths);
|
||||
}
|
||||
|
||||
void WorkspaceOperationsMonitor.IDisableAssetsProcessor.Disable()
|
||||
{
|
||||
mLastExceptionDateTime = DateTime.Now;
|
||||
}
|
||||
|
||||
bool IsDisableBecauseExceptionHappened(DateTime now)
|
||||
{
|
||||
return (now - mLastExceptionDateTime).TotalSeconds < 5;
|
||||
}
|
||||
|
||||
DateTime mLastExceptionDateTime = DateTime.MinValue;
|
||||
WorkspaceOperationsMonitor mWorkspaceOperationsMonitor;
|
||||
|
||||
static readonly ILog mLog = LogManager.GetLogger("PlasticAssetsProcessor");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d3daa94b5fca9a648b12f6ef2aae752f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,536 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
using Codice.Client.BaseCommands;
|
||||
using Codice.Client.Commands;
|
||||
using Codice.Client.Commands.WkTree;
|
||||
using Codice.LogWrapper;
|
||||
using GluonGui;
|
||||
using PlasticGui;
|
||||
using PlasticGui.WorkspaceWindow;
|
||||
using Unity.PlasticSCM.Editor.UI;
|
||||
using Unity.PlasticSCM.Editor.Views.IncomingChanges;
|
||||
using Unity.PlasticSCM.Editor.Views.PendingChanges;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.AssetUtils.Processor
|
||||
{
|
||||
internal class WorkspaceOperationsMonitor
|
||||
{
|
||||
public interface IDisableAssetsProcessor
|
||||
{
|
||||
void Disable();
|
||||
}
|
||||
|
||||
internal WorkspaceOperationsMonitor(
|
||||
IPlasticAPI plasticApi,
|
||||
IDisableAssetsProcessor disableAssetsProcessor,
|
||||
bool isGluonMode)
|
||||
{
|
||||
mPlasticAPI = plasticApi;
|
||||
mDisableAssetsProcessor = disableAssetsProcessor;
|
||||
mIsGluonMode = isGluonMode;
|
||||
}
|
||||
|
||||
internal void RegisterWindow(
|
||||
WorkspaceWindow workspaceWindow,
|
||||
ViewHost viewHost,
|
||||
NewIncomingChangesUpdater incomingChangesUpdater)
|
||||
{
|
||||
mWorkspaceWindow = workspaceWindow;
|
||||
mViewHost = viewHost;
|
||||
mNewIncomingChangesUpdater = incomingChangesUpdater;
|
||||
}
|
||||
|
||||
internal void UnRegisterWindow()
|
||||
{
|
||||
mWorkspaceWindow = null;
|
||||
mViewHost = null;
|
||||
mNewIncomingChangesUpdater = null;
|
||||
}
|
||||
|
||||
internal void RegisterPendingChangesView(
|
||||
PendingChangesTab pendingChangesTab)
|
||||
{
|
||||
mPendingChangesTab = pendingChangesTab;
|
||||
}
|
||||
|
||||
internal void RegisterIncomingChangesView(
|
||||
IIncomingChangesTab incomingChangesTab)
|
||||
{
|
||||
mIncomingChangesTab = incomingChangesTab;
|
||||
}
|
||||
|
||||
internal void UnRegisterViews()
|
||||
{
|
||||
mPendingChangesTab = null;
|
||||
mIncomingChangesTab = null;
|
||||
}
|
||||
|
||||
internal void Start()
|
||||
{
|
||||
mIsRunning = true;
|
||||
|
||||
Thread thread = new Thread(TaskLoopThread);
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
internal void Stop()
|
||||
{
|
||||
SetAsFinished();
|
||||
}
|
||||
|
||||
internal void AddAssetsProcessorPathsToAdd(
|
||||
List<string> paths)
|
||||
{
|
||||
AddPathsToProcess(
|
||||
mAssetsProcessorPathsToAdd, paths,
|
||||
mLock, mResetEvent);
|
||||
}
|
||||
|
||||
internal void AddAssetsProcessorPathsToDelete(
|
||||
List<string> paths)
|
||||
{
|
||||
AddPathsToProcess(
|
||||
mAssetsProcessorPathsToDelete, paths,
|
||||
mLock, mResetEvent);
|
||||
}
|
||||
|
||||
internal void AddAssetsProcessorPathsToCheckout(
|
||||
List<string> paths)
|
||||
{
|
||||
AddPathsToProcess(
|
||||
mAssetsProcessorPathsToCheckout, paths,
|
||||
mLock, mResetEvent);
|
||||
}
|
||||
|
||||
internal void AddAssetsProcessorPathsToMove(
|
||||
List<AssetPostprocessor.PathToMove> paths)
|
||||
{
|
||||
AddPathsToMoveToProcess(
|
||||
mAssetsProcessorPathsToMove, paths,
|
||||
mLock, mResetEvent);
|
||||
}
|
||||
|
||||
internal void AddPathsToCheckout(
|
||||
List<string> paths)
|
||||
{
|
||||
AddPathsToProcess(
|
||||
mPathsToCheckout, paths,
|
||||
mLock, mResetEvent);
|
||||
}
|
||||
|
||||
void TaskLoopThread()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!mIsRunning)
|
||||
break;
|
||||
|
||||
ProcessAssetProcessorOperations(
|
||||
mPlasticAPI,
|
||||
mAssetsProcessorPathsToAdd,
|
||||
mAssetsProcessorPathsToDelete,
|
||||
mAssetsProcessorPathsToCheckout,
|
||||
mAssetsProcessorPathsToMove,
|
||||
mLock,
|
||||
mDisableAssetsProcessor);
|
||||
|
||||
ProcessCheckoutOperation(
|
||||
mPlasticAPI,
|
||||
mPathsToCheckout,
|
||||
mLock);
|
||||
|
||||
bool hasAssetProcessorOperations = false;
|
||||
bool hasCheckoutOperations = false;
|
||||
HasPendingOperationsToProcess(
|
||||
mAssetsProcessorPathsToAdd,
|
||||
mAssetsProcessorPathsToDelete,
|
||||
mAssetsProcessorPathsToCheckout,
|
||||
mAssetsProcessorPathsToMove,
|
||||
mPathsToCheckout,
|
||||
mLock,
|
||||
out hasAssetProcessorOperations,
|
||||
out hasCheckoutOperations);
|
||||
|
||||
if (hasAssetProcessorOperations ||
|
||||
hasCheckoutOperations)
|
||||
continue;
|
||||
|
||||
if (!hasAssetProcessorOperations)
|
||||
EditorDispatcher.Dispatch(AfterAssetProcessorOperation);
|
||||
|
||||
if (!hasCheckoutOperations)
|
||||
EditorDispatcher.Dispatch(AfterCheckoutOperation);
|
||||
|
||||
SleepUntilNextWorkload();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
mLog.ErrorFormat(
|
||||
"Error running the tasks loop : {0}", e.Message);
|
||||
mLog.DebugFormat(
|
||||
"Stacktrace: {0}", e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AfterAssetProcessorOperation()
|
||||
{
|
||||
AutoRefresh.PendingChangesView(
|
||||
mPendingChangesTab);
|
||||
|
||||
AutoRefresh.IncomingChangesView(
|
||||
mIncomingChangesTab);
|
||||
}
|
||||
|
||||
void AfterCheckoutOperation()
|
||||
{
|
||||
RefreshAsset.VersionControlCache();
|
||||
|
||||
if (mIsGluonMode)
|
||||
{
|
||||
RefreshViewsAfterCheckoutForGluon(mViewHost);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mNewIncomingChangesUpdater != null)
|
||||
mNewIncomingChangesUpdater.Update(DateTime.Now);
|
||||
|
||||
RefreshViewsAfterCheckoutForDeveloper(mWorkspaceWindow);
|
||||
}
|
||||
|
||||
void SetAsFinished()
|
||||
{
|
||||
if (!mIsRunning)
|
||||
return;
|
||||
|
||||
mIsRunning = false;
|
||||
mResetEvent.Set();
|
||||
}
|
||||
|
||||
void SleepUntilNextWorkload()
|
||||
{
|
||||
mResetEvent.Reset();
|
||||
mResetEvent.WaitOne();
|
||||
}
|
||||
|
||||
static void ProcessAssetProcessorOperations(
|
||||
IPlasticAPI plasticApi,
|
||||
List<string> assetsProcessorPathsToAdd,
|
||||
List<string> assetsProcessorPathsToDelete,
|
||||
List<string> assetsProcessorPathsToCheckout,
|
||||
List<AssetPostprocessor.PathToMove> assetsProcessorPathsToMove,
|
||||
object lockObj,
|
||||
IDisableAssetsProcessor disableAssetsProcessor)
|
||||
{
|
||||
try
|
||||
{
|
||||
AssetsProcessorOperations.AddIfNotControlled(
|
||||
plasticApi, ExtractPathsToProcess(
|
||||
assetsProcessorPathsToAdd, lockObj),
|
||||
FilterManager.Get().GetIgnoredFilter());
|
||||
|
||||
AssetsProcessorOperations.DeleteIfControlled(
|
||||
plasticApi, ExtractPathsToProcess(
|
||||
assetsProcessorPathsToDelete, lockObj));
|
||||
|
||||
AssetsProcessorOperations.CheckoutIfControlledAndChanged(
|
||||
plasticApi, ExtractPathsToProcess(
|
||||
assetsProcessorPathsToCheckout, lockObj));
|
||||
|
||||
AssetsProcessorOperations.MoveIfControlled(
|
||||
plasticApi, ExtractPathsToMoveToProcess(
|
||||
assetsProcessorPathsToMove, lockObj));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
|
||||
disableAssetsProcessor.Disable();
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessCheckoutOperation(
|
||||
IPlasticAPI plasticApi,
|
||||
List<string> pathsToProcess,
|
||||
object lockObj)
|
||||
{
|
||||
List<string> paths = ExtractPathsToProcess(
|
||||
pathsToProcess, lockObj);
|
||||
|
||||
if (paths.Count == 0)
|
||||
return;
|
||||
|
||||
plasticApi.Checkout(
|
||||
paths.ToArray(),
|
||||
CheckoutModifiers.ProcessSymlinks);
|
||||
}
|
||||
|
||||
static void AddPathsToProcess(
|
||||
List<string> pathsToProcess,
|
||||
List<string> paths,
|
||||
object lockObj,
|
||||
ManualResetEvent resetEvent)
|
||||
{
|
||||
lock (lockObj)
|
||||
{
|
||||
pathsToProcess.AddRange(paths);
|
||||
}
|
||||
|
||||
resetEvent.Set();
|
||||
}
|
||||
|
||||
static void AddPathsToMoveToProcess(
|
||||
List<AssetPostprocessor.PathToMove> pathsToProcess,
|
||||
List<AssetPostprocessor.PathToMove> paths,
|
||||
object lockObj,
|
||||
ManualResetEvent resetEvent)
|
||||
{
|
||||
lock (lockObj)
|
||||
{
|
||||
pathsToProcess.AddRange(paths);
|
||||
}
|
||||
|
||||
resetEvent.Set();
|
||||
}
|
||||
|
||||
static List<string> ExtractPathsToProcess(
|
||||
List<string> pathsToProcess,
|
||||
object lockObj)
|
||||
{
|
||||
List<string> result;
|
||||
|
||||
lock (lockObj)
|
||||
{
|
||||
result = new List<string>(pathsToProcess);
|
||||
pathsToProcess.Clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<AssetPostprocessor.PathToMove> ExtractPathsToMoveToProcess(
|
||||
List<AssetPostprocessor.PathToMove> pathsToProcess,
|
||||
object lockObj)
|
||||
{
|
||||
List<AssetPostprocessor.PathToMove> result;
|
||||
|
||||
lock (lockObj)
|
||||
{
|
||||
result = new List<AssetPostprocessor.PathToMove>(pathsToProcess);
|
||||
pathsToProcess.Clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void HasPendingOperationsToProcess(
|
||||
List<string> assetsProcessorPathsToAdd,
|
||||
List<string> assetsProcessorPathsToDelete,
|
||||
List<string> assetsProcessorPathsToCheckout,
|
||||
List<AssetPostprocessor.PathToMove> assetsProcessorPathsToMove,
|
||||
List<string> pathsToCheckout,
|
||||
object lockObj,
|
||||
out bool hasAssetProcessorOperations,
|
||||
out bool hasCheckoutOperations)
|
||||
{
|
||||
lock (lockObj)
|
||||
{
|
||||
hasAssetProcessorOperations =
|
||||
assetsProcessorPathsToAdd.Count > 0 ||
|
||||
assetsProcessorPathsToDelete.Count > 0 ||
|
||||
assetsProcessorPathsToCheckout.Count > 0 ||
|
||||
assetsProcessorPathsToMove.Count > 0;
|
||||
|
||||
hasCheckoutOperations =
|
||||
pathsToCheckout.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void RefreshViewsAfterCheckoutForDeveloper(
|
||||
IWorkspaceWindow workspaceWindow)
|
||||
{
|
||||
if (workspaceWindow == null)
|
||||
return;
|
||||
|
||||
workspaceWindow.RefreshView(ViewType.BranchExplorerView);
|
||||
workspaceWindow.RefreshView(ViewType.PendingChangesView);
|
||||
workspaceWindow.RefreshView(ViewType.HistoryView);
|
||||
}
|
||||
|
||||
static void RefreshViewsAfterCheckoutForGluon(
|
||||
ViewHost viewHost)
|
||||
{
|
||||
if (viewHost == null)
|
||||
return;
|
||||
|
||||
viewHost.RefreshView(ViewType.WorkspaceExplorerView);
|
||||
viewHost.RefreshView(ViewType.CheckinView);
|
||||
viewHost.RefreshView(ViewType.IncomingChangesView);
|
||||
viewHost.RefreshView(ViewType.SearchView);
|
||||
}
|
||||
|
||||
static void LogException(Exception ex)
|
||||
{
|
||||
mLog.WarnFormat("Message: {0}", ex.Message);
|
||||
|
||||
mLog.DebugFormat(
|
||||
"StackTrace:{0}{1}",
|
||||
Environment.NewLine, ex.StackTrace);
|
||||
}
|
||||
|
||||
static class AssetsProcessorOperations
|
||||
{
|
||||
internal static void AddIfNotControlled(
|
||||
IPlasticAPI plasticApi,
|
||||
List<string> paths,
|
||||
IgnoredFilesFilter ignoredFilter)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string metaPath = MetaPath.GetMetaPath(path);
|
||||
|
||||
if (plasticApi.GetWorkspaceFromPath(path) == null)
|
||||
return;
|
||||
|
||||
if (plasticApi.GetWorkspaceTreeNode(path) == null &&
|
||||
!ignoredFilter.IsIgnored(path))
|
||||
result.Add(path);
|
||||
|
||||
if (File.Exists(metaPath) &&
|
||||
plasticApi.GetWorkspaceTreeNode(metaPath) == null &&
|
||||
!ignoredFilter.IsIgnored(path))
|
||||
result.Add(metaPath);
|
||||
}
|
||||
|
||||
if (result.Count == 0)
|
||||
return;
|
||||
|
||||
IList checkouts;
|
||||
plasticApi.Add(
|
||||
result.ToArray(),
|
||||
GetDefaultAddOptions(),
|
||||
out checkouts);
|
||||
}
|
||||
|
||||
internal static void DeleteIfControlled(
|
||||
IPlasticAPI plasticApi,
|
||||
List<string> paths)
|
||||
{
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string metaPath = MetaPath.GetMetaPath(path);
|
||||
|
||||
if (plasticApi.GetWorkspaceTreeNode(path) != null)
|
||||
{
|
||||
plasticApi.DeleteControlled(
|
||||
path, DeleteModifiers.None);
|
||||
}
|
||||
|
||||
if (plasticApi.GetWorkspaceTreeNode(metaPath) != null)
|
||||
{
|
||||
plasticApi.DeleteControlled(
|
||||
metaPath, DeleteModifiers.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void MoveIfControlled(
|
||||
IPlasticAPI plasticApi,
|
||||
List<AssetPostprocessor.PathToMove> paths)
|
||||
{
|
||||
foreach (AssetPostprocessor.PathToMove pathToMove in paths)
|
||||
{
|
||||
string srcMetaPath = MetaPath.GetMetaPath(pathToMove.SrcPath);
|
||||
string dstMetaPath = MetaPath.GetMetaPath(pathToMove.DstPath);
|
||||
|
||||
if (plasticApi.GetWorkspaceTreeNode(pathToMove.SrcPath) != null)
|
||||
{
|
||||
plasticApi.Move(
|
||||
pathToMove.SrcPath, pathToMove.DstPath,
|
||||
MoveModifiers.None);
|
||||
}
|
||||
|
||||
if (plasticApi.GetWorkspaceTreeNode(srcMetaPath) != null)
|
||||
{
|
||||
plasticApi.Move(
|
||||
srcMetaPath, dstMetaPath,
|
||||
MoveModifiers.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void CheckoutIfControlledAndChanged(
|
||||
IPlasticAPI plasticApi,
|
||||
List<string> paths)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
string metaPath = MetaPath.GetMetaPath(path);
|
||||
|
||||
WorkspaceTreeNode node =
|
||||
plasticApi.GetWorkspaceTreeNode(path);
|
||||
WorkspaceTreeNode nodeMeta =
|
||||
plasticApi.GetWorkspaceTreeNode(metaPath);
|
||||
|
||||
if (node != null && ChangedFileChecker.IsChanged(
|
||||
node.LocalInfo, path, false))
|
||||
result.Add(path);
|
||||
|
||||
if (nodeMeta != null && ChangedFileChecker.IsChanged(
|
||||
nodeMeta.LocalInfo, metaPath, false))
|
||||
result.Add(metaPath);
|
||||
}
|
||||
|
||||
if (result.Count == 0)
|
||||
return;
|
||||
|
||||
plasticApi.Checkout(
|
||||
result.ToArray(),
|
||||
CheckoutModifiers.None);
|
||||
}
|
||||
|
||||
static AddOptions GetDefaultAddOptions()
|
||||
{
|
||||
AddOptions options = new AddOptions();
|
||||
options.AddPrivateParents = true;
|
||||
options.NeedCheckPlatformPath = true;
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
object mLock = new object();
|
||||
volatile bool mIsRunning;
|
||||
volatile ManualResetEvent mResetEvent = new ManualResetEvent(false);
|
||||
|
||||
List<string> mAssetsProcessorPathsToAdd = new List<string>();
|
||||
List<string> mAssetsProcessorPathsToDelete = new List<string>();
|
||||
List<string> mAssetsProcessorPathsToCheckout = new List<string>();
|
||||
List<AssetPostprocessor.PathToMove> mAssetsProcessorPathsToMove =
|
||||
new List<AssetPostprocessor.PathToMove>();
|
||||
List<string> mPathsToCheckout = new List<string>();
|
||||
|
||||
PendingChangesTab mPendingChangesTab;
|
||||
IIncomingChangesTab mIncomingChangesTab;
|
||||
|
||||
NewIncomingChangesUpdater mNewIncomingChangesUpdater;
|
||||
ViewHost mViewHost;
|
||||
IWorkspaceWindow mWorkspaceWindow;
|
||||
|
||||
readonly bool mIsGluonMode = false;
|
||||
readonly IDisableAssetsProcessor mDisableAssetsProcessor;
|
||||
readonly IPlasticAPI mPlasticAPI;
|
||||
|
||||
static readonly ILog mLog = LogManager.GetLogger("WorkspaceOperationsMonitor");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fdec637f96aaa6546ad88a90cae5dcf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue