OSDN Git Service

loggign chat
authorLatif Khalifa <latifer@streamgrid.net>
Tue, 16 Jun 2009 18:33:51 +0000 (18:33 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Tue, 16 Jun 2009 18:33:51 +0000 (18:33 +0000)
git-svn-id: https://radegast.googlecode.com/svn/trunk@52 f7a694da-4d33-11de-9ad6-1127a62b9fcd

13 files changed:
Radegast/Core/ChatTextManager.cs
Radegast/Core/Config/ConfigManager.cs
Radegast/Core/IMTextManager.cs
Radegast/Core/RadegastInstance.cs
Radegast/Core/RadegastLogger.cs
Radegast/GUI/Consoles/AnimDetail.cs
Radegast/GUI/Consoles/AnimTab.cs
Radegast/GUI/Consoles/ConferenceIMTabWindow.cs
Radegast/GUI/Consoles/GroupIMTabWindow.cs
Radegast/GUI/Consoles/IMTabWindow.cs
Radegast/GUI/Consoles/TabsConsole.cs
Radegast/GUI/Dialogs/MainForm.cs
RadegastNetcom/RadegastNetcom/SLNetCom.cs

index 1ea2563..532fb81 100644 (file)
@@ -156,6 +156,7 @@ namespace Radegast
 \r
         public void ProcessBufferItem(ChatBufferItem item, bool addToBuffer)\r
         {\r
+            instance.LogClientMessage("chat.txt", item.Text);\r
             if (addToBuffer) textBuffer.Add(item);\r
 \r
             if (showTimestamps)\r
@@ -208,9 +209,7 @@ namespace Radegast
         {\r
             StringBuilder sb = new StringBuilder();\r
 \r
-            sb.Append("(channel ");\r
-            sb.Append(e.Channel);\r
-            sb.Append(") You");\r
+            sb.AppendFormat("(channel {0}) {1}", e.Channel, client.Self.Name);\r
 \r
             switch (e.Type)\r
             {\r
@@ -252,7 +251,7 @@ namespace Radegast
             }\r
             else if (e.FromName == netcom.LoginOptions.FullName && e.SourceType == ChatSourceType.Agent)\r
             {\r
-                sb.Append("You");\r
+                sb.Append(client.Self.Name);\r
 \r
                 switch (e.Type)\r
                 {\r
@@ -261,11 +260,11 @@ namespace Radegast
                         break;\r
 \r
                     case ChatType.Whisper:\r
-                        sb.Append(" whisper: ");\r
+                        sb.Append(" whispers: ");\r
                         break;\r
 \r
                     case ChatType.Shout:\r
-                        sb.Append(" shout: ");\r
+                        sb.Append(" shouts: ");\r
                         break;\r
                 }\r
 \r
index 90b9622..a249826 100644 (file)
@@ -42,7 +42,7 @@ namespace Radegast
 \r
         public ConfigManager(RadegastInstance instance)\r
         {\r
-            defaultConfigPath = Path.Combine(instance.userDir, Properties.Resources.ProgramName + @".ini");\r
+            defaultConfigPath = Path.Combine(instance.UserDir, Properties.Resources.ProgramName + @".ini");\r
         }\r
 \r
         public void ApplyCurrentConfig()\r
index 9754ad8..1b6c54d 100644 (file)
@@ -44,15 +44,16 @@ namespace Radegast
         private RadegastNetcom netcom;\r
         private ITextPrinter textPrinter;\r
         private UUID sessionID;\r
+        private string sessionName;\r
 \r
         private ArrayList textBuffer;\r
 \r
         private bool showTimestamps;\r
 \r
-        public IMTextManager(RadegastInstance instance, ITextPrinter textPrinter, UUID sessionID)\r
+        public IMTextManager(RadegastInstance instance, ITextPrinter textPrinter, UUID sessionID, string sessionName)\r
         {\r
             this.sessionID = sessionID;\r
-\r
+            this.sessionName = sessionName;\r
             this.textPrinter = textPrinter;\r
             this.textBuffer = new ArrayList();\r
 \r
@@ -143,6 +144,7 @@ namespace Radegast
                 sb.Append(message);\r
             }\r
 \r
+            instance.LogClientMessage(sessionName + ".txt", message);\r
             textPrinter.PrintTextLine(sb.ToString());\r
             sb = null;\r
         }\r
index 9256af6..d669f69 100644 (file)
@@ -64,8 +64,26 @@ namespace Radegast
             }\r
         }\r
 \r
-        public readonly string userDir;\r
-        public readonly string animCacheDir;\r
+        private string userDir;\r
+        /// <summary>\r
+        /// System (not grid!) user's dir\r
+        /// </summary>\r
+        public string UserDir { get { return userDir; } }\r
+\r
+        private string clientDir;\r
+        /// <summary>\r
+        /// Grid client's user dir for settings and logs\r
+        /// </summary>\r
+        public string ClientDir { get { return clientDir; } }\r
+\r
+        private string animCacheDir;\r
+        public string AnimCacheDir { get { return animCacheDir; } }\r
+\r
+        private string globalLogFile;\r
+        public string GlobalLogFile { get { return globalLogFile; } }\r
+\r
+        private bool monoRuntime;\r
+        public bool MonoRuntime { get { return monoRuntime; } }\r
 \r
         public Dictionary<UUID, Group> groups;\r
         public Dictionary<UUID, string> nameCache = new Dictionary<UUID,string>();\r
@@ -74,33 +92,10 @@ namespace Radegast
         public event OnAvatarNameCallBack OnAvatarName;\r
 \r
         public readonly bool advancedDebugging = false;\r
-        public readonly bool MonoRuntime;\r
 \r
         private RadegastInstance()\r
         {\r
-            try\r
-            {\r
-                userDir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), Properties.Resources.ProgramName);\r
-                if (!Directory.Exists(userDir))\r
-                {\r
-                    Directory.CreateDirectory(userDir);\r
-                }\r
-            }\r
-            catch (Exception) \r
-            {\r
-                userDir = System.Environment.CurrentDirectory;\r
-            };\r
-            animCacheDir = Path.Combine(userDir, @"anim_cache");\r
-\r
-            // Are we running mono?\r
-            if (null == Type.GetType("Mono.Runtime"))\r
-            {\r
-                MonoRuntime = false;\r
-            }\r
-            else\r
-            {\r
-                MonoRuntime = true;\r
-            }\r
+            InitializeLoggingAndConfig();\r
 \r
             Settings.PIPELINE_REFRESH_INTERVAL = 2000.0f;\r
 \r
@@ -110,7 +105,7 @@ namespace Radegast
             client.Settings.OBJECT_TRACKING = true;\r
             client.Settings.ENABLE_SIMSTATS = true;\r
             client.Settings.FETCH_MISSING_INVENTORY = true;\r
-            client.Settings.MULTIPLE_SIMS = false;\r
+            client.Settings.MULTIPLE_SIMS = true;\r
             client.Settings.SEND_AGENT_THROTTLE = true;\r
             client.Settings.SEND_AGENT_UPDATES = true;\r
 \r
@@ -126,10 +121,10 @@ namespace Radegast
             client.Settings.USE_INTERPOLATION_TIMER = false;\r
 \r
             netcom = new RadegastNetcom(client);\r
-\r
             imageCache = new ImageCache();\r
             state = new StateManager(this);\r
-            InitializeConfig();\r
+\r
+            InitializeConfigLegacy();\r
 \r
             mainForm = new frmMain(this);\r
             mainForm.InitializeControls();\r
@@ -144,6 +139,8 @@ namespace Radegast
             client.Groups.OnGroupJoined += new GroupManager.GroupJoinedCallback(Groups_OnGroupJoined);\r
             client.Groups.OnGroupProfile += new GroupManager.GroupProfileCallback(Groups_OnGroupProfile);\r
             client.Avatars.OnAvatarNames += new AvatarManager.AvatarNamesCallback(Avatars_OnAvatarNames);\r
+            client.Network.OnLogin += new NetworkManager.LoginCallback(Network_OnLogin);\r
+            client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(Network_OnDisconnected);\r
         }\r
 \r
         public void CleanUp()\r
@@ -156,6 +153,8 @@ namespace Radegast
                 client.Groups.OnGroupJoined -= new GroupManager.GroupJoinedCallback(Groups_OnGroupJoined);\r
                 client.Groups.OnGroupProfile -= new GroupManager.GroupProfileCallback(Groups_OnGroupProfile);\r
                 client.Avatars.OnAvatarNames -= new AvatarManager.AvatarNamesCallback(Avatars_OnAvatarNames);\r
+                client.Network.OnLogin -= new NetworkManager.LoginCallback(Network_OnLogin);\r
+                client.Network.OnDisconnected -= new NetworkManager.DisconnectedCallback(Network_OnDisconnected);\r
             }\r
 \r
             if (MonoRuntime)\r
@@ -228,6 +227,53 @@ namespace Radegast
             }\r
         }\r
 \r
+        void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)\r
+        {\r
+            clientDir = null;\r
+        }\r
+\r
+        void Network_OnLogin(LoginStatus login, string message)\r
+        {\r
+            if (login != LoginStatus.Success)\r
+                return;\r
+\r
+            clientDir = Path.Combine(userDir, client.Self.Name);\r
+            try\r
+            {\r
+                if (!Directory.Exists(clientDir))\r
+                {\r
+                    Directory.CreateDirectory(clientDir);\r
+                }\r
+            }\r
+            catch (Exception)\r
+            {\r
+                clientDir = Directory.GetCurrentDirectory();\r
+            }\r
+\r
+        }\r
+\r
+        public void LogClientMessage(string fileName, string message)\r
+        {\r
+            if (clientDir == null) return;\r
+\r
+            lock (this)\r
+            {\r
+                try\r
+                {\r
+                    foreach (char lDisallowed in System.IO.Path.GetInvalidFileNameChars())\r
+                    {\r
+                        fileName = fileName.Replace(lDisallowed.ToString(), "_");\r
+                    }\r
+\r
+                    StreamWriter logfile = File.AppendText(Path.Combine(clientDir, fileName));\r
+                    logfile.WriteLine(DateTime.Now.ToString("yyyy-MM-dd [HH:mm:ss] ") + message);\r
+                    logfile.Close();\r
+                    logfile.Dispose();\r
+                }\r
+                catch (Exception) { }\r
+            }\r
+        }\r
+\r
         void Groups_OnCurrentGroups(Dictionary<UUID, Group> gr)\r
         {\r
             this.groups = gr;\r
@@ -238,7 +284,36 @@ namespace Radegast
             config.SaveCurrentConfig();\r
         }\r
 \r
-        private void InitializeConfig()\r
+        private void InitializeLoggingAndConfig()\r
+        {\r
+            // Are we running mono?\r
+            if (null == Type.GetType("Mono.Runtime"))\r
+            {\r
+                monoRuntime = false;\r
+            }\r
+            else\r
+            {\r
+                monoRuntime = true;\r
+            }\r
+\r
+            try\r
+            {\r
+                userDir = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), Properties.Resources.ProgramName);\r
+                if (!Directory.Exists(userDir))\r
+                {\r
+                    Directory.CreateDirectory(userDir);\r
+                }\r
+            }\r
+            catch (Exception)\r
+            {\r
+                userDir = System.Environment.CurrentDirectory;\r
+            };\r
+\r
+            animCacheDir = Path.Combine(userDir, @"anim_cache");\r
+            globalLogFile = Path.Combine(userDir, Properties.Resources.ProgramName + ".log");\r
+        }\r
+\r
+        private void InitializeConfigLegacy()\r
         {\r
             config = new ConfigManager(this);\r
             config.ApplyDefault();\r
index d194112..4e4edda 100644 (file)
@@ -29,6 +29,7 @@
 // $Id$\r
 //\r
 using System;\r
+using System.IO;\r
 using System.Text.RegularExpressions;\r
 using log4net.Appender;\r
 using log4net.Core;\r
@@ -46,6 +47,14 @@ namespace Radegast
             {\r
                 string loggingMessage = RenderLoggingEvent(le);\r
 \r
+                lock (this)\r
+                {\r
+                    StreamWriter logfile = File.AppendText(RadegastInstance.GlobalInstance.GlobalLogFile);\r
+                    logfile.WriteLine(loggingMessage);\r
+                    logfile.Close();\r
+                    logfile.Dispose();\r
+                }\r
+\r
                 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";\r
 \r
                 Regex RE = new Regex(regex, RegexOptions.Multiline);\r
index 15e05fc..155f8ac 100644 (file)
@@ -71,7 +71,7 @@ namespace Radegast
 \r
         private void AnimDetail_Load(object sender, EventArgs e)\r
         {\r
-            if (File.Exists(instance.animCacheDir + "/" + anim + ".fail")) {\r
+            if (File.Exists(instance.AnimCacheDir + "/" + anim + ".fail")) {\r
                 Visible = false;\r
                 return;\r
             }\r
@@ -88,7 +88,7 @@ namespace Radegast
                 cbFriends.Items.Add(f);\r
             }\r
 \r
-            if (File.Exists(instance.animCacheDir + "/" + anim + ".sla"))\r
+            if (File.Exists(instance.AnimCacheDir + "/" + anim + ".sla"))\r
             {\r
                 pnlSave.Visible = true;\r
                 return;\r
@@ -110,7 +110,7 @@ namespace Radegast
 \r
             if (res == DialogResult.OK) {\r
                 try {\r
-                    byte[] data = File.ReadAllBytes(instance.animCacheDir + "/" + anim + ".sla");\r
+                    byte[] data = File.ReadAllBytes(instance.AnimCacheDir + "/" + anim + ".sla");\r
                     File.WriteAllBytes(dlg.FileName, data);\r
                 } catch (Exception ex) {\r
                     Logger.Log("Saving animation failed: " + ex.Message, Helpers.LogLevel.Debug);\r
@@ -132,11 +132,11 @@ namespace Radegast
 \r
             if (transfer.Success) {\r
                 Logger.Log("Animation " + anim + " download success " + asset.AssetData.Length + " bytes.", Helpers.LogLevel.Debug);\r
-                File.WriteAllBytes(instance.animCacheDir + "/" + anim + ".sla", asset.AssetData);\r
+                File.WriteAllBytes(instance.AnimCacheDir + "/" + anim + ".sla", asset.AssetData);\r
                 pnlSave.Visible = true;\r
             } else {\r
                 Logger.Log("Animation " + anim + " download failed.", Helpers.LogLevel.Debug);\r
-                FileStream f = File.Create(instance.animCacheDir + "/" + anim + ".fail");\r
+                FileStream f = File.Create(instance.AnimCacheDir + "/" + anim + ".fail");\r
                 f.Close();\r
                 Visible = false;\r
             }\r
@@ -153,7 +153,7 @@ namespace Radegast
 \r
         private void btnSend_Click(object sender, EventArgs e)\r
         {\r
-            byte[] data = File.ReadAllBytes(instance.animCacheDir + "/" + anim + ".sla");\r
+            byte[] data = File.ReadAllBytes(instance.AnimCacheDir + "/" + anim + ".sla");\r
             instance.Client.Inventory.RequestCreateItemFromAsset(data, boxAnimName.Text, "(No description)", AssetType.Animation, InventoryType.Animation, instance.Client.Inventory.FindFolderForType(AssetType.Animation), On_ItemCreated);\r
             lblStatus.Text = "Uploading...";\r
             cbFriends.Enabled = false;\r
index fc1786a..c9fa12c 100644 (file)
@@ -97,9 +97,9 @@ namespace Radegast
         {\r
             if (!checkedDir) {\r
                 checkedDir = true;\r
-                if (!Directory.Exists(instance.animCacheDir))\r
+                if (!Directory.Exists(instance.AnimCacheDir))\r
                 {\r
-                    Directory.CreateDirectory(instance.animCacheDir);\r
+                    Directory.CreateDirectory(instance.AnimCacheDir);\r
                 }\r
             }\r
         }\r
index d9c2082..47cb8b1 100644 (file)
@@ -51,7 +51,7 @@ namespace Radegast
         private List<UUID> participants = new List<UUID>();\r
         ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);\r
 \r
-        public ConferenceIMTabWindow(RadegastInstance instance, UUID session)\r
+        public ConferenceIMTabWindow(RadegastInstance instance, UUID session, string sessionName)\r
         {\r
             InitializeComponent();\r
             Disposed += new EventHandler(IMTabWindow_Disposed);\r
@@ -62,7 +62,7 @@ namespace Radegast
 \r
             this.session = session;\r
 \r
-            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session);\r
+            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, sessionName);\r
             \r
             ApplyConfig(this.instance.Config.CurrentConfig);\r
 \r
index 59a70f3..eece2d3 100644 (file)
@@ -51,7 +51,7 @@ namespace Radegast
 \r
         ManualResetEvent WaitForSessionStart = new ManualResetEvent(false);\r
 \r
-        public GroupIMTabWindow(RadegastInstance instance, UUID session)\r
+        public GroupIMTabWindow(RadegastInstance instance, UUID session, string sessionName)\r
         {\r
             InitializeComponent();\r
             Disposed += new EventHandler(IMTabWindow_Disposed);\r
@@ -59,7 +59,7 @@ namespace Radegast
             this.instance = instance;\r
             this.session = session;\r
 \r
-            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session);\r
+            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, sessionName);\r
             ApplyConfig(this.instance.Config.CurrentConfig);\r
             \r
             // Callbacks\r
index a3b32b7..af3dc37 100644 (file)
@@ -61,7 +61,7 @@ namespace Radegast
             this.session = session;\r
             this.toName = toName;\r
 \r
-            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session);\r
+            textManager = new IMTextManager(this.instance, new RichTextBoxPrinter(rtbIMText), this.session, toName);\r
             ApplyConfig(this.instance.Config.CurrentConfig);\r
             this.instance.Config.ConfigApplied += new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);\r
         }\r
index a08f8df..34a6b2d 100644 (file)
@@ -578,7 +578,7 @@ namespace Radegast
 \r
         public ConferenceIMTabWindow AddConferenceIMTab(UUID session, string name)\r
         {\r
-            ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session);\r
+            ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session, name);\r
             imTab.Dock = DockStyle.Fill;\r
 \r
             toolStripContainer1.ContentPanel.Controls.Add(imTab);\r
@@ -598,7 +598,7 @@ namespace Radegast
 \r
         public GroupIMTabWindow AddGroupIMTab(UUID session, string name)\r
         {\r
-            GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session);\r
+            GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session, name);\r
             imTab.Dock = DockStyle.Fill;\r
 \r
             toolStripContainer1.ContentPanel.Controls.Add(imTab);\r
index baa3e12..826270e 100644 (file)
@@ -638,7 +638,7 @@ namespace Radegast
         private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)\r
         {\r
             client.Assets.Cache.Clear();\r
-            DirectoryInfo di = new DirectoryInfo(instance.animCacheDir);\r
+            DirectoryInfo di = new DirectoryInfo(instance.AnimCacheDir);\r
             FileInfo[] files = di.GetFiles();\r
 \r
             int num = 0;\r
index 60581fe..4382f84 100644 (file)
@@ -84,7 +84,7 @@ namespace RadegastNc
 \r
         void Network_OnCurrentSimChanged(Simulator PreviousSimulator)\r
         {\r
-            client.Appearance.SetPreviousAppearance(true);\r
+            // client.Appearance.SetPreviousAppearance(true);\r
         }\r
 \r
         private void Self_OnInstantMessage(InstantMessage im, Simulator simulator)\r