private void WriteStringFile() { try { List<string> strings = localizer.GetCollectedStrings(); //debugger.Debug(this, "writing strings to file - count: " + strings.Count); uint fileHandle = 0u; string result = Simulator.CreateScriptErrorFile(ref fileHandle); if (fileHandle != 0u) { // The XmlWriter has methods to write anything CustomXmlWriter xmlWriter = new CustomXmlWriter(fileHandle); foreach (string key in strings) { xmlWriter.WriteToBuffer(key); xmlWriter.WriteToBuffer(System.Environment.NewLine); } xmlWriter.FlushBufferToFile(); Simulator.CloseScriptErrorFile(fileHandle); } } catch (Exception ex) { Debugger debugger = new Debugger(this); debugger.DebugError(this, "String collector failed to write file", ex); debugger.EndDebugLog(); } }
/// <summary> /// Convert into XML. Store XML into a file with the specified name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dataToSerialize">Any aribitary object</param> /// <param name="filePath">File storage location with file name</param> public static void Serialize <T>(this T dataToSerialize, string filePath) { if (dataToSerialize == null) { throw new ArgumentNullException(nameof(dataToSerialize)); } if (String.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(nameof(filePath)); } var namespaces = new XmlSerializerNamespaces(); namespaces.Add(String.Empty, String.Empty); var serializer = new XmlSerializer(dataToSerialize.GetType()); var settings = new XmlWriterSettings { Encoding = new UTF8Encoding(false) }; using (var fileStream = new FileStream(filePath, FileMode.Create)) using (var writer = XmlWriter.Create(fileStream, settings)) using (var customXmlWriter = new CustomXmlWriter(writer) { AlwaysWriteFullEndElement = true }) { customXmlWriter.WriteDocType("boost_serialization", "", "xGG", ""); serializer.Serialize(customXmlWriter, dataToSerialize, namespaces); } }
public void StartDebugLog(object target) { string result = ""; try { uint num = 0u; result = Simulator.CreateScriptErrorFile(ref num); if (num != 0u) { mLogXmlWriter = new CustomXmlWriter(num); mLogXmlWriter.WriteStartDocument(); mLogXmlWriter.WriteElementString("VirtualArtisanDebugger", target.GetType().ToString()); string[] data = GameUtils.GetGenericString(GenericStringID.VersionData).Split(new char[] { '\n' }); string[] labels = GameUtils.GetGenericString(GenericStringID.VersionLabels).Split(new char[] { '\n' }); int count = (labels.Length > data.Length) ? data.Length : labels.Length; for (int i = 0; i < count; i++) { if (labels[i] == "Game Version:") { mLogXmlWriter.WriteElementString("GameVersion", data[i]); } else if (labels[i] == "Build Version:") { mLogXmlWriter.WriteElementString("BuildVersion", data[i]); } } IGameUtils gameUtils = (IGameUtils)AppDomain.CurrentDomain.GetData("GameUtils"); if (gameUtils != null) { ProductVersion productFlags = (ProductVersion)gameUtils.GetProductFlags(); mLogXmlWriter.WriteElementString("Installed", productFlags.ToString()); } mLogXmlWriter.WriteStartElement("Assemblies"); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { string shortName = assembly.FullName.Replace(", Culture=neutral", ""); mLogXmlWriter.WriteElementString("Assembly", shortName); } mLogXmlWriter.WriteEndElement(); mLogXmlWriter.FlushBufferToFile(); NotifyUserOfDebugging(result); } } catch (Exception ex) { EndDebugLog(); string title = I18n.Localize(CommonTexts.DEBUG_CANNOT_START_LOGGER, "Virtual Artisan Debugger CANNOT be started"); string text = I18n.Localize(CommonTexts.DEBUG_CANNOT_CREATE_LOG_FILE, "Cannot create debug log"); Message.Sender.ShowError(title, text, false, ex); } }
private void WriteStringFile() { try { List <string> strings = localizer.GetCollectedStrings(); //debugger.Debug(this, "writing strings to file - count: " + strings.Count); uint fileHandle = 0u; string result = Simulator.CreateScriptErrorFile(ref fileHandle); if (fileHandle != 0u) { // The XmlWriter has methods to write anything CustomXmlWriter xmlWriter = new CustomXmlWriter(fileHandle); foreach (string key in strings) { xmlWriter.WriteToBuffer(key); xmlWriter.WriteToBuffer(System.Environment.NewLine); } xmlWriter.FlushBufferToFile(); Simulator.CloseScriptErrorFile(fileHandle); } } catch (Exception ex) { Debugger debugger = new Debugger(this); debugger.DebugError(this, "String collector failed to write file", ex); debugger.EndDebugLog(); } }
private void StartDebugLog(object target) { string result = ""; try { uint num = 0u; result = Simulator.CreateScriptErrorFile(ref num); if (num != 0u) { mLogXmlWriter = new CustomXmlWriter(num); mLogXmlWriter.WriteStartDocument(); mLogXmlWriter.WriteElementString("VirtualArtisanDebugger", target.GetType().ToString()); string[] data = GameUtils.GetGenericString(GenericStringID.VersionData).Split(new char[] { '\n' }); string[] labels = GameUtils.GetGenericString(GenericStringID.VersionLabels).Split(new char[] { '\n' }); int count = (labels.Length > data.Length) ? data.Length : labels.Length; for (int i = 0; i < count; i++) { if (labels[i] == "Game Version:") { mLogXmlWriter.WriteElementString("GameVersion", data[i]); } else if (labels[i] == "Build Version:") { mLogXmlWriter.WriteElementString("BuildVersion", data[i]); } } IGameUtils gameUtils = (IGameUtils)AppDomain.CurrentDomain.GetData("GameUtils"); if (gameUtils != null) { ProductVersion productFlags = (ProductVersion)gameUtils.GetProductFlags(); mLogXmlWriter.WriteElementString("Installed", productFlags.ToString()); } mLogXmlWriter.WriteStartElement("Assemblies"); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { string shortName = assembly.FullName.Replace(", Culture=neutral", ""); mLogXmlWriter.WriteElementString("Assembly", shortName); } mLogXmlWriter.WriteEndElement(); mLogXmlWriter.FlushBufferToFile(); } } catch (Exception ex) { EndDebugLog(); } }
private static void Save() { PrintLine("Atempting Save of leaderboards"); FileStream fs = UFile.Create(_savePath); CustomXmlWriter cxw = CustomXmlWriter.Create(fs); cxw.WriteStartDocument(); cxw.WriteStartElement("LocalScores"); foreach (QueuededScore qs in _scoresToSend) { cxw.WriteStartElement("ScoresToSend"); cxw.WriteAttributeString("Leaderboard", qs.Leaderboard); cxw.WriteAttributeULong("Id", qs.Score.Principal_ID); cxw.WriteAttributeULong("Nex_Id", qs.Score.Nex_Unique_ID); cxw.WriteAttributeULong("Misc", qs.Score.Misc); cxw.WriteAttributeUInt("Score", qs.Score.Score); cxw.WriteAttributeArray <byte>("Cud", qs.Score.CommonDataBinary); cxw.WriteAttributeString("UserName", qs.Score.CommonDataUserName); cxw.WriteAttributeInt("Type", (int)qs.Type); cxw.WriteEndElement(); } foreach (KeyValuePair <string, List <HighScore> > kvp in _localLeaderboards) { cxw.WriteStartElement("Leaderboard"); cxw.WriteAttributeString("Name", kvp.Key); foreach (HighScore hs in kvp.Value) { cxw.WriteStartElement("Score"); cxw.WriteAttributeULong("Id", hs.Principal_ID); cxw.WriteAttributeULong("Nex_Id", hs.Nex_Unique_ID); cxw.WriteAttributeUInt("Score", hs.Score); cxw.WriteAttributeULong("Misc", hs.Misc); cxw.WriteAttributeString("UserName", hs.CommonDataUserName); cxw.WriteAttributeArray <byte>("Cud", hs.CommonDataBinary); cxw.WriteEndElement(); } cxw.WriteEndElement(); } cxw.WriteEndElement(); cxw.WriteEndDocument(); cxw.Close(); fs.Close(); UFile.Commit(); PrintLine("Save Compleate"); }
public void EndDebugLog() { try { if (mLogXmlWriter != null) { // Closes the file handles too mLogXmlWriter.WriteEndDocument(); mLogXmlWriter = null; } } catch (Exception ex) { } }
public void EndDebugLog() { try { if (mLogXmlWriter != null) { // Closes the file handles too mLogXmlWriter.WriteEndDocument(); mLogXmlWriter = null; } } catch (Exception ex) { Message.Sender.ShowError(this, "Cannot stop debugging", false, ex); } }
/// <summary> /// Get the List of T and serialize into XML Memory stream /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dataToSerialize"></param> /// <returns></returns> public static MemoryStream Serialize <T>(this T dataToSerialize) { try { if (dataToSerialize == null) { throw new ArgumentNullException(); } var namespaces = new XmlSerializerNamespaces(); namespaces.Add("", ""); var serializer = new XmlSerializer(dataToSerialize.GetType()); var settings = new XmlWriterSettings { Encoding = new UTF8Encoding(false) }; var memstream = new MemoryStream(); var writer = XmlWriter.Create(memstream, settings); using (var customXmlWriter = new CustomXmlWriter(writer) { AlwaysWriteFullEndElement = true }) { customXmlWriter.WriteDocType("boost_serialization", "", "xGG", ""); serializer.Serialize(customXmlWriter, dataToSerialize, namespaces); } return(memstream); } catch { throw; } }
public void Debug(object sender, string msg) { string finalMsg = sender.GetType().ToString() + " - " + msg; StyledNotification.Format format = new StyledNotification.Format(finalMsg, StyledNotification.NotificationStyle.kSystemMessage); StyledNotification.Show(format); bool result; try { if (addHeader) { Common.sLogEnumerator++; string[] array = GameUtils.GetGenericString(GenericStringID.VersionLabels).Split(new char[] { '\n' }); string[] array2 = GameUtils.GetGenericString(GenericStringID.VersionData).Split(new char[] { '\n' }); string text2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Common.NewLine; string text3 = text2; text2 = string.Concat(new string[] { text3, "<", VersionStamp.sNamespace, ">", Common.NewLine }); object obj = text2; text2 = string.Concat(new object[] { obj, "<ModVersion value=\"", VersionStamp.sVersion, "\"/>", Common.NewLine }); int num = (array.Length > array2.Length) ? array2.Length : array.Length; for (int i = 0; i < num; i++) { string text4 = array[i].Replace(":", "").Replace(" ", ""); string a; if ((a = text4) != null && (a == "GameVersion" || a == "BuildVersion")) { string text5 = text2; text2 = string.Concat(new string[] { text5, "<", text4, " value=\"", array2[i], "\"/>", Common.NewLine }); } } IGameUtils gameUtils = (IGameUtils)AppDomain.CurrentDomain.GetData("GameUtils"); if (gameUtils != null) { ProductVersion productFlags = (ProductVersion)gameUtils.GetProductFlags(); object obj2 = text2; text2 = string.Concat(new object[] { obj2, "<Installed=\"", productFlags, "\"/>", Common.NewLine }); } object obj3 = text2; text2 = string.Concat(new object[] { obj3, "<Enumerator value=\"", Common.sLogEnumerator, "\"/>", Common.NewLine }); text2 = text2 + "<Content>" + Common.NewLine; text = text2 + text.Replace("&", "&"); text = text + Common.NewLine + "</Content>"; string text6 = text; text = string.Concat(new string[] { text6, Common.NewLine, "</", VersionStamp.sNamespace, ">" }); } uint num2 = 0u; Simulator.CreateScriptErrorFile(ref num2); if (num2 != 0u) { CustomXmlWriter customXmlWriter = new CustomXmlWriter(num2); customXmlWriter.WriteToBuffer(text); customXmlWriter.WriteEndDocument(); } result = true; } catch { result = false; } return result; }
public static bool WriteLog(string text, bool addHeader, bool scripterror, bool printmessage) { try { if (string.IsNullOrEmpty(text)) { return(false); } if (addHeader) { sLogEnumerator++; try { if (printmessage) { PrintMessage("Write Log is Created"); } else if (scripterror) { PrintMessage("NiecMod " + NewLine + "Script Error is Found No: " + sLogEnumerator); } } catch (Exception) { } string[] labels = GameUtils.GetGenericString(GenericStringID.VersionLabels).Split(new char[] { '\n' }); string[] data = GameUtils.GetGenericString(GenericStringID.VersionData).Split(new char[] { '\n' }); string header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + NewLine; header += "<" + "NiecMod" + ">" + NewLine; try { header += "<ModVersion value=\"" + "1.0" + "\"/>" + NewLine; } catch (Exception) { header += "<ModVersion value=\"" + "1.0" + "\"/>" + NewLine; } int num2 = (labels.Length > data.Length) ? data.Length : labels.Length; for (int j = 0x0; j < num2; j++) { string label = labels[j].Replace(":", "").Replace(" ", ""); switch (label) { //case "GameVersion": case "BuildVersion": header += "<" + label + " value=\"" + data[j] + "\"/>" + NewLine; break; } } IGameUtils utils = (IGameUtils)AppDomain.CurrentDomain.GetData("GameUtils"); if (utils != null) { ProductVersion version = (ProductVersion)utils.GetProductFlags(); header += "<Installed value=\"" + version + "\"/>" + NewLine; } header += "<Enumerator value=\"" + sLogEnumerator + "\"/>" + NewLine; header += "<Content>" + NewLine; if (scripterror) { header += ScriptError() + NewLine; } text = header + text.Replace("&", "&");//.Replace(NewLine, " <br />" + NewLine); text += NewLine + "</Content>"; text += NewLine + "</" + "NiecMod" + ">"; } uint fileHandle = 0x0; string str = Simulator.CreateScriptErrorFile(ref fileHandle); if (fileHandle != 0x0) { CustomXmlWriter xmlWriter = new CustomXmlWriter(fileHandle); xmlWriter.WriteToBuffer(text); xmlWriter.WriteEndDocument(); } return(true); } catch { return(false); } }
public void Debug(object sender, string msg) { string finalMsg = sender.GetType().ToString() + " - " + msg; StyledNotification.Format format = new StyledNotification.Format(finalMsg, StyledNotification.NotificationStyle.kSystemMessage); StyledNotification.Show(format); bool result; try { if (addHeader) { Common.sLogEnumerator++; string[] array = GameUtils.GetGenericString(GenericStringID.VersionLabels).Split(new char[] { '\n' }); string[] array2 = GameUtils.GetGenericString(GenericStringID.VersionData).Split(new char[] { '\n' }); string text2 = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Common.NewLine; string text3 = text2; text2 = string.Concat(new string[] { text3, "<", VersionStamp.sNamespace, ">", Common.NewLine }); object obj = text2; text2 = string.Concat(new object[] { obj, "<ModVersion value=\"", VersionStamp.sVersion, "\"/>", Common.NewLine }); int num = (array.Length > array2.Length) ? array2.Length : array.Length; for (int i = 0; i < num; i++) { string text4 = array[i].Replace(":", "").Replace(" ", ""); string a; if ((a = text4) != null && (a == "GameVersion" || a == "BuildVersion")) { string text5 = text2; text2 = string.Concat(new string[] { text5, "<", text4, " value=\"", array2[i], "\"/>", Common.NewLine }); } } IGameUtils gameUtils = (IGameUtils)AppDomain.CurrentDomain.GetData("GameUtils"); if (gameUtils != null) { ProductVersion productFlags = (ProductVersion)gameUtils.GetProductFlags(); object obj2 = text2; text2 = string.Concat(new object[] { obj2, "<Installed=\"", productFlags, "\"/>", Common.NewLine }); } object obj3 = text2; text2 = string.Concat(new object[] { obj3, "<Enumerator value=\"", Common.sLogEnumerator, "\"/>", Common.NewLine }); text2 = text2 + "<Content>" + Common.NewLine; text = text2 + text.Replace("&", "&"); text = text + Common.NewLine + "</Content>"; string text6 = text; text = string.Concat(new string[] { text6, Common.NewLine, "</", VersionStamp.sNamespace, ">" }); } uint num2 = 0u; Simulator.CreateScriptErrorFile(ref num2); if (num2 != 0u) { CustomXmlWriter customXmlWriter = new CustomXmlWriter(num2); customXmlWriter.WriteToBuffer(text); customXmlWriter.WriteEndDocument(); } result = true; } catch { result = false; } return(result); }