Author: pbartok
Date: 2005-05-13 04:49:08 -0400 (Fri, 13 May 2005)
New Revision: 44488

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Resources/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs
Log:
2005-05-13  Peter Bartok  <[EMAIL PROTECTED]>

        * ResXResourceWriter.cs: 
          - Fixed/Improved AddResource(), now only uses string converter if 
            the converter supports both directions
          - Added ability for AddResource(string, object) to detect if
            a byte[] converter is supported for the object, if so it now calls
            AddResource(string, byte[]) for those
          - WriteBytes: Changed to write it's base64 output as pretty 
            as Microsoft's, inserting newlines every 80 chars
          - WriteBytes: Added output of mimetype even if type is specified



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Resources/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Resources/ChangeLog    
2005-05-13 07:42:28 UTC (rev 44487)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Resources/ChangeLog    
2005-05-13 08:49:08 UTC (rev 44488)
@@ -1,3 +1,15 @@
+2005-05-13  Peter Bartok  <[EMAIL PROTECTED]>
+
+       * ResXResourceWriter.cs: 
+         - Fixed/Improved AddResource(), now only uses string converter if 
+           the converter supports both directions
+         - Added ability for AddResource(string, object) to detect if
+           a byte[] converter is supported for the object, if so it now calls
+           AddResource(string, byte[]) for those
+         - WriteBytes: Changed to write it's base64 output as pretty 
+           as Microsoft's, inserting newlines every 80 chars
+         - WriteBytes: Added output of mimetype even if type is specified
+
 2005-05-11  Peter Bartok  <[EMAIL PROTECTED]>
 
        * ResXResourceSet.cs: Implemented

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs
===================================================================
--- 
trunk/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs    
    2005-05-13 07:42:28 UTC (rev 44487)
+++ 
trunk/mcs/class/Managed.Windows.Forms/System.Resources/ResXResourceWriter.cs    
    2005-05-13 08:49:08 UTC (rev 44488)
@@ -116,19 +116,45 @@
                        writer.WriteEndElement ();
                }
 
+               void WriteNiceBase64(byte[] value, int offset, int length) {
+                       string          b64;
+                       StringBuilder   sb;
+                       int             pos;
+                       int             inc;
+                       string          ins;
+
+                       b64 = Convert.ToBase64String(value, offset, length);
+
+                       // Wild guess; two extra newlines, and one newline/tab 
pair for every 80 chars
+                       sb = new StringBuilder(b64, b64.Length + ((b64.Length + 
160) / 80) * 3);
+                       pos = 0;
+                       inc = 80 + Environment.NewLine.Length + 1;
+                       ins = Environment.NewLine + "\t";
+                       while (pos < sb.Length) {
+                               sb.Insert(pos, ins);
+                               pos += inc;
+                       }
+                       sb.Insert(sb.Length, Environment.NewLine);
+                       writer.WriteString(sb.ToString());
+               }
+
                void WriteBytes (string name, string typename, byte [] value, 
int offset, int length)
                {
                        writer.WriteStartElement ("data");
                        writer.WriteAttributeString ("name", name);
+
                        if (typename != null) {
                                writer.WriteAttributeString ("type", typename);
+                               writer.WriteAttributeString ("mimetype", 
"application/x-microsoft.net.object.bytearray.base64");
+                               writer.WriteStartElement ("value");
+                               WriteNiceBase64(value, offset, length);
                        } else {
                                writer.WriteAttributeString ("mimetype",
                                                
"application/x-microsoft.net.object.binary.base64");
+                               writer.WriteStartElement ("value");
+                               writer.WriteBase64 (value, offset, length);
                        }
 
-                       writer.WriteStartElement ("value");
-                       writer.WriteBase64 (value, offset, length);
                        writer.WriteEndElement ();
                        writer.WriteEndElement ();
                }
@@ -181,12 +207,18 @@
                                InitWriter ();
 
                        TypeConverter converter = TypeDescriptor.GetConverter 
(value);
-                       if (converter != null && converter.CanConvertTo (typeof 
(string))) {
+                       if (converter != null && converter.CanConvertTo (typeof 
(string)) && converter.CanConvertFrom (typeof (string))) {
                                string str = (string) converter.ConvertTo 
(value, typeof (string));
                                WriteString (name, str);
                                return;
                        }
                        
+                       if (converter != null && converter.CanConvertTo (typeof 
(byte[])) && converter.CanConvertFrom (typeof (byte[]))) {
+                               byte[] b = (byte[]) converter.ConvertTo (value, 
typeof (byte[]));
+                               WriteBytes (name, 
value.GetType().AssemblyQualifiedName, b);
+                               return;
+                       }
+                       
                        MemoryStream ms = new MemoryStream ();
                        BinaryFormatter fmt = new BinaryFormatter ();
                        try {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to