Ejemplo n.º 1
0
        private void OnlineModBuildAction(PendingChangeBase.PendingAction pendingAction)
        {
            if (_selectedOnlineMod == null)
            {
                MessageBox.Show("Please select a mod beforehand");
                return;
            }
            if (_selectedOnlineModReleaseIdx == -1)
            {
                MessageBox.Show("Please specify a release version.");
                return;
            }
            switch (pendingAction)
            {
            case PendingChangeBase.PendingAction.Download:
                PendingChanges.AddDownload(_selectedOnlineMod, _selectedOnlineModReleaseIdx, _localModManager.GetDownloadPath(_selectedOnlineMod, _selectedOnlineModReleaseIdx));
                break;

            case PendingChangeBase.PendingAction.Install:

                PendingChanges.AddDownload(_selectedOnlineMod, _selectedOnlineModReleaseIdx, _localModManager.GetDownloadPath(_selectedOnlineMod, _selectedOnlineModReleaseIdx));
                PendingChanges.AddInstall(_selectedOnlineMod, _localModManager.GetDownloadPath(_selectedOnlineMod, _selectedOnlineModReleaseIdx));
                break;

            case PendingChangeBase.PendingAction.Uninstall:
                PendingChanges.AddUninstall(_selectedOnlineMod);
                break;

            case PendingChangeBase.PendingAction.Update:
                PendingChanges.AddDownload(_selectedOnlineMod, _selectedOnlineModReleaseIdx, _localModManager.GetDownloadPath(_selectedOnlineMod, _selectedOnlineModReleaseIdx));
                PendingChanges.AddUninstall(_selectedOnlineMod);
                PendingChanges.AddInstall(_selectedOnlineMod, _localModManager.GetDownloadPath(_selectedOnlineMod, _selectedOnlineModReleaseIdx));
                break;
            }
        }
        private void FillServerSyncResult(ServerInfo si)
        {
            lstServerSyncMods.Enabled = btnServerSyncSyncToLocal.Enabled = false;
            foreach (ServerInfo.ServerModInfo modinfo in si.ActiveMods)
            {
                LocalModManager.ModSyncState state = _localModManager.CompareToLocal(modinfo);
                lstServerSyncMods.Items.Add(new ListViewItem(new[] { modinfo.Name, modinfo.Version.ToString(3), state.ToString() }));

                int row = lstServerSyncMods.Items.Count - 1;
                int col = 3;

                FlowLayoutPanel btnHolder = new FlowLayoutPanel();
                if (state != LocalModManager.ModSyncState.Installed)
                {
                    string installBtnText = "";
                    switch (state)
                    {
                    case LocalModManager.ModSyncState.ServerOutdated:
                        installBtnText = "Downgrade";
                        break;

                    case LocalModManager.ModSyncState.LocalOutdated:
                        installBtnText = "Update";
                        break;

                    case LocalModManager.ModSyncState.NotInstalled:
                        installBtnText = "Install";
                        break;
                    }
                    Button installBtn = new Button {
                        Text = installBtnText
                    };
                    installBtn.Click += (sender, e) =>
                    {
                        #region install btn event

                        if (modinfo.Name.ToLower() == "base")
                        {
                            MessageBox.Show("The base mod can not be updated with the mod manager. Please update the game and retry.");
                            return;
                        }

                        if (!_onlineModManager.SyncDone)
                        {
                            MessageBox.Show("Before you can use this feature please enable the online feature. Please try again after the sync is done.");
                            return;
                        }

                        //this step would be unnecessary as it is implied by FindReleaseInfoByNameAndVersion
                        //still it's here just for informing the user about the real failed case, if any
                        ModInfo mod = _onlineModManager.FindModByName(modinfo.Name);
                        if (mod == null)
                        {
                            //the online mod manager didn't find the mod. most likely it's not available.
                            MessageBox.Show("We couldn't find the mod on factoriomods.com. We can't install this one. Please ask the server admin to provide you with a copy.");
                            return;
                        }

                        ModInfo.ReleaseInfo?ri = _onlineModManager.FindReleaseInfoByNameAndVersion(modinfo.Name, modinfo.Version);
                        if (!ri.HasValue)
                        {
                            //the online mod manager found the mod but not the requested release. can be many cases why.
                            MessageBox.Show("We found the mod on factoriomods.com but not the requested release version. We are not able to install. Please ask the server admin to provide you with a copy.");
                            return;
                        }

                        //if we are here the checks are complete and ri has value.
                        string tmpDownloadName = _localModManager.GetDownloadPath(mod, _selectedOnlineModReleaseIdx);
                        PendingChanges.AddDownload(mod, mod.Releases.IndexOf(ri.Value), tmpDownloadName);
                        PendingChanges.AddInstall(mod, tmpDownloadName);
                        #endregion
                    };
                    if (modinfo.Name.ToLower() == "base")
                    {
                        installBtn.BackColor = Color.DarkGray;
                    }
                    btnHolder.Controls.Add(MakeButtonCompatible(installBtn));
                }
                if (modinfo.Name.ToLower() != "base")
                {
                    Button downloadBtn = new Button {
                        Text = "Download"
                    };
                    downloadBtn.Click += (sender, e) => { }; //TODO
                    Button browseBtn = new Button {
                        Text = "Show on web"
                    };
                    browseBtn.Click += (sender, e) => { }; //TODO
                    btnHolder.Controls.Add(MakeButtonCompatible(downloadBtn));
                    btnHolder.Controls.Add(MakeButtonCompatible(browseBtn));
                }
                lstServerSyncMods.AddEmbeddedControl(btnHolder, col, row);
                ResizeServerSyncList();
            }
            lstServerSyncMods.Enabled = btnServerSyncSyncToLocal.Enabled = true;
        }