/// <summary> /// Search for a new CMP build /// </summary> /// <param name="manual">Whether this was triggered manually</param> void searchForCmpBuild(bool manual = false) { try { string buildsPath = @"\\USRAL1WVFIL01\Shares\USRAL01\Departments\Dept\Engineering\MeterTools\Mtdata\A4\All\Development"; string lastBuild = SysSettings.getSetting(SysSettings.lastCmpBuildName, ""); foreach (string folder in Directory.EnumerateDirectories(buildsPath)) { try { string buildName = Path.GetFileName(folder); // Execute if a new build is found Action buildFound = delegate { Toast.show(string.Format("New CMP Build {0}", buildName), backgroundColor: Color.Green, click: delegate { Process.Start(folder); }, timeout: Time.seconds(10)); SysSettings.setSetting(SysSettings.lastCmpBuildName, buildName); cmpVersionMenuItem.Text = string.Format("Check For New CMP Build ({0})", SysSettings.getSetting(SysSettings.lastCmpBuildName, "?")); Process.Start("svn", "update c:\\MeterDefinitions"); }; string[] buildInfo = buildName.Split('.'); string[] oldBuildInfo = lastBuild.Split('.'); int oldMajor = int.Parse(oldBuildInfo[0]); int newMajor = int.Parse(buildInfo[0]); if (oldMajor < newMajor) { continue; } if (oldMajor == newMajor) { // Same Major Number, check for new minor number if (int.Parse(oldBuildInfo[1]) >= int.Parse(buildInfo[1])) { continue; } else { buildFound.Invoke(); return; } } else { // Definately a new build, smaller major number buildFound.Invoke(); return; } } catch (Exception e) { handle(e); } } if (manual) { Toast.show(string.Format("No new CMP Builds found ({0})", SysSettings.getSetting(SysSettings.lastCmpBuildName, "")), click: delegate { Process.Start(buildsPath); }); } } catch (Exception e) { handle(e); Toast.show("Error while checking for new CMP build", backgroundColor: Color.Red); } }
private void handleGlobalKeydown(Keys key) { try { if (keyStatus.ContainsKey(key)) { keyStatus[key] = true; } foreach (Keys k in keyTracker.Keys) { if (k != key) { keyTracker[k].count = 0; } } if (key != Keys.LWin && keyStatus[Keys.LWin]) { // --------------------- Windows + Other Key ------------------------------- switch (key) { case Keys.Q: // Toast.show("Windows Q"); break; default: break; } } if (!keyTracker.ContainsKey(key) || keyTracker[key].state == KeyTrackerHandler.State.Down) { return; } keyTracker[key].state = KeyTrackerHandler.State.Down; if (keyTracker[key].count == 0) { keyTracker[key].count++; System.Timers.Timer t2 = new System.Timers.Timer(keyTracker[key].time); t2.Elapsed += delegate { keyTracker[key].count = 0; t2.Dispose(); }; t2.Start(); } else if (keyTracker[key].count >= 1) { keyTracker[key].count++; } if (keyTracker[key].count == keyTracker[key].pressCount) { keyTracker[key].count = 0; if (bool.Parse(SysSettings.getSetting(SysSettings.keyPressListenerOn))) { keyTracker[key].handler.Invoke(null, null); } } } catch { return; } }
/// <summary> /// Cleans up downloads older than defined date, and deletes empty directories /// </summary> /// <param name="log">Whether or not to log information</param> public void cleanUpDownloads(bool log = false) { Action openDownloads = delegate { Process.Start(KnownFolders.GetPath(KnownFolder.Downloads)); }; try { string daysString = SysSettings.getSetting(SysSettings.deleteFromDownloadsDays); int days = int.Parse(daysString); string downloadsFolder = KnownFolders.GetPath(KnownFolder.Downloads); try { bool didSomething = false; List <string> dirs = new List <string>(); foreach (string path in Directory.GetFileSystemEntries(downloadsFolder, "*", SearchOption.AllDirectories)) { if (Directory.Exists(path)) { dirs.Add(path); // Is a path DateTime time = Directory.GetLastWriteTime(path); if ((DateTime.Now - time).TotalDays >= days) { Directory.Delete(path, true); didSomething = true; } } else { // Is a file DateTime time = new FileInfo(path).LastWriteTime; if ((DateTime.Now - time).TotalDays >= days) { File.Delete(path); didSomething = true; } } } foreach (string path in dirs) { if (!Directory.EnumerateFileSystemEntries(path).Any()) { // Empty Directory, delete it Directory.Delete(path, true); } } if (didSomething || log) { Toast.show("Downloads Cleaned Up", click: openDownloads, timeout: 3000); } } catch (Exception e) { handle(e); Toast.show("Error while trying to clear your Downloads folder", click: openDownloads); } } catch (Exception e) { handle(e); Toast.show("Could not parse your settings. Please verify them", click: delegate { new SettingsForm().Show(); }); } }
/// <summary> /// Initialize settings, and if the value does not exist, give it a default value /// </summary> void initializeSettings() { try { SysSettings.init(); foreach (string key in SysSettings.defaults.Keys) { string value = SysSettings.getSetting(key, null); if (value == null) { SysSettings.setSetting(key, SysSettings.defaults[key]); } } } catch { } }
private bool isLocked = false; // Assume that the program initializes while the computer is unlocked public Sys() { runOnStartup(); _proc = HookCallback; _hookID = SetHook(_proc); actions = new List <Timer>(); keyStatus = new Dictionary <Keys, bool>(); keyTracker = new Dictionary <Keys, KeyTrackerHandler>(); // ----------- List of KeyTrackers ------------- keyTracker.Add(Keys.Escape, new KeyTrackerHandler(delegate { exit(); })); keyTracker.Add(Keys.LControlKey, new KeyTrackerHandler(delegate { Process.Start(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "https://google.com"); Toast.show("Click to disable", timeout: Time.seconds(2.5), backgroundColor: Color.Black, animate: false, click: delegate { SysSettings.setSetting(SysSettings.keyPressListenerOn, false.ToString()); }); }, time: Time.seconds(.5))); keyTracker.Add(Keys.RControlKey, new KeyTrackerHandler(delegate { string num = Microsoft.VisualBasic.Interaction.InputBox("Which VM?", "Which VM?", "1"); if (!string.IsNullOrEmpty(num) && (num.Length == 1 || num.Length == 2)) { try { string cmd = string.Format("\\\\nc45lta3virt{0}\\c$\\", num); if (Directory.Exists(cmd)) { Process.Start("c:\\windows\\explorer.exe", cmd); } } catch (Exception e) { Toast.show(e.Message); } } else { Toast.show("Invalid"); } })); keyTracker.Add(Keys.RShiftKey, new KeyTrackerHandler(delegate { Toast.show("Stop pressing Shift so much", timeout: Time.seconds(3.5), backgroundColor: Color.Red); }, 5, Time.seconds(10))); keyTracker.Add(Keys.PrintScreen, new KeyTrackerHandler(delegate { Toast.show("Give Me a Macro", Time.seconds(3), Color.Gray); })); keyTracker.Add(Keys.Pause, new KeyTrackerHandler(delegate { Toast.show("Give Me a Macro", Time.seconds(3), Color.Gray); })); foreach (Keys key in new Keys[] { Keys.LWin }) { keyStatus.Add(key, false); } initializeSettings(); trayIcon = new NotifyIcon() { Icon = Properties.Resources.icon, Text = "System Info", BalloonTipTitle = "System Manager", Visible = true, ContextMenu = new ContextMenu() }; trayIcon.MouseClick += (object o, MouseEventArgs args) => { try { typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(trayIcon, null); } catch { } }; cmpVersionMenuItem = new MenuItem(string.Format("Check For New CMP Build ({0})", SysSettings.getSetting(SysSettings.lastCmpBuildName, "?")), delegate { closeMenu(); searchForCmpBuild(manual: true); }); trayIcon.ContextMenu.MenuItems.AddRange(new MenuItem[] { new MenuItem("Update APM", delegate { closeMenu(); ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "APM.cmd"; psi.Arguments = "update"; //psi.UseShellExecute = false; //psi.RedirectStandardInput = true; Process p = Process.Start(psi); try { using (var processInput = p.StandardInput) { processInput.WriteLine("\n"); processInput.Close(); } p.WaitForExit(); p.Close(); } catch (Exception e) { handle(e); } }), new MenuItem("Clean Up Downloads", delegate { closeMenu(); cleanUpDownloads(log: true); }), new MenuItem("Fix the stupid internet issue", delegate { closeMenu(); fixStupidInternetIssue(); }), new MenuItem("Show Editor", delegate { closeMenu(); new TextEditor().show(); }), new MenuItem("Show Info", showInfo), new MenuItem("Check For New Comms Build", delegate { closeMenu(); searchForNewCommsBuild(manual: true); }), cmpVersionMenuItem, new MenuItem("-"), new MenuItem("Settings", delegate { closeMenu(); new SettingsForm().Show(); }), new MenuItem("E&xit", delegate { closeMenu(); exit(); }) }); trayIcon.MouseDoubleClick += delegate(object o, MouseEventArgs args) { if (args.Button == MouseButtons.Left) { new TextEditor().Show(); } }; foreach (Timer t in new Timer[] { // ----------- List of Timers ------------- createTimer(delegate { try { foreach (Process p in Process.GetProcesses()) { if (!p.Responding && p.ProcessName.Equals("OUTLOOK")) { Toast.show("Outlook is not responding, click here to resart it", animate:false, backgroundColor:Color.Red, click:delegate { //Restart Outlook try { p.Kill(); System.Threading.Thread.Sleep(100); Process.Start("outlook.exe"); } catch (Exception e) { Toast.show("Could not restart outlook"); handle(e); } }); } else if (!p.Responding && bool.Parse(SysSettings.getSetting(SysSettings.showNonRespondingProcesses))) { Toast.show(string.Format("\"{0}\" is not responding", p.ProcessName), animate: false, click:delegate { Process.Start("procexp"); // Start Process Explorer }); } } } catch (Exception e) { handle(e); } }, interval: Time.seconds(1)), createTimer(delegate { cleanUpDownloads(); }, interval: Time.minutes(1)), createTimer(delegate { if (!isLocked) { fixStupidInternetIssue(); } }, interval: Time.minutes(10)), createTimer(delegate { if (!isLocked) { searchForNewCommsBuild(); } }, interval: Time.minutes(5)), createTimer(delegate { if (!isLocked) { searchForCmpBuild(); } }, interval: Time.minutes(5)) // -------------- End of Timers List ------------------ }) { t.Start(); actions.Add(t); } Application.ApplicationExit += delegate { trayIcon.Visible = false; }; // Listener for sign-in and sign-off events SystemEvents.SessionSwitch += (object sender, SessionSwitchEventArgs args) => { switch (args.Reason) { case SessionSwitchReason.SessionLock: // Lock the Computer isLocked = true; break; case SessionSwitchReason.SessionUnlock: // Sign In to the Computer isLocked = false; Toast.show("Welcome Back!", timeout: 5000, animate: false); fixStupidInternetIssue(); searchForCmpBuild(manual: false); break; default: return; } }; Toast.show("Sys Manager Now Running", backgroundColor: Color.DarkGreen); try { string openString = SysSettings.getSetting(SysSettings.openTextEditorOnStartup); if (bool.Parse(openString)) { new TextEditor().show(); } } catch { } }
public override void init() { BackColor = Color.FromArgb(0x2e, 0x2e, 0x2e); allControls = new List <Control>(); Text = "Text Editor"; setScreenSizePercentage(.75); editor = new Editor(backColor: BackColor) { Dock = DockStyle.Fill }; int colorBase = 0x88; HorizontalPanel topPanel = new HorizontalPanel() { Dock = DockStyle.Top, Height = topHeight, BackColor = Color.FromArgb(colorBase, colorBase, colorBase) }; topPanel.addControl(new TopButton(click: delegate { save(SysSettings.getSetting(openFileSetting, null)); }, text: "Save")); topPanel.addControl(new TopButton(click: delegate { open(); }, text: "Open")); topPanel.addControl(new TopButton(click: delegate { SysSettings.deleteSetting(openFileSetting); editor.Text = string.Empty; }, text: "Close File")); this.addControl(topPanel); Panel editorContainer = new Panel() { Padding = new Padding(5), Dock = DockStyle.Bottom }; editor.scrollEvent += delegate { }; Action <Control> addToList = null; addToList = (Control c) => { if (c == null) { return; } allControls.Add(c); foreach (Control subC in c.Controls) { addToList(subC); } }; editorContainer.addControl(editor); this.addControl(editorContainer); addToList(this); async(() => { string openFile = SysSettings.getSetting(openFileSetting, null); if (openFile != null) { editor.runOnUiThread(() => { open(openFile); }); } }); KeyEventHandler keyHandler = (object o, KeyEventArgs args) => { if (args.Control) { switch (args.KeyCode) { case Keys.O: open(); break; case Keys.S: save(SysSettings.getSetting(openFileSetting, null)); break; case Keys.A: editor.SelectAll(); break; } } }; KeyDown += keyHandler; foreach (Control c in allControls) { c.KeyDown += keyHandler; } resizeHandler = delegate { editorContainer.Height = ClientSize.Height - (topHeight + 10); }; }