private void anonymousAnalyticsCheckbox_CheckedChanged(object sender, EventArgs e) { bool theStatus = anonymousAnalyticsCheckbox.Checked; MainProgram.DoDebug("Send annonymous analytics; " + theStatus); Properties.Settings.Default.SendAnonymousAnalytics = theStatus; Properties.Settings.Default.Save(); if (theStatus) { AnalyticsSettings.SetupAnalyticsAsync(); } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); SetupDataFolder(); if (File.Exists(logFilePath)) { File.WriteAllText(logFilePath, string.Empty); } else { CreateLogFile(); } //Check if software already runs, if so kill this instance var otherACCs = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(currentLocationFull)); if (otherACCs.Length > 1) { //DoDebug("ACC is already running, killing this proccess"); //MessageBox.Show("ACC is already running.", "Already running | " + messageBoxTitle + ""); //Process.GetCurrentProcess().Kill(); Process.GetCurrentProcess(); //Try kill the _other_ process instead foreach (Process p in otherACCs) { if (p.Id != Process.GetCurrentProcess().Id) { p.Kill(); DoDebug("Other ACC instance was running. Killed it."); } } } DoDebug("[ACC begun (v" + softwareVersion + ")]"); AnalyticsSettings.SetupAnalyticsAsync(); if (Properties.Settings.Default.CheckForUpdates) { if (HasInternet()) { new Thread(() => { new ACC_Updater().Check(); }).Start(); } else { DoDebug("Couldn't check for new update as PC does not have access to the internet"); } } //"updated.txt" not created. Use registry instead (for 1.1.0) /*if (File.Exists(Path.Combine(dataFolderLocation, "updated.txt"))) { * File.Delete(Path.Combine(dataFolderLocation, "updated.txt")); * new AboutVersion().Show(); * }*/ //On console close: hide NotifyIcon Application.ApplicationExit += new EventHandler(OnApplicationExit); handler = new ConsoleEventDelegate(ConsoleEventCallback); SetConsoleCtrlHandler(handler, true); //Check if software starts with Windows if (!Properties.Settings.Default.StartWithWindows) { sysIcon.AddOpenOnStartupMenu(); } //Create shortcut folder if doesn't exist if (!Directory.Exists(shortcutLocation)) { Directory.CreateDirectory(shortcutLocation); } if (!File.Exists(Path.Combine(shortcutLocation, @"example.txt"))) { //Create example-file using (StreamWriter sw = File.CreateText(Path.Combine(shortcutLocation, @"example.txt"))) { sw.WriteLine("This is an example file."); sw.WriteLine("If you haven't already, make your assistant open this file!"); } } //Delete all old action files if (Directory.Exists(CheckPath())) { foreach (string file in Directory.GetFiles(CheckPath(), "*." + Properties.Settings.Default.ActionFileExtension)) { ClearFile(file); } } //SetupListener(); watcher = new FileSystemWatcher() { Path = CheckPath(), NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName, Filter = "*." + Properties.Settings.Default.ActionFileExtension, EnableRaisingEvents = true }; watcher.Changed += new FileSystemEventHandler(ActionChecker.FileFound); watcher.Created += new FileSystemEventHandler(ActionChecker.FileFound); DoDebug("\n[" + messageBoxTitle + "] Initiated. \nListening in: \"" + CheckPath() + "\" for \"." + Properties.Settings.Default.ActionFileExtension + "\" extensions"); Application.EnableVisualStyles(); sysIcon.TrayIcon.Icon = Properties.Resources.ACC_icon; RegistryKey key = Registry.CurrentUser.OpenSubKey("Software", true); if (Registry.GetValue(key.Name + "\\AssistantComputerControl", "FirstTime", null) == null) { key.CreateSubKey("AssistantComputerControl"); key = key.OpenSubKey("AssistantComputerControl", true); key.SetValue("FirstTime", false); Properties.Settings.Default.HasCompletedTutorial = true; Properties.Settings.Default.Save(); ShowGettingStarted(); DoDebug("Starting setup guide"); } else { if (!Properties.Settings.Default.HasCompletedTutorial) { ShowGettingStarted(); DoDebug("Didn't finish setup guide last time, opening again"); } } SetRegKey("ActionFolder", CheckPath()); SetRegKey("ActionExtension", Properties.Settings.Default.ActionFileExtension); Application.Run(); }