Пример #1
0
    public void _SaveToFile(string rFileName)
    {
        if (null == GameRecordDataHandle)
        {
            return;
        }
        var dirPath = Util.GetDataPath() + Path;

        if (Directory.Exists(dirPath))
        {
            //日志过多。删除
            DirectoryInfo dInfo = new DirectoryInfo(dirPath);
            var           files = dInfo.GetFiles();
            if (files.Length > MAX_FILES)
            {
                Directory.Delete(dirPath, true);
            }
        }
        var path   = GetFullPath(rFileName);
        var stream = new MemoryStream();

        stream.Write(FightRecordManager.NowTimeToFileName());
        //记录关卡ID
        stream.Write(GameRecordDataHandle.DataType.ToString());
        GameRecordDataHandle.Save(stream);

        stream.Seek(0, SeekOrigin.Begin);
        var bytes = new byte[stream.Length];

        stream.Read(bytes, 0, (int)stream.Length);
        Logger.LogInfo($" save file : {path}");
        Util.SaveFile(path, bytes);

        stream?.Close();
    }
Пример #2
0
    private void _SaveToFile(object obj)
    {
        Logger.LogWarning($"开始文件保存线程:{m_saveThread.GetHashCode()}");

        while (m_logThread != null && m_logThread.IsAlive)
        {
            Thread.Sleep(100);
        }
        while (m_packetThread != null && m_packetThread.IsAlive)
        {
            Thread.Sleep(100);
        }
        try
        {
            var fileName = (string)obj;

            if (string.IsNullOrWhiteSpace(fileName))
            {
                fileName = FightRecordManager.NowTimeToFileName();
            }

            try
            {
                if (m_packetThread != null)
                {
                    gameRecorder._SaveToFile(fileName);
                    SetSaveState(fileName + ".gr", SaveState.Complete);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
            }

            try
            {
                if (m_logThread != null)
                {
                    gameLogger.SaveToFile(fileName);
                    SetSaveState(fileName + ".log", SaveState.Complete);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
            }

            m_saveThread.Interrupt();
        }
        catch (Exception e)
        {
            Logger.LogError(e.ToString());
        }
        Logger.LogWarning($"结束文件保存线程:{m_saveThread.GetHashCode()}");
        m_saveThread = null;
    }