KFreonLib.Scripting.ModMaker.ModJob.GuessGame C# (CSharp) Method

GuessGame() private method

private GuessGame ( List pccs ) : int
pccs List
return int
            private int GuessGame(List<string> pccs)
            {
                int[] NumFounds = { 0, 0, 0 };

                DebugOutput.PrintLn("Starting to guess game...");

                IEnumerable<string>[] GameFiles = new IEnumerable<string>[3];

                GameFiles[0] = ME1Directory.Files;
                if (GameFiles[0] == null)
                    DebugOutput.PrintLn("Could not find ME1 files!");
                else
                    DebugOutput.PrintLn("Got ME1 files...");

                GameFiles[1] = ME2Directory.Files;
                if (GameFiles[1] == null)
                    DebugOutput.PrintLn("Could not find ME2 files!");
                else
                    DebugOutput.PrintLn("Got ME2 files...");

                GameFiles[2] = ME3Directory.Files;
                if (GameFiles[2] == null)
                    DebugOutput.PrintLn("Could not find ME3 files!");
                else
                    DebugOutput.PrintLn("Got ME3 files...");
                //DebugOutput.PrintLn("List of gamefiles acquired with counts " + ME1Directory.Files.Count + "  " + ME2Directory.Files.Count + "  " + ME3Directory.Files.Count + ". Beginning search...");

                try
                {
                    int test = 0;
                    foreach (IEnumerable<string> gamefiles in GameFiles)
                    {
                        if (gamefiles == null)
                        {
                            DebugOutput.PrintLn("Gamefiles was null in GuessGame for ME" + test++ + 1);
                            continue;
                        }
                        int found = 0;
                        Parallel.ForEach(pccs, pcc =>
                        {
                            if (pcc == null)
                            {
                                DebugOutput.PrintLn("PCC was null in GuessGame related to ME" + test + 1);
                                return;
                            }
                            //DebugOutput.PrintLn("Searching for game in pcc: " + pcc);
                            string temp = pcc.Replace("\\\\", "\\");
                            if (gamefiles.FirstOrDefault(t => t.Contains(temp)) != null)
                                found++;
                        });

                        NumFounds[test++] = found;
                    }
                }
                catch (Exception e)
                {
                    DebugOutput.PrintLn("Error guessing game: " + e.ToString());
                }


                DebugOutput.PrintLn("Finished guessing game.");
                if (NumFounds.Sum() == 0)
                    return -1;
                else
                {
                    int maxVal = NumFounds.Max();
                    var indices = Enumerable.Range(0, NumFounds.Count())
                        .Where(i => NumFounds[i] == maxVal)
                        .ToList();

                    if (indices.Count > 1)
                    {
                        DebugOutput.PrintLn("Could not guess game, files were present in more than one!");
                        return -2;
                    }
                    else
                        return indices[0] + 1;
                }
            }