public static bool TryCreateModToSync(ModMetaData mod, out ModToSync modToSync) { if (mod.OnSteamWorkshop || mod.IsCoreMod) { modToSync = null; return(false); } ModSyncInfo info = null; IHost host = null; string f = mod.RootDir + "/About/ModSync.xml"; if (File.Exists(f)) { try { XmlDocument xml = new XmlDocument(); xml.Load(f); if (ReadModSync(xml, mod.Name, out info, out host)) { modToSync = new ModToSync(mod, info); modToSync.Host = host; return(true); } } catch { } } f = mod.RootDir + "/About/Version.xml"; if (File.Exists(f)) { try { XmlDocument xml = new XmlDocument(); xml.Load(f); if (ReadVersion(xml, mod.Name, out info, out host)) { modToSync = new ModToSync(mod, info); modToSync.Host = host; return(true); } } catch { } } modToSync = null; return(false); }
static void Postfix(Page_ModsConfig __instance, Rect rect) { ModMetaData selectedMod = __instance.selectedMod; if (Prefs.DevMode && selectedMod != null && !selectedMod.IsCoreMod && selectedMod.Source == ContentSource.LocalFolder) { Rect buttonRect = new Rect(580f, rect.height - 95f, 200f, 40f); ModToSync mod = null; if (File.Exists(selectedMod.RootDir + "/About/ModSync.xml")) { // Draw the "Update ModSync" button if (Widgets.ButtonText(buttonRect, "ModSync.UpdateModSyncFile".Translate())) { if (!ModToSyncFactory.TryCreateModToSync(selectedMod, out mod)) { mod = null; Log.Error("Could not open ModSync.xml file for [" + selectedMod.Name + "]"); } } } else // No ModSync.xml for the mod { if (Widgets.ButtonText(buttonRect, "ModSync.CreateModSyncFile".Translate())) { mod = new ModToSync(selectedMod, new ModSyncInfo(selectedMod.Name, "1.0.0.0")); } } if (mod != null) { string assemblyVersion = FileUtil.GetVersionFromDll(selectedMod); Dialog_CreateModSyncFile dialog = new Dialog_CreateModSyncFile(mod, assemblyVersion); Find.WindowStack.Add(dialog); } } }