예제 #1
0
        private object Generate(string action, IParkitect parkitect, Exception exception)
        {
            try
            {
                var os = OperatingSystem.Detect();
                switch (os)
                {
                case SupportedOperatingSystem.Windows:
                    return(new WindowsCrashReport(parkitect, action, exception, _log));

                case SupportedOperatingSystem.MacOSX:
                    return(new MacOSXCrashReport(parkitect, action, exception, _log));

                case SupportedOperatingSystem.Linux:
                    return(new LinuxCrashReport(parkitect, action, exception, _log));

                default:
                    throw new Exception("unsupported operating system " + os);
                }
            }
            catch (Exception e)
            {
                return(new FailedCrashReport(action, exception, e));
            }
        }
예제 #2
0
        protected virtual string GetUpdateVersionUrl()
        {
            switch (OperatingSystem.Detect())
            {
            case SupportedOperatingSystem.Windows:
                return(_website.ResolveUrl("update.json", "client"));

            case SupportedOperatingSystem.MacOSX:
                return(_website.ResolveUrl("update-osx.json", "client"));

            case SupportedOperatingSystem.Linux:
                throw new NotImplementedException();

            default:
                throw new Exception("unknown operating system");
            }
        }
예제 #3
0
        /// <summary>
        ///     Installs the specified update.
        /// </summary>
        /// <param name="update">The update.</param>
        /// <returns>true on success; false otherwise.</returns>
        public bool InstallUpdate(UpdateInfo update)
        {
            try
            {
                switch (OperatingSystem.Detect())
                {
                case SupportedOperatingSystem.Windows:
                {
                    var tempPath = Path.Combine(Path.GetTempPath(), "pncsetup.msi");

                    using (var webClient = _webClientFactory.CreateWebClient(true))
                    {
                        webClient.DownloadFile(update.DownloadUrl, tempPath);
                        Process.Start(tempPath);
                    }
                    break;
                }

                case SupportedOperatingSystem.MacOSX:
                {
                    var targetFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                                    "Downloads");

                    if (!Directory.Exists(targetFolder))
                    {
                        targetFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                                    "Documents");
                    }

                    if (!Directory.Exists(targetFolder))
                    {
                        targetFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                    }

                    if (!Directory.Exists(targetFolder))
                    {
                        return(false);
                    }

                    var tempPath = Path.Combine(targetFolder,
                                                $"parkitectnexus-client-{update.Version}-{RandomString(6)}.dmg");

                    using (var webClient = _webClientFactory.CreateWebClient())
                    {
                        webClient.DownloadFile(update.DownloadUrl, tempPath);

                        Process.Start(new ProcessStartInfo(
                                          "hdiutil",
                                          "attach \"" + tempPath + "\"")
                            {
                                UseShellExecute = false
                            });
                    }
                    break;
                }

                case SupportedOperatingSystem.Linux:
                    throw new NotImplementedException();

                default:
                    throw new Exception("unknown operating system");
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        ///     Checks for available updates.
        /// </summary>
        /// <returns>Information about the available update.</returns>
        public UpdateInfo CheckForUpdates <TEntryPoint>()
        {
            var currentVersion = typeof(TEntryPoint).Assembly.GetName().Version;

            try
            {
                _log.WriteLine(
                    $"Checking for client updates... Currently on version v{currentVersion}-{OperatingSystem.Detect()}.");

                using (var webClient = _webClientFactory.CreateWebClient(true))
                    using (var stream = webClient.OpenRead(GetUpdateVersionUrl()))
                        using (var streamReader = new StreamReader(stream))
                            using (var jsonTextReader = new JsonTextReader(streamReader))
                            {
                                var serializer = new JsonSerializer();
                                var updateInfo = (UpdateInfo)serializer.Deserialize(jsonTextReader, typeof(UpdateInfo));

                                if (updateInfo != null)
                                {
                                    var newestVersion = new Version(updateInfo.Version);

                                    _log.WriteLine($"Server reported newest version is v{updateInfo.Version}.");
                                    if (newestVersion > currentVersion)
                                    {
                                        _log.WriteLine($"Found newer version v{newestVersion}.");
                                        return(updateInfo);
                                    }
                                }
                            }
            }
            catch (Exception e)
            {
                //TODO: hotfix to avoid the application from crashing
                try{
                    _log.WriteLine(GetUpdateVersionUrl());
                    _log.WriteLine("Failed to check for updates");
                    _log.WriteException(e);
                }
                catch (Exception ex)
                {
                    _log.WriteException(ex);
                }
            }

            return(null);
        }
예제 #5
0
        private IEnumerable <Tile> LoadTiles()
        {
            yield return(CreateTile("Visit ParkitectNexus", App.DImages["parkitectnexus_logo-64x64.png"],
                                    Color.FromBytes(0xf3, 0x77, 0x35), _website.Launch));

            if (OperatingSystem.Detect() == SupportedOperatingSystem.Linux)
            {
                yield return
                    (CreateTile("Download URL", App.DImages["appbar.browser.wire.png"], Color.FromBytes(0xf3, 0x77, 0x35),
                                () =>
                {
                    var entry = new TextEntry();

                    var box = new HBox();
                    box.PackStart(new Label("URL:"));
                    box.PackStart(entry, true, true);

                    var dialog = new Dialog
                    {
                        Width = 300,
                        Icon = ParentWindow.Icon,
                        Title = "Enter URL to download",
                        Content = box
                    };
                    dialog.Buttons.Add(new DialogButton(Command.Cancel));
                    dialog.Buttons.Add(new DialogButton(Command.Ok));


                    var result = dialog.Run(ParentWindow);

                    NexusUrl url;
                    if (result.Label.ToLower() == "ok" && NexusUrl.TryParse(entry.Text, out url))
                    {
                        ObjectFactory.GetInstance <IApp>().HandleUrl(url);
                    }
                    dialog.Dispose();
                }));
            }

            yield return
                (CreateTile("Launch Parkitect", App.DImages["parkitect_logo.png"], Color.FromBytes(45, 137, 239),
                            () => { _parkitect.Launch(); }));

            yield return(CreateTile("Help", App.DImages["appbar.information.png"], Color.FromBytes(45, 137, 239), () =>
            {
                // Temporary help solution.
                Process.Start(
                    "https://parkitectnexus.com/forum/2/parkitectnexus-website-client/70/troubleshooting-mods-and-client");
            }));

            yield return(CreateTile("Donate!", App.DImages["appbar.thumbs.up.png"], Color.FromBytes(45, 137, 239), () =>
            {
                if (MessageDialog.AskQuestion("Maintaining this client and adding new features takes a lot of time.\n" +
                                              "If you appreciate our work, please consider sending a donation our way!\n" +
                                              "All donations will be used for further development of the ParkitectNexus Client and the website.\n" +
                                              "\nSelect Yes to visit PayPal and send a donation.", 1, Command.No,
                                              Command.Yes) == Command.Yes)
                {
                    Process.Start("https://paypal.me/ikkentim");
                }
            }));
        }