Esempio n. 1
0
        private static void FormatOutput(string v, bool bypassLog)
        {
            List <Tuple <OutputColour, string> > outputs = new List <Tuple <OutputColour, string> >();
            OutputColour currentColour = OutputColour.Normal;
            int          pos           = 0;

            while (pos < v.Length)
            {
                int nextLineBreak    = v.IndexOf('\n', pos);
                int nextFindLocation = v.IndexOf('#', pos);
                if (nextLineBreak >= 0 && (nextFindLocation == -1 || nextLineBreak < nextFindLocation))
                {
                    outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextLineBreak + 1 - pos)));
                    pos = nextLineBreak + 1;
                }
                else if (nextFindLocation >= 0)
                {
                    // escaping a hash sign
                    if (nextFindLocation > 0 && v[nextFindLocation - 1] == '\\')
                    {
                        int len = nextFindLocation - 1 - pos;
                        if (len > 0)
                        {
                            outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, len)));
                        }
                        outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(nextFindLocation, 1)));
                        pos = nextFindLocation + 1;
                        continue;
                    }
                    int end = v.IndexOf('#', nextFindLocation + 1);
                    if (end <= nextFindLocation + 2 && end != -1)
                    {
                        // valid formatting tag
                        outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextFindLocation - pos)));
                        if (end == nextFindLocation + 1)
                        {
                            currentColour = OutputColour.Normal;
                            pos           = end + 1;
                        }
                        else
                        {
                            if (!OutputStyles.TryGetValue(v[nextFindLocation + 1], out currentColour))
                            {
                                SetOutputColour(OutputColour.Warning);
                                if (EnableDiagnostics)
                                {
                                    System.Console.WriteLine("Unrecognized formatting tag: '{0}'!", v[nextFindLocation + 1]);
                                }
                                currentColour = OutputColour.Normal;
                                if (nextFindLocation > pos)
                                {
                                    pos = nextFindLocation;
                                    outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, 1)));
                                }
                                else
                                {
                                    pos = pos + 1;
                                }
                            }
                            else
                            {
                                pos = end + 1;
                            }
                        }
                    }
                    else
                    {
                        outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextFindLocation - pos)));
                        pos = nextFindLocation + 1;
                    }
                }
                else if (nextLineBreak == -1)
                {
                    outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, v.Length - pos)));
                    pos = v.Length;
                }
            }

            bool newline = true;

            foreach (var x in outputs)
            {
                if (newline)
                {
                    FlushOutput(true, x, bypassLog);
                    newline = false;
                }
                else
                {
                    FlushOutput(false, x, bypassLog);
                }
                if (x.Item2.EndsWith("\n"))
                {
                    newline = true;
                }
            }
            SetOutputColour(OutputColour.Normal);
        }
Esempio n. 2
0
        private static int RunList(ListOptions p_Options)
        {
            try {
                ScrapPackedFile packedFile = new(p_Options.PackedFile);
                List <string>   FileList   = packedFile.GetFileNames();
                FileList.Sort();

                if (FileList.Count == 0)
                {
                    Console.WriteLine($"'{p_Options.PackedFile}' is empty.");
                }
                else
                {
                    List <string> SearchedList = Search(FileList, p_Options.SearchString, p_Options.IsRegex, p_Options.MatchBeginning, p_Options.MatchFilename);

                    if (SearchedList.Count == 0)
                    {
                        Console.WriteLine($"Could not find anything by query '{p_Options.SearchString}' in '{p_Options.PackedFile}'");
                    }

                    foreach (var File in SearchedList)
                    {
                        OutputStyles Styles = p_Options.OutputStyle;

                        string[] FileData   = File.Split("\t");
                        string   FilePath   = Path.GetDirectoryName(FileData[0]).Replace("\\", "/");
                        string   FileName   = Path.GetFileName(FileData[0]);
                        string   FileSize   = FileData[1];
                        string   FileOffset = FileData[2];

                        if (FilePath != "")
                        {
                            FilePath += "/";
                        }

                        string Output = FileName;

                        if (Styles != OutputStyles.Name)
                        {
                            Output = FilePath + Output;
                        }

                        if (p_Options.ShowFileSize)
                        {
                            Output += "\t" + FileSize;
                        }

                        if (p_Options.ShowFileOffset)
                        {
                            Output += "\t" + FileOffset;
                        }

                        Console.WriteLine(Output);
                    }
                }
                return(0);
            } catch (Exception ex) {
                Console.Error.WriteLine($"Error: {ex.Message}");
                return(1);
            }
        }