/// <summary> /// Saves the Document to the given Stream with the default and given headers, and /// using the given IO completion callback. /// </summary> /// <param name="stream">The Stream to serialize the Document to.</param> /// <param name="callback"> /// This can be used to keep track of the number of uncompressed bytes that are written. The /// values reported through the IOEventArgs.Count+Offset will vary from 1 to approximately /// Layers.Count*Width*Height*sizeof(ColorBgra). The final number will actually be higher /// because of hierarchical overhead, so make sure to cap any progress reports to 100%. This /// callback will be wired to the IOFinished event of a SiphonStream. Events may be raised /// from any thread. May be null. /// </param> public void SaveToStream(Stream stream, IOEventHandler callback) { PrepareHeader(); string headerText = this.HeaderXml.OuterXml; // Write the header byte[] magicBytes = Document.MagicBytes; stream.Write(magicBytes, 0, magicBytes.Length); byte[] headerBytes = Encoding.UTF8.GetBytes(headerText); stream.WriteByte((byte)(headerBytes.Length & 0xff)); stream.WriteByte((byte)((headerBytes.Length & 0xff00) >> 8)); stream.WriteByte((byte)((headerBytes.Length & 0xff0000) >> 16)); stream.Write(headerBytes, 0, headerBytes.Length); stream.Flush(); // Copy version info this.savedWith = PdnInfo.GetVersion(); // Write 0x00, 0x01 to indicate normal .NET serialized data stream.WriteByte(0x00); stream.WriteByte(0x01); // Write the remainder of the file (gzip compressed) SiphonStream siphonStream = new SiphonStream(stream); BinaryFormatter formatter = new BinaryFormatter(); DeferredFormatter deferred = new DeferredFormatter(true, null); SaveProgressRelay relay = new SaveProgressRelay(deferred, callback); formatter.Context = new StreamingContext(formatter.Context.State, deferred); formatter.Serialize(siphonStream, this); deferred.FinishSerialization(siphonStream); stream.Flush(); }
/// <summary> /// Returns a version string that is presentable without the Paint.NET name. example: "version 2.5 Beta 5" /// </summary> /// <returns></returns> public static string GetFriendlyVersionString() { Version version = PdnInfo.GetVersion(); string versionFormat = PdnResources.GetString("PdnInfo.FriendlyVersionString.Format"); string configFormat = PdnResources.GetString("PdnInfo.FriendlyVersionString.ConfigWithSpace.Format"); string config = string.Format(configFormat, "???"); string configText = config; string versionText = string.Format(versionFormat, GetVersionNumberString(version, 2), configText); return(versionText); }