Ejemplo n.º 1
0
    public static string Convert(string path)
    {
        string dir  = Path.GetDirectoryName(path);
        var    inst = new Atxt2InlineHTML(dir);

        return(inst.Process(path));
    }
Ejemplo n.º 2
0
    public static void ConvertSave(string path, string outputPath)
    {
        string dir  = Path.GetDirectoryName(path);
        var    inst = new Atxt2InlineHTML(dir);
        string r    = inst.Process(path);

        File.WriteAllText(outputPath, r);
        Log.Note("Saved: " + outputPath);
    }
Ejemplo n.º 3
0
    public static void ConvertSaveDir(string path, string outputDir)
    {
        var inst = new Atxt2InlineHTML(path);

        foreach (var f in Directory.GetFiles(path))
        {
            if (AeroNovel.isIndexedTxt(f))
            {
                string r          = inst.Process(f);
                var    outputPath = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(f) + ".txt");
                File.WriteAllText(outputPath, r);
                Log.Note("Saved: " + outputPath);
            }
        }
    }
Ejemplo n.º 4
0
    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine("AeroNovelTool by AE Ver." + Version.date);
        Console.ForegroundColor = ConsoleColor.White;
        if (args.Length >= 2)
        {
            switch (args[0].ToLower())
            {
            case "epub":
            {
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                var gen = new AeroNovelEpub.GenEpub();
                for (int i = 2; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "--t2s":
                        gen.cc_option = AeroNovelEpub.ChineseConvertOption.T2S; break;

                    case "--no-info":
                        gen.addInfo = false;
                        break;

                    case "--no-indent-adjust":
                        gen.indentAdjust = false;
                        break;
                    }
                }

                EpubFile      e          = gen.Gen(args[1]);
                List <string> creators   = new List <string>();
                string        dateString = DateTime.Today.ToString("yyyyMMdd");
                e.dc_creators.ForEach((x) =>
                    {
                        if (x.refines.Count > 0)
                        {
                            foreach (var refine in x.refines)
                            {
                                if (refine.name == "role")
                                {
                                    if (refine.value != "aut")
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        creators.Add(x.value);
                    });
                try
                {
                    e.meta.ForEach((x) => { if (x.name == "dcterms:modified")
                                            {
                                                dateString = x.value.Replace("-", "").Substring(0, 8);
                                            }
                                   });
                }
                catch (ArgumentOutOfRangeException)
                {
                    Log.Warn("Error at getting modified date in metadata");
                }

                e.filename = $"[{string.Join(",", creators)}] {e.title} [{dateString}]";
                if (args.Length >= 3 && DirectoryExist(args[2]))
                {
                    e.Save(args[2]);
                }
                else
                {
                    e.Save("");
                }
            }
            break;

            case "txt":
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                GenTxt.Gen(args[1]);
                break;

            case "bbcode":
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                if (args.Length >= 3)
                {
                    if (DirectoryExist(args[2]))
                    {
                        GenBbcode.output_path        = Path.Combine(args[2], GenBbcode.output_path);
                        GenBbcode.output_path_single = Path.Combine(args[2], GenBbcode.output_path_single);
                    }
                }
                GenBbcode.GenSingle(args[1]);
                break;

            case "epub2comment":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Epub2Comment e2c = new Epub2Comment(args[1]);
                if (args.Length > 2)
                {
                    switch (args[2])
                    {
                    case "BlackMagic-Cloud":
                        e2c.setTextTranslation = new BlackMagic_Cloud();
                        break;

                    case "BlackMagic-Dog":
                        e2c.setTextTranslation = new BlackMagic_Dog();
                        break;

                    case "Glossary":
                        if (args.Length > 3)
                        {
                            e2c.glossaryDocPath = args[3];
                        }
                        else
                        {
                            Log.Error("Should give glossary document.");
                        }
                        break;
                    }
                }
                e2c.Proc();
                break;

            case "epub2atxt":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Epub2Atxt.Proc(args[1]);
                break;

            case "html2comment":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Html2Comment.Proc(args[1]);
                break;

            case "atxt2bbcode":
                if (!FileExist(args[1]))
                {
                    return;
                }
                GenBbcode.Proc(args[1]);
                break;

            case "kakuyomu2comment":
            {
                var xhtml = WebSource.KakuyomuEpisode(args[1]);
                var atxt  = Html2Comment.ProcXHTML(xhtml.text);
                File.WriteAllText("output_kakuyomu2comment.txt", atxt);
                Log.Note("output_kakuyomu2comment.txt");
            }
            break;

            case "websrc":
            {
                TextEpubItemFile[] xhtmls;
                string             dirname = "output_websrc_";
                if (args[1].Contains("kakuyomu.jp"))
                {
                    xhtmls   = WebSource.KakuyomuAuto(args[1]);
                    dirname += "kakuyomu";
                }
                else
                {
                    Log.Error("什么网站");
                    break;
                }
                if (xhtmls != null)
                {
                    Directory.CreateDirectory(dirname);
                    foreach (var xhtml in xhtmls)
                    {
                        Save(xhtml, dirname);
                    }
                }
            }
            break;

            case "atxtcc":
            {
                if (!FileExist(args[1]))
                {
                    return;
                }
                bool t2s = false, s2t = false, replace = false;
                for (int i = 2; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "t2s": t2s = true; break;

                    case "s2t": s2t = true; break;

                    case "replace": replace = true; break;
                    }
                }
                if (t2s)
                {
                    AeroNovelEpub.AtxtChineseConvert.ProcT2C(args[1], replace);
                }
                else if (s2t)
                {
                    //Not Implemented
                }
            }
            break;

            case "atxt2inlinehtml":
                if (File.Exists(args[1]))
                {
                    Atxt2InlineHTML.ConvertSave(args[1], $"output_inlineHTML_{Path.GetFileNameWithoutExtension(args[1])}.txt");
                    break;
                }
                if (Directory.Exists(args[1]))
                {
                    var outputPath = "output_inlineHTML_" + Path.GetFileName(args[1]);
                    Directory.CreateDirectory(outputPath);
                    Atxt2InlineHTML.ConvertSaveDir(args[1], outputPath);
                    break;
                }
                Log.Warn("Nothing happens. Make sure there is a file or folder to process.");
                break;

            case "analyze":
                if (Directory.Exists(args[1]))
                {
                    if (args.Length >= 3)
                    {
                        int chap = 0;
                        if (!int.TryParse(args[2], out chap))
                        {
                            Log.Error("Chapter number!");
                        }
                        Statistic.AnalyzeProject(args[1], chap);
                        break;
                    }
                    Statistic.AnalyzeProject(args[1]);
                    break;
                }
                break;

            default:
                Log.Warn("Nothing happens. " + usage);
                break;
            }
        }
        else
        {
            Log.Warn(usage);
        }
    }