Пример #1
0
        public static void CleanXml(string fileName)
        {
            stringBuilder.Remove(0, stringBuilder.Length);

            using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (System.IO.StreamReader sr = new StreamReader(fileStream))
                {
                    while (!sr.EndOfStream)
                    {
                        string  lineAsString = sr.ReadLine();
                        XmlLine line         = new XmlLine(lineAsString);

                        if (!ShouldRemoveLine(line))
                        {
                            stringBuilder.AppendLine(lineAsString);
                        }
                    }

                    sr.Close();
                }
            }

            string newFileName = FileManager.RemoveExtension(fileName) + "Clean" + "." + FileManager.GetExtension(fileName);

            FileManager.SaveText(stringBuilder.ToString(), newFileName);
        }
Пример #2
0
        private static bool ShouldRemoveLine(XmlLine line)
        {
            bool returnValue = true;

            if (line.IsClosing)
            {
                //if (TypeStack.Count == 1)
                //{
                //    int m = 3;
                //}
                PopLayer();
                returnValue = false;
            }

            else if (line.Name.StartsWith("?xml"))
            {
                returnValue = false;
            }
            else
            {
                switch (line.Name)
                {
                case "SpriteEditorScene":
                    PushNewLayer(ShouldRemoveLineSpriteEditorScene, typeof(SpriteEditorScene), new SpriteEditorScene());

                    returnValue = false;
                    break;

                default:
                    if (TypeBasedRemovals.Count == 0)
                    {
                        returnValue = false;
                    }
                    else
                    {
                        returnValue = TypeBasedRemovals.Peek()(line);
                    }
                    break;
                }
            }

            return(returnValue);
        }
Пример #3
0
        private static bool ShouldRemoveLineSpriteEditorScene(XmlLine line)
        {
            bool returnValue = false;


            switch (line.Name)
            {
            case "Sprite":
                PushNewLayer(ShouldRemoveLineGeneral, typeof(SpriteSave), new SpriteSave());

                returnValue = false;
                break;

            case "Camera":
                PushNewLayer(ShouldRemoveLineGeneral, typeof(CameraSave), new CameraSave());

                break;
            }

            return(returnValue);
        }
Пример #4
0
        private static bool ShouldRemoveLineGeneral(XmlLine line)
        {
            Type currentType = TypeStack.Peek();

            if (currentType.GetField(line.Name) != null)
            {
                object value = currentType.GetField(line.Name).GetValue(ObjectStack.Peek());

                if (value is float)
                {
                    return((float)value == float.Parse(line.Value, CultureInfo.InvariantCulture));
                }
                else if (value is string)
                {
                    return((string)value == line.Value);
                }
                else if (value is bool)
                {
                    return((bool)value == bool.Parse(line.Value.ToLower()));
                }
                else if (value is int)
                {
                    return((int)value == int.Parse(line.Value));
                }
                else if (value is Microsoft.Xna.Framework.Graphics.TextureAddressMode)
                {
                    return((Microsoft.Xna.Framework.Graphics.TextureAddressMode)value ==
                           (Microsoft.Xna.Framework.Graphics.TextureAddressMode)Enum.Parse(
                               typeof(Microsoft.Xna.Framework.Graphics.TextureAddressMode),
                               line.Value, true));
                }
            }


            return(false);
        }
Пример #5
0
        public static void CleanXml(string fileName)
        {
            stringBuilder.Remove(0, stringBuilder.Length);

            using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				using (System.IO.StreamReader sr = new StreamReader(fileStream))
				{
                    while (!sr.EndOfStream)
                    {
                        string lineAsString = sr.ReadLine();
                        XmlLine line = new XmlLine(lineAsString);

                        if (!ShouldRemoveLine(line))
                        {
                            stringBuilder.AppendLine(lineAsString);
                        }
                    }

					sr.Close();
				}
			}

            string newFileName = FileManager.RemoveExtension(fileName) + "Clean" + "." + FileManager.GetExtension(fileName);

            FileManager.SaveText(stringBuilder.ToString(), newFileName);

        }
Пример #6
0
        private static bool ShouldRemoveLineGeneral(XmlLine line)
        {
            Type currentType = TypeStack.Peek();

            if (currentType.GetField(line.Name) != null)
            {
                object value = currentType.GetField(line.Name).GetValue(ObjectStack.Peek());

                if (value is float)
                {
                    return (float)value == float.Parse(line.Value, CultureInfo.InvariantCulture);
                }
                else if (value is string)
                {
                    return (string)value == line.Value;
                }
                else if (value is bool)
                {
                    return (bool)value == bool.Parse(line.Value.ToLower());
                }
                else if (value is int)
                {
                    return (int)value == int.Parse(line.Value);
                }
                else if (value is Microsoft.Xna.Framework.Graphics.TextureAddressMode)
                {
                    return (Microsoft.Xna.Framework.Graphics.TextureAddressMode)value ==
                        (Microsoft.Xna.Framework.Graphics.TextureAddressMode)Enum.Parse(
                        typeof(Microsoft.Xna.Framework.Graphics.TextureAddressMode),
                            line.Value, true);

                }
            }
            

            return false;
        }
Пример #7
0
        private static bool ShouldRemoveLineSpriteEditorScene(XmlLine line)
        {
            bool returnValue = false;


            switch (line.Name)
            {
                case "Sprite":
                    PushNewLayer(ShouldRemoveLineGeneral, typeof(SpriteSave), new SpriteSave());

                    returnValue = false;
                    break;
                case "Camera":
                    PushNewLayer(ShouldRemoveLineGeneral, typeof(CameraSave), new CameraSave());

                    break;
                
            }

            return returnValue;
        }
Пример #8
0
        private static bool ShouldRemoveLine(XmlLine line)
        {
            bool returnValue = true;

            if (line.IsClosing)
            {
                //if (TypeStack.Count == 1)
                //{
                //    int m = 3;
                //}
                PopLayer();
                returnValue = false;
            }

            else if (line.Name.StartsWith("?xml"))
            {
                returnValue = false;
            }
            else
            {

                switch (line.Name)
                {
                    case "SpriteEditorScene":
                        PushNewLayer(ShouldRemoveLineSpriteEditorScene, typeof(SpriteEditorScene), new SpriteEditorScene());

                        returnValue = false;
                        break;
                    default:
                        if (TypeBasedRemovals.Count == 0)
                        {
                            returnValue = false;
                        }
                        else
                        {
                            returnValue = TypeBasedRemovals.Peek()(line);
                        }
                        break;

                }

            }

            return returnValue;
        }