XLabsProject / iw4-zone-asset-finder

IW4 zone asset finder & source builder
GNU General Public License v3.0
2 stars 2 forks source link

Writing iwd dependencies to .txt #1

Open kryptoxide opened 1 year ago

kryptoxide commented 1 year ago

When using the command 'iwdfiles mp_terminal'

Output: "Successfully wrote all referenced iwd-files in mp_terminal_iwd.txt"

The output text file is unfortunately blank, I have fully processed the 'update' command.

kryptoxide commented 1 year ago

It seems like the issue might be related to the regular expression not matching the expected pattern in the output of the command. Let's take a closer look at the regular expression and the output to troubleshoot the problem.

The regular expression used in your code is:

var reg = new Regex(@"(\([a-z]+ [0-9]\)) (.*)");

This regex is meant to match lines that have a format like "([a-z] [0-9]) asset_name". Make sure that the output you're trying to parse matches this pattern exactly. If the pattern in the output is different, the regex won't be able to capture the asset names correctly.

To troubleshoot:

  1. Check Output Format: Examine the actual output from the command that is being captured in the output variable. Make sure it matches the expected format of the regex.

  2. Adjust Regex Pattern: If the output format is different, you might need to adjust the regular expression pattern to match the actual output format. If the asset names are enclosed in double quotes or brackets, for example, you would need to adjust the regex pattern accordingly.

  3. Debugging: Add some debugging statements to print the captured output before attempting to process it with the regular expression. This can help you visually confirm the format and identify any mismatches.

Here's an example of how you can add debugging statements to your code to help diagnose the issue:

// ... (previous code)

if (result == 0)
{
    // Add this line to debug the captured output
    cli.WriteLine($"Captured Output:\n{output}");

    var dumpFile = $"{zoneName}_iwd.txt";

    using (FileStream fs = new FileStream(dumpFile, FileMode.Create))
    {
        using (StreamWriter sw = new StreamWriter(fs))
        {
            var reg = new Regex(@"(\([a-z]+ [0-9]\)) (.*)");
            var matches = reg.Matches(output);

            foreach (Match match in matches)
            {
                // ... (remaining code)
            }
        }
    }

    // ... (remaining code)
}
else
{
    // ... (remaining code)
}

By examining the captured output and potentially adjusting the regular expression pattern, you should be able to resolve the issue of the blank .txt file being generated.