예제 #1
0
 protected void open(string filename = null)
 {
     try {
         if (filename == null)
         {
             OpenFileDialog dialog = new OpenFileDialog()
             {
                 Multiselect = false
             };
             if (dialog.ShowDialog() == DialogResult.OK && File.Exists(dialog.FileName))
             {
                 SysSettings.setSetting(openFileSetting, dialog.FileName);
                 string cont = File.ReadAllText(dialog.FileName);
                 editor.Text = cont;
                 Text        = Path.GetFileName(dialog.FileName);
             }
         }
         else
         {
             SysSettings.setSetting(openFileSetting, filename);
             editor.Text = File.ReadAllText(filename);
             Text        = Path.GetFileName(filename);
         }
     } catch (Exception e) { handle(e); Toast.show("Problem opening file"); }
 }
예제 #2
0
파일: Program.cs 프로젝트: kamackay/sys
        /// <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); }
        }
예제 #3
0
파일: Program.cs 프로젝트: kamackay/sys
 /// <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 { }
 }
예제 #4
0
파일: Program.cs 프로젝트: kamackay/sys
        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 { }
        }