Ejemplo n.º 1
0
        bool Changed(string f)
        {
            var ret  = false;
            var hash = qstr.md5(QuickStream.LoadString(f));
            var info = new FileInfo(f);

            ret = ret || hash != Data.C($"HASH {f}");
            // This checkup is new, and I don't want adeptions due to changes made by outdated MKL updaters.
            if (Data.C($"SIZE {f}") != "")
            {
                ret = ret || $"{info.Length}" != Data.C($"SIZE {f}");
            }
            // This checkup is new, and I don't want adeptions due to changes made by outdated MKL updaters. Also the way this is constructed will only work properly in C#, so if this tool is ever rewritten in another language, this checkup will be ignored.
            // C#TM means "C# time", but I guess that was obvious :P
            if (Data.C($"C#TM {f}") != "")
            {
                ret = ret || $"{info.CreationTime.ToString()}" != Data.C($"C#TM {f}");
            }
#if ChangeDebug
            Console.WriteLine($"Outcome to the check is {ret}");
            Console.WriteLine($"hashcheck:  {hash}/{Data.C($"HASH {f}")}/{hash == Data.C($"HASH {f}")}");
            Console.WriteLine($"sizecheck:  {info.Length}/{Data.C($"SIZE {f}")}");
#endif

            return(ret);
        }
Ejemplo n.º 2
0
        public string ScriptVersion()
        {
            var ss = QuickStream.LoadString(Script);
            var s  = ss.Split('\n');

            foreach (string ln in s)
            {
                //Console.WriteLine($"TEST:  {ln.Trim().ToUpper()} >> {qstr.Prefixed(ln.Trim().ToUpper(), "#MKL_VERSION")}");
                if (qstr.Prefixed(ln.Trim().ToUpper(), "#MKL_VERSION"))
                {
                    var version = new StringBuilder("");
                    var quotes  = 0;
                    for (int i = 0; i < ln.Length; i++)
                    {
                        if (ln[i] == '"')
                        {
                            quotes++;
                        }
                        else if (quotes == 3)
                        {
                            version.Append($"{ln[i]}");
                        }
                    }
                    return($"{version}");
                }
            }
            return("<< Script Version Not Retreived >>");
        }
Ejemplo n.º 3
0
 public string LoadString(string file)
 {
     if (!FileExists(file))
     {
         return("");
     }
     return(QuickStream.LoadString(file));
 }
Ejemplo n.º 4
0
        void UpdateData(string f)
        {
            var info = new FileInfo(f);

            Data.D($"HASH {f}", qstr.md5(QuickStream.LoadString(f)));
            Data.D($"SIZE {f}", $"{info.Length}");
            Data.D($"C#TM {f}", $"{info.CreationTime.ToString()}");
            Data.SaveSource(GINIFile);
        }
Ejemplo n.º 5
0
        static void RunScript(string[] args)
        {
            var API       = new NIL_API();
            var argscript = new StringBuilder("AppArgs={}\n");

            API.NILScript = QuickStream.StringFromEmbed("NIL.lua");
            for (int i = 0; i < args.Length; i++)
            {
                if (i == 0)
                {
                    argscript.Append("AppArgs.Application =");
                }
                else
                {
                    argscript.Append($"AppArgs[{i}] = ");
                }
                argscript.Append($"\"{qstr.SafeString(args[i].Replace("\\","/"))}\"\n");
            }
            var state = new Lua();

            try {
                state["QNIL"] = API;
                var initNIL = "NIL = assert((loadstring or load)(QNIL.NILScript,\"NIL\")())"; //$"NIL = (loadstring or load)(\n\"{qstr.SafeString(nilscript)}\"\n,'NIL')\n()";
                Debug.WriteLine($"initNIL: {initNIL}");
                state.DoString(initNIL, "Internal: NIL");
                state.DoString("NIL.SayFuncs[#NIL.SayFuncs+1]=function(sayit) print(\"#say \"..tostring(sayit)) end", "NIL.Say Init");
                //var initARGS = $"local act = assert(NIL.Load(\"{qstr.SafeString(argscript.ToString())}\"))\nact()";
                //Debug.WriteLine($"--- ARGUMENTS ---\n{initARGS}\n--- END ARGUMENTS ---");
                Debug.WriteLine($"--- ARGUMENTS ---\n{argscript.ToString()}\n--- END ARGUMENTS ---");
                state.DoString(argscript.ToString(), "Interal: CLI Arguments");
                var script = QuickStream.LoadString(args[0]);
                switch (qstr.ExtractExt(args[0]).ToLower())
                {
                case "lua":
                    state.DoString(script, $"Lua:{args[0]}");
                    break;

                case "nil":
                    state.DoString($"local run = assert(NIL.Load(\"{qstr.SafeString(script)}\"))\nrun()", $"NIL:{args[0]}");
                    break;

                default:
                    throw new Exception("Unknown file extension!");
                }
            } catch (Exception Fout) {
                Debug.WriteLine($"ERROR: {Fout.Message}");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("ERROR! ");
                Console.Beep();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(Fout.Message);
                Console.ResetColor();
            }
        }
Ejemplo n.º 6
0
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
         Console.WriteLine("txt2unix - Coded by Jeroen P. Broks");
         Console.WriteLine("\n\tUsage: txt2unix <text-files>");
         Console.WriteLine("\n\nWarning this tool is very very simplistic and although it does try to distiguish text files from binary files, there is no 100% protection, and using it on binary files can have very funny outcomes!");
     }
     else
     {
         foreach (string fl in args)
         {
             Console.ForegroundColor = ConsoleColor.Yellow;
             Console.Write("Processing: ");
             Console.ForegroundColor = ConsoleColor.Cyan;
             Console.Write($"{fl} ");
             Console.ForegroundColor = ConsoleColor.Magenta;
             Console.Write("r\b");
             string s = QuickStream.LoadString(fl);
             Console.Write("p\b");
             if (s.IndexOf((char)26) >= 0)
             {
                 E("Binary file! Can't process!");
             }
             else
             {
                 s = s.Replace("\r\n", "\n");
                 Console.Write("w\b");
                 QuickStream.SaveString(fl, s);
                 Console.ForegroundColor = ConsoleColor.Green;
                 Console.WriteLine("Ok");
             }
         }
     }
     Console.ForegroundColor = ConsoleColor.Gray;
 }
Ejemplo n.º 7
0
        static void LoadScript(string script, string args)
        {
            script = Dirry.AD(script.Replace("\\", "/"));
            State  = new Lua();
            var CallScript = $"ls = loadstring or load\nlocal LoadNeil = assert(ls(\"{NeilScript.Replace("\\","\\\\").Replace("\n", "\\n").Replace("\r", "").Replace("\"","\\\"")}\",\"Neil itself\"))\nNeil = LoadNeil()";

            Debug.WriteLine(CallScript);
            State.DoString(CallScript, "Call Neil itself");
            // newk,oftype,rw,defaultvalue
            // if (true) throw new Exception(args);
            State.DoString($"Neil.Globals('Args','table','constant',{args})", "Set CLI arguments");
            new API(State, script);
            TrickyDebug.Chat("Loaded Neil");
            var s = QuickStream.LoadString(Dirry.AD(script));

            TrickyDebug.Chat($"Loaded Script: {script}");
            //var scr = s.Replace("\\", "\\\\").Replace("\n", "\\n").Replace("\r", "").Replace("\"", "\\\"");
            var scr = s.Replace("\\", "\\\\");

            for (int i = 0; i < 256; i++)
            {
                if (i < 32 || i > 120 || (char)i == '"')
                {
                    scr = scr.Replace($"{(char)i}", $"\\{qstr.Right($"00{i}", 3)}");
                }
            }
            // Console.WriteLine($"<C#>{scr}</C#>");
            // Console.WriteLine($"Script: {script}");
            TrickyDebug.Chat("String secured");
            var sendscr = $"local translation = assert(Neil.Translate(\"{scr}\",\"Translate: {script}\"))\n\nlocal err; QUICKNEILSCRIPTFUNCTION,err = ls(translation,\"{script}\")\n\nif not QUICKNEILSCRIPTFUNCTION then error(\"Compiling the translation failed\\n\"..tostring(err)..\"\\n\\n\"..translation) end";

            //Console.WriteLine($"<TRANSLATION>\n{sendscr}\n</TRANSLATION>");
            Debug.WriteLine(sendscr);
            State.DoString(sendscr, "Translating");
            State.DoString("QUICKNEILSCRIPTFUNCTION()", "Run-Time");
        }
Ejemplo n.º 8
0
        private void DirBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Entry_Alias.Items.Clear();
            Entry_Ratio.Content = "N/A";
            Entry_Main.Content  = "--";
            if (DirBox.SelectedItem == null)
            {
                foreach (string EL in EntryLink.Keys)
                {
                    EntryLink[EL].Content = "--";
                }
                UpdateBlockView(false);
                return;
            }
            var item = (string)DirBox.SelectedItem;

            if (Core.IN_Resource)
            {
                var ename = $"{Core.CDirectory}/{item}";
                while (ename != "" && ename[0] == '/')
                {
                    ename = ename.Substring(1);
                }
                if (qstr.Suffixed(ename, "/"))
                {
                    foreach (string EL in EntryLink.Keys)
                    {
                        EntryLink[EL].Content = "N/A";
                    }
                    Entry_Entry.Content = ename;
                    Entry_Type.Content  = "Directory";
                    UpdateBlockView(false);
                }
                else
                {
                    var E = Core.JCR.Entries[ename.ToUpper()];
                    UpdateBlockView(E.Block != 0);
                    foreach (TJCREntry ECHK in Core.JCR.Entries.Values)
                    {
                        if (ECHK != E && ECHK.MainFile == E.MainFile && ECHK.Offset == E.Offset && ECHK.Block == E.Block)
                        {
                            Entry_Alias.Items.Add(ECHK.Entry);
                        }
                    }
                    foreach (string k in E.databool.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            if (E.databool[k])
                            {
                                EntryLink[k].Content = "Yes";
                            }
                            else
                            {
                                EntryLink[k].Content = "No";
                            }
                        }
                    }
                    foreach (string k in E.dataint.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            EntryLink[k].Content = $"{E.dataint[k]}";
                        }
                    }
                    foreach (string k in E.datastring.Keys)
                    {
                        if (EntryLink.ContainsKey(k))
                        {
                            EntryLink[k].Content = $"{E.datastring[k]}";
                        }
                    }
                    Entry_Main.Content  = E.MainFile;
                    Entry_Ratio.Content = E.Ratio;
                    if (E.Block != 0)
                    {
                        Entry_Ratio.Content  = "Unavailable (block)";
                        Entry_Offset.Content = "Unavailable (block)";
                        var B = Core.JCR.Blocks[$"{E.Block}:{E.MainFile}"];
                        Entry_Entry_Block.Content = E.Entry;
                        Entry_Block.Content       = $"{E.Block}";
                        Block_Entries.Items.Clear();
                        foreach (var BE in Core.JCR.Entries.Values)
                        {
                            if (BE.Block == E.Block)
                            {
                                Block_Entries.Items.Add(BE.Entry);
                            }
                        }
                        Block_EntryOffset.Content = $"{E.Offset}";
                        Block_Offset.Content      = $"{B.Offset}";
                        Block_Size.Content        = $"{B.Size}";
                        Block_CSize.Content       = $"{B.CompressedSize}";
                        Block_Ratio.Content       = $"{B.Ratio}%";
                    }
                    if (Core.Config[Core.Platform, "ViewSwap"] == "")
                    {
                        Viewer.Navigate($"file://{Core.MyExeDir}/NoViewSwap.html");
                    }
                    else
                    {
                        switch (qstr.ExtractExt(E.Entry).ToLower())
                        {
                        case "jpg":
                        case "jpeg":
                        case "gif":
                        case "bmp":
                        case "png":
                            ImgViewer.ViewImg(Core.JCR.JCR_B(E.Entry), $"{E.MainFile}/{E.Entry}");
                            Viewer.Refresh();
                            break;

                        default:
                            KittyViewer.View($"{E.MainFile}/{E.Entry}", Core.JCR.LoadString(E.Entry));
                            break;
                        }
                        Viewer.Navigate($"file://{Core.Config[Core.Platform, "VIEWSWAP"]}/ViewFile.html");
                    }
                }
            }
            else
            {
                var ename = $"{Core.CDirectory}/{item}";
                if (!qstr.Suffixed(ename, "/"))
                {
                    if (Core.Config[Core.Platform, "ViewSwap"] == "")
                    {
                        Viewer.Navigate($"file://{Core.MyExeDir}/NoViewSwap.html");
                    }
                    else if (JCR6.Recognize(ename).ToUpper() != "NONE")
                    {
                        var odir = Core.Config[Core.Platform, "VIEWSWAP"];
                        var KV   = new KittyViewer();
                        KV.ForegroundColor = ConsoleColor.Yellow;
                        KV.WriteLine("JCR6 resource");
                        KV.ForegroundColor = ConsoleColor.White;
                        KV.WriteLine($"File {qstr.StripDir(ename)} has been recognized as: {JCR6.Recognize(ename)}");
                        KV.WriteLine($"JCR6 understands this format, so why don't you open it to see its contents?");
                        Directory.CreateDirectory(odir);
                        QuickStream.SaveString($"{odir}/ViewJCRFile.html", KV.ToString());
                        Viewer.Navigate($"{odir}/ViewJCRFile.html");
                    }
                    else
                    {
                        switch (qstr.ExtractExt(ename).ToLower())
                        {
                        case "jpg":
                        case "jpeg":
                        case "gif":
                        case "bmp":
                        case "png":
                            ImgViewer.ViewImg(QuickStream.GetFile(ename), ename);
                            break;

                        default:
                            KittyViewer.View($"{ename}", QuickStream.LoadString(ename));
                            break;
                        }
                        Viewer.Navigate($"file://{Core.Config[Core.Platform, "VIEWSWAP"]}/ViewFile.html");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // Header
            QCol.Red("Kitty "); QCol.Magenta("Coded by: Tricky\n");
            QCol.Yellow($"(c) {MKL.CYear(2019)} Jeroen P. Broks\n\n");
            // Init
            Dirry.InitAltDrives();
            KittyHigh.Init();
            new KittyHighCS();
            new KittyHighNIL();
            new KittyHighLua();
            new KittyHighGINI();
            new KittyHighScyndi();
            new KittyBlitzMax();
            new KittyHighC();
            new KittyHighPascal();
            new KittyHighBrainFuck();
            new KittyHighGo();
            new KittyHighBlitzBasic();
            new KittyHighSASKIA();
            new KittyHighPython();
            new KittyHighJavaScript();
            new KittyHighWhiteSpace();
            new KittyHighBASIC();
            new KittyHighJava();
            new KittyHighINI();
            new KittyHighVB();
            new KittyHighCobra();
            new KittyHighHtml();
            new KittyHighXml();
            new KittyHighNeil();
            var slin = true;

            if (args.Length == 0)
            {
                QCol.Green("Kitty is a simple program which will help you view source files in syntax highlight\n");
                QCol.Magenta("Usage:\t");
                QCol.Yellow("Kitty ");
                QCol.Cyan("<switches> ");
                QCol.White("<files>");
                QCol.Green("[");
                QCol.Cyan("<switches> ");
                QCol.White("<files>");
                QCol.Green("..]");
                Console.WriteLine("\n\n");
                QCol.Yellow("Please note that switches affect all files defined after it not those that come before it. This allows you to configure each file shown\n\n");
                QCol.Cyan("-ln              "); QCol.Yellow("Toggle line numbers on/off (default is on)\n");
                QCol.Cyan("-nolinenumbers   "); QCol.Yellow("Turn line numbers off\n");
                QCol.Cyan("-Showlinenumbers "); QCol.Yellow("Turn line numbers on\n");
                QCol.Cyan("-re              "); QCol.Yellow("Toggle searching by RegEx (this allows limited support for Wild Cards and more nice things)\n");
                QCol.Cyan("-p, -more        "); QCol.Yellow("Turn \"more\" mode on/off. (Read note below)\n");
                QCol.Cyan("-support         "); QCol.Yellow("Show a list of all supported file formats\n");
                QCol.Red("\n\nThe \"more\" mode!\n");
                QCol.Yellow("Does not entirely work the same as the 'more' utility, but has the same primary function!\n");
                QCol.Yellow("When the \"more\" bar appears you can hit space to show the next line, Enter/Return to show the entire next page and escape to turn the more mode off\n");
                QCol.White("\n\nKitty can be used as as CLI tool, but the integry has been made to be included in your own projects, and has been released under the terms of the zlib license\n\n");
                return;
            }
            // Go for it
            QCol.Doing("Called from:", System.IO.Directory.GetCurrentDirectory());
            void ViewFile(string a)
            {
                try {
                    var arg = Dirry.AD(a).Replace("\\", "/");
                    QCol.Doing("Reading", arg); KittyHigh.PageBreak();
                    var src  = QuickStream.LoadString(arg);
                    var eoln = qstr.EOLNType(arg);
                    // QCol.Doing("EOLN", eoln); // didn't work anyway
                    //QCol.OriCol();
                    var       ext    = qstr.ExtractExt(arg).ToLower();
                    KittyHigh Viewer = KittyHigh.Langs["OTHER"];
                    if (KittyHigh.Langs.ContainsKey(ext))
                    {
                        Viewer = KittyHigh.Langs[ext];
                    }
                    QCol.Doing("Type", Viewer.Language); KittyHigh.PageBreak();
                    KittyHigh.WriteLine();
                    Viewer.Show(src, slin);
                } catch (Exception ex) {
                    QCol.QuickError($"{ex.Message}\n");
#if DEBUG
                    QCol.Magenta($"{ex.StackTrace}\n\n");
#endif
                }
            }

            var aregex = false;
            foreach (string a in args)
            {
                if (qstr.Prefixed(a, "-"))
                {
                    switch (a.ToLower())
                    {
                    case "-ln": slin = !slin; break;

                    case "-nolinenumbers": slin = false; break;

                    case "-showlinenumbers": slin = true; break;

                    case "-p":
                    case "-more": KittyHigh.BrkLines = !KittyHigh.BrkLines; break;

                    case "-re": aregex = !aregex; break;

                    case "-support":
                        foreach (string ext in KittyHigh.Langs.Keys)
                        {
                            QCol.Cyan(qstr.Left($"{ext}                    ", 20));
                            QCol.Yellow($"{KittyHigh.Langs[ext].Language}\n");
                        }
                        break;

                    default: QCol.QuickError($"Unknown switch: {a}"); break;
                    }
                }
                else if (aregex)
                {
                    QCol.Doing("Searching for RegEx", a);
                    var rgxl = RegExTree.Tree(a);
                    foreach (string af in rgxl)
                    {
                        ViewFile(af);
                    }
                }
                else
                {
                    ViewFile(a);
                }
            }
            TrickyDebug.AttachWait();
        }
Ejemplo n.º 10
0
        static public void Gen()
        {
            string template;
            var    cp = CurrentProject; if (cp == null)

            {
                GUI.WriteLn("GEN: No project!"); return;
            }

            try {
                System.IO.Directory.CreateDirectory(OutDir);
            } catch (Exception e) {
                GUI.WriteLn($"GEN: {e.Message}");
                return;
            }
            int    pages        = cp.CountRecords / 200;
            int    page         = 1;
            int    pcountdown   = 200;
            bool   justnewpaged = false;
            string olddate      = "____OLD____";

            string[] iconext = { "png", "gif", "svg", "jpg" };
            if (cp.CountRecords % 200 > 0)
            {
                pages++;
            }
            try{
                template = QuickStream.LoadString(cp.Template.Trim());
            } catch {
                QuickGTK.Error($"Template {cp.Template} could not be properly loaded!");
                GUI.WriteLn($"GEN:Template {cp.Template} could not be properly loaded!");
                return;
            }
            GUI.Write("Exporting...");
            var pageline = "";

            for (int p = 1; p <= pages; p++)
            {
                if (page == p)
                {
                    pageline += $"<big><big>{p}</big></big> ";
                }
                else
                {
                    pageline += $"<a href='{cp.PrjName}_DevLog_Page_{p}.html'>{p}</a> ";
                }
            }
            pageline = pageline.Trim();
            var content = new System.Text.StringBuilder($"<table style=\"width:{cp.GetDataDefaultInt("EXPORT.TABLEWIDTH", 1200)}\">\n");

            content.Append($"<tr><td colspan=3 align=center>{pageline}</td></tr>\n");
            for (int i = cp.HighestRecordNumber; i > 0; i--)
            {
                //if (i % 6 == 0) { GUI.Write("."); Console.Write($".{i}."); }
                justnewpaged = false;
                var rec = new dvEntry(cp, i, true);
                if (rec.Loaded)
                {
                    if (rec.Date != olddate)
                    {
                        content.Append($"<tr><td align=center colspan=3 style='font-size:30pt;'>- = {rec.Date} = -</td></tr>\n");
                    }
                    olddate = rec.Date;
                    string headstyle    = cp.Data.C($"HEAD.{rec.Tag.ToUpper()}");
                    string contentstyle = cp.Data.C($"INHD.{rec.Tag.ToUpper()}");
                    content.Append($"<tr valign=top><td align=left><a id='dvRec_{rec.RecID}'></a>{rec.Time}</td><td style=\"{headstyle}\">{rec.Tag}</td><td style='width: { cp.GetDataDefaultInt("EXPORT.CONTENTWIDTH", 800)}; {contentstyle}'><div style=\"width: { cp.GetDataDefaultInt("EXPORT.CONTENTWIDTH", 800)}; overflow-x:auto;\">");
                    var alticon = cp.Data.C($"ICON.{rec.Tag.ToUpper()}").Trim();
                    if (alticon == "")
                    {
                        var icon    = $"{OutDir}/Icons/{rec.Tag.ToLower()}";
                        var neticon = $"Icons/{rec.Tag.ToLower()}";
                        neticon = neticon.Replace("#", "%23");
                        icon    = icon.Replace("#", "hashtag");
                        foreach (string pfmt in iconext)
                        {
                            var iconfile = $"{icon}.{pfmt}";
                            iconfile = iconfile.Replace("#", "%23");
                            if (System.IO.File.Exists(iconfile))
                            {
                                content.Append($"<img style='float:{cp.GetDataDefault("EXPORT.ICONFLOATPOSITION", "Right")}; height:{cp.GetDataDefaultInt("EXPORT.ICONHEIGHT", 50)}' src='{neticon}.{pfmt}' alt='{rec.Tag}'>"); break;
                            }
                        }
                    }
                    else
                    {
                        //content.Append($"<img style='float:{cp.GetDataDefault("EXPORT.ICONFLOATPOSITION", "Right")}; height:{cp.GetDataDefaultInt("EXPORT.ICONHEIGHT", 50)};'  src='{alticon}' alt='{rec.Tag}'>");
                        content.Append($"<img style='float:{cp.GetDataDefault("EXPORT.ICONFLOATPOSITION", "Right")};' height='{cp.GetDataDefaultInt("EXPORT.ICONHEIGHT", 50)}' src='{alticon}' alt='{rec.Tag}'>");
                    }
                    content.Append($"{rec.Text}</div></td></tr>\n");
                    pcountdown--;
                    if (pcountdown <= 0)
                    {
                        pcountdown   = 200;
                        justnewpaged = true;
                        content.Append($"<tr><td colspan=3 align=center>{pageline}</td></tr>\n</table>\n\n");
                        QuickStream.SaveString($"{OutDir}/{cp.PrjName}_DevLog_Page_{page}.html", template.Replace("@CONTENT@", content.ToString()));
                        page++;
                        pageline = "";
                        for (int p = 1; p <= pages; p++)
                        {
                            if (page == p)
                            {
                                pageline += $"<big><big>{p}</big></big> ";
                            }
                            else
                            {
                                pageline += $"<a href='{cp.PrjName}_DevLog_Page_{p}.html'>{p}</a> ";
                            }
                        }
                        content = new System.Text.StringBuilder($"<table style=\"width:{cp.GetDataDefaultInt("EXPORT.TABLEWIDTH", 1200)}\">\n");
                        content.Append($"<tr><td colspan=3 align=center>{pageline}</td></tr>\n");
                    }
                }
            }
            if (!justnewpaged)
            {
                content.Append($"<tr><td colspan=3 align=center>{pageline}</td></tr>\n</table>");
                QuickStream.SaveString($"{OutDir}/{cp.PrjName}_DevLog_Page_{page}.html", template.Replace("@CONTENT@", content.ToString()));
            }
            GUI.WriteLn(" Done");
            Console.WriteLine(" GENERATED");
        }
Ejemplo n.º 11
0
        internal Source(string file)
        {
            if (!File.Exists(file))
            {
                WASM_Main.CRASH($"File '{file}' has not been found!");
            }
            var fpath = qstr.ExtractDir(file).Replace("\\", "/");

            try {
                var src    = new List <Line>();
                var rawsrc = QuickStream.LoadString(file);
                if (rawsrc.IndexOf('\r') >= 0)
                {
                    WASM_Main.WARN("<CR> characters found in source! Please deliver source in <LF> only format!"); rawsrc = rawsrc.Replace("\r", "");
                }
                var srcl = rawsrc.Split('\n');
                for (int i = 0; i < srcl.Length; i++)
                {
                    srcl[i] = srcl[i].Trim();
                    if (qstr.Left(srcl[i].ToUpper(), 8) == "INCLUDE ")
                    {
                        var    f   = srcl[i].Substring(8).Trim().Replace('\\', '/');
                        string ult = "";
                        if (IncPath.Count == 0)
                        {
                            if (fpath != "")
                            {
                                IncPath.Add(fpath);
                            }
                            else
                            {
                                IncPath.Add(".");
                            }
                        }

                        if (f[0] == '/' || f[1] == ':')
                        {
                            ult = f;
                        }
                        else
                        {
                            foreach (string p in IncPath)
                            {
                                var test = $"{p}/{f}";
                                if (File.Exists(test))
                                {
                                    ult = test; break;
                                }
                            }
                            if (ult == "")
                            {
                                WASM_Main.CRASH($"No path provided a way to find requested include file {f}");
                            }
                        }
                        WASM_Main.VP($" Including: {ult}");
                        var Sub = new Source(ult);
                        foreach (Line L in Sub.Lines)
                        {
                            src.Add(L);
                        }
                    }
                    else if (qstr.Prefixed(srcl[i], ";"))
                    {
                        System.Diagnostics.Debug.WriteLine($"Skipping comment: {srcl[i]}");
                    }
                    else if (srcl[i] == "")
                    {
                        System.Diagnostics.Debug.WriteLine($"Skipping whiteline {i+1}");
                    }
                    else
                    {
                        src.Add(new Line(srcl[i], file, i + 1));
                    }
                }
                Lines = src.ToArray();
            } catch (Exception e) {
                WASM_Main.CRASH(e);
            }
        }