public AdvancedSettings() { InitializeComponent(); actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSound); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } actionFolderPath.KeyDown += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); }; actionFolderPath.KeyUp += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); }; actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; mainPanel.Click += delegate { mainPanel.Focus(); }; actionFolderPath.GotFocus += delegate { if (!hasUnfocused) { mainPanel.Focus(); hasUnfocused = true; } }; //Fixes it being auto-foxused }
private bool Check() { if (EmptyCheck()) { DirectoryInfo di = new DirectoryInfo(MainProgram.CheckPath(true)); int numFiles = 0; try { foreach (string file in Directory.GetFiles(MainProgram.CheckPath(true), "*." + Properties.Settings.Default.ActionFileExtension)) { //if (cleanedFiles.Contains(file)) continue; bool hidden = (File.GetAttributes(file) & FileAttributes.Hidden) == FileAttributes.Hidden; if (!hidden) { File.SetAttributes(file, FileAttributes.Hidden); } string tmpFolder = Path.Combine(Path.GetTempPath(), "AssistantComputerControl"); if (!Directory.Exists(tmpFolder)) { Directory.CreateDirectory(tmpFolder); } //string newFilename = Path.Combine(Path.GetDirectoryName(file), "action_" + DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + "_" + Guid.NewGuid() + "." + Properties.Settings.Default.ActionFileExtension); //string newFilename = Path.Combine(tmpFolder, "action_" + DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + "_" + Guid.NewGuid() + "." + Properties.Settings.Default.ActionFileExtension); //string newFilename = Path.Combine(Path.Combine(MainProgram.CheckPath(true), "used_actions"), "action_" + DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() + "_" + Guid.NewGuid() + "." + Properties.Settings.Default.ActionFileExtension); //File.Move(file, newFilename); //File.Delete(newFilename); File.Delete(file); //cleanedFiles.Add(newFilename); numFiles++; } } catch (Exception e) { MainProgram.DoDebug("[CLEANUP] Failed to rename a file in action folder; " + e.Message + ". Successfully renamed and hid " + numFiles.ToString() + " files"); return(false); } if (numFiles > 0) { Thread.Sleep(1000); } return(true); /*if (!EmptyCheck()) { * MainProgram.DoDebug("[CLEANUP] All action folder files successfully renamed and hid (" + numFiles.ToString() + " files)"); * return true; * } else { * MainProgram.DoDebug("[CLEANUP] Folder wasn't cleared"); * }*/ } else { MainProgram.DoDebug("[CLEANUP] Check done - action folder is empty"); } return(false); }
public AdvancedSettings() { InitializeComponent(); actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSoundNoHandle); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } void FreakingStopDingSoundNoHandle(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; e.Handled = true; MainProgram.SetCheckFolder(actionFolderPath.Text); } } //actionFolderPath.KeyDown += delegate { pathChanged(); }; //actionFolderPath.KeyUp += delegate { pathChanged(); }; /*void pathChanged() { * MainProgram.SetCheckFolder(actionFolderPath.Text); * actionFolderPath.Text = MainProgram.CheckPath(); * }*/ actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; mainPanel.Click += delegate { mainPanel.Focus(); }; actionFolderPath.GotFocus += delegate { if (!hasUnfocused) { mainPanel.Focus(); hasUnfocused = true; } }; //Fixes it being auto-foxused Text = Translator.__("window_name", "advanced_settings"); foreach (Control x in this.Controls) { Translator.TranslateWinForms("advanced_settings", x.Controls); } }
private void pickFolderBtn_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog() { InitialDirectory = MainProgram.CheckPath(), IsFolderPicker = true }; if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { actionFolderPath.Text = dialog.FileName; } }
private bool AllHiddenCheck() { int count = 0; foreach (string file in Directory.GetFiles(MainProgram.CheckPath(), "*." + Properties.Settings.Default.ActionFileExtension)) { bool hidden = (File.GetAttributes(file) & FileAttributes.Hidden) == FileAttributes.Hidden; if (!hidden || file.Contains("computerAction")) { count++; } } return(count == 0); }
public void AllDone(string chosenService) { MainProgram.DoDebug("'AllDone' pressed"); if (CheckSetPath(chosenService)) { theTabControl.SelectTab(3); MainProgram.SetRegKey("ActionFolder", MainProgram.CheckPath()); } else { theWebBrowser.Document.InvokeScript("DoneError"); } }
public TestActionWindow() { InitializeComponent(); MaximizeBox = false; sWebBrowser = webBrowser; string listeningInText = "\n\nListening in: " + MainProgram.CheckPath() + "\nfor \"." + Properties.Settings.Default.ActionFileExtension + "\" extensions"; actionTesterLabel.Text += listeningInText; //webBrowser.Url = new Uri(String.Format("file:///{0}/test.html", MainProgram.currentLocation)); sWebBrowser.Url = new Uri("http://acc.albe.pw/success_error_listen.html"); sWebBrowser.DocumentCompleted += delegate { browserLoaded = true; webBrowser.Document.InvokeScript("showLoader"); }; VisibleChanged += VisibilityChanged; }
private int AllHiddenCheck() { int count = 0; foreach (string file in Directory.GetFiles(MainProgram.CheckPath(true), "*." + Properties.Settings.Default.ActionFileExtension)) { if (File.Exists(file)) { try { //Shouldn't think it'd be needed, but it is bool hidden = (File.GetAttributes(file) & FileAttributes.Hidden) == FileAttributes.Hidden; if (!hidden || file.Contains("computerAction")) { //MainProgram.DoDebug("[CLEANUP] Found file; " + file); count++; } } catch { //Probably failed to get attribute } } } return(count); }
static public void FileFound(object source, FileSystemEventArgs e) { string file = e.FullPath; string originalFileName = file; if (!File.Exists(file) || inProgressFileNames.Contains(e.FullPath) || file.Contains("in_progress")) { return; } inProgressFileNames.Add(originalFileName); MainProgram.DoDebug("\n[ -- DOING ACTION(S) -- ]"); MainProgram.DoDebug(file); MainProgram.DoDebug("File exists, checking the content..."); while (FileInUse(file)) { ; } string newFileName = Path.Combine(MainProgram.CheckPath(), "in_progress_" + Guid.NewGuid().ToString("n").Substring(0, 8) + "." + Properties.Settings.Default.ActionFileExtension); try { File.Move(file, newFileName); inProgressFileNames.Add(newFileName); } catch { //File in use inProgressFileNames.Remove(file); inProgressFileNames.Remove(originalFileName); MainProgram.DoDebug("Can't move file - used by another process"); return; } file = newFileName; while (File.Exists(originalFileName) && !File.Exists(newFileName)) { ; } if (new FileInfo(file).Length != 0) { MainProgram.DoDebug("Action set. File is not empty..."); //string line = Regex.Replace(File.ReadAllText(file), @"\t|\n|\r", ""); string fullContent = Regex.Replace(File.ReadAllText(file), @"\t|\r", ""); MainProgram.DoDebug("Read complete, content: " + fullContent); using (StringReader reader = new StringReader(fullContent)) { string theLine = string.Empty; do { theLine = reader.ReadLine(); if (theLine != null) { MainProgram.DoDebug("\n[EXECUTING ACTION]"); CheckAction(theLine); } } while (theLine != null); } } else { MainProgram.DoDebug("File is empty"); MainProgram.errorMessage = "No action set (file is empty)"; } MainProgram.ClearFile(file); while (File.Exists(file)) { ; } inProgressFileNames.Remove(file); inProgressFileNames.Remove(originalFileName); MainProgram.DoDebug("[ -- DONE -- ]"); if (MainProgram.errorMessage.Length != 0 && !MainProgram.debug) { MessageBox.Show(MainProgram.errorMessage, "Error | " + MainProgram.messageBoxTitle); MainProgram.errorMessage = ""; } }
public TestActionWindow() { InitializeComponent(); MaximizeBox = false; sWebBrowser = webBrowser; //TODO: Make it local //webBrowser.Url = new Uri(String.Format("file:///{0}/test.html", MainProgram.currentLocation)); sWebBrowser.Url = new Uri("https://assistantcomputercontrol.com/success_error_listen.html"); sWebBrowser.DocumentCompleted += delegate { browserLoaded = true; webBrowser.Document.InvokeScript("showLoader"); }; VisibleChanged += VisibilityChanged; FormClosed += delegate { MainProgram.testingAction = false; }; Text = Translator.__("window_name", "test_action_window"); string listeningInText = Translator.__("description", "test_action_window") + "\n\n" + Translator.__("listening_in", "test_action_window") + "\n" + MainProgram.CheckPath() + "\n" + Translator.__("listening_for", "test_action_window") + " \"." + Properties.Settings.Default.ActionFileExtension + "\""; actionTesterLabel.Text = listeningInText; }
private bool EmptyCheck() { return(Directory.GetFiles(MainProgram.CheckPath(true)).Length > 0); }
public GettingStarted(int startTab = 0) { InitializeComponent(); Thread.CurrentThread.Priority = ThreadPriority.Highest; FormClosed += delegate { if (MainProgram.aboutVersionAwaiting) { Properties.Settings.Default.LastKnownVersion = MainProgram.softwareVersion; new NewVersion().Show(); Properties.Settings.Default.Save(); } }; tabControl.Appearance = TabAppearance.FlatButtons; tabControl.ItemSize = new Size(0, 1); tabControl.SizeMode = TabSizeMode.Fixed; tabControl.BackColor = Color.Transparent; tabControl.SelectTab(startTab); tabControl.Selected += delegate { if (tabControl.SelectedIndex == 1) { //Clicked on recommended setup guide (HTML), can show "move on" popover now theWebBrowser.Document.InvokeScript("showHelpPopover"); } else if (tabControl.SelectedIndex == 2) { expert.Focus(); } }; //Auto-select "recommended" panel RecommendedClicked(null, null); finalOptionButton.FlatStyle = FlatStyle.Flat; finalOptionButton.FlatAppearance.BorderSize = 0; setupSelect.MouseHover += delegate { if (selectedPanel != recommendedPanel) { recommendedPanel.borderColor = Pens.Black; recommendedPanel.Refresh(); } if (selectedPanel != expertPanel) { expertPanel.borderColor = Pens.Black; expertPanel.Refresh(); } }; //Recommended panel recommendedPanel.MouseHover += RecommendedHovered; recommendedPanel.Click += RecommendedClicked; recommendedLabel.MouseHover += RecommendedHovered; recommendedLabel.Click += RecommendedClicked; recommendedLabel2.MouseHover += RecommendedHovered; recommendedLabel2.Click += RecommendedClicked; recommendedLabel3.MouseHover += RecommendedHovered; recommendedLabel3.Click += RecommendedClicked; recommendedImage.MouseHover += RecommendedHovered; recommendedImage.Click += RecommendedClicked; //Expert panel expertPanel.MouseHover += ExpertHovered; expertPanel.Click += ExpertClicked; expertLabel1.MouseHover += ExpertHovered; expertLabel1.Click += ExpertClicked; expertLabel2.MouseHover += ExpertHovered; expertLabel2.Click += ExpertClicked; expertLabel2.MouseHover += ExpertHovered; expertLabel2.Click += ExpertClicked; expertLabel3.MouseHover += ExpertHovered; expertLabel3.Click += delegate { Process.Start("https://acc.readme.io/v1.0/docs/application-advanced-settings-expert-setup"); }; tooltip.SetToolTip(expertLabel3, "This will open a link in your default browser"); expertLabel4.MouseHover += ExpertHovered; expertLabel4.Click += ExpertClicked; expertImage.MouseHover += ExpertHovered; expertImage.Click += ExpertClicked; //Further expert settings actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSound); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; actionFolderPath.KeyDown += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFolderPath.KeyUp += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; expert.Click += delegate { expert.Focus(); }; customSetupInfo.Click += delegate { expert.Focus(); }; expertDoneButton.FlatStyle = FlatStyle.Flat; expertDoneButton.FlatAppearance.BorderSize = 0; closeWindowButton.FlatStyle = FlatStyle.Flat; closeWindowButton.FlatAppearance.BorderSize = 0; analyticsMoveOn.FlatStyle = FlatStyle.Flat; analyticsMoveOn.FlatAppearance.BorderSize = 0; //Browser theWebBrowser = GuideWebBrowser; theWebBrowser.DocumentCompleted += BrowserDocumentCompleted; theWebBrowser.Navigating += BrowserNavigating; theWebBrowser.NewWindow += NewBrowserWindow; VisibleChanged += delegate { MainProgram.testingAction = Visible; MainProgram.gettingStarted = Visible ? this : null; }; FormClosed += delegate { MainProgram.testingAction = false; MainProgram.gettingStarted = null; }; }
public GettingStarted(int startTab = 0) { //Start function thisForm = this; InitializeComponent(); Thread.CurrentThread.Priority = ThreadPriority.Highest; theTabControl = tabControl; FormClosed += delegate { if (MainProgram.aboutVersionAwaiting) { Properties.Settings.Default.LastKnownVersion = MainProgram.softwareVersion; new NewVersion().Show(); Properties.Settings.Default.Save(); } }; tabControl.Appearance = TabAppearance.FlatButtons; tabControl.ItemSize = new Size(0, 1); tabControl.SizeMode = TabSizeMode.Fixed; tabControl.BackColor = Color.White; tabControl.SelectTab(startTab); tabControl.Selected += delegate { if (tabControl.SelectedIndex == 1) { //Clicked on recommended setup guide (HTML), can show "move on" popover now //theWebBrowser.Document.InvokeScript("showHelpPopover"); // Why would I do this...? } else if (tabControl.SelectedIndex == 2) { expert.Focus(); } }; backToSetupGuide.Visible = false; theInstance = this; //Set GettingStarted web-browser things (unless user has IE >9) //Check for IE version using JS, as the C# way requires admin rights, which we don't want to ask for just because of this... string fileName = Path.Combine(MainProgram.currentLocation, "WebFiles/IECheck.html"); /* Internet Explorer test */ if (File.Exists(fileName)) { string fileLoc = "file:///" + fileName; Uri theUri = new Uri(fileLoc); ieWebBrowser.Url = theUri; } else { ieWebBrowser.Visible = false; } ieWebBrowser.ObjectForScripting = new WebBrowserHandler(); theWebBrowser = ieWebBrowser; //theWebBrowser.DocumentCompleted += BrowserDocumentCompleted; theWebBrowser.Navigating += BrowserNavigating; theWebBrowser.NewWindow += NewBrowserWindow; /* Getting Started */ fileName = Path.Combine(MainProgram.currentLocation, "WebFiles/GettingStarted.html"); if (File.Exists(fileName)) { string fileLoc = "file:///" + fileName; Uri theUri = new Uri(fileLoc); GettingStartedWebBrowser.Url = theUri; } else { GettingStartedWebBrowser.Visible = false; } GettingStartedWebBrowser.ObjectForScripting = new WebBrowserHandler(); theWebBrowser = GettingStartedWebBrowser; theDoneActionViewBrowser = doneActionViewBrowser; theDoneActionViewBrowser.DocumentCompleted += DoneActionGridLoadCompleted; theDoneActionViewBrowser.Navigating += BrowserNavigating; theDoneActionViewBrowser.NewWindow += NewBrowserWindow; theWebBrowser.DocumentCompleted += BrowserDocumentCompleted; theWebBrowser.Navigating += BrowserNavigating; theWebBrowser.NewWindow += NewBrowserWindow; //Further expert settings actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSound); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; actionFolderPath.KeyDown += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFolderPath.KeyUp += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; expert.Click += delegate { expert.Focus(); }; customSetupInfo.Click += delegate { expert.Focus(); }; expertDoneButton.FlatStyle = FlatStyle.Flat; expertDoneButton.FlatAppearance.BorderSize = 0; VisibleChanged += delegate { MainProgram.testingAction = Visible; MainProgram.gettingStarted = Visible ? this : null; isConfiguringActions = Visible; }; FormClosed += delegate { //Is needed isConfiguringActions = false; MainProgram.testingAction = false; MainProgram.gettingStarted = null; }; this.HandleCreated += delegate { Invoke(new Action(() => { FlashWindow.Flash(this); if (Application.OpenForms[this.Name] != null) { Application.OpenForms[this.Name].Activate(); Application.OpenForms[this.Name].Focus(); } })); }; //"Expert setup" translations customSetupTitle.Text = Translator.__("title", "expert_setup"); customSetupInfo.Text = Translator.__("description", "expert_setup"); actionFolderPathLabel.Text = Translator.__("action_folder_path", "expert_setup"); actionFileExtensionLabel.Text = Translator.__("action_file_extension", "expert_setup"); disclaimerLabel.Text = Translator.__("disclaimer", "expert_setup"); backToSetupGuide.Text = Translator.__("back_to_setup", "expert_setup"); expertDoneButton.Text = Translator.__("done_button", "expert_setup"); } // End main function
public static void TaskSchedulerSetup() { //Create "Task Scheduler" service; cleanup ACC on startup, log on, workstation unlock try { using (TaskService ts = new TaskService()) { var ps1File = Path.Combine(MainProgram.currentLocation, "ExtraCleanupper.ps1"); TaskDefinition td = ts.NewTask(); td.Principal.LogonType = TaskLogonType.S4U; td.RegistrationInfo.Author = "Albert MN. | AssistantComputerControl"; td.RegistrationInfo.Description = "AssistantComputerControl cleanup - clears the action folder to prevent the same action being executed twice"; td.Triggers.Add(new BootTrigger()); td.Triggers.Add(new LogonTrigger()); td.Triggers.Add(new SessionStateChangeTrigger { StateChange = TaskSessionStateChangeType.SessionUnlock }); td.Actions.Add(new ExecAction("powershell.exe", $"-WindowStyle Hidden -file \"{ps1File}\" \"{Path.Combine(MainProgram.CheckPath(), "*")}\" \"*.{Properties.Settings.Default.ActionFileExtension}\"", null)); // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(@"AssistantComputerControl cleanup", td); // Remove the task we just created //ts.RootFolder.DeleteTask("Test"); } } catch { DoDebug("Failed to create / update Task Scheduler service"); } }
public GettingStarted(int startTab = 0) { InitializeComponent(); Thread.CurrentThread.Priority = ThreadPriority.Highest; theTabControl = tabControl; FormClosed += delegate { if (MainProgram.aboutVersionAwaiting) { Properties.Settings.Default.LastKnownVersion = MainProgram.softwareVersion; new NewVersion().Show(); Properties.Settings.Default.Save(); } }; tabControl.Appearance = TabAppearance.FlatButtons; tabControl.ItemSize = new Size(0, 1); tabControl.SizeMode = TabSizeMode.Fixed; tabControl.BackColor = Color.Transparent; tabControl.SelectTab(startTab); tabControl.Selected += delegate { if (tabControl.SelectedIndex == 1) { //Clicked on recommended setup guide (HTML), can show "move on" popover now //theWebBrowser.Document.InvokeScript("showHelpPopover"); // Why would I do this...? } else if (tabControl.SelectedIndex == 2) { expert.Focus(); } }; //Set GettingStarted web-browser things string fileName = Path.Combine(MainProgram.currentLocation, "WebFiles/GettingStarted.html"); if (File.Exists(fileName)) { string fileLoc = "file:///" + fileName; Uri theUri = new Uri(fileLoc); GettingStartedWebBrowser.Url = theUri; } else { GettingStartedWebBrowser.Visible = false; } GettingStartedWebBrowser.ObjectForScripting = new WebBrowserHandler(); theWebBrowser = GettingStartedWebBrowser; theWebBrowser.DocumentCompleted += BrowserDocumentCompleted; theWebBrowser.Navigating += BrowserNavigating; theWebBrowser.NewWindow += NewBrowserWindow; //Further expert settings actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSound); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; actionFolderPath.KeyDown += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFolderPath.KeyUp += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); actionFolderPath.Text = MainProgram.CheckPath(); }; actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; expert.Click += delegate { expert.Focus(); }; customSetupInfo.Click += delegate { expert.Focus(); }; expertDoneButton.FlatStyle = FlatStyle.Flat; expertDoneButton.FlatAppearance.BorderSize = 0; closeWindowButton.FlatStyle = FlatStyle.Flat; closeWindowButton.FlatAppearance.BorderSize = 0; VisibleChanged += delegate { MainProgram.testingAction = Visible; MainProgram.gettingStarted = Visible ? this : null; }; FormClosed += delegate { MainProgram.testingAction = false; MainProgram.gettingStarted = null; }; this.HandleCreated += delegate { Invoke(new Action(() => { FlashWindow.Flash(this); if (Application.OpenForms[this.Name] != null) { Application.OpenForms[this.Name].Activate(); Application.OpenForms[this.Name].Focus(); } })); }; }
public static void TaskSchedulerSetup() { //Create "Task Scheduler" service; cleanup ACC on startup, log on, workstation unlock var ps1File = Path.Combine(MainProgram.currentLocation, "ExtraCleanupper.ps1"); try { var userId = WindowsIdentity.GetCurrent().Name; using (var ts = new TaskService()) { var td = ts.NewTask(); td.RegistrationInfo.Author = "Albert MN. | AssistantComputerControl"; td.RegistrationInfo.Description = "AssistantComputerControl cleanup - clears the action folder to prevent the same action being executed twice"; td.Actions.Add(new ExecAction("powershell.exe", $"-WindowStyle Hidden -file \"{ps1File}\" \"{Path.Combine(MainProgram.CheckPath(), "*")}\" \"*.{Properties.Settings.Default.ActionFileExtension}\"", null)); td.Triggers.Add(new LogonTrigger { UserId = userId, }); ts.RootFolder.RegisterTaskDefinition(@"AssistantComputerControl cleanup", td); } } catch (Exception e) { DoDebug("Failed to create / update cleanup Task Scheduler service; " + e.Message); Console.WriteLine(e); } }
//Execute mod public static void ExecuteModAction(string name, string parameter = "", string secondaryParameter = "") { MainProgram.DoDebug("\nRunning MOD ACTION!\n"); string modLocation = Path.Combine(MainProgram.actionModsPath, modActions[name]), infoJsonFile = Path.Combine(modLocation, "info.json"); if (File.Exists(infoJsonFile)) { string modFileContent = ReadInfoFile(infoJsonFile); if (modFileContent != null) { try { dynamic jsonTest = JsonConvert.DeserializeObject <dynamic>(modFileContent); if (jsonTest != null) { if (ValidateInfoJson(jsonTest)) { //JSON is valid - get script file string scriptFile = jsonTest["options"]["file_name"], scriptFileLocation = Path.Combine(modLocation, scriptFile); if (File.Exists(scriptFileLocation)) { try { ProcessStartInfo p = new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true }; string theExtension = Path.GetExtension(scriptFile); if (theExtension == ".ps1") { //Is powershell - open it correctly p.FileName = "powershell.exe"; p.Arguments = $"-WindowStyle Hidden -file \"{scriptFileLocation}\" \"{Path.Combine(MainProgram.CheckPath(), "*")}\" \"*.{Properties.Settings.Default.ActionFileExtension}\""; } else if (theExtension == ".py") { //Python - open it correctly MainProgram.DoDebug("Is python!"); string minPythonVersion = (jsonTest["options"]["min_python_version"] != null ? jsonTest["options"]["min_python_version"] : ""), maxPythonVersion = (jsonTest["options"]["max_python_version"] != null ? jsonTest["options"]["max_python_version"] : ""), pythonPath = GetPythonPath(minPythonVersion, maxPythonVersion); if (pythonPath != "") { MainProgram.DoDebug("Python path; " + pythonPath); p.FileName = GetPythonPath(); p.Arguments = scriptFileLocation; } else { //No python version (or one with the min-max requirements) not found. if (minPythonVersion == "" && maxPythonVersion == "") { //Python just not found MessageBox.Show("We could not locate Python on your computer. Please either download Python or specify its path in the ACC settings if it's already installed.", MainProgram.messageBoxTitle); } else { if (minPythonVersion != "" && maxPythonVersion != "") { //Both min & max set MessageBox.Show("We could not locate a version of Python between v" + minPythonVersion + " and v" + maxPythonVersion + ". Please either download a version of Python in between the specified versions, or specify its path in the ACC settings if it's already installed.", MainProgram.messageBoxTitle); } else { if (minPythonVersion != "") { //Min only MessageBox.Show("We could not locate a version of Python greater than v" + minPythonVersion + ". Please either download Python (min version " + minPythonVersion + ") or specify its path in the ACC settings if it's already installed.", MainProgram.messageBoxTitle); } else { //Max only MessageBox.Show("We could not locate a version of Python lower than v" + maxPythonVersion + ". Please either download Python (max version " + maxPythonVersion + ") or specify its path in the ACC settings if it's already installed.", MainProgram.messageBoxTitle); } } } return; } } else { //"Other" filetype. Simply open file. p.FileName = scriptFileLocation; p.Arguments = "how to do dis?"; } Process theP = Process.Start(p); string output = theP.StandardOutput.ReadToEnd(); theP.WaitForExit(); Console.WriteLine(output); } catch (Exception e) { //Process init failed - it shouldn't, but better safe than sorry MainProgram.DoDebug("6"); Console.WriteLine(e); } } else { //Script file doesn't exist MainProgram.DoDebug("5"); } } else { //JSON is not valid; validateErrMsg MainProgram.DoDebug("4"); } } else { //JSON is invalid or failed MainProgram.DoDebug("3"); } } catch (Exception e) { //Failed to parse MainProgram.DoDebug("2"); Console.WriteLine(e.Message); } } else { //Couldn't read file MainProgram.DoDebug("1"); } } else { MainProgram.DoDebug("0; " + modLocation); } MainProgram.DoDebug("\n\n"); }
public GettingStarted() { InitializeComponent(); tabControl.Appearance = TabAppearance.FlatButtons; tabControl.ItemSize = new Size(0, 1); tabControl.SizeMode = TabSizeMode.Fixed; tabControl.BackColor = Color.Transparent; tabControl.Selected += delegate { if (tabControl.SelectedIndex == 1) { //Clicked on recommended setup guide (HTML), can show "move on" popover now theWebBrowser.Document.InvokeScript("showHelpPopover"); } else if (tabControl.SelectedIndex == 2) { expert.Focus(); } }; //Auto-select "recommended" panel RecommendedClicked(null, null); finalOptionButton.FlatStyle = FlatStyle.Flat; finalOptionButton.FlatAppearance.BorderSize = 0; setupSelect.MouseHover += delegate { if (selectedPanel != recommendedPanel) { recommendedPanel.borderColor = Pens.Black; recommendedPanel.Refresh(); } if (selectedPanel != expertPanel) { expertPanel.borderColor = Pens.Black; expertPanel.Refresh(); } }; //Recommended panel recommendedPanel.MouseHover += RecommendedHovered; recommendedPanel.Click += RecommendedClicked; recommendedLabel.MouseHover += RecommendedHovered; recommendedLabel.Click += RecommendedClicked; recommendedLabel2.MouseHover += RecommendedHovered; recommendedLabel2.Click += RecommendedClicked; recommendedLabel3.MouseHover += RecommendedHovered; recommendedLabel3.Click += RecommendedClicked; recommendedImage.MouseHover += RecommendedHovered; recommendedImage.Click += RecommendedClicked; //Expert panel expertPanel.MouseHover += ExpertHovered; expertPanel.Click += ExpertClicked; expertLabel1.MouseHover += ExpertHovered; expertLabel1.Click += ExpertClicked; expertLabel2.MouseHover += ExpertHovered; expertLabel2.Click += ExpertClicked; expertLabel2.MouseHover += ExpertHovered; expertLabel2.Click += ExpertClicked; expertLabel3.MouseHover += ExpertHovered; expertLabel3.Click += delegate { Process.Start("https://github.com/AlbertMN/AssistantComputerControl/wiki/Application-advanced-settings-expert-setup"); }; tooltip.SetToolTip(expertLabel3, "This will open a link in your default browser"); expertLabel4.MouseHover += ExpertHovered; expertLabel4.Click += ExpertClicked; expertImage.MouseHover += ExpertHovered; expertImage.Click += ExpertClicked; //Further expert settings actionFolderPath.KeyDown += new KeyEventHandler(FreakingStopDingSound); actionFileExtension.KeyDown += new KeyEventHandler(FreakingStopDingSound); void FreakingStopDingSound(Object o, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.Handled = true; e.SuppressKeyPress = true; } } actionFolderPath.Text = MainProgram.CheckPath(); actionFileExtension.Text = Properties.Settings.Default.ActionFileExtension; actionFolderPath.KeyDown += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); }; actionFolderPath.KeyUp += delegate { MainProgram.SetCheckFolder(actionFolderPath.Text); }; actionFileExtension.KeyDown += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; actionFileExtension.KeyUp += delegate { MainProgram.SetCheckExtension(actionFileExtension.Text); }; expert.Click += delegate { expert.Focus(); }; customSetupInfo.Click += delegate { expert.Focus(); }; expertDoneButton.FlatStyle = FlatStyle.Flat; expertDoneButton.FlatAppearance.BorderSize = 0; closeWindowButton.FlatStyle = FlatStyle.Flat; closeWindowButton.FlatAppearance.BorderSize = 0; //Browser theWebBrowser = GuideWebBrowser; string tes = "http://acc.albe.pw/recommended_setup.html?" + new Random().Next(10000); Console.WriteLine(tes); //theWebBrowser.Url = new Uri(tes); theWebBrowser.DocumentCompleted += BrowserDocumentCompleted; theWebBrowser.Navigating += BrowserNavigating; theWebBrowser.NewWindow += NewBrowserWindow; VisibleChanged += delegate { MainProgram.testingAction = Visible; MainProgram.gettingStarted = Visible ? this : null; }; FormClosed += delegate { MainProgram.testingAction = false; MainProgram.gettingStarted = null; }; }
//public static List<string> cleanedFiles = new List<string>(); public void Start() { new Thread(() => { Thread.CurrentThread.IsBackground = true; MainProgram.DoDebug("[CLEANUP] Service started"); Thread.Sleep(150); if (isCleaning) { MainProgram.DoDebug("[CLEANUP] Another cleanup service in progress. Waiting..."); while (isCleaning) { Thread.Sleep(200); } MainProgram.DoDebug("[CLEANUP] Other cleanup service done - starting check..."); } isCleaning = true; if (AllHiddenCheck() != 0 && EmptyCheck()) { int tries = 0; while (!Check() && tries <= 10) { tries++; Thread.Sleep(1000); } if (tries >= 10) { MainProgram.DoDebug("[CLEANUP] Timeout. Failed to remove files in action folder."); } else { int filesAmount = AllHiddenCheck(); if (filesAmount != 0) { MainProgram.DoDebug("[CLEANUP] Did not timeout, but action folder is still not empty (" + filesAmount.ToString() + " non-hidden files in folder) - not supposed to happen Emtpy check returns " + (EmptyCheck() ? "true" : "false")); } else { MainProgram.DoDebug("[CLEANUP] Successful"); } } } else { MainProgram.DoDebug("[CLEANUP] Action folder is completely empty"); } /* Launch a follow-up investigation */ new Thread(() => { Thread.CurrentThread.IsBackground = true; void ExtraCleanup() { MainProgram.DoDebug("[CLEANUP] Running extra cleanup (followup)"); try { var ps1File = Path.Combine(MainProgram.currentLocation, "ExtraCleanupper.ps1"); Process p = new Process(); p.StartInfo.FileName = "powershell.exe"; p.StartInfo.Arguments = $"-WindowStyle Hidden -file \"{ps1File}\" \"{Path.Combine(MainProgram.CheckPath(true), "*")}\" \"*.{Properties.Settings.Default.ActionFileExtension}\""; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.Start(); } catch { MainProgram.DoDebug("[CLEANUP] Extra checkup failed"); } } Thread.Sleep(5000); ExtraCleanup(); Thread.Sleep(25000); ExtraCleanup(); }).Start(); isCleaning = false; }).Start(); }
public TestActionWindow() { InitializeComponent(); MaximizeBox = false; sWebBrowser = webBrowser; string fileName = Path.Combine(MainProgram.currentLocation, "WebFiles/ActionTester.html"); if (File.Exists(fileName)) { string fileLoc = "file:///" + fileName; Uri theUri = new Uri(fileLoc); sWebBrowser.Url = theUri; } else { sWebBrowser.Visible = false; } sWebBrowser.DocumentCompleted += delegate { browserLoaded = true; webBrowser.Document.InvokeScript("showLoader"); }; VisibleChanged += VisibilityChanged; FormClosed += delegate { MainProgram.testingAction = false; }; Text = Translator.__("window_name", "test_action_window"); string listeningInText = Translator.__("description", "test_action_window") + "\n\n" + Translator.__("listening_in", "test_action_window") + "\n" + MainProgram.CheckPath() + "\n" + Translator.__("listening_for", "test_action_window") + " \"." + Properties.Settings.Default.ActionFileExtension + "\""; actionTesterLabel.Text = listeningInText; }