Beispiel #1
0
    public static void UpdatePreset(PresetConfig config, bool dryRun)
    {
        if (!new DirectoryInfo(config.DestinationPath).Exists)
        {
            throw new FileNotFoundException($"Folder {config.DestinationPath} doesn't exist");
        }

        var modUpdates = new List <ModUpdatePaths>();

        foreach (var modName in config.ModList)
        {
            var sourcePath      = new DirectoryInfo(Path.Combine(config.SourcePath, modName));
            var destinationPath = new DirectoryInfo(Path.Combine(config.DestinationPath, modName));

            if (!sourcePath.Exists)
            {
                throw new DirectoryNotFoundException($"Directory {sourcePath} does not exist");
            }

            if (!destinationPath.Exists)
            {
                if (dryRun)
                {
                    Console.WriteLine($"Would create folder {destinationPath}");
                }
                else
                {
                    destinationPath.Create();
                }
            }

            modUpdates.Add(new ModUpdatePaths(sourcePath, destinationPath));
        }

        foreach (var(sourcePath, destinationPath) in modUpdates)
        {
            ModUpdater.UpdateMod(sourcePath, destinationPath, dryRun, config.ZsyncThreads);
        }

        var serverFile     = BuildServerFile(config);
        var serverFileJson = JsonConvert.SerializeObject(serverFile, Formatting.Indented);
        var serverFilePath = Path.Combine(config.DestinationPath, config.ServerFileName);

        if (dryRun)
        {
            Console.WriteLine($"Would write {serverFilePath}");
        }
        else
        {
            File.WriteAllText(serverFilePath, serverFileJson);
        }
    }
        private void cbAvailableMods_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = GetCurrentId();

            _currentSelectedIndex = Settings.installedMods.FindIndex(f => f.Id == id);

            if (_currentSelectedIndex >= 0)
            {
                btnDeleteMod.Enabled = true;
                btnStartMod.Enabled  = true;
                string text = Settings.installedMods[_currentSelectedIndex].Description.Replace("§", Environment.NewLine);
                txtModDescription.Text = text;

                if (!String.IsNullOrEmpty(Settings.installedMods[_currentSelectedIndex].Preview_url))
                {
                    try
                    {
                        pbModPreview.Load(Settings.installedMods[_currentSelectedIndex].Preview_url);
                    }
                    catch (Exception)
                    {
                        pbModPreview.Image = Properties.Resources.nopreview;
                    }
                }
                else
                {
                    pbModPreview.Image = Properties.Resources.nopreview;
                }

                if (ModUpdater.availableMods[id].Github && Settings.checkModUpdates)
                {
                    if (ModUpdater.CheckForModUpdates(ModUpdater.availableMods[id].Id))
                    {
                        lblUpdate.Visible = true;
                    }
                    else
                    {
                        lblUpdate.Visible = false;
                    }
                }
                else
                {
                    lblUpdate.Visible = false;
                }
            }
        }
Beispiel #3
0
        private void cbAvailableMods_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = GetCurrentId();

            string text = ModUpdater.availableMods[id].Description.Replace("§", Environment.NewLine);

            lblAuthorName.Text     = ModUpdater.availableMods[id].Author;
            txtModDescription.Text = text;
            if (!String.IsNullOrEmpty(ModUpdater.availableMods[id].Preview_url))
            {
                try
                {
                    pbModPreview.Load(ModUpdater.availableMods[id].Preview_url);
                }
                catch (Exception)
                {
                    pbModPreview.Image = Properties.Resources.nopreview;
                }
            }
            else
            {
                pbModPreview.Image = Properties.Resources.nopreview;
            }

            if (ModUpdater.availableMods[id].Github && Settings.checkModUpdates)
            {
                if (ModUpdater.CheckForModUpdates(ModUpdater.availableMods[id].Id))
                {
                    _updateMod = true;

                    btnInstallMod.BackColor = Utils.btnHighlightColor;
                    btnInstallMod.Text      = "Update";
                    btnInstallMod.IconChar  = IconChar.SyncAlt;
                }
                else
                {
                    ResetInstallButton();
                }
            }
            else
            {
                ResetInstallButton();
            }
        }