Exemplo n.º 1
0
        public override void SetDataPaths(List <string> queryPahts)
        {
            base.SetDataPaths(queryPahts);

            data = FileListToAssetInfos(queryPahts);

            List <string> fileList = AssetDanshariUtility.GetAllPrefebFile(AssetDanshariUtility.ValidFile);
            var           rstList  = AssetDanshariUtility.ResultList(fileList.Count, queryPahts.Count);

            ThreadDoFilesTextSearch(fileList, queryPahts, rstList);

            // 根据搜索结果来挂载额外信息
            for (int i = 0; i < fileList.Count; i++)
            {
                for (int j = 0; j < queryPahts.Count; j++)
                {
                    if (rstList[i][j])
                    {
                        AssetInfo info = GenAssetInfo(fileList[i]);
                        info.isRst = true;
                        data[j].AddChild(info);
                    }
                }
            }
            for (int i = data.Count - 1; i >= 0; i--)
            {
                AssetInfo info = data[i];
                if (info.hasChildren)
                {
                    continue;
                }
                data.RemoveAt(i);
            }
            EditorUtility.ClearProgressBar();
        }
        public override void ExportCsv()
        {
            string path = AssetDanshariUtility.GetSaveFilePath(typeof(AssetDuplicateWindow).Name);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var style = AssetDanshariStyle.Get();
            var sb    = new StringBuilder();

            sb.AppendFormat("\"{0}\",", style.duplicateHeaderContent.text);
            sb.AppendFormat("\"{0}\",", style.duplicateHeaderContent2.text);
            sb.AppendFormat("\"{0}\",", style.duplicateHeaderContent3.text);
            sb.AppendFormat("\"{0}\"\n", style.duplicateHeaderContent4.text);

            foreach (var group in data.children)
            {
                sb.AppendLine(String.Format(style.duplicateGroup, group.displayName));

                foreach (var info in group.children)
                {
                    sb.AppendFormat("\"{0}\",", info.displayName);
                    sb.AppendFormat("\"{0}\",", info.fileRelativePath);

                    FileMd5Info md5Info = info.bindObj as FileMd5Info;
                    sb.AppendFormat("\"{0}\",", md5Info.fileLength);
                    sb.AppendFormat("\"{0}\"\n", md5Info.fileTime);
                }
            }

            AssetDanshariUtility.SaveFileText(path, sb.ToString());
            GUIUtility.ExitGUI();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到资源文件列表
        /// </summary>
        /// <returns></returns>
        protected List <string> GetResFileList()
        {
            List <string> fileList = new List <string>();

            foreach (var resPath in resPaths)
            {
                if (!Directory.Exists(resPath))
                {
                    continue;
                }

                EditorUtility.DisplayProgressBar(AssetDanshariStyle.Get().progressTitle, String.Empty, 0f);
                var allFiles = Directory.GetFiles(resPath, "*", SearchOption.AllDirectories);

                for (var i = 0; i < allFiles.Length; i++)
                {
                    var file = allFiles[i];
                    if (AssetDanshariUtility.IsMetaExt(file))
                    {
                        continue;
                    }

                    fileList.Add(PathToStandardized(file));
                }
            }

            return(fileList);
        }
Exemplo n.º 4
0
        protected void ThreadDoFileMD5(List <string> fileList, string[] fileDic)
        {
            List <JobFileMD5>       jobList   = new List <JobFileMD5>();
            List <ManualResetEvent> eventList = new List <ManualResetEvent>();

            int numFiles = fileList.Count;

            for (int i = 0; i < numFiles; i++)
            {
                string     path = fileList[i];
                JobFileMD5 job  = new JobFileMD5(path, i, fileDic);
                jobList.Add(job);
                eventList.Add(job.doneEvent);
                ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

                if (eventList.Count >= Environment.ProcessorCount || (i == numFiles - 1 && eventList.Count > 0))
                {
                    WaitHandle.WaitAll(eventList.ToArray());
                    eventList.Clear();
                    AssetDanshariUtility.DisplayThreadProgressBar(numFiles, i);
                }
            }
            foreach (var job in jobList)
            {
                if (!string.IsNullOrEmpty(job.exception))
                {
                    Debug.LogError(job.exception);
                }
            }
        }
Exemplo n.º 5
0
        public virtual void SetDataPaths(string refPathStr, string pathStr, string commonPathStr)
        {
            data = null;
            ResetAutoId();
            assetPaths    = pathStr;
            refPaths      = AssetDanshariUtility.PathStrToArray(refPathStr);
            resPaths      = AssetDanshariUtility.PathStrToArray(pathStr);
            commonPaths   = AssetDanshariUtility.PathStrToArray(commonPathStr);
            m_DataPathLen = Application.dataPath.Length - 6;

            commonDirs = new List <AssetInfo>();
            foreach (var commonPath in commonPaths)
            {
                if (!Directory.Exists(commonPath))
                {
                    continue;
                }

                var commonName = Path.GetFileNameWithoutExtension(commonPath);
                var commonLen  = commonPath.Length - commonName.Length;
                commonDirs.Add(new AssetInfo(GetAutoId(), commonPath, commonName));

                var allDirs = Directory.GetDirectories(commonPath, "*", SearchOption.AllDirectories);
                foreach (var allDir in allDirs)
                {
                    var dirInfo = GenAssetInfo(PathToStandardized(allDir));
                    dirInfo.displayName = dirInfo.fileRelativePath.Substring(commonLen);
                    commonDirs.Add(dirInfo);
                }
            }
        }
Exemplo n.º 6
0
        protected void ThreadDoFilesTextSearch(List <string> fileList, List <string> depList, bool[][] rstList)
        {
            List <JobFileTextSearch> jobList   = new List <JobFileTextSearch>();
            List <ManualResetEvent>  eventList = new List <ManualResetEvent>();

            //生成guid字典,快速查询
            Dictionary <string, int> guidDic  = new Dictionary <string, int>();
            List <string>            guidList = AssetDanshariUtility.GuidFromFileList(depList);

            for (int i = 0; i < guidList.Count; i++)
            {
                guidDic[guidList[i]] = i;
            }

            Stopwatch sw       = Stopwatch.StartNew();
            int       numFiles = fileList.Count;
            int       dealNum  = 0;

            for (int i = 0; i < numFiles; i++)
            {
                string            path = fileList[i];
                JobFileTextSearch job;
                if (path == AssetDanshariUtility.Res_Obj || path == AssetDanshariUtility.Res_Pref ||
                    path == AssetDanshariUtility.Res_Sprite)
                {
                    //如果是资源表,直接使用路径进行匹配
                    job = new JobFileTextSearch(path, depList, rstList[i]);
                }
                else
                {
                    if (!AssetDanshariUtility.ValidFileHasRef(path))
                    {
                        continue;
                    }
                    job = new JobFileTextSearch(path, guidDic, rstList[i]);
                }
                jobList.Add(job);
                eventList.Add(job.doneEvent);
                ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

                if (eventList.Count >= Environment.ProcessorCount || (i == numFiles - 1 && eventList.Count > 0))
                {
                    dealNum++;
                    WaitHandle.WaitAll(eventList.ToArray());
                    eventList.Clear();
                    AssetDanshariUtility.DisplayThreadProgressBar(numFiles, i);
                }
            }
            Debug.Log("处理次数:" + dealNum + ",耗时:" + sw.ElapsedMilliseconds / 1000f);
            foreach (var job in jobList)
            {
                if (!string.IsNullOrEmpty(job.exception))
                {
                    Debug.LogError(job.exception);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取Asset下所有的文件
        /// </summary>
        public static List <string> GetAllPrefebFile(Func <string, bool> compareCB)
        {
            List <string> fileList = new List <string>();

            for (int i = 0; i < AssetDanshariUtility.ResDir.Length; i++)
            {
                fileList.AddRange(AssetDanshariUtility.GetFileList(AssetDanshariUtility.ResPrefebDir[i], compareCB));
            }
            return(fileList);
        }
Exemplo n.º 8
0
        public override void SetDataPaths(List <string> queryPaths)
        {
            base.SetDataPaths(queryPaths);
            data = FileListToAssetInfos(queryPaths);

            List <string> resFileList   = AssetDanshariUtility.GetAllFile(AssetDanshariUtility.ValidFile);
            var           searchRetList = AssetDanshariUtility.ResultList(queryPaths.Count, resFileList.Count);

            ThreadDoFilesTextSearch(queryPaths, resFileList, searchRetList);

            //隶属信息
            var spritePackingDict = new Dictionary <string, string>();

            // 根据搜索结果来挂载额外信息
            for (int i = 0; i < queryPaths.Count; i++)
            {
                for (int j = 0; j < resFileList.Count; j++)
                {
                    if (searchRetList[i][j])
                    {
                        AssetInfo info = GenAssetInfo(resFileList[j]);
                        info.isRst = true;
                        data[i].AddChild(info);

                        // 隶属
                        string val;
                        if (!spritePackingDict.TryGetValue(info.fileRelativePath, out val))
                        {
                            var             assetImporter   = AssetImporter.GetAtPath(info.fileRelativePath);
                            TextureImporter textureImporter = assetImporter as TextureImporter;
                            if (textureImporter)
                            {
                                val = textureImporter.spritePackingTag;
                            }
                        }

                        info.bindObj = val;
                    }
                }
            }

            for (int i = data.Count - 1; i >= 0; i--)
            {
                AssetInfo info = data[i];
                if (info.hasChildren)
                {
                    continue;
                }
                data.RemoveAt(i);
            }
            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 9
0
        protected void ThreadDoFilesTextReplace(Dictionary <string, List <string> > targetFileDic, string usePath)
        {
            List <JobFileTextReplace> jobList   = new List <JobFileTextReplace>();
            List <ManualResetEvent>   eventList = new List <ManualResetEvent>();

            string useGUID = AssetDatabase.AssetPathToGUID(usePath);

            int numFiles = 0;

            foreach (var pair in targetFileDic)
            {
                numFiles += pair.Value.Count;
            }

            int i = 0;

            foreach (var pair in targetFileDic)
            {
                string targetGUID = AssetDatabase.AssetPathToGUID(pair.Key);
                numFiles = pair.Value.Count;
                for (int j = 0; j < pair.Value.Count; j++)
                {
                    if (!AssetDanshariUtility.ValidFileRepeat(pair.Value[j]))
                    {
                        continue;
                    }
                    JobFileTextReplace job = new JobFileTextReplace(pair.Value[j], useGUID, targetGUID);
                    jobList.Add(job);
                    eventList.Add(job.doneEvent);
                    ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

                    if (eventList.Count >= Environment.ProcessorCount || (i == numFiles - 1 && eventList.Count > 0))
                    {
                        WaitHandle.WaitAll(eventList.ToArray());
                        eventList.Clear();
                        EditorUtility.DisplayProgressBar(AssetDanshariStyle.Get().progressTitle, "替换引用...", (i + 1) * 1f / numFiles);
                    }
                    i++;
                }
            }
            foreach (var job in jobList)
            {
                if (!string.IsNullOrEmpty(job.exception))
                {
                    Debug.LogError(job.exception);
                }
            }
        }
Exemplo n.º 10
0
        public static List <string> GetSelectAssets()
        {
            UnityEngine.Object[] selecObjs = Selection.GetFiltered <UnityEngine.Object>(SelectionMode.Assets);
            List <string>        tmpList   = new List <string>();

            foreach (UnityEngine.Object obj in selecObjs)
            {
                string objPath = AssetDatabase.GetAssetPath(obj);
                if (AssetDatabase.IsValidFolder(objPath))
                {
                    tmpList.AddRange(AssetDanshariUtility.GetFileList(objPath, AssetDanshariUtility.ValidFile));
                }
                else
                {
                    tmpList.Add(objPath);
                }
            }
            return(tmpList);
        }
Exemplo n.º 11
0
        protected void ThreadDoFilesTextSearchReplace(List <string> fileList, List <string> patterns, string replaceStr, bool[][] searchRetList)
        {
            List <JobFileTextSearchReplace> jobList   = new List <JobFileTextSearchReplace>();
            List <ManualResetEvent>         eventList = new List <ManualResetEvent>();

            int numFiles    = fileList.Count;
            int numFinished = 0;

            AssetDanshariUtility.DisplayThreadProgressBar(numFiles, numFinished);

            int timeout = 600000;  // 10 分钟超时

            for (var i = 0; i < fileList.Count; i++)
            {
                JobFileTextSearchReplace job = new JobFileTextSearchReplace(fileList[i], patterns, replaceStr, searchRetList[i]);
                jobList.Add(job);
                eventList.Add(job.doneEvent);
                ThreadPool.QueueUserWorkItem(job.ThreadPoolCallback);

                if (eventList.Count >= Environment.ProcessorCount)
                {
                    WaitForDoFile(eventList, timeout);
                    AssetDanshariUtility.DisplayThreadProgressBar(numFiles, numFinished);
                    numFinished++;
                }
            }

            while (eventList.Count > 0)
            {
                WaitForDoFile(eventList, timeout);
                AssetDanshariUtility.DisplayThreadProgressBar(numFiles, numFinished);
                numFinished++;
            }

            foreach (var job in jobList)
            {
                if (!string.IsNullOrEmpty(job.exception))
                {
                    Debug.LogError(job.exception);
                }
            }
        }
        public override void ExportCsv()
        {
            string path = AssetDanshariUtility.GetSaveFilePath(typeof(AssetDependenciesWindow).Name);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var style = AssetDanshariStyle.Get();
            var sb    = new StringBuilder();

            sb.AppendFormat("\"{0}\",", style.nameHeaderContent.text);
            sb.AppendFormat("\"{0}\"\n", style.dependenciesHeaderContent2.text);

            foreach (var info in data.children)
            {
                ExportCsvDataDir(info, sb, "├");
            }

            AssetDanshariUtility.SaveFileText(path, sb.ToString());
            GUIUtility.ExitGUI();
        }
        private string OnDrawElementAcceptDrop(Rect rect, string label)
        {
            if (rect.Contains(Event.current.mousePosition))
            {
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0 && !string.IsNullOrEmpty(DragAndDrop.paths[0]))
                {
                    if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    }

                    if (Event.current.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        GUI.changed = true;

                        return(AssetDanshariUtility.PathArrayToStr(DragAndDrop.paths));
                    }
                }
            }

            return(label);
        }
Exemplo n.º 14
0
        static void FindDependence()
        {
            List <string> queryFileList = AssetDanshariUtility.GetSelectAssets();

            CheckPaths <AssetDepWindow>(queryFileList);
        }
Exemplo n.º 15
0
        static void FindReference()
        {
            List <string> queryFileList = AssetDanshariUtility.GetSelectAssets();

            AssetBaseWindow.CheckPaths <AssetRefWindow>(queryFileList);
        }
Exemplo n.º 16
0
        public override void SetDataPaths(List <string> queryPahts)
        {
            base.SetDataPaths(queryPahts);
            data = FileListToAssetInfos(queryPahts);

            List <string> fileList = AssetDanshariUtility.GetAllFile(AssetDanshariUtility.ValidFile);
            var           rstList  = AssetDanshariUtility.ResultList(fileList.Count, queryPahts.Count);

            ThreadDoFilesTextSearch(fileList, queryPahts, rstList);

            for (int i = 0; i < fileList.Count; i++)
            {
                for (int j = 0; j < queryPahts.Count; j++)
                {
                    if (rstList[i][j])
                    {
                        AssetInfo info = GenAssetInfo(fileList[i]);
                        info.isRst = true;
                        data[j].AddChild(info);
                    }
                }
            }

            string[] md5Array = new string[queryPahts.Count];
            ThreadDoFileMD5(queryPahts, md5Array);
            Dictionary <string, List <AssetInfo> > dic = new Dictionary <string, List <AssetInfo> >();

            for (int i = 0; i < md5Array.Length; i++)
            {
                string           md5  = md5Array[i];
                List <AssetInfo> list = null;
                if (dic.TryGetValue(md5, out list))
                {
                    list.Add(data[i]);
                }
                else
                {
                    dic.Add(md5, new List <AssetInfo>()
                    {
                        data[i]
                    });
                }
            }
            var assetInfos = new List <AssetInfo>();

            foreach (var pair in dic)
            {
                if (pair.Value.Count < 2)
                {
                    continue;
                }
                AssetInfo dirInfo = new AssetInfo(GetAutoId(), String.Empty, String.Format(AssetDanshariStyle.Get().duplicateGroup, pair.Value.Count()));
                for (int i = 0; i < pair.Value.Count; i++)
                {
                    dirInfo.AddChild(pair.Value[i]);
                }
                assetInfos.Add(dirInfo);
            }

            if (assetInfos.Count > 0)
            {
                data = assetInfos;
            }
            else
            {
                data = null;
            }
            EditorUtility.ClearProgressBar();
        }