/Forms/FormMain.cs
C# | 5902 lines | 4742 code | 622 blank | 538 comment | 1083 complexity | 8ee8a60ee574ed4551d6a56ec918084b MD5 | raw file
Possible License(s): AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- /******************************************************************************\
- * IceChat 9 Internet Relay Chat Client
- *
- * Copyright (C) 2011 Paul Vanderzee <snerf@icechat.net>
- * <www.icechat.net>
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Please consult the LICENSE.txt file included with this project for
- * more details
- *
- \******************************************************************************/
-
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing.Drawing2D;
- using System.Drawing;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.Xml.Serialization;
- using System.IO;
- using System.Reflection;
- using System.Runtime.InteropServices;
-
-
- using IceChatPlugin;
-
- namespace IceChat
- {
- public partial class FormMain : Form
- {
- public static FormMain Instance;
-
- private string optionsFile;
- private string messagesFile;
- private string fontsFile;
- private string colorsFile;
- private string soundsFile;
- private string favoriteChannelsFile;
- private string serversFile;
- private string aliasesFile;
- private string popupsFile;
- private string pluginsFile;
-
- private string currentFolder;
- private string logsFolder;
- private string pluginsFolder;
- private string emoticonsFile;
- private string scriptsFolder;
- private string soundsFolder;
- private string picturesFolder;
-
- private List<LanguageItem> languageFiles;
- private LanguageItem currentLanguageFile;
-
- private StreamWriter errorFile;
-
- private IceChatOptions iceChatOptions;
- private IceChatColors iceChatColors;
- private IceChatMessageFormat iceChatMessages;
- private IceChatFontSetting iceChatFonts;
- private IceChatAliases iceChatAliases;
- private IceChatPopupMenus iceChatPopups;
- private IceChatEmoticon iceChatEmoticons;
- private IceChatLanguage iceChatLanguage;
- private IceChatSounds iceChatSounds;
- private IceChatPluginFile iceChatPlugins;
-
- //private System.Threading.Mutex mutex;
-
- private List<IPluginIceChat> loadedPlugins;
-
- private IdentServer identServer;
-
- private TabPage nickListTab;
- private TabPage serverListTab;
- private TabPage channelListTab;
- private TabPage buddyListTab;
-
- private delegate IceTabPage AddWindowDelegate(IRCConnection connection, string windowName, IceTabPage.WindowType windowType);
-
- private delegate void CurrentWindowDelegate(string data, int color);
- private delegate void WindowMessageDelegate(IRCConnection connection, string name, string data, int color, bool scrollToBottom);
- private delegate void CurrentWindowMessageDelegate(IRCConnection connection, string data, int color, bool scrollToBottom);
-
- private System.Timers.Timer flashTrayIconTimer;
- private int flashTrayCount;
-
- private System.Timers.Timer flashTaskBarIconTimer;
- private int flashTaskBarCount;
-
- private System.Media.SoundPlayer player;
- private bool muteAllSounds;
-
- [StructLayout(LayoutKind.Sequential)]
- private struct OSVERSIONINFOEX
- {
- public int dwOSVersionInfoSize;
- public int dwMajorVersion;
- public int dwMinorVersion;
- public int dwBuildNumber;
- public int dwPlatformId;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string szCSDVersion;
- public short wServicePackMajor;
- public short wServicePackMinor;
- public short wSuiteMask;
- public byte wProductType;
- public byte wReserved;
- }
-
- [DllImport("kernel32.dll")]
- private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
-
- private const int VER_NT_WORKSTATION = 1;
- private const int VER_NT_DOMAIN_CONTROLLER = 2;
- private const int VER_NT_SERVER = 3;
- private const int VER_SUITE_SMALLBUSINESS = 1;
- private const int VER_SUITE_ENTERPRISE = 2;
- private const int VER_SUITE_TERMINAL = 16;
- private const int VER_SUITE_DATACENTER = 128;
- private const int VER_SUITE_SINGLEUSERTS = 256;
- private const int VER_SUITE_PERSONAL = 512;
- private const int VER_SUITE_BLADE = 1024;
-
- public const string ProgramID = "IceChat 9";
- public const string VersionID = "Release Candidate 2.5";
-
- /// <summary>
- /// All the Window Message Types used for Coloring the Tab Text for Different Events
- /// </summary>
- internal enum ServerMessageType
- {
- Default = 0,
- Message = 1,
- Action = 2,
- JoinChannel = 3,
- PartChannel = 4,
- QuitServer = 5,
- ServerMessage = 6,
- Other = 7
- }
-
- public FormMain(string[] args, Form splash)
- {
- FormMain.Instance = this;
-
- player = new System.Media.SoundPlayer();
-
- bool forceCurrentFolder = false;
-
- if (args.Length > 0)
- {
- string prevArg = "";
- foreach (string arg in args)
- {
- if (prevArg.Length == 0)
- prevArg = arg;
- else
- {
- switch (prevArg.ToLower())
- {
- case "-profile":
- currentFolder = arg;
- //check if the folder exists, ir not, create it
- if (!Directory.Exists(currentFolder))
- Directory.CreateDirectory(currentFolder);
- forceCurrentFolder = true;
- break;
- }
-
- prevArg = "";
- }
- }
- }
-
- //mutex = new System.Threading.Mutex(true, "IceChatMutex");
-
- #region Settings Files
-
- //check if the xml settings files exist in current folder
- if (currentFolder == null)
- currentFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
-
- if (!File.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml") && !forceCurrentFolder)
- {
- if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat"))
- Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat");
-
- currentFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat";
- }
-
- //load all files from the Local AppData folder, unless it exist in the current folder
- serversFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml";
- optionsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatOptions.xml";
- messagesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatMessages.xml";
- fontsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatFonts.xml";
- colorsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatColors.xml";
- soundsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatSounds.xml";
- favoriteChannelsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatChannels.xml";
- aliasesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatAliases.xml";
- popupsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPopups.xml";
- pluginsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPlugins.xml";
- emoticonsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Emoticons" + System.IO.Path.DirectorySeparatorChar + "IceChatEmoticons.xml";
-
- logsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Logs";
- scriptsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Scripts";
- soundsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Sounds";
- picturesFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Pictures";
-
- //pluginsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Plugins";
- pluginsFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + System.IO.Path.DirectorySeparatorChar + "Plugins";
- //pluginsFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
-
- if (!Directory.Exists(pluginsFolder))
- Directory.CreateDirectory(pluginsFolder);
-
- if (!Directory.Exists(scriptsFolder))
- Directory.CreateDirectory(scriptsFolder);
-
- if (!Directory.Exists(soundsFolder))
- Directory.CreateDirectory(soundsFolder);
-
- if (!Directory.Exists(picturesFolder))
- Directory.CreateDirectory(picturesFolder);
-
-
- #endregion
-
- languageFiles = new List<LanguageItem>();
-
- DirectoryInfo languageDirectory = null;
-
- languageDirectory = new DirectoryInfo(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");
- if (!Directory.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages"))
- Directory.CreateDirectory(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");
-
- if (languageDirectory != null)
- {
- // scan the language directory for xml files and make LanguageItems for each file
- FileInfo[] langFiles = languageDirectory.GetFiles("*.xml");
- foreach (FileInfo fi in langFiles)
- {
- string langFile = languageDirectory.FullName + System.IO.Path.DirectorySeparatorChar + fi.Name;
- LanguageItem languageItem = LoadLanguageItem(langFile);
- if (languageItem != null) languageFiles.Add(languageItem);
- }
-
- if (languageFiles.Count == 0)
- {
- currentLanguageFile = new LanguageItem();
- languageFiles.Add(currentLanguageFile); // default language English
- }
- }
-
- LoadOptions();
- LoadColors();
- LoadSounds();
-
- // use the language saved in options if availlable,
- // if not (e.g. user deleted xml file) default is used
- foreach (LanguageItem li in languageFiles)
- {
- if (li.LanguageName == iceChatOptions.Language)
- {
- currentLanguageFile = li;
- break;
- }
- }
- LoadLanguage(); // The language class MUST be loaded before any GUI component is created
-
- //check if we have any servers/settings saved, if not, load firstrun
- if (!File.Exists(serversFile))
- {
- FormFirstRun firstRun = new FormFirstRun(currentFolder);
- firstRun.ShowDialog(this);
- }
-
- InitializeComponent();
- //load icons from Embedded Resources
- this.toolStripQuickConnect.Image = StaticMethods.LoadResourceImage("quick.png");
- this.toolStripSettings.Image = StaticMethods.LoadResourceImage("settings.png");
- this.toolStripColors.Image = StaticMethods.LoadResourceImage("colors.png");
- this.toolStripEditor.Image = StaticMethods.LoadResourceImage("editor.png");
- this.toolStripAway.Image = StaticMethods.LoadResourceImage("away.png");
- this.toolStripSystemTray.Image = StaticMethods.LoadResourceImage("system-tray.png");
- this.toolStripUpdate.Image = StaticMethods.LoadResourceImage("update.png");
-
- //disable this by default
- this.toolStripUpdate.Visible = false;
-
- this.minimizeToTrayToolStripMenuItem.Image = StaticMethods.LoadResourceImage("new-tray-icon.ico");
- this.debugWindowToolStripMenuItem.Image = StaticMethods.LoadResourceImage("window-icon.ico");
- this.exitToolStripMenuItem.Image = StaticMethods.LoadResourceImage("disconected.png");
- this.iceChatSettingsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("settings.png");
- this.iceChatColorsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("colors.png");
- this.iceChatEditorToolStripMenuItem.Image = StaticMethods.LoadResourceImage("editormenu.png");
- this.codePlexPageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("codeplex.ico");
- this.forumsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("smf.ico");
- this.facebookFanPageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("facebook.png");
- this.checkForUpdateToolStripMenuItem.Image = StaticMethods.LoadResourceImage("update-menu.png");
- this.iceChatHomePageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("home.png");
- this.downloadPluginsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("plug-icon.png");
- this.pluginsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("plug-icon.png");
-
- //this.muteAllSoundsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("mute.png");
- //this.browseDataFolderToolStripMenuItem.Image = StaticMethods.LoadResourceImage("folder.ico");
-
- this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
- this.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
-
- this.toolStripMain.VisibleChanged += new EventHandler(toolStripMain_VisibleChanged);
-
- serverListToolStripMenuItem.Checked = iceChatOptions.ShowServerTree;
- panelDockLeft.Visible = serverListToolStripMenuItem.Checked;
- splitterLeft.Visible = serverListToolStripMenuItem.Checked;
-
- nickListToolStripMenuItem.Checked = iceChatOptions.ShowNickList;
- panelDockRight.Visible = nickListToolStripMenuItem.Checked;
- splitterRight.Visible = nickListToolStripMenuItem.Checked;
-
- statusBarToolStripMenuItem.Checked = iceChatOptions.ShowStatusBar;
- statusStripMain.Visible = statusBarToolStripMenuItem.Checked;
-
- toolBarToolStripMenuItem.Checked = iceChatOptions.ShowToolBar;
- toolStripMain.Visible = toolBarToolStripMenuItem.Checked;
-
- serverTree = new ServerTree();
- serverTree.Dock = DockStyle.Fill;
-
- this.Text = ProgramID + " :: " + VersionID + " :: September 14 2011";
- this.notifyIcon.Text = ProgramID + " :: " + VersionID;
-
- if (!Directory.Exists(logsFolder))
- Directory.CreateDirectory(logsFolder);
-
- try
- {
- errorFile = new StreamWriter(logsFolder + System.IO.Path.DirectorySeparatorChar + "errors.log");
- }
- catch (IOException io)
- {
- System.Diagnostics.Debug.WriteLine("Can not create errors.log:" + io.Message);
- }
-
- if (!iceChatOptions.TimeStamp.EndsWith(" "))
- iceChatOptions.TimeStamp += " ";
-
- if (iceChatOptions.WindowSize != null)
- {
- if (iceChatOptions.WindowSize.Width != 0)
- this.Size = iceChatOptions.WindowSize;
- else
- {
- Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
- this.Width = r.Width;
- this.Height = r.Height;
- }
- }
-
- if (iceChatOptions.WindowLocation != null)
- this.Location = iceChatOptions.WindowLocation;
-
- statusStripMain.Visible = iceChatOptions.ShowStatusBar;
- inputPanel.ShowColorPicker = iceChatOptions.ShowColorPicker;
- inputPanel.ShowEmoticonPicker = iceChatOptions.ShowEmoticonPicker;
- inputPanel.ShowSearchPanel = false;
-
- LoadAliases();
- LoadPopups();
- LoadEmoticons();
- LoadMessageFormat();
- LoadFonts();
-
- if (iceChatOptions.CurrentTheme == null)
- iceChatOptions.CurrentTheme = "Default";
- else
- {
- //load in the new color theme, if it not Default
- if (iceChatOptions.CurrentTheme != "Default")
- {
- string themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Colors-" + iceChatOptions.CurrentTheme + ".xml";
- if (File.Exists(themeFile))
- {
- XmlSerializer deserializer = new XmlSerializer(typeof(IceChatColors));
- TextReader textReader = new StreamReader(themeFile);
- iceChatColors = (IceChatColors)deserializer.Deserialize(textReader);
- textReader.Close();
- textReader.Dispose();
- colorsFile = themeFile;
- }
- else
- {
- System.Diagnostics.Debug.WriteLine("Color Theme File not found:" + themeFile);
- }
-
- themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Messages-" + iceChatOptions.CurrentTheme + ".xml";
- if (File.Exists(themeFile))
- {
- XmlSerializer deserializer = new XmlSerializer(typeof(IceChatMessageFormat));
- TextReader textReader = new StreamReader(themeFile);
- iceChatMessages = (IceChatMessageFormat)deserializer.Deserialize(textReader);
- textReader.Close();
- textReader.Dispose();
-
- messagesFile = themeFile;
- }
- else
- {
- System.Diagnostics.Debug.WriteLine("Messages Theme File not found:" + themeFile);
- }
-
- }
- }
- if (iceChatOptions.Themes == null)
- {
- iceChatOptions.Themes = new string[1];
- iceChatOptions.Themes[0] = "Default";
- }
-
- channelList = new ChannelList();
- channelList.Dock = DockStyle.Fill;
- buddyList = new BuddyList();
- buddyList.Dock = DockStyle.Fill;
-
- toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
- menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];
- statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
- toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];
- inputPanel.SetInputBoxColors();
- channelList.SetListColors();
- buddyList.SetListColors();
-
- nickList = new NickList();
- nickList.Header = iceChatLanguage.consoleTabTitle;
- nickList.Dock = DockStyle.Fill;
-
- serverListTab = new TabPage("Favorite Servers");
- Panel serverPanel = new Panel();
- serverPanel.Dock = DockStyle.Fill;
- serverPanel.Controls.Add(serverTree);
- serverListTab.Controls.Add(serverPanel);
- serverListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
- serverListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
- this.panelDockLeft.TabControl.TabPages.Add(serverListTab);
-
- nickListTab = new TabPage("Nick List");
- Panel nickPanel = new Panel();
- nickPanel.Dock = DockStyle.Fill;
- nickPanel.Controls.Add(nickList);
- nickListTab.Controls.Add(nickPanel);
- nickListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
- nickListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
- this.panelDockRight.TabControl.TabPages.Add(nickListTab);
-
- channelListTab = new TabPage("Favorite Channels");
- Panel channelPanel = new Panel();
- channelPanel.Dock = DockStyle.Fill;
- channelPanel.Controls.Add(channelList);
- channelListTab.Controls.Add(channelPanel);
- channelListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
- channelListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
- this.panelDockRight.TabControl.TabPages.Add(channelListTab);
-
- buddyListTab = new TabPage("Buddy List");
- Panel buddyPanel = new Panel();
- buddyPanel.Dock = DockStyle.Fill;
- buddyPanel.Controls.Add(buddyList);
- buddyListTab.Controls.Add(buddyPanel);
- buddyListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
- buddyListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
- this.panelDockRight.TabControl.TabPages.Add(buddyListTab);
-
- panelDockLeft.Width = iceChatOptions.LeftPanelWidth;
- panelDockLeft.TabControl.Alignment = TabAlignment.Left;
- panelDockRight.Width = iceChatOptions.RightPanelWidth;
- panelDockRight.TabControl.Alignment = TabAlignment.Right;
-
- nickList.Font = new Font(iceChatFonts.FontSettings[3].FontName, iceChatFonts.FontSettings[3].FontSize);
- serverTree.Font = new Font(iceChatFonts.FontSettings[4].FontName, iceChatFonts.FontSettings[4].FontSize);
-
- inputPanel.OnCommand +=new InputPanel.OnCommandDelegate(inputPanel_OnCommand);
- inputPanel.InputBoxFont = new Font(iceChatFonts.FontSettings[5].FontName, iceChatFonts.FontSettings[5].FontSize);
-
- mainTabControl.SelectedIndexChanged += new IceTabControl.TabEventHandler(TabSelectedIndexChanged);
- mainTabControl.OnTabClosed += new IceTabControl.TabClosedDelegate(mainTabControl_OnTabClosed);
-
- panelDockLeft.Initialize();
- panelDockRight.Initialize();
-
- //menuMainStrip.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);
-
- serverTree.NewServerConnection += new NewServerConnectionDelegate(NewServerConnection);
- serverTree.SaveDefault += new ServerTree.SaveDefaultDelegate(OnDefaultServerSettings);
-
- CreateDefaultConsoleWindow();
-
- this.FormClosing += new FormClosingEventHandler(FormMainClosing);
- this.Resize += new EventHandler(FormMainResize);
-
- if (iceChatOptions.IdentServer)
- identServer = new IdentServer();
-
- loadedPlugins = new List<IPluginIceChat>();
-
- if (iceChatLanguage.LanguageName != "English") ApplyLanguage(); // ApplyLanguage can first be called after all child controls are created
-
- WindowMessage(null, "Console", "Data Folder: " + currentFolder, 4, true);
- WindowMessage(null, "Console", "Plugins Folder: " + pluginsFolder, 4, true);
-
- //check for an update
- System.Threading.Thread checkThread = new System.Threading.Thread(checkForUpdate);
- checkThread.Name = "CheckUpdateThread";
- checkThread.Start();
-
- //check for router ip
- if (iceChatOptions.DCCLocalIP == null || iceChatOptions.DCCLocalIP.Length == 0)
- {
- System.Threading.Thread thread = new System.Threading.Thread(getLocalIPAddress);
- thread.Name = "DCCIP";
- thread.Start();
- }
-
- splash.Close();
- splash.Dispose();
-
- //load any plugin addons
- LoadPlugins();
-
- //load the plugin settings file
- LoadPluginFiles();
-
- //set any plugins as disabled
- //add any items top the pluginsFile if they do not exist, or remove any that do not
- foreach (IPluginIceChat ipc in FormMain.Instance.IceChatPlugins)
- {
- bool found = false;
- for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
- {
- if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.FileName))
- {
- found = true;
-
- //check if the plugin is enabled or not
- if (iceChatPlugins.listPlugins[i].Enabled == false)
- {
- WindowMessage(null, "Console", "Disabled Plugin - " + ipc.Name + " v" + ipc.Version, 4, true);
-
- foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
- if (t.ToolTipText.ToLower() == ipc.FileName.ToLower())
- t.Image = StaticMethods.LoadResourceImage("CloseButton.png");
-
- ipc.Enabled = false;
- }
- }
- }
-
- if (found == false)
- {
- //plugin file not found in plugin Items file, add it
- PluginItem item = new PluginItem();
- item.Enabled = true;
- item.PluginFile = ipc.FileName;
- iceChatPlugins.AddPlugin(item);
- SavePluginFiles();
- }
-
- //fire the event that the program has fully loaded
- if (ipc.Enabled == true)
- ipc.MainProgramLoaded();
- }
-
- if (iceChatPlugins.listPlugins.Count != loadedPlugins.Count)
- {
- //find the file that is missing
- List<int> removeItems = new List<int>();
- for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
- {
- bool found = false;
- foreach (IPluginIceChat ipc in FormMain.Instance.IceChatPlugins)
- {
- if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.FileName))
- found = true;
- }
-
- if (found == false)
- removeItems.Add(i);
- }
-
- if (removeItems.Count > 0)
- {
- try
- {
- foreach (int i in removeItems)
- iceChatPlugins.listPlugins.Remove(iceChatPlugins.listPlugins[i]);
- }
- catch { }
-
- SavePluginFiles();
- }
- }
-
- this.Activated += new EventHandler(FormMainActivated);
-
- nickList.ShowNickButtons = iceChatOptions.ShowNickButtons;
- serverTree.ShowServerButtons = iceChatOptions.ShowServerButtons;
-
- this.flashTrayIconTimer = new System.Timers.Timer(2000);
- this.flashTrayIconTimer.Enabled = false;
- this.flashTrayIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTrayIconTimer_Elapsed);
- this.notifyIcon.Tag = "off";
- this.flashTrayCount = 0;
-
- this.flashTaskBarIconTimer = new System.Timers.Timer(2000);
- this.flashTaskBarIconTimer.Enabled = false;
- this.flashTaskBarIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTaskBarIconTimer_Elapsed);
- this.Tag = "off";
- this.flashTrayCount = 0;
-
- ToolStripMenuItem closeWindow = new ToolStripMenuItem(StaticMethods.LoadResourceImage("CloseButton.png"));
- closeWindow.Alignment = ToolStripItemAlignment.Right;
- closeWindow.Click += new EventHandler(closeWindow_Click);
- menuMainStrip.Items.Add(closeWindow);
- }
-
- private void closeWindow_Click(object sender, EventArgs e)
- {
- //close the current window
- mainTabControl.CloseCurrentTab();
- }
-
- private void UpdateIcon(string iconName, string tag)
- {
- this.Invoke((MethodInvoker)delegate()
- {
- this.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage(iconName).GetHicon());
- this.Tag = tag;
- });
- }
-
- private void UpdateTrayIcon(string iconName, string tag)
- {
- this.Invoke((MethodInvoker)delegate()
- {
- this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage(iconName).GetHicon());
- this.notifyIcon.Tag = tag;
- });
- }
-
- private void flashTaskBarIconTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- if (this.Tag.Equals("on"))
- {
- UpdateIcon("new-tray-icon.ico", "off");
- }
- else
- {
- UpdateIcon("tray-icon-flash.ico", "on");
- }
-
- flashTaskBarCount++;
-
- if (flashTaskBarCount == 10)
- {
- this.flashTaskBarIconTimer.Stop();
- UpdateIcon("new-tray-icon.ico", "off");
- flashTaskBarCount = 0;
- }
-
- }
- else
- {
- this.flashTaskBarIconTimer.Stop();
- UpdateIcon("new-tray-icon.ico", "off");
- }
- }
-
- private void flashTrayIconTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (this.notifyIcon.Visible == true)
- {
- if (this.notifyIcon.Tag.Equals("on"))
- {
- UpdateTrayIcon("new-tray-icon.ico", "off");
- }
- else
- {
- UpdateTrayIcon("tray-icon-flash.ico", "on");
- }
-
- flashTrayCount++;
-
- if (flashTrayCount == 10)
- {
- this.flashTrayIconTimer.Stop();
- UpdateTrayIcon("new-tray-icon.ico", "off");
- flashTrayCount = 0;
- }
- }
- else
- {
- this.flashTrayIconTimer.Stop();
- UpdateTrayIcon("new-tray-icon.ico", "off");
- }
- }
-
- private void FormMainActivated(object sender, EventArgs e)
- {
- if (iceChatOptions.IsOnTray == true)
- {
- minimizeToTrayToolStripMenuItem.PerformClick();
- }
-
- //auto start any Auto Connect Servers
- foreach (ServerSetting s in serverTree.ServersCollection.listServers)
- {
- if (s.AutoStart)
- {
- NewServerConnection(s);
- }
- }
-
- //remove the event handler, because it only needs to be run once, on startup
- this.Activated -= FormMainActivated;
- }
-
- private void FormMainResize(object sender, EventArgs e)
- {
- if (this.WindowState == FormWindowState.Minimized)
- {
- if (iceChatOptions.MinimizeToTray)
- {
- this.notifyIcon.Visible = true;
- this.Hide();
- }
- }
- }
-
- private void toolStripMain_VisibleChanged(object sender, EventArgs e)
- {
- toolBarToolStripMenuItem.Checked =toolStripMain.Visible;
- }
-
- /// <summary>
- /// Save Default Server Settings
- /// </summary>
- private void OnDefaultServerSettings()
- {
- SaveOptions();
- }
-
- #region Load Language File
-
- private LanguageItem LoadLanguageItem(string languageFileName)
- {
- if (File.Exists(languageFileName))
- {
- LanguageItem languageItem = null;
- XmlSerializer deserializer = new XmlSerializer(typeof(LanguageItem));
- TextReader textReader = new StreamReader(languageFileName);
- try
- {
- languageItem = (LanguageItem)deserializer.Deserialize(textReader);
- languageItem.LanguageFile = languageFileName;
- }
- catch
- {
- languageItem = null;
- }
- finally
- {
- textReader.Close();
- textReader.Dispose();
- }
- return languageItem;
- }
- else
- {
- return null;
- }
- }
-
- private void LoadLanguage()
- {
- if (File.Exists(currentLanguageFile.LanguageFile))
- {
- XmlSerializer deserializer = new XmlSerializer(typeof(IceChatLanguage));
- TextReader textReader = new StreamReader(currentLanguageFile.LanguageFile);
- iceChatLanguage = (IceChatLanguage)deserializer.Deserialize(textReader);
- textReader.Close();
- textReader.Dispose();
- }
- else
- {
- iceChatLanguage = new IceChatLanguage();
- //write the language file
- XmlSerializer serializer = new XmlSerializer(typeof(IceChatLanguage));
- TextWriter textWriter = new StreamWriter(currentFolder + Path.DirectorySeparatorChar + "Languages" + Path.DirectorySeparatorChar + "English.xml");
- serializer.Serialize(textWriter,iceChatLanguage);
- textWriter.Close();
- textWriter.Dispose();
- }
- }
-
- private void ApplyLanguage()
- {
- mainToolStripMenuItem.Text = iceChatLanguage.mainToolStripMenuItem;
- minimizeToTrayToolStripMenuItem.Text = iceChatLanguage.minimizeToTrayToolStripMenuItem;
- debugWindowToolStripMenuItem.Text = iceChatLanguage.debugWindowToolStripMenuItem;
- exitToolStripMenuItem.Text = iceChatLanguage.exitToolStripMenuItem;
- optionsToolStripMenuItem.Text = iceChatLanguage.optionsToolStripMenuItem;
- iceChatSettingsToolStripMenuItem.Text = iceChatLanguage.iceChatSettingsToolStripMenuItem;
- iceChatColorsToolStripMenuItem.Text = iceChatLanguage.iceChatColorsToolStripMenuItem;
- iceChatEditorToolStripMenuItem.Text = iceChatLanguage.iceChatEditorToolStripMenuItem;
- pluginsToolStripMenuItem.Text = iceChatLanguage.pluginsToolStripMenuItem;
- viewToolStripMenuItem.Text = iceChatLanguage.viewToolStripMenuItem;
- serverListToolStripMenuItem.Text = iceChatLanguage.serverListToolStripMenuItem;
- nickListToolStripMenuItem.Text = iceChatLanguage.nickListToolStripMenuItem;
- statusBarToolStripMenuItem.Text = iceChatLanguage.statusBarToolStripMenuItem;
- toolBarToolStripMenuItem.Text = iceChatLanguage.toolBarToolStripMenuItem;
- helpToolStripMenuItem.Text = iceChatLanguage.helpToolStripMenuItem;
- codePlexPageToolStripMenuItem.Text = iceChatLanguage.codePlexPageToolStripMenuItem;
- iceChatHomePageToolStripMenuItem.Text = iceChatLanguage.iceChatHomePageToolStripMenuItem;
- forumsToolStripMenuItem.Text = iceChatLanguage.forumsToolStripMenuItem;
- aboutToolStripMenuItem.Text = iceChatLanguage.aboutToolStripMenuItem;
- toolStripQuickConnect.Text = iceChatLanguage.toolStripQuickConnect;
- toolStripSettings.Text = iceChatLanguage.toolStripSettings;
- toolStripColors.Text = iceChatLanguage.toolStripColors;
- toolStripEditor.Text = iceChatLanguage.toolStripEditor;
- toolStripAway.Text = iceChatLanguage.toolStripAway;
- toolStripSystemTray.Text = iceChatLanguage.toolStripSystemTray;
- toolStripStatus.Text = iceChatLanguage.toolStripStatus;
-
- channelListTab.Text = iceChatLanguage.tabPageFaveChannels;
- nickListTab.Text = iceChatLanguage.tabPageNicks;
- serverListTab.Text = iceChatLanguage.serverTreeHeader;
-
- channelList.ApplyLanguage();
- nickList.ApplyLanguage();
- serverTree.ApplyLanguage();
- inputPanel.ApplyLanguage();
-
- mainTabControl.Invalidate(); // repaint tabs to apply changes to user drawn tabs
- }
-
- #endregion
-
- private void FormMainClosing(object sender, FormClosingEventArgs e)
- {
- //check if there are any connections open
- foreach (IRCConnection c in serverTree.ServerConnections.Values)
- {
- if (c.IsConnected)
- {
- DialogResult dr = MessageBox.Show("You are connected to a Server(s), are you sure you want to close IceChat?", "Close IceChat", MessageBoxButtons.OKCancel);
- if (e.CloseReason == CloseReason.UserClosing && dr == DialogResult.Cancel)
- {
- e.Cancel = true;
- return;
- }
- else
- break;
- }
- }
-
- if (identServer != null)
- {
- identServer.Stop();
- identServer = null;
- }
-
- foreach (IPluginIceChat ipc in loadedPlugins)
- ipc.Dispose();
-
- //unload and dispose of all the plugins
- foreach (IPluginIceChat ipc in loadedPlugins)
- {
- //AppDomain.Unload(ipc.domain);
- ipc.Dispose();
- }
-
- for (int i = 0; i < loadedPlugins.Count; i++)
- {
- loadedPlugins.RemoveAt(i);
- }
-
- //disconnect all the servers
- foreach (IRCConnection c in serverTree.ServerConnections.Values)
- {
- if (c.IsConnected)
- {
- c.AttemptReconnect = false;
- ParseOutGoingCommand(c, "//quit " + c.ServerSetting.QuitMessage);
- }
- }
-
- if (iceChatOptions.SaveWindowPosition)
- {
- //save the window position , as long as its not minimized
- if (this.WindowState != FormWindowState.Minimized && this.notifyIcon.Visible == false)
- {
- iceChatOptions.WindowLocation = this.Location;
- iceChatOptions.WindowSize = this.Size;
- if (!panelDockRight.IsDocked)
- iceChatOptions.RightPanelWidth = panelDockRight.Width;
- if (!panelDockLeft.IsDocked)
- iceChatOptions.LeftPanelWidth = panelDockLeft.Width;
- }
-
- iceChatOptions.IsOnTray = this.notifyIcon.Visible;
-
- SaveOptions();
- }
-
- //mutex.ReleaseMutex();
-
- if (errorFile != null)
- {
- errorFile.Close();
- errorFile.Dispose();
- }
- }
-
- /// <summary>
- /// Play the specified sound file (currently only supports WAV files)
- /// </summary>
- /// <param name="sound"></param>
- internal void PlaySoundFile(string key)
- {
- IceChatSounds.SoundEntry sound = IceChatSounds.getSound(key);
- if (sound != null && !muteAllSounds)
- {
- string file = sound.getSoundFile();
- if (file != null && file.Length > 0)
- {
- try
- {
- if (iceChatOptions.SoundUseExternalCommand && iceChatOptions.SoundExternalCommand.Length > 0)
- ParseOutGoingCommand(inputPanel.CurrentConnection, iceChatOptions.SoundExternalCommand + " " + file);
- else
- ParseOutGoingCommand(inputPanel.CurrentConnection, "/play " + file);
-
- //player.SoundLocation = @file;
- //player.Play();
- }
- catch { }
- }
- }
- }
-
- /// <summary>
- /// Create a Default Tab for showing Welcome Information
- /// </summary>
- private void CreateDefaultConsoleWindow()
- {
- IceTabPage p = new IceTabPage(IceTabPage.WindowType.Console, "Console");
- p.AddConsoleTab(iceChatLanguage.consoleTabWelcome);
- mainTabControl.TabPages.Add(p);
-
- WindowMessage(null, "Console", "\x00034Welcome to " + ProgramID + " " + VersionID, 1, false);
- WindowMessage(null, "Console", "\x00034** This is a Release Candidate version, fully functional, not all the options are added **", 1, false);
- WindowMessage(null, "Console", "\x00033If you want a fully working version of \x0002IceChat\x0002, visit http://www.icechat.net and download IceChat 7.70", 1, false);
- WindowMessage(null, "Console", "\x00034Please visit \x00030,4#icechat\x0003 on \x00030,2irc://irc.quakenet.org/icechat\x0003 if you wish to help with this project", 1, true);
- }
-
- #region Internal Properties
-
- /// <summary>
- /// Gets the instance of the Nick List
- /// </summary>
- internal NickList NickList
- {
- get { return nickList; }
- }
- /// <summary>
- /// Gets the instance of the Server Tree
- /// </summary>
- internal ServerTree ServerTree
- {
- get { return serverTree; }
- }
- /// <summary>
- /// Gets the instance of the Main Tab Control
- /// </summary>
- internal IceTabControl TabMain
- {
- get { return mainTabControl; }
- }
-
- /// <summary>
- /// Gets the instance of the InputPanel
- /// </summary>
- internal InputPanel InputPanel
- {
- get
- {
- return this.inputPanel;
- }
- }
-
- internal IceChatOptions IceChatOptions
- {
- get
- {
- return this.iceChatOptions;
- }
- }
-
- internal IceChatMessageFormat MessageFormats
- {
- get
- {
- return this.iceChatMessages;
- }
- }
-
- internal IceChatFontSetting IceChatFonts
- {
- get
- {
- return this.iceChatFonts;
- }
- }
-
- internal IceChatColors IceChatColors
- {
- get
- {
- return this.iceChatColors;
- }
- }
-
- internal IceChatSounds IceChatSounds
- {
- get
- {
- return this.iceChatSounds;
- }
- }
-
- internal IceChatAliases IceChatAliases
- {
- get
- {
- return iceChatAliases;
- }
- set
- {
- iceChatAliases = value;
- //save the aliases
- SaveAliases();
- }
- }
-
- internal IceChatPopupMenus IceChatPopupMenus
- {
- get
- {
- return iceChatPopups;
- }
- set
- {
- iceChatPopups = value;
- //save the popups
- SavePopups();
- }
-
- }
-
- internal IceChatEmoticon IceChatEmoticons
- {
- get
- {
- return iceChatEmoticons;
- }
- set
- {
- iceChatEmoticons = value;
- //save the Emoticons
- SaveEmoticons();
- }
- }
-
- internal IceChatLanguage IceChatLanguage
- {
- get
- {
- return iceChatLanguage;
- }
- }
-
- internal List<LanguageItem> IceChatLanguageFiles
- {
- get
- {
- return languageFiles;
- }
- }
-
- internal LanguageItem IceChatCurrentLanguageFile
- {
- get
- {
- return currentLanguageFile;
- }
- set
- {
- if (currentLanguageFile != value)
- {
- currentLanguageFile = value;
- LoadLanguage();
- ApplyLanguage();
- }
- }
- }
-
- internal string FavoriteChannelsFile
- {
- get
- {
- return favoriteChannelsFile;
- }
- }
-
- internal BuddyList BuddyList
- {
- get
- {
- return this.buddyList;
- }
- }
-
- internal string MessagesFile
- {
- get
- {
- return messagesFile;
- }
- set
- {
- messagesFile = value;
- }
- }
-
- internal string ColorsFile
- {
- get
- {
- return colorsFile;
- }
- set
- {
- colorsFile = value;
- }
- }
-
- internal string ServersFile
- {
- get
- {
- return serversFile;
- }
- }
-
- internal string AliasesFile
- {
- get
- {
- return aliasesFile;
- }
- }
-
- internal string PopupsFile
- {
- get
- {
- return popupsFile;
- }
- }
-
- internal List<IPluginIceChat> IceChatPlugins
- {
- get
- {
- return loadedPlugins;
- }
- }
-
- public string LogsFolder
- {
- get
- {
- return logsFolder;
- }
- }
-
- public string CurrentFolder
- {
- get
- {
- return currentFolder;
- }
- }
-
- internal string EmoticonsFolder
- {
- get
- {
- return System.IO.Path.GetDirectoryName(emoticonsFile);
- }
- }
-
- internal void StatusText(string data)
- {
- try
- {
- this.Invoke((MethodInvoker)delegate()
- {
- toolStripStatus.Text = "Status: " + data;
- });
- }
- catch { }
- }
-
- #endregion
-
- #region Private Properti…
Large files files are truncated, but you can click here to view the full file