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);
            }
        }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
0
        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("&", "&amp;");//.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("&", "&amp;");
                    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);
        }