private void SetModState(ModInfoHolder modInfo, ModInfoHolder.ModState newState) { if (newState == modInfo.State) { return; } //if (modInfo.State == ModInfoHolder.ModState.Disabled) //{ // SetLocalModDisabled(ref modInfo.FilePath, false); //} modInfo.State = newState; ModListStoreLocal.SetValue(modInfo.TreeIter, (int)TreeColumnInfo.State, newState == ModInfoHolder.ModState.Enabled); //if (newState == ModInfoHolder.ModState.Disabled) //{ // SetLocalModDisabled(ref modInfo.FilePath, true); // Log("Relocated " + modInfo.FancyName()); // return; //} modInfo.EditModJson("Enable", modInfo.State == ModInfoHolder.ModState.Enabled); if (newState == ModInfoHolder.ModState.Enabled) { Log("Activated " + modInfo.FancyName() + (EnableDependencies(modInfo) ? " and dependencies" : "")); } else if (newState == ModInfoHolder.ModState.Inactive) { Log("Deactivated " + modInfo.FancyName()); } }
protected void TryDownloadAllModUpdates(object sender, EventArgs e) { foreach (var localMod in ModInfoTools.LocalMods) { if (localMod.Value.CloudName != null) { ModInfoHolder cloudModInfo = null; if (localMod.Value.FoundOther == 0) { bool flag = true; try { var repoItem = GetRepos.GetOneRepo(localMod.Value.CloudName); if (ModInfoTools.GetGithubMod(repoItem)) { cloudModInfo = ModInfoTools.lastGithubMod; flag = false; } } catch (Exception E) { Console.WriteLine(E); } if (flag) { localMod.Value.FoundOther = -1; } } if (cloudModInfo != null || ModInfoTools.GithubMods.TryGetValue(localMod.Value.CloudName, out cloudModInfo)) { if (localMod.Value.CurrentVersion == cloudModInfo.CurrentVersion) { continue; } //if (localMod.Value.State == ModInfo.ModState.Disabled) //{ // Log("Can't update a disabled mod! (" + localMod.Value.Name + ")", Color.OrangeRed); // continue; //} if (ModDownloader.AddModDownload(cloudModInfo, ModListStoreGithub)) { ModListStoreLocal.SetValue(localMod.Value.TreeIter, (int)TreeColumnInfo.Desc, "Updating..."); } continue; } } } }
//internal void SetLocalModDisabled(ref string path, bool Disable) //{ // string newPath = ModInfoTools.RootFolder + @"/QMods" + (Disable ? @"-Disabled/" : @"/") + new System.IO.DirectoryInfo(path).Name; // System.IO.Directory.Move(path, newPath); // path = newPath; //} private bool EnableDependencies(ModInfoHolder mod) { bool result = false; foreach (string dependency in mod.RequiredModNames) { if (ModInfoTools.LocalMods.TryGetValue(dependency.Substring(dependency.LastIndexOf('/') + 1), out ModInfoHolder modDependency)) { if (modDependency.State != ModInfoHolder.ModState.Enabled) { SetModState(modDependency, ModInfoHolder.ModState.Enabled); result = true; } } } return(result); }
private void UpdateModInfoUI(ModInfoHolder modInfo) { labelModTitle.Markup = "<b>" + modInfo.FancyName() + "</b>"; labelModLink.Text = modInfo.Site; labelModDesc.Text = modInfo.InlineDescription; if (TabPagerMods.CurrentPage == 0) { comboboxModState.Visible = true; buttonModDownload.Label = "Update"; buttonModRemove.Visible = true; comboboxModState.Active = (int)modInfo.State; } else { comboboxModState.Visible = false; buttonModDownload.Label = "Download"; buttonModRemove.Visible = false; } }
public void DownloadMod(ModInfoHolder ModRef, int TabPage) { if (TabPage != 0) // Is a server tab { if (ModRef.FoundOther == 1) { var localMod = ModInfoTools.LocalMods[ModRef.Name]; //if (localMod.State == ModInfoHolder.ModState.Disabled) //{ // Log("Can't update a disabled mod!"); // return; //} if (ModDownloader.AddModDownload(ModRef, ModListStoreGithub)) { ModListStoreLocal.SetValue(localMod.TreeIter, (int)TreeColumnInfo.Desc, "Updating..."); } return; } ModDownloader.AddModDownload(ModRef, ModListStoreGithub); return; } if (!string.IsNullOrEmpty(ModRef.CloudName)) { ModInfoHolder cloudModInfo = null; if (ModRef.FoundOther == 0) { bool flag = true; try { var repoItem = GetRepos.GetOneRepo(ModRef.CloudName); if (ModInfoTools.GetGithubMod(repoItem)) { cloudModInfo = ModInfoTools.lastGithubMod; flag = false; } } catch (Exception E) { Console.WriteLine(E); } if (flag) { Log("Could not locate server mod!"); ModRef.FoundOther = -1; return; } } if (cloudModInfo != null || ModInfoTools.GithubMods.TryGetValue(ModRef.CloudName, out cloudModInfo)) { //if (modInfo.State == ModInfoHolder.ModState.Disabled) //{ // Log("Can't update a disabled mod!"); // return; //} if (ModDownloader.AddModDownload(cloudModInfo, ModListStoreGithub)) { ModListStoreLocal.SetValue(ModRef.TreeIter, (int)TreeColumnInfo.Desc, "Updating..."); return; } } } Log("Can't download mod!"); }