/// <summary> /// Inits the repo, gpg etc /// </summary> public FrmMain() { InitializeComponent(); toolStripStatusLabel1.Text = ""; // ReSharper disable once UnusedVariable var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171"); this.enableTray = false; // Getting actual version var assembly = Assembly.GetExecutingAssembly(); var fvi = FileVersionInfo.GetVersionInfo(assembly.Location); var version = fvi.FileVersion; Cfg["version"] = version.Remove(5, 2); Text = @"Pass4Win " + Strings.Version + @" " + Cfg["version"]; // checking for update this an async operation #pragma warning disable 4014 LatestPass4WinRelease(); #pragma warning restore 4014 // Do we have a valid password store and settings try { if (Cfg["PassDirectory"] == "") { // this will fail, I know ugly hack } } catch (Exception) { Cfg["FirstRun"] = true; var config = new FrmConfig(); config.ShowDialog(); } //checking git status if (!IsValid(Cfg["PassDirectory"])) { // Remote or generate a new one if (Cfg["UseGitRemote"] == true) { // check if server is alive if (IsGitAlive(Cfg["UseGitRemote"]) || IsHttpsAlive(Cfg["UseGitRemote"])) { // clone the repo and catch any error try { Clone(Cfg["GitRemote"], Cfg["PassDirectory"], new CloneOptions { CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials { Username = Cfg["GitUser"], Password = DecryptConfig(Cfg["GitPass"], "pass4win") } }); } catch (Exception) { MessageBox.Show(Strings.Error_connection, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.toolStripOffline.Visible = true; } } else { MessageBox.Show(Strings.Error_git_unreachable, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); toolStripOffline.Visible = true; } } else { // creating new Git Repository.Init(Cfg["PassDirectory"], false); toolStripOffline.Visible = true; } } else { // Do we do remote or not CheckOnline(true); } // Making sure core.autocrlf = true using (var repo = new Repository(Cfg["PassDirectory"])) { repo.Config.Set("core.autocrlf", true); } // Init GPG if needed string gpgfile = Cfg["PassDirectory"]; gpgfile += "\\.gpg-id"; // Check if we need to init the directory if (!File.Exists(gpgfile)) { // ReSharper disable once AssignNullToNotNullAttribute Directory.CreateDirectory(Path.GetDirectoryName(gpgfile)); var newKeySelect = new KeySelect(); if (newKeySelect.ShowDialog() == DialogResult.OK) { using (var w = new StreamWriter(gpgfile)) { w.Write(newKeySelect.Gpgkey); } using (var repo = new Repository(Cfg["PassDirectory"])) { repo.Stage(gpgfile); repo.Commit("gpgid added", new Signature("pass4win", "pass4win", DateTimeOffset.Now), new Signature("pass4win", "pass4win", DateTimeOffset.Now)); } } else { newKeySelect.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 = Cfg["GPGEXE"]; // init FileSystemInterface class fsi = new FileSystemInterface(Cfg["PassDirectory"]); // Fill tree CreateNodes(); this.enableTray = true; }
private void ToolStripbtnConfigClick(object sender, EventArgs e) { var config = new FrmConfig(); config.SendOffline += this.ConfigSendOffline; config.Show(); }
private void toolStripbtnConfig_Click(object sender, EventArgs e) { var config = new FrmConfig(); config.SendOffline += Config_SendOffline; config.Show(); }