Inheritance: Terraria.GameContent.UI.Elements.UIPanel
Ejemplo n.º 1
0
        //public override void Update(GameTime gameTime)
        //{
        //	if (modsToDownload == null || modsToDownload.Count == 0)
        //		Main.menuMode = Interface.modBrowserID;
        //}

        private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            //Main.menuMode = Interface.modBrowserID;
            if (e.Error != null)
            {
                if (e.Cancelled)
                {
                    Interface.modBrowser.ClearItems();
                    Main.menuMode = Interface.modBrowserID;
                }
                else
                {
                    var errorKey = GetHttpStatusCode(e.Error) == HttpStatusCode.ServiceUnavailable ? "MBExceededBandwidth" : "MBUnknownMBError";
                    Interface.errorMessage.Show(Language.GetTextValue("tModLoader." + errorKey), 0);
                }
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
            }
            else if (!e.Cancelled)
            {
                // Downloaded OK
                File.Copy(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod", ModLoader.ModPath + Path.DirectorySeparatorChar + currentDownload.mod + ".tmod", true);
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
                if (!currentDownload.update)
                {
                    Interface.modBrowser.aNewModDownloaded = true;
                }
                else
                {
                    Interface.modBrowser.aModUpdated = true;
                }
                if (ModLoader.autoReloadAndEnableModsLeavingModBrowser)
                {
                    ModLoader.EnableMod(currentDownload.mod);
                }

                // Start next download
                if (modsToDownload.Count != 0)
                {
                    currentDownload = modsToDownload.Dequeue();
                    loadProgress.SetText(Language.GetTextValue("tModLoader.MBDownloadingMod", $"{name}: {currentDownload.displayname}"));
                    loadProgress.SetProgress(0f);
                    client.DownloadFileAsync(new Uri(currentDownload.download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
                }
                else
                {
                    client.Dispose();
                    client = null;
                    Interface.modBrowser.ClearItems();
                    Main.menuMode = Interface.modBrowserID;
                    if (missingMods.Count > 0)
                    {
                        Interface.infoMessage.Show(Language.GetTextValue("tModLoader.MBModsNotFoundOnline", String.Join(",", missingMods)), Interface.modsMenuID);
                    }
                }
            }
            else
            {
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
            }
        }
Ejemplo n.º 2
0
 public override void OnActivate()
 {
     loadProgress.SetText(Language.GetTextValue("tModLoader.MBDownloadingMod", name + ": ???"));
     loadProgress.SetProgress(0f);
     if (UIModBrowser.PlatformSupportsTls12)                                 // Needed for downloads from Github
     {
         ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
     }
     if (modsToDownload != null && modsToDownload.Count > 0)
     {
         client = new WebClient();
         ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); });
         SetCancel(client.CancelAsync);
         client.DownloadProgressChanged += Client_DownloadProgressChanged;
         client.DownloadFileCompleted   += Client_DownloadFileCompleted;
         currentDownload = modsToDownload.Dequeue();
         loadProgress.SetText(Language.GetTextValue("tModLoader.MBDownloadingMod", $"{name}: {currentDownload.displayname}"));
         client.DownloadFileAsync(new Uri(currentDownload.download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
     }
     else
     {
         Interface.modBrowser.ClearItems();
         Main.menuMode = Interface.modBrowserID;
         if (missingMods.Count > 0)
         {
             Interface.infoMessage.SetMessage(Language.GetTextValue("tModLoader.MBModsNotFoundOnline", String.Join(",", missingMods)));
             Interface.infoMessage.SetGotoMenu(Interface.modBrowserID);
             Main.menuMode = Interface.infoMessageID;
         }
     }
 }
Ejemplo n.º 3
0
        public override void OnActivate()
        {
            loadProgress.SetText($"Downloading: {name}: ???");
            loadProgress.SetProgress(0f);

            if (modsToDownload != null && modsToDownload.Count > 0)
            {
                client = new WebClient();
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); });
                SetCancel(client.CancelAsync);
                client.DownloadProgressChanged += Client_DownloadProgressChanged;
                client.DownloadFileCompleted   += Client_DownloadFileCompleted;
                currentDownload = modsToDownload.Dequeue();
                loadProgress.SetText($"Downloading: {name}: {currentDownload.displayname}");
                client.DownloadFileAsync(new Uri(currentDownload.download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
            }
            else
            {
                Interface.modBrowser.ClearItems();
                Main.menuMode = Interface.modBrowserID;
                if (missingMods.Count > 0)
                {
                    Interface.infoMessage.SetMessage("The following mods were not found on the Mod Browser: " + String.Join(",", missingMods));
                    Interface.infoMessage.SetGotoMenu(Interface.modBrowserID);
                    Main.menuMode = Interface.infoMessageID;
                }
            }
        }
Ejemplo n.º 4
0
 private void PopulateFromJSON(List <BuildProperties> modBuildProperties, string json)
 {
     try
     {
         JObject jsonObject   = JObject.Parse(json);
         JObject updateObject = (JObject)jsonObject["update"];
         if (updateObject != null)
         {
             updateAvailable = true;
             updateText      = (string)updateObject["message"];
             updateURL       = (string)updateObject["url"];
         }
         JArray modlist = (JArray)jsonObject["modlist"];
         foreach (JObject mod in modlist.Children <JObject>())
         {
             string displayname = (string)mod["displayname"];
             string name        = (string)mod["name"];
             string version     = (string)mod["version"];
             string author      = (string)mod["author"];
             string download    = (string)mod["download"];
             int    downloads   = (int)mod["downloads"];
             string timeStamp   = (string)mod["updateTimeStamp"];
             bool   exists      = false;
             bool   update      = false;
             foreach (BuildProperties bp in modBuildProperties)
             {
                 if (bp.displayName.Equals(displayname))
                 {
                     exists = true;
                     if (!bp.version.Equals(new Version(version.Substring(1))))
                     {
                         update = true;
                     }
                 }
             }
             UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, download, downloads, timeStamp, update, exists);
             modListAll._items.Add(modItem);                     //add directly to the underlying, SortList will repopulate it anyway
         }
         SortList();
     }
     catch (Exception e)
     {
         ErrorLogger.LogModBrowserException(e);
         return;
     }
 }
Ejemplo n.º 5
0
 public override void OnActivate()
 {
     if (!loaded)
     {
         modList.Clear();
         TmodFile[] modFiles = ModLoader.FindMods();
         List<BuildProperties> modBuildProperties = new List<BuildProperties>();
         foreach (TmodFile tmodfile in modFiles)
         {
             modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile));
         }
         XmlDocument xmlDoc = new XmlDocument();
         try
         {
             xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php");
         }
         catch (WebException e)
         {
             if (e.Status == WebExceptionStatus.Timeout)
             {
                 uITextPanel.SetText("Mod Browser OFFLINE", 0.8f, true);
                 return;
             }
         }
         catch (Exception e)
         {
             ErrorLogger.LogModBrowserException(e);
             return;
         }
         foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
         {
             string displayname = xmlNode.SelectSingleNode("displayname").InnerText;
             string name = xmlNode.SelectSingleNode("name").InnerText;
             string version = xmlNode.SelectSingleNode("version").InnerText;
             string author = xmlNode.SelectSingleNode("author").InnerText;
             string description = xmlNode.SelectSingleNode("description").InnerText;
             string download = xmlNode.SelectSingleNode("download").InnerText;
             bool exists = false;
             bool update = false;
             foreach (BuildProperties bp in modBuildProperties)
             {
                 if (bp.displayName.Equals(displayname))
                 {
                     exists = true;
                     if (!bp.version.Equals(version))
                     {
                         update = true;
                     }
                 }
             }
             //   if (!exists || update)
             //   {
             UIModDownloadItem modItem = new UIModDownloadItem(/*this, */displayname, name, version, author, description, download, update, exists);
             modList.Add(modItem);
             //  }
         }
         loaded = true;
     }
 }
Ejemplo n.º 6
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string modIconURL, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, LocalMod installed)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.modIconURL        = modIconURL;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.installed         = installed;
            this.BorderColor       = new Color(89, 116, 213) * 0.7f;
            this.dividerTexture    = TextureManager.Load("Images/UI/Divider");
            this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground");
            this.Height.Set(90f, 0f);
            this.Width.Set(0f, 1f);
            base.SetPadding(6f);

            this.left = HasModIcon ? 85f : 0f;
            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(this.left + 5, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);

            moreInfoButton = new UIAutoScaleTextTextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false);
            moreInfoButton.Width.Set(100f, 0f);
            moreInfoButton.Height.Set(36f, 0f);
            moreInfoButton.Left.Set(this.left, 0f);
            moreInfoButton.Top.Set(40f, 0f);
            moreInfoButton.PaddingTop    -= 2f;
            moreInfoButton.PaddingBottom -= 2f;
            moreInfoButton.OnMouseOver   += UICommon.FadedMouseOver;
            moreInfoButton.OnMouseOut    += UICommon.FadedMouseOut;
            moreInfoButton.OnClick       += RequestMoreinfo;
            Append(moreInfoButton);

            if (update || installed == null)
            {
                updateButton = new UIAutoScaleTextTextPanel <string>(this.update ? (updateIsDowngrade ? Language.GetTextValue("tModLoader.MBDowngrade") : Language.GetTextValue("tModLoader.MBUpdate")) : Language.GetTextValue("tModLoader.MBDownload"), 1f,
                                                                     false);
                updateButton.CopyStyle(moreInfoButton);
                updateButton.Width.Set(HasModIcon ? 120f : 200f, 0f);
                updateButton.Left.Set(moreInfoButton.Width.Pixels + moreInfoButton.Left.Pixels + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                Texture2D icon = Texture2D.FromStream(Main.instance.GraphicsDevice,
                                                      Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.ButtonExclamation.png"));
                UIHoverImage modReferenceIcon = new UIHoverImage(icon, Language.GetTextValue("tModLoader.MBClickToViewDependencyMods", string.Join("\n", modreferences.Split(',').Select(x => x.Trim()))));
                modReferenceIcon.Left.Set(-149f, 1f);
                modReferenceIcon.Top.Set(48f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').Select(x => x.Trim()).ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = Language.GetTextValue("tModLoader.MBFilterDependencies");                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.updateNeeded = true;
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            OnDoubleClick += RequestMoreinfo;
        }
Ejemplo n.º 7
0
		public override void OnActivate()
		{
			Main.clrInput();
			if (!loaded)
			{
				uITextPanel.SetText("Mod Browser", 0.8f, true);
				modListAll.Clear();
				TmodFile[] modFiles = ModLoader.FindMods();
				List<BuildProperties> modBuildProperties = new List<BuildProperties>();
				foreach (TmodFile tmodfile in modFiles)
				{
					modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile));
				}
				XmlDocument xmlDoc = new XmlDocument();
				try
				{
					//	xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php");
					System.Net.ServicePointManager.Expect100Continue = false;
					string url = "http://javid.ddns.net/tModLoader/listmods.php";
					IO.UploadFile[] files = new IO.UploadFile[0];
					var values = new NameValueCollection
					{
						{ "modloaderversion", ModLoader.versionedName },
					};
					byte[] result = IO.UploadFile.UploadFiles(url, files, values);
					xmlDoc.LoadXml(System.Text.Encoding.UTF8.GetString(result, 0, result.Length));
				}
				catch (WebException e)
				{
					if (e.Status == WebExceptionStatus.Timeout)
					{
						uITextPanel.SetText("Mod Browser OFFLINE (Busy)", 0.8f, true);
						return;
					}
					if (e.Status == WebExceptionStatus.ProtocolError)
					{
						var resp = (HttpWebResponse)e.Response;
						if (resp.StatusCode == HttpStatusCode.NotFound)
						{
							uITextPanel.SetText("Mod Browser OFFLINE (404)", 0.8f, true);
							return;
						}
						uITextPanel.SetText("Mod Browser OFFLINE..", 0.8f, true);
						return;
					}
				}
				catch (Exception e)
				{
					ErrorLogger.LogModBrowserException(e);
					return;
				}
				try
				{
					foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
					{
						if (xmlNode.Name.Equals("update"))
						{
							updateAvailable = true;
							updateText = xmlNode.SelectSingleNode("message").InnerText;
							updateURL = xmlNode.SelectSingleNode("url").InnerText;
						}
						else if (xmlNode.Name.Equals("modlist"))
						{
							foreach (XmlNode xmlNode2 in xmlNode)
							{
								string displayname = xmlNode2.SelectSingleNode("displayname").InnerText;
								string name = xmlNode2.SelectSingleNode("name").InnerText;
								string version = xmlNode2.SelectSingleNode("version").InnerText;
								string author = xmlNode2.SelectSingleNode("author").InnerText;
								string description = xmlNode2.SelectSingleNode("description").InnerText;
								string homepage = xmlNode2.SelectSingleNode("homepage").InnerText;
								string download = xmlNode2.SelectSingleNode("download").InnerText;
								string timeStamp = xmlNode2.SelectSingleNode("updateTimeStamp").InnerText;
								int downloads;
								Int32.TryParse(xmlNode2.SelectSingleNode("downloads").InnerText, out downloads);
								bool exists = false;
								bool update = false;
								foreach (BuildProperties bp in modBuildProperties)
								{
									if (bp.displayName.Equals(displayname))
									{
										exists = true;
										if (!bp.version.Equals(new Version(version.Substring(1))))
										{
											update = true;
										}
									}
								}
								UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, description, homepage, download, downloads, timeStamp, update, exists);
								modListAll.Add(modItem);
							}
							SortList(null, null);
						}
					}
				}
				catch (Exception e)
				{
					ErrorLogger.LogModBrowserException(e);
					return;
				}
				loaded = true;
			}
		}
Ejemplo n.º 8
0
        //public override void Update(GameTime gameTime)
        //{
        //	if (modsToDownload == null || modsToDownload.Count == 0)
        //		Main.menuMode = Interface.modBrowserID;
        //}

        private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            //Main.menuMode = Interface.modBrowserID;
            if (e.Error != null)
            {
                if (e.Cancelled)
                {
                    Interface.modBrowser.ClearItems();
                    Main.menuMode = Interface.modBrowserID;
                }
                else
                {
                    HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error);
                    if (httpStatusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        Interface.errorMessage.SetMessage("The Mod Browser server has exceeded its daily bandwidth allotment. Please consult this mod's homepage for an alternate download or try again later.");
                        Interface.errorMessage.SetGotoMenu(0);
                        Interface.errorMessage.SetFile(ErrorLogger.LogPath);
                        Main.gameMenu = true;
                        Main.menuMode = Interface.errorMessageID;
                    }
                    else
                    {
                        Interface.errorMessage.SetMessage("Unknown Mod Browser Error. Try again later.");
                        Interface.errorMessage.SetGotoMenu(0);
                        Interface.errorMessage.SetFile(ErrorLogger.LogPath);
                        Main.gameMenu = true;
                        Main.menuMode = Interface.errorMessageID;
                    }
                }
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
            }
            else if (!e.Cancelled)
            {
                // Downloaded OK
                File.Copy(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod", ModLoader.ModPath + Path.DirectorySeparatorChar + currentDownload.mod + ".tmod", true);
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
                if (!currentDownload.update)
                {
                    Interface.modBrowser.aNewModDownloaded = true;
                }
                else
                {
                    Interface.modBrowser.aModUpdated = true;
                }

                // Start next download
                if (modsToDownload.Count != 0)
                {
                    currentDownload = modsToDownload.Dequeue();
                    loadProgress.SetText($"Downloading: {name}: {currentDownload.displayname}");
                    loadProgress.SetProgress(0f);
                    client.DownloadFileAsync(new Uri(currentDownload.download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
                }
                else
                {
                    client.Dispose();
                    client = null;
                    Interface.modBrowser.ClearItems();
                    Main.menuMode = Interface.modBrowserID;
                    if (missingMods.Count > 0)
                    {
                        Interface.infoMessage.SetMessage("The following mods were not found on the Mod Browser: " + String.Join(",", missingMods));
                        Interface.infoMessage.SetGotoMenu(Interface.modsMenuID);
                        Main.menuMode = Interface.infoMessageID;
                    }
                }
            }
            else
            {
                File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod");
            }
        }
Ejemplo n.º 9
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, bool exists)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.exists            = exists;
            this.BorderColor       = new Color(89, 116, 213) * 0.7f;
            this.dividerTexture    = TextureManager.Load("Images/UI/Divider");
            this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground");
            this.Height.Set(90f, 0f);
            this.Width.Set(0f, 1f);
            base.SetPadding(6f);
            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(10f, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);
            UITextPanel <string> button = new UITextPanel <string>("More info", 1f, false);

            button.Width.Set(100f, 0f);
            button.Height.Set(30f, 0f);
            button.Left.Set(5f, 0f);
            button.Top.Set(40f, 0f);
            button.PaddingTop    -= 2f;
            button.PaddingBottom -= 2f;
            button.OnMouseOver   += UICommon.FadedMouseOver;
            button.OnMouseOut    += UICommon.FadedMouseOut;
            button.OnClick       += RequestMoreinfo;
            base.Append(button);
            if (update || !exists)
            {
                updateButton = new UITextPanel <string>(this.update ? (updateIsDowngrade ? "Downgrade" : "Update") : "Download", 1f,
                                                        false);
                updateButton.CopyStyle(button);
                updateButton.Width.Set(200f, 0f);
                updateButton.Left.Set(button.Width.Pixels + button.Left.Pixels * 2f + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                base.Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + modreferences);
                modReferenceIcon.Left.Set(-135f, 1f);
                modReferenceIcon.Top.Set(50f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = "Dependencies";                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.SortList();
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            base.OnDoubleClick += RequestMoreinfo;
        }
Ejemplo n.º 10
0
        private void PopulateFromJSON(LocalMod[] installedMods, string json)
        {
            string tls = PlatformSupportsTls12 ? "&tls12=y" : "";

            try
            {
                JObject jsonObject;
                try
                {
                    jsonObject = JObject.Parse(json);
                }
                catch (Exception e)
                {
                    throw new Exception("Bad JSON: " + json, e);
                }
                JObject updateObject = (JObject)jsonObject["update"];
                if (updateObject != null)
                {
                    updateAvailable = true;
                    updateText      = (string)updateObject["message"];
                    updateURL       = (string)updateObject["url"];
                }
                JArray modlist = (JArray)jsonObject["modlist"];
                foreach (JObject mod in modlist.Children <JObject>())
                {
                    string displayname = (string)mod["displayname"];
                    //reloadButton.SetText("Adding " + displayname + "...");
                    string name      = (string)mod["name"];
                    string version   = (string)mod["version"];
                    string author    = (string)mod["author"];
                    string download  = (string)mod["download"] + tls;
                    int    downloads = (int)mod["downloads"];
                    int    hot       = (int)mod["hot"];            // for now, hotness is just downloadsYesterday
                    string timeStamp = (string)mod["updateTimeStamp"];
                    //string[] modreferences = ((string)mod["modreferences"]).Split(',');
                    string  modreferences = (string)mod["modreferences"];
                    ModSide modside       = ModSide.Both;               // TODO: add filter option for modside.
                    string  modIconURL    = (string)mod["iconurl"];
                    string  modsideString = (string)mod["modside"];
                    if (modsideString == "Client")
                    {
                        modside = ModSide.Client;
                    }
                    if (modsideString == "Server")
                    {
                        modside = ModSide.Server;
                    }
                    if (modsideString == "NoSync")
                    {
                        modside = ModSide.NoSync;
                    }
                    bool exists            = false;
                    bool update            = false;
                    bool updateIsDowngrade = false;
                    var  installed         = installedMods.FirstOrDefault(m => m.Name == name);
                    if (installed != null)
                    {
                        exists = true;
                        var cVersion = new Version(version.Substring(1));
                        if (cVersion > installed.modFile.version)
                        {
                            update = true;
                        }
                        else if (cVersion < installed.modFile.version)
                        {
                            update = updateIsDowngrade = true;
                        }
                    }
                    UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, modreferences, modside, modIconURL, download, downloads, hot, timeStamp, update, updateIsDowngrade, installed);
                    items.Add(modItem);
                }
                updateNeeded = true;
            }
            catch (Exception e)
            {
                ErrorLogger.LogModBrowserException(e);
                return;
            }
        }
Ejemplo n.º 11
0
 public override void OnActivate()
 {
     if (!loaded)
     {
         modList.Clear();
         TmodFile[]             modFiles           = ModLoader.FindMods();
         List <BuildProperties> modBuildProperties = new List <BuildProperties>();
         foreach (TmodFile tmodfile in modFiles)
         {
             modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile));
         }
         XmlDocument xmlDoc = new XmlDocument();
         try
         {
             xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php");
         }
         catch (WebException e)
         {
             if (e.Status == WebExceptionStatus.Timeout)
             {
                 uITextPanel.SetText("Mod Browser OFFLINE", 0.8f, true);
                 return;
             }
         }
         catch (Exception e)
         {
             ErrorLogger.LogModBrowserException(e);
             return;
         }
         foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
         {
             string displayname = xmlNode.SelectSingleNode("displayname").InnerText;
             string name        = xmlNode.SelectSingleNode("name").InnerText;
             string version     = xmlNode.SelectSingleNode("version").InnerText;
             string author      = xmlNode.SelectSingleNode("author").InnerText;
             string description = xmlNode.SelectSingleNode("description").InnerText;
             string download    = xmlNode.SelectSingleNode("download").InnerText;
             string timeStamp   = xmlNode.SelectSingleNode("updateTimeStamp").InnerText;
             int    downloads;
             Int32.TryParse(xmlNode.SelectSingleNode("downloads").InnerText, out downloads);
             bool exists = false;
             bool update = false;
             foreach (BuildProperties bp in modBuildProperties)
             {
                 if (bp.displayName.Equals(displayname))
                 {
                     exists = true;
                     if (!bp.version.Equals(version))
                     {
                         update = true;
                     }
                 }
             }
             //   if (!exists || update)
             //   {
             UIModDownloadItem modItem = new UIModDownloadItem(/*this, */ displayname, name, version, author, description, download, downloads, timeStamp, update, exists);
             modList.Add(modItem);
             //  }
         }
         loaded = true;
     }
 }
Ejemplo n.º 12
0
 private void PopulateFromXML(List<BuildProperties> modBuildProperties, XmlDocument xmlDoc)
 {
     try
     {
         foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
         {
             if (xmlNode.Name.Equals("update"))
             {
                 updateAvailable = true;
                 updateText = xmlNode.SelectSingleNode("message").InnerText;
                 updateURL = xmlNode.SelectSingleNode("url").InnerText;
             }
             else if (xmlNode.Name.Equals("modlist"))
             {
                 foreach (XmlNode xmlNode2 in xmlNode)
                 {
                     string displayname = xmlNode2.SelectSingleNode("displayname").InnerText;
                     string name = xmlNode2.SelectSingleNode("name").InnerText;
                     string version = xmlNode2.SelectSingleNode("version").InnerText;
                     string author = xmlNode2.SelectSingleNode("author").InnerText;
                     string description = xmlNode2.SelectSingleNode("description").InnerText;
                     string homepage = xmlNode2.SelectSingleNode("homepage").InnerText;
                     string download = xmlNode2.SelectSingleNode("download").InnerText;
                     string timeStamp = xmlNode2.SelectSingleNode("updateTimeStamp").InnerText;
                     int downloads;
                     Int32.TryParse(xmlNode2.SelectSingleNode("downloads").InnerText, out downloads);
                     bool exists = false;
                     bool update = false;
                     foreach (BuildProperties bp in modBuildProperties)
                     {
                         if (bp.displayName.Equals(displayname))
                         {
                             exists = true;
                             if (!bp.version.Equals(new Version(version.Substring(1))))
                             {
                                 update = true;
                             }
                         }
                     }
                     UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, description, homepage, download, downloads, timeStamp, update, exists);
                     modListAll.Add(modItem);
                 }
                 SortList(null, null);
             }
         }
     }
     catch (Exception e)
     {
         ErrorLogger.LogModBrowserException(e);
         return;
     }
 }
Ejemplo n.º 13
0
 private void PopulateFromJSON(TmodFile[] installedMods, string json)
 {
     try
     {
         JObject jsonObject   = JObject.Parse(json);
         JObject updateObject = (JObject)jsonObject["update"];
         if (updateObject != null)
         {
             updateAvailable = true;
             updateText      = (string)updateObject["message"];
             updateURL       = (string)updateObject["url"];
         }
         JArray modlist = (JArray)jsonObject["modlist"];
         foreach (JObject mod in modlist.Children <JObject>())
         {
             string displayname = (string)mod["displayname"];
             //reloadButton.SetText("Adding " + displayname + "...");
             string name      = (string)mod["name"];
             string version   = (string)mod["version"];
             string author    = (string)mod["author"];
             string download  = (string)mod["download"];
             int    downloads = (int)mod["downloads"];
             int    hot       = (int)mod["hot"];            // for now, hotness is just downloadsYesterday
             string timeStamp = (string)mod["updateTimeStamp"];
             //string[] modreferences = ((string)mod["modreferences"]).Split(',');
             string  modreferences = (string)mod["modreferences"];
             ModSide modside       = ModSide.Both;               // TODO: add filter option for modside.
             string  modsideString = (string)mod["modside"];
             if (modsideString == "Client")
             {
                 modside = ModSide.Client;
             }
             if (modsideString == "Server")
             {
                 modside = ModSide.Server;
             }
             if (modsideString == "NoSync")
             {
                 modside = ModSide.NoSync;
             }
             bool exists            = false;
             bool update            = false;
             bool updateIsDowngrade = false;
             var  installed         = installedMods.SingleOrDefault(m => m.name == name);
             if (installed != null)
             {
                 exists = true;
                 var cVersion = new Version(version.Substring(1));
                 if (cVersion > installed.version)
                 {
                     update = true;
                 }
                 else if (cVersion < installed.version)
                 {
                     update = updateIsDowngrade = true;
                 }
             }
             UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, modreferences, modside, download, downloads, hot, timeStamp, update, updateIsDowngrade, installed);
             modListAll._items.Add(modItem);                     //add directly to the underlying, SortList will repopulate it anyway
         }
         SortList();
     }
     catch (Exception e)
     {
         ErrorLogger.LogModBrowserException(e);
         return;
     }
 }
Ejemplo n.º 14
0
        public UIModDownloadItem(string displayname, string name, string version, string author, string modreferences, ModSide modside, string modIconURL, string download, int downloads, int hot, string timeStamp, bool update, bool updateIsDowngrade, TmodFile installed)
        {
            this.displayname       = displayname;
            this.mod               = name;
            this.version           = version;
            this.author            = author;
            this.modreferences     = modreferences;
            this.modside           = modside;
            this.modIconURL        = modIconURL;
            this.download          = download;
            this.downloads         = downloads;
            this.hot               = hot;
            this.timeStamp         = timeStamp;
            this.update            = update;
            this.updateIsDowngrade = updateIsDowngrade;
            this.installed         = installed;
            this.BorderColor       = new Color(89, 116, 213) * 0.7f;
            this.dividerTexture    = TextureManager.Load("Images/UI/Divider");
            this.innerPanelTexture = TextureManager.Load("Images/UI/InnerPanelBackground");
            this.Height.Set(90f, 0f);
            this.Width.Set(0f, 1f);
            base.SetPadding(6f);

            float left = 0f;

            if (modIconURL != null)
            {
                left += 85;
            }

            string text = displayname + " " + version;

            this.modName = new UIText(text, 1f, false);
            this.modName.Left.Set(left + 5, 0f);
            this.modName.Top.Set(5f, 0f);
            base.Append(this.modName);

            UITextPanel <string> moreInfoButton = new UITextPanel <string>(Language.GetTextValue("tModLoader.ModsMoreInfo"), 1f, false);

            moreInfoButton.Width.Set(100f, 0f);
            moreInfoButton.Height.Set(30f, 0f);
            moreInfoButton.Left.Set(left, 0f);
            moreInfoButton.Top.Set(40f, 0f);
            moreInfoButton.PaddingTop    -= 2f;
            moreInfoButton.PaddingBottom -= 2f;
            moreInfoButton.OnMouseOver   += UICommon.FadedMouseOver;
            moreInfoButton.OnMouseOut    += UICommon.FadedMouseOut;
            moreInfoButton.OnClick       += RequestMoreinfo;
            Append(moreInfoButton);

            if (update || installed == null)
            {
                updateButton = new UITextPanel <string>(this.update ? (updateIsDowngrade ? Language.GetTextValue("tModLoader.MBDowngrade") : Language.GetTextValue("tModLoader.MBUpdate")) : Language.GetTextValue("tModLoader.MBDownload"), 1f,
                                                        false);
                updateButton.CopyStyle(moreInfoButton);
                updateButton.Width.Set(modIconURL != null ? 120f : 200f, 0f);
                updateButton.Left.Set(moreInfoButton.Width.Pixels + moreInfoButton.Left.Pixels + 5f, 0f);
                updateButton.OnMouseOver += UICommon.FadedMouseOver;
                updateButton.OnMouseOut  += UICommon.FadedMouseOut;
                updateButton.OnClick     += this.DownloadMod;
                Append(updateButton);
            }
            if (modreferences.Length > 0)
            {
                UIHoverImage modReferenceIcon = new UIHoverImage(Main.quicksIconTexture, "This mod depends on: " + modreferences);
                modReferenceIcon.Left.Set(-135f, 1f);
                modReferenceIcon.Top.Set(50f, 0f);
                modReferenceIcon.OnClick += (s, e) =>
                {
                    UIModDownloadItem modListItem = (UIModDownloadItem)e.Parent;
                    Interface.modBrowser.SpecialModPackFilter        = modListItem.modreferences.Split(',').ToList();
                    Interface.modBrowser.SpecialModPackFilterTitle   = "Dependencies";                   // Toolong of \n" + modListItem.modName.Text;
                    Interface.modBrowser.filterTextBox.currentString = "";
                    Interface.modBrowser.updateNeeded = true;
                    Main.PlaySound(SoundID.MenuOpen);
                };
                Append(modReferenceIcon);
            }
            OnDoubleClick += RequestMoreinfo;
        }
Ejemplo n.º 15
0
 public override void OnActivate()
 {
     if (!loaded)
     {
         uITextPanel.SetText("Mod Browser", 0.8f, true);
         modListAll.Clear();
         TmodFile[]             modFiles           = ModLoader.FindMods();
         List <BuildProperties> modBuildProperties = new List <BuildProperties>();
         foreach (TmodFile tmodfile in modFiles)
         {
             modBuildProperties.Add(BuildProperties.ReadModFile(tmodfile));
         }
         XmlDocument xmlDoc = new XmlDocument();
         try
         {
             //	xmlDoc = GetDataFromUrl("http://javid.ddns.net/tModLoader/listmods.php");
             System.Net.ServicePointManager.Expect100Continue = false;
             string          url    = "http://javid.ddns.net/tModLoader/listmods.php";
             IO.UploadFile[] files  = new IO.UploadFile[0];
             var             values = new NameValueCollection
             {
                 { "modloaderversion", ModLoader.version },
             };
             byte[] result = IO.UploadFile.UploadFiles(url, files, values);
             xmlDoc.LoadXml(System.Text.Encoding.UTF8.GetString(result, 0, result.Length));
         }
         catch (WebException e)
         {
             if (e.Status == WebExceptionStatus.Timeout)
             {
                 uITextPanel.SetText("Mod Browser OFFLINE (Busy)", 0.8f, true);
                 return;
             }
             if (e.Status == WebExceptionStatus.ProtocolError)
             {
                 var resp = (HttpWebResponse)e.Response;
                 if (resp.StatusCode == HttpStatusCode.NotFound)
                 {
                     uITextPanel.SetText("Mod Browser OFFLINE (404)", 0.8f, true);
                     return;
                 }
                 uITextPanel.SetText("Mod Browser OFFLINE..", 0.8f, true);
                 return;
             }
         }
         catch (Exception e)
         {
             ErrorLogger.LogModBrowserException(e);
             return;
         }
         try
         {
             foreach (XmlNode xmlNode in xmlDoc.DocumentElement)
             {
                 if (xmlNode.Name.Equals("update"))
                 {
                     updateAvailable = true;
                     updateText      = xmlNode.SelectSingleNode("message").InnerText;
                     updateURL       = xmlNode.SelectSingleNode("url").InnerText;
                 }
                 else if (xmlNode.Name.Equals("modlist"))
                 {
                     foreach (XmlNode xmlNode2 in xmlNode)
                     {
                         string displayname = xmlNode2.SelectSingleNode("displayname").InnerText;
                         string name        = xmlNode2.SelectSingleNode("name").InnerText;
                         string version     = xmlNode2.SelectSingleNode("version").InnerText;
                         string author      = xmlNode2.SelectSingleNode("author").InnerText;
                         string description = xmlNode2.SelectSingleNode("description").InnerText;
                         string homepage    = xmlNode2.SelectSingleNode("homepage").InnerText;
                         string download    = xmlNode2.SelectSingleNode("download").InnerText;
                         string timeStamp   = xmlNode2.SelectSingleNode("updateTimeStamp").InnerText;
                         int    downloads;
                         Int32.TryParse(xmlNode2.SelectSingleNode("downloads").InnerText, out downloads);
                         bool exists = false;
                         bool update = false;
                         foreach (BuildProperties bp in modBuildProperties)
                         {
                             if (bp.displayName.Equals(displayname))
                             {
                                 exists = true;
                                 if (!bp.version.Equals(version))
                                 {
                                     update = true;
                                 }
                             }
                         }
                         UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, description, homepage, download, downloads, timeStamp, update, exists);
                         modListAll.Add(modItem);
                     }
                     SortList(null, null);
                 }
             }
         }
         catch (Exception e)
         {
             ErrorLogger.LogModBrowserException(e);
             return;
         }
         loaded = true;
     }
 }