示例#1
0
        private void Initialize()
        {
            m_PlayingControl = new PlayingControl();
            ReadSettings();
            Settings.Settings.Instance.MessageFilterLevel = 1;
            Messages.Instance.MessageReceived            += new MessageReceivedHandler(MessageReceived);
            if (Ares.Settings.Settings.Instance.RecentFiles.GetFiles().Count > 0)
            {
                OpenProject(Ares.Settings.FolderFactory.CreateFile(Ares.Settings.Settings.Instance.RecentFiles.GetFiles()[0].FilePath), false);
            }
            bool   foundAddress     = false;
            bool   foundIPv4Address = false;
            String ipv4Address      = String.Empty;
            String ipAddress        = String.Empty;

            foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(String.Empty))
            {
                //if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                //    continue;
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    foundIPv4Address = true;
                    ipv4Address      = address.ToString();
                }
                String s = address.ToString();
                if (s == Settings.Settings.Instance.IPAddress)
                {
                    foundAddress = true;
                    ipAddress    = s;
                }
                else if (!foundAddress)
                {
                    ipAddress = s;                     // take first one
                }
            }
            if (!foundAddress && foundIPv4Address)
            {
                ipAddress = ipv4Address;                 // prefer v4
            }
            if (!String.IsNullOrEmpty(ipAddress))
            {
                Settings.Settings.Instance.IPAddress = ipAddress;
            }
            else
            {
                Toast.MakeText(this, Resource.String.no_ip_address, ToastLength.Long).Show();
                return;
            }
            m_Network = new Networks(this, Settings.Settings.Instance.UseLegacyNetwork, Settings.Settings.Instance.UseWebNetwork);
            m_Network.InitConnectionData();
            m_Network.StartUdpBroadcast();
            m_BroadcastTimer          = new System.Timers.Timer(50);
            m_BroadcastTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_BroadcastTimer_Elapsed);
            m_BroadcastTimer.Enabled  = true;
            m_Network.ListenForClient();
        }
示例#2
0
        private int Initialize(PlayerOptions options)
        {
            m_BasicSettings = new BasicSettings();
            ReadSettings();
            if (options.MessageFilterLevel != -1)
            {
                Settings.Settings.Instance.MessageFilterLevel = options.MessageFilterLevel;
            }
            Messages.Instance.MessageReceived += new MessageReceivedHandler(MessageReceived);
            if (options.UdpPort != -1)
            {
                Settings.Settings.Instance.UdpPort = options.UdpPort;
            }
            if (options.LegacyTcpPort > 0)
            {
                Settings.Settings.Instance.TcpPort          = options.LegacyTcpPort;
                Settings.Settings.Instance.UseLegacyNetwork = true;
            }
            else
            {
                Settings.Settings.Instance.UseLegacyNetwork = (options.LegacyTcpPort != -1);
            }
            if (options.WebTcpPort != -1)
            {
                if (!IsLinux && options.WebTcpPort != Settings.Settings.Instance.WebTcpPort)
                {
                    String args = String.Format("ChangePort {0} {1}", Settings.Settings.Instance.WebTcpPort, options.WebTcpPort);
                    ChangeSecuritySettings(args);
                }
                Settings.Settings.Instance.WebTcpPort    = options.WebTcpPort;
                Settings.Settings.Instance.UseWebNetwork = true;
            }
            else
            {
                Settings.Settings.Instance.UseWebNetwork = false;
            }
            if (options.OutputDevice == 0)
            {
                int outputDevice = Settings.Settings.Instance.OutputDeviceIndex;
                if (outputDevice != -1)
                {
                    try
                    {
                        m_BassInit.SwitchDevice(outputDevice);
                    }
                    catch (Ares.Playing.BassInitException)
                    {
                        Console.WriteLine(StringResources.DeviceInitError);
                    }
                }
            }
            else
            {
                Settings.Settings.Instance.OutputDeviceIndex = options.OutputDevice;
            }
            if (!String.IsNullOrEmpty(options.InitialProject))
            {
                if (options.InitialProject.EndsWith(".apkg", StringComparison.InvariantCultureIgnoreCase))
                {
                    ImportProject(options.InitialProject, false);
                }
                else
                {
                    OpenProject(options.InitialProject, false);
                }
            }
            else if (Ares.Settings.Settings.Instance.RecentFiles.GetFiles().Count > 0)
            {
                OpenProject(Ares.Settings.Settings.Instance.RecentFiles.GetFiles()[0].FilePath, false);
            }
            else
            {
                Console.WriteLine(StringResources.NoOpenedProject);
            }
            bool   foundAddress     = false;
            bool   foundIPv4Address = false;
            String ipv4Address      = String.Empty;
            String ipAddress        = String.Empty;

            foreach (System.Net.IPAddress address in System.Net.Dns.GetHostAddresses(String.Empty))
            {
                //if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                //    continue;
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    foundIPv4Address = true;
                    ipv4Address      = address.ToString();
                }
                String s = address.ToString();
                if (s == Settings.Settings.Instance.IPAddress)
                {
                    foundAddress = true;
                    ipAddress    = s;
                }
                else if (!foundAddress)
                {
                    ipAddress = s; // take first one
                }
            }
            if (!foundAddress && foundIPv4Address)
            {
                ipAddress = ipv4Address; // prefer v4
            }
            if (!String.IsNullOrEmpty(ipAddress))
            {
                Settings.Settings.Instance.IPAddress = ipAddress;
            }
            else
            {
                Console.WriteLine(StringResources.NoIpAddress);
                return(2);
            }
            m_Network = new Networks(this, Settings.Settings.Instance.UseLegacyNetwork, Settings.Settings.Instance.UseWebNetwork);
            m_Network.InitConnectionData();
            m_Network.StartUdpBroadcast();
            m_BroadcastTimer          = new System.Timers.Timer(50);
            m_BroadcastTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_BroadcastTimer_Elapsed);
            m_BroadcastTimer.Enabled  = true;
            m_Network.ListenForClient();
            return(0);
        }