/// <summary>Closes the writer and the stream.</summary> public void Close() { if (writer != null) { writer.Close(); writer = null; } }
public static void Save(string filePath, Dictionary <string, object> values) { string json = Json.Serialize(values); var file = new DataWriter(filePath); file.Write(Hash(json)); file.Write(json); file.Close(); }
/// <summary>Closes the writer and the stream.</summary> public void Close() { if (CloseBaseStream) { writer?.Close(); } writer = null; }
/// <summary>Disposes this instance.</summary> public void Dispose() { if (stream == null) { throw new ObjectDisposedException("NamedPipeWriter"); } writer.Close(); writer = null; stream = null; GC.SuppressFinalize(this); }
private void writeChar() { DataWriter dw = initPofWriter("Char"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteChar(0, 'f'); psw.WriteChar(0, '0'); dw.Flush(); dw.Close(); }
private void Setup(CharacterEntity character, PlaneEntity vehicle) { DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteLong(character.EID); dw.WriteByte(2); // TODO: Enum? dw.WriteLong(vehicle.EID); dw.Flush(); Data = ds.ToArray(); dw.Close(); }
private void writeInt64() { DataWriter dw = initPofWriter("Int64"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteInt64(0, -1L); psw.WriteInt64(0, Int64.MaxValue); dw.Flush(); dw.Close(); }
private void writeDecimal32() { DataWriter dw = initPofWriter("Dec32"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, new Decimal(99999, 0, 0, false, 0)); psw.WriteDecimal(0, new Decimal(9999999, 0, 0, false, 0)); psw.WriteDecimal(0, new Decimal(9999999, 0, 0, false, 28)); dw.Flush(); dw.Close(); }
/*---------Utility methods for writing POF data----------------------*/ private void writeByte() { DataWriter dw = initPofWriter("Byte"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteByte(0, 1); psw.WriteByte(0, 0); psw.WriteByte(0, 200); psw.WriteByte(0, 255); dw.Flush(); dw.Close(); }
private void writeDecimal64() { DataWriter dw = initPofWriter("Dec64"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, new Decimal(9999999999)); Decimal d2 = new Decimal(9999999999999999); psw.WriteDecimal(0, d2); int[] value = Decimal.GetBits(d2); psw.WriteDecimal(0, new Decimal(value[0], value[1], value[3], false, 28)); dw.Flush(); dw.Close(); }
private void writeDecimal128() { DataWriter dw = initPofWriter("Dec128"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, Decimal.MaxValue); Decimal d1 = Decimal.Add(new Decimal(Int64.MaxValue), Decimal.One); psw.WriteDecimal(0, d1); // Scale the maximum integer plus one value int[] value = Decimal.GetBits(d1); psw.WriteDecimal(0, new Decimal(value[0], value[1], value[3], false, 28)); dw.Flush(); dw.Close(); }
private void WriteControlFile(TarWriter tarFile, string fileName, int fileMode) { SystemConsole.WriteLine(" file: <cyan>{0}", fileName); using (MemoryStream ms = new MemoryStream()) { DataWriter writer = new DataWriter(ms); foreach (string line in ini.ReadSection("control.tgz:" + fileName, false)) { if (string.IsNullOrWhiteSpace(line)) { continue; } string text = line.Replace("{NAME}", packageName).Replace("{VERSION}", packageVersion.ToString()); writer.WriteLine(text); } writer.Close(); byte[] data = ms.ToArray(); tarFile.AddFile(fileName, data); } }
public AddCloudPacketOut(Cloud cloud) { UsageType = NetUsageType.CLOUDS; ID = ServerToClientPacket.ADD_CLOUD; DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteBytes(cloud.Position.ToDoubleBytes()); dw.WriteBytes((cloud.Velocity + cloud.TheRegion.Wind).ToDoubleBytes()); dw.WriteLong(cloud.CID); dw.WriteInt(cloud.Points.Count); for (int i = 0; i < cloud.Points.Count; i++) { dw.WriteBytes(cloud.Points[i].ToDoubleBytes()); dw.WriteFloat((float)cloud.Sizes[i]); dw.WriteFloat((float)cloud.EndSizes[i]); } dw.Flush(); Data = ds.ToArray(); dw.Close(); }
private void Setup(CharacterEntity character, CarEntity vehicle) { DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteLong(character.EID); dw.WriteByte(0); // TODO: Enum? dw.WriteInt(vehicle.DrivingMotors.Count); dw.WriteInt(vehicle.SteeringMotors.Count); for (int i = 0; i < vehicle.DrivingMotors.Count; i++) { dw.WriteLong(vehicle.DrivingMotors[i].JID); } for (int i = 0; i < vehicle.SteeringMotors.Count; i++) { dw.WriteLong(vehicle.SteeringMotors[i].JID); } dw.Flush(); Data = ds.ToArray(); dw.Close(); }
/// <summary> /// LIST. /// </summary> /// <remarks> /// This command causes a list to be sent from the server to the /// passive DTP. If the pathname specifies a directory or other /// group of files, the server should transfer a list of files /// in the specified directory. If the pathname specifies a /// file then the server should send current information on the /// file. A null argument implies the user's current working or /// default directory. The data transfer is over the data /// connection in type ASCII or type EBCDIC. (The user must /// ensure that the TYPE is appropriately ASCII or EBCDIC). /// Since the information on a file may vary widely from system /// to system, this information may be hard to use automatically /// in a program, but may be quite useful to a human user. /// </remarks> void LIST(string args) { if (!CheckLogin()) { return; } //get entries if (!GetDirectoryEntries(out FtpDirectoryEntry[] entries)) { return; } //get connection if (!GetDataConnection(out TcpClient tcpClient)) { return; } //send data try { using (Stream s = tcpClient.GetStream()) { DataWriter dataWriter = new DataWriter(s, newLineMode: NewLineMode.CRLF); foreach (FtpDirectoryEntry entry in entries) { dataWriter.WriteLine(entry.ToString()); Trace.TraceInformation("{0}: {1}", tcpClient.Client.RemoteEndPoint, entry); } dataWriter.Flush(); dataWriter.Close(); SendAnswer("226 Transfer complete"); } } catch { tcpClient.Close(); SendAnswer("426 Connection closed; transfer aborted."); } }
private void writeInt128() { DataWriter dw = initPofWriter("Int128"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); // Test data: // First byte array is equivalent to BigInteger.TEN byte[] b1 = { 0x0a }; // Second byte array is equivalent to BigInteger("55 5555 5555 5555 5555") // (spaces are there for human parsing). // Equivalent to hex: 0x 07 b5 ba d5 95 e2 38 e3 byte[] b2 = { 0x07, 0xb5, 0xba, 0xd5, 0x95, 0xe2, 0x38, 0xe3 }; RawInt128 rawInt1 = new RawInt128(b1); RawInt128 rawInt2 = new RawInt128(b2); psw.WriteRawInt128(0, rawInt1); psw.WriteRawInt128(0, rawInt2); dw.Flush(); dw.Close(); }
public void Save(string newFilename = null) { //This always saves in little-endian format: //- Metadata will always be little-endian. //- Header will always be big-endian as per the file format. //- Object Data follows this.IsLittleEndian #region Metadata List <byte> metadataSection = new List <byte>(); DataWriter metadataWriter = DataWriter.FromList(metadataSection, true); #region Class Hierarchy Descriptor if (FormatVersion > 7) { metadataWriter.WriteString(UnityVersion); metadataWriter.WriteInt32(RTTIAttributes); } metadataWriter.WriteInt32(BaseClasses.Count); foreach (int baseClass in BaseClasses.Keys) { metadataWriter.WriteInt32(baseClass); BaseClasses[baseClass].Write(metadataWriter); } if (FormatVersion > 7) { metadataWriter.WriteBytes(new byte[] { 0, 0, 0, 0 }); } #endregion metadataWriter.WriteInt32(Objects.Count); int currentOffset = 0; foreach (ObjectData od in Objects) { od.Write(metadataWriter, currentOffset, FormatVersion > 13); metadataWriter.WriteInt64(0); currentOffset += od.Bytes.Length + 8; } metadataWriter.WriteInt32(ExternalFiles.Count); foreach (FileIdentifier f in ExternalFiles) { f.Write(metadataWriter, FormatVersion > 5); } metadataWriter.WriteByte(0); #endregion #region Header and Object Data DataWriter fileWriter = DataWriter.OpenFile(newFilename == null ? filename : newFilename, false); fileWriter.WriteInt32(metadataSection.Count); int headerSize = 16 + (FormatVersion > 8 ? 4 : 0); fileWriter.WriteInt32(metadataSection.Count + currentOffset + headerSize); fileWriter.WriteInt32(FormatVersion); if (FormatVersion > 8) { fileWriter.WriteInt32(headerSize + metadataSection.Count); fileWriter.WriteByte(IsLittleEndian ? (byte)0 : (byte)1); fileWriter.WriteBytes(new byte[] { 0, 0, 0 }); fileWriter.IsLittleEndian = IsLittleEndian; fileWriter.WriteBytes(metadataSection.ToArray()); foreach (ObjectData od in Objects) { fileWriter.WriteBytes(od.Bytes); } } else { fileWriter.WriteInt32(headerSize); fileWriter.IsLittleEndian = IsLittleEndian; foreach (ObjectData od in Objects) { fileWriter.WriteBytes(od.Bytes); } fileWriter.WriteBytes(metadataSection.ToArray()); } #endregion fileWriter.Close(); }
void Build() { int debberVer = 0; ini.GetValue("debber", "debber-version", ref debberVer); if (debberVer != 1) { throw new Exception("File requires a newer debber version. Please update!"); } string binVer = ini.ReadSetting("debber", "debian-binary"); if (binVer != "2.0") { throw new Exception("Invalid or unknown debian version!"); } packageVersion = SemanticVersion.Parse(ini.ReadSetting("package", "version")); packageName = ini.ReadSetting("package", "name"); packageFile = ini.ReadSetting("package", "output").Replace("{NAME}", packageName).Replace("{VERSION}", packageVersion.ToString()); FileSystem.TouchFile(packageFile); SystemConsole.WriteLine("Create <cyan>data.tar.gz<default>..."); byte[] data_tar_gz; using (MemoryStream ms = new MemoryStream()) { TarWriter tarFile = new TarWriter(ms, true); foreach (string line in ini.ReadSection("data.tgz", true)) { string[] parts = line.Split(':'); if (parts.Length < 2) { continue; } switch (parts[0].Trim()) { case "directory": PackDirectory(tarFile, parts[1]); break; case "file": PackFiles(tarFile, parts); break; default: throw new Exception(string.Format("Invalid setting {0} at [data.tgz]!", line)); } } tarFile.Close(); data_tar_gz = ms.ToArray(); } SystemConsole.WriteLine("Create <cyan>control.tar.gz<default>..."); byte[] control_tar_gz; using (MemoryStream tarStream = new MemoryStream()) { TarWriter tarFile = new TarWriter(tarStream, true); WriteControlFile(tarFile, "control", 640); #region md5sums using (MemoryStream ms = new MemoryStream()) { DataWriter writer = new DataWriter(ms); foreach (KeyValuePair <string, string> md5sum in md5sums) { writer.Write(md5sum.Value); writer.Write(" "); writer.Write(md5sum.Key); writer.Write("\n"); } writer.Close(); SystemConsole.WriteLine(" file: <cyan>md5sums"); tarFile.AddFile("md5sums", ms.ToArray()); } #endregion WriteControlFile(tarFile, "conffiles", 640); WriteControlFile(tarFile, "preinst", 700); WriteControlFile(tarFile, "postinst", 700); WriteControlFile(tarFile, "prerm", 700); WriteControlFile(tarFile, "postrm", 700); tarFile.Close(); control_tar_gz = tarStream.ToArray(); } using (MemoryStream ms = new MemoryStream()) { var arFile = ArFile.CreateNewAr(ms); arFile.WriteHeader(ArHeader.CreateFile("debian-binary", 4)); arFile.WriteData(Encoding.ASCII.GetBytes("2.0\n")); arFile.WriteHeader(ArHeader.CreateFile("control.tar.gz", control_tar_gz.Length)); arFile.WriteData(control_tar_gz); arFile.WriteHeader(ArHeader.CreateFile("data.tar.gz", data_tar_gz.Length)); arFile.WriteData(data_tar_gz); arFile.Close(); File.WriteAllBytes(packageFile, ms.ToArray()); SystemConsole.WriteLine("Completed <green>{0}<default> ...", packageFile); } }
public byte[] GetCharacterNetData() { DataStream ds = new DataStream(); DataWriter dr = new DataWriter(ds); dr.WriteBytes(GetPosition().ToDoubleBytes()); Quaternion quat = GetOrientation(); dr.WriteFloat((float)quat.X); dr.WriteFloat((float)quat.Y); dr.WriteFloat((float)quat.Z); dr.WriteFloat((float)quat.W); dr.WriteFloat((float)GetMass()); dr.WriteFloat((float)CBAirForce); dr.WriteFloat((float)CBAirSpeed); dr.WriteFloat((float)CBCrouchSpeed); dr.WriteFloat((float)CBDownStepHeight); dr.WriteFloat((float)CBGlueForce); dr.WriteFloat((float)CBHHeight); dr.WriteFloat((float)CBJumpSpeed); dr.WriteFloat((float)CBMargin); dr.WriteFloat((float)CBMaxSupportSlope); dr.WriteFloat((float)CBMaxTractionSlope); dr.WriteFloat((float)CBProneSpeed); dr.WriteFloat((float)CBRadius); dr.WriteFloat((float)CBSlideForce); dr.WriteFloat((float)CBSlideJumpSpeed); dr.WriteFloat((float)CBSlideSpeed); dr.WriteFloat((float)CBStandSpeed); dr.WriteFloat((float)CBStepHeight); dr.WriteFloat((float)CBTractionForce); dr.WriteFloat((float)mod_xrot); dr.WriteFloat((float)mod_yrot); dr.WriteFloat((float)mod_zrot); dr.WriteFloat((float)mod_scale); dr.WriteInt(mod_color.ToArgb()); byte dtx = 0; if (Visible) { dtx |= 1; } if (CGroup == CollisionUtil.Solid) { dtx |= 2; } else if (CGroup == CollisionUtil.NonSolid) { dtx |= 4; } else if (CGroup == CollisionUtil.Item) { dtx |= 2 | 4; } else if (CGroup == CollisionUtil.Player) { dtx |= 8; } else if (CGroup == CollisionUtil.Water) { dtx |= 2 | 8; } else if (CGroup == CollisionUtil.WorldSolid) { dtx |= 2 | 4 | 8; } else if (CGroup == CollisionUtil.Character) { dtx |= 16; } dr.Write(dtx); dr.WriteInt(TheServer.Networking.Strings.IndexForString(model)); dr.Flush(); byte[] Data = ds.ToArray(); dr.Close(); return(Data); }