private async void archives() { StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await folder.CreateFileAsync("buttonRecord.json", CreationCollisionOption.ReplaceExisting); ButtonRecord butt = new ButtonRecord { pesticideButton = new List <string> { }, wateringButton = new List <string> { }, illuminationButton = new List <string> { } }; string json = JsonConvert.SerializeObject(butt); await FileIO.WriteTextAsync(sampleFile, json); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); buttonId = binaryReader.ReadUInt16(); characters = new ButtonRecordCollection(); bool characterEndFlag = false; while (!characterEndFlag) { byte first = binaryReader.ReadByte(); if (first == 0) { characterEndFlag = true; } else { ButtonRecord buttRecord = new ButtonRecord(); buttRecord.ReadData(binaryReader, first, TagCodeEnum.DefineButton); characters.Add(buttRecord); } } int offset = 2; foreach (ButtonRecord butRec in characters) { offset += butRec.GetSizeOf(); } int lenght = System.Convert.ToInt32(rh.TagLength) - offset - 1; //-1 for the ActionEndFlag actions = binaryReader.ReadBytes(lenght); //Read ActionEndFlag binaryReader.ReadByte(); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); long startPosition = binaryReader.BaseStream.Position; buttonId = binaryReader.ReadUInt16(); binaryReader.ReadUBits(7); //reserved trackAsMenu = binaryReader.ReadBoolean(); long startPos = binaryReader.BaseStream.Position; actionOffset = binaryReader.ReadUInt16(); if (characters == null) { characters = new ButtonRecordCollection(); } else { characters.Clear(); } bool characterEndFlag = false; while (!characterEndFlag) { byte first = binaryReader.ReadByte(); if (first == 0) { characterEndFlag = true; } else { ButtonRecord buttRecord = new ButtonRecord(); buttRecord.ReadData(binaryReader, first, TagCodeEnum.DefineButton2); characters.Add(buttRecord); } } long curr = startPos + actionOffset; actions = new ButtonCondactionCollection(); bool lastCondAction = false; if (actionOffset == 0) { lastCondAction = true; } while (!lastCondAction) { long readedBytes = binaryReader.BaseStream.Position - startPosition; ushort condActionSize = binaryReader.ReadUInt16(); if (condActionSize == 0) { lastCondAction = true; condActionSize = (ushort)(rh.TagLength - readedBytes); } ButtonCondaction buttCond = new ButtonCondaction(); buttCond.ReadData(binaryReader, condActionSize); actions.Add(buttCond); } }
public static void WriteInAllocatedMemoryImpl(BinaryWriter writer, MemoryPool memory, ButtonRecord record) { writer.Write((Byte)record.Flags); writer.WriteUInt24(0); // reserved writer.Write((UInt32)record.Character); writer.Write((Int32)record.Depth); writer.Write((Matrix2x2)record.RotScale); writer.Write((Vector2)record.Translation); writer.Write((ColorRgbaF)record.Color); writer.Write((Vector4)record.Unknown); }
public static uint GetElementSizeImpl(ButtonRecord record) => Constants.IntPtrSize * 17;
/// <summary> /// Parses this object out of a stream /// </summary> protected override void Parse() { // TODO: Completely Untested!!! long initialPosition = this._dataStream.Position; BinaryReader2 br = new BinaryReader2(this._dataStream ); this._buttonID = br.ReadUInt16(); while ( 0 != br.PeekByte() ) { ButtonRecord buttonR = new ButtonRecord( this.Version ); buttonR.Parse( this._dataStream ); if ( buttonR._ButtonHasBlendMode && ( this.Version < 8 ) ) { throw new SwfFormatException( "DefineButton with ButtonHasBlendMode requires Swf 8 (file: " + this.Version.ToString( "d" ) ); } if ( buttonR._ButtonHasFilterList && ( this.Version < 8 ) ) { throw new SwfFormatException( "DefineButton with ButtonHasFilterList requires Swf 8 (file: " + this.Version.ToString( "d" ) ); } this._characters.Add( buttonR ); } // read the CharacterEndFlag br.ReadByte(); // // Now read the ActionRecords that might be there // ParseCode(this._tag.Length - (uint)(this._dataStream.Position - initialPosition ) ); if (this._dataStream.Position != this._dataStream.Length ) { Log.Warn(this, "Trailing garbage within DefineButton: " + this._dataStream.Position.ToString( "d" ) + " of " + this._dataStream.Length.ToString( "d" ) + " bytes used." ); } }
private async void recordControl(string types) { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await storageFolder.GetFileAsync("buttonRecord.json"); if (types == "watering") { try { string text = await FileIO.ReadTextAsync(sampleFile); ButtonRecord person = JsonConvert.DeserializeObject <ButtonRecord>(text); person.wateringButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(person); await FileIO.WriteTextAsync(sampleFile, json); } catch (Exception) { ButtonRecord butt = new ButtonRecord { wateringButton = new List <string> { } }; butt.wateringButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(butt); await FileIO.WriteTextAsync(sampleFile, json); } } else if (types == "illumination") { try { string text = await FileIO.ReadTextAsync(sampleFile); ButtonRecord person = JsonConvert.DeserializeObject <ButtonRecord>(text); person.illuminationButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(person); await FileIO.WriteTextAsync(sampleFile, json); } catch (Exception) { ButtonRecord butt = new ButtonRecord { illuminationButton = new List <string> { } }; butt.illuminationButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(butt); await FileIO.WriteTextAsync(sampleFile, json); } } else if (types == "pesticide") { try { string text = await FileIO.ReadTextAsync(sampleFile); ButtonRecord person = JsonConvert.DeserializeObject <ButtonRecord>(text); person.pesticideButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(person); await FileIO.WriteTextAsync(sampleFile, json); } catch (Exception) { ButtonRecord butt = new ButtonRecord { pesticideButton = new List <string> { } }; butt.pesticideButton.Add(DateTime.Now.ToString()); string json = JsonConvert.SerializeObject(butt); await FileIO.WriteTextAsync(sampleFile, json); } } }