예제 #1
0
파일: WzXml.cs 프로젝트: odasm/WZ-Dumper
        private void WriteSoundProp(string wzPath, WzSoundProperty soundProp, AWzObject uol, bool uolDirCopy, string overridePath)
        {
            string fileName    = CleanFileName(uol != null && !uolDirCopy ? uol.Name : soundProp.Name);
            string newFilePath = overridePath ?? Path.Combine(ExtractPath, wzPath, fileName + ".mp3");

            CreateDirectory(ref wzPath);
            Form.UpdateToolstripStatus("Dumping " + soundProp.Name + ".mp3 to " + wzPath);
            using (var stream = new FileStream(newFilePath, FileMode.Create, FileAccess.Write)) {
                stream.Write(soundProp.GetBytes(), 0, soundProp.GetBytes().Length);
            }
        }
        public WzMp3Streamer(WzSoundProperty sound, bool repeat)
        {
            this.repeat = repeat;
            this.sound  = sound;
            byteStream  = new MemoryStream(sound.GetBytes(false));

            wavePlayer = new WaveOut(WaveCallbackInfo.FunctionCallback());
            try
            {
                mpegStream = new Mp3FileReader(byteStream);
                wavePlayer.Init(mpegStream);
            }
            catch (System.InvalidOperationException)
            {
                try
                {
                    waveFileStream = new WaveFileReader(byteStream);
                    wavePlayer.Init(waveFileStream);
                }
                catch (FormatException)
                {
                    playbackSuccessfully = false;
                }
                //InvalidDataException
            }
            wavePlayer.PlaybackStopped += new EventHandler <StoppedEventArgs>(wavePlayer_PlaybackStopped);
        }
예제 #3
0
 public WzMp3Streamer(WzSoundProperty sound, bool repeat)
 {
     this.repeat = repeat;
     this.sound  = sound;
     byteStream  = new MemoryStream(sound.GetBytes(false));
     mpegStream  = new Mp3FileReader(byteStream);
     wavePlayer  = new WaveOut(WaveCallbackInfo.FunctionCallback());
     wavePlayer.Init(mpegStream);
     wavePlayer.PlaybackStopped += new EventHandler(wavePlayer_PlaybackStopped);
 }
예제 #4
0
 protected void WritePropertyToXML(TextWriter tw, string depth, WzImageProperty prop)
 {
     if (prop is WzCanvasProperty)
     {
         WzCanvasProperty property3 = (WzCanvasProperty)prop;
         if (ExportBase64Data)
         {
             MemoryStream stream = new MemoryStream();
             property3.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
             byte[] pngbytes = stream.ToArray();
             stream.Close();
             tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\" basedata=\"", Convert.ToBase64String(pngbytes), "\">" }) + lineBreak);
         }
         else
         {
             tw.Write(string.Concat(new object[] { depth, "<canvas name=\"", XmlUtil.SanitizeText(property3.Name), "\" width=\"", property3.PngProperty.Width, "\" height=\"", property3.PngProperty.Height, "\">" }) + lineBreak);
         }
         string newDepth = depth + indent;
         foreach (WzImageProperty property in property3.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</canvas>" + lineBreak);
     }
     else if (prop is WzIntProperty)
     {
         WzIntProperty property4 = (WzIntProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<int name=\"", XmlUtil.SanitizeText(property4.Name), "\" value=\"", property4.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzDoubleProperty)
     {
         WzDoubleProperty property5 = (WzDoubleProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<double name=\"", XmlUtil.SanitizeText(property5.Name), "\" value=\"", property5.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzNullProperty)
     {
         WzNullProperty property6 = (WzNullProperty)prop;
         tw.Write(depth + "<null name=\"" + XmlUtil.SanitizeText(property6.Name) + "\"/>" + lineBreak);
     }
     else if (prop is WzSoundProperty)
     {
         WzSoundProperty property7 = (WzSoundProperty)prop;
         if (ExportBase64Data)
         {
             tw.Write(string.Concat(new object[] { depth, "<sound name=\"", XmlUtil.SanitizeText(property7.Name), "\" length=\"", property7.Length.ToString(), "\" basehead=\"", Convert.ToBase64String(property7.Header), "\" basedata=\"", Convert.ToBase64String(property7.GetBytes(false)), "\"/>" }) + lineBreak);
         }
         else
         {
             tw.Write(depth + "<sound name=\"" + XmlUtil.SanitizeText(property7.Name) + "\"/>" + lineBreak);
         }
     }
     else if (prop is WzStringProperty)
     {
         WzStringProperty property8 = (WzStringProperty)prop;
         string           str       = XmlUtil.SanitizeText(property8.Value);
         tw.Write(depth + "<string name=\"" + XmlUtil.SanitizeText(property8.Name) + "\" value=\"" + str + "\"/>" + lineBreak);
     }
     else if (prop is WzSubProperty)
     {
         WzSubProperty property9 = (WzSubProperty)prop;
         tw.Write(depth + "<imgdir name=\"" + XmlUtil.SanitizeText(property9.Name) + "\">" + lineBreak);
         string newDepth = depth + indent;
         foreach (WzImageProperty property in property9.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</imgdir>" + lineBreak);
     }
     else if (prop is WzShortProperty)
     {
         WzShortProperty property10 = (WzShortProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<short name=\"", XmlUtil.SanitizeText(property10.Name), "\" value=\"", property10.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzLongProperty)
     {
         WzLongProperty long_prop = (WzLongProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<long name=\"", XmlUtil.SanitizeText(long_prop.Name), "\" value=\"", long_prop.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzUOLProperty)
     {
         WzUOLProperty property11 = (WzUOLProperty)prop;
         tw.Write(depth + "<uol name=\"" + property11.Name + "\" value=\"" + XmlUtil.SanitizeText(property11.Value) + "\"/>" + lineBreak);
     }
     else if (prop is WzVectorProperty)
     {
         WzVectorProperty property12 = (WzVectorProperty)prop;
         tw.Write(string.Concat(new object[] { depth, "<vector name=\"", XmlUtil.SanitizeText(property12.Name), "\" x=\"", property12.X.Value, "\" y=\"", property12.Y.Value, "\"/>" }) + lineBreak);
     }
     else if (prop is WzFloatProperty)
     {
         WzFloatProperty property13 = (WzFloatProperty)prop;
         string          str2       = Convert.ToString(property13.Value, formattingInfo);
         if (!str2.Contains("."))
         {
             str2 = str2 + ".0";
         }
         tw.Write(depth + "<float name=\"" + XmlUtil.SanitizeText(property13.Name) + "\" value=\"" + str2 + "\"/>" + lineBreak);
     }
     else if (prop is WzConvexProperty)
     {
         tw.Write(depth + "<extended name=\"" + XmlUtil.SanitizeText(prop.Name) + "\">" + lineBreak);
         WzConvexProperty property14 = (WzConvexProperty)prop;
         string           newDepth   = depth + indent;
         foreach (WzImageProperty property in property14.WzProperties)
         {
             WritePropertyToXML(tw, newDepth, property);
         }
         tw.Write(depth + "</extended>" + lineBreak);
     }
 }
예제 #5
0
파일: WZXML.cs 프로젝트: xnum/hasuite
 private static void DumpXML(TextWriter tw, string depth, List <IWzImageProperty> props)
 {
     foreach (IWzImageProperty property in props)
     {
         if (property != null)
         {
             if (property is WzCanvasProperty)
             {
                 WzCanvasProperty canvas = (WzCanvasProperty)property;
                 MemoryStream     stream = new MemoryStream();
                 canvas.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                 byte[] pngbytes = stream.ToArray();
                 stream.Close();
                 tw.WriteLine(string.Concat(new object[] { depth, "<canvas name=\"", canvas.Name, "\" width=\"", canvas.PngProperty.Width, "\" height=\"", canvas.PngProperty.Height, "\" basedata=\"", Convert.ToBase64String(pngbytes), "\">" }));
                 DumpXML(tw, depth + indent, canvas.WzProperties);
                 tw.WriteLine(depth + "</canvas>");
             }
             else if (property is WzCompressedIntProperty)
             {
                 WzCompressedIntProperty compressedInt = (WzCompressedIntProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<int name=\"", compressedInt.Name, "\" value=\"", compressedInt.Value, "\"/>" }));
             }
             else if (property is WzDoubleProperty)
             {
                 WzDoubleProperty doubleProp = (WzDoubleProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<double name=\"", doubleProp.Name, "\" value=\"", doubleProp.Value.ToString(formattingInfo), "\"/>" }));
             }
             else if (property is WzNullProperty)
             {
                 WzNullProperty nullProp = (WzNullProperty)property;
                 tw.WriteLine(depth + "<null name=\"" + nullProp.Name + "\"/>");
             }
             else if (property is WzSoundProperty)
             {
                 WzSoundProperty sound = (WzSoundProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<sound name=\"", sound.Name, "\" basedata=\"", Convert.ToBase64String(sound.GetBytes(false)), "\"/>" }));
             }
             else if (property is WzStringProperty)
             {
                 WzStringProperty stringProp = (WzStringProperty)property;
                 string           str        = stringProp.Value.Replace("<", "&lt;").Replace("&", "&amp;").Replace(">", "&gt;").Replace("'", "&apos;").Replace("\"", "&quot;");
                 tw.WriteLine(depth + "<string name=\"" + stringProp.Name + "\" value=\"" + str + "\"/>");
             }
             else if (property is WzSubProperty)
             {
                 WzSubProperty sub = (WzSubProperty)property;
                 tw.WriteLine(depth + "<imgdir name=\"" + sub.Name + "\">");
                 DumpXML(tw, depth + indent, sub.WzProperties);
                 tw.WriteLine(depth + "</imgdir>");
             }
             else if (property is WzUnsignedShortProperty)
             {
                 WzUnsignedShortProperty ushortProp = (WzUnsignedShortProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<short name=\"", ushortProp.Name, "\" value=\"", ushortProp.Value.ToString(formattingInfo), "\"/>" }));
             }
             else if (property is WzUOLProperty)
             {
                 WzUOLProperty uol = (WzUOLProperty)property;
                 tw.WriteLine(depth + "<uol name=\"" + uol.Name + "\" value=\"" + uol.Value + "\"/>");
             }
             else if (property is WzVectorProperty)
             {
                 WzVectorProperty vector = (WzVectorProperty)property;
                 tw.WriteLine(string.Concat(new object[] { depth, "<vector name=\"", vector.Name, "\" x=\"", vector.X.Value, "\" y=\"", vector.Y.Value, "\"/>" }));
             }
             else if (property is WzByteFloatProperty)
             {
                 WzByteFloatProperty floatProp = (WzByteFloatProperty)property;
                 string str2 = floatProp.Value.ToString(formattingInfo);
                 if (!str2.Contains("."))
                 {
                     str2 = str2 + ".0";
                 }
                 tw.WriteLine(depth + "<float name=\"" + floatProp.Name + "\" value=\"" + str2 + "\"/>");
             }
             else if (property is WzConvexProperty)
             {
                 tw.WriteLine(depth + "<extended name=\"" + property.Name + "\">");
                 DumpXML(tw, depth + indent, ((WzConvexProperty)property).WzProperties);
                 tw.WriteLine(depth + "</extended>");
             }
         }
     }
 }
예제 #6
0
 // TODO: this is not deserializable due to missing type information
 protected void WritePropertyToJson(TextWriter tw, WzImageProperty prop, bool isArray = false)
 {
     tw.Write("\n");
     if (prop is WzCanvasProperty)
     {
         WzCanvasProperty property = (WzCanvasProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         if (ExportBase64Data)
         {
             MemoryStream stream = new MemoryStream();
             property.PngProperty.GetPNG(false).Save(stream, System.Drawing.Imaging.ImageFormat.Png);
             byte[] pngbytes = stream.ToArray();
             stream.Close();
             tw.Write($"{{" +
                      $"\"width\": {property.PngProperty.Width}, " +
                      $"\"height\": {property.PngProperty.Height}, " +
                      $"\"basedata\": {Convert.ToBase64String(pngbytes)}\",");
         }
         else
         {
             tw.Write($"{{" +
                      $"\"width\": {property.PngProperty.Width}, " +
                      $"\"height\": {property.PngProperty.Height},");
         }
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 WritePropertyToJson(tw, p);
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write("}");
     }
     else if (prop is WzIntProperty)
     {
         WzIntProperty property = (WzIntProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzDoubleProperty)
     {
         WzDoubleProperty property = (WzDoubleProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzNullProperty)
     {
         WzNullProperty property = (WzNullProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": null");
     }
     else if (prop is WzSoundProperty)
     {
         WzSoundProperty property = (WzSoundProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         if (ExportBase64Data)
         {
             tw.Write($"{{" +
                      $"\"length\":\"{property.Length}\", " +
                      $"\"basehead\": \"{Convert.ToBase64String(property.Header)}\"" +
                      $"\"basedata\": \"{Convert.ToBase64String(property.GetBytes(false))}\"" +
                      $"}}");
         }
         else
         {
             tw.Write("{}");
         }
     }
     else if (prop is WzStringProperty)
     {
         WzStringProperty property = (WzStringProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {JsonConvert.ToString(property.Value)}");
     }
     else if (prop is WzSubProperty)
     {
         WzSubProperty property = (WzSubProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         // This has the same problem as the convex property
         bool propertyIsArray = property.WzProperties.TrueForAll(x => { int num; return(int.TryParse(x.Name, out num)); });
         tw.Write(propertyIsArray ? "[" : "{");
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 bool isObject = p is WzConvexProperty || p is WzSubProperty || p is WzSoundProperty || p is WzCanvasProperty || p is WzVectorProperty;
                 if (propertyIsArray)
                 {
                     tw.Write($"{{\"index\":{p.Name}, \"item\":");
                     tw.Write(!isObject ? "{" : "");
                 }
                 WritePropertyToJson(tw, p, propertyIsArray);
                 if (propertyIsArray)
                 {
                     tw.Write(!isObject ? "}" : "");
                     tw.Write("}");
                 }
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write(propertyIsArray ? "]" : "}");
     }
     else if (prop is WzShortProperty)
     {
         WzShortProperty property = (WzShortProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzLongProperty)
     {
         WzLongProperty property = (WzLongProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value}");
     }
     else if (prop is WzUOLProperty)
     {
         WzUOLProperty property = (WzUOLProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": \"{property.Value}\"");
     }
     else if (prop is WzVectorProperty)
     {
         WzVectorProperty property = (WzVectorProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         tw.Write($"{{" +
                  $"\"x\": {property.X.Value}, " +
                  $"\"y\": {property.Y.Value}" +
                  $"}}");
     }
     else if (prop is WzFloatProperty)
     {
         WzFloatProperty property = (WzFloatProperty)prop;
         tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\": {property.Value * 1.0}");
     }
     else if (prop is WzConvexProperty)
     {
         WzConvexProperty property = (WzConvexProperty)prop;
         if (!isArray)
         {
             tw.Write($"\"{XmlUtil.SanitizeText(property.Name)}\":");
         }
         tw.Write("[");
         if (property.WzProperties.Count() > 0)
         {
             var last = property.WzProperties.Last();
             foreach (WzImageProperty p in property.WzProperties)
             {
                 bool isObject = p is WzConvexProperty || p is WzSubProperty || p is WzSoundProperty || p is WzCanvasProperty || p is WzVectorProperty;
                 tw.Write(isObject ? "" : "{");
                 WritePropertyToJson(tw, p, true);
                 tw.Write(isObject ? "" : "}");
                 if (!p.Equals(last))
                 {
                     tw.Write(",");
                 }
             }
         }
         tw.Write("]");
     }
 }