public int Run(PlayerOptions options) { SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); int res = Initialize(options); if (res != 0) { return(res); } if (!options.NonInteractive) { Console.WriteLine(StringResources.PressKeyToExit); Console.ReadKey(); } else { m_IsDaemon = options.Daemon; m_NonInteractiveWaitEvent = new System.Threading.AutoResetEvent(false); bool shutdown = false; while (!shutdown) { m_NonInteractiveWaitEvent.WaitOne(200); lock (m_LockObject) { shutdown = m_Shutdown; } } } Shutdown(); return(0); }
static int Main(string[] args) { System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); ServiceStack.Licensing.RegisterLicense(@"1001-e1JlZjoxMDAxLE5hbWU6VGVzdCBCdXNpbmVzcyxUeXBlOkJ1c2luZXNzLEhhc2g6UHVNTVRPclhvT2ZIbjQ5MG5LZE1mUTd5RUMzQnBucTFEbTE3TDczVEF4QUNMT1FhNXJMOWkzVjFGL2ZkVTE3Q2pDNENqTkQyUktRWmhvUVBhYTBiekJGUUZ3ZE5aZHFDYm9hL3lydGlwUHI5K1JsaTBYbzNsUC85cjVJNHE5QVhldDN6QkE4aTlvdldrdTgyTk1relY2eis2dFFqTThYN2lmc0JveHgycFdjPSxFeHBpcnk6MjAxMy0wMS0wMX0="); if (Environment.GetCommandLineArgs().Length > 1) { string arg = Environment.GetCommandLineArgs()[1]; string paramName = "Language="; if (arg.StartsWith(paramName)) { arg = arg.Substring(paramName.Length); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(arg); } } Console.WriteLine(String.Format(StringResources.AresPlayer, (new System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().FullName)).Version.ToString())); Console.WriteLine(); int res = 0; try { PlayerOptions options = new PlayerOptions(); if (options.Parse(args)) { int outputDevice = options.OutputDevice == 0 ? -1 : options.OutputDevice; using (Ares.Playing.BassInit bassInit = new Ares.Playing.BassInit(outputDevice, s => Console.WriteLine(s))) { { Player player = new Player(bassInit); res = player.Run(options); } } } else { res = 2; } } catch (Ares.Playing.BassInitException ex) { Console.WriteLine(ex.Message); res = 1; } return(res); }
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); }