private void Select_Plugin(uiControl c)
        {
            Plugin_StoreItem pl = (Plugin_StoreItem)c;

            if (selected_plugin != null)
            {
                selected_plugin.Active = false;
            }
            selected_plugin = pl;

            if (c != null)
            {
                tabPanel.Select_Tab(MAIN_TAB_NAME);
            }
            else
            {
                tabPanel.Select_Tab(INSTRUCTION_TAB_NAME);
            }

            if (c == null)
            {
                pl_title.Text          = "";
                pl_auth.Text           = "N/A";
                pl_desc.Text           = "N/A";
                install_btn.isDisabled = true;
                return;
            }
            else
            {
                install_btn.isDisabled = false;
            }
            c.Active = true;
            Plugin_Download_Data data = this.plugins[pl.plugin_hash];

            pl_title.Text = data.Name;
            pl_auth.Text  = String.Format("<color=#808080ff>Author:</color> {0}", data.Author);
            pl_desc.Text  = data.Description;
            if (pl_desc.Text == null || pl_desc.Text.Length <= 0)
            {
                pl_desc.Text = "N/A";
            }

            //install_btn.isVisible = !data.isInstalled;
            install_btn.isDisabled = data.isInstalled;
            install_btn.Text       = data.isInstalled ? "Installed" : "Download";
        }
        private void Download_Plugin(string hash, string url)
        {
            Plugin_Download_Data plData = plugins[hash];
            string pl_title             = "unknown";

            if (plData != null)
            {
                pl_title = plData.Title;
            }

            if (plData.Updater == null)
            {
                SLog.Info("The plugin \"{0}\" has an invalid updater instance, it's update method might not have been specified by the author!", pl_title);
                return;
            }

            Plugin_StoreItem plugin = (list[hash] as Plugin_StoreItem);

            plugin.download_info.Expand();
            //plugin.download_info.Collapse();
            plugin.progress_text.Text  = "Connecting...";
            plugin.progress_text.Value = "0%";

            string local_file = String.Format("{0}\\..\\plugins\\{1}", UnityEngine.Application.dataPath, plData.Filename);

            StartCoroutine(plData.Updater.DownloadAsync(url, local_file, (string ContentType) =>
            {
                (list[hash] as Plugin_StoreItem).progress_text.Text = "Downloading:";
                if (ContentType.StartsWith("application/"))
                {
                    return(true);                                      //yea it's binary file data
                }
                SLog.Info("The download url for the plugin \"{0}\" returns content of type \"{1}\" rather than the plugin file itself.\nThis may indicate that the url for this plugin leads to a download PAGE as opposed to giving the actual file, the plugin creator should supply a valid url leading DIRECTLY to the file.", pl_title, ContentType);
                return(false);//This file is not ok to download.
            },
                                                        (float read, float total) =>
            {
                if (list == null)
                {
                    return;
                }

                Plugin_StoreItem pl = list[hash] as Plugin_StoreItem;
                if (pl != null)
                {
                    float pct              = ((float)read / (float)total);
                    pl.progress_bar.Value  = pct;
                    pl.progress_text.Value = pct.ToString("P0");
                }
            },
                                                        (string filename) =>
            {
                bool success = Loader.Add_Plugin_To_List(filename);
                if (success)
                {
                    Plugin pl = Plugin.Get_Plugin(plData.Hash);
                    if (pl != null)
                    {
                        pl.Enable();           //enable the plugin by default, since they JUST installed it and all.
                    }
                    else
                    {
                        throw new Exception("Cannot find and enable plugin: " + plData.Name);
                    }

                    Select_Plugin(selected_plugin);
                }
            }));
        }
        private void Rebuild_Plugins_UI()
        {
            pending_rebuild = false;
            list.Clear_Children();
            string search_str = search.text.ToLower();

            // add all the plugins to the sidebar
            foreach (KeyValuePair <string, Plugin_Download_Data> kv in this.plugins)
            {
                Plugin_Download_Data plugin = kv.Value;

                Plugin_Data dat = new Plugin_Data()
                {
                    AUTHOR      = plugin.Author,
                    NAME        = plugin.Name,
                    DESCRIPTION = plugin.Description
                };

                if (search_str.Length > 0)
                {
                    bool match = false;
                    if (plugin.Name.ToLower().IndexOf(search_str) > -1)
                    {
                        match = true;
                    }
                    if (plugin.Author.ToLower().IndexOf(search_str) > -1)
                    {
                        match = true;
                    }

                    if (!match)
                    {
                        continue;
                    }
                }


                Plugin_StoreItem itm = uiControl.Create <Plugin_StoreItem>();
                itm.onClicked += this.Select_Plugin;
                itm.Set_Plugin_Data(dat);
                list.Add(itm.plugin_hash, itm);
            }

            // select one of the plugins
            if (list.Get_Children().Count() > 0)
            {
                if (this.selected_plugin == null)
                {
                    //Select nothing, show instructions instead
                    //Select_Plugin(list.Get_Children()[0]);
                    tabPanel.Select_Tab(INSTRUCTION_TAB_NAME);
                }
                else
                {
                    uiControl found = null;
                    foreach (uiControl c in this.list.Get_Children())
                    {
                        Plugin_StoreItem itm = (Plugin_StoreItem)c;
                        if (itm.plugin_hash == selected_plugin.plugin_hash)
                        {
                            found = c;
                            break;
                        }
                    }

                    if (found != null)
                    {
                        Select_Plugin(found);
                    }
                    else
                    {
                        Select_Plugin(list.Get_Children().First());
                    }
                }
            }
            else
            {
                Select_Plugin(null);
            }
        }