private void toolStripbtnConfig_Click(object sender, EventArgs e) { frmConfig Config = new frmConfig(); Config.SendOffline += new EventHandler(Config_SendOffline); Config.Show(); }
/// <summary> /// Callback for the event from config that the git repo is changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Config_SendOffline(object sender, EventArgs e) { frmConfig child = sender as frmConfig; if (child != null) { toolStripOffline.Visible = child.IsOffline; if (!child.IsOffline) { CheckOnline(true); } } }
/// <summary> /// Inits the repo, gpg etc /// </summary> public frmMain() { InitializeComponent(); var bugsnag = new BaseClient("23814316a6ecfe8ff344b6a467f07171"); EnableTray = false; // Getting actual version System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); string version = fvi.FileVersion; cfg["version"] = version.Remove(5, 2); this.Text = "Pass4Win " + Strings.Version + " " + cfg["version"]; // checking for update this an async operation LatestPass4WinRelease(); // Do we have a valid password store and settings try { if (cfg["PassDirectory"] == "") { // this will fail, I know ugly hack } } catch { cfg["FirstRun"] = true; frmConfig Config = new frmConfig(); var dialogResult = Config.ShowDialog(); } //checking git status if (!LibGit2Sharp.Repository.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 { string clonedRepoPath = LibGit2Sharp.Repository.Clone(cfg["GitRemote"], cfg["PassDirectory"], new CloneOptions() { CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = cfg["GitUser"], Password = DecryptConfig(cfg["GitPass"], "pass4win") } }); } catch { MessageBox.Show(Strings.Error_connection, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); toolStripOffline.Visible = true; } } else { MessageBox.Show(Strings.Error_git_unreachable, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); toolStripOffline.Visible = true; } } else { // creating new Git var repo = LibGit2Sharp.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 LibGit2Sharp.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)) { Directory.CreateDirectory(Path.GetDirectoryName(gpgfile)); KeySelect newKeySelect = new KeySelect(); if (newKeySelect.ShowDialog() == DialogResult.OK) { using (StreamWriter w = new StreamWriter(gpgfile)) { w.Write(newKeySelect.gpgkey); } using (var repo = new LibGit2Sharp.Repository(cfg["PassDirectory"])) { repo.Stage(gpgfile); repo.Commit("gpgid added", new LibGit2Sharp.Signature("pass4win", "pass4win", System.DateTimeOffset.Now), new LibGit2Sharp.Signature("pass4win", "pass4win", System.DateTimeOffset.Now)); } } else { newKeySelect.Close(); MessageBox.Show(Strings.Error_nokey, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); System.Environment.Exit(1); } } // Setting the exe location for the GPG Dll GpgInterface.ExePath = cfg["GPGEXE"]; // Setting up datagrid dt.Columns.Add("colPath", typeof(string)); dt.Columns.Add("colText", typeof(string)); treeDt.Columns.Add("colPath", typeof(string)); treeDt.Columns.Add("colText", typeof(string)); ListDirectory(new DirectoryInfo(cfg["PassDirectory"]), ""); fillDirectoryTree(dirTreeView, cfg["PassDirectory"]); dataPass.DataSource = dt.DefaultView; dataPass.Columns[0].Visible = false; EnableTray = true; }