private void saveButton_Click(object sender, EventArgs e) { try { using (StreamWriter sw = new StreamWriter(confFile.FullName, false)) { uint activemodules = (uint)LoadModules(); sw.WriteLine(activemodules); sw.WriteLine(intervalDomainUpDown.Text); sw.Close(); } if (MessageBox.Show("Settings saved but will not take effect until you restart.\r\nRestart system now?", "Control Panel", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { WindowsController.ExitWindows(RestartOptions.Reboot, false); } } catch (Exception ex) { Debug.WriteLine(String.Format("Exception in SaveMethod() (ControlPanel): {0}", ex.Message)); } }
private void installToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.ShowNewFolderButton = false; dialog.Description = "Select source files' location"; if (dialog.ShowDialog() == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; // Creating folders structure rootdir = Directory.CreateDirectory(rootdir.FullName); DirectoryInfo logdir = Directory.CreateDirectory(rootdir.FullName + "\\Logs"); DirectoryInfo screensdir = Directory.CreateDirectory(rootdir.FullName + "\\Screencaptures"); // Creating configuration file using (StreamWriter sw = new StreamWriter(rootdir.FullName + "\\Monitorizare.conf", false)) { sw.WriteLine("1151"); sw.WriteLine("15"); sw.Close(); } // Coping files uint filescopied = 0; DirectoryInfo sourcedir = new DirectoryInfo(dialog.SelectedPath); foreach (FileInfo fi in sourcedir.GetFiles("*.*", SearchOption.AllDirectories)) { if (fi.Name == "winsvc.exe") { filescopied += Copyfile(fi, rootdir); } if (fi.Name == "winsvc-launcher.exe") { filescopied += Copyfile(fi, rootdir); } if (fi.Name == "Monitorizare.dll") { filescopied += Copyfile(fi, rootdir); } if (filescopied == 3) { break; } } if (filescopied < 2) { MessageBox.Show("All or some of source files could not be found\r\nInstallation incomplete.", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Error); } try {// Install service agent ManagedInstallerClass.InstallHelper(new string[] { rootdir.FullName + "\\winsvc-launcher.exe" }); if (MessageBox.Show("Installation successful.\r\nSystem must be restarted\r\nRestart system now?", "Control Panel", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { WindowsController.ExitWindows(RestartOptions.Reboot, false); } } catch (InvalidOperationException ex) { MessageBox.Show("You need to run application as administrator.", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); if (rootdir.Exists) { rootdir.Delete(true); } } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Arrow; } // end if ShowDialog() }