public static void Save_Config()
        {
            if (IN_LOADING_PHASE == true)
            {
                return;
            }

            try
            {
                if (plugins == null)
                {
                    SLog.Warn("CRITICAL ERROR: Active plugins list is null!");
                    return;
                }

                // Select the keynames of all non-null, enabled plugins from our dictionary.
                List <string> list = Loader.plugins.Where(kv => (kv.Value != null && kv.Value.Enabled)).Select(kv => kv.Key).ToList();

                Config.Set_Array <string>("ENABLED_PLUGINS", list);
                Config.Save();
            }
            catch (Exception ex)
            {
                SLog.Error(ex);
            }
        }
Example #2
0
        public void Remove_Upgrade(PlotUpgrade upgrade)
        {
            bool b = upgrades.Remove(upgrade);

            if (!b)
            {
                SLog.Warn("Failed to remove custom plot upgrade from tracker. Upgrade: {0}", upgrade);
            }
        }
Example #3
0
        public static void Play(SoundId snd, Vector3 pos)
        {
            //PLog.Info("[Sound] Playing: SoundId.{0}", snd.ToString());
            Func <SECTR_AudioCue> cue;

            if (SOUND_MAP.TryGetValue(snd, out cue))
            {
                SECTR_AudioSystem.Play(cue(), pos, false);
            }
            else
            {
                SLog.Warn("[Sound] No sound listed for SoundId.{0}", snd.ToString());
            }
        }
Example #4
0
        public DevMenu()
        {
            onLayout += DevMenu_onLayout;
            Title     = "DevMenu";
            Set_Size(800, 600);
            Center();

            list = uiControl.Create <uiListView>(this);
            list.alignTop();
            list.alignLeftSide();
            list.Set_Margin(0, 4, 0, 0);

            tabPanel = uiControl.Create <uiTabPanel>(this);
            tabPanel.Autosize_Method = AutosizeMethod.FILL;
            //tabPanel.local_style.normal.background = null;

            foreach (var kvp in Menus)
            {
                string eStr = Enum.GetName(typeof(Dev_Menu_Type), kvp.Key);
                var    tab  = tabPanel.Add_Tab();
                tab.Scrollable      = false;
                Menus[kvp.Key].Tab  = tab;
                Menus[kvp.Key].Type = kvp.Key;

                switch (kvp.Key)
                {
                case Dev_Menu_Type.HIERARCHY:
                    Create <Dev_Hierarchy_Browser>(tab);
                    break;

                case Dev_Menu_Type.SPAWN:
                    Create <Dev_SpawnMenu>(tab);
                    break;

                default:
                    SLog.Warn("Unhandled Dev_Menu type: {0}", eStr);
                    break;
                }

                var itm = uiControl.Create <uiListItem>();
                itm.Title       = kvp.Value.Title;
                itm.Description = kvp.Value.Description;
                itm.onSelected += (uiControl c) => { Set_Active_Menu(kvp.Value.Type); };
                list.Add(itm);
            }
        }
Example #5
0
        internal static void Register(IUpgrade upgrade)
        {
            if (!ALL.ContainsKey(upgrade.Type))
            {
                ALL.Add(upgrade.Type, new Dictionary <string, IUpgrade>());
            }

            var dict = ALL[upgrade.Type];

            if (dict.ContainsKey(upgrade.ID))
            {
                SLog.Warn("[Upgrades] Blocked Attempt to register duplicate {0} upgrade instance for \"{1}\"", upgrade.Type, upgrade.ID);
                return;
            }
            //var old = ALL[upgrade.Type].FirstOrDefault(o => String.Compare(o.ID, upgrade.ID) == 0);
            //if (old != null) ALL[upgrade.Type].Remove(old);

            SLog.Debug("[Upgrades] Registered: {0}", upgrade.ID);
            ALL[upgrade.Type].Add(upgrade.ID, upgrade);
        }
 public static void Restart_App()
 {
     try
     {
         byte[] buf = Util.Load_Resource("Restart_Helper.exe");
         if (buf != null && buf.Length > 0)
         {
             File.WriteAllBytes(update_helper_file, buf);
             string args = String.Format("{0}", Process.GetCurrentProcess().Id);
             Process.Start(update_helper_file, args);
         }
         else
         {
             SLog.Warn("Failed to unpack the auto update helper!");
         }
     }
     catch (Exception ex)
     {
         SLog.Error(ex);
     }
 }
        /// <summary>
        /// Removes the upgrades effects from the LandPlot
        /// </summary>
        public void Remove(bool ignore_tracker, LandPlot plot)
        {
            PlotID pID = new PlotID(plot);

            // Clear any save data this upgrade might have set for this plot.
            Upgrades.Clear_Upgrade_Data(pID, this.ID);
            if (!ignore_tracker)
            {
                // Remove the upgrade from this plot's tracker.
                PlotUpgradeTracker tracker = plot.GetComponent <PlotUpgradeTracker>();
                if (tracker == null)
                {
                    SLog.Warn("Failed to remove upgrade from plot {0}. Cannot find PlotUpgradeTracker!", pID);
                }
                else
                {
                    tracker.Remove_Upgrade(this);
                }
            }
            // Call the upgrades cleanup logic.
            removal_function?.Invoke(plot);
        }
        /// <summary>
        /// Causes this plugin to check and see if it has any updates.
        /// </summary>
        public bool check_for_updates()
        {
            if (is_update_available)
            {
                return(true);
            }

            if (data == null)
            {
                SLog.Warn("{0} Plugin has no DATA structure!", this);
                return(false);
            }

            if (data.UPDATE_METHOD == null || !data.UPDATE_METHOD.Valid)
            {
                return(false);
            }

            _update_status      = Updater.Get_Update_Status(data.UPDATE_METHOD.URL, FilePath);
            is_update_available = (_update_status == FILE_UPDATE_STATUS.OUT_OF_DATE);

            //PLog.Info("{0}  update_status: {1}", this, Enum.GetName(typeof(FILE_UPDATE_STATUS), status));
            return(is_update_available);
        }
        public IEnumerator Get_Update_Status_Async(string remote_path, string local_file)
        {
            if (!File.Exists(local_file))
            {
                yield return(FILE_UPDATE_STATUS.OUT_OF_DATE);

                yield break;// ensure we stop here
            }

            string repo_url    = Extract_Repository_URL_From_Github_URL(remote_path);
            string remote_file = Extract_File_Path_From_Github_URL(remote_path);

            // Time to check with GitHub and see if there is a newer version of the plugin loader out!
            JSONArray repo = Cache_Git_Repo(repo_url);
            // Go ahead and get the hash for the file we're checking on.
            string cSHA = Util.Git_File_Sha1_Hash(local_file);
            // Let's make sure we didn't already check on this same file in the past.
            FILE_UPDATE_STATUS?lastResult = Get_Cached_Result(remote_path, local_file);

            //if we DID cache the result from a past check against this file then return it here and don't waste time.
            if (lastResult.HasValue)
            {
                //SLog.Debug("Cached {2}  |  \"{0}\"  |  SHA({1})", local_file, cSHA, Enum.GetName(typeof(FILE_UPDATE_STATUS), lastResult.Value));
                yield return(lastResult.Value);

                yield break;// ensure we stop here
            }


            if (repo == null)
            {
                SLog.Info("[AutoUpdater] Unable to cache git repository!");
                yield return(FILE_UPDATE_STATUS.ERROR);

                yield break;// ensure we stop here
            }

            // Find the plugin loaders DLL installation file
            foreach (JSONNode file in repo)
            {
                if (String.Compare(file["path"], remote_file) == 0)
                {
                    // Compare the SHA1 hash for the dll on GitHub to the hash for the one currently installed
                    string nSHA = file["sha"];
                    //PLog.Info("nSHA({0})  cSHA({1})  local_file: {2}", nSHA, cSHA, local_file);

                    if (String.Compare(nSHA, cSHA) != 0)
                    {
                        // ok they don't match, now let's just make double sure that it isn't because we are using an unreleased developer version
                        // First find the url for the file on GitHub
                        string tmpurl = file["url"];
                        // now we want to replace it's hash with ours and check if it exists!
                        tmpurl = tmpurl.Replace(nSHA, cSHA);

                        // Check if the file for the currently installed loaders sha1 hash exists.
                        bool exist = false;
                        var  it    = Query_Remote_File_Exists_Async(tmpurl);
                        bool fail  = false;
                        do
                        {
                            yield return(null);

                            try
                            {
                                if (!it.MoveNext())
                                {
                                    fail = true;                //stop
                                }
                            }
                            catch (WebException wex)
                            {
                                fail = true;//stop
                                if (wex.Status == WebExceptionStatus.ProtocolError)
                                {
                                    var response = wex.Response as HttpWebResponse;
                                    if (response != null)
                                    {
                                        if (response.StatusCode == HttpStatusCode.NotFound)// A file for this hash does not exhist on the github repo. So this must be a Dev version.
                                        {
                                            exist = false;
                                        }
                                    }
                                }
                            }
                        } while (!fail);

                        if (!exist)
                        {
                            //PLog.Info("[Updater] Dev file: {0}", Path.GetFileName(local_file));
                            Cache_Result(remote_path, local_file, FILE_UPDATE_STATUS.DEV_FILE);
                            yield return(FILE_UPDATE_STATUS.DEV_FILE);

                            yield break;// ensure we stop here
                        }

                        //PLog.Info("[Updater] Outdated file: {0}", Path.GetFileName(local_file));
                        Cache_Result(remote_path, local_file, FILE_UPDATE_STATUS.OUT_OF_DATE);
                        yield return(FILE_UPDATE_STATUS.OUT_OF_DATE);

                        yield break;// ensure we stop here
                    }
                    else
                    {
                        Cache_Result(remote_path, local_file, FILE_UPDATE_STATUS.UP_TO_DATE);
                        yield return(FILE_UPDATE_STATUS.UP_TO_DATE);

                        yield break;// ensure we stop here
                    }
                }
            }

            SLog.Warn("[Git_Updater] Unable to find file in repository: {0}", remote_file);
            yield return(FILE_UPDATE_STATUS.NOT_FOUND); //no update

            yield break;                                // ensure we stop here
        }