From 220ae6e46166266eb48b2f8d59e58673ef368350 Mon Sep 17 00:00:00 2001 From: Jacob Fliss Date: Sat, 27 Jul 2024 11:50:04 -0400 Subject: [PATCH] fixed filewatcher exiting after 10 seconds --- aol_4/Classes/chat.cs | 5 +++-- aol_4/Classes/email.cs | 8 ++++---- aol_4/Forms/chatroom.Designer.cs | 9 +++++---- aol_4/Forms/chatroom.cs | 29 ++++++++++++++++++++--------- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/aol_4/Classes/chat.cs b/aol_4/Classes/chat.cs index 4e6b8ea..0aebe43 100644 --- a/aol_4/Classes/chat.cs +++ b/aol_4/Classes/chat.cs @@ -165,7 +165,7 @@ public static void debugOutputCallback(object source, IrcDebugMessageEventArgs a public static void userListCallback(object source, IrcUserListReceivedEventArgs args) { - if (args.UsersPerChannel.Count == 0) + if (args.UsersPerChannel.Count <= 0) return; Debug.WriteLine("Generating user list..."); @@ -178,7 +178,8 @@ public static void userListCallback(object source, IrcUserListReceivedEventArgs if (!users.ContainsKey(channel)) // sometimes skipped?! { Debug.WriteLine("Creating users key " + channel); - users.TryAdd(channel, args.UsersPerChannel[usersPerChannel.Key]); + if (args.UsersPerChannel.ContainsKey(usersPerChannel.Key)) + users.TryAdd(channel, args.UsersPerChannel[usersPerChannel.Key]); continue; } // check if offline user is still in list diff --git a/aol_4/Classes/email.cs b/aol_4/Classes/email.cs index a49cb2a..8e327ec 100644 --- a/aol_4/Classes/email.cs +++ b/aol_4/Classes/email.cs @@ -62,10 +62,10 @@ public static bool checkNewEmail() Debug.WriteLine("[MAIL] YOU'VE GOT NEW MAIL!!"); return true; } - else - { - Debug.WriteLine("[MAIL] nothing new"); - } + //else + //{ + // Debug.WriteLine("[MAIL] nothing new"); + //} client.Disconnect(true); diff --git a/aol_4/Forms/chatroom.Designer.cs b/aol_4/Forms/chatroom.Designer.cs index e9cbd92..3bcf3a4 100644 --- a/aol_4/Forms/chatroom.Designer.cs +++ b/aol_4/Forms/chatroom.Designer.cs @@ -65,12 +65,13 @@ private void InitializeComponent() // chatRoomTextBox // chatRoomTextBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + chatRoomTextBox.BackColor = System.Drawing.Color.White; chatRoomTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; - chatRoomTextBox.Location = new System.Drawing.Point(17, 35); + chatRoomTextBox.Location = new System.Drawing.Point(23, 40); chatRoomTextBox.Margin = new System.Windows.Forms.Padding(5); chatRoomTextBox.Name = "chatRoomTextBox"; chatRoomTextBox.ReadOnly = true; - chatRoomTextBox.Size = new System.Drawing.Size(620, 547); + chatRoomTextBox.Size = new System.Drawing.Size(614, 540); chatRoomTextBox.TabIndex = 6; chatRoomTextBox.Text = ""; // @@ -190,10 +191,10 @@ private void InitializeComponent() usersListView.BorderStyle = System.Windows.Forms.BorderStyle.None; usersListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { users }); usersListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; - usersListView.Location = new System.Drawing.Point(649, 157); + usersListView.Location = new System.Drawing.Point(652, 159); usersListView.Margin = new System.Windows.Forms.Padding(5); usersListView.Name = "usersListView"; - usersListView.Size = new System.Drawing.Size(233, 271); + usersListView.Size = new System.Drawing.Size(230, 269); usersListView.TabIndex = 7; usersListView.UseCompatibleStateImageBehavior = false; usersListView.View = System.Windows.Forms.View.Details; diff --git a/aol_4/Forms/chatroom.cs b/aol_4/Forms/chatroom.cs index 7eed6a9..881d1f0 100644 --- a/aol_4/Forms/chatroom.cs +++ b/aol_4/Forms/chatroom.cs @@ -22,6 +22,7 @@ public partial class chatroom : Win95Theme string roomname = ""; string pChat = ""; int pplCount = 0; + FileSystemWatcher watch = null; List rects = new List(); bool formClosing = false; @@ -53,6 +54,8 @@ public chatroom(string channel) } chat.irc.SendRawMessage("join #" + channel); + keepReading(); + InitializeComponent(); } @@ -62,12 +65,15 @@ private void chatroom_Shown(object sender, EventArgs e) //chat.users.Clear(); Text = pChat + " Chatroom"; mainTitle.Text = pChat + " Chatroom"; + + writeFileToBox(true); + if (!backgroundWorker1.IsBusy) backgroundWorker1.RunWorkerAsync(); - rects.Add(new Rectangle(423, 467, 54, 23)); // 0 send button - rects.Add(new Rectangle(532, 265, 39, 50)); // 1 buddy info - rects.Add(new Rectangle(574, 265, 39, 50)); // 2 ignore user + //rects.Add(new Rectangle(423, 467, 54, 23)); // 0 send button + //rects.Add(new Rectangle(532, 265, 39, 50)); // 1 buddy info + //rects.Add(new Rectangle(574, 265, 39, 50)); // 2 ignore user } private void writeFileToBox(bool init = false) @@ -96,30 +102,35 @@ private void writeFileToBox(bool init = false) chatRoomTextBox.AppendText(lastLine + Environment.NewLine); chatRoomTextBox.ScrollToCaret(); })); + } else + { + Debug.WriteLine("[ERROR] handle creation failed?"); } //} catch { Debug.WriteLine("writeFileToBox just crashed."); } } public void OnChanged(object source, FileSystemEventArgs e) { - writeFileToBox(); + if (e.ChangeType == WatcherChangeTypes.Changed) + { + Debug.WriteLine($"Changed: {e.FullPath}"); + writeFileToBox(); + } } - public void keepReading() + private void keepReading() { - var watch = new FileSystemWatcher(); + watch = new FileSystemWatcher(); watch.Path = Path.GetDirectoryName(chatlog); watch.Filter = Path.GetFileName(chatlog); watch.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite; watch.Changed += new FileSystemEventHandler(OnChanged); watch.EnableRaisingEvents = true; + Debug.WriteLine($"watching {chatlog} for changes"); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { - writeFileToBox(true); - keepReading(); - // keep users list up to date while (true) {