Ejemplo n.º 1
0
        public void Save(Stream Target,SaveFormatInfo Format,StreamProgress.ProgressFunction pfunction)
        {
            SerializationInfo sinfo;
            try
            {

                Stream outstream = Target;
                {
                    using (StreamProgress sp = new StreamProgress(outstream, pfunction))
                    {
                        if (Format is BinarySaveFormatInfo)
                        {
                            BinarySaveFormatInfo BinInfo = Format as BinarySaveFormatInfo;
                            //write out whether this is compressed.
                            IFormatter binformatter = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_Binary);
                            outstream.WriteByte((byte)(BinInfo.CompressionType != CompressionTypeConstants.Compression_None ? 1 : 0));
                            Stream targetstream;
                            switch (BinInfo.CompressionType)
                            {
                            case CompressionTypeConstants.Compression_GZip:
                                targetstream = new GZipStream(outstream, CompressionMode.Compress);
                                break;
                            case CompressionTypeConstants.Compression_Deflate:
                                targetstream = new DeflateStream(outstream, CompressionMode.Compress, CompressionLevel.BestCompression);
                                break;
                            default:
                                targetstream = outstream;
                                break;
                            }
                            using (targetstream)
                            {
                                Cursor.Current = Cursors.WaitCursor;
                                binformatter.Serialize(targetstream, this);
                                targetstream.Close();
                                Cursor.Current = Cursors.Default;
                            }
                        }
                        else if(Format is XmlSaveFormatInfo)
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            //almost forgot to change this code to save to XML properly. the SOAP stuff, we have to remove at some stage...
                            XElement BuildElement = this.GetXmlData("EditorSet",null);
                            XDocument buildDocument = new XDocument(BuildElement);

                            buildDocument.Save(outstream,SaveOptions.OmitDuplicateNamespaces);

                            /*IFormatter xmlformat = BCBlockGameState.getFormatter<EditorSet>(BCBlockGameState.DataSaveFormats.Format_XML);
                            Cursor.Current = Cursors.WaitCursor;
                            xmlformat.Serialize(outstream,this);*/
                        }

                    }
                }

            }
            catch (Exception e)
            {
                Debug.Print("Exception in EditorSet.Save:" + e.ToString());

            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Ejemplo n.º 2
0
 public void Save(String sTarget,SaveFormatInfo Format,StreamProgress.ProgressFunction pfunction)
 {
     //if(!File.Exists(sTarget)) throw new FileNotFoundException(sTarget);
     using (FileStream fs = new FileStream(sTarget, FileMode.Create))
     {
         Save(fs, Format, pfunction);
     }
 }