Example #1
0
        public bool SaveTypeToFile(EntityType type)
        {
            TextBlock textBlock = new TextBlock();
            TextBlock typeBlock = textBlock.AddChild("type", type.Name);

            typeBlock.SetAttribute("class", type.ClassInfo.EntityClassType.Name);

            if (!type.Save(typeBlock))
            {
                return(false);
            }

            if (!type._OnSave(typeBlock))
            {
                return(false);
            }

            try
            {
                using (FileStream fileStream = new FileStream(VirtualFileSystem.GetRealPathByVirtual(type.FilePath), FileMode.Create))
                {
                    using (StreamWriter streamWriter = new StreamWriter(fileStream))
                    {
                        streamWriter.Write(textBlock.DumpToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warning("Save type to file failed: {0}", ex.ToString());
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// Saves a map to file.
        /// </summary>
        /// <param name="virtualFileName">The file name of virtual file system.</param>
        /// <param name="compressEntityUINs"></param>
        /// <returns><b>true</b> if the map has been saved; otherwise, <b>false</b>.</returns>
        public static bool MapSave(string virtualFileName, bool compressEntityUINs)
        {
            if (Map.Instance == null)
            {
                Log.Fatal("MapSystemWorld: MapSave: Map instance is not created.");
            }
            virtualFileName = PathUtils.NormalizeSlashes(virtualFileName);
            Entities.Instance.DeleteEntitiesQueuedForDeletion();
            if (compressEntityUINs)
            {
                Entities.Instance.CompressUINs();
            }

            Map.Instance.virtualFileName = virtualFileName;
            TextBlock textBlock = new TextBlock();

            Entities.Instance.WriteEntityTreeToTextBlock(Map.Instance, textBlock);
            string realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(virtualFileName);

            try
            {
                using (StreamWriter streamWriter = new StreamWriter(realPathByVirtual))
                {
                    streamWriter.Write(textBlock.DumpToString());
                }
            }
            catch
            {
                Log.Error("Unable to save file \"{0}\".", realPathByVirtual);
                return(false);
            }
            return(true);
        }
Example #3
0
        private void bgwBuyVariant_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] args         = (string[])e.Argument;
            string   fullFileName = args[0];
            string   saveDir      = args[1];

            try
            {
                //Decreasing Credit
                string       sql = "UPDATE phpap_AKusers SET money = @DeductedCash WHERE Username=@User";
                MySqlCommand cmd = new MySqlCommand(sql, Program.AKsqlcon);

                MySqlParameter DeductedCashP = new MySqlParameter();
                DeductedCashP.ParameterName = "@DeductedCash";
                DeductedCashP.Value         = cash - variantCost;
                cmd.Parameters.Add(DeductedCashP);

                MySqlParameter EmailP = new MySqlParameter();
                EmailP.ParameterName = "@User";
                EmailP.Value         = Program.username;
                cmd.Parameters.Add(EmailP);

                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    OnBuyLog update = new OnBuyLog(Log.Info);
                    update.Invoke(ex.Message);
                    return;
                }
            }

            cash -= variantCost;

            string finalFilePath = string.Format("{0}\\{1}", saveDir, fullFileName);

            File.Create(finalFilePath).Close();

            StreamWriter sw = new StreamWriter(finalFilePath);

            sw.Write(variant.DumpToString());
            sw.Close();
        }
Example #4
0
        protected override void OnNewResource(string directory)
        {
            base.OnNewResource(directory);
            EntityTypeNewResourceDialog cd = new EntityTypeNewResourceDialog(directory);

            if (cd.ShowDialog(MainForm.Instance) != DialogResult.OK)
            {
                return;
            }

            string text = "";

            if (directory != "")
            {
                text = text + directory + "\\";
            }
            text = text + cd.TypeName + ".type";
            TextBlock textBlock = new TextBlock();
            TextBlock typeBlock = textBlock.AddChild("type", cd.TypeName);

            typeBlock.SetAttribute("class", cd.TypeClass.EntityClassType.Name);
            try
            {
                using (Stream stream = new FileStream(VirtualFileSystem.GetRealPathByVirtual(text), FileMode.Create))
                {
                    using (StreamWriter streamWriter = new StreamWriter(stream))
                    {
                        streamWriter.Write(textBlock.DumpToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex.Message);
                return;
            }
            if (EntityTypes.Instance.LoadTypeFromFile(text) != null)
            {
                MainForm.Instance.ResourcesForm.UpdateAddResource(text);
                MainForm.Instance.ResourcesForm.SelectNodeByPath(text);
                return;
            }
            Log.Fatal("OnNewResource: EntityTypes.Instance.LoadType: Internal error.");
        }
        void SaveEngineConfig(TextBlock engineConfigBlock)
        {
            string fileName = VirtualFileSystem.GetRealPathByVirtual("user:Configs/Engine.config");

            try
            {
                string directoryName = Path.GetDirectoryName(fileName);
                if (directoryName != "" && !Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }
                using (StreamWriter writer = new StreamWriter(fileName))
                {
                    writer.Write(engineConfigBlock.DumpToString());
                }
            }
            catch (Exception e)
            {
                Log.Warning("Unable to save file \"{0}\". {1}", fileName, e.Message);
            }
        }
Example #6
0
        public static void Save()
        {
            if (!ToolsLocalization.IsInitialized)
            {
                return;
            }
            string    realPathByVirtual = VirtualFileSystem.GetRealPathByVirtual(ToolsLocalization.EL);
            TextBlock textBlock         = new TextBlock();
            TextBlock textBlock2        = textBlock.AddChild("groups");

            foreach (ToolsLocalization.GroupItem current in ToolsLocalization.EM.Values)
            {
                TextBlock textBlock3 = textBlock2.AddChild("group", current.eM);
                foreach (KeyValuePair <string, string> current2 in current.em)
                {
                    textBlock3.SetAttribute(current2.Key, current2.Value);
                }
            }
            using (StreamWriter streamWriter = new StreamWriter(realPathByVirtual))
            {
                streamWriter.Write(textBlock.DumpToString());
            }
        }
Example #7
0
        bool SaveEngineConfig()
        {
            TextBlock block = new TextBlock();

            //Renderer
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxRenderSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxRenderSystems.SelectedIndex];
                }

                TextBlock rendererBlock = block.AddChild("Renderer");
                if (component != null)
                {
                    rendererBlock.SetAttribute("implementationComponent", component.Name);
                }

                //rendering device
                if (component != null && component.Name.Contains("Direct3D"))
                {
                    rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem);
                    rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString());
                }

                if (!checkBoxAllowShaders.Checked)
                {
                    rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString());
                }

                //depthBufferAccess
                if (comboBoxDepthBufferAccess.SelectedIndex != -1)
                {
                    rendererBlock.SetAttribute("depthBufferAccess",
                                               (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString());
                }

                //fullSceneAntialiasing
                if (comboBoxAntialiasing.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem;
                    rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier);
                }

                //filtering
                if (comboBoxFiltering.SelectedIndex != -1)
                {
                    RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes)
                                                             comboBoxFiltering.SelectedIndex;
                    rendererBlock.SetAttribute("filtering", filtering.ToString());
                }

                //renderTechnique
                if (comboBoxRenderTechnique.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem;
                    rendererBlock.SetAttribute("renderTechnique", item.Identifier);
                }

                //multiMonitorMode
                if (comboBoxVideoMode.SelectedIndex == 1)
                {
                    rendererBlock.SetAttribute("multiMonitorMode", true.ToString());
                }

                //videoMode
                if (comboBoxVideoMode.SelectedIndex >= 2)
                {
                    string[] strings = ((string)comboBoxVideoMode.SelectedItem).
                                       Split(new char[] { 'x' });
                    Vec2I videoMode = new Vec2I(int.Parse(strings[0]),
                                                int.Parse(strings[1]));
                    rendererBlock.SetAttribute("videoMode", videoMode.ToString());
                }

                //fullScreen
                rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString());

                //vertical sync
                rendererBlock.SetAttribute("verticalSync",
                                           checkBoxVerticalSync.Checked.ToString());
            }

            //Physics system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.PhysicsSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxPhysicsSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxPhysicsSystems.SelectedIndex];
                }

                if (component != null)
                {
                    TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem");
                    physicsSystemBlock.SetAttribute("implementationComponent", component.Name);
                    //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration",
                    //   checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() );
                }
            }

            //Sound system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.SoundSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxSoundSystems.SelectedIndex != -1)
                {
                    component = components[comboBoxSoundSystems.SelectedIndex];
                }

                if (component != null)
                {
                    TextBlock soundSystemBlock = block.AddChild("SoundSystem");
                    soundSystemBlock.SetAttribute("implementationComponent", component.Name);
                }
            }

            //Localization
            {
                string language = "Autodetect";
                if (comboBoxLanguages.SelectedIndex > 0)
                {
                    language = (string)comboBoxLanguages.SelectedItem;
                }

                TextBlock localizationBlock = block.AddChild("Localization");
                localizationBlock.SetAttribute("language", language);
                if (!checkBoxLocalizeEngine.Checked)
                {
                    localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString());
                }
                if (!checkBoxLocalizeToolset.Checked)
                {
                    localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString());
                }
            }

            //save file
            {
                string fileName = VirtualFileSystem.GetRealPathByVirtual(
                    "user:Configs/Engine.config");

                try
                {
                    string directoryName = Path.GetDirectoryName(fileName);
                    if (directoryName != "" && !Directory.Exists(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    using (StreamWriter writer = new StreamWriter(fileName))
                    {
                        writer.Write(block.DumpToString());
                    }
                }
                catch
                {
                    string text = string.Format("Saving file failed \"{0}\".", fileName);
                    MessageBox.Show(text, "Configurator", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    return(false);
                }
            }

            return(true);
        }
		void SaveEngineConfig( TextBlock engineConfigBlock )
		{
			string fileName = VirtualFileSystem.GetRealPathByVirtual( "user:Configs/Engine.config" );
			try
			{
				string directoryName = Path.GetDirectoryName( fileName );
				if( directoryName != "" && !Directory.Exists( directoryName ) )
					Directory.CreateDirectory( directoryName );
				using( StreamWriter writer = new StreamWriter( fileName ) )
				{
					writer.Write( engineConfigBlock.DumpToString() );
				}
			}
			catch( Exception e )
			{
				Log.Warning( "Unable to save file \"{0}\". {1}", fileName, e.Message );
			}
		}
        public void SaveCustomConfig()
        {
            var block = new TextBlock();
            var controlBloc = block.AddChild("Controls");

            //var deadzone = controlBloc.AddChild("DeadZone");
            var keyBlockDz = DeadZone.ToString();
            block.SetAttribute("DeadZone", keyBlockDz);

            foreach (GameControlItem item in Items)
            {
                var currentKeyBlock = controlBloc.AddChild(item.ControlKey.ToString());
                //keybord Setting
                if (item.BindedKeyboardMouseValues.Count > 0)
                {
                    var keyboardBlock = currentKeyBlock.AddChild("Keyboard");
                    foreach (var keyboardvalue in item.BindedKeyboardMouseValues)
                    {
                        var keyBlock = keyboardBlock.AddChild("Item");
                        SystemKeyboardMouseValue.Save(keyboardvalue, keyBlock);
                    }
                }
                //Joystick setting
                if (item.BindedJoystickValues.Count > 0)
                {
                    var joystickBlock = currentKeyBlock.AddChild("Joystick");
                    foreach (var joystickvalue in item.BindedJoystickValues)
                    {
                        var keyBlock = joystickBlock.AddChild("Item");
                        SystemJoystickValue.Save(joystickvalue, keyBlock);
                    }
                }
            }

            string fileName = VirtualFileSystem.GetRealPathByVirtual(keyconfig);
            try
            {
                string directoryName = Path.GetDirectoryName(fileName);
                if (directoryName != "" && !Directory.Exists(directoryName))
                    Directory.CreateDirectory(directoryName);
                using (StreamWriter writer = new StreamWriter(fileName))
                {
                    writer.Write(block.DumpToString());
                }
            }
            catch
            {
                Log.Fatal(string.Format("Saving file failed \"{0}\".", fileName));
                return;
            }
        }
Example #10
0
        private bool SaveEngineConfig()
        {
            TextBlock block = new TextBlock();

            //Renderer
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.RenderingSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxRenderSystems.SelectedIndex != -1)
                    component = components[comboBoxRenderSystems.SelectedIndex];

                TextBlock rendererBlock = block.AddChild("Renderer");
                if (component != null)
                    rendererBlock.SetAttribute("implementationComponent", component.Name);

                //rendering device
                if (component != null && component.Name.Contains("Direct3D"))
                {
                    rendererBlock.SetAttribute("renderingDeviceName", (string)comboBoxRenderingDevices.SelectedItem);
                    rendererBlock.SetAttribute("renderingDeviceIndex", (comboBoxRenderingDevices.SelectedIndex - 1).ToString());
                }

                if (!checkBoxAllowShaders.Checked)
                    rendererBlock.SetAttribute("allowShaders", checkBoxAllowShaders.Checked.ToString());

                //depthBufferAccess
                if (comboBoxDepthBufferAccess.SelectedIndex != -1)
                {
                    rendererBlock.SetAttribute("depthBufferAccess",
                        (comboBoxDepthBufferAccess.SelectedIndex == 1).ToString());
                }

                //fullSceneAntialiasing
                if (comboBoxAntialiasing.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxAntialiasing.SelectedItem;
                    rendererBlock.SetAttribute("fullSceneAntialiasing", item.Identifier);
                }

                //filtering
                if (comboBoxFiltering.SelectedIndex != -1)
                {
                    RendererWorld.FilteringModes filtering = (RendererWorld.FilteringModes)
                        comboBoxFiltering.SelectedIndex;
                    rendererBlock.SetAttribute("filtering", filtering.ToString());
                }

                //renderTechnique
                if (comboBoxRenderTechnique.SelectedIndex != -1)
                {
                    ComboBoxItem item = (ComboBoxItem)comboBoxRenderTechnique.SelectedItem;
                    rendererBlock.SetAttribute("renderTechnique", item.Identifier);
                }

                //multiMonitorMode
                if (comboBoxVideoMode.SelectedIndex == 1)
                    rendererBlock.SetAttribute("multiMonitorMode", true.ToString());

                //videoMode
                if (comboBoxVideoMode.SelectedIndex >= 2)
                {
                    string[] strings = ((string)comboBoxVideoMode.SelectedItem).
                        Split(new char[] { 'x' });
                    Vec2I videoMode = new Vec2I(int.Parse(strings[0]),
                        int.Parse(strings[1]));
                    rendererBlock.SetAttribute("videoMode", videoMode.ToString());
                }

                //fullScreen
                rendererBlock.SetAttribute("fullScreen", checkBoxFullScreen.Checked.ToString());

                //vertical sync
                rendererBlock.SetAttribute("verticalSync",
                    checkBoxVerticalSync.Checked.ToString());
            }

            //Physics system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.PhysicsSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxPhysicsSystems.SelectedIndex != -1)
                    component = components[comboBoxPhysicsSystems.SelectedIndex];

                if (component != null)
                {
                    TextBlock physicsSystemBlock = block.AddChild("PhysicsSystem");
                    physicsSystemBlock.SetAttribute("implementationComponent", component.Name);
                    //physicsSystemBlock.SetAttribute( "allowHardwareAcceleration",
                    //   checkBoxPhysicsAllowHardwareAcceleration.Checked.ToString() );
                }
            }

            //Sound system
            {
                EngineComponentManager.ComponentInfo[] components = GetSortedComponentsByType(
                    EngineComponentManager.ComponentTypeFlags.SoundSystem);

                EngineComponentManager.ComponentInfo component = null;
                if (comboBoxSoundSystems.SelectedIndex != -1)
                    component = components[comboBoxSoundSystems.SelectedIndex];

                if (component != null)
                {
                    TextBlock soundSystemBlock = block.AddChild("SoundSystem");
                    soundSystemBlock.SetAttribute("implementationComponent", component.Name);
                }
            }

            //Localization
            {
                string language = "Autodetect";
                if (comboBoxLanguages.SelectedIndex > 0)
                    language = (string)comboBoxLanguages.SelectedItem;

                TextBlock localizationBlock = block.AddChild("Localization");
                localizationBlock.SetAttribute("language", language);
                if (!checkBoxLocalizeEngine.Checked)
                    localizationBlock.SetAttribute("localizeEngine", checkBoxLocalizeEngine.Checked.ToString());
                if (!checkBoxLocalizeToolset.Checked)
                    localizationBlock.SetAttribute("localizeToolset", checkBoxLocalizeToolset.Checked.ToString());
            }

            //save file
            {
                string fileName = VirtualFileSystem.GetRealPathByVirtual(
                    "user:Configs/Engine.config");

                try
                {
                    string directoryName = Path.GetDirectoryName(fileName);
                    if (directoryName != "" && !Directory.Exists(directoryName))
                        Directory.CreateDirectory(directoryName);
                    using (StreamWriter writer = new StreamWriter(fileName))
                    {
                        writer.Write(block.DumpToString());
                    }
                }
                catch
                {
                    string text = string.Format("Saving file failed \"{0}\".", fileName);
                    MessageBox.Show(text, "Configurator", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    return false;
                }
            }

            return true;
        }
Example #11
0
        protected override void OnFormClosing( FormClosingEventArgs e )
        {
            if( DialogResult == DialogResult.OK )
            {
                //save Engine.config

                TextBlock block = new TextBlock();

                //Renderer
                {
                    TextBlock rendererBlock = block.AddChild( "Renderer" );

                    string renderSystemName = "";
                    if( comboBoxRenderSystems.SelectedIndex != -1 )
                        renderSystemName = (string)comboBoxRenderSystems.SelectedItem;

                    if( renderSystemName != "" )
                        rendererBlock.SetAttribute( "renderSystemName", renderSystemName );

                    //maxPixelShaders
                    {
                        EnumTypeConverter enumConverter = new EnumTypeConverter(
                            typeof( RendererWorld.MaxPixelShadersVersions ) );
                        string text = comboBoxMaxPixelShaders.SelectedItem.ToString();
                        RendererWorld.MaxPixelShadersVersions maxPixelShaders =
                            (RendererWorld.MaxPixelShadersVersions)enumConverter.ConvertFromString( text );
                        rendererBlock.SetAttribute( "maxPixelShaders", maxPixelShaders.ToString() );
                    }

                    //maxVertexShaders
                    {
                        EnumTypeConverter enumConverter = new EnumTypeConverter(
                            typeof( RendererWorld.MaxVertexShadersVersions ) );
                        string text = comboBoxMaxVertexShaders.SelectedItem.ToString();
                        RendererWorld.MaxVertexShadersVersions maxVertexShaders =
                            (RendererWorld.MaxVertexShadersVersions)enumConverter.ConvertFromString( text );
                        rendererBlock.SetAttribute( "maxVertexShaders", maxVertexShaders.ToString() );
                    }

                    //fullSceneAntialiasing
                    {
                        int fullSceneAntialiasing = 0;
                        if( comboBoxAntialiasing.SelectedIndex > 0 )
                            fullSceneAntialiasing = int.Parse( (string)comboBoxAntialiasing.SelectedItem );
                        rendererBlock.SetAttribute( "fullSceneAntialiasing",
                            fullSceneAntialiasing.ToString() );
                    }

                    //filtering
                    {
                        EnumTypeConverter enumConverter = new EnumTypeConverter(
                            typeof( RendererWorld.FilteringModes ) );
                        string text = comboBoxFiltering.SelectedItem.ToString();
                        RendererWorld.FilteringModes filtering =
                            (RendererWorld.FilteringModes)enumConverter.ConvertFromString( text );
                        rendererBlock.SetAttribute( "filtering", filtering.ToString() );
                    }

                    //renderTechnique
                    if( comboBoxRenderTechnique.SelectedIndex != -1 )
                    {
                        string renderTechnique = "";
                        if( comboBoxRenderTechnique.SelectedIndex != 0 )
                        {
                            renderTechnique =
                                ( (RenderTechniqueItem)comboBoxRenderTechnique.SelectedItem ).Name;
                        }
                        rendererBlock.SetAttribute( "renderTechnique", renderTechnique );
                    }

                    //videoMode
                    if( comboBoxVideoMode.SelectedIndex > 0 )
                    {
                        string[] strings = ( (string)comboBoxVideoMode.SelectedItem ).
                            Split( new char[] { 'x' } );
                        Vec2i videoMode = new Vec2i( int.Parse( strings[ 0 ] ),
                            int.Parse( strings[ 1 ] ) );
                        rendererBlock.SetAttribute( "videoMode", videoMode.ToString() );
                    }

                    //fullScreen
                    rendererBlock.SetAttribute( "fullScreen", checkBoxFullScreen.Checked.ToString() );

                    //vertical sync
                    rendererBlock.SetAttribute( "verticalSync",
                        checkBoxVerticalSync.Checked.ToString() );

                    //allowChangeDisplayFrequency
                    rendererBlock.SetAttribute( "allowChangeDisplayFrequency",
                        checkBoxAllowChangeDisplayFrequency.Checked.ToString() );
                }

                //Physics system
                {
                    string physicsSystemName = "";
                    if( comboBoxPhysicsSystems.SelectedIndex != -1 )
                        physicsSystemName = (string)comboBoxPhysicsSystems.SelectedItem;

                    //physics system name
                    TextBlock physicsSystemBlock = block.AddChild( "PhysicsSystem" );
                    if( physicsSystemName != "" )
                        physicsSystemBlock.SetAttribute( "physicsSystemName", physicsSystemName );
                }

                //Sound system
                {
                    string soundSystemName = "";
                    if( comboBoxSoundSystems.SelectedIndex != -1 )
                        soundSystemName = (string)comboBoxSoundSystems.SelectedItem;

                    TextBlock soundSystemBlock = block.AddChild( "SoundSystem" );
                    if( soundSystemName != "" )
                        soundSystemBlock.SetAttribute( "soundSystemName", soundSystemName );
                }

                //Localization
                {
                    string language = "English";
                    if( comboBoxLanguages.SelectedIndex != -1 )
                        language = (string)comboBoxLanguages.SelectedItem;

                    TextBlock localizationBlock = block.AddChild( "Localization" );
                    localizationBlock.SetAttribute( "language", language );
                }

                //save file
                {
                    string fileName = VirtualFileSystem.GetRealPathByVirtual(
                        "user:Configs/Engine.config" );

                    try
                    {
                        string directoryName = Path.GetDirectoryName( fileName );
                        if( directoryName != "" && !Directory.Exists( directoryName ) )
                            Directory.CreateDirectory( directoryName );
                        using( StreamWriter writer = new StreamWriter( fileName ) )
                        {
                            writer.Write( block.DumpToString() );
                        }
                    }
                    catch
                    {
                        string text = string.Format( "Saving file failed \"{0}\".", fileName );
                        MessageBox.Show( text, "Configurator", MessageBoxButtons.OK,
                            MessageBoxIcon.Warning );
                        e.Cancel = true;
                        return;
                    }
                }
            }

            base.OnFormClosing( e );
        }
Example #12
0
        public void TestLoadAndSave()
        {
            TextBlock textBlock = new TextBlock();

            string id   = "09234";
            string name = "你的名字";

            textBlock.SetAttribute("id", id);
            textBlock.SetAttribute("name", name);

            string    section      = "管理器";
            TextBlock ctb          = textBlock.AddChild(section);
            string    section_id   = "sec_928023874";
            string    section_name = "中文系统简要设计";

            ctb.SetAttribute("id", section_id);
            ctb.SetAttribute("name", section_name);

            string    rowsName  = "rows";
            TextBlock rowsBlock = ctb.AddChild(rowsName);
            int       rowCount  = 8;

            rowsBlock.SetAttribute("cnt", Convert.ToString(rowCount));
            for (int i = 0; i < rowCount; i++)
            {
                string row_name  = string.Format("row_{0}", i);
                string row_value = string.Format("值_{0}", i);
                rowsBlock.SetAttribute(row_name, row_value);
            }

            string textResult = textBlock.DumpToString();

            string    errorMessage = "";
            TextBlock block        = TextBlock.Parse(textResult, out errorMessage);

            Assert.IsNotNull(block);
            // Level 0
            string _id = block.GetAttribute("id");

            Assert.IsTrue(id == _id);

            string _name = block.GetAttribute("name");

            Assert.IsTrue(name == _name);

            TextBlock _tbRnd = block.FindChild(Guid.NewGuid().ToString());

            Assert.IsNull(_tbRnd);

            TextBlock _ctb = block.FindChild(section);

            Assert.IsNotNull(_ctb);

            string _section_id = _ctb.GetAttribute("id");

            Assert.IsTrue(section_id == _section_id);

            string _section_name = _ctb.GetAttribute("name");

            Assert.IsTrue(section_name == _section_name);

            TextBlock _rowsBlock = _ctb.FindChild(rowsName);

            Assert.IsNotNull(_rowsBlock);

            string _cnt = _rowsBlock.GetAttribute("cnt");
            int    nCnt = -1;

            int.TryParse(_cnt, out nCnt);
            Assert.IsTrue(nCnt == rowCount);

            for (int i = 0; i < nCnt; i++)
            {
                string _row_name  = string.Format("row_{0}", i);
                string _row_value = string.Format("值_{0}", i);
                Assert.IsTrue(_rowsBlock.IsAttributeExist(_row_name));

                string __row_value = _rowsBlock.GetAttribute(_row_name);
                Assert.IsTrue(__row_value == _row_value);
            }
        }