Beispiel #1
0
        public static List <ClassTemplate> GetAllClasses(string fileName, IEnumerable <ClassTemplate> classes)
        {
            var dataBuffer             = new ClassBuffer();
            var list                   = new List <ClassBuffer>();
            Func <ClassBuffer> newFunc = () => new ClassBuffer();
            Func <ClassBuffer, ClassTemplate> convert = x => x.ToClass(classes.SingleOrDefault(y => y.Id == x.Number));

            // Yes, yes. Copied Code. How horrible. There's really no good alternative to DllImport-interfacing code though. Dynamic doesn't work,
            // templates don't work, etc. So. Given that the MajorMUD database format will never change in the future (it's been dead 10 years!),
            // I'm ok with copied code. Huzzah.
            byte[] posBlock     = new byte[128];
            char[] keyBuffer    = fileName.ToCharArray(); //@"E:\PROJECTS\DEVELOPMENT\00-Current\KatanaMUD\KatanaMUD.Importer\bin\Debug\dats\wccrace2.dat".ToCharArray();
            int    bufferLength = 156;                    // System.Runtime.InteropServices.Marshal.SizeOf(dataBuffer);

            int status = Btrieve.BTRCALL(Btrieve.BOPEN, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);

            if (status == 0)
            {
                status = Btrieve.BTRCALL(Btrieve.BGETFIRST, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);
                if (status == 0)
                {
                    list.Add(dataBuffer);
                }
                else
                {
                    throw new InvalidOperationException(ErrorCode(status));
                }

                // Get subsequent records
                while (status == 0) // BReturnCodes.END_OF_FILE or an error will occur
                {
                    dataBuffer = newFunc();
                    status     = Btrieve.BTRCALL(Btrieve.BGETNEXT, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);

                    if (status == 0)
                    {
                        list.Add(dataBuffer);
                    }
                    else if (status != 9)
                    {
                        throw new InvalidOperationException(ErrorCode(status));
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(ErrorCode(status));
            }

            return(list.Select(x => convert(x)).ToList());
        }
Beispiel #2
0
        public static List <RoomBuffer> GetAllRooms(string fileName)
        {
            var dataBuffer            = new RoomBuffer();
            var list                  = new List <RoomBuffer>();
            Func <RoomBuffer> newFunc = () => new RoomBuffer();

            // Yes, yes. Copied Code. How horrible. There's really no good alternative to DllImport-interfacing code though. Dynamic doesn't work,
            // templates don't work, etc. So. Given that the MajorMUD database format will never change in the future (it's been dead 10 years!),
            // I'm ok with copied code. Huzzah.
            byte[] posBlock     = new byte[128];
            char[] keyBuffer    = fileName.ToCharArray();
            int    bufferLength = 1544; //System.Runtime.InteropServices.Marshal.SizeOf(dataBuffer);

            int status = Btrieve.BTRCALL(Btrieve.BOPEN, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);

            if (status == 0)
            {
                status = Btrieve.BTRCALL(Btrieve.BGETFIRST, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);
                if (status == 0)
                {
                    list.Add(dataBuffer);
                }
                else
                {
                    throw new InvalidOperationException(ErrorCode(status));
                }

                // Get subsequent records
                while (status == 0) // BReturnCodes.END_OF_FILE or an error will occur
                {
                    dataBuffer = newFunc();
                    status     = Btrieve.BTRCALL(Btrieve.BGETNEXT, posBlock, ref dataBuffer, ref bufferLength, keyBuffer, (ushort)keyBuffer.Length, 0);

                    if (status == 0)
                    {
                        list.Add(dataBuffer);
                    }
                    else if (status != 9)
                    {
                        throw new InvalidOperationException(ErrorCode(status));
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(ErrorCode(status));
            }

            return(list);
        }
Beispiel #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var context = new GameEntities("Server=KATANAMUD\\SQLEXPRESS;Database=KatanaMUD;integrated security=True;");

            context.LoadFromDatabase();

            //var races = Btrieve.GetAllRaces(new FileInfo(@"C:\Users\spsadmin\Documents\MMUDDats\wccrace2.dat").FullName, context.RaceTemplates);
            //var classes = Btrieve.GetAllClasses(new FileInfo(@"C:\Users\spsadmin\Documents\MMUDDats\wccclas2.dat").FullName, context.ClassTemplates);
            var items = Btrieve.GetAllItems(new FileInfo(@"C:\CleanP\wccitem2.dat").FullName, context.ItemTemplates);


            //var rooms = Btrieve.GetAllRooms(new FileInfo(@"C:\CleanP\wccmp002.dat").FullName);

            //Regex r = new Regex("\\s+");
            //var descriptions = rooms.GroupBy(x => x.Description).ToList();//.OrderBy(x => x.Key).ToList();

            //foreach (var group in descriptions)
            //{
            //    var textBlock = context.TextBlocks.New();
            //    textBlock.Text = group.Key;

            //    foreach (var room in group)
            //    {
            //        var dbRoom = room.ToRoom(null);
            //        dbRoom.TextBlock = textBlock;
            //        context.Rooms.Add(dbRoom, false);
            //    }
            //}

            //foreach (var room in rooms)
            //{
            //	var dbRoom = room.ToRoom(context.Rooms.SingleOrDefault(x => x.Id == RoomBuffer.GetRoomNumber(room.MapNumber, room.RoomNumber)));
            //}



            //var notdrop = items.Where(x => x.NotDroppable != 0).ToList();
            //var retain = items.Where(x => x.RetainAfterUses != 0).ToList();
            //var destroy = items.Where(x => x.DestroyOnDeath != 0).ToList();



            //context.RaceTemplates.AddRange(races, true);
            //context.ClassTemplates.AddRange(classes, true);
            //context.ItemTemplates.AddRange(items, true);
            context.SaveChanges();
        }