Example #1
0
        public bool ClearResCachePath()
        {
            string[] clearExtFiles = new string[] { ".json", ".res", ".bytes", ".txt" };
            string[] clearPaths    = new string[] { FileUtil.IFSExtractFolder };
            string   cachePath     = FileUtil.GetCachePath();

#if UNITY_EDITOR
            FileUtil.ClearDirectory(cachePath, clearExtFiles, clearPaths);
            return(true);
#else
            int tryCount = 0;
            while (true)
            {
                bool   isClearSuc   = FileUtil.ClearDirectory(cachePath, clearExtFiles, clearPaths);
                bool   isDirExsit   = true;
                string notClearFile = "";

                try
                {
                    if (isClearSuc)
                    {
                        string resCachePath = FileUtil.GetIFSExtractPath();
                        isDirExsit = FileUtil.IsDirectoryExist(resCachePath);
                        if (!isDirExsit)
                        {
                            bool     filesClear = true;
                            string[] files      = System.IO.Directory.GetFiles(cachePath);
                            for (int i = 0; i < files.Length; i++)
                            {
                                for (int j = 0; j < clearExtFiles.Length; j++)
                                {
                                    if (files[i].Contains(clearExtFiles[j]))
                                    {
                                        notClearFile = files[i];
                                        filesClear   = false;
                                        break;
                                    }
                                }

                                if (!filesClear)
                                {
                                    break;
                                }
                            }

                            if (filesClear)
                            {
                                return(true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    JW.Common.Log.LogE("CleanCache Exception : {0}", ex.ToString());
                }

                ++tryCount;

                if (tryCount >= 3)
                {
                    JW.Common.Log.LogE("CleanCache Res Cache Failed isClearSuc : {0}, isDirExsit : {1}, notClearFile : {2}",
                                       isClearSuc, isDirExsit, notClearFile);
                    return(false);
                }
                else
                {
                    JW.Common.Log.LogE("CleanCache Res Cache Failed [Have Chance : {0}] isClearSuc : {1}, isDirExsit : {2}, notClearFile : {3}",
                                       tryCount, isClearSuc, isDirExsit, notClearFile);
                }
            }
#endif
        }