Esempio n. 1
0
        /// <summary>
        /// Save this configuration list.
        /// </summary>

        static internal void SaveList(string path, List <string> list)
        {
            if (list.size > 0)
            {
                if (!File.Exists(path) && !string.IsNullOrEmpty(Tools.applicationDirectory))
                {
                    path = Tools.GetDocumentsPath(path);
                }

                string dir = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                StreamWriter sw = new StreamWriter(path, false);
                for (int i = 0; i < list.size; ++i)
                {
                    sw.WriteLine(list[i]);
                }
                sw.Close();
            }
            else
            {
                Tools.DeleteFile(path);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Log an error message.
        /// </summary>

        static public void LogError(string msg, string stack = null, bool logInFile = true)
        {
            if (msg.Contains("forcibly closed"))
            {
                return;
            }
#if UNITY_EDITOR
            UnityEngine.Debug.LogError(msg);
#else
            msg = "ERROR: " + msg;
            Tools.Print(msg);

            if (logInFile)
            {
                try
                {
                    msg = "[" + System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "] " + msg;
                    string path = Tools.GetDocumentsPath("Debug/TNetLog.txt");
                    string dir  = Path.GetDirectoryName(path);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    StreamWriter sw = new StreamWriter(path, true);
                    sw.WriteLine(msg);
                    if (!string.IsNullOrEmpty(stack))
                    {
                        sw.WriteLine(stack);
                    }
                    sw.Close();

                    path = Tools.GetDocumentsPath("Debug/TNetErrors.txt");
                    dir  = Path.GetDirectoryName(path);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    sw = new StreamWriter(path, true);
                    sw.WriteLine(msg);
                    if (!string.IsNullOrEmpty(stack))
                    {
                        sw.WriteLine(stack);
                    }
                    sw.Close();
                }
                catch (System.Exception) { }
            }
#endif
        }
Esempio n. 3
0
        /// <summary>
        /// Log the specified string to the log file.
        /// </summary>

        static public void LogFile(string msg)
        {
            try
            {
                string path = Tools.GetDocumentsPath("Debug/TNetLog.txt");
                string dir  = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                StreamWriter sw = new StreamWriter(path, true);
                sw.WriteLine(msg);
                sw.Close();
            }
            catch (System.Exception) { }
        }
Esempio n. 4
0
        /// <summary>
        /// Helper function that loads a list from within specified file.
        /// </summary>

        static internal void LoadList(string path, List <string> list)
        {
            if (path == null)
            {
                return;
            }

            list.Clear();

            bool exists = false;

            if (File.Exists(path))
            {
                exists = true;
            }
            else if (!string.IsNullOrEmpty(Tools.applicationDirectory))
            {
                path = Tools.GetDocumentsPath(path);
                if (File.Exists(path))
                {
                    exists = true;
                }
            }

            if (exists)
            {
                StreamReader reader = new StreamReader(path);

                while (!reader.EndOfStream)
                {
                    string s = reader.ReadLine();
                    if (!string.IsNullOrEmpty(s))
                    {
                        list.Add(s);
                    }
                    else
                    {
                        break;
                    }
                }
                reader.Close();
            }
        }