static void Main(string[] args) { /* if (System.DateTime.Compare(DateTime.Now, new DateTime(MuteFm.Constants.ExpireYear, MuteFm.Constants.ExpireMonth, MuteFm.Constants.ExpireDay, 23, 59, 59, DateTimeKind.Utc)) > 0) { MessageBox.Show("This version of mute.fm is beta software and has expired. Thanks for demoing! Get a new version at http://www.mute.fm/"); return; }*/ MuteFm.SmartVolManagerPackage.SoundEventLogger.LogMsg(Constants.ProgramName + " loaded!"); if (System.Environment.CommandLine.ToUpper().Contains("FIRSTTIME")) FirstTime = true; if (System.Environment.CommandLine.ToUpper().Contains("SERVICE")) IsService = true; if ((args.Length > 0) && (args[0].ToUpper().Contains("INTERNALBUILDMODE"))) InternalBuildMode = true; // Initialize Awesomium (the browser control) /* if (Awesomium.Core.WebCore.IsChildProcess) { Awesomium.Core.WebCore.ChildProcessMain(); return; }*/ #if !NOAWE Awesomium.Core.WebConfig config = new Awesomium.Core.WebConfig(); // config.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36"; //TODO-AWE config.EnableDatabases = true; //TODO-AWE config.SaveCacheAndCookies = true; //config.LogLevel = Awesomium.Core.LogLevel.Verbose; #if !DEBUG config.LogLevel = Awesomium.Core.LogLevel.None; #else config.LogLevel = Awesomium.Core.LogLevel.Normal; #endif if (!InternalBuildMode) { string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); config.ChildProcessPath = path +"/mute_fm_web"; //TODO-AWE config.ChildProcessPath = Awesomium.Core.WebConfig.CHILD_PROCESS_SELF; } Awesomium.Core.WebCore.Initialize(config); #endif // get application GUID as defined in AssemblyInfo.cs string appGuid = ((GuidAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString(); // unique id for global mutex - Global prefix means it is global to the machine string mutexId = string.Format("Global\\{{{0}}}", appGuid); using (var mutex = new Mutex(false, mutexId)) { // note: some of this is Windows-only // edited by Jeremy Wiebe to add example of setting up security for multi-user usage // edited by 'Marc' to work also on localized systems (don't use just "Everyone") var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); var securitySettings = new MutexSecurity(); securitySettings.AddAccessRule(allowEveryoneRule); mutex.SetAccessControl(securitySettings); //edited by acidzombie24 var hasHandle = false; try { try { // note, you may want to time out here instead of waiting forever //edited by acidzombie24 //mutex.WaitOne(Timeout.Infinite, false); hasHandle = mutex.WaitOne(500, false); // was 5000 here // We just show a UI here if (hasHandle == false) { //MessageBox. Show(Constants.ProgramName + " is already running. You can access it via the system tray."); MuteFm.UiPackage.PlayerForm playerForm = new UiPackage.PlayerForm(); playerForm.Show(); playerForm.Init(true); Application.Run(playerForm); Environment.Exit(0); //MessageBox. Show(Constants.ProgramName + " is already running. You can access it via the system tray or the " + Constants.ProgramName + " Google Chrome extension."); //Environment.Exit(1); //throw new TimeoutException("Timeout waiting for exclusive access"); } } catch (AbandonedMutexException) { // Log the fact the mutex was abandoned in another process, it will still get aquired hasHandle = true; } // Perform your work here. Init(args); } finally { //edit by acidzombie24, added if statemnet if (hasHandle) mutex.ReleaseMutex(); } //SmartVolManagerPackage.SoundServer.RestoreVolumes(); Environment.Exit(0); } }
static void Main(string[] args) { /* * if (System.DateTime.Compare(DateTime.Now, new DateTime(MuteFm.Constants.ExpireYear, MuteFm.Constants.ExpireMonth, MuteFm.Constants.ExpireDay, 23, 59, 59, DateTimeKind.Utc)) > 0) * { * MessageBox.Show("This version of mute.fm is beta software and has expired. Thanks for demoing! Get a new version at http://www.mutefm.com/"); * return; * }*/ MuteFm.SmartVolManagerPackage.SoundEventLogger.LogMsg(Constants.ProgramName + " loaded!"); if (System.Environment.CommandLine.ToUpper().Contains("FIRSTTIME")) { FirstTime = true; } if (System.Environment.CommandLine.ToUpper().Contains("SERVICE")) { IsService = true; } if ((args.Length > 0) && (args[0].ToUpper().Contains("INTERNALBUILDMODE"))) { InternalBuildMode = true; } // Initialize Awesomium (the browser control) /* if (Awesomium.Core.WebCore.IsChildProcess) * { * Awesomium.Core.WebCore.ChildProcessMain(); * return; * }*/ #if !NOAWE Awesomium.Core.WebConfig config = new Awesomium.Core.WebConfig(); // config.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36"; //TODO-AWE config.EnableDatabases = true; //TODO-AWE config.SaveCacheAndCookies = true; //config.LogLevel = Awesomium.Core.LogLevel.Verbose; #if !DEBUG config.LogLevel = Awesomium.Core.LogLevel.None; #else config.LogLevel = Awesomium.Core.LogLevel.Normal; #endif if (!InternalBuildMode) { string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); config.ChildProcessPath = path + "/mute_fm_web"; //TODO-AWE config.ChildProcessPath = Awesomium.Core.WebConfig.CHILD_PROCESS_SELF; } Awesomium.Core.WebCore.Initialize(config); #endif // get application GUID as defined in AssemblyInfo.cs string appGuid = ((GuidAttribute)System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString(); // unique id for global mutex - Global prefix means it is global to the machine string mutexId = string.Format("Global\\{{{0}}}", appGuid); using (var mutex = new Mutex(false, mutexId)) { // note: some of this is Windows-only // edited by Jeremy Wiebe to add example of setting up security for multi-user usage // edited by 'Marc' to work also on localized systems (don't use just "Everyone") var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow); var securitySettings = new MutexSecurity(); securitySettings.AddAccessRule(allowEveryoneRule); mutex.SetAccessControl(securitySettings); //edited by acidzombie24 var hasHandle = false; try { try { // note, you may want to time out here instead of waiting forever //edited by acidzombie24 //mutex.WaitOne(Timeout.Infinite, false); hasHandle = mutex.WaitOne(500, false); // was 5000 here // We just show a UI here if (hasHandle == false) { //MessageBox. Show(Constants.ProgramName + " is already running. You can access it via the system tray."); MuteFm.UiPackage.PlayerForm playerForm = new UiPackage.PlayerForm(); playerForm.Show(); playerForm.Init(true); Application.Run(playerForm); Environment.Exit(0); //MessageBox. Show(Constants.ProgramName + " is already running. You can access it via the system tray or the " + Constants.ProgramName + " Google Chrome extension."); //Environment.Exit(1); //throw new TimeoutException("Timeout waiting for exclusive access"); } } catch (AbandonedMutexException) { // Log the fact the mutex was abandoned in another process, it will still get aquired hasHandle = true; } // Perform your work here. Init(args); } finally { //edit by acidzombie24, added if statemnet if (hasHandle) { mutex.ReleaseMutex(); } } //SmartVolManagerPackage.SoundServer.RestoreVolumes(); Environment.Exit(0); } }
private static void mPlayer_FormClosed(object sender, FormClosedEventArgs e) { mPlayerForm = null; // UiPackage.UiCommands.UpdatePlayerVisibleState(false); }
// Must be run within UI thread public static void InitUI(bool firstTime) { #if !NOAWE WebBgMusicForm = new MuteFm.UiPackage.WebBgMusicForm(); WebBgMusicForm.FormClosing += new FormClosingEventHandler(WebBgMusicForm_FormClosing); WebBgMusicForm.Resize += new EventHandler(WebBgMusicForm_Resize); //WebBgMusicForm.Show(); #endif _notificationType = new NotificationType("MUTEFM_NOTIFICATION", "mute.fm notification"); _growl = new GrowlConnector(); _growl.NotificationCallback += new GrowlConnector.CallbackEventHandler(growl_notification_callback); _growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; // set to ease debugging // OLDNOTIFY TopForm.Instance.Show(); //UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started (expires " + Constants.GetExpirationDateString() + ")", false); UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started", false); if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.Hotkeys == null) { MuteFmConfigUtil.LoadDefaultHotkeys(SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS == 0) { SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS = MuteFmConfig.SoundPollIntervalDefault; } RegisterHotkeys(); UiPackage.UiCommands.UpdateUiForState(MuteFm.SmartVolManagerPackage.BgMusicManager.GetValidOperation(), false, false, true); mPlayerForm = new PlayerForm(); mPlayerForm.FormClosed += new FormClosedEventHandler(mPlayer_FormClosed); mPlayerForm.Init(false); // MuteApp.UiPackage.UiCommands.ShowPlayer(); if (firstTime) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoFirstTimeWork); firstTimeWorker.RunWorkerAsync(); #if !NOAWE UiPackage.UiCommands.ShowGettingStartedWizard(); #endif mPlayerForm.ToggleTopmost(true); } else { if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.PlayMusicOnStartup) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { SoundPlayerInfo playerInfo = (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic()); System.Threading.Thread.Sleep(2000); OnOperation(Operation.Play, playerInfo.AutoPlaysOnStartup, false); if (playerInfo.AutoPlaysOnStartup == false) { System.ComponentModel.BackgroundWorker firstTimeWorker2 = new BackgroundWorker(); firstTimeWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { //System.Threading.Thread.Sleep(5000); //todo OnOperation(Operation.Play); }); firstTimeWorker2.RunWorkerAsync(); } System.Threading.Thread.Sleep(1000); OnOperation(Operation.Minimize); }); firstTimeWorker.RunWorkerAsync(); } } System.Windows.Forms.Application.Run(MuteFm.UiPackage.WinSoundServerSysTray.Instance); }
// Must be run within UI thread public static void InitUI(bool firstTime) { #if !NOAWE WebBgMusicForm = new MuteFm.UiPackage.WebBgMusicForm(); WebBgMusicForm.FormClosing += new FormClosingEventHandler(WebBgMusicForm_FormClosing); WebBgMusicForm.Resize += new EventHandler(WebBgMusicForm_Resize); //WebBgMusicForm.Show(); #endif _notificationType = new NotificationType("MUTEFM_NOTIFICATION", "mute.fm notification"); _growl = new GrowlConnector(); _growl.NotificationCallback += new GrowlConnector.CallbackEventHandler(growl_notification_callback); _growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; // set to ease debugging // OLDNOTIFY TopForm.Instance.Show(); //UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started (expires " + Constants.GetExpirationDateString() + ")", false); UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started", false); if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.Hotkeys == null) MuteFmConfigUtil.LoadDefaultHotkeys(SmartVolManagerPackage.BgMusicManager.MuteFmConfig); if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS == 0) SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS = MuteFmConfig.SoundPollIntervalDefault; RegisterHotkeys(); UiPackage.UiCommands.UpdateUiForState(MuteFm.SmartVolManagerPackage.BgMusicManager.GetValidOperation(), false, false, true); mPlayerForm = new PlayerForm(); mPlayerForm.FormClosed += new FormClosedEventHandler(mPlayer_FormClosed); mPlayerForm.Init(false); // MuteApp.UiPackage.UiCommands.ShowPlayer(); if (firstTime) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoFirstTimeWork); firstTimeWorker.RunWorkerAsync(); #if !NOAWE UiPackage.UiCommands.ShowGettingStartedWizard(); #endif mPlayerForm.ToggleTopmost(true); } else { if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.PlayMusicOnStartup) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { SoundPlayerInfo playerInfo = (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic()); System.Threading.Thread.Sleep(2000); OnOperation(Operation.Play, playerInfo.AutoPlaysOnStartup, false); if (playerInfo.AutoPlaysOnStartup == false) { System.ComponentModel.BackgroundWorker firstTimeWorker2 = new BackgroundWorker(); firstTimeWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { //System.Threading.Thread.Sleep(5000); //todo OnOperation(Operation.Play); }); firstTimeWorker2.RunWorkerAsync(); } System.Threading.Thread.Sleep(1000); OnOperation(Operation.Minimize); }); firstTimeWorker.RunWorkerAsync(); } } System.Windows.Forms.Application.Run(MuteFm.UiPackage.WinSoundServerSysTray.Instance); }