Exemple #1
0
        void GetJCR()
        {
            var f = new List <TJCREntry>();

            JCR = JCR6.Dir(Dirry.AD(args[1]));
            Assert(JCR, JCR6.JERROR);

            foreach (TJCREntry e in JCR.Entries.Values)
            {
                var ok = qstr.Suffixed(e.Entry.ToLower(), ".png");
                var p  = false;
                for (int i = 2; i < args.Length; i++)
                {
                    p = p || qstr.Prefixed(e.Entry.ToLower(), args[i].ToLower());
                }
                ok = (args.Length == 2 || p);
                if (ok)
                {
                    f.Add(e);
                }
            }
            Files = f.ToArray();
            TQMG.Init(graphics, GraphicsDevice, spriteBatch, JCR);
            JCRC = new TJCRCreate($"{qstr.StripExt(args[1])}.Negative.JCR");
        }
Exemple #2
0
        public static void PSave(Kthura map, string outfile, string prefix, string storage = "Store", string Author = "", string Notes = "")
        {
            var j = new TJCRCreate(outfile, storage);

            Save(map, j, prefix, storage, Author, Notes);
            j.Close();
        }
Exemple #3
0
        static void OnGoForIt(object sender, EventArgs e)
        {
            var outdir = Data["Project"].Text;
            var prj    = System.IO.Path.GetFileName(outdir);
            var langs  = Languages.Buffer.Text.Split('\n');
            var gini   = new TGINI();

            gini.D("Author", Data["Author"].Text);
            gini.D("Copyright", Data["Author"].Text);
            gini.D("Notes", Data["License"].Text);
            gini.D("License", Data["License"].Text);
            gini.D("lzma", "YES");
            var outt = "[rem]\nEmpty now\n[tags]\n\n[scenario]\n\n";
            var li   = 0;

            if (langs.Length < 1)
            {
                QuickGTK.Error("At least one language is required to do the job!"); return;
            }
            foreach (string flang in langs)
            {
                li++;
                Console.WriteLine($"Creating language #{li}: {flang}");
                var lang = flang.Trim(); gini.D($"Lang{li}.Name", lang);
                var outj = outdir + "/" + lang + ".jcr"; gini.D($"Lang{li}.File", outj);
                var jo   = new TJCRCreate(outj, "lzma");
                jo.AddString(outt, "BASICENTRY", "lzma", Data["Author"].Text, Data["License"].Text);
                jo.Close();
            }
            Console.WriteLine("Creating project GINI");
            gini.SaveSource(outdir + "/" + prj + ".scenlang.gini");
            QuickGTK.Info("Project has been created.\nYou can now use the regular ScenLang tool and open project file:\n\n" + outdir + "/" + prj + ".scenlang.gini");
            Application.Quit();
        }
        /// <summary>
        /// Saves a TeddyBear map. If you are not really well versed in how JCR6 works, you may only need the first two paramters, I only added the others so more advanced users can benefit from the true power of JCR6 ;)
        /// </summary>
        /// <param name="map"></param>
        /// <param name="jcr"></param>
        /// <param name="Entry"></param>
        /// <param name="Storage"></param>
        /// <param name="FileTableStorage"></param>
        static public string Save(TeddyMap map, string filename, string EntryPref = "", string Storage = "Store", string FileTableStorage = "Store")
        {
            var bt = new TJCRCreate(filename, FileTableStorage);
            var r  = Save(map, bt, EntryPref, Storage);

            bt.Close();
            return(r);
        }
Exemple #5
0
 public static void Save(Kthura map, TJCRCreate j, string prefix = "", string storage = "Store", string Author = "", string Notes = "")
 {
     if (Kthura.LoadUnknown)
     {
         foreach (var unk in map.Unknown)
         {
             System.Diagnostics.Debug.WriteLine($"Adding unknown {unk.Key} ({unk.Value.Length} bytes)");
             j.AddBytes(unk.Value, unk.Key, storage, Author, Notes);
         }
     }
     j.NewStringMap(map.MetaData, $"{prefix}Data", storage, Author, Notes);
     j.AddString(GenObjects(map), $"{prefix}Objects", storage, Author, Notes);
 }
Exemple #6
0
        void KthuraCheck(string map)
        {
            var mapfile  = $"{Old["Maps"]}/{map}";
            var modified = false;

            Print($"Checking Kthura map: {map}");
            Print($"= File: {mapfile}");
            var jd = JCR6.Dir(mapfile);

            foreach (var e in jd.Entries.Values)
            {
                if (e.Storage == "lzma")
                {
                    modified = true;
                    Print($"  = Entry {e.Entry} was packed with lzma, which is not (yet) supported in the new Kthura. So a repack is in order");
                }
            }
            if (modified)
            {
                //if (true) {
                Print("= Repacking in zlib");
                var ed = new SortedDictionary <string, byte[]>();
                foreach (var e in jd.Entries.Values)
                {
                    Print($"  = Reading: {e.Entry}");
                    ed[e.Entry] = jd.JCR_B(e.Entry);
                }
                var st = $"[IGNORECASE]\nLABELS=NO\nTAGS=NO\n\n[Save]\nStorage=zlib\n";
                ed["Options"] = new byte[st.Length];
                for (int i = 0; i < st.Length; ++i)
                {
                    ed["Options"][i] = (byte)st[i];
                }
                Print("= Saving new map");
                var jc = new TJCRCreate(mapfile, "zlib");
                foreach (var e in ed)
                {
                    Print($"  = Writing: {e.Key}");
                    jc.AddBytes(e.Value, e.Key, "zlib");
                }
                Print("= Finalizing");
                jc.Close();
            }
            else
            {
                Print("= Map appears to be in order. No changes needed!");
            }
        }
Exemple #7
0
        void Go()
        {
            string[] files;
            if (!GetGINI())
            {
                return;
            }
            List <string> sources = new List <string>();
            int           count   = 0;

            try {
                files = FileList.GetTree(dir);
                Directory.CreateDirectory($"{dir}/MKL_Backup");
            } catch (Exception e) {
                Error(e.Message);
                return;
            }
            Console.WriteLine("Re-arranging backups");
            if (File.Exists($"{dir}/MKL_Backup/10.JCR"))
            {
                File.Delete($"{dir}/MKL_Backup/10.JCR");
            }
            for (int i = 9; i > 0; i--)
            {
                if (File.Exists($"{dir}/MKL_Backup/{i}.JCR"))
                {
                    File.Move($"{dir}/MKL_Backup/{i}.JCR", $"{dir}/MKL_Backup/{i+1}.JCR");
                }
            }
            Console.WriteLine("Backing up source files");
            var jout = new TJCRCreate($"{dir}/MKL_Backup/1.JCR", "lzma");

            foreach (string f in files)
            {
                count++;
                if (count == f.Length || count % 50 == 0)
                {
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.Write($"{count}/{files.Length}\r");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
                var s = f.Split('.');
                if (s.Length > 0)
                {
                    var e = s[s.Length - 1];
#if DEBUG
                    Console.WriteLine($"DEBUG: {count}: {f} {e} {Ext.Contains(e.ToUpper())}");
#endif
                    if (Ext.Contains(e.ToUpper()))
                    {
                        sources.Add(f);
                        jout.AddFile($"{dir}/{f}", f, "lzma", "", "This is a backup created by MKL_Update");
                    }
                }
            }
            jout.Close();
            Console.WriteLine("Processing source files");
            foreach (string f in sources)
            {
                count++;
                if (count == f.Length || count % 50 == 0)
                {
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.Write($"{count}/{sources.Count}\r");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
                Look(f);
                count = 0;
            }
        }
Exemple #8
0
        public void Go()
        {
            // Create or update?
            TJCRCreate jout;
            var        temp = $"{qstr.ExtractDir(jcrfile)}/{qstr.md5($"{jcrfile}.{DateTime.Now.ToString()}")}.$jcr";
            TJCRDIR    jtmp = null;

            if (updating)
            {
                jout = new TJCRCreate(temp, filetablecompression, sig);
            }
            else
            {
                jout = new TJCRCreate(jcrfile, filetablecompression, sig);
            }
            if (jout == null || jout.mystream == null)
            {
                QCol.QuickError($"Error creating JCR file >> {JCR6.JERROR}");
                return;
            }


            // Add Comments
            foreach (string n in Comments.Keys)
            {
                QCol.Doing("Comment", n);
                jout.AddComment(n, Comments[n]);
            }

            // Add Dependencies
            foreach (var d in Imports)
            {
                QCol.Doing("Import", d);
                jout.Import(d);
            }
            foreach (var d in Requires)
            {
                QCol.Doing("Require", d);
                jout.Require(d);
            }



            // Add files
            foreach (Fil2Add aFile in Jiffy)
            {
                try {
                    if (nomerge || JCR6.Recognize(aFile.source) == "NONE")
                    {
                        QCol.Doing("Adding", aFile.source, "\r");
                        jout.AddFile(aFile.source, aFile.target, aFile.storage, aFile.author, aFile.notes);
                        //Console.WriteLine("\nBefore AfterAdd\n");
#if DEBUG
                        QCol.Doing("TARGET:", $"{aFile.target}=>{aFile.TARGET}");
#endif
                        var E = jout.Entries[aFile.TARGET];
                        AfterAdd(E, aFile);
                        //Console.WriteLine("\nAfter AfterAdd\n");
                    }
                    else
                    {
                        QCol.Doing("Merging", aFile.source);
                        var merge = JCR6.Dir(aFile.source);
                        foreach (TJCREntry ent in merge.Entries.Values)
                        {
                            QCol.Doing("Adding", "", "");
                            QCol.Magenta($"{aFile.source}/");
                            QCol.Cyan($"{ent.Entry}\r");
                            var tar = $"{aFile.target}/{ent.Entry}";
                            if (puremerge)
                            {
                                jout.JCRCopy(merge, ent.Entry, tar);
                            }
                            else
                            {
                                var buf = merge.JCR_B(ent.Entry);
                                jout.AddBytes(buf, tar, aFile.storage, ent.Author, ent.Notes);
                            }
                            //var E = jout.Entries[tar.ToUpper()];
                            var E = jout.LastAddedEntry;
                            AfterAdd(E, aFile);
                        }
                    }
                } catch (Exception crap) {
                    QCol.Red("     Failed:\n");
                    if (JCR6.JERROR != "")
                    {
                        QCol.QuickError($"JCR6: {JCR6.JERROR}");
                    }
                    QCol.QuickError($".NET: {crap.Message}");
#if DEBUG
                    QCol.Magenta($"{crap.StackTrace}\n\n");
#endif
                }
            }

            // Process aliases
            //foreach(string ori in AliasList.Keys) {
            foreach (SAlias SAL in AliasList)
            {
                QCol.Yellow("Alias: ");
                QCol.Red(SAL.ori);
                QCol.White(" => ");
                QCol.Green(SAL.tar);
                jout.Alias(SAL.ori, SAL.tar);
                QCol.White("\n");
            }

            // Reorganize Files
            if (updating)
            {
                try {
                    QCol.Doing("Reorganizing", "Data");
                    jtmp = JCR6.Dir(jcrfile);
                    if (jtmp == null)
                    {
                        throw new Exception($"JCR failed to analyse the old archive: {JCR6.JERROR}");
                    }
                    var indicator = 0;
                    foreach (TJCREntry entry in jtmp.Entries.Values)
                    {
                        indicator++;
                        if (indicator % 5 == 0)
                        {
                            QCol.Blue("\r                \r.\b");
                        }
                        else
                        {
                            QCol.Blue(".\b");
                        }
                        if (!jout.Entries.ContainsKey(entry.Entry.ToUpper()))
                        {
                            QCol.Green("O");
                            jout.JCRCopy(jtmp, entry.Entry);
                        }
                        else
                        {
                            QCol.Red("X");
                        }
                    }
                    Console.WriteLine();
                } catch (Exception well) {
                    QCol.QuickError(well.Message);
                }
            }

            // Add dependency requests
            // TODO: Dependency requests

            // Closure and overwrite old JCR file if applicable.
            QCol.Doing("Finalizing", jcrfile);
            jout.Close();
            if (updating)
            {
                try {
                    File.Delete(jcrfile);
                    File.Move(temp, jcrfile);
                } catch (Exception E) {
                    QCol.QuickError(E.Message);
                }
            }
        }
 /// <summary>
 /// Saves the TeddyBear map inside a JCR6 resouce currently in creation. Returns "Ok" if succesful and otherwise an error message.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="jcr"></param>
 /// <param name="Entry"></param>
 /// <param name="Storage"></param>
 public static string Save(TeddyMap map, TJCRCreate jcr, string EntryPref, string Storage = "Store")
 {
     try {
         Init();
         //Local MP$ = Replace(MapFile, "\"," / ")
         TJCRCreate       BT = jcr;
         TJCRCreateStream BTE;
         // var K = "";
         // Local Ak, X, Y
         // TeddyObject Obj;
         // Local Obj: TeddyObject
         //'If Right(MP,1)<>"/" MP:+"/"
         //'If Not CreateDir(MP,1) Return "Required path could not be created!"
         // BT = JCR_Create(MapFile)
         Log("Gonna save a Teddy Bear map");
         if (BT == null)
         {
             return("Save file could not be created or null sent to saveJCR request!");
         }
         // DEFS
         Log("Saving Defs");
         BTE = BT.NewEntry($"{EntryPref}Defs", Storage);
         if (BTE == null)
         {
             return($"Entry creation failed: {JCR6.JERROR}");
         }
         BTE.WriteByte(0); BTE.WriteInt(map.GridX); BTE.WriteInt(map.GridY);
         BTE.WriteByte(1); if (map.TexResize)
         {
             BTE.WriteByte(1);
         }
         else
         {
             BTE.WriteByte(0);
         }
         BTE.WriteByte(2); BTE.WriteInt(map.SizeX); BTE.WriteInt(map.SizeY);
         Log("\tWriting Textures");
         for (byte Ak = 255; Ak > 0; Ak--)
         {
             // Log($"\tWriting texture {Ak}"); // Needless to log all the time, but I used this line for debugging purposes.
             if (map.Texture[Ak] != null && map.Texture[Ak] != "")
             {
                 BTE.WriteByte(3);
                 BTE.WriteByte(Ak);
                 BTE.WriteString(map.Texture[Ak]);
             }
         }
         Log("\tWriting Layers");
         foreach (string K in map.Layers.Keys)
         {
             Log($"\tWriting Layer: {K}");
             BTE.WriteByte(4);
             BTE.WriteString(K);
             if (qstr.Left(K, 5) == "Zone_")
             {
                 for (byte Ak = 255; Ak > 0; Ak--)   // Zone Names (if the specific layer is a zone)
                 {
                     if (map.ZName(K).Name[Ak] == null)
                     {
                         map.ZName(K).Name[Ak] = "";
                     }
                     BTE.WriteByte(5);
                     BTE.WriteByte(Ak);
                     BTE.WriteString(map.ZName(K).Name[Ak]);
                 }
             }
         }
         BTE.Close();
         // Layers
         Log("Saving Layers");
         foreach (string K in map.Layers.Keys)
         {
             Log($"Saving Layer {K}");
             var Prefix = "Layer_";
             var lay    = map.Layers[K];
             if (qstr.Left(K, 5) == "Zone_")
             {
                 Prefix = "";
             }
             BTE = BT.NewEntry($"{EntryPref}{Prefix}{K}", Storage);
             // Layer Type (should in this version be 0 always)
             BTE.WriteByte(0);
             BTE.WriteByte(map.Layers[K].T);
             // Format
             BTE.WriteByte(1);
             BTE.WriteInt(lay.W);
             BTE.WriteInt(lay.H);
             // Hot Spots
             BTE.WriteByte(2);
             BTE.WriteString(qstr.Left($"{lay.Hot}   ", 2), true);
             // Saving the map itself. No compression is used in saving the data, as TeddyBear has been designed to be used in combination with JCR6 which already compresses everything by itself.
             // Also note, the map itself tagged with $ff will cause the loader to end loading as soon as the map itself is read. In other words it must always come last in the file.
             // This is simply a security measure as some tags above can cause the loaded level to be unloaded immediatly, when this comes last, this simply can't happen.
             // A level without a $ff tagged map will also result into an error when loading.
             // $fe is also reserved in case 32 bit maps may be added in the future, which is in the current state of things, not likely to happen, but just in case :)
             // and for that reason $fd is reserved in case of the very small chance 64bit is used.
             // Must I really reserve $fc for 128bit (which is not even supported by BlitzMax yet)? Nah.... :-P
             BTE.WriteByte(0xff);
             for (int X = 0; X <= lay.W; X++)
             {
                 for (int Y = 0; Y <= lay.H; Y++)
                 {
                     BTE.WriteByte(lay.Get(X, Y));
                 }
             }
             BTE.Close();
         }
         // Objects
         Log("Saving Objects");
         BTE = BT.NewEntry($"{EntryPref}Objects", Storage);
         BTE.WriteInt(map.OWidth);
         BTE.WriteInt(map.OHeight);
         for (int X = 0; X <= map.OWidth; X++)
         {
             for (int Y = 0; Y <= map.OHeight; Y++)
             {
                 foreach (TeddyObject Obj in map.ObjectList(X, Y))
                 {
                     BTE.WriteByte(0); // New Object on the next coordinates
                     BTE.WriteInt(X);
                     BTE.WriteInt(Y);
                     BTE.WriteByte(2);
                     BTE.WriteString(Obj.ObjType);
                     foreach (string K in Obj.Keys)   // New field, with the next data
                     {
                         BTE.WriteByte(1);
                         BTE.WriteString(K);
                         BTE.WriteString(Obj.Cl(K));
                     }
                 }
             }
         }
         BTE.Close();
         // General Data
         Log("Saving General Data");
         BT.NewStringMap(map.MetaData, $"{EntryPref}Data", Storage);
         // All done
         Log("Closing");
         BT.Close();
         Log("Map saved");
         return("Ok");
     } catch (System.Exception err) {
         return($"System Error: {err.Message}");
     }
 }