/// <summary> /// Initializes the updater and sets up all the sub systems. /// </summary> /// <returns>True if initialization was sucessfull.</returns> private bool Initialize() { #region Command Line & Configuration Parsing // Parse the command lines for configuration options. ParseCommandLines(_commandLineArguments, true); // First things first lets read in the engine configuration file. _engineConfigFile = new XmlConfigFile(_configFilePath); // Get any configuration values relative to initializing the engine. _relativeBasePath = _engineConfigFile["basepath", _basePath]; _basePath = _relativeBasePath; // Parse the command lines for anything besides configuration options. ParseCommandLines(_commandLineArguments, false); // Check an update file has been specified. if (_updateFile == "") { MessageBox.Show("Unable to update, no update file was specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } #endregion #region Sub System Initialization // Create the updater's window. _window = new UpdaterWindow(); _window.Show(); #endregion return(true); }
public FlowRuleParameterTests() { UniqueIDCache.ClearIdCache(); this.config = new XmlConfigFile(); GetDNComponentTransform transform1 = new GetDNComponentTransform(); transform1.ID = "xform1"; this.config.Transforms.Add(transform1); GetDNComponentTransform transform2 = new GetDNComponentTransform(); transform2.ID = "xform2"; this.config.Transforms.Add(transform2); MVBooleanToBitmaskTransform transform3 = new MVBooleanToBitmaskTransform(); transform3.ID = "loopback"; this.config.Transforms.Add(transform3); FlowRuleAlias alias1 = new FlowRuleAlias(); alias1.Alias = "alias1"; alias1.FlowRuleDefinition = "csattribute>>xform1>>mvattribute"; this.config.FlowRuleAliases.Add(alias1); FlowRuleAlias alias2 = new FlowRuleAlias(); alias2.Alias = "alias2"; alias2.FlowRuleDefinition = "csattribute>>xform2>>mvattribute"; this.config.FlowRuleAliases.Add(alias2); }
public void AddOrSetTest() { IConfigFile testFile = new XmlConfigFile("test.xml"); testFile.AddOrSet("Config/Test/Property", "myValue"); Assert.IsTrue(File.Exists("test.xml")); Assert.AreEqual(testFile["Config/Test/Property"], "myValue"); }
public void SetTest() { var time = DateTime.Now; var test = new XmlConfigFile(testFile); test["SetTest"] = time.ToString(); var test2 = new XmlConfigFile(testFile); Assert.AreEqual(test2["SetTest"], time.ToString()); }
public void CreateEmptyTest() { var testFile = "test.xml"; if (File.Exists(testFile)) { File.Delete(testFile); } var test = new XmlConfigFile(testFile); Assert.IsTrue(File.Exists(testFile)); }
public void DeleteTest() { var test = new XmlConfigFile(testFile); test["DelTest"] = "test"; var test2 = new XmlConfigFile(testFile); Assert.AreEqual(test2["DelTest"], "test"); test2.Delete("DelTest"); var test3 = new XmlConfigFile(testFile); Assert.IsNull(test3["DelTest"]); }
public void GetTest() { var datetime = DateTime.Now; var test = new XmlConfigFile(testFile); test["Generic.IntTest"] = 1234.ToString(); test["Generic.BoolTest"] = true.ToString(); test["Generic.DateTest"] = datetime.ToString(); var test2 = new XmlConfigFile(testFile); Assert.AreEqual(1234, test2.Get <int>("Generic.IntTest")); Assert.AreEqual(true, test2.Get <bool>("Generic.BoolTest")); Assert.AreEqual(datetime.ToString(), test2.Get <DateTime>("Generic.DateTest").ToString()); }
public void FastReadWriteTest() { var test = new XmlConfigFile(testFile); test["F**k"] = "f**k"; test["Config.Test1"] = "test1"; test["Config:Test2"] = "test2"; test["Config.Section.Font"] = "consolas"; var test2 = new XmlConfigFile(testFile); Assert.AreEqual(test["F**k"], "f**k"); Assert.AreEqual(test["Config.Test1"], "test1"); Assert.AreEqual(test["Config:Test2"], "test2"); Assert.AreEqual(test["Config.Section.Font"], "consolas"); }
/// <summary> /// 格式化数据 /// </summary> /// <returns>The buffer.</returns> /// <param name="buffer">Buffer.</param> protected override XmlConfigFile FormatBuffer(XmlConfigFile buffer) { // 如果直接使用数组或字典序列化, 可以直接返回 buffer //return buffer; BaseXmlConfig <TKey, TData> config = buffer as BaseXmlConfig <TKey, TData>; foreach (TData data in config.datas) { if (dataDict.ContainsKey(data.GetKey())) { Debug.LogWarningFormat("{0} -> Key '{1}' is exist. Pass.", GetType().Name, data.GetKey()); continue; } dataDict.Add(data.GetKey(), data); } return(this); }
protected override XmlConfigFile FormatBuffer(XmlConfigFile buffer) { // 长度要和TerrainType数量保持一致 int length = (int)TerrainType.MaxLength; MoveConsumptionInfoConfig config = buffer as MoveConsumptionInfoConfig; for (int i = 0; i < config.datas.Length; i++) { if (config.datas[i].consumptions.Length != length) { int oldLength = config.datas[i].consumptions.Length; Array.Resize(ref config.datas[i].consumptions, length); for (int j = oldLength; j < length; j++) { config.datas[i].consumptions[j] = 255f; } } } return(base.FormatBuffer(config)); }
/// <summary> /// 反序列化完成时执行。 /// </summary> /// <param name="buffer"></param> protected override XmlConfigFile FormatBuffer(XmlConfigFile buffer) { //// 如果你要直接使用m_Datas。请直接返回Buffer //return buffer; // 将反序列化数据从buffer填充到本config的Dict TestLogXmlConfig logBuffer = buffer as TestLogXmlConfig; m_DataDict = new Dictionary <int, TestLogData>(); for (int i = 0; i < logBuffer.m_Datas.Length; i++) { TestLogData data = logBuffer.m_Datas[i]; if (!m_DataDict.ContainsKey(data.id)) { m_DataDict.Add(data.id, data); } } // 这里将buffer的数据填充到dict,buffer将丢弃。 // 需要注意,buffer的m_Datas属性有数据,而Dict没有数据。 // 本config,m_Datas没有数据,而Dict有数据。 // 你也可以把buffer填充,然后直接返回buffer,将本config丢弃。 return(this); }
public void TestSerialization() { AttributeValueDeleteConstructor constructorToSerialize1 = new AttributeValueDeleteConstructor(); constructorToSerialize1.Attribute = ActiveConfig.DB.GetAttribute("sn"); constructorToSerialize1.ID = "abc123"; constructorToSerialize1.Description = "some description"; constructorToSerialize1.RuleGroup = new RuleGroup() { Operator = GroupOperator.Any }; constructorToSerialize1.RuleGroup.Items.Add(new ObjectChangeRule() { TriggerEvents = TriggerEvents.Delete }); AttributeValueDeleteConstructor constructorToSerialize2 = new AttributeValueDeleteConstructor(); constructorToSerialize2.Attribute = ActiveConfig.DB.GetAttribute("sn"); constructorToSerialize2.ID = "abc123"; constructorToSerialize2.Description = "some description"; constructorToSerialize2.RuleGroup = new RuleGroup() { Operator = GroupOperator.All }; constructorToSerialize2.RuleGroup.Items.Add(new ObjectChangeRule() { TriggerEvents = TriggerEvents.Add }); AttributeConstructorGroup groupToSerialize = new AttributeConstructorGroup(); groupToSerialize.Description = "my description"; groupToSerialize.ID = "myID"; groupToSerialize.ExecutionRule = GroupExecutionRule.ExitAfterFirstSuccess; groupToSerialize.RuleGroup = new RuleGroup() { Operator = GroupOperator.Any }; groupToSerialize.RuleGroup.Items.Add(new ObjectChangeRule() { TriggerEvents = TriggerEvents.Delete }); groupToSerialize.Constructors.Add(constructorToSerialize1); ClassConstructor classConstructorToSerialize = new ClassConstructor(); classConstructorToSerialize.ObjectClass = ActiveConfig.DB.GetObjectClass("person"); classConstructorToSerialize.ExitEvents.Add(new AcmaInternalExitEvent() { ID = "testName" }); classConstructorToSerialize.Constructors.Add(groupToSerialize); classConstructorToSerialize.Constructors.Add(constructorToSerialize2); classConstructorToSerialize.ResurrectionParameters = new DBQueryGroup(); classConstructorToSerialize.ResurrectionParameters.Operator = GroupOperator.Any; classConstructorToSerialize.ResurrectionParameters.DBQueries.Add(new DBQueryByValue(ActiveConfig.DB.GetAttribute("sn"), ValueOperator.Equals, new ValueDeclaration("test"))); classConstructorToSerialize.ResurrectionParameters.DBQueries.Add(new DBQueryByValue(ActiveConfig.DB.GetAttribute("sn"), ValueOperator.Equals, ActiveConfig.DB.GetAttribute("sn"))); XmlConfigFile toSerialize = new XmlConfigFile(); toSerialize.ClassConstructors.Add(classConstructorToSerialize); toSerialize.Transforms = new TransformKeyedCollection(); toSerialize.Transforms.Add(new TrimStringTransform() { TrimType = TrimType.Both, ID = "trimboth" }); UniqueIDCache.ClearIdCache(); XmlConfigFile deserialized = UnitTestControl.XmlSerializeRoundTrip <XmlConfigFile>(toSerialize); Assert.AreEqual(toSerialize.ClassConstructors.Count, deserialized.ClassConstructors.Count); Assert.AreEqual(toSerialize.Transforms.Count, deserialized.Transforms.Count); }
void IEditorConfigSerializer.EditorDeserializeToObject(byte[] bytes) { XmlConfigFile config = XmlUtility.ObjectFromXmlBytes(bytes, GetType()); datas = (config as BaseXmlConfig <TKey, TData>).datas; }
/// <summary> /// Used as an entry point for the project building thread. /// </summary> private void BuildProjectThread() { // Work out script compiling options _compileFlags = _compileInDebugMode == true ? CompileFlags.Debug : 0; if (_treatMessagesAsErrors) { _compileFlags |= CompileFlags.TreatMessagesAsErrors; } if (_treatWarningsAsErrors) { _compileFlags |= CompileFlags.TreatWarningsAsErrors; } // Split up the script defines string. string[] defines = _scriptDefines.Split(new char[1] { ',' }); _scriptDefineList = new Define[defines.Length + 1]; for (int i = 0; i < defines.Length; i++) { if (defines[i].IndexOf('=') >= 0) { string[] splitList = defines[i].Split(new char[1] { '=' }); _scriptDefineList[i] = new Define(splitList[0], splitList[1], TokenID.TypeIdentifier); } else { _scriptDefineList[i] = new Define(defines[i], "", TokenID.TypeIdentifier); } } _scriptDefineList[_scriptDefineList.Length - 1] = new Define(_compileInDebugMode ? "__DEBUG__" : "__RELEASE__", "", TokenID.TypeBoolean); // Set the include path list to include the script library path. _scriptIncludePathList = new string[] { Environment.CurrentDirectory + "\\" + Editor.GlobalInstance.ScriptLibraryPath, Editor.GlobalInstance.GlobalScriptLibraryPath }; // Work out a directory that we can build to. _buildBasePath = _buildDirectory; _buildDirectory = _buildBasePath + "\\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second; int buildIndex = 2; if (Directory.Exists(_buildBasePath) == false) { Directory.CreateDirectory(_buildBasePath); } while (Directory.Exists(_buildDirectory) == true) { _buildDirectory = _buildBasePath + "\\" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + (buildIndex++).ToString().PadLeft(4, '0'); } // Create the build directory. Directory.CreateDirectory(_buildDirectory); // Open the game configuration file, change the pak file settings and save it into // the new build folder. XmlConfigFile configFile = new XmlConfigFile(Editor.GlobalInstance.GameName + ".xml"); configFile.SetSetting("path:resources:usepakfiles", _compilePakFiles == true || _buildStandAlone == true ? "1" : "0"); if (_buildStandAlone == false) { configFile.Save(_buildDirectory + "\\" + Editor.GlobalInstance.GameName + ".xml"); } // Copy the configuration directory into the build directory. //IOMethods.CopyDirectory(Editor.GlobalInstance.ConfigPath, _buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath); // Copy the language directory into the build directory. //IOMethods.CopyDirectory(Editor.GlobalInstance.LanguagePath, _buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath); // Copy the saves file if we have been told to. if (_copySaves == true && Directory.GetFiles(Editor.GlobalInstance.SavePath).Length != 0) { IOMethods.CopyDirectory(Editor.GlobalInstance.SavePath, _buildDirectory + "\\" + Editor.GlobalInstance.SavePath); } // Create a plugins folder. //IOMethods.CopyDirectory(Editor.GlobalInstance.GamePluginPath, _buildDirectory + "\\" + Editor.GlobalInstance.GamePluginPath); // Copy the icon. if (_buildStandAlone == false && File.Exists(Editor.GlobalInstance.GamePath + "\\icon.ico")) { File.Copy(Editor.GlobalInstance.GamePath + "\\icon.ico", _buildDirectory + "\\icon.ico"); } // Compile the pak files or copy the media directory if we are not using pak files. if (_buildStandAlone == true) { _taskProgress = 0; _task = "Packing files"; _logStack.Push(_task); // Work out the game ID code. long gameIDCode = DateTime.Now.Ticks ^ (long)configFile["title", "engine"].GetHashCode(); // Create the pak file to save resources to. _pakFile = new PakFile(); _pakFileIndex = 0; _pakFileSize = 0; _pakFileMaximumSize = 0; // Compile the media directory to the pak file. CompileDirectoryToPak(Editor.GlobalInstance.MediaPath); CompileDirectoryToPak(Editor.GlobalInstance.ConfigPath); CompileDirectoryToPak(Editor.GlobalInstance.LanguagePath); // Work out game files that we need. ArrayList gameFiles = new ArrayList(); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "fusion.exe"); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "graphics.dll"); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "runtime.dll"); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "input.dll"); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "audio.dll"); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + "engine.dll"); // Copy plugins. string[] requiredPlugins = Editor.GlobalInstance.GameConfigFile.GetSettings("requirements"); if (requiredPlugins != null) { foreach (string requirement in requiredPlugins) { string[] pathSplit = requirement.Split(new char[] { ':' }); string name = pathSplit[pathSplit.Length - 1]; string value = Editor.GlobalInstance.GameConfigFile[requirement, ""]; switch (name.ToLower()) { case "plugin": if (File.Exists(Editor.GlobalInstance.PluginPath + "\\" + value)) { //if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.PluginPath) == false) // Directory.CreateDirectory(_buildDirectory + "\\" + Editor.GlobalInstance.PluginPath); //File.Copy(Editor.GlobalInstance.PluginPath + "\\" + value, _buildDirectory + "\\" + Editor.GlobalInstance.PluginPath + value); gameFiles.Add(AppDomain.CurrentDomain.BaseDirectory + Editor.GlobalInstance.PluginPath + "\\" + value); } break; } } } // Copy all! else { if (Directory.Exists(Editor.GlobalInstance.PluginPath)) { foreach (string file in Directory.GetFiles(Editor.GlobalInstance.PluginPath)) { if (Path.GetExtension(file).ToLower() != ".dll") { continue; } gameFiles.Add(file); } } // Game plugins as well. // TODO } _taskProgress = 50; _task = "Building executable"; // Create the sub that we are going to add the files into. string stubFile = _buildDirectory + "\\" + string.Join("", configFile["title", "engine"].Split(new char[] { '\\', '/', ':', '*', '?', '"', '<', '>', '|' }, StringSplitOptions.None)) + ".exe"; File.Copy(AppDomain.CurrentDomain.BaseDirectory + "Stand Alone Stub.exe", stubFile); // Open up the stub. Stream stubStream = StreamFactory.RequestStream(stubFile, StreamMode.Append); BinaryWriter stubWriter = new BinaryWriter(stubStream); // Grab the offset. long offset = stubStream.Position; stubWriter.Write(gameFiles.Count + 3); foreach (string gameFilePath in gameFiles) { Stream fileStream = null; fileStream = StreamFactory.RequestStream(gameFilePath, StreamMode.Open); if (fileStream == null) { string tmpFile = Path.GetTempFileName(); File.Delete(tmpFile); File.Copy(gameFilePath, tmpFile); fileStream = StreamFactory.RequestStream(tmpFile, StreamMode.Open); } byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, (int)fileStream.Length); string url = gameFilePath; if (url.ToLower().StartsWith(AppDomain.CurrentDomain.BaseDirectory.ToLower())) { url = url.Substring(AppDomain.CurrentDomain.BaseDirectory.Length); } stubWriter.Write(url); stubWriter.Write(buffer.Length); stubWriter.Write(buffer, 0, buffer.Length); } stubStream.Flush(); GC.Collect(); // Write the pak file into a memory stream. MemoryStream engineMemStream = new MemoryStream(); BinaryWriter engineMemWriter = new BinaryWriter(engineMemStream); XmlConfigFile engineConfigFile = new XmlConfigFile(AppDomain.CurrentDomain.BaseDirectory + "fusion.xml"); engineConfigFile.SetSetting("standalone", _buildStandAlone == true ? "1" : "0"); engineConfigFile.Save(engineMemWriter); GC.Collect(); // Write the game config file. stubWriter.Write("fusion.xml"); stubWriter.Write((int)engineMemStream.Length); engineMemStream.WriteTo(stubStream); // Write the pak file into a memory stream. MemoryStream gameMemStream = new MemoryStream(); BinaryWriter gameMemWriter = new BinaryWriter(gameMemStream); configFile.Save(gameMemWriter); GC.Collect(); // Write the game config file. stubWriter.Write("standalone.xml"); stubWriter.Write((int)gameMemStream.Length); gameMemStream.WriteTo(stubStream); // Write the pak file into a memory stream. MemoryStream memStream = new MemoryStream(); BinaryWriter memWriter = new BinaryWriter(memStream); _pakFile.Save(memWriter); _pakFile.Resources.Clear(); GC.Collect(); // Write in the pak file. stubWriter.Write("data.pk"); stubWriter.Write((int)memStream.Length); memStream.WriteTo(stubStream); // Write in the offset footer stubWriter.Write(gameIDCode); stubWriter.Write(offset); // Write the data into the stub. stubWriter.Close(); stubStream.Close(); } else { if (_compilePakFiles == true) { _taskProgress = 0; _task = "Compiling pak files"; _logStack.Push(_task); // Create the pak file to save resources to. _pakFile = new PakFile(); _pakFileIndex = 0; _pakFileSize = 0; // Compile the media directory to the pak file. CompileDirectoryToPak(Editor.GlobalInstance.MediaPath); CompileDirectoryToPak(Editor.GlobalInstance.ConfigPath); CompileDirectoryToPak(Editor.GlobalInstance.LanguagePath); // Save the pak file to the hard drive. if (_pakFile.Resources.Count != 0) { string filePath = _buildDirectory + "\\" + _pakFilePrefix.Replace("#", _pakFileIndex.ToString()) + ".pk"; int index = 0; while (File.Exists(filePath) == true) { filePath = _buildDirectory + "\\" + _pakFilePrefix.Replace("#", _pakFileIndex.ToString()) + (index++) + ".pk"; } _pakFile.Save(filePath); _pakFile.Dispose(); } } else { _taskProgress = 0; _task = "Copying media"; _logStack.Push(_task); CopyDirectoryWithProgress(Editor.GlobalInstance.MediaPath, _buildDirectory + "\\" + Editor.GlobalInstance.MediaPath); CopyDirectoryWithProgress(Editor.GlobalInstance.ConfigPath, _buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath); CopyDirectoryWithProgress(Editor.GlobalInstance.LanguagePath, _buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath); } // If we are building an FGE distrubutable file then copy the icon file and copile all to pak file. if (_buildFGE) { _taskProgress = 0; _task = "Compiling FGE files"; _logStack.Push(_task); // Create the pak file to save resources to. _pakFile = new PakFile(); _pakFileIndex = 0; _pakFileSize = 0; _pakFileMaximumSize = 0; // Pak the build directory. string oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(_buildDirectory); CompileDirectoryToPak(Directory.GetCurrentDirectory()); // Save the pak file. _pakFile.Save(Editor.GlobalInstance.GameName + ".pk"); _pakFile.Dispose(); Directory.SetCurrentDirectory(oldDirectory); // Delete folder. if (_copySaves == true && Directory.GetFiles(Editor.GlobalInstance.SavePath).Length != 0) { Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.SavePath); } // Delete all files and folders. File.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.GameName + ".xml"); if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.MediaPath)) { Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.MediaPath, true); } if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath)) { Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.ConfigPath, true); } if (Directory.Exists(_buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath)) { Directory.Delete(_buildDirectory + "\\" + Editor.GlobalInstance.LanguagePath, true); } } } }