Example #1
0
        public void OnClearTempFile()
        {
            //RankXml
            DateTime time     = SystemTime.Instance.GetSystemDateTime;
            UInt32   WriteSec = FishConfig.Instance.GetWriteSec();

            time = time.AddSeconds(WriteSec * -1);
            string NowDayRankFileName = string.Format("Rank_{0}_{1}_{2}.xml", time.Year, time.Month, time.Day);

            //MonthXml
            //比赛的排行榜文件 更加复杂 删除一个星期以前的文件 取日期 判断时间
            //1.排行榜文件
            string[] FileList = RuntimeInfo.GetLocalFiles();
            for (int i = 0; i < FileList.Length; ++i)
            {
                string FileName = FileList[i];
                if (FileName.Length == 0 || FileName == "")
                {
                    continue;
                }
                //判断文件的类型
                //1.每天排行榜文件 Rank_xxx_xxx
                if (FileName.IndexOf("Rank_") != -1 && FileName.IndexOf(".xml") != -1)
                {
                    if (FileName != NowDayRankFileName)
                    {
                        try
                        {
                            File.Delete(FileName);
                        }
                        catch
                        {
                        }
                        //RuntimeInfo.DeleteLocalFile(FileName);//将文件移除掉
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
                //2.周排行榜文件
                if (FileName.IndexOf("Month_") != -1 && FileName.IndexOf(".xml") != -1)
                {
                    string   strName = FileName.Substring(0, FileName.IndexOf(".xml"));
                    string[] Info    = strName.Split('_');
                    if (Info.Length != 7)
                    {
                        continue;
                    }

                    //Convert.ToInt32(Info[1]),
                    DateTime data = new DateTime(Convert.ToInt32(Info[2]), Convert.ToInt32(Info[3]),
                                                 Convert.ToInt32(Info[4]), Convert.ToInt32(Info[5]), Convert.ToInt32(Info[6]), 0);
                    TimeSpan span = SystemTime.Instance.GetSystemDateTime - data;
                    if (span.TotalSeconds >= 7 * 24 * 3600) //超过一个星期了
                    {
                        try
                        {
                            File.Delete(FileName);
                        }
                        catch
                        {
                        }
                        //RuntimeInfo.DeleteLocalFile(FileName);//将文件移除掉
                        continue;
                    }
                }
            }
        }