Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug analyst in not isolation version #165

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

Tartilla-TAIGO
Copy link
Contributor

@Tartilla-TAIGO Tartilla-TAIGO commented Nov 13, 2024

Bug fixes due to which the code analyzer cannot find the latest log if the version is not isolated


PR-Codex overview

This PR focuses on modifying the DefaultLogAnalyzer.cs file to enhance the handling of log file paths based on a new VersionIsolation condition, affecting how crash report and log file directories are constructed.

Detailed summary

  • Updated the crashReportDi initialization to consider VersionIsolation when determining the path.
  • Modified the paths for adding latest.log and debug.log to use VersionIsolation.
  • Ensured that the logic for log file retrieval remains consistent with the new path handling.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@laolarou726
Copy link
Member

LGTM, can you also fix the SonarCloud code suggestions? Thx

@yueyinqiu
Copy link
Member

LGTM, can you also fix the SonarCloud code suggestions? Thx

Would it be too strict?

@laolarou726 laolarou726 merged commit 6606d39 into Corona-Studio:master Nov 13, 2024
6 of 7 checks passed
@Tartilla-TAIGO
Copy link
Contributor Author

  IEnumerable<(LogFileType, (string, string))> GetAllLogs()
    {
        if (string.IsNullOrEmpty(RootPath))
            throw new NullReferenceException("未提供 RootPath 参数");
        if (string.IsNullOrEmpty(GameId))
            throw new NullReferenceException("未提供 GameId 参数");

        var logFiles = new List<FileInfo>();
        var fullRootPath = Path.GetFullPath(RootPath);
        var versionPath = Path.Combine(fullRootPath, GamePathHelper.GetGamePath(GameId));
        var logRootPath = VersionIsolation ? versionPath : RootPath;
        
        var crashReportDi = new DirectoryInfo(Path.Combine(logRootPath, "crash-reports"));
        if (crashReportDi.Exists)
            logFiles.AddRange(crashReportDi.GetFiles().Where(fi => fi.Extension is ".log" or ".txt"));

        var versionDi = new DirectoryInfo(logRootPath); //There may have been a typo
        if (versionDi.Exists)
            logFiles.AddRange(versionDi.GetFiles().Where(fi => fi.Extension == ".log"));

        logFiles.Add(new FileInfo(Path.Combine(logRootPath, "logs", "latest.log")));
        logFiles.Add(new FileInfo(Path.Combine(logRootPath, "logs", "debug.log")));

        if (CustomLogFiles is { Count: > 0 })
            logFiles.AddRange(CustomLogFiles.Select(custom => new FileInfo(custom)));

        foreach (var log in logFiles)
        {
            if (!IsValidLogFile(log, LogFileLastWriteTimeLimit)) continue;

            var logType = GetLogFileType(log);

            if (logType == LogFileType.Unknown) continue;

            var content = File.ReadAllText(log.FullName, Encoding.GetEncoding("GB2312"));

            if (string.IsNullOrWhiteSpace(content)) continue;

            yield return (logType, (log.FullName, content));
        }
    }

I have slightly corrected the code so that there are fewer conditions in it. Perhaps there was a typo in this line before, because it seems to me that the condition was constructed incorrectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants