Esempio n. 1
0
 public void AddPlugin(PluginItem plugin)
 {
     listPlugins.Add(plugin);
 }
Esempio n. 2
0
 public void AddPlugin(PluginItem plugin)
 {
     listPlugins.Add(plugin);
 }
Esempio n. 3
0
        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);
        }