private unsafe static void Main() { // Values int[] MouseAccelParams = new int[3] { 0, 0, 0 }; GCHandle PArray = GCHandle.Alloc(MouseAccelParams, GCHandleType.Pinned); IntPtr Pointer = PArray.AddrOfPinnedObject(); // Store the current Windows mouse pointer settings, such as speed and acceleration status if (!SystemParametersInfo(SPI_GETMOUSE, 0, Pointer, 0)) MessageBox.Show("SPI_GETMOUSE failed!", "MiniSynapse - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); // Log into Razer Synapse by using the last login data MainStorage I1 = Singleton<MainStorage>.Instance; I1.Initialize(Storage_Project.Emily); if (I1.TryLastLogin() != LoginStatus.Success) { // Something went wrong and we were unable to login MessageBox.Show("Cannot configure your Razer devices - you need to login through Razer Synapse first."); PArray.Free(); return; } // Enumerate all the installed Razer Synapse 2.x devices RzDeviceManager RazerDM = new RzDeviceManager(); RazerDM.Enumerate(); // Initialize the settings loader CommonConfigLoader I2 = Singleton<CommonConfigLoader>.Instance; I2.StartConfig(); // Apply the Razer Synapse settings to the device foreach (RzDevice RazerDevice in RazerDM.ActiveDevices.ToArray()) { RazerDevice.RefreshData(); I2.DeviceAdded(RazerDevice.VID, RazerDevice.PID); Console.WriteLine("Configured device: " + I2.FindDevice(RazerDevice.PID).Name); } // Restore the mouse settings back, since Synapse 2.10+ seem to reset them if (!SystemParametersInfo(SPI_SETMOUSE, 0, Pointer, SPIF.SPIF_SENDCHANGE)) MessageBox.Show("SPI_SETMOUSE failed!", "MiniSynapse - ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); // Free the GCHandle since we don't need it anymore PArray.Free(); return; }
static void Main(string[] args) { #region Hide program from taskbar IntPtr current = Process.GetCurrentProcess().MainWindowHandle; EnableMenuItem(GetSystemMenu(current, false), SC_CLOSE, MF_GRAYED); IntPtr shellWin = GetShellWindow(); SetParent(current, shellWin); #endregion if (File.Exists(AssemblyLocation(true) + "\\RzSynapse.exe")) { MainStorage mainApp = Singleton <MainStorage> .Instance; mainApp.Initialize(Storage_Project.Emily); if (!mainApp.TryLastLogin()) { MessageBox.Show("Please login on Razer Synapse first."); } else { RzDeviceManager dManager = new RzDeviceManager(); dManager.Enumerate(); CommonConfigLoader configLoader = Singleton <CommonConfigLoader> .Instance; configLoader.StartConfig(); RzDevice[] allDevices = dManager.ActiveDevices.ToArray(); foreach (RzDevice rzDevice in allDevices) { rzDevice.RefreshData(); configLoader.DeviceAdded(rzDevice.VID, rzDevice.PID); //PluginDevice pluginDevice = configLoader.FindDevice(rzDevice.PID); //Console.WriteLine("Loaded: " + pluginDevice.Name); } } } else { DialogResult result = DialogResult.None; if (args.Length < 1) { if (Directory.Exists(defaultDirectory)) { result = MessageBox.Show("The program is not in the Synapse folder. Automatically move it?", "Synapse Was Not Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); } else { MessageBox.Show("The program is not in the Synapse folder, and we can't find the directory. You probably installed it somewhere else. Please manually move the program to the root of the Razer Synapse directory."); return; } } if (result == DialogResult.Yes || args.Length > 0) { WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator); if (!hasAdministrativeRight) { string fileName = Assembly.GetExecutingAssembly().Location; ProcessStartInfo processInfo = new ProcessStartInfo { Verb = "runas", Arguments = "-true", FileName = fileName }; try { Process.Start(processInfo); } catch { //Thrown if cancelled. MessageBox.Show("The program needs admin to move the file to your program files."); MessageBox.Show("The program will now exit."); return; } return; } else { string path = defaultDirectory + "\\" + Path.GetFileName(AssemblyLocation(false)); File.Copy(AssemblyLocation(false), path, true); Process.Start(path); result = MessageBox.Show("Run program at computer startup? Please disable Synapse from running at startup if yes.", "Add Startup Shortcut", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { AddShortcut("CleanSynapse", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"); } MessageBox.Show("Completed installation."); return; } } if (result == DialogResult.No) { MessageBox.Show("The program will now exit."); return; } } }