public static string AppendArguments(this Result.SearchType searchType, List <string> excludes) { if (searchType == Result.SearchType.OSX_Grep) { string appendArguments = string.Empty; foreach (string exclude in excludes) { appendArguments += string.Format(" --exclude='{0}'", exclude); } return(appendArguments); } return(string.Empty); }
/// <summary> /// OSコマンドで検索を実行 /// Execute search with OS command. /// </summary> public static Result FindReferencesByCommand(Result.SearchType searchType, List <string> excludeExtentionList) { CommandInfo commandInfo = searchType.Command(); string[] eol = { commandInfo.NewLine }; Result result = new Result(); string applicationDataPathWithoutAssets = Application.dataPath.Replace("Assets", ""); try { // パスを取得し、Projectビュー内の順番と同じになるようにソートする // Get the path, Sort so that it is the same as the order in the project view. List <AssetPath> paths = new List <AssetPath>(); for (int i = 0; i < Selection.assetGUIDs.Length; ++i) { string guid = Selection.assetGUIDs[i]; var assetPath = new AssetPath { GUID = guid, Path = AssetDatabase.GUIDToAssetPath(guid), }; bool isDirectory = File.GetAttributes(assetPath.Path).Equals(FileAttributes.Directory); if (!isDirectory) { paths.Add(assetPath); } else { // ディレクトリを選択した場合は中のファイルも全て対象にする // When directory is selected, all the files in the target are also targeted. var includeFilePaths = Directory.GetFiles(assetPath.Path, "*.*", SearchOption.AllDirectories).Where(x => !x.EndsWith(".meta")); foreach (string path in includeFilePaths) { guid = AssetDatabase.AssetPathToGUID(path); if (string.IsNullOrEmpty(guid)) { continue; } assetPath = new AssetPath { GUID = guid, Path = path }; paths.Add(assetPath); } } } paths.Sort((a, b) => a.Path.CompareTo(b.Path)); // アセット毎の参照情報の作成 // Create reference information for each asset. int assetCount = paths.Count; for (int i = 0; i < assetCount; ++i) { string guid = paths[i].GUID; string path = paths[i].Path; string fileName = Path.GetFileName(path); var assetData = new AssetReferenceData(path); float progress = i / (float)assetCount; string progressText = string.Format("{0}% : {1}", (int)(progress * 100f), fileName); if (EditorUtility.DisplayCancelableProgressBar(ProgressBarTitle, progressText, progress)) { // キャンセルしたら現時点での結果を返す // On canceled, return current result. EditorUtility.ClearProgressBar(); return(result); } var p = new Process(); string arguments = string.Format(commandInfo.Arguments, Application.dataPath, guid); arguments += searchType.AppendArguments(excludeExtentionList); p.StartInfo.FileName = commandInfo.Command; p.StartInfo.Arguments = arguments; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.WorkingDirectory = Application.dataPath; p.Start(); p.WaitForExit(); FindByCommand(p, applicationDataPathWithoutAssets, path, eol, assetData, excludeExtentionList); p.Close(); assetData.Apply(); result.Assets.Add(assetData); } EditorUtility.ClearProgressBar(); result.Type = searchType; return(result); } catch (System.Exception e) { UnityEngine.Debug.LogError(e); EditorUtility.ClearProgressBar(); } return(null); }
public static CommandInfo Command(this Result.SearchType searchType) { return(Commands[searchType]); }