Exemplo n.º 1
0
        private void buttonRemove_Click(object sender, EventArgs e)
        {
            if (Msg.YesNo(this, string.Format(Resources.DeleteCheckedEntries, _treeView.CheckedEntries.Count), MsgSeverity.Warn))
            {
                try
                {
                    using var handler = new DialogTaskHandler(this);
                    foreach (var node in _treeView.CheckedEntries.Select(x => x.BackingNode).ToList())
                    {
                        node.Delete(handler);
                    }
                }
                #region Error handling
                catch (OperationCanceledException)
                {}
                catch (KeyNotFoundException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                }
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                }
                #endregion

                finally
                {
                    RefreshList();
                }
            }
        }
Exemplo n.º 2
0
        private void installerCaptureDiffPage_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            var session = _installerCapture.CaptureSession;

            if (session == null)
            {
                return;
            }

            try
            {
                session.InstallationDir = textBoxInstallationDir.Text;
                using (var handler = new DialogTaskHandler(this))
                    session.Diff(handler);
            }
            #region Error handling
            catch (InvalidOperationException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (IOException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            #endregion

            try
            {
                using (var handler = new DialogTaskHandler(this))
                    _installerCapture.ExtractInstallerAsArchive(_feedBuilder, handler);

                pageInstallerCaptureDiff.NextPage = pageArchiveExtract;
            }
            catch (IOException)
            {
                Msg.Inform(this, Resources.InstallerExtractFailed + Environment.NewLine + Resources.InstallerNeedAltSource, MsgSeverity.Info);
                pageInstallerCaptureDiff.NextPage = pageInstallerCollectFiles;
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                e.Cancel = true;
            }
            catch (UnauthorizedAccessException ex)
            {
                e.Cancel = true;
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion
        }
Exemplo n.º 3
0
        private void buttonSkipCapture_Click(object sender, EventArgs e)
        {
            if (!Msg.YesNo(this, Resources.AskSkipCapture, MsgSeverity.Info))
            {
                return;
            }

            try
            {
                using var handler = new DialogTaskHandler(this);
                _installerCapture.ExtractInstallerAsArchive(_feedBuilder, handler);
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return;
            }
            catch (IOException ex)
            {
                Msg.Inform(this, Resources.InstallerExtractFailed + Environment.NewLine + ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }
            #endregion

            wizardControl.NextPage(pageArchiveExtract, skipCommit: true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a feed to the list of custom feeds.
        /// </summary>
        private void AddCustomFeed(string input)
        {
            FeedUri feedUri;

            try
            {
                feedUri = new FeedUri(input);
            }
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }

            if (_interfaceUri.IsFile)
            {
                if (!File.Exists(_interfaceUri.LocalPath))
                {
                    Msg.Inform(this, string.Format(Resources.FileOrDirNotFound, _interfaceUri.LocalPath), MsgSeverity.Warn);
                    return;
                }
            }
            else
            {
                Feed feed = null;
                try
                {
                    using var handler = new DialogTaskHandler(this);
                    handler.RunTask(new SimpleTask(Resources.CheckingFeed,
                                                   delegate
                    {
                        using var webClient = new WebClientTimeout();
                        feed = XmlStorage.FromXmlString <Feed>(webClient.DownloadString(feedUri));
                    }));
                }
Exemplo n.º 5
0
        private void buttonCreateArchive_Click(object sender, EventArgs e)
        {
            try
            {
                using var handler = new DialogTaskHandler(this);
                _installerCapture.CaptureSession !.CollectFiles(textBoxArchivePath.Text, textBoxUploadUrl.Uri !, handler);
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return;
            }
            catch (Exception ex) when(ex is IOException or NotSupportedException)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }
            #endregion

            wizardControl.NextPage(pageEntryPoint);
        }
Exemplo n.º 6
0
        /// <inheritdoc/>
        protected override void OnSaveFile()
        {
            // Automatically update outdated shadow maps
            if ((_universe.Terrain.OcclusionIntervalMapOutdated || _universe.Terrain.OcclusionIntervalMap == null) && Msg.YesNo(this, "Calculate shadows?\nThis may take some time.", MsgSeverity.Info))
            {
                try
                {
                    var generator = OcclusionIntervalMapGenerator.FromTerrain(_universe.Terrain, _universe.SunInclination);
                    using (var handler = new DialogTaskHandler(this)) handler.RunTask(generator);

                    _universe.Terrain.OcclusionIntervalMap         = generator.Result;
                    _universe.Terrain.OcclusionIntervalMapOutdated = false;
                }
                catch (OperationCanceledException)
                {}
            }

            Log.Info("Save file: " + _fullPath);
            string directory = Path.GetDirectoryName(_fullPath);

            if (!string.IsNullOrEmpty(directory))
            {
                Directory.CreateDirectory(directory);
            }
            _universe.Save(_fullPath);

            base.OnSaveFile();
        }
Exemplo n.º 7
0
        private void pageCredentials_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            _config.SyncServerUsername = textBoxUsername.Text;
            _config.SyncServerPassword = textBoxPassword.Text;

            try
            {
                using var handler = new DialogTaskHandler(this);
                handler.RunTask(new SimpleTask(Text, CheckCredentials));
            }
            #region Error handling
            catch (WebException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
                return;
            }
            catch (OperationCanceledException)
            {
                e.Cancel = true;
                return;
            }
            #endregion

            pageCredentials.NextPage = _existingAccount ? pageExistingCryptoKey : pageNewCryptoKey;
        }
Exemplo n.º 8
0
        private void pageExistingCryptoKey_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            _config.SyncCryptoKey = textBoxCryptoKey.Text;

            try
            {
                using var handler = new DialogTaskHandler(this);
                handler.RunTask(new SimpleTask(Text, CheckCryptoKey));
            }
            #region Error handling
            catch (WebException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
            }
            catch (InvalidDataException ex)
            {
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                e.Cancel = true;
            }
            catch (OperationCanceledException)
            {
                e.Cancel = true;
            }
            #endregion

            pageExistingCryptoKey.NextPage = _troubleshooting ? pageChangeCryptoKey : pageSetupFinished;
        }
Exemplo n.º 9
0
        private void buttonVerify_Click(object sender, EventArgs e)
        {
            try
            {
                using var handler = new DialogTaskHandler(this);
                foreach (var entry in _treeView.CheckedEntries.Select(x => x.BackingNode).OfType <ImplementationNode>())
                {
                    entry.Verify(handler);
                }
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            catch (UnauthorizedAccessException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            #endregion

            RefreshList();
        }
Exemplo n.º 10
0
        private void pageInstallerCaptureStart_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            try
            {
                var captureSession = CaptureSession.Start(_feedBuilder);

                using (var handler = new DialogTaskHandler(this))
                    _installerCapture.RunInstaller(handler);

                _installerCapture.CaptureSession = captureSession;
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                e.Cancel = true;
            }
            catch (Exception ex) when(ex is IOException or InvalidOperationException)
            {
                e.Cancel = true;
                Log.Warn(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
            }
            catch (UnauthorizedAccessException ex)
            {
                e.Cancel = true;
                Log.Error(ex);
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion
        }
Exemplo n.º 11
0
        private void pageArchiveExtract_Commit(object sender, WizardPageConfirmEventArgs e)
        {
            using (var handler = new DialogTaskHandler(this))
            {
                if (FileUtils.IsBreakoutPath(listBoxExtract.Text))
                {
                    e.Cancel = true;
                    Msg.Inform(this, Resources.ArchiveBreakoutPath, MsgSeverity.Error);
                    return;
                }

                _archive.Extract = listBoxExtract.Text ?? "";
                _feedBuilder.ImplementationDirectory = Path.Combine(_feedBuilder.TemporaryDirectory !, _archive.Extract.ToNativePath() !);

                try
                {
                    // Candidate detection is handled differently when capturing an installer
                    if (_installerCapture.CaptureSession == null)
                    {
                        _feedBuilder.DetectCandidates(handler);
                    }

                    _feedBuilder.GenerateDigest(handler);
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    e.Cancel = true;
                    return;
                }
                catch (Exception ex) when(ex is ArgumentException or IOException)
                {
                    e.Cancel = true;
                    Log.Warn(ex);
                    Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                    return;
                }
                catch (UnauthorizedAccessException ex)
                {
                    e.Cancel = true;
                    Log.Error(ex);
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                #endregion
            }

            if (_feedBuilder.ManifestDigest.PartialEquals(ManifestDigest.Empty))
            {
                Msg.Inform(this, Resources.EmptyImplementation, MsgSeverity.Warn);
                e.Cancel = true;
            }
            if (_feedBuilder.MainCandidate == null)
            {
                Msg.Inform(this, Resources.NoEntryPointsFound, MsgSeverity.Warn);
                e.Cancel = true;
            }
        }
Exemplo n.º 12
0
        private void buttonAddMissing_Click(object sender, EventArgs e)
        {
            var commandCollector = new CommandCollector {
                Path = CommandExecutor.Path
            };                                                                         // Represent all changes in a single undo step

            try
            {
                using (var handler = new DialogTaskHandler(this))
                    CheckDigest(handler, commandCollector);
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return;
            }
            catch (ArgumentException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (UnauthorizedAccessException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (WebException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Warn);
                return;
            }
            catch (NotSupportedException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }
            #endregion

            finally
            {
                var command = commandCollector.BuildComposite();
                if (CommandExecutor == null)
                {
                    command.Execute();
                }
                else
                {
                    CommandExecutor.Execute(command);
                }
            }

            _labelUpdateHint.Visible = false;
        }
Exemplo n.º 13
0
        private void Retrieve(DownloadRetrievalMethod retrievalMethod, string localPath)
        {
            _feedBuilder.RetrievalMethod = retrievalMethod;

            using (var handler = new DialogTaskHandler(this))
            {
                _feedBuilder.TemporaryDirectory = (localPath == null)
                    ? retrievalMethod.DownloadAndApply(handler)
                    : retrievalMethod.LocalApply(localPath, handler);
            }
        }
Exemplo n.º 14
0
        private void OnInstaller()
        {
            if (checkLocalCopy.Checked)
            {
                _installerCapture.SetLocal(textBoxDownloadUrl.Uri !, textBoxLocalPath.Text);
            }
            else
            {
                using var handler = new DialogTaskHandler(this);
                _installerCapture.Download(textBoxDownloadUrl.Uri !, handler);
            }

            pageDownload.NextPage = pageIstallerCaptureStart;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Signs a number of <see cref="Feed"/>s with a single <see cref="OpenPgpSecretKey"/>.
        /// </summary>
        /// <param name="secretKey">The private key to use for signing the files.</param>
        /// <param name="passphrase">The passphrase to use to unlock the key.</param>
        /// <exception cref="IOException">The feed file could not be read or written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to the feed file is not permitted.</exception>
        private void SignFiles(OpenPgpSecretKey secretKey, string passphrase)
        {
            var task = ForEachTask.Create("Signing feeds", _files, file =>
            {
                SignedFeed signedFeed;
                try
                {
                    signedFeed = SignedFeed.Load(file.FullName);
                }
                #region Error handling
                catch (UnauthorizedAccessException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (InvalidDataException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message + (ex.InnerException == null ? "" : Environment.NewLine + ex.InnerException.Message), ex);
                }
                #endregion

                signedFeed.SecretKey = secretKey;
                try
                {
                    signedFeed.Save(file.FullName, passphrase);
                }
                #region Error handling
                catch (UnauthorizedAccessException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (KeyNotFoundException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                catch (WrongPassphraseException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                #endregion
            });

            using (var handler = new DialogTaskHandler(this)) handler.RunTask(task);
            Msg.Inform(this, "Successfully signed files.", MsgSeverity.Info);
        }
Exemplo n.º 16
0
        private void AddCatalogSource(string input)
        {
            try
            {
                var uri = new FeedUri(input);
                if (listBoxCatalogSources.Items.Contains(uri))
                {
                    return;
                }

                using (var handler = new DialogTaskHandler(this))
                {
                    var services = new ServiceLocator(handler);
                    services.CatalogManager.DownloadCatalog(uri);
                }
                listBoxCatalogSources.Items.Add(uri);

                // Trusted keys may have changed as a side-effect
                LoadTrust();
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            catch (WebException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            catch (SignatureException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            catch (InvalidDataException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion
        }
Exemplo n.º 17
0
 private void OnSingleFile()
 {
     Retrieve(
         new SingleFile {
         Href = textBoxDownloadUrl.Uri
     },
         checkLocalCopy.Checked ? textBoxLocalPath.Text : null);
     _feedBuilder.ImplementationDirectory = _feedBuilder.TemporaryDirectory !;
     using (var handler = new DialogTaskHandler(this))
     {
         _feedBuilder.DetectCandidates(handler);
         _feedBuilder.GenerateDigest(handler);
     }
     if (_feedBuilder.MainCandidate == null)
     {
         throw new NotSupportedException(Resources.NoEntryPointsFound);
     }
     else
     {
         pageDownload.NextPage = pageDetails;
     }
 }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public ContextMenu GetContextMenu()
        {
            var menu = new List <MenuItem>();

            var storeNode = BackingNode as StoreNode;

            if (storeNode != null)
            {
                if (storeNode.Path != null)
                {
                    menu.Add(new MenuItem(Resources.OpenInFileManager, delegate { ProcessUtils.Start(storeNode.Path); }));
                }

                var implementationNode = storeNode as ImplementationNode;
                if (implementationNode != null)
                {
                    using (var handler = new DialogTaskHandler(_manageForm))
                    {
                        menu.Add(new MenuItem(Resources.Verify, delegate
                        {
                            try
                            {
                                implementationNode.Verify(handler);
                            }
                            #region Error handling
                            catch (OperationCanceledException)
                            {}
                            catch (IOException ex)
                            {
                                Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                            }
                            catch (UnauthorizedAccessException ex)
                            {
                                Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                            }
                            #endregion

                            _manageForm.RefreshList();
                        }));
                    }
                }
            }

            menu.Add(new MenuItem(Resources.Remove, delegate
            {
                using (var handler = new DialogTaskHandler(_manageForm))
                {
                    if (handler.Ask(Resources.DeleteEntry))
                    {
                        try
                        {
                            handler.RunTask(new SimpleTask(Resources.DeletingImplementations, () => BackingNode.Delete(handler)));
                        }
                        #region Error handling
                        catch (KeyNotFoundException ex)
                        {
                            Msg.Inform(null, ex.Message, MsgSeverity.Error);
                        }
                        catch (IOException ex)
                        {
                            Msg.Inform(null, ex.Message, MsgSeverity.Error);
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            Msg.Inform(null, ex.Message, MsgSeverity.Error);
                        }
                        #endregion

                        _manageForm.RefreshList();
                    }
                }
            }));

            return(new ContextMenu(menu.ToArray()));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Adds a feed to the list of custom feeds.
        /// </summary>
        private void AddCustomFeed(string input)
        {
            FeedUri feedUri;

            try
            {
                feedUri = new FeedUri(input);
            }
            catch (UriFormatException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
                return;
            }

            if (_interfaceUri.IsFile)
            {
                if (!File.Exists(_interfaceUri.LocalPath))
                {
                    Msg.Inform(this, string.Format(Resources.FileOrDirNotFound, _interfaceUri.LocalPath), MsgSeverity.Warn);
                    return;
                }
            }
            else
            {
                Feed feed = null;
                try
                {
                    using (var handler = new DialogTaskHandler(this))
                    {
                        handler.RunTask(new SimpleTask(Resources.CheckingFeed,
                                                       delegate
                        {
                            using (var webClient = new WebClientTimeout())
                                feed = XmlStorage.FromXmlString <Feed>(webClient.DownloadString(feedUri));
                        }));
                    }
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    return;
                }
                catch (IOException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (InvalidDataException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (WebException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                catch (UnauthorizedAccessException ex)
                {
                    Msg.Inform(this, ex.Message, MsgSeverity.Error);
                    return;
                }
                #endregion

                // Ensure a matching <feed-for> is present for online feeds
                if (feed.FeedFor.All(entry => entry.Target != _interfaceUri))
                {
                    if (!Msg.YesNo(this, Resources.IgnoreMissingFeedFor, MsgSeverity.Warn))
                    {
                        return;
                    }
                }
            }

            var reference = new FeedReference {
                Source = feedUri
            };
            if (_interfacePreferences.Feeds.Contains(reference))
            {
                return;
            }
            _interfacePreferences.Feeds.Add(reference);
            listBoxFeeds.Items.Add(reference);
        }