예제 #1
0
        static void Main(string[] args)
        {
            Source.Hello();
            Compile.Hello();
            Dirry.InitAltDrives();
            Instruction.Init();
            MKL.Version("Wendicka Project - WASM_Main.cs", "20.03.01");
            MKL.Lic("Wendicka Project - WASM_Main.cs", "GNU General Public License 3");
            Console.WriteLine($"Wendicka Assembler {MKL.Newest} - (c) {MKL.CYear(2020)} Jeroen P. Broks\n");
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: WASM [options] <File>");
                TrickyDebug.AttachWait();
                return;
            }
            var parse = new FlagParse(args);

            parse.CrBool("s", false);
            parse.Parse();
            Silence = parse.GetBool("s");
            foreach (string f in parse.Args)
            {
                Compile.Go(Dirry.AD(f).Replace("\\", "/"));
            }
            Console.WriteLine($"\tErrors: {Errors}; Warnings: {Warnings}");
            TrickyDebug.AttachWait();
        }
예제 #2
0
 void RunMain()
 {
     if (fp.GetBool("h"))
     {
         HelpScreen();
         TrickyDebug.AttachWait();
         return;
     }
 }
예제 #3
0
        void Show(TJCRDIR jcr, string entry, FlagParse fp)
        {
            QCol.Doing("Reading", entry);
            var kind      = "OTHER";
            var highlight = !fp.GetBool("nsh");
            var linenums  = !fp.GetBool("nln");
            var istext    = !fp.GetBool("b");
            var src       = jcr.LoadString(entry);

            if (JCR6.JERROR != "")
            {
                QCol.QuickError(JCR6.JERROR);
                return;
            }
            if (istext)
            {
                var i = src.IndexOf((char)26);
                if (i >= 0)
                {
                    src = src.Substring(0, i);
                }
            }
            if (highlight)
            {
                var ext = qstr.ExtractExt(entry).ToLower();
                if (KittyHigh.Langs.ContainsKey(ext))
                {
                    kind = ext;
                }
                else if (ext == "bubbleproject")
                {
                    kind = "gini";
                }
            }
            var Viewer = KittyHigh.Langs[kind];

            QCol.Doing("Language", Viewer.Language);
            Console.WriteLine();
            Viewer.Show(src, linenums);
        }
예제 #4
0
파일: F_Extract.cs 프로젝트: jcr6/NJCR
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length == 1 || fp.GetBool("h"))
            {
                QCol.Green("Extract files from a JCR file! Available switches are:\n\n");
                QCol.Yellow("-nx             "); QCol.Cyan("No eXternals. This means that any file imported from external JCR files will be ignored\n");
                QCol.Yellow("-ow             "); QCol.Cyan("Overwrite existing files\n");
                QCol.Yellow("-nodir          "); QCol.Cyan("Remove paths from file names\n");
                QCol.Yellow("-nac            "); QCol.Cyan("No auto-creation of new directories if needed\n");
                QCol.Yellow("-output <path>  "); QCol.Cyan("Define output path\n");
                QCol.Magenta("\n\nWhat is important to note is that JCR6 was never set up as a real archiver like ZIP, RAR and 7z.\nIt has therefore features that ZIP, RAR, 7z nor any other archiver has.\n\nIt also lacks features the others have.\n\nExtracting was never a full feature of JCR6, but was rather added for completeness sake.\nExtracting files from it can therefore have some funny results.\n\n");
                return;
            }
            var nx         = fp.GetBool("nx");
            var ow         = fp.GetBool("ow");
            var nodir      = fp.GetBool("nodir");
            var autocreate = fp.GetBool("nac");
            var outdir     = fp.GetString("output");

            if (outdir != "")
            {
                outdir = outdir.Replace("\\", "/");
                if (!qstr.Suffixed(outdir, "/"))
                {
                    outdir += "/";
                }
            }
            QCol.Doing("Reading", fp.Args[1]);
            var jcr = JCR6.Dir(fp.Args[1]);

            if (JCR6.JERROR != "")
            {
                QCol.QuickError($"JCR6 Error: {JCR6.JERROR}");
                return;
            }
            try {
                var skipreason = "";
                var allow      = true;
                var offsets    = new Dictionary <string, List <TJCREntry> >();
                var alias      = aliashanding.Ignore;
                void skip(string reason)
                {
                    if (skipreason != "")
                    {
                        skipreason += "; ";
                    }
                    skipreason += reason;
                    allow       = false;
                }
                var shared = false;
                foreach (TJCREntry Ent in jcr.Entries.Values)
                {
                    var tag = $"{Ent.MainFile}:{Ent.Offset}";
                    if (!offsets.ContainsKey(tag))
                    {
                        offsets[tag] = new List <TJCREntry>();
                    }
                    else
                    {
                        shared = true;
                    }
                    offsets[tag].Add(Ent);
                }
                if (shared)
                {
                    Console.Beep();
                    QCol.Red("\n\nWARNING!\n");
                    QCol.Yellow("This resource has some shared-references or aliases as they are properly called in JCR6.\n");
                    QCol.Yellow("Extracting from this file can therefore create tons of duplicate files, as JCR6 cannot tell which entry is more relevant than others.\n");
                    QCol.Yellow("It's strongly recommended to extract files from this resource unless you are sure about what you are doing and what the consequences are and how to deal with them\n");
                    QCol.Cyan("1 = Continue, but ask about any files that has aliases, what to do with them\n");
                    QCol.Cyan("2 = Continue, but skip all files with aliases\n");
                    QCol.Cyan("3 = Continue, and just let the duplicate files come, I don't fear them!\n");
                    QCol.Cyan("Q = Cancel this operation\n");
                    QCol.Magenta("What do you want to do? "); QCol.Green("");
                    {
                        var loop = true;
                        do
                        {
                            var ch = Console.ReadKey();
                            switch (ch.KeyChar)
                            {
                            case '1': alias = aliashanding.Ask; loop = false; break;

                            case '2': alias = aliashanding.Skip; loop = false; break;

                            case '3': alias = aliashanding.Ignore; loop = false; break;

                            case 'q':
                            case 'Q': return;
                            }
                        } while (loop);
                        Console.WriteLine($" -- {alias}");
                    }
                }
                foreach (TJCREntry Ent in jcr.Entries.Values)
                {
                    allow      = true;
                    skipreason = "";
                    // can we do this?
                    var source = Ent.Entry;
                    var target = Ent.Entry;
                    var tag    = $"{Ent.MainFile}:{Ent.Offset}";
                    if (!JCR6.CompDrivers.ContainsKey(Ent.Storage))
                    {
                        skip($"Unknown compression method ({Ent.Storage})");
                    }
                    if (offsets[tag].Count > 1)
                    {
                        switch (alias)
                        {
                        case aliashanding.Skip: skip($"Offset reference as {offsets[tag].Count} entries, and system has been set to skip those"); break;

                        case aliashanding.Ask: {
                            Console.Beep();
                            QCol.Red($"Entry {Ent.Entry} has been aliased.\n");
                            foreach (TJCREntry aliasentry in offsets[tag])
                            {
                                QCol.Magenta("= "); QCol.Cyan($"{aliasentry.Entry}\n");
                            }
                            QCol.Green("Extract ? <Y/N> ");
                            do
                            {
                                var d = Console.ReadKey().KeyChar;
                                if (d == 'Y' || d == 'y')
                                {
                                    break;
                                }
                                if (d == 'N' || d == 'n')
                                {
                                    skip("User decided not to extract"); break;
                                }
                            } while (true);
                            Console.Write("\r");
                            break;
                        }
                        }
                    }
                    if (Ent.MainFile != fp.Args[1] && nx)
                    {
                        skip("No Externals");
                    }
                    if (nodir)
                    {
                        target = qstr.StripDir(target);
                    }
                    target = $"{outdir}{target}";
                    if (!Directory.Exists(qstr.ExtractDir(target)) && !autocreate)
                    {
                        Console.Beep();
                        QCol.Red($"{target}! ");
                        QCol.Yellow($"Create directory {qstr.ExtractDir(target)} ? <Y/N> ");
                        do
                        {
                            var d = Console.ReadKey().KeyChar;
                            if (d == 'Y' || d == 'y')
                            {
                                break;
                            }
                            if (d == 'N' || d == 'n')
                            {
                                skip("User decided not to extract"); break;
                            }
                        } while (true);
                        Console.Write("\n");
                    }
                    if (File.Exists(target) && (!ow))
                    {
                        Console.Beep();
                        QCol.Red($"{target} exists! ");
                        QCol.Yellow($"Overwrite ? <Y/N> ");
                        do
                        {
                            var d = Console.ReadKey().KeyChar;
                            if (d == 'Y' || d == 'y')
                            {
                                break;
                            }
                            if (d == 'N' || d == 'n')
                            {
                                skip("User decided not to extract"); break;
                            }
                        } while (true);
                        Console.Write("\n");
                    }
                    if (allow)
                    {
                        QCol.Doing("Extracting", target, "\r");
                        Directory.CreateDirectory(qstr.ExtractDir(target));
                        var b = jcr.JCR_B(source);
                        QuickStream.SaveBytes(target, b);
                        QCol.Doing(" Extracted", target);
                    }
                    else
                    {
                        QCol.Doing("   Skipped", target, "\t"); QCol.Red($"{skipreason}\n");
                    }
                }
            } catch (Exception e) {
                QCol.QuickError($".NET Error: {e.Message}");
#if DEBUG
                QCol.Magenta(e.StackTrace);
#endif
            }
        }
예제 #5
0
        public override void Run(FlagParse fp)
        {
            var ShowXStuff = fp.GetBool("x");
            var ShowAlias  = fp.GetBool("a");
            var ShowAllDat = fp.GetBool("xd");

            if (fp.Args.Length == 1)
            {
                QCol.Green("Verboses the files in a JCR resource:\n\n");
                QCol.Yellow("-x              "); QCol.Cyan("Show notes and author (if available)\n");
                QCol.Yellow("-a              "); QCol.Cyan("List out all aliases");
                QCol.Yellow("-xd             "); QCol.Cyan("Show all entry variable settings");
                return;
            }
            if (fp.Args.Length > 2)
            {
                QCol.QuickError("Only ONE file please!");
                return;
            }
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            { // Resources
                var ResCount = new TMap <string, int>();
                var CmpCount = new TMap <string, int>();
                foreach (TJCREntry ent in jcr.Entries.Values)
                {
                    ResCount[ent.MainFile]++;
                    CmpCount[ent.Storage]++;
                }
                XPrint(15, ConsoleColor.White, "Type");
                XPrint(9, ConsoleColor.White, "Entries", Just.Right);
                XPrint(10, ConsoleColor.White, " Resource:"); Console.WriteLine();
                XPrint(15, ConsoleColor.White, "====");
                XPrint(9, ConsoleColor.White, " =======", Just.Right);
                XPrint(10, ConsoleColor.White, " ========="); Console.WriteLine();
                foreach (string k in ResCount.Keys)
                {
                    var rec = JCR6.Recognize(k);
                    if (rec != "NONE")
                    {
                        XPrint(15, ConsoleColor.Blue, JCR6.FileDrivers[rec].name);
                        XPrint(9, ConsoleColor.Cyan, ResCount[k]);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine($" {k}");
                    }
                }
                Console.WriteLine();
                XPrint(20, ConsoleColor.White, "Storage Method");
                XPrint(10, ConsoleColor.White, "Used", Just.Right); Console.WriteLine();
                XPrint(20, ConsoleColor.White, "==============");
                XPrint(10, ConsoleColor.White, "====", Just.Right); Console.WriteLine();
                foreach (string k in CmpCount.Keys)
                {
                    XPrint(20, ConsoleColor.Blue, k);
                    XPrint(10, ConsoleColor.Cyan, CmpCount[k], Just.Right);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            // Comments
            foreach (string name in jcr.Comments.Keys)
            {
                QCol.White($"{name}\n");
                for (int i = 0; i < name.Length; i++)
                {
                    QCol.White("=");
                }
                QCol.Yellow($"\n{jcr.Comments[name]}\n\n");
            }
            // Blocks (if any)
            //if (jcr.Blocks.Count>0) {
            bool bfirst = true;

            foreach (var B in jcr.Blocks.Values)
            {
                if (bfirst)
                {
                    bfirst = false;
                    Console.WriteLine();
                    XPrint(5, ConsoleColor.White, "Block", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "Compressed", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "Size", Just.Right); WhiteSpace(2);
                    XPrint(5, ConsoleColor.White, "Ratio", Just.Right); WhiteSpace(2);
                    XPrint(7, ConsoleColor.White, "Storage"); Console.WriteLine();
                    XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "==========", Just.Right); WhiteSpace(2);
                    XPrint(10, ConsoleColor.White, "====", Just.Right); WhiteSpace(2);
                    XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
                    XPrint(7, ConsoleColor.White, "======="); Console.WriteLine();
                }
                XPrint(5, ConsoleColor.Blue, B.ID); WhiteSpace(2);
                XPrint(10, ConsoleColor.Green, B.CompressedSize); WhiteSpace(2);
                XPrint(10, ConsoleColor.Red, B.Size); WhiteSpace(2);
                XPrint(5, ConsoleColor.Magenta, $"{B.Ratio}%", Just.Right); WhiteSpace(2);
                XPrint(7, ConsoleColor.Yellow, B.Storage); Console.WriteLine();
            }
            //foreach (var BK in jcr.Blocks.Keys) Console.WriteLine(BK);

            //}
            // Entries
            Console.WriteLine();
            XPrint(15, ConsoleColor.White, "Kind"); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "Compressed", Just.Right); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "Size", Just.Right); WhiteSpace(2);
            XPrint(5, ConsoleColor.White, "Ratio", Just.Right); WhiteSpace(2);
            XPrint(7, ConsoleColor.White, "Storage"); WhiteSpace(2);
            Console.WriteLine("Entry");
            XPrint(15, ConsoleColor.White, "===="); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "==========", Just.Right); WhiteSpace(2);
            XPrint(10, ConsoleColor.White, "====", Just.Right); WhiteSpace(2);
            XPrint(5, ConsoleColor.White, "=====", Just.Right); WhiteSpace(2);
            XPrint(7, ConsoleColor.White, "======="); WhiteSpace(2);
            Console.WriteLine("=====");
            foreach (TJCREntry ent in jcr.Entries.Values)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                if (ent.MainFile != fp.Args                    [1].Replace("\\", "/"))
                {
                    Console.BackgroundColor = ConsoleColor.DarkBlue;
                }
                XPrint(15, ConsoleColor.Blue, FTypes[qstr.ExtractExt(ent.Entry).ToLower()]); WhiteSpace(2);
                if (ent.Block == 0)
                {
                    XPrint(10, ConsoleColor.Green, ent.CompressedSize);
                }
                else
                {
                    XPrint(10, ConsoleColor.DarkGreen, $"Block: {ent.Block}");
                }
                WhiteSpace(2);
                XPrint(10, ConsoleColor.Red, ent.Size); WhiteSpace(2);
                if (ent.Block == 0)
                {
                    XPrint(5, ConsoleColor.Magenta, ent.Ratio, Just.Right);
                }
                else
                {
                    XPrint(5, ConsoleColor.Magenta, "");
                } WhiteSpace(2);
                XPrint(7, ConsoleColor.Yellow, ent.Storage); WhiteSpace(2);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(ent.Entry);
                if (ShowXStuff)
                {
                    if (ent.Author != "")
                    {
                        QCol.Doing("\tAuthor", ent.Author);
                    }
                    if (ent.Notes != "")
                    {
                        QCol.Green($"{ent.Notes}\n");
                    }
                }
                if (ShowAlias)
                {
                    foreach (string AlFile in jcr.Aliases(ent))
                    {
                        QCol.Doing("\tAlias", AlFile);
                    }
                }
                if (ShowAllDat)
                {
                    foreach (string k in ent.databool.Keys)
                    {
                        QCol.Magenta("\tbool   "); QCol.Yellow(k); QCol.White(" = "); if (ent.databool[k])
                        {
                            QCol.Green("True\n");
                        }
                        else
                        {
                            QCol.Red("False\n");
                        }
                    }
                    foreach (string k in ent.datastring.Keys)
                    {
                        QCol.Magenta("\tstring "); QCol.Yellow(k); QCol.White(" = "); QCol.Green($"\"{ent.datastring[k]}\"\n");
                    }
                    foreach (string k in ent.dataint.Keys)
                    {
                        QCol.Magenta("\tint    "); QCol.Yellow(k); QCol.White(" = "); QCol.Cyan($"{ent.dataint[k]}\n");
                    }
                }
            }
        }
예제 #6
0
파일: F_Add.cs 프로젝트: jcr6/NJCR
 public override void Run(FlagParse fp)
 {
     if (fp.Args.Length == 1 || fp.GetBool("h"))
     {
         QCol.Green("Add files to a JCR file! Available switches are:\n\n");
         QCol.Yellow("-doj             "); QCol.Cyan("Destroy original JCR file, so begin completely fresh, always\n");
         QCol.Yellow("-i               "); QCol.Cyan("Input file(s) or directory/directories. (deprecated)\n");
         QCol.Yellow("-cm <method>     "); QCol.Cyan("Compression method for the files inside the JCR file (default is lzma)\n");
         QCol.Yellow("-fc <method>     "); QCol.Cyan("Compression method for the file table inside the JCR file (default is lzma)\n");
         QCol.Yellow("-jif <file>      "); QCol.Cyan("Read a JCR Instruction File to see how files must be stored and under which conditions\n");
         QCol.Yellow("-author <author> "); QCol.Cyan("Add an author to the files added (jif files ignore this flag)\n");
         QCol.Yellow("-notes <notes>   "); QCol.Cyan("Add notes to the files added (jif files ignore this flag)\n");
         QCol.Yellow("-nomerge         "); QCol.Cyan("When set, files detected as JCR6 compatible files will not be merged, but just be addd as a regular file!\n");
         QCol.Yellow("-puremerge       "); QCol.Cyan("When set, entries being added due to JCR-merging will not be repacked, but be directly copied\n");
         QCol.Yellow("                 "); QCol.Magenta("It goes without saying, but using -nomerge and -puremerge in one run is not a very clever thing to do.");
         //QCol.Yellow("-qu              "); QCol.Cyan("Quick update. (Type \"NJCR quhelp\" for more information)\n");
         QCol.Blue("\n\n\n");
         QCol.Green("JCR6 supports the next compression methods:\n");
         foreach (string name in JCR6.CompDrivers.Keys)
         {
             QCol.Red("\t* "); QCol.Yellow($"{name}\n");
         }
         return;
     }
     quick   = fp.GetBool("qu");
     jcrfile = fp.Args[1];
     toadd   = Files(fp);
     filetablecompression = fp.GetString("fc");
     compressionmethod    = fp.GetString("cm");
     puremerge            = fp.GetBool("puremerge");
     nomerge = fp.GetBool("nomerge");
     if (fp.GetString("i") != "")
     {
         var l = new List <string>(toadd);
         l.Add(fp.GetString("i"));
         toadd = l.ToArray();
     }
     updating = File.Exists(jcrfile) && !fp.GetBool("doj");
     if (toadd.Length == 0)
     {
         Add2List(Directory.GetCurrentDirectory(), "", compressionmethod, fp.GetString("author"), fp.GetString("notes"));
     }
     else
     {
         foreach (string fil in toadd)
         {
             Add2List(fil, qstr.StripDir(fil), compressionmethod, fp.GetString("author"), fp.GetString("notes"));
         }
     }
     if (fp.GetString("jif") != "")
     {
         ParseJIF(fp.GetString("jif"));
     }
     if (updating)
     {
         QCol.Doing("Updating", jcrfile);
     }
     else
     {
         QCol.Doing("Creating", jcrfile);
     }
     QCol.Doing("File Storage", compressionmethod);
     QCol.Doing("Table Storage", filetablecompression);
     QCol.Doing("No merge", $"{nomerge}");
     QCol.Doing("Pure merge", $"{puremerge}");
     QCol.Doing("Files", $"{Jiffy.Count}");
     QCol.Doing("NJCR", MKL.MyExe);
     QCol.Doing("PWD", Directory.GetCurrentDirectory());
     Console.WriteLine("\n\n");
     Go();
 }
예제 #7
0
 private static void InitArgs()
 {
     JCR6_lzma.Init();
     MyArgs.CrBool("version", false);
     MyArgs.CrBool("help", false);
     MyArgs.CrBool("h", false);
     if (!MyArgs.Parse(true))
     {
         throw new Exception("Invalid input");
     }
     if (MyArgs.GetBool("version"))
     {
         Head();
         Console.WriteLine(MKL.All(true));
         Environment.Exit(0);
     }
     if (MyArgs.GetBool("h") || MyArgs.GetBool("help"))
     {
         Head();
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.Write("MKL_Update ");
         Console.ForegroundColor = ConsoleColor.Yellow;
         Console.WriteLine("[<dir1> [<dir2> [<dir3>....]]]");
         Console.ForegroundColor = ConsoleColor.Gray;
         Console.WriteLine("\tUpdates the MKL data and license blocks in given directories. If none given, the current directory will be done");
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.Write("MKL_Update ");
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine("-h");
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.Write("MKL_Update ");
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine("-help");
         Console.ForegroundColor = ConsoleColor.Gray;
         Console.WriteLine("\tShows this help text");
         Console.ForegroundColor = ConsoleColor.Cyan;
         Console.Write("MKL_Update ");
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine("-version");
         Console.ForegroundColor = ConsoleColor.Gray;
         Console.WriteLine("\tShows detailed version information");
         Console.WriteLine("\n\n\nThe next programming languages are supported by MKL_Update");
         foreach (string k in JCR.Entries.Keys)
         {
             if (qstr.Prefixed(k, "EXT/"))
             {
                 TGINI T = GINI.ReadFromLines(JCR.ReadLines(k));
                 // Console.WriteLine($"{k} => {qstr.Prefixed(k, "EXT/")}"); // debug line
                 Console.ForegroundColor = ConsoleColor.Yellow;
                 Console.BackgroundColor = ConsoleColor.Blue;
                 Console.Write(k.ToLower());
                 for (int i = k.Length; i < 30; i++)
                 {
                     Console.Write(" ");
                 }
                 Console.BackgroundColor = ConsoleColor.Black;
                 Console.ForegroundColor = ConsoleColor.Magenta;
                 Console.WriteLine($" {T.C("LANGUAGE")}");
             }
         }
         Console.ResetColor();
         Environment.Exit(0);
     }
 }