Exemplo n.º 1
0
        protected override void PopulateViewBoxWithButtons(VBox vBox, IAsset asset)
        {
            var mod = asset as IModAsset;

            var viewOnWebsiteButton = new Button("View on ParkitectNexus")
            {
                Sensitive = !mod.Information.IsDevelopment
            };

            if (!mod.Information.IsDevelopment)
            {
                viewOnWebsiteButton.Clicked +=
                    (sender, args) => { Process.Start(_website.ResolveUrl($"redirect/{mod.Repository}", "client")); }
            }
            ;

            var recompileButton = new Button("Recompile");

            recompileButton.Clicked += (sender, args) =>
            {
                _queueableTaskManager.With(mod).Add <CompileModTask>();
                MainView.SwitchToTab <TasksPageView>();
            };

            var updateButton = new Button("Update")
            {
                Sensitive = !mod.Information.IsDevelopment
            };

            if (!mod.Information.IsDevelopment)
            {
                updateButton.Clicked += (sender, args) =>
                {
                    _queueableTaskManager.With(mod).Add <UpdateModTask>();
                }
            }
            ;

            var utils = new HBox();

            utils.PackStart(recompileButton, true);
            utils.PackStart(updateButton, true);

            vBox.PackStart(viewOnWebsiteButton);
            vBox.PackStart(utils);

            base.PopulateViewBoxWithButtons(vBox, asset);
        }

        #endregion
    }
}
Exemplo n.º 2
0
        public override async Task Run(CancellationToken token)
        {
            var count = 0;

            UpdateStatus("Gathering information...", 0, TaskStatus.Running);

            foreach (var required in await _website.API.GetRequiredModIdentifiers())
            {
                if (_parkitect.Assets[AssetType.Mod].All(m => m.Id != required))
                {
                    // Create install task for the dependency.
                    var installDependencyTask = ObjectFactory.GetInstance <InstallAssetTask>();
                    installDependencyTask.Data = new InstallUrlAction(required);

                    // Insert the install task in the queueable task manager.
                    _queueableTaskManager.Add(installDependencyTask);
                }
            }

            var mods = _parkitect.Assets[AssetType.Mod].OfType <IModAsset>().ToArray();

            for (var index = 0; index < mods.Length; index++)
            {
                var mod = mods[index];
                if (mod.Information.IsDevelopment || mod.Id == null)
                {
                    continue;
                }

                UpdateStatus($"{index + 1}/{mods.Length}: Checking mod: {mod.Name}...", (int)(index * (100.0f / mods.Length)), TaskStatus.Running);

                try
                {
                    var info = await _website.API.GetAsset(mod.Id);

                    if (mod.Tag != info.Resource.Data.Version)
                    {
                        _queueableTaskManager.With(mod).Add <UpdateModTask>();
                        count++;
                    }
                }
                catch (Exception e)
                {
                    _log.WriteLine("Failed to gather mod info: " + e.Message);
                }
            }

            UpdateStatus($"Found {count} available updates.", 100, TaskStatus.Finished);
        }
Exemplo n.º 3
0
        public override async Task Run(CancellationToken token)
        {
            try
            {
                // Cast the data instance to InstallUrlAction.
                var data = Data as InstallUrlAction;
                if (data == null)
                {
                    UpdateStatus("Invalid URL supplied.", 100, TaskStatus.Canceled);
                    return;
                }

                // Fetch asset information from the PN API.
                UpdateStatus("Fetching asset information...", 0, TaskStatus.Running);

                var assetData = await _website.API.GetAsset(data.Id);

                if (assetData.Type == AssetType.Mod && assetData.Resource.Data.Version == null)
                {
                    UpdateStatus($"The '{assetData.Name}' mod has not yet been released! Ask the author to release it.", 100, TaskStatus.Canceled);
                    return;
                }

                // Download the asset trough the RemoveAssetRepository.
                UpdateStatus($"Installing {assetData.Type.ToString().ToLower()} '{assetData.Name}'...", 15,
                             TaskStatus.Running);

                var downloadedAsset = await _remoteAssetRepository.DownloadAsset(assetData);

                // Store the asset in in the appropriate location.
                var asset = await _parkitect.Assets.StoreAsset(downloadedAsset);

                // If the downloaded asset is a mod, add a "compile mod" task to the queue.
                var modAsset = asset as IModAsset;
                if (modAsset != null)
                {
                    _queueableTaskManager.With(modAsset).InsertAfter <CompileModTask>(this);
                }

                // Ensure dependencies have been installed.
                foreach (var dependency in assetData.Dependencies.Data)
                {
//                    if (!dependency.Required && !InstallOptionalDependencies)
//                        continue;

                    if (_parkitect.Assets.Any(a => a.Id == dependency.Id))
                    {
                        continue;
                    }

                    // Create install task for the dependency.
                    var installDependencyTask = ObjectFactory.GetInstance <InstallAssetTask>();
                    installDependencyTask.Data = new InstallUrlAction(dependency.Id);

                    // Insert the install task in the queueable task manager.
                    _queueableTaskManager.InsertAfter(installDependencyTask, this);
                }


                // Update the status of the task.
                UpdateStatus($"Installed {assetData.Type.ToString().ToLower()} '{assetData.Name}'.", 100,
                             TaskStatus.Finished);
            }
            catch (Exception e)
            {
                UpdateStatus($"Installation failed. {e.Message}", 100, TaskStatus.FinishedWithErrors);
            }
        }