示例#1
0
        private void CheckOnline(bool silent = false)
        {
            if (!Program.NoGit)
            {
                // Is remote on in the config
                if (_config["UseGitRemote"])
                {
                    // Check if the remote is there
                    if (GitHandling.CheckConnection(_config["GitRemote"]))
                    {
                        // looks good, let's try
                        this.gitRepoOffline = false;
                    }

                    // Do a fetch to get the latest repo.
                    if (!GitRepo.Fetch(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                    {
                        // nope not online
                        this.gitRepoOffline = true;
                        MessageBox.Show(Strings.Error_connection, Strings.Error, MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        // We're online
                        toolStripOffline.Visible = false;
                        // sync with remote
                        if (!GitRepo.Push(_config["GitUser"], DecryptConfig(_config["GitPass"], "pass4win")))
                        {
                            MessageBox.Show(
                                Strings.FrmMain_EncryptCallback_Push_to_remote_repo_failed_,
                                Strings.Error,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    // no remote checkbox so we're staying offline
                    if (!silent)
                    {
                        MessageBox.Show(
                            Strings.Error_remote_disabled,
                            Strings.Error,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Validates if the host is filled when the remote repo is checked
 /// Also checkes on alive (with a connect) and when that fails if it's a valid formed URL
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TxtGitHostValidating(object sender, CancelEventArgs e)
 {
     if (chkboxRemoteRepo.Checked && txtGitHost.Text == "")
     {
         errorProvider1.SetError(txtGitHost, Strings.Error_required_field);
         if (this.valCancel)
         {
             e.Cancel = true;
         }
     }
     else
     {
         if (chkboxRemoteRepo.Checked)
         {
             if (!GitHandling.CheckConnection(txtGitHost.Text))
             {
                 if (this.valCancel)
                 {
                     Uri hostTest;
                     if (!Uri.TryCreate(txtGitHost.Text, UriKind.Absolute, out hostTest))
                     {
                         errorProvider1.SetError(txtGitHost, Strings.Error_notvalid_URL);
                         e.Cancel = true;
                     }
                 }
                 else
                 {
                     errorProvider1.SetError(txtGitHost, Strings.Error_host_unreachable);
                     this.offline = true;
                 }
             }
             else
             {
                 this.offline = false;
             }
         }
     }
 }
示例#3
0
        /// <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;
        }
示例#4
0
文件: Main.cs 项目: shaleh/Pass4Win
        /// <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;
        }