Exemple #1
0
        /*public WzSoundProperty(string name)
         * {
         *  this.name = name;
         *  this.len_ms = 0;
         *  this.header = null;
         *  this.mp3bytes = null;
         * }*/

        /// <summary>
        /// Creates a WzSoundProperty with the specified name and data from another WzSoundProperty Object
        /// </summary>
        /// <param name="name"></param>
        /// <param name="wavFormat"></param>
        /// <param name="len_ms"></param>
        /// <param name="soundDataLen"></param>
        /// <param name="headerClone"></param>
        /// <param name="data"></param>
        /// <param name="headerEncrypted"></param>
        public WzSoundProperty(WzSoundProperty otherProperty)
        {
            this.name         = otherProperty.name;
            this.wavFormat    = otherProperty.wavFormat;
            this.len_ms       = otherProperty.len_ms;
            this.soundDataLen = otherProperty.soundDataLen;
            this.offs         = otherProperty.offs;

            if (otherProperty.header == null) // not initialized yet
            {
                otherProperty.ParseWzSoundPropertyHeader();
            }
            this.header = new byte[otherProperty.header.Length];
            Array.Copy(otherProperty.header, this.header, otherProperty.header.Length);

            if (otherProperty.mp3bytes == null)
            {
                this.mp3bytes = otherProperty.GetBytes(false);
            }
            else
            {
                this.mp3bytes = new byte[otherProperty.mp3bytes.Length];
                Array.Copy(otherProperty.mp3bytes, mp3bytes, otherProperty.mp3bytes.Length);
            }
            this.headerEncrypted = otherProperty.headerEncrypted;
        }
Exemple #2
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);
 }
Exemple #3
0
        public static WzSoundProperty CreateCustomProperty(string name, string file)
        {
            WzSoundProperty newProp = new WzSoundProperty(name);
            MP3Header       header  = new MP3Header();

            header.ReadMP3Information(file);
            newProp.mLenMs = header.intLength * 1000;
            byte[] frequencyBytes = BitConverter.GetBytes(header.intFrequency);
            byte[] headerBytes    = new byte[SoundHeaderMask.Length];
            Array.Copy(SoundHeaderMask, headerBytes, headerBytes.Length);
            for (int i = 0; i < 4; i++)
            {
                headerBytes[56 + i] = frequencyBytes[i];
            }
            newProp.mMp3bytes = WzTool.Combine(headerBytes, File.ReadAllBytes(file));
            return(newProp);
        }
        public override WzImageProperty DeepClone()
        {
            WzSoundProperty clone = new WzSoundProperty(name, len_ms, header, mp3bytes);

            return(clone);
        }
 internal static IExtended ExtractMore(WzBinaryReader reader, uint offset, int eob, string name, string iname, IWzObject parent, WzImage imgParent)
 {
     if (iname == "")
         iname = reader.ReadString();
     switch (iname)
     {
         case "Property":
             WzSubProperty subProp = new WzSubProperty(name) { Parent = parent };
             reader.BaseStream.Position += 2;
             subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
             return subProp;
         case "Canvas":
             WzCanvasProperty canvasProp = new WzCanvasProperty(name) { Parent = parent };
             reader.BaseStream.Position++;
             if (reader.ReadByte() == 1)
             {
                 reader.BaseStream.Position += 2;
                 canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
             }
             canvasProp.PngProperty = new WzPngProperty(reader, imgParent.parseEverything) { Parent = canvasProp };
             return canvasProp;
         case "Shape2D#Vector2D":
             WzVectorProperty vecProp = new WzVectorProperty(name) { Parent = parent };
             vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt()) { Parent = vecProp };
             vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt()) { Parent = vecProp };
             return vecProp;
         case "Shape2D#Convex2D":
             WzConvexProperty convexProp = new WzConvexProperty(name) { Parent = parent };
             int convexEntryCount = reader.ReadCompressedInt();
             convexProp.WzProperties.Capacity = convexEntryCount; //performance thing
             for (int i = 0; i < convexEntryCount; i++)
             {
                 convexProp.AddProperty(ParseExtendedProp(reader, offset, 0, name, convexProp, imgParent));
             }
             return convexProp;
         case "Sound_DX8":
             WzSoundProperty soundProp = new WzSoundProperty(name, reader, imgParent.parseEverything) { Parent = parent };
             return soundProp;
         case "UOL":
             reader.BaseStream.Position++;
             switch (reader.ReadByte())
             {
                 case 0:
                     return new WzUOLProperty(name, reader.ReadString()) { Parent = parent };
                 case 1:
                     return new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent };
             }
             throw new Exception("Unsupported UOL type");
         default:
             throw new Exception("Unknown iname: " + iname);
     }
 }
        internal IWzImageProperty ParsePropertyFromXMLElement(XmlElement element)
        {
            switch (element.Name)
            {
                case "imgdir":
                    WzSubProperty sub = new WzSubProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        sub.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return sub;

                case "canvas":
                    WzCanvasProperty canvas = new WzCanvasProperty(element.GetAttribute("name"));
                    if (!element.HasAttribute("basedata")) throw new NoBase64DataException("no base64 data in canvas element with name " + canvas.Name);
                    canvas.PngProperty = new WzPngProperty();
                    MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(element.GetAttribute("basedata")));
                    canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
                    foreach (XmlElement subelement in element)
                        canvas.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return canvas;

                case "int":
                    WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(element.GetAttribute("name"), int.Parse(element.GetAttribute("value"), formattingInfo));
                    return compressedInt;

                case "double":
                    WzDoubleProperty doubleProp = new WzDoubleProperty(element.GetAttribute("name"), double.Parse(element.GetAttribute("value"), formattingInfo));
                    return doubleProp;

                case "null":
                    WzNullProperty nullProp = new WzNullProperty(element.GetAttribute("name"));
                    return nullProp;

                case "sound":
                    if (!element.HasAttribute("basedata") || !element.HasAttribute("basehead") || !element.HasAttribute("length")) throw new NoBase64DataException("no base64 data in sound element with name " + element.GetAttribute("name"));
                    WzSoundProperty sound = new WzSoundProperty(element.GetAttribute("name"),
                        int.Parse(element.GetAttribute("length")),
                        Convert.FromBase64String(element.GetAttribute("basehead")),
                        Convert.FromBase64String(element.GetAttribute("basedata")));
                    return sound;

                case "string":
                    WzStringProperty stringProp = new WzStringProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return stringProp;

                case "short":
                    WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(element.GetAttribute("name"), ushort.Parse(element.GetAttribute("value"), formattingInfo));
                    return shortProp;

                case "uol":
                    WzUOLProperty uol = new WzUOLProperty(element.GetAttribute("name"), element.GetAttribute("value"));
                    return uol;

                case "vector":
                    WzVectorProperty vector = new WzVectorProperty(element.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(element.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(element.GetAttribute("y"))));
                    return vector;

                case "float":
                    WzByteFloatProperty floatProp = new WzByteFloatProperty(element.GetAttribute("name"), float.Parse(element.GetAttribute("value"), formattingInfo));
                    return floatProp;

                case "extended":
                    WzConvexProperty convex = new WzConvexProperty(element.GetAttribute("name"));
                    foreach (XmlElement subelement in element)
                        convex.AddProperty(ParsePropertyFromXMLElement(subelement));
                    return convex;
            }
            throw new InvalidDataException("unknown XML prop " + element.Name);
        }
		internal void ExtractMore(int eob, string name, string iname)
		{
			if (iname == "")
				iname = reader.ReadString();
			switch (iname)
			{
				case "Property":
					WzSubProperty subProp = new WzSubProperty(name) { Parent = parent, ParentImage = imgParent };
					reader.BaseStream.Position += 2;
					subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
					extendedProperty = subProp;
					break;
				case "Canvas":
					WzCanvasProperty canvasProp = new WzCanvasProperty(name) { Parent = parent, ParentImage = imgParent };
					reader.BaseStream.Position++;
					if (reader.ReadByte() == 1)
					{
						reader.BaseStream.Position += 2;
						canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
					}
					canvasProp.PngProperty = new WzPngProperty(reader) { Parent = canvasProp, ParentImage = imgParent };
					extendedProperty = canvasProp;
					break;
				case "Shape2D#Vector2D":
					WzVectorProperty vecProp = new WzVectorProperty(name) { Parent = parent, ParentImage = imgParent };
					vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt()) { Parent = vecProp, ParentImage = imgParent };
					vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt()) { Parent = vecProp, ParentImage = imgParent };
					extendedProperty = vecProp;
					break;
				case "Shape2D#Convex2D":
					WzConvexProperty convexProp = new WzConvexProperty(name) { Parent = parent, ParentImage = imgParent };
					int convexEntryCount = reader.ReadCompressedInt();
					for (int i = 0; i < convexEntryCount; i++)
					{
						WzExtendedProperty exProp = new WzExtendedProperty(offset, name) { Parent = convexProp, ParentImage = imgParent };
						exProp.ParseExtendedProperty(reader);
						convexProp.AddProperty(exProp);
					}
					extendedProperty = convexProp;
					break;
				case "Sound_DX8":
					WzSoundProperty soundProp = new WzSoundProperty(name) { Parent = parent, ParentImage = imgParent };
					soundProp.ParseSound(reader);
					extendedProperty = soundProp;
					break;
				case "UOL":
					reader.BaseStream.Position++;
                    extendedProperty = new WzUOLProperty(name, ExtractString()) { Parent = parent, ParentImage = imgParent };
                    /*
                    switch (reader.ReadByte())
					{
						case 0:
							extendedProperty = new WzUOLProperty(name, reader.ReadString()) { Parent = parent, ParentImage = imgParent };
							break;
						case 1:
							extendedProperty = new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent, ParentImage = imgParent };
							break;
					}
                    */
					break;
			}
		}
Exemple #8
0
 private static void ParseXML(XmlElement element, IPropertyContainer wo)
 {
     foreach (XmlNode node in element)
     {
         if (!(node is XmlElement)) continue;
         XmlElement childElement = (XmlElement)node;
         if (childElement.Name == "imgdir")
         {
             WzSubProperty sub = new WzSubProperty(childElement.GetAttribute("name"));
             wo.AddProperty(sub);
             ParseXML(childElement, (IPropertyContainer)sub);
         }
         else if (childElement.Name == "canvas")
         {
             WzCanvasProperty canvas = new WzCanvasProperty(childElement.GetAttribute("name"));
             canvas.PngProperty = new WzPngProperty();
             MemoryStream pngstream = new MemoryStream(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             canvas.PngProperty.SetPNG((Bitmap)Image.FromStream(pngstream, true, true));
             wo.AddProperty(canvas);
             ParseXML(childElement, (IPropertyContainer)canvas);
         }
         if (childElement.Name == "int")
         {
             WzCompressedIntProperty compressedInt = new WzCompressedIntProperty(childElement.GetAttribute("name"), int.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(compressedInt);
         }
         if (childElement.Name == "double")
         {
             WzDoubleProperty doubleProp = new WzDoubleProperty(childElement.GetAttribute("name"), double.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(doubleProp);
         }
         if (childElement.Name == "null")
         {
             WzNullProperty nullProp = new WzNullProperty(childElement.GetAttribute("name"));
             wo.AddProperty(nullProp);
         }
         if (childElement.Name == "sound")
         {
             WzSoundProperty sound = new WzSoundProperty(childElement.GetAttribute("name"));
             sound.SetDataUnsafe(Convert.FromBase64String(childElement.GetAttribute("basedata")));
             wo.AddProperty(sound);
         }
         if (childElement.Name == "string")
         {
             string str = childElement.GetAttribute("value").Replace("&lt;", "<").Replace("&amp;", "&").Replace("&gt;", ">").Replace("&apos;", "'").Replace("&quot;", "\"");
             WzStringProperty stringProp = new WzStringProperty(childElement.GetAttribute("name"), str);
             wo.AddProperty(stringProp);
         }
         if (childElement.Name == "short")
         {
             WzUnsignedShortProperty shortProp = new WzUnsignedShortProperty(childElement.GetAttribute("name"), ushort.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(shortProp);
         }
         if (childElement.Name == "uol")
         {
             WzUOLProperty uol = new WzUOLProperty(childElement.GetAttribute("name"), childElement.GetAttribute("value"));
             wo.AddProperty(uol);
         }
         if (childElement.Name == "vector")
         {
             WzVectorProperty vector = new WzVectorProperty(childElement.GetAttribute("name"), new WzCompressedIntProperty("x", Convert.ToInt32(childElement.GetAttribute("x"))), new WzCompressedIntProperty("y", Convert.ToInt32(childElement.GetAttribute("y"))));
             wo.AddProperty(vector);
         }
         if (childElement.Name == "float")
         {
             WzByteFloatProperty floatProp = new WzByteFloatProperty(childElement.GetAttribute("name"), float.Parse(childElement.GetAttribute("value"), formattingInfo));
             wo.AddProperty(floatProp);
         }
         if (childElement.Name == "extended")
         {
             WzConvexProperty convex = new WzConvexProperty(childElement.GetAttribute("name"));
             wo.AddProperty(convex);
             ParseXML(childElement, (IPropertyContainer)convex);
         }
     }
 }
Exemple #9
0
        public override WzImageProperty DeepClone()
        {
            WzSoundProperty clone = new WzSoundProperty(this);

            return(clone);
        }
Exemple #10
0
        public override IWzImageProperty DeepClone()
        {
            WzSoundProperty clone = (WzSoundProperty)MemberwiseClone();

            return(clone);
        }
Exemple #11
0
        internal void ExtractMore(int eob, string name, string iname)
        {
            if (iname == "")
            {
                iname = reader.ReadString();
            }
            switch (iname)
            {
            case "Property":
                WzSubProperty subProp = new WzSubProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                reader.BaseStream.Position += 2;
                subProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, subProp, imgParent));
                extendedProperty = subProp;
                break;

            case "Canvas":
                WzCanvasProperty canvasProp = new WzCanvasProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                reader.BaseStream.Position++;
                if (reader.ReadByte() == 1)
                {
                    reader.BaseStream.Position += 2;
                    canvasProp.AddProperties(IWzImageProperty.ParsePropertyList(offset, reader, canvasProp, imgParent));
                }
                canvasProp.PngProperty = new WzPngProperty(reader)
                {
                    Parent = canvasProp, ParentImage = imgParent
                };
                extendedProperty = canvasProp;
                break;

            case "Shape2D#Vector2D":
                WzVectorProperty vecProp = new WzVectorProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                vecProp.X = new WzCompressedIntProperty("X", reader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = imgParent
                };
                vecProp.Y = new WzCompressedIntProperty("Y", reader.ReadCompressedInt())
                {
                    Parent = vecProp, ParentImage = imgParent
                };
                extendedProperty = vecProp;
                break;

            case "Shape2D#Convex2D":
                WzConvexProperty convexProp = new WzConvexProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                int convexEntryCount = reader.ReadCompressedInt();
                for (int i = 0; i < convexEntryCount; i++)
                {
                    WzExtendedProperty exProp = new WzExtendedProperty(offset, name)
                    {
                        Parent = convexProp, ParentImage = imgParent
                    };
                    exProp.ParseExtendedProperty(reader);
                    convexProp.AddProperty(exProp);
                }
                extendedProperty = convexProp;
                break;

            case "Sound_DX8":
                WzSoundProperty soundProp = new WzSoundProperty(name)
                {
                    Parent = parent, ParentImage = imgParent
                };
                soundProp.ParseSound(reader);
                extendedProperty = soundProp;
                break;

            case "UOL":
                reader.BaseStream.Position++;
                extendedProperty = new WzUOLProperty(name, ExtractString())
                {
                    Parent = parent, ParentImage = imgParent
                };

                /*
                 * switch (reader.ReadByte())
                 *                  {
                 *                          case 0:
                 *                                  extendedProperty = new WzUOLProperty(name, reader.ReadString()) { Parent = parent, ParentImage = imgParent };
                 *                                  break;
                 *                          case 1:
                 *                                  extendedProperty = new WzUOLProperty(name, reader.ReadStringAtOffset(offset + reader.ReadInt32())) { Parent = parent, ParentImage = imgParent };
                 *                                  break;
                 *                  }
                 */
                break;
            }
        }
Exemple #12
0
 public override WzImageProperty DeepClone()
 {
     WzSoundProperty clone = new WzSoundProperty(name, len_ms, header, mp3bytes);
     return clone;
 }
 private void changeSoundButton_Click(object sender, EventArgs e)
 {
     if (DataTree.SelectedNode.Tag is WzSoundProperty)
     {
         OpenFileDialog dialog = new OpenFileDialog() { Title = "Select the sound", Filter = "Moving Pictures Experts Group Format 1 Audio Layer 3(*.mp3)|*.mp3" };
         if (dialog.ShowDialog() != DialogResult.OK) return;
         WzSoundProperty prop;
         try
         {
             prop = new WzSoundProperty(((WzSoundProperty)DataTree.SelectedNode.Tag).Name, dialog.FileName);
         }
         catch
         {
             Warning.Error(Properties.Resources.MainImageLoadError);
             return;
         }
         IPropertyContainer parent = (IPropertyContainer)((WzSoundProperty)DataTree.SelectedNode.Tag).Parent;
         ((WzSoundProperty)DataTree.SelectedNode.Tag).ParentImage.Changed = true;
         ((WzSoundProperty)DataTree.SelectedNode.Tag).Remove();
         DataTree.SelectedNode.Tag = prop;
         parent.AddProperty(prop);
         mp3Player.SoundProperty = prop;
     }
 }