Ejemplo n.º 1
0
 bool GetGINI()
 {
     if (File.Exists(qstr.RemSuffix(GINIFile, ".gini") + ".ini"))
     {
         Console.Beep();
         Console.WriteLine("Renaming old ini file to GINI!");
         File.Move(qstr.RemSuffix(GINIFile, ".gini") + ".ini", GINIFile);
     }
     if (!File.Exists(GINIFile))
     {
         for (int i = 0; i < 10; i++)
         {
             Console.Beep(2000, 1000);
             Console.Beep(1000, 1000);
         }
         Console.WriteLine("This directory has not been initized as a MKL based project!");
         Console.Write("Do you want it to be a MKL based project ? <Y/N> ");
         if (Console.ReadLine().ToUpper() != "Y")
         {
             return(false);
         }
         QuickStream.SaveString(GINIFile, "[rem]\nVoid Dark(){ cprintf(\"Void the darkness\"); }\n");
     }
     Data = GINI.ReadFromFile(GINIFile);
     Data.CL("KNOWN");
     Data.CL("SKIPFILE");
     Data.CL("SKIPDIR");
     Ask("Project", dir, "Please name the project: ");
     return(true);
 }
Ejemplo n.º 2
0
        public override byte[] Expand(byte[] inputbuffer, int realsize)
        {
            byte[]      ret = new byte[realsize];
            int         pos = 0;
            QuickStream bi  = QuickStream.StreamFromBytes(inputbuffer);

            bi.ReadByte(); // First byte had to be ignored... A little issue that came up in the first draft... silly me!
            while (!bi.EOF)
            {
                byte xbyte = bi.ReadByte();
                byte xkeer = bi.ReadByte();
                for (byte i = 0; i < xkeer; ++i)
                {
                    if (pos >= realsize)
                    {
                        JCR6.JERROR = $"JXSRCCA: Pos {i} expanded over the realsize length {pos}/{realsize}. Is this entry corrupted?";
                        System.Console.WriteLine("ERROR! " + JCR6.JERROR);
                        bi.Close();
                        return(null);
                    }
                    //System.Console.Write(qstr.Chr(xbyte));
                    ret[pos] = xbyte;
                    pos++;
                }
            }
            bi.Close();
            return(ret);
        }
Ejemplo n.º 3
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.º 4
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.º 5
0
        static public void View(string file, string showme)
        {
            if (HexViewer.IsBinary(showme))
            {
                HexViewer.View(showme, file);
                return;
            }
            if (!InitDone)
            {
                Init();
            }
            Debug.WriteLine("Setting up view");
            var KV   = new KittyViewer();
            var ext  = qstr.ExtractExt(file).ToLower();
            var odir = Core.Config[Core.Platform, "VIEWSWAP"];

            Debug.WriteLine("Linking to Kitty");
            KittyHigh.Console = (KittyOutput)KV;
            if (KittyHigh.Langs.ContainsKey(ext))
            {
                KittyHigh.Langs[ext].Show(showme, LineNumbers);
            }
            else
            {
                KittyHigh.Langs["OTHER"].Show(showme, LineNumbers);
            }
            Directory.CreateDirectory(odir);
            QuickStream.SaveString($"{odir}/ViewFile.html", KV.ToString());
        }
Ejemplo n.º 6
0
 public API(Lua State, string Script)
 {
     this.State  = State;
     this.Script = Script;
     this.State["LuaQuickNeil"] = this;
     this.State.DoString($"Neil.Load([[{QuickStream.StringFromEmbed("QuickNeil.Neil")}]],\"QuickNeil API Linkup\")()", "QuickNeil API Linkup from C#");
 }
Ejemplo n.º 7
0
        public override bool Recognize(string file)
        {
            QuickStream BT = null;

            try {
                //Console.WriteLine($"JQL Recognize {File.Exists(file)}");
                if (!File.Exists(file))
                {
                    return(false);
                }
                BT = QuickStream.ReadFile(file);
                string s;
                do
                {
                    s = RL(BT);
                    //Console.WriteLine($"_{s}_");
                    if (s != "" && (!qstr.Prefixed(s, "#")))
                    {
                        return(s == "JQL");
                    }
                } while (!BT.EOF);
                return(false);
            } finally {
                if (BT != null)
                {
                    BT.Close();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the content of a JCR6 resource entry.
        /// </summary>
        /// <returns>The contents of the entry in a byte array</returns>
        /// <param name="entry">The entry name (case insensitive)</param>
        public byte[] JCR_B(string entry)
        {
            JCR6.JERROR = "";
            var ce = entry.ToUpper();

            if (!Entries.ContainsKey(ce))
            {
                JCR6.JERROR = "Resource does not appear to contain an entry called: " + entry; return(null);
            }
            var e = Entries[ce];

            byte[] cbuf;
            byte[] ubuf;
            var    bt = QuickStream.ReadFile(e.MainFile);

            bt.Position = e.Offset;
            cbuf        = bt.ReadBytes(e.CompressedSize);
            bt.Close();
            if (!JCR6.CompDrivers.ContainsKey(e.Storage))
            {
                JCR6.JERROR = "Entry \"" + entry + "\" has been packed with the unsupported \"" + e.Storage + "\" algorithm"; return(null);
            }
            ubuf = JCR6.CompDrivers[e.Storage].Expand(cbuf, e.Size);
            return(ubuf);
        }
Ejemplo n.º 9
0
        public override void Run(FlagParse fp)
        {
            if (fp.Args.Length < 2)
            {
                QCol.Green("This feature allows you to show the content of a certain file.\n");
                QCol.Green("In order to do this, some additional configuration will be needed, as well as knowledge of the file system you are using.\n");
                QCol.Green("Don't worry about having to set up this file, manually. You will be prompted whenever NJCR requires more information.\n");
                QCol.Green($"The configuration can lateron be edited with your favority text editor (as long as it supports Unix LF line ends), as it will be saved as {ShowConfig}");
                return;
            }
            QCol.Doing("Reading JCR", fp.Args[1].Replace("\\", "/"));
            var jcr = JCR6.Dir(fp.Args[1]);

            if (jcr == null)
            {
                QCol.QuickError(JCR6.JERROR); return;
            }
            if (!File.Exists(ShowConfig))
            {
                QuickStream.SaveString(ShowConfig, "[rem]\nNothint to see here yet\n");
            }
            Config = GINI.ReadFromFile(ShowConfig);
            Ask("Temp.Dir", "I am in need of a temp-directory.\nYou can pick any directory you want for this, and the system will try to create the desired directory if it doesn't yet exist.\nThe files to show will be temporarily stored here, and IT'S VERY IMPORTANT THAT THIS DIRECTORY IS ONLY USED FOR THIS PURPOSE!!!", "Temp Folder");
            QCol.Doing("Temp dir", TempFolder);
            Directory.CreateDirectory(TempFolder);
            for (int i = 2; i < fp.Args.Length; i++)
            {
                Show(jcr, fp.Args[i]);
            }
        }
Ejemplo n.º 10
0
        static public void ViewImg(byte[] Buffer, string File)
        {
            var ext = qstr.ExtractExt(File).ToLower();

            QuickStream.SaveBytes($"{Core.ViewSwap}/Image.{ext}", Buffer);
            QuickStream.SaveString($"{Core.ViewSwap}/ViewFile.html", HTMLTemplate.Replace("<HEADER>", $"Viewing: {File}").Replace("<URI>", $"{Core.ViewSwap}/Image.{ext}"));
        }
Ejemplo n.º 11
0
        void UpdateMe()
        {
            if (!DoUpdate)
            {
                return;
            }
            var newindex = new dvIndex();

            newindex.id = RecID;
            var bt    = new QuickStream(System.IO.File.OpenWrite($"{project.PrjFile}.Content"));          // Does this append?
            var start = bt.Size;

            bt.Position = bt.Size;
            foreach (string k in core.Keys)
            {
                bt.WriteByte(0);
                bt.WriteString(k);
                bt.WriteString(core[k]);
            }
            var einde = bt.Position;

            bt.Close();
            newindex.size          = einde - start;
            newindex.offset        = start;
            project.Indexes[RecID] = newindex;
            project.SaveIndexes();
        }
Ejemplo n.º 12
0
        string RL(QuickStream BT, bool trim = true)
        {
            var  r = new StringBuilder();
            byte b = 0;

            while (true)
            {
                if (BT.EOF)
                {
                    break;
                }
                b = BT.ReadByte();
                if (b == 10)
                {
                    break;
                }
                if (b != 13)
                {
                    r.Append((char)b);
                }
            }
            if (trim)
            {
                return(r.ToString().Trim());
            }
            return(r.ToString());
        }
Ejemplo n.º 13
0
        public Bubble_Audio(string s)
        {
            var state  = SBubble.State(s).state;
            var script = QuickStream.StringFromEmbed("Audio.nil");

            state["Bubble_Audio"] = this;
            SBubble.DoNIL(s, script, "Audio init script");
        }
Ejemplo n.º 14
0
        private Bubble_Input(string state)
        {
            var script = QuickStream.StringFromEmbed("Input.lua");

            SBubble.State(state).state["Bubble_Input"] = this;
            SBubble.DoNIL(state, "#macro MouseLeft 1\n#macro MouseRight 2\n#macro MouseCenter 3", "Mouse Button macros");
            SBubble.State(state).DoString(script, "Input API header");
        }
Ejemplo n.º 15
0
        private APIFlow(string state)
        {
            State = state;
            var s = SBubble.State(state).state;

            s["Bubble_Flow"] = this;
            SBubble.State(state).DoString(QuickStream.StringFromEmbed("Flow.lua"), "Flow Management");
        }
Ejemplo n.º 16
0
 public string LoadString(string file)
 {
     if (!FileExists(file))
     {
         return("");
     }
     return(QuickStream.LoadString(file));
 }
Ejemplo n.º 17
0
        static public void API_Init(string namestate)
        {
            var ret    = new MapScriptAPI();
            var state  = SBubble.State(namestate).state;
            var script = QuickStream.StringFromEmbed("MapScriptAPI.nil");

            state["NALAMSAPI"] = ret;
            SBubble.DoNIL(namestate, script, "MapScript init script");
        }
Ejemplo n.º 18
0
        static public void Init(string state)
        {
            me = new RPG_API();
            var script = QuickStream.StringFromEmbed("RPG_API.nil");

            SBubble.State(state).state["NALA_RPG"] = me;
            SBubble.DoNIL(state, script, "Link code RPG API");
            me.statename = state;
        }
Ejemplo n.º 19
0
 static QuickNeil()
 {
     QCol.Hello();
     Dirry.InitAltDrives();
     FileList.Hello();
     qstr.Hello();
     QuickStream.Hello();
     //Launch.Hello();
 }
Ejemplo n.º 20
0
        private void Butt_Extract_Click(object sender, RoutedEventArgs e)
        {
            if (DirBox.SelectedItem == null)
            {
                Debug.WriteLine("No item, so no extract"); return;
            }
            var item = (string)DirBox.SelectedItem; Debug.WriteLine($"Item: {item}"); if (item == "" || qstr.Suffixed(item, "/"))
            {
                Debug.WriteLine("Item is directory, so no extract"); return;
            }
            var xas = FFS.RequestFile(true); if (xas == "")
            {
                return;
            }
            var ix = qstr.ExtractExt(item).ToLower();
            var ex = qstr.ExtractExt(xas).ToLower();

            if (ix != ex)
            {
                switch (Confirm.YNC($"Original extention is \"{ix}\", and given extension is \"{ex}\". This does not match. Add this extension?"))
                {
                case -1:
                    return;

                case 0:
                    break;

                case 1:
                    xas += $".{ix}";
                    break;

                default:
                    throw new Exception("Invalid output from Confirm.YNC");
                }
            }
            if (Core.IN_Resource)
            {
                try {
                    var data = Core.JCR.JCR_B($"{Core.CDirectory}/{item}");
                    if (data == null)
                    {
                        throw new Exception($"Unable to get data!\nJCR6 reported: {JCR6.JERROR}");
                    }
                    QuickStream.SaveBytes(xas, data);
                } catch (Exception E) {
                    Confirm.Annoy(E.Message, "Error!", System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
            else
            {
                try {
                    File.Copy($"{Core.CDirectory}/{item}", xas, true);
                } catch (Exception E) {
                    Confirm.Annoy(E.Message, "Error!", System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 21
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.º 22
0
        /// <summary>
        /// Opens the file as a QuickStream. See the qstream.cs class file for more information about that.
        /// </summary>
        /// <returns>The QuickStream</returns>
        /// <param name="entry">>The entry name (case insensitive)</param>
        /// <param name="endian">QuickStream.LittleEndian or QuickStream.BigEndian for automatic endian conversion, if set to 0 it will just read endians by the way the CPU does it.</param>
        public QuickStream ReadFile(string entry, byte endian = QuickStream.LittleEndian)
        {
            var buf = JCR_B(entry);

            if (buf == null)
            {
                return(null);
            }
            return(QuickStream.StreamFromBytes(buf, endian));
        }
Ejemplo n.º 23
0
 public void DataWrite(QuickStream f)
 {
     foreach (string key in D.Keys)
     {
         f.WriteByte(0);
         f.WriteString(key);
         f.WriteString(D[key]);
         //Console.WriteLine($"Writing string {key} => {D[key]}");
     }
 }
Ejemplo n.º 24
0
        public static void Init(string s)
        {
            var state  = SBubble.State(s).state;
            var script = QuickStream.StringFromEmbed("Bubble_Conf.nil");

            state["Bubble_Conf"] = new Bubble_Conf();
            Debug.WriteLine($"Initiating state: {s}");
            BubConsole.CSay($"State \"{s}\" being prepared for Bubble_Conf");
            SBubble.DoNIL(s, script, "Message box init script");
        }
Ejemplo n.º 25
0
        public void AddFile(string OriginalFile, string Entry, string Storage = "Store", string Author = "", string Notes = "")
        {
            var rs  = QuickStream.ReadFile(OriginalFile);
            var buf = rs.ReadBytes((int)rs.Size);

            rs.Close();
            var ws = NewEntry(Entry, Storage, Author, Notes);

            ws.WriteBytes(buf);
            ws.Close();
        }
Ejemplo n.º 26
0
        //public byte[] buffer;


        public TJCRCreateStream(TJCRCreate theparent, string theentry, string thestorage, string theauthor = "", string thenotes = "", byte Endian = QuickStream.LittleEndian)
        {
            entry     = theentry;
            storage   = thestorage;
            author    = theauthor;
            notes     = thenotes;
            memstream = new MemoryStream();
            stream    = new QuickStream(memstream, Endian);
            parent    = theparent;
            parent.OpenEntries[this] = theentry;
        }
Ejemplo n.º 27
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.º 28
0
        static public void DrawText(string text, int x, int y)
        {
            var dx = x;
            var dy = y;

            for (int i = 0; i < text.Length; i++)
            {
                var b = (byte)text[i];
                if (b == 32)
                {
                    dx += fw;
                }
                else if (b == 10)
                {
                    dx  = x;
                    dy += fh;
                }
                else if (b > 32 && b < 127)
                {
                    if (!CharPics.ContainsKey(b))
                    {
                        var q = QuickStream.OpenEmbedded($"SysFont.{b}.png");
                        if (q != null)
                        {
                            CharPics[b] = TQMG.GetImage(q);
                            Debug.WriteLine($"Loaded character {b} => {text[i]}");
                        }
                    }
                    if (CharPics.ContainsKey(b))   // NO ELSE! That won't cause the desired effect
                    {
                        try {
                            var cp = CharPics[b];
                            cp.Draw(dx, dy);
                            if (fw < cp.Width)
                            {
                                fw = cp.Width;
                            }
                            if (fh < cp.Height)
                            {
                                fh = cp.Height;
                            }
                            dx += fw;
                            if (dx + fw > TQMG.ScrWidth)
                            {
                                dx  = x;
                                dy += fh;
                            }
                        } catch (Exception E) {
                            Debug.Print($"Caught: {E.Message}");
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        private BubbleGraphics(Lua state, string id)
        {
            var bt     = QuickStream.OpenEmbedded("Graphics.nil");
            var script = bt.ReadString((int)bt.Size);

            vm = id;
            bt.Close();
            state["BubbleGraphics"] = this;
            SBubble.DoNIL(id, script, "Graphics init script");
            SBubble.State(id).DoString("Color = SetColor", "HACKING!"); // Prevent confusion since the console's not really accesible anyway
        }
Ejemplo n.º 30
0
 public override bool Recognize(string file)
 {
     try {
         var ret = false;
         var bt  = QuickStream.ReadFile(file);
         ret = bt.ReadString(header.Length) == header;
         bt.Close();
         return(ret);
     } catch {
         return(false);
     }
 }