public void Delete() { var standardConfig = new ConfigHandling(); standardConfig["test"] = 1024; standardConfig.Delete("test"); Assert.IsEmpty(standardConfig["test"]); }
public FrmAbout(ConfigHandling config) { _config = config; InitializeComponent(); // Getting actual version txtPassVersion.Text += @" " + _config["version"]; }
/// <summary> /// Initializes a new instance of the <see cref="FileSystemInterface"/> class. /// </summary> /// <param name="config"></param> /// <param name="directoryProvider"></param> public FileSystemInterface(ConfigHandling config, IDirectoryProvider directoryProvider) { _config = config; _directoryProvider = directoryProvider; SearchList = new List<string> { "No", "Value" }; //// Filling the Directory and search datatable this.UpdateDirectoryList(directoryProvider); }
/// <summary> /// Initializes a new instance of the <see cref="FrmKeyManager"/> class. /// </summary> public FrmKeyManager(FileSystemInterface fileSystemInterface, ConfigHandling config, KeySelect keySelect) { _fileSystemInterface = fileSystemInterface; _config = config; _keySelect = keySelect; InitializeComponent(); GpgInterface.ExePath = _config["GPGEXE"]; ListDirectory(treeView1); }
public DirectoryProvider(ConfigHandling config) { _config = config; try { _directoryInfo = new DirectoryInfo(_config["PassDirectory"]); } catch (ArgumentException) { } }
public void ReferenceTypes() { ConfigHandling standardConfig = new ConfigHandling(); string referenceString = "referenced string"; string[] referenceArray = { "referenced", "string"}; standardConfig["testString"] = referenceString; standardConfig["testArray"] = referenceArray; Assert.AreEqual(referenceString, standardConfig["testString"]); Assert.AreEqual(referenceArray, standardConfig["testArray"]); }
public void SavingLoading() { int value = 1024; { var standardConfig = new ConfigHandling {["test"] = value}; standardConfig.Save(); } { var standardConfig = new ConfigHandling(); Assert.AreEqual(value, standardConfig["test"]); } }
public FrmConfig(ConfigHandling config) { _config = config; InitializeComponent(); // fill in the blanks if (_config["FirstRun"] == false) { // set config values try { txtPassFolder.Text = _config["PassDirectory"]; txtPassValidTime.Text = _config.PassValidTime.ToString(); txtGPG.Text = _config["GPGEXE"]; chkboxRemoteRepo.Checked = _config["UseGitRemote"]; txtGitUser.Text = _config["GitUser"]; txtGitPass.Text = _config["GitPass"]; txtGitHost.Text = _config["GitRemote"]; ExternalGit.CheckedChanged -= ExternalGit_CheckedChanged; ExternalGit.Checked = _config["ExternalGit"]; ExternalGit.CheckedChanged += ExternalGit_CheckedChanged; } catch { } // set access txtGitUser.ReadOnly = !chkboxRemoteRepo.Checked; txtGitPass.ReadOnly = !chkboxRemoteRepo.Checked; txtGitHost.ReadOnly = !chkboxRemoteRepo.Checked; txtGitUser.Visible = chkboxRemoteRepo.Checked; txtGitPass.Visible = chkboxRemoteRepo.Checked; txtGitHost.Visible = chkboxRemoteRepo.Checked; label4.Visible = chkboxRemoteRepo.Checked; label5.Visible = chkboxRemoteRepo.Checked; label6.Visible = chkboxRemoteRepo.Checked; } else { _config.ResetConfig(); _config["PassValidTime"] = _config.DefaultPassValidTime.ToString(); _config["UseGitRemote"] = false; _config["GitUser"] = ""; _config["GitPass"] = ""; _config["GitRemote"] = ""; _config["ExternalGit"] = false; _config["FirstRun"] = false; } }
public void ValueTypes() { var standardConfig = new ConfigHandling(); int valueInteger = 5000; standardConfig["testInteger"] = valueInteger; DateTime valueDate = DateTime.Now; standardConfig["testDate"] = valueDate; char valueChar = 'x'; standardConfig["testChar"] = valueChar; Assert.AreEqual(valueDate, standardConfig["testDate"]); Assert.AreEqual(valueInteger, standardConfig["testInteger"]); Assert.AreEqual(valueChar, standardConfig["testChar"]); }
/// <summary> /// Inits the repo, gpg etc /// </summary> public FrmMain(FileSystemInterface fileSystemInterface, KeySelect keySelect, ConfigHandling config) { log.Debug("Init variables"); fsi = fileSystemInterface; _keySelect = keySelect; _config = config; InitializeComponent(); toolStripStatusLabel1.Text = ""; log.Debug("init Bugsnag"); var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171"); this.enableTray = false; // Getting actual version log.Debug("Getting program version"); var assembly = Assembly.GetExecutingAssembly(); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); var version = fvi.FileVersion; _config["version"] = version.Remove(5); Text = @"Pass4Win " + Strings.Version + @" " + _config["version"]; // check config input log.Debug("Checking config validity"); try { bool ChkBool = Directory.Exists(_config["PassDirectory"]); if (!ChkBool) { throw new Exception("Pass directory fail"); } ChkBool = File.Exists(_config["GPGEXE"]); if (!ChkBool) { throw new Exception("GPG location fail"); } if (_config["UseGitRemote"] || _config["ExternalGit"]) { // nobody cares, we want the exception and it's auto generated due to a null value or not a boolean } } catch { // no matter if it's a first run or a corrupt entry, let them fix it. log.Debug("Config corrupt or first run"); _config["FirstRun"] = true; Program.Scope.Resolve <FrmConfig>().ShowDialog(); } // checking for update in the background log.Debug("Checking online for latest release"); LatestPass4WinRelease(); // making new git object if (_config["ExternalGit"]) { log.Debug("Using an external git executable"); GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"], _config["ExternalGitLocation"]); } else { log.Debug("Using the internal git executable"); GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"]); } //checking git status if (_config["UseGitRemote"] == true || _config["ExternalGit"]) { if (GitRepo.ConnectToRepo() || (_config["ExternalGit"])) { log.Debug("Remote Git is valid and active"); this.gitRepoOffline = false; toolStripOffline.Visible = false; if (!GitRepo.Fetch(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win"))) { // Something failed which shouldn't fail, rechecking online status CheckOnline(false); } } // checking if we can clone, otherwise make a new one else if (!GitRepo.GitClone(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win"))) { log.Debug("Making a new git repo"); Repository.Init(_config["PassDirectory"], false); GitRepo.ConnectToRepo(); toolStripOffline.Visible = true; } } // no connection, no repo. So make a new one else if (!GitHandling.IsValid(_config["PassDirectory"])) { log.Debug("Making a new git repo"); Repository.Init(_config["PassDirectory"], false); GitRepo.ConnectToRepo(); toolStripOffline.Visible = true; } // Init GPG if needed string gpgfile = _config["PassDirectory"]; gpgfile += "\\.gpg-id"; // Check if we need to init the directory if (!File.Exists(gpgfile)) { log.Debug("Creating .gpg-id"); // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(gpgfile)); if (_keySelect.ShowDialog() == DialogResult.OK) { using (var w = new StreamWriter(gpgfile)) { w.Write(_keySelect.Gpgkey); } if (!GitRepo.Commit(gpgfile)) { MessageBox.Show( Strings.FrmMain_EncryptCallback_Commit_failed_, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { _keySelect.Close(); MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } } // Setting the exe location for the GPG Dll GpgInterface.ExePath = _config["GPGEXE"]; // Fill tree CreateNodes(); this.enableTray = true; }
public KeySelect(ConfigHandling config) { _config = config; InitializeComponent(); }
/// <summary> /// Inits the repo, gpg etc /// </summary> public FrmMain(FileSystemInterface fileSystemInterface, KeySelect keySelect, ConfigHandling config) { log.Debug("Init variables"); fsi = fileSystemInterface; _keySelect = keySelect; _config = config; InitializeComponent(); toolStripStatusLabel1.Text = ""; log.Debug("init Bugsnag"); var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171"); this.enableTray = false; // Getting actual version log.Debug("Getting program version"); var assembly = Assembly.GetExecutingAssembly(); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); var version = fvi.FileVersion; _config["version"] = version.Remove(5); Text = @"Pass4Win " + Strings.Version + @" " + _config["version"]; // check config input log.Debug("Checking config validity"); try { bool ChkBool = Directory.Exists(_config["PassDirectory"]); if (!ChkBool) throw new Exception("Pass directory fail"); ChkBool = File.Exists(_config["GPGEXE"]); if (!ChkBool) throw new Exception("GPG location fail"); if (_config["UseGitRemote"] || _config["ExternalGit"]) { // nobody cares, we want the exception and it's auto generated due to a null value or not a boolean } } catch { // no matter if it's a first run or a corrupt entry, let them fix it. log.Debug("Config corrupt or first run"); _config["FirstRun"] = true; Program.Scope.Resolve<FrmConfig>().ShowDialog(); } // checking for update in the background log.Debug("Checking online for latest release"); LatestPass4WinRelease(); // making new git object if (_config["ExternalGit"] && !Program.NoGit) { log.Debug("Using an external git executable"); GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"], _config["ExternalGitLocation"]); } else if (!Program.NoGit) { log.Debug("Using the internal git executable"); GitRepo = new GitHandling(_config["PassDirectory"], _config["GitRemote"]); } //checking git status if (_config["UseGitRemote"] == true || _config["ExternalGit"]) { if (!Program.NoGit) { if (GitRepo.ConnectToRepo() || (_config["ExternalGit"])) { log.Debug("Remote Git is valid and active"); this.gitRepoOffline = false; toolStripOffline.Visible = false; if (!GitRepo.Fetch(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win"))) { // Something failed which shouldn't fail, rechecking online status CheckOnline(false); } } // checking if we can clone, otherwise make a new one else if (!GitRepo.GitClone(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win"))) { log.Debug("Making a new git repo"); Repository.Init(_config["PassDirectory"], false); GitRepo.ConnectToRepo(); toolStripOffline.Visible = true; } // no connection, no repo. So make a new one else if (!GitHandling.IsValid(_config["PassDirectory"])) { log.Debug("Making a new git repo"); Repository.Init(_config["PassDirectory"], false); GitRepo.ConnectToRepo(); toolStripOffline.Visible = true; } } } // Init GPG if needed string gpgfile = _config["PassDirectory"]; gpgfile += "\\.gpg-id"; // Check if we need to init the directory if (!File.Exists(gpgfile)) { log.Debug("Creating .gpg-id"); // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(gpgfile)); if (_keySelect.ShowDialog() == DialogResult.OK) { using (var w = new StreamWriter(gpgfile)) { w.Write(_keySelect.Gpgkey); } if (!Program.NoGit) { if (!GitRepo.Commit(gpgfile)) { MessageBox.Show( Strings.FrmMain_EncryptCallback_Commit_failed_, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { _keySelect.Close(); MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } } // Setting the exe location for the GPG Dll GpgInterface.ExePath = _config["GPGEXE"]; // Fill tree CreateNodes(); this.enableTray = true; }