コード例 #1
0
ファイル: Main.cs プロジェクト: michalbali256/ezshare
            /// <summary>
            /// Loads settings from file (or sets default ones if not available) and starts manager
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private async void Main_Load(object sender, EventArgs e)
            {
                Logger.Initialise(AppDomain.CurrentDomain.FriendlyName + ".log");

                Logger.WriteLine("Loading settings.xml");
                XmlDocument doc = new XmlDocument();

                try
                {
                    try
                    {
                        doc.Load(SettingsFile);
                        manager = TorrentManager.FromXml(doc[XmlName][TorrentManager.XmlName]);
                        Logger.WriteLine("Loaded settings.xml");
                    }
                    catch (IOException)
                    {
                        Logger.WriteLine("Loading settings.xml failed, using default settings");
                        manager = new TorrentManager();
                    }
                    catch (NullReferenceException)
                    {
                        Logger.WriteLine("Loading settings.xml failed, using default settings");
                        manager = new TorrentManager();
                    }
                }
                catch (SocketException exception)
                {
                    Logger.WriteLine(exception.Message);
                    Logger.WriteLine("Unable to determine IP automatically. Please edit settings.xml.");
                    MessageBox.Show("Unable to determine IP automatically. Please edit settings.xml.");
                    manager = new TorrentManager(new byte[] { 127, 0, 0, 1 });
                    Close();
                }

                dataGridView.Rows.Clear();
                foreach (var t in manager)
                {
                    AddRow(t);
                }


                if (TorrentManager.IsPortUsed(manager.MyConnectInfo))
                {
                    Logger.WriteLine("The port " + manager.MyConnectInfo.Port + " is already in use. Please change settings.xml to use another port.");
                    MessageBox.Show("The port " + manager.MyConnectInfo.Port + " is already in use. Please change settings.xml to use another port.");
                    Close();
                }

                manager.StartListeningAsync();

                timerUpdate.Enabled = true;

                await manager.ConnectAllDownloadingTorrentsAsync();
            }