Exemple #1
0
        public override void initDevice()
        {
#if UNITY_EDITOR
            //string path = string.Format("{0}{1}", Application.dataPath, "/Debug");
            string path = string.Format("{0}{1}", Ctx.m_instance.m_localFileSys.getWorkPath(), "/Debug");
#else
            string path = string.Format("{0}{1}", Application.persistentDataPath, "/Debug");
#endif
            checkDirSize(path); // 检查目录大小

            string file;
            if (string.IsNullOrEmpty(m_fileSuffix))
            {
                file = string.Format("{0}/{1}_{2}{3}", path, m_filePrefix, UtilApi.getUTCFormatText(), ".txt");
            }
            else
            {
                file = string.Format("{0}/{1}_{2}{3}{4}{5}", path, m_filePrefix, m_fileSuffix, "_", UtilApi.getUTCFormatText(), ".txt");
            }

            if (!Directory.Exists(path))                    // 判断是否存在
            {
                Directory.CreateDirectory(path);            // 创建新路径
            }

            //if (File.Exists(@file))                  // 判断文件是否存在
            //{
            //    FileInfo fileinfo = new FileInfo(file);
            //    if (fileinfo.Length > 1 * 1024 * 1024)           // 如果大于 1 M ,就删除
            //    {
            //        File.Delete(@file);
            //    }
            //}

            if (File.Exists(@file))                  // 如果文件存在
            {
                //m_fileStream = new FileStream(file, FileMode.Append);
                File.Delete(@file);
                m_fileStream = new FileStream(file, FileMode.Create);
            }
            else
            {
                m_fileStream = new FileStream(file, FileMode.Create);
            }

            m_streamWriter = new StreamWriter(m_fileStream);
        }