Esempio n. 1
0
        private static void Pack(RantPackage package, string contentPath)
        {
            foreach (var path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories)
                     .Where(p => p.EndsWith(".rant") || p.EndsWith(".rants")))
            {
                var    pattern = RantPattern.FromFile(path);
                string relativePath;
                TryGetRelativePath(contentPath, path, out relativePath, true);
                pattern.Name = relativePath;
                package.AddPattern(pattern);
                Console.WriteLine("+ " + pattern.Name);
            }

            foreach (var path in Directory.GetFiles(contentPath, "*.dic", SearchOption.AllDirectories))
            {
                Console.WriteLine("+ " + path);
                var table = RantDictionaryTable.FromFile(path);
                package.AddTable(table);
            }
        }
Esempio n. 2
0
        private static void ProcessDicFile(string path)
        {
            var table = RantDictionaryTable.FromFile(path);

            table.Save(path, Flag("diff"));
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

            Title = "Rant Console" + (Flag("nsfw") ? " [NSFW]" : "");

            var rant = new RantEngine();

#if !DEBUG
            try
            {
#endif
            if (!String.IsNullOrEmpty(DIC_PATH))
            {
                rant.Dictionary = RantDictionary.FromDirectory(DIC_PATH);
            }
            else
            {
                foreach (var dic in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dic", SearchOption.AllDirectories))
                {
                    rant.Dictionary.AddTable(RantDictionaryTable.FromFile(dic));
                }
            }

            if (!String.IsNullOrEmpty(PKG_PATH))
            {
#if DEBUG
                Stopwatch timer = Stopwatch.StartNew();
#endif
                rant.LoadPackage(PKG_PATH);
#if DEBUG
                timer.Stop();
                WriteLine($"Package loading: {timer.ElapsedMilliseconds}ms");
#endif
            }
            else
            {
                foreach (var pkg in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.rantpkg", SearchOption.AllDirectories))
                {
                    rant.LoadPackage(pkg);
                }
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            ForegroundColor = ConsoleColor.Cyan;
            WriteLine($"Dictionary load error: {e.Message}");
        }
#endif
            if (Flag("nsfw"))
            {
                rant.Dictionary.IncludeHiddenClass("nsfw");
            }

            if (!String.IsNullOrEmpty(FILE))
            {
#if !DEBUG
                try
                {
#endif
                PrintOutput(rant, File.ReadAllText(FILE));
#if !DEBUG
            }
            catch (Exception ex)
            {
                ForegroundColor = ConsoleColor.Red;
                WriteLine(ex.Message);
                ResetColor();
            }
#endif

                if (Flag("wait"))
                {
                    ReadKey(true);
                }
                return;
            }

            while (true)
            {
                ForegroundColor = Flag("nsfw") ? ConsoleColor.DarkRed : ConsoleColor.Gray;
                Write("RANT> "); // real number symbol
                ForegroundColor = ConsoleColor.White;
                PrintOutput(rant, ReadLine());
            }
        }