void ReadProcessOutput() { try { IsSearching = true; while (true) { if (Thread.CurrentThread.ManagedThreadId != workerId) { return; } ReferenceSearchEngineProcess p; lock (sync) { if (processQueue.Count == 0) { AssetDependencyDatabase.SetScanPaused(false); return; } p = processQueue[0]; processQueue.RemoveAt(0); currentProcess = p; p.StartProcess(); } if (Thread.CurrentThread.ManagedThreadId != workerId) { return; } p.WaitForComplete(); if (Thread.CurrentThread.ManagedThreadId != workerId) { return; } lock (sync) { currentProcess = null; } } } catch (ThreadAbortException) { } catch (System.Exception e) { Log(e.ToString()); } finally { IsSearching = false; } }
public void CancelImpl() { if (currentProcess != null) { currentProcess.Cancel(); currentProcess = null; } if (worker != null && !worker.IsAlive) { worker.Abort(); worker = null; workerId = 0; IsSearching = false; } processQueue.Clear(); }
public void FoundReference(ReferenceSearchEngineProcess process, string objectPath, string targetPath) { // var o = process.Callback.Target as UnityObject; // if (o == null) // { // return; // } if (objectPath.StartsWith(Root)) { objectPath = objectPath.Substring(objectPath.Length + 1); } process.Callback(objectPath); if (process.IsRecursive && !targetPath.StartsWith("ProjectSettings/")) { EnqueueProcess(objectPath, process.IsRecursive, process.Callback, process.Results); } if (process.Results.Count > 5) { AssetDependencyDatabase.SetScanPaused(false); } AssetDependencyDatabase.EnqueueScanDependency(objectPath); }
void EnqueueProcess(string path, bool isRecursive, ResultCallback callback, HashSet <string> results = null) { results = results ?? new HashSet <string>(); var guid = AssetDependencyDatabase.PathToGUID(path); var crumbs = Path.GetDirectoryName(path).Split(new[] { '/', '\\' }); var sb = new StringBuilder(); var dirs = new List <string>(); for (var n = crumbs.Length; n > 0; --n) { sb.Length = 0; for (var j = 0; j < n; ++j) { if (j > 0) { sb.Append('/'); } sb.Append(crumbs[j]); } dirs.Add(sb.ToString()); } dirs.Add("ProjectSettings"); ReferenceSearchEngineProcess process = null; for (var i = 0; i < dirs.Count; ++i) { var dir = dirs[i]; var ignore = i > 0 ? dirs[i - 1] + "/" : null; if (dir == "ProjectSettings") { ignore = null; } var merged = false; foreach (var q in processQueue) { if (q.SearchDirectory == dir && q.IgnoreDirectory == ignore) { q.TargetPaths.Add(path); q.TargetGUIDs.Add(guid); merged = true; process = q; break; } } if (!merged) { process = new ReferenceSearchEngineProcess() { Argument = string.Format("--json {0} ", commonIgnorePatterns), SearchDirectory = Prefix + dir, IgnoreDirectory = ignore == null ? null : Prefix + ignore, TargetPaths = new List <string>() { path }, TargetGUIDs = new List <string>() { guid }, Callback = callback, IsRecursive = isRecursive, Results = results, Reporter = this, }; processQueue.Add(process); } } var refPaths = AssetDependencyDatabase.GetReferences(path); if (refPaths == null) { return; } foreach (var refPath in refPaths) { lock (results) { if (results.Contains(refPath)) { continue; } results.Add(refPath); } FoundReference(process, refPath, path); } }