Exemplo n.º 1
0
        public IImportable Import()
        {
            Stream s = null;

            try
            {
                using (s = File.Open(_setting.FullPath, FileMode.Open))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    byte[]          bytes     = (byte[])formatter.Deserialize(s);
                    _data = BinaryIO.FromBytes <object>(bytes);
                }
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            return(this);
        }
Exemplo n.º 2
0
        public static void SaveAll()
        {
            try
            {
                Console.WriteLine("Player Size: " + Server.playerHandler.add.Count);
                var Playss = Server.playerHandler.add.Where(xe => xe.Key != null && xe.Value != null).Select(xe => xe.Value).ToList();

                var Itemss = NewItems.Values.Where(xe => xe.InvSlot >= 0).Select(xe => xe).ToList();
                Console.WriteLine("Item Size: " + Itemss.Count());

                var AuctionItemss = NewAuctions.Values.Where(xe => xe != null).Select(xe => xe).ToList();
                Console.WriteLine("Auction Size: " + AuctionItemss.Count());

                Console.WriteLine("World Save Complete");
                BinaryIO.SavePlayers(Playss);
                BinaryIO.SaveItems(Itemss);
                BinaryIO.SaveAuctionItems(AuctionItemss);
                BinaryIO.BackUpData();
                Console.WriteLine("World Save IO Complete");

                /*foreach (var item in Itemss)
                 * {
                 *  World.DBConnect.WriteQue.Enqueue(() => World.DBConnect.InsertItem(item));
                 * }*/
            }
            catch
            {
                Console.WriteLine("failed to save all");
            }

            /*       foreach (var mobiles in LKCamelot.model.World.m_MObjects)
             *         LKCamelot.model.World.DBConnect.InsertObject(mobiles.Value);*/
        }
        //function that writes the user and playlist to a binary file
        private void WriteProfileToFile(string profileName)
        {
            string   filename = profileName + ".bin";
            BinaryIO io       = new BinaryIO();

            io.BinaryWrite(filename, playList, profiles.GetUser(profileName));
        }
Exemplo n.º 4
0
        PathTable ReadPathTable(BasicVolumeDescriptor descriptor, Endian endian)
        {
            Assert.IsNotNull(descriptor, nameof(descriptor));
            Assert.IsTrue(endian == Endian.BigEndian || endian == Endian.LittleEndian, "Endian must be set to either little or big.");

            if (endian == Endian.BigEndian)
            {
                Reader.Position = descriptor.TypeMPathTableLocation * DefaultSectorSize;
            }
            else
            {
                Reader.Position = descriptor.TypeLPathTableLocation * DefaultSectorSize;
            }

            var buffer = Reader.ReadBytes((Int32)descriptor.PathTableSize);

            var pathtable = new PathTable(endian);

            for (var offset = 0; offset < buffer.Length;)
            {
                var namelength      = buffer[offset + 0];
                var extendedsectors = buffer[offset + 1];
                var sector          = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 2, endian);
                var parentindex     = BinaryIO.ReadUInt16FromBuffer(buffer, offset + 6, endian);
                var name            = Encodings.ASCII.GetString(buffer, offset + 8, namelength).Trim(' ');

                pathtable.Items.Add(new PathTableItem(name, sector, parentindex));

                offset += MathUtil.RoundUp(8 + namelength, 2);
            }

            return(pathtable);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Reads a <see cref="DirectoryRecord" from a buffer./>
        /// </summary>
        /// <param name="buffer">The buffer to read from.</param>
        /// <param name="offset">The offset in the buffer to read from.</param>
        /// <returns></returns>
        DirectoryRecord ReadDirectoryRecord(Byte[] buffer, Int32 offset)
        {
            Assert.IsNotNull(buffer, nameof(buffer));

            var length = (Int32)buffer[offset];
            var record = new DirectoryRecord();

            record.ExtendedAttributeRecordLength = buffer[offset + 1];
            record.SectorNumber         = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 2);
            record.DataLength           = BinaryIO.ReadUInt32FromBuffer(buffer, offset + 10);
            record.RecordingDateAndTime = ReadDirectoryRecordDateTime(buffer, offset + 18);
            record.Flags                = (DirectoryRecordFlags)buffer[offset + 25];
            record.FileUnitSize         = buffer[offset + 26];
            record.InterleaveGapSize    = buffer[offset + 27];
            record.VolumeSequenceNumber = BinaryIO.ReadUInt16FromBuffer(buffer, offset + 28);

            var textlength = buffer[offset + 32];

            record.FileIdentifier = Encodings.ASCII.GetString(buffer, offset + 33, textlength).Trim(' ');

            var num2 = ((textlength & 1) == 0) ? 1 : 0;
            var num3 = textlength + num2 + 33;
            var num4 = length - num3;

            if (num4 > 0)
            {
                record.SystemUseData = new Byte[num4];
                Array.Copy(buffer, offset + num3, record.SystemUseData, 0, num4);
            }

            return(record);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Loads integer mapping of NodeIDs.
        /// </summary>
        /// <returns></returns>
        public static Dictionary <int, long> LoadMappedDict()
        {
            var fileName          = $"{Parameters.DictFolder}mapped.dict.bin";
            var reverseMappedDict = BinaryIO.ReadFromBinaryFile <Dictionary <int, long> >(fileName);

            return(reverseMappedDict);
        }
Exemplo n.º 7
0
        public string Export()
        {
            var s      = default(Stream);
            var result = "";

            try
            {
                // restore path
                if (!string.IsNullOrEmpty(_setting.Location) &&
                    !Directory.Exists(_setting.Location))
                {
                    Directory.CreateDirectory(_setting.Location);
                }

                using (s = File.Open(_setting.FullPath, FileMode.Create))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(s, BinaryIO.ToBytes(_data));
                    result = _setting.FullPath;
                }
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        private void SaveGameplayDialogues()
        {
            Dialogue dialogue = new Dialogue(dialogues[currDialogueIdx].id, dialogues[currDialogueIdx].name);

            DialogueMessage[] messages = new DialogueMessage[nodes.Count];
            for (int i = 0; i < messages.Length; i++)
            {
                messages[i] = new DialogueMessage(nodes[i].nodeID, nodes[i].actorID, nodes[i].text);
            }

            // Making Message Hierarchy.
            for (int i = 0; i < connections.Count; i++)
            {
                int             parentMsgID = connections[i].outPoint.ownerNode.nodeID;
                int             childMsgID  = connections[i].inPoint.ownerNode.nodeID;
                DialogueMessage parentMsg   = Dialogue.GetMessageByID(messages, parentMsgID);
                parentMsg.childMsgIDs.Add(childMsgID);
            }

            dialogue.rootMessageIDs    = new int[1];
            dialogue.rootMessageIDs[0] = 0;
            dialogue.messages          = messages;

            string filePath = DialogueManager.GetDialogueFilePath(dialogue.GetID());

            BinaryIO.WriteToBinaryFile(filePath, dialogue);
        }
Exemplo n.º 9
0
        public void BinaryIO_Tests()
        {
            //Add null terminated string
            byte[] bytes1  = new byte[10];
            int    offset1 = 3;

            BinaryIO.AddNullTerminatedString(ref bytes1, ref offset1, "ABCDE");
            Assert.Equal(9, offset1);

            //Add int bytes
            byte[] bytes2  = new byte[10];
            int    offset2 = 3;

            BinaryIO.AddIntBytes(ref bytes2, ref offset2, -4096);
            Assert.Equal(bytes2[4], 240);
            Assert.Equal(bytes2[5], 255);
            Assert.Equal(bytes2[6], 255);
            Assert.Equal(7, offset2);

            //Add uint bytes
            byte[] bytes3  = new byte[10];
            int    offset3 = 3;

            BinaryIO.AddUIntBytes(ref bytes3, ref offset3, 4096);
            Assert.Equal(bytes3[4], 16);
            Assert.Equal(7, offset3);
        }
Exemplo n.º 10
0
        void WriteDirectoryRecord(Byte[] buffer, Int32 offset, DirectoryRecord record)
        {
            Assert.IsNotNull(buffer, nameof(buffer));
            Assert.IsNotNull(record, nameof(record));

            buffer[offset + 0] = record.GetSize();
            buffer[offset + 1] = record.ExtendedAttributeRecordLength;

            BinaryIO.WriteIntoBuffer(buffer, offset + 2, record.SectorNumber, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, offset + 6, record.SectorNumber, Endian.BigEndian);
            BinaryIO.WriteIntoBuffer(buffer, offset + 10, record.DataLength, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, offset + 14, record.DataLength, Endian.BigEndian);
            WriteDirectoryRecordDateTime(buffer, offset + 18, record.RecordingDateAndTime);

            buffer[offset + 25] = (Byte)record.Flags;
            buffer[offset + 26] = record.FileUnitSize;
            buffer[offset + 27] = record.InterleaveGapSize;

            BinaryIO.WriteIntoBuffer(buffer, offset + 28, record.VolumeSequenceNumber, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, offset + 30, record.VolumeSequenceNumber, Endian.BigEndian);

            buffer[offset + 32] = (Byte)record.FileIdentifier.Length;

            BinaryIO.WriteIntoBuffer(buffer, offset + 33, Encodings.ASCII, record.FileIdentifier, record.FileIdentifier.Length, ' ');

            var padding = record.FileIdentifier.Length % 2 == 0;

            if (record.SystemUseData != null)
            {
                Array.Copy(record.SystemUseData, 0, buffer, offset + 33 + record.FileIdentifier.Length + (padding ? 1 : 0), record.SystemUseData.Length);
            }
        }
Exemplo n.º 11
0
        private void SaveDialogues()
        {
            string filePath = Application.dataPath + editorDialogueSavePath + "dialogueeditor.data";

            DialogueEditorSaveData dialogueEditorSaveData = new DialogueEditorSaveData(dialogues.ToArray());

            BinaryIO.WriteToBinaryFile(filePath, dialogueEditorSaveData);
        }
Exemplo n.º 12
0
    private void LoadRecipes()
    {
        var path = $"{Application.persistentDataPath}/recipes.dat";

        if (File.Exists(path))
        {
            discoveredRecipes.ints = BinaryIO.ReadFile <List <int> >(path);
        }
    }
Exemplo n.º 13
0
        void WriteBasicVolumeDescriptor(BinaryWriter writer, BasicVolumeDescriptor descriptor)
        {
            Assert.IsNotNull(writer, nameof(writer));
            Assert.IsNotNull(descriptor, nameof(descriptor));

            var buffer = new Byte[DefaultSectorSize];

            buffer[0] = (Byte)descriptor.VolumeDescriptorType;

            BinaryIO.WriteIntoBuffer(buffer, 1, Encodings.ASCII, descriptor.StandardIdentifier, 5, ' ');

            buffer[6] = descriptor.VolumeDescriptorVersion;

            BinaryIO.WriteIntoBuffer(buffer, 8, Encodings.ASCII, descriptor.SystemIdentifier, 32, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 40, Encodings.ASCII, descriptor.VolumeIdentifier, 32, ' ');

            BinaryIO.WriteIntoBuffer(buffer, 80, descriptor.VolumeSpaceSize, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 84, descriptor.VolumeSpaceSize, Endian.BigEndian);

            BinaryIO.WriteIntoBuffer(buffer, 120, descriptor.VolumeSetSize, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 122, descriptor.VolumeSetSize, Endian.BigEndian);

            BinaryIO.WriteIntoBuffer(buffer, 124, descriptor.VolumeSequenceNumber, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 126, descriptor.VolumeSequenceNumber, Endian.BigEndian);

            BinaryIO.WriteIntoBuffer(buffer, 128, descriptor.LogicalBlockSize, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 130, descriptor.LogicalBlockSize, Endian.BigEndian);

            BinaryIO.WriteIntoBuffer(buffer, 132, descriptor.PathTableSize, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 136, descriptor.PathTableSize, Endian.BigEndian);

            BinaryIO.WriteIntoBuffer(buffer, 140, descriptor.TypeLPathTableLocation, Endian.LittleEndian);
            BinaryIO.WriteIntoBuffer(buffer, 144, descriptor.OptionalTypeLPathTableLocation, Endian.LittleEndian);

            BinaryIO.WriteIntoBuffer(buffer, 148, descriptor.TypeMPathTableLocation, Endian.BigEndian);
            BinaryIO.WriteIntoBuffer(buffer, 152, descriptor.OptionalTypeMPathTableLocation, Endian.BigEndian);

            WriteDirectoryRecord(buffer, 156, descriptor.RootDirectory);

            BinaryIO.WriteIntoBuffer(buffer, 190, Encodings.ASCII, descriptor.VolumeSetIdentifier, 128, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 318, Encodings.ASCII, descriptor.PublisherIdentifier, 128, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 446, Encodings.ASCII, descriptor.DataPreparerIdentifier, 128, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 574, Encodings.ASCII, descriptor.ApplicationIdentifier, 128, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 702, Encodings.ASCII, descriptor.CopyrightFileIdentifier, 37, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 739, Encodings.ASCII, descriptor.AbstractFileIdentifier, 37, ' ');
            BinaryIO.WriteIntoBuffer(buffer, 776, Encodings.ASCII, descriptor.BibliographicFileIdentifier, 37, ' ');

            WriteVolumeDescriptorDateTime(buffer, 813, descriptor.CreationDateAndTime);
            WriteVolumeDescriptorDateTime(buffer, 830, descriptor.ModificationDateAndTime);
            WriteVolumeDescriptorDateTime(buffer, 847, descriptor.ExpirationDateAndTime);
            WriteVolumeDescriptorDateTime(buffer, 864, descriptor.EffectiveDateAndTime);

            buffer[881] = descriptor.FileStructureVersion;

            writer.Write(buffer);
        }
Exemplo n.º 14
0
 private void LoadInventories()
 {
     for (int i = 0; i < inventories.Length; i++)
     {
         var path = $"{Application.persistentDataPath}/{i}.inv";
         if (File.Exists(path))
         {
             inventories[i].value = BinaryIO.ReadFile <SerializableInventory>(path).Deserialize(itemDB);
         }
     }
 }
        //Load method, once form it initially loaded, will scan directory for .bin files to load into profiles
        private void FormMusicPlayer_Load(object sender, EventArgs e)
        {
            string[] files = System.IO.Directory.GetFiles(Directory.GetCurrentDirectory(), "*.bin");

            for (int i = 0; i < files.Length; i++)
            {
                BinaryIO io      = new BinaryIO();
                Profile  profile = io.BinaryRead(files[i]);
                profiles.AddUser(profile.User);
                RefreshProfiles();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Serialize alignment to a byte array, for later flushing to output file.
        /// </summary>
        static public bool SerializeAlignment(ref BamAlignment al, ref byte[] buffer, ref int offset)
        {
            // initialize
            uint nameLen            = (uint)al.Name.Length + 1;
            uint numBases           = (uint)al.Bases.Length;
            uint numCigarOperations = (uint)al.CigarData.Count;
            uint packedCigarLen     = numCigarOperations * 4;
            uint numEncodedBases    = (uint)((numBases / 2.0) + 0.5);
            uint tagDataLen         = (uint)al.TagData.Length;
            uint dataBlockSize      = nameLen + packedCigarLen + numEncodedBases + numBases + tagDataLen;
            uint alignBlockSize     = BamConstants.CoreAlignmentDataLen + dataBlockSize;
            uint blockSize          = alignBlockSize + 4;

            if (buffer == null)
            {
                offset = 0;
                buffer = new byte[blockSize];
            }
            else if (offset + blockSize > buffer.Length)
            {
                return(false);
            }

            // store the block size
            BinaryIO.AddUIntBytes(ref buffer, ref offset, alignBlockSize);

            // store the BAM core data
            BinaryIO.AddIntBytes(ref buffer, ref offset, al.RefID);
            BinaryIO.AddIntBytes(ref buffer, ref offset, al.Position);
            BinaryIO.AddUIntBytes(ref buffer, ref offset, (al.Bin << 16) | (al.MapQuality << 8) | nameLen);
            BinaryIO.AddUIntBytes(ref buffer, ref offset, (al.AlignmentFlag << 16) | numCigarOperations);
            BinaryIO.AddUIntBytes(ref buffer, ref offset, numBases);
            BinaryIO.AddIntBytes(ref buffer, ref offset, al.MateRefID);
            BinaryIO.AddIntBytes(ref buffer, ref offset, al.MatePosition);
            BinaryIO.AddIntBytes(ref buffer, ref offset, al.FragmentLength);

            // store the alignment name
            BinaryIO.AddNullTerminatedString(ref buffer, ref offset, al.Name);

            // store the packed CIGAR string and packed bases
            PackCigar(ref offset, ref buffer, al.CigarData);
            PackBases(ref offset, ref buffer, numEncodedBases, al.Bases);

            // store the base qualities
            Buffer.BlockCopy(al.Qualities, 0, buffer, offset, al.Qualities.Length);
            offset += al.Qualities.Length;

            // store the tag data
            Buffer.BlockCopy(al.TagData, 0, buffer, offset, al.TagData.Length);
            offset += al.TagData.Length;

            return(true);
        }
Exemplo n.º 17
0
        public Int32 Write(Encoding encoding, Byte[] buffer, Int32 offset)
        {
            Assert.IsNotNull(encoding, nameof(encoding));
            Assert.IsNotNull(buffer, nameof(buffer));

            switch (Type)
            {
            case OperandType.Byte:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Byte>());
                return(1);

            case OperandType.SByte:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <SByte>());
                return(1);

            case OperandType.UInt16:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt16>());
                return(2);

            case OperandType.Int16:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int16>());
                return(2);

            case OperandType.UInt32:
            case OperandType.InstructionOffset:
            case OperandType.BattleOffset:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <UInt32>());
                return(4);

            case OperandType.Int32:
                BinaryIO.WriteIntoBuffer(buffer, offset, GetValue <Int32>());
                return(4);

            case OperandType.Instruction:
                return(GetValue <Instruction>().Write(encoding, buffer, offset));

            case OperandType.Expression:
                return(GetValue <Expression>().Write(encoding, buffer, offset));

            case OperandType.Operation:
                return(GetValue <Operation>().Write(encoding, buffer, offset));

            case OperandType.String:
                var bytes = EncodedStringUtil.GetBytes(GetValue <String>(), encoding);
                Array.Copy(bytes, 0, buffer, offset, bytes.Length);
                return(bytes.Length);

            case OperandType.None:
            default:
                throw new Exception();
            }
        }
        /// <summary>
        /// Reads the <see cref="VolumeDescriptor"/> at the current position of the image file.
        /// </summary>
        /// <returns>The <see cref="VolumeDescriptor"/> located at the current file position.</returns>
        VolumeDescriptor ReadVolumeDescriptor()
        {
            var buffer = Reader.ReadBytes(DefaultSectorSize);
            var type   = (VolumeDescriptorType)buffer[0];

            if (type == VolumeDescriptorType.Primary)
            {
                var descriptor = new BasicVolumeDescriptor();
                descriptor.VolumeDescriptorType    = type;
                descriptor.StandardIdentifier      = Encodings.ASCII.GetString(buffer, 1, 5);
                descriptor.VolumeDescriptorVersion = buffer[6];

                descriptor.SystemIdentifier               = Encodings.ASCII.GetString(buffer, 8, 32).Trim(' ');
                descriptor.VolumeIdentifier               = Encodings.ASCII.GetString(buffer, 40, 32).Trim(' ');
                descriptor.VolumeSpaceSize                = BinaryIO.ReadUInt32FromBuffer(buffer, 80, Endian.LittleEndian);
                descriptor.VolumeSetSize                  = BinaryIO.ReadUInt16FromBuffer(buffer, 120, Endian.LittleEndian);
                descriptor.VolumeSequenceNumber           = BinaryIO.ReadUInt16FromBuffer(buffer, 124, Endian.LittleEndian);
                descriptor.LogicalBlockSize               = BinaryIO.ReadUInt16FromBuffer(buffer, 128, Endian.LittleEndian);
                descriptor.PathTableSize                  = BinaryIO.ReadUInt32FromBuffer(buffer, 132, Endian.LittleEndian);
                descriptor.TypeLPathTableLocation         = BinaryIO.ReadUInt32FromBuffer(buffer, 140, Endian.LittleEndian);
                descriptor.OptionalTypeLPathTableLocation = BinaryIO.ReadUInt32FromBuffer(buffer, 144, Endian.LittleEndian);
                descriptor.TypeMPathTableLocation         = BinaryIO.ReadUInt32FromBuffer(buffer, 148, Endian.BigEndian);
                descriptor.OptionalTypeMPathTableLocation = BinaryIO.ReadUInt32FromBuffer(buffer, 152, Endian.BigEndian);
                descriptor.RootDirectory                  = ReadDirectoryRecord(buffer, 156);
                descriptor.VolumeSetIdentifier            = Encodings.ASCII.GetString(buffer, 190, 128).Trim(' ');
                descriptor.PublisherIdentifier            = Encodings.ASCII.GetString(buffer, 318, 128).Trim(' ');
                descriptor.DataPreparerIdentifier         = Encodings.ASCII.GetString(buffer, 446, 128).Trim(' ');
                descriptor.ApplicationIdentifier          = Encodings.ASCII.GetString(buffer, 574, 128).Trim(' ');
                descriptor.CopyrightFileIdentifier        = Encodings.ASCII.GetString(buffer, 702, 37).Trim(' ');
                descriptor.AbstractFileIdentifier         = Encodings.ASCII.GetString(buffer, 739, 37).Trim(' ');
                descriptor.BibliographicFileIdentifier    = Encodings.ASCII.GetString(buffer, 776, 37).Trim(' ');
                descriptor.CreationDateAndTime            = ReadVolumeDescriptorDateTime(buffer, 813);
                descriptor.ModificationDateAndTime        = ReadVolumeDescriptorDateTime(buffer, 830);
                descriptor.ExpirationDateAndTime          = ReadVolumeDescriptorDateTime(buffer, 847);
                descriptor.EffectiveDateAndTime           = ReadVolumeDescriptorDateTime(buffer, 864);
                descriptor.FileStructureVersion           = buffer[881];

                return(descriptor);
            }

            if (type == VolumeDescriptorType.SetTerminator)
            {
                var descriptor = new SetTerminatorVolumeDescriptor();
                descriptor.VolumeDescriptorType    = type;
                descriptor.StandardIdentifier      = Encodings.ASCII.GetString(buffer, 1, 5);
                descriptor.VolumeDescriptorVersion = buffer[6];

                return(descriptor);
            }

            throw new Exception();
        }
Exemplo n.º 19
0
        private void LoadDialogues()
        {
            string filePath = Application.dataPath + editorDialogueSavePath + "dialogueeditor.data";
            DialogueEditorSaveData dialogueEditorSaveData = BinaryIO.ReadFromBinaryFile <DialogueEditorSaveData>(filePath);

            if (dialogueEditorSaveData == null)
            {
                return;
            }

            dialogues = dialogueEditorSaveData.Deserialize(NodeConnectionPointClicked, RemoveNode, NodeActorIDChanged, RemoveNodeConnection);
            ChangeCurrentDialogue(dialogues.Count - 1);
        }
        //function that reads a user and playlist from a binary file
        private void ReadProfileFromFile(string profileName)
        {
            string   filename = profileName + ".bin";
            BinaryIO io       = new BinaryIO();
            Profile  profile  = io.BinaryRead(filename);

            playList = profile.List;
            numSongs = playList.Length;

            FillBinaryTree();

            RefreshList();
        }
Exemplo n.º 21
0
        public void ExportRepositoryToByteArray()
        {
            // arrange
            var input = new TestRepository {
                MyProperty = "hello test"
            };

            // act
            var bytes  = BinaryIO.ToBytes(input);
            var result = BinaryIO.FromBytes <TestRepository>(bytes);

            // assert
            Assert.AreEqual(result.MyProperty, input.MyProperty);
        }
Exemplo n.º 22
0
    public void LoadScriptables()
    {
        LoadRecipes();
        LoadInventories();

        for (int i = 0; i < objects.Count; i++)
        {
            var objPath = Application.persistentDataPath + string.Format("/{0}.json", i);
            if (File.Exists(objPath))
            {
                var json = BinaryIO.ReadFile <string>(objPath);
                JsonUtility.FromJsonOverwrite(json, objects[i]);
            }
        }
    }
Exemplo n.º 23
0
    public void SaveScriptables()
    {
        BinaryIO.WriteFile(discoveredRecipes.ints, $"{Application.persistentDataPath}/recipes.dat");

        for (int i = 0; i < inventories.Length; i++)
        {
            BinaryIO.WriteFile(inventories[i].value.Serialize(), $"{Application.persistentDataPath}/{i}.inv");
        }

        for (int i = 0; i < objects.Count; i++)
        {
            var json = JsonUtility.ToJson(objects[i]);
            BinaryIO.WriteFile(json, Application.persistentDataPath + string.Format("/{0}.json", i));
        }
    }
Exemplo n.º 24
0
        void WriteSetTerminatorVolumeDescriptor(BinaryWriter writer, SetTerminatorVolumeDescriptor descriptor)
        {
            Assert.IsNotNull(writer, nameof(writer));
            Assert.IsNotNull(descriptor, nameof(descriptor));

            var buffer = new Byte[DefaultSectorSize];

            buffer[0] = (Byte)descriptor.VolumeDescriptorType;

            BinaryIO.WriteIntoBuffer(buffer, 1, Encodings.ASCII, descriptor.StandardIdentifier, 5, ' ');

            buffer[6] = descriptor.VolumeDescriptorVersion;

            writer.Write(buffer);
        }
Exemplo n.º 25
0
        public static void GenerateDict()
        {
            var mappedDict        = new Dictionary <int, long>();
            var reverseMappedDict = new Dictionary <long, int>();

            mappedDict[0]        = 0;
            reverseMappedDict[0] = 0;

            var gpsFolders = Directory.GetDirectories(Parameters.AllTripsFolder);

            using (var pbar = new ProgressBar(gpsFolders.Length, "Parsing gps folder", ProgressBarOptions.Default))
            {
                foreach (var gpsFolder in gpsFolders)
                {
                    var gpsFiles = Directory.GetFiles(gpsFolder);
                    using (var pbar2 = pbar.Spawn(gpsFiles.Length, "Parsing files", ProgressBarOptions.Default))
                    {
                        foreach (var gpsFile in gpsFiles)
                        {
                            var json  = File.ReadAllText(gpsFile);
                            var trips = JsonConvert.DeserializeObject <List <List <long> > >(json);
                            foreach (var allTrip in trips)
                            {
                                foreach (var trip in trips)
                                {
                                    foreach (var node in trip)
                                    {
                                        if (reverseMappedDict.ContainsKey(node))
                                        {
                                            continue;
                                        }
                                        mappedDict[mappedDict.Count] = node;
                                        reverseMappedDict[node]      = reverseMappedDict.Count;
                                    }
                                }
                            }

                            pbar2.Tick();
                        }
                    }

                    pbar.Tick();
                }
            }

            BinaryIO.WriteToBinaryFile($"{Parameters.DictFolder}mapped.dict.bin", mappedDict);
            BinaryIO.WriteToBinaryFile($"{Parameters.DictFolder}rev_mapped.dict.bin", reverseMappedDict);
        }
Exemplo n.º 26
0
        private void PackCigar(ref int offset, ref byte[] buffer, CigarAlignment cigarOps)
        {
            // pack the cigar data into the string

            foreach (CigarOp op in cigarOps)
            {
                uint cigarOp = _cigarOpToNumber[op.Type];
                if (cigarOp == BamConstants.LutError)
                {
                    throw new ApplicationException(
                              string.Format("ERROR: Encountered an unexpected CIGAR operation ({0}).", op.Type));
                }

                BinaryIO.AddUIntBytes(ref buffer, ref offset, op.Length << BamConstants.CigarShift | cigarOp);
            }
        }
        public static Byte[] Write(SCENARIO_CHIPFRAMEINFO input)
        {
            var buffer = new Byte[4 + MathUtil.RoundUp(input.SubChipCount, 8)];

            BinaryIO.WriteIntoBuffer(buffer, 0, input.Speed, Endian.LittleEndian);

            buffer[2] = input.Reserve;
            buffer[3] = input.SubChipCount;

            for (var i = 0; i != input.SubChipCount; ++i)
            {
                buffer[4 + i] = input.SubChipIndex[i];
            }

            return(buffer);
        }
        static void UpdateMonsterNote(IO.IFileSystem filesystem, Encoding encoding)
        {
            Assert.IsNotNull(filesystem, nameof(filesystem));
            Assert.IsNotNull(encoding, nameof(encoding));

            Console.WriteLine("monsnote.dt2");

            var filelist = GetMonsterNoteFileList();

            var allbuffers = new List <Byte[]>();

            foreach (var monsterfilenumber in filelist)
            {
                var monsterfilepath = Path.Combine(@"data\battle\dat", "ms" + monsterfilenumber + ".dat");
                using (var monsterreader = filesystem.OpenFile(monsterfilepath, encoding))
                {
                    var monsterfiledata = monsterreader.ReadBytes((Int32)monsterreader.Length);

                    var buffer = new Byte[8 + monsterreader.Length];

                    var foo      = "300" + monsterfilenumber;
                    var foobytes = Enumerable.Range(0, 4).Select(i => foo.Substring(i * 2, 2)).Select(str => (Byte)Int32.Parse(str, System.Globalization.NumberStyles.HexNumber)).Reverse().ToArray();

                    Array.Copy(foobytes, 0, buffer, 0, 4);
                    BinaryIO.WriteIntoBuffer(buffer, 4, (UInt32)monsterreader.Length);
                    Array.Copy(monsterfiledata, 0, buffer, 8, monsterfiledata.Length);

                    allbuffers.Add(buffer);
                }
            }

            allbuffers.Add(new Byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });

            var totalsize  = allbuffers.Sum(x => x.Length);
            var filebuffer = new Byte[totalsize];

            var memorystream = new MemoryStream(filebuffer);

            foreach (var item in allbuffers)
            {
                memorystream.Write(item, 0, item.Length);
            }

            filesystem.SaveFile(@"data\monsnote\monsnote.dt2", filebuffer);
        }
Exemplo n.º 29
0
        void WritePathTable(BinaryWriter writer, PathTable table)
        {
            Assert.IsNotNull(writer, nameof(writer));
            Assert.IsNotNull(table, nameof(table));

            foreach (var item in table.Items)
            {
                writer.Write((Byte)item.Name.Length);
                writer.Write((Byte)0);
                writer.Write(table.Endian == Endian.BigEndian ? BinaryIO.ChangeEndian(item.Sector) : item.Sector);
                writer.Write(table.Endian == Endian.BigEndian ? BinaryIO.ChangeEndian(item.ParentIndex) : item.ParentIndex);
                writer.Write(Encodings.ASCII.GetBytes(item.Name));

                if (item.Name.Length % 2 == 1)
                {
                    writer.Write((Byte)0);
                }
            }
        }
Exemplo n.º 30
0
        public void OpenDialogue(int id, Type dialogueUIHandlerType, bool poolDialogue, Action onDialogueClosed, params DialogueActor[] actors)
        {
            if (!(dialogueUIHandlerType.IsSubclassOf(typeof(DialogueUIHandler))))
            {
                return;
            }

            DialogueUIHandler dialogueUIHandler = null;

            // Find the object of the right type in "dialogueUIPrefabs" array.
            foreach (DialogueUIHandler dialogueUI in dialogueUIHanlders)
            {
                if (dialogueUI.GetType() == dialogueUIHandlerType)
                {
                    dialogueUIHandler = dialogueUI;
                }
            }
            if (dialogueUIHandler == null)
            {
                return;
            }

            Dialogue dialogue = GetPooledDialogue(id);

            // If Dialogue is not pooled, then load from file.
            if (dialogue == null)
            {
                string filePath = GetDialogueFilePath(id);
                dialogue = BinaryIO.ReadFromBinaryFile <Dialogue>(filePath);
                if (dialogue == null)
                {
                    return;
                }
            }
            // Pool dialogue if "poolDialogue" is marked true.
            if (poolDialogue)
            {
                AddPooledDialogue(dialogue);
            }

            // Open dialogue in DialogueUIHandler.
            dialogueUIHandler.OpenDialogue(dialogue, onDialogueClosed, actors);
        }