Esempio n. 1
0
        public static void UpdateAnalyticsSharing(bool theBool)
        {
            //Purpose of this function is to only define "HasAnalyticsClass" one place
#if (HasAnalyticsClass)
            AnalyticsSettings.UpdateSharing(theBool);
#endif
        }
Esempio n. 2
0
        private void anonymousAnalyticsCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            bool theStatus = anonymousAnalyticsCheckbox.Checked;

            MainProgram.DoDebug("Send annonymous analytics; " + theStatus);

            AnalyticsSettings.UpdateSharing(theStatus);
        }
        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();
            }
        }
Esempio n. 4
0
        public static void AnalyticsAddCount(string actionStr = null, int?actionInt = null, string param = "")
        {
#if (HasAnalyticsClass)
            if (actionStr == null && actionInt != null)
            {
                //By number
                AnalyticsSettings.AddCount((int)actionInt, param);
            }
            else
            {
                //By action name
                AnalyticsSettings.AddCount(actionStr, param);
            }
#endif
        }
Esempio n. 5
0
        private void SetupDone()
        {
            //Start with Windows if user said so
            if (Properties.Settings.Default.StartWithWindows != startWithWindowsCheckbox.Checked)
            {
                Properties.Settings.Default.StartWithWindows = startWithWindowsCheckbox.Checked;
                MainProgram.SetStartup(startWithWindowsCheckbox.Checked);

                Properties.Settings.Default.Save();

                MainProgram.DoDebug("Starting with Windows now");
            }
            Properties.Settings.Default.AnalyticsInformed = true;
            AnalyticsSettings.UpdateSharing(analyticsEnabledBox.Checked);

            MainProgram.DoDebug("Anonymous analyitcs " + (analyticsEnabledBox.Checked ? "IS" : "is NOT") + " enabled");

            MainProgram.DoDebug("Completed setup guide");
            Properties.Settings.Default.HasCompletedTutorial = true;
            Properties.Settings.Default.Save();
        }
        static public void FileFound(object source, FileSystemEventArgs e)
        {
            string file   = e.FullPath
            , action      = null
            , parameter   = null
            , fullContent = null;

            if (!MainProgram.isPerformingAction)
            {
                MainProgram.isPerformingAction = true;
                MainProgram.DoDebug("File exists, checking the content...");

                while (FileInUse(file))
                {
                    ;
                }
                if (!File.Exists(file))
                {
                    MainProgram.isPerformingAction = false;
                    return;
                }
                if (new FileInfo(file).Length != 0)
                {
                    MainProgram.DoDebug("Action set. File is not empty...");
                    action = "empty file";

                    string line = File.ReadAllText(file);
                    MainProgram.DoDebug("Read complete, content: " + line);
                    DateTime lastModified = File.GetLastWriteTime(file);
                    action      = line;
                    fullContent = line;
                    string assistantParam = null;

                    if (lastModified.AddSeconds(Properties.Settings.Default.FileEditedMargin) > DateTime.Now)
                    {
                        //If file has been modified recently - check for action
                        MainProgram.DoDebug("File modified within the last " + Properties.Settings.Default.FileEditedMargin + " seconds...");

                        //Whether it's Google Assistant or Amazon Alexa (included in the default IFTTT applets)
                        if (line.Contains("[") && line.Contains("]"))
                        {
                            action         = line.Split('[')[0];
                            assistantParam = line.Split('[')[1];
                            assistantParam = assistantParam.Split(']')[0];

                            MainProgram.DoDebug("Executed using; " + assistantParam);
                        }

                        if (action.Contains(":"))
                        {
                            //Contains a parameter
                            action    = line.Split(':')[0];
                            parameter = line.Split(':')[1];
                            if (parameter == "")
                            {
                                parameter = null;
                            }
                        }

                        if (MainProgram.testingAction)
                        {
                            MainProgram.DoDebug("Test went through: " + action);
                        }

                        //TO-DO; Optimize action-execution (less code) & make it its own function
                        int?actionNumber = null;
                        switch (action)
                        {
                        case "shutdown":
                            //Shuts down the computer
                            string shutdownParameters = "/s /t 0";
                            if (parameter != null)
                            {
                                if (parameter == "abort")
                                {
                                    shutdownParameters = "abort";
                                }
                                else
                                {
                                    if (parameter.Contains("/t"))
                                    {
                                        shutdownParameters = !parameter.Contains("/s") ? "/s " : "" + parameter;
                                    }
                                    else
                                    {
                                        shutdownParameters = !parameter.Contains("/s") ? "/s " : "" + parameter + " /t 0";
                                    }
                                }
                            }

                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated shutdown";
                            }
                            else
                            {
                                if (shutdownParameters != "abort")
                                {
                                    MainProgram.DoDebug("Shutting down computer...");
                                    successMessage = "Shutting down";
                                    Process.Start("shutdown", shutdownParameters);
                                }
                                else
                                {
                                    MainProgram.DoDebug("Cancelling shutdown...");
                                    Process.Start("shutdown", "/a");
                                    successMessage = "Aborted shutdown";
                                }
                            }
                            break;

                        case "restart":
                            //Restart the computer
                            string restartParameters = "/r /t 0";
                            if (parameter != null)
                            {
                                if (parameter == "abort")
                                {
                                    restartParameters = "abort";
                                }
                                else
                                {
                                    if (parameter.Contains("/t"))
                                    {
                                        restartParameters = !parameter.Contains("/r") ? "/s " : "" + parameter;
                                    }
                                    else
                                    {
                                        restartParameters = !parameter.Contains("/r") ? "/s " : "" + parameter + " /t 0";
                                    }
                                }
                            }
                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated restart";
                            }
                            else
                            {
                                if (restartParameters != "abort")
                                {
                                    MainProgram.DoDebug("Restarting computer...");
                                    successMessage = "Restarting";
                                    Process.Start("shutdown", restartParameters);
                                }
                                else
                                {
                                    MainProgram.DoDebug("Cancelling restart...");
                                    Process.Start("shutdown", "/a");
                                    successMessage = "Aborted restart";
                                }
                            }
                            break;

                        case "sleep":
                            //Puts computer to sleep
                            if (parameter == null)
                            {
                                if (!MainProgram.testingAction)
                                {
                                    MainProgram.DoDebug("Sleeping computer...");
                                    Application.SetSuspendState(PowerState.Suspend, true, true);
                                }
                            }
                            else
                            {
                                bool doForce = true;
                                switch (parameter)
                                {
                                case "true":
                                    doForce = true;
                                    break;

                                case "false":
                                    doForce = false;
                                    break;

                                default:
                                    MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                                    MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                                    break;
                                }
                                if (!MainProgram.testingAction)
                                {
                                    MainProgram.DoDebug("Sleeping computer...");
                                    Application.SetSuspendState(PowerState.Suspend, doForce, true);
                                }
                            }

                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated PC sleep";
                            }
                            else
                            {
                                successMessage = "Put computer to sleep";
                            }
                            break;

                        case "hibernate":
                            //Hibernates computer
                            actionNumber = 12;
                            if (parameter == null)
                            {
                                if (!MainProgram.testingAction)
                                {
                                    MainProgram.DoDebug("Hibernating computer...");
                                    Application.SetSuspendState(PowerState.Hibernate, true, true);
                                }
                            }
                            else
                            {
                                bool doForce = true;
                                switch (parameter)
                                {
                                case "true":
                                    doForce = true;
                                    break;

                                case "false":
                                    doForce = false;
                                    break;

                                default:
                                    MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                                    MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                                    break;
                                }
                                if (!MainProgram.testingAction)
                                {
                                    MainProgram.DoDebug("Hibernating computer...");
                                    Application.SetSuspendState(PowerState.Hibernate, doForce, true);
                                }
                            }

                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated PC hibernate";
                            }
                            else
                            {
                                successMessage = "Put computer in hibernation";
                            }
                            break;

                        case "logout":
                            //Logs out of the current user
                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated logout";
                            }
                            else
                            {
                                MainProgram.DoDebug("Logging out of user...");
                                successMessage = "Logged out of user";
                                ExitWindowsEx(0, 0);
                            }
                            break;

                        case "lock":
                            //Lock computer
                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated PC lock";
                            }
                            else
                            {
                                MainProgram.DoDebug("Locking computer...");
                                LockWorkStation();
                                successMessage = "Locked pc";
                            }
                            break;

                        case "mute":
                            //Mutes windows
                            //Parameter optional (true/false)
                            bool doMute = true;

                            if (parameter == null)
                            {
                                //No parameter - toggle
                                doMute = !AudioManager.GetMasterVolumeMute();
                            }
                            else
                            {
                                //Parameter set;
                                switch (parameter)
                                {
                                case "true":
                                    doMute = true;
                                    break;

                                case "false":
                                    doMute = false;
                                    break;

                                default:
                                    MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                                    MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                                    break;
                                }
                            }

                            if (MainProgram.testingAction)
                            {
                                successMessage = "Simulated PC" + (doMute ? "muted " : "unmute");
                            }
                            else
                            {
                                AudioManager.SetMasterVolumeMute(doMute);
                                successMessage = (doMute ? "Muted " : "Unmuted") + " pc";
                            }
                            break;

                        case "set_volume":
                            //Sets volume to a specific percent
                            //Requires parameter (percent, int)
                            if (requireParameter(parameter))
                            {
                                if (double.TryParse(parameter, out double volumeLevel))
                                {
                                    if (volumeLevel >= 0 && volumeLevel <= 100)
                                    {
                                        if (!MainProgram.testingAction)
                                        {
                                            if (Properties.Settings.Default.UnmuteOnVolumeChange)
                                            {
                                                AudioManager.SetMasterVolumeMute(false);
                                            }
                                            AudioManager.SetMasterVolume((float)volumeLevel);
                                        }
                                        if (AudioManager.GetMasterVolume() != volumeLevel)
                                        {
                                            //Something went wrong... Audio not set to parameter-level
                                            MainProgram.DoDebug("ERROR: Volume was not sat");
                                            MainProgram.errorMessage = "Something went wrong when setting the volume";
                                        }
                                        else
                                        {
                                            if (!MainProgram.testingAction)
                                            {
                                                successMessage = "Set volume to " + volumeLevel + "%";
                                            }
                                            else
                                            {
                                                successMessage = "Simulated setting system volume to " + volumeLevel + "%";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MainProgram.DoDebug("ERROR: Parameter is an invalid number, range; 0-100 (" + volumeLevel + ")");
                                        MainProgram.errorMessage = "Can't set volume to " + volumeLevel + "%, has to be a number from 0-100";
                                    }
                                }
                                else
                                {
                                    MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") not convertable to double");
                                    MainProgram.errorMessage = "Not a valid parameter (has to be a number)";
                                }
                            }
                            break;

                        case "music":
                            if (requireParameter(parameter))
                            {
                                switch (parameter)
                                {
                                case "previous":
                                    actionNumber = 8;

                                    if (MainProgram.testingAction)
                                    {
                                        successMessage = "MUSIC: Simulated skipping song";
                                    }
                                    else
                                    {
                                        keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                                        successMessage = "MUSIC: Skipped song";
                                    }
                                    break;

                                /*case "previousx2": //WIP
                                 *  keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                                 *  keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                                 *  success_message = "MUSIC: Skipped song (x2)";
                                 *  break;*/
                                case "next":
                                    actionNumber = 10;

                                    if (MainProgram.testingAction)
                                    {
                                        successMessage = "MUSIC: Simulated going to next song";
                                    }
                                    else
                                    {
                                        keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                                        successMessage = "MUSIC: Next song";
                                    }
                                    break;

                                case "play_pause":
                                    actionNumber = 9;

                                    if (MainProgram.testingAction)
                                    {
                                        successMessage = "MUSIC: Simulated play/pause";
                                    }
                                    else
                                    {
                                        keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_EXTENTEDKEY, 0);
                                        successMessage = "MUSIC: Played/Paused";
                                    }
                                    break;

                                default:
                                    MainProgram.DoDebug("ERROR: Unknown parameter");
                                    MainProgram.errorMessage = "Unknown parameter \"" + parameter + "\"";
                                    break;
                                }
                            }
                            break;

                        case "open":
                            if (requireParameter(parameter))
                            {
                                string fileLocation = (!parameter.Contains(@":\")) ? Path.Combine(MainProgram.shortcutLocation, parameter) : parameter;
                                if (File.Exists(fileLocation))
                                {
                                    if (!MainProgram.testingAction)
                                    {
                                        Process.Start(fileLocation);
                                        successMessage = "OPEN: opened file; " + fileLocation;
                                    }
                                    else
                                    {
                                        successMessage = "OPEN: simulated opening file; " + fileLocation;
                                    }
                                }
                                else
                                {
                                    MainProgram.DoDebug("ERROR: file doesn't exist (" + fileLocation + ")");
                                    MainProgram.errorMessage = "File doesn't exist (" + fileLocation + ")";
                                }
                            }
                            break;

                        case "die":
                            //Exit ACC
                            if (!MainProgram.testingAction)
                            {
                                successMessage = "Shutting down ACC";
                                Application.Exit();
                            }
                            else
                            {
                                successMessage = "Simulated shutting down ACC";
                            }
                            break;

                        default:
                            //Unknown action
                            MainProgram.DoDebug("ERROR: Unknown action");
                            MainProgram.errorMessage = "Unknown action \"" + action + "\"";
                            break;
                        }
                        if (successMessage != "")
                        {
                            if (actionNumber != null)
                            {
                                //Has specified number
                                AnalyticsSettings.AddCount((int)actionNumber, assistantParam);
                            }
                            else
                            {
                                //YOLO
                                AnalyticsSettings.AddCount(action, assistantParam);
                            }

                            MainProgram.DoDebug("\nSUCCESS: " + successMessage + "\n");
                        }
                    }
                    else
                    {
                        MainProgram.DoDebug("No action set within the last " + Properties.Settings.Default.FileEditedMargin + " seconds. File last edited; " + lastModified + ". PC time; " + DateTime.Now);
                        MainProgram.errorMessage = "No action set within the last " + Properties.Settings.Default.FileEditedMargin + " seconds. File last edited; " + lastModified + ". PC time; " + DateTime.Now;
                    }
                }
                else
                {
                    MainProgram.DoDebug("File is empty");
                    MainProgram.errorMessage = "No action set (file is empty)";
                }

                MainProgram.ClearFile(file);
                if (MainProgram.errorMessage.Length != 0 && !MainProgram.debug)
                {
                    MessageBox.Show(MainProgram.errorMessage, "Error | " + MainProgram.messageBoxTitle);
                    MainProgram.errorMessage = "";
                }
                MainProgram.isPerformingAction = false;
            }
            else
            {
                MainProgram.DoDebug("Already performing an action");
                MainProgram.errorMessage = "Already performing an action";
            }

            if (MainProgram.testingAction)
            {
                MainProgram.testActionWindow.ActionExecuted(successMessage, MainProgram.errorMessage, action, parameter, fullContent);
            }
            successMessage = "";
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            hasAnalyticsClass = Type.GetType("AssistantComputerControl.AnalyticsSettings") != null;

            string sentryToken = "super_secret";

            if (hasAnalyticsClass)
            {
#if (HasAnalyticsClass)
                sentryToken = AnalyticsSettings.sentryToken;
#endif
            }

            if (sentryToken != "super_secret")
            {
                //Tracking issues with Sentry.IO - not forked from GitHub (official version)
                bool sentryOK = false;
                try {
                    if (Properties.Settings.Default.UID != "")
                    {
                        SentrySdk.ConfigureScope(scope => {
                            scope.User = new Sentry.Protocol.User {
                                Id = Properties.Settings.Default.UID
                            };
                        });
                    }

                    using (SentrySdk.Init(sentryToken)) {
                        sentryOK = true;
                    }
                } catch {
                    //Sentry failed. Error sentry's side or invalid key - don't let this stop the app from running
                    DoDebug("Sentry initiation failed");
                    ActualMain();
                }

                if (sentryOK)
                {
                    using (SentrySdk.Init(sentryToken)) {
                        DoDebug("Sentry initiated");
                        ActualMain();
                    }
                }
            }
            else
            {
                //Code is (most likely) forked - skip issue tracking
                ActualMain();
            }

            void ActualMain()
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                SetupDataFolder();
                if (File.Exists(logFilePath))
                {
                    try {
                        File.WriteAllText(logFilePath, string.Empty);
                    } catch {
                        // Don't let this being DENIED crash the software
                    }
                }
                else
                {
                    CreateLogFile();
                }

                //Check if software already runs, if so kill this instance
                var otherACCs = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(currentLocationFull));

                if (otherACCs.Length > 1)
                {
                    //Try kill the _other_ process instead
                    foreach (Process p in otherACCs)
                    {
                        if (p.Id != Process.GetCurrentProcess().Id)
                        {
                            try {
                                p.Kill();
                                DoDebug("Other ACC instance was running. Killed it.");
                            } catch {
                                DoDebug("Could not kill other process of ACC; access denied");
                            }
                        }
                    }
                }

                Application.EnableVisualStyles();

                DoDebug("[ACC begun (v" + softwareVersion + ")]");
#if (HasAnalyticsClass)
                AnalyticsSettings.SetupAnalytics();
#endif

                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");
                    }
                }

                //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
                    try {
                        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!");
                        }
                    } catch {
                        DoDebug("Could not create or write to example 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");

                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);

                if (gettingStarted is null && !Properties.Settings.Default.AnalyticsInformed)
                {
                    //"Getting started" not shown but user hasn't been told about analytics gathering yet
                    ShowGettingStarted(3);
                }

                //If newly updated
                if (Properties.Settings.Default.LastKnownVersion != softwareVersion)
                {
                    //Up(or down)-grade, display version notes
                    if (gettingStarted != null)
                    {
                        DoDebug("'AboutVersion' window awaits, as 'Getting Started' is showing");
                        aboutVersionAwaiting = true;
                    }
                    else
                    {
                        Properties.Settings.Default.LastKnownVersion = softwareVersion;
                        new NewVersion().Show();
                        Properties.Settings.Default.Save();
                    }
                }

                SystemEvents.SessionSwitch += new SessionSwitchEventHandler(SystemEvents_SessionSwitch); //On wake up from sleep
                Application.Run();
            }
        }
Esempio n. 8
0
        private static void ExecuteAction(string action, string line, string parameter, string assistantParam)
        {
            int?actionNumber = null;

            switch (action)
            {
            case "shutdown":
                //Shuts down the computer
                string shutdownParameters = "/s /t 0";
                if (parameter != null)
                {
                    if (parameter == "abort")
                    {
                        shutdownParameters = "abort";
                    }
                    else
                    {
                        if (parameter.Contains("/t"))
                        {
                            shutdownParameters = !parameter.Contains("/s") ? "/s " : "" + parameter;
                        }
                        else
                        {
                            shutdownParameters = !parameter.Contains("/s") ? "/s " : "" + parameter + " /t 0";
                        }
                    }
                }

                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated shutdown";
                }
                else
                {
                    if (shutdownParameters != "abort")
                    {
                        MainProgram.DoDebug("Shutting down computer...");
                        successMessage = "Shutting down";
                        Process.Start("shutdown", shutdownParameters);
                    }
                    else
                    {
                        MainProgram.DoDebug("Cancelling shutdown...");
                        Process.Start("shutdown", "/a");
                        successMessage = "Aborted shutdown";
                    }
                }
                break;

            case "restart":
                //Restart the computer
                string restartParameters = "/r /t 0";
                if (parameter != null)
                {
                    if (parameter == "abort")
                    {
                        restartParameters = "abort";
                    }
                    else
                    {
                        if (parameter.Contains("/t"))
                        {
                            restartParameters = !parameter.Contains("/r") ? "/s " : "" + parameter;
                        }
                        else
                        {
                            restartParameters = !parameter.Contains("/r") ? "/s " : "" + parameter + " /t 0";
                        }
                    }
                }
                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated restart";
                }
                else
                {
                    if (restartParameters != "abort")
                    {
                        MainProgram.DoDebug("Restarting computer...");
                        successMessage = "Restarting";
                        Process.Start("shutdown", restartParameters);
                    }
                    else
                    {
                        MainProgram.DoDebug("Cancelling restart...");
                        Process.Start("shutdown", "/a");
                        successMessage = "Aborted restart";
                    }
                }
                break;

            case "sleep":
                //Puts computer to sleep
                if (parameter == null)
                {
                    if (!MainProgram.testingAction)
                    {
                        MainProgram.DoDebug("Sleeping computer...");
                        Application.SetSuspendState(PowerState.Suspend, true, true);
                    }
                }
                else
                {
                    bool doForce = true;
                    switch (parameter)
                    {
                    case "true":
                        doForce = true;
                        break;

                    case "false":
                        doForce = false;
                        break;

                    default:
                        MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                        MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                        break;
                    }
                    if (!MainProgram.testingAction)
                    {
                        MainProgram.DoDebug("Sleeping computer...");
                        Application.SetSuspendState(PowerState.Suspend, doForce, true);
                    }
                }

                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated PC sleep";
                }
                else
                {
                    successMessage = "Put computer to sleep";
                }
                break;

            case "hibernate":
                //Hibernates computer
                actionNumber = 12;
                if (parameter == null)
                {
                    if (!MainProgram.testingAction)
                    {
                        MainProgram.DoDebug("Hibernating computer...");
                        Application.SetSuspendState(PowerState.Hibernate, true, true);
                    }
                }
                else
                {
                    bool doForce = true;
                    switch (parameter)
                    {
                    case "true":
                        doForce = true;
                        break;

                    case "false":
                        doForce = false;
                        break;

                    default:
                        MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                        MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                        break;
                    }
                    if (!MainProgram.testingAction)
                    {
                        MainProgram.DoDebug("Hibernating computer...");
                        Application.SetSuspendState(PowerState.Hibernate, doForce, true);
                    }
                }

                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated PC hibernate";
                }
                else
                {
                    successMessage = "Put computer in hibernation";
                }
                break;

            case "logout":
                //Logs out of the current user
                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated logout";
                }
                else
                {
                    MainProgram.DoDebug("Logging out of user...");
                    successMessage = "Logged out of user";
                    ExitWindowsEx(0, 0);
                }
                break;

            case "lock":
                //Lock computer
                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated PC lock";
                }
                else
                {
                    MainProgram.DoDebug("Locking computer...");
                    LockWorkStation();
                    successMessage = "Locked pc";
                }
                break;

            case "mute":
                //Mutes windows
                //Parameter optional (true/false)
                bool doMute = true;

                if (parameter == null)
                {
                    //No parameter - toggle
                    doMute = !AudioManager.GetMasterVolumeMute();
                }
                else
                {
                    //Parameter set;
                    switch (parameter)
                    {
                    case "true":
                        doMute = true;
                        break;

                    case "false":
                        doMute = false;
                        break;

                    default:
                        MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") is invalid for \"" + action + "\". Accepted parameters: \"true\" and \"false\"");
                        MainProgram.errorMessage = "Parameter \"" + parameter + "\" is invalid for the \"" + action + "\" action. Accepted parameters: \"true\" and \"false\")";
                        break;
                    }
                }

                if (MainProgram.testingAction)
                {
                    successMessage = "Simulated PC" + (doMute ? "muted " : "unmute");
                }
                else
                {
                    AudioManager.SetMasterVolumeMute(doMute);
                    successMessage = (doMute ? "Muted " : "Unmuted") + " pc";
                }
                break;

            case "set_volume":
                //Sets volume to a specific percent
                //Requires parameter (percent, int)
                if (RequireParameter(parameter))
                {
                    if (double.TryParse(parameter, out double volumeLevel))
                    {
                        if (volumeLevel >= 0 && volumeLevel <= 100)
                        {
                            if (!MainProgram.testingAction)
                            {
                                if (Properties.Settings.Default.UnmuteOnVolumeChange)
                                {
                                    AudioManager.SetMasterVolumeMute(false);
                                }
                                AudioManager.SetMasterVolume((float)volumeLevel);
                            }
                            if (!MainProgram.testingAction)
                            {
                                if ((int)AudioManager.GetMasterVolume() != (int)volumeLevel)
                                {
                                    //Something went wrong... Audio not set to parameter-level
                                    MainProgram.DoDebug("ERROR: Volume was not set properly. Master volume is " + AudioManager.GetMasterVolume() + ", not " + volumeLevel);
                                    MainProgram.errorMessage = "Something went wrong when setting the volume";
                                }
                                else
                                {
                                    successMessage = "Set volume to " + volumeLevel + "%";
                                }
                            }
                            else
                            {
                                successMessage = "Simulated setting system volume to " + volumeLevel + "%";
                            }
                        }
                        else
                        {
                            MainProgram.DoDebug("ERROR: Parameter is an invalid number, range; 0-100 (" + volumeLevel + ")");
                            MainProgram.errorMessage = "Can't set volume to " + volumeLevel + "%, has to be a number from 0-100";
                        }
                    }
                    else
                    {
                        MainProgram.DoDebug("ERROR: Parameter (" + parameter + ") not convertable to double");
                        MainProgram.errorMessage = "Not a valid parameter (has to be a number)";
                    }
                }
                break;

            case "music":
                if (RequireParameter(parameter))
                {
                    switch (parameter)
                    {
                    case "previous":
                        actionNumber = 8;

                        if (MainProgram.testingAction)
                        {
                            successMessage = "MUSIC: Simulated going to previous track";
                        }
                        else
                        {
                            keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                            successMessage = "MUSIC: Skipped song";
                        }
                        break;

                    case "previousx2":
                        actionNumber = 8;
                        if (MainProgram.testingAction)
                        {
                            successMessage = "MUSIC: Simulated double-previous track";
                        }
                        else
                        {
                            keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                            Thread.Sleep(100);
                            keybd_event(VK_MEDIA_PREV_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                            successMessage = "MUSIC: Skipped song (x2)";
                        }
                        break;

                    case "next":
                        actionNumber = 10;

                        if (MainProgram.testingAction)
                        {
                            successMessage = "MUSIC: Simulated going to next song";
                        }
                        else
                        {
                            keybd_event(VK_MEDIA_NEXT_TRACK, 0, KEYEVENTF_EXTENTEDKEY, 0);
                            successMessage = "MUSIC: Next song";
                        }
                        break;

                    case "play_pause":
                        actionNumber = 9;

                        if (MainProgram.testingAction)
                        {
                            successMessage = "MUSIC: Simulated play/pause";
                        }
                        else
                        {
                            keybd_event(VK_MEDIA_PLAY_PAUSE, 0, KEYEVENTF_EXTENTEDKEY, 0);
                            successMessage = "MUSIC: Played/Paused";
                        }
                        break;

                    default:
                        MainProgram.DoDebug("ERROR: Unknown parameter");
                        MainProgram.errorMessage = "Unknown parameter \"" + parameter + "\"";
                        break;
                    }
                }
                break;

            case "open":
                if (RequireParameter(parameter))
                {
                    string fileLocation = (!parameter.Contains(@":\")) ? Path.Combine(MainProgram.shortcutLocation, parameter) : parameter;

                    if (File.Exists(fileLocation) || Directory.Exists(fileLocation) || Uri.IsWellFormedUriString(fileLocation, UriKind.Absolute))
                    {
                        if (!MainProgram.testingAction)
                        {
                            Process.Start(fileLocation);
                            successMessage = "OPEN: opened file/url; " + fileLocation;
                        }
                        else
                        {
                            successMessage = "OPEN: simulated opening file; " + fileLocation;
                        }
                    }
                    else
                    {
                        MainProgram.DoDebug("ERROR: file or directory doesn't exist (" + fileLocation + ")");
                        MainProgram.errorMessage = "File or directory doesn't exist (" + fileLocation + ")";
                    }
                }
                break;

            case "open_all":
                if (RequireParameter(parameter))
                {
                    string fileLocation = (!parameter.Contains(@":\")) ? Path.Combine(MainProgram.shortcutLocation, parameter) : parameter;

                    if (Directory.Exists(fileLocation) || Uri.IsWellFormedUriString(fileLocation, UriKind.Absolute))
                    {
                        DirectoryInfo d = new DirectoryInfo(fileLocation);
                        int           x = 0;
                        foreach (var dirFile in d.GetFiles())
                        {
                            if (!MainProgram.testingAction)
                            {
                                Process.Start(dirFile.FullName);
                            }
                            x++;
                        }

                        if (!MainProgram.testingAction)
                        {
                            successMessage = "OPEN: opened " + x + " files in; " + fileLocation;
                        }
                        else
                        {
                            successMessage = "OPEN: simulated opening " + x + " files in; " + fileLocation;
                        }
                    }
                    else
                    {
                        MainProgram.DoDebug("ERROR: directory doesn't exist (" + fileLocation + ")");
                        MainProgram.errorMessage = "Directory doesn't exist (" + fileLocation + ")";
                    }
                }
                break;

            case "die":
                //Exit ACC
                if (!MainProgram.testingAction)
                {
                    successMessage = "Shutting down ACC";
                    Application.Exit();
                }
                else
                {
                    successMessage = "Simulated shutting down ACC";
                }
                break;

            case "monitors_off":
                if (!MainProgram.testingAction)
                {
                    Form f = new Form();
                    SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)2);
                    f.Close();
                    successMessage = "Turned monitors off";
                }
                else
                {
                    successMessage = "Simulated turning monitors off";
                }
                break;

            /*case "keypress":
             *  if (RequireParameter(parameter)) {
             *      if (parameter.Length > 1) {
             *          if (!MainProgram.testingAction) {
             *              successMessage = "Pressed \"" + parameter + "\"";
             *              PressKey((char)parameter[0]);
             *          } else {
             *              successMessage = "Simulated press of \"" + parameter + "\"";
             *          }
             *      } else {
             *          MainProgram.DoDebug("ERROR: Parameter can only be one character long");
             *          MainProgram.errorMessage = "(Keypress) Parameter can only be one character long";
             *      }
             *  }
             *  break;*/
            case "write_out":
                if (RequireParameter(parameter))
                {
                    int    i             = 0;
                    string writtenString = "";
                    foreach (char c in parameter)
                    {
                        char toWrite = (i == 0 && Properties.Settings.Default.WriteOutUCFirst ? Char.ToUpper(c) : c);
                        if (!MainProgram.testingAction)
                        {
                            PressKey(toWrite);
                        }
                        writtenString += toWrite;

                        if (i > line.Length && Properties.Settings.Default.WriteOutDotLast)
                        {
                            if (!MainProgram.testingAction)
                            {
                                PressKey('.');
                            }
                            writtenString += ".";
                        }
                        i++;
                    }
                    if (!MainProgram.testingAction)
                    {
                        successMessage = "Wrote \"" + writtenString + "\"";
                    }
                    else
                    {
                        successMessage = "Simulated writing \"" + writtenString + "\"";
                    }
                }
                break;

            /*case "key_shortcut": //TODO - version 1.3(?)
             *  //Currently just keeps holding CTRL down, f*****g everything up
             *  //Do "testing" check
             *  if (RequireParameter(parameter)) {
             *      parameter = parameter.Replace("ctrl", "%");
             *
             *      /*foreach (char c in parameter) {
             *          if (c == '%') {
             *              keybd_event(VK_RCONTROL, 0, KEYEVENTF_EXTENTEDKEY, 0);
             *              keybd_event(VK_RCONTROL, 0, KEYEVENTF_KEYUP, 0);
             *          } else {
             *              PressKey(c);
             *          }
             *      }*/
            /*}
             * PressKeys();
             * break;*/
            case "create_file":
                if (RequireParameter(parameter))
                {
                    string fileLocation = parameter;
                    if (!File.Exists(fileLocation))
                    {
                        string parentPath = Path.GetDirectoryName(fileLocation);
                        if (Directory.Exists(parentPath))
                        {
                            bool succeeded = true;
                            try {
                                string toDelete;
                                //Is file
                                if (MainProgram.testingAction)
                                {
                                    //Create a test-file and delete it to test if has permission
                                    toDelete = Path.Combine(parentPath, "acc_testfile.txt");
                                    var myFile = File.Create(toDelete);
                                    myFile.Close();
                                    while (!File.Exists(toDelete))
                                    {
                                        ;
                                    }
                                    while (!FileInUse(toDelete))
                                    {
                                        ;
                                    }
                                    File.Delete(toDelete);
                                }
                                else
                                {
                                    //Actually create file
                                    var myFile = File.Create(fileLocation);
                                    myFile.Close();
                                }
                            } catch (Exception exc) {
                                succeeded = false;
                                MainProgram.DoDebug(exc.Message);
                                MainProgram.errorMessage = "Couldn't create file - folder might be locked. Try running ACC as administrator.";
                            }

                            if (succeeded)
                            {
                                if (!MainProgram.testingAction)
                                {
                                    successMessage = "Created file at " + fileLocation;
                                }
                                else
                                {
                                    successMessage = "Simulated creating file at " + fileLocation;
                                }
                            }
                        }
                        else
                        {
                            MainProgram.errorMessage = "File parent folder doesn't exist (" + parentPath + ")";
                            MainProgram.DoDebug("File parent folder doesn't exist (" + parentPath + ")");
                        }
                    }
                    else
                    {
                        MainProgram.errorMessage = "File already exists";
                        MainProgram.DoDebug("File already exists");
                    }
                }
                break;

            case "delete_file":
                if (RequireParameter(parameter))
                {
                    string fileLocation = parameter;
                    if (File.Exists(fileLocation) || Directory.Exists(fileLocation))
                    {
                        FileAttributes attr      = File.GetAttributes(fileLocation);
                        bool           succeeded = true;
                        MainProgram.DoDebug("Deleting file/folder at " + fileLocation);

                        try {
                            string toDelete;
                            if (attr.HasFlag(FileAttributes.Directory))
                            {
                                //Is folder
                                MainProgram.DoDebug("Deleting folder...");
                                DirectoryInfo d        = new DirectoryInfo(fileLocation);
                                bool          doDelete = true;
                                if (d.GetFiles().Length > Properties.Settings.Default.MaxDeleteFiles && Properties.Settings.Default.WarnWhenDeletingManyFiles)
                                {
                                    //Has more than x files - do warning
                                    DialogResult dialogResult = MessageBox.Show("You're about to delete more than 10 files at " + fileLocation + " - are you sure you wish to proceed?",
                                                                                "Are you sure?", MessageBoxButtons.YesNo);
                                    if (dialogResult == DialogResult.Yes)
                                    {
                                    }
                                    else if (dialogResult == DialogResult.No)
                                    {
                                        doDelete = false;
                                    }
                                }

                                if (doDelete)
                                {
                                    if (MainProgram.testingAction)
                                    {
                                        //Make test-folder and delete it to test if has permission
                                        toDelete = Path.Combine(Directory.GetParent(fileLocation).FullName, "acc_testfolder");
                                        Directory.CreateDirectory(toDelete);
                                        Directory.Delete(toDelete);
                                    }
                                    else
                                    {
                                        //Actually delete folder
                                        Directory.Delete(fileLocation);
                                        MainProgram.DoDebug("Deleted directory at " + fileLocation);
                                    }
                                }
                                else
                                {
                                    MainProgram.errorMessage = "";
                                }
                            }
                            else
                            {
                                //Is file
                                if (MainProgram.testingAction)
                                {
                                    //Make test-file and delete it to test if has permission
                                    MainProgram.DoDebug("(Fake) Deleting file...");

                                    toDelete = Path.Combine(fileLocation, "acc_testfile.txt");
                                    File.Create(toDelete);
                                    File.Delete(toDelete);
                                }
                                else
                                {
                                    //Actually delete file
                                    MainProgram.DoDebug("Deleting file...");
                                    File.Delete(fileLocation);
                                }
                            }
                        } catch (Exception exc) {
                            succeeded = false;
                            MainProgram.DoDebug(exc.Message);
                            MainProgram.errorMessage = "Couldn't access file/folder - file might be in use or locked. Try running ACC as administrator.";
                        }

                        if (succeeded)
                        {
                            if (!MainProgram.testingAction)
                            {
                                successMessage = "Deleted file/folder at " + fileLocation;
                            }
                            else
                            {
                                successMessage = "Simulated deleting file/folder at " + fileLocation;
                            }
                        }
                    }
                    else
                    {
                        MainProgram.errorMessage = "File or folder doesn't exist";
                        MainProgram.DoDebug("File or folder doesn't exist");
                    }
                }
                break;

            case "append_text":
                if (RequireParameter(parameter))
                {
                    string fileLocation = GetSecondaryParam(parameter)[0]
                    , toAppend          = GetSecondaryParam(parameter).Length > 1 ? GetSecondaryParam(parameter)[1] : null;

                    MainProgram.DoDebug("Appending \"" + toAppend + "\" to " + fileLocation);

                    if (fileLocation != null && toAppend != null)
                    {
                        if (toAppend != "")
                        {
                            if (File.Exists(fileLocation))
                            {
                                string parentPath = Path.GetDirectoryName(fileLocation);
                                bool   succeeded  = true;
                                try {
                                    //Is file
                                    if (MainProgram.testingAction)
                                    {
                                        //Write empty string to file to test permission
                                        using (StreamWriter w = File.AppendText(fileLocation)) {
                                            w.Write(String.Empty);
                                        }
                                    }
                                    else
                                    {
                                        //Actually write to file
                                        using (StreamWriter w = File.AppendText(fileLocation)) {
                                            //string[] lines = toAppend.Split(new string[] { "\n" }, StringSplitOptions.None);
                                            string[] lines = toAppend.Split(new string[] { "\\n" }, StringSplitOptions.None);
                                            MainProgram.DoDebug(lines.Length.ToString());
                                            int i = 0;
                                            foreach (string appendChild in lines)
                                            {
                                                if (i == 0)
                                                {
                                                    w.Write(appendChild);
                                                }
                                                else
                                                {
                                                    w.WriteLine(String.Empty);
                                                    w.Write(appendChild);
                                                }

                                                i++;
                                            }
                                        }
                                    }
                                } catch (Exception exc) {
                                    succeeded = false;
                                    MainProgram.DoDebug(exc.Message);
                                    MainProgram.errorMessage = "Couldn't create file - folder might be locked. Try running ACC as administrator.";
                                }

                                if (succeeded)
                                {
                                    if (!MainProgram.testingAction)
                                    {
                                        successMessage = "Appended \"" + toAppend + "\" to file at " + fileLocation;
                                    }
                                    else
                                    {
                                        successMessage = "Simulated appending \"" + toAppend + "\" to file at " + fileLocation;
                                    }
                                }
                            }
                            else
                            {
                                MainProgram.errorMessage = "File doesn't exists";
                                MainProgram.DoDebug("File doesn't exists");
                            }
                        }
                        else
                        {
                            MainProgram.errorMessage = "Can't append nothing";
                            MainProgram.DoDebug("Can't append nothing");
                        }
                    }
                    else
                    {
                        MainProgram.errorMessage = "Parameter doesn't contain a string to append";
                        MainProgram.DoDebug("Parameter doesn't contain a string to append");
                    }
                }
                break;

            case "message_box":
                if (RequireParameter(parameter))
                {
                    string theMessage = GetSecondaryParam(parameter)[0]
                    , theTitle        = (GetSecondaryParam(parameter).Length > 1 ? GetSecondaryParam(parameter)[1] : null);

                    if (MainProgram.testingAction)
                    {
                        successMessage = "Simulated making a message box with the content \"" + theMessage + "\" and " + (theTitle == null ? "no title" : "title \"" + theTitle + "\"");
                    }
                    else
                    {
                        new Thread(() => {
                            Thread.CurrentThread.Priority = ThreadPriority.Highest;
                            MessageBox.Show(theMessage, theTitle ?? "ACC Generated Message Box");
                        }).Start();
                    }
                }
                break;

            default:
                //Unknown action
                MainProgram.DoDebug("ERROR: Unknown action \"" + action + "\"");
                MainProgram.errorMessage = "Unknown action \"" + action + "\"";
                break;
            }
            if (successMessage != "")
            {
                if (actionNumber != null)
                {
                    //Has specified number
                    AnalyticsSettings.AddCount((int)actionNumber, assistantParam);
                }
                else
                {
                    //YOLO
                    AnalyticsSettings.AddCount(action, assistantParam);
                }

                MainProgram.DoDebug("\nSUCCESS: " + successMessage + "\n");
            }

            if (MainProgram.testingAction)
            {
                MainProgram.testActionWindow.ActionExecuted(successMessage, MainProgram.errorMessage, action, parameter, line);
            }
            successMessage = "";
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            //Check if software already runs, if so kill this instance
            if (Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1)
            {
                DoDebug("ACC is already running, killing this proccess");
                MessageBox.Show("ACC is already running.", "Already running | " + messageBoxTitle + "");
                Process.GetCurrentProcess().Kill();
            }
            SetupDataFolder();
            if (File.Exists(logFilePath))
            {
                File.WriteAllText(logFilePath, string.Empty);
            }

            DoDebug("[ACC begun (v" + softwareVersion + ")]");
            AnalyticsSettings.SetupArray();

            if (Properties.Settings.Default.CheckForUpdates)
            {
                if (HasInternet())
                {
                    new ACC_Updater().Check();
                }
                else
                {
                    DoDebug("Couldn't check for new update as PC does not have access to the internet");
                }
            }
            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);

                //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
            foreach (string file in Directory.GetFiles(CheckPath(), "*." + Properties.Settings.Default.ActionFileExtension))
            {
                ClearFile(file);
            }

            //WATCHER
            FileSystemWatcher 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);
            //END WATCHER

            DoDebug("\n[" + messageBoxTitle + "] Initiated. \nListening in: \"" + CheckPath() + "\" for \"." + Properties.Settings.Default.ActionFileExtension + "\" extensions");

            Application.EnableVisualStyles();
            sysIcon.TrayIcon.Icon = Properties.Resources.ACC_icon;

            //REMOVE THIS
            //ShowGettingStarted();

            //Create "first time" reg-key
            //ShowGettingStarted();

            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();
        }
Esempio n. 10
0
 private void analyticsEnabledBox_CheckedChanged(object sender, EventArgs e)
 {
     Properties.Settings.Default.AnalyticsInformed = true;
     Properties.Settings.Default.Save();
     AnalyticsSettings.UpdateSharing(analyticsEnabledBox.Checked);
 }