Exemplo n.º 1
0
 public static void SaveSettings()
 {
     try
     {
         XElement xElement = new XElement("Settings");
         foreach (PropertyInfo item in from pi in typeof(SettingsManager).GetRuntimeProperties()
                  where pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic
                  select pi)
         {
             try
             {
                 string   value = HumanReadableConverter.ConvertToString(item.GetValue(null, null));
                 XElement node  = XmlUtils.AddElement(xElement, "Setting");
                 XmlUtils.SetAttributeValue(node, "Name", item.Name);
                 XmlUtils.SetAttributeValue(node, "Value", value);
             }
             catch (Exception ex)
             {
                 Log.Warning($"Setting \"{item.Name}\" could not be saved. Reason: {ex.Message}");
             }
         }
         using (Stream stream = Storage.OpenFile("config:/Settings.xml", OpenFileMode.Create))
         {
             XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true);
         }
         Log.Information("Saved settings");
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser("Saving settings failed.", e);
     }
 }
Exemplo n.º 2
0
 public static void Save()
 {
     try
     {
         XElement xElement  = new XElement("Cache");
         XElement xElement2 = new XElement("Feedback");
         xElement.Add(xElement2);
         foreach (string key in m_feedbackCache.Keys)
         {
             XElement xElement3 = new XElement("Item");
             XmlUtils.SetAttributeValue(xElement3, "Key", key);
             xElement2.Add(xElement3);
         }
         XElement xElement4 = new XElement("Content");
         xElement.Add(xElement4);
         foreach (KeyValuePair <string, string> item in m_idToAddressMap)
         {
             XElement xElement5 = new XElement("Item");
             XmlUtils.SetAttributeValue(xElement5, "Path", item.Key);
             XmlUtils.SetAttributeValue(xElement5, "Address", item.Value);
             xElement4.Add(xElement5);
         }
         using (Stream stream = Storage.OpenFile("config:/CommunityContentCache.xml", OpenFileMode.Create))
         {
             XmlUtils.SaveXmlToStream(xElement, stream, null, throwOnError: true);
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser("Saving Community Content cache failed.", e);
     }
 }
Exemplo n.º 3
0
 public static void Load()
 {
     try
     {
         if (Storage.FileExists("config:/CommunityContentCache.xml"))
         {
             using (Stream stream = Storage.OpenFile("config:/CommunityContentCache.xml", OpenFileMode.Read))
             {
                 XElement xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true);
                 foreach (XElement item in xElement.Element("Feedback").Elements())
                 {
                     string attributeValue = XmlUtils.GetAttributeValue <string>(item, "Key");
                     m_feedbackCache[attributeValue] = true;
                 }
                 foreach (XElement item2 in xElement.Element("Content").Elements())
                 {
                     string attributeValue2 = XmlUtils.GetAttributeValue <string>(item2, "Path");
                     string attributeValue3 = XmlUtils.GetAttributeValue <string>(item2, "Address");
                     m_idToAddressMap[attributeValue2] = attributeValue3;
                 }
             }
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser("Loading Community Content cache failed.", e);
     }
 }
Exemplo n.º 4
0
        public static void Run()
        {
            VrManager.WaitGetPoses();
            double realTime = Time.RealTime;

            LastFrameTime               = (float)(realTime - m_frameBeginTime);
            LastCpuFrameTime            = (float)(m_cpuEndTime - m_frameBeginTime);
            m_frameBeginTime            = realTime;
            Window.PresentationInterval = ((!VrManager.IsVrStarted) ? SettingsManager.PresentationInterval : 0);
            try
            {
                if (ExceptionManager.Error == null)
                {
                    while (m_urisToHandle.Count > 0)
                    {
                        Uri obj = m_urisToHandle[0];
                        m_urisToHandle.RemoveAt(0);
                        Program.HandleUri?.Invoke(obj);
                    }
                    PerformanceManager.Update();
                    MotdManager.Update();
                    MusicManager.Update();
                    ScreensManager.Update();
                    DialogsManager.Update();
                }
                else
                {
                    ExceptionManager.UpdateExceptionScreen();
                }
            }
            catch (Exception e)
            {
                ExceptionManager.ReportExceptionToUser(null, e);
                ScreensManager.SwitchScreen("MainMenu");
            }
            try
            {
                Display.RenderTarget = null;
                if (ExceptionManager.Error == null)
                {
                    ScreensManager.Draw();
                    PerformanceManager.Draw();
                    ScreenCaptureManager.Run();
                }
                else
                {
                    ExceptionManager.DrawExceptionScreen();
                }
                m_cpuEndTime = Time.RealTime;
            }
            catch (Exception e2)
            {
                ExceptionManager.ReportExceptionToUser(null, e2);
                ScreensManager.SwitchScreen("MainMenu");
            }
        }
 public static void DeleteFurniturePack(string name)
 {
     try
     {
         Storage.DeleteFile(GetFileName(name));
         FurniturePacksManager.FurniturePackDeleted?.Invoke(name);
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser($"Unable to delete furniture pack \"{name}\"", e);
     }
 }
Exemplo n.º 6
0
 public static void Main()
 {
     CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
     CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;
     Log.RemoveAllLogSinks();
     Log.AddLogSink(new GameLogSink());
     Window.HandleUri          += HandleUriHandler;
     Window.Deactivated        += DeactivatedHandler;
     Window.Frame              += FrameHandler;
     Window.UnhandledException += delegate(UnhandledExceptionInfo e)
     {
         ExceptionManager.ReportExceptionToUser("Unhandled exception.", e.Exception);
         e.IsHandled = true;
     };
     Window.Run(1920, 1080, Engine.WindowMode.Resizable, "Survivalcraft 2");
 }
Exemplo n.º 7
0
 public static void DeleteBlocksTexture(string name)
 {
     try
     {
         string fileName = GetFileName(name);
         if (!string.IsNullOrEmpty(fileName))
         {
             Storage.DeleteFile(fileName);
             BlocksTexturesManager.BlocksTextureDeleted?.Invoke(name);
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser($"Unable to delete blocks texture \"{name}\"", e);
     }
 }
Exemplo n.º 8
0
 public static void DeleteCharacterSkin(string name)
 {
     try
     {
         string fileName = GetFileName(name);
         if (!string.IsNullOrEmpty(fileName))
         {
             Storage.DeleteFile(fileName);
             CharacterSkinsManager.CharacterSkinDeleted?.Invoke(name);
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser($"Unable to delete character skin \"{name}\"", e);
     }
 }
Exemplo n.º 9
0
 public void Execute(string code)
 {
     if (string.IsNullOrWhiteSpace(code))
     {
         return;
     }
     try
     {
         Jint.Engine engine = JsEngine.Execute(code);
         if (ComponentPlayer != null)
         {
             ComponentPlayer.ComponentGui.DisplaySmallMessage(engine.GetCompletionValue().ToString(), false, false);
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser("JS", e);
     }
     lastcode = code;
 }
Exemplo n.º 10
0
 public static void LoadSettings()
 {
     try
     {
         if (Storage.FileExists("config:/Settings.xml"))
         {
             using (Stream stream = Storage.OpenFile("config:/Settings.xml", OpenFileMode.Read))
             {
                 foreach (XElement item in XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true).Elements())
                 {
                     string name = "<unknown>";
                     try
                     {
                         name = XmlUtils.GetAttributeValue <string>(item, "Name");
                         string       attributeValue = XmlUtils.GetAttributeValue <string>(item, "Value");
                         PropertyInfo propertyInfo   = (from pi in typeof(SettingsManager).GetRuntimeProperties()
                                                        where pi.Name == name && pi.GetMethod.IsStatic && pi.GetMethod.IsPublic && pi.SetMethod.IsPublic
                                                        select pi).FirstOrDefault();
                         if (propertyInfo != null)
                         {
                             object value = HumanReadableConverter.ConvertFromString(propertyInfo.PropertyType, attributeValue);
                             propertyInfo.SetValue(null, value, null);
                         }
                     }
                     catch (Exception ex)
                     {
                         Log.Warning($"Setting \"{name}\" could not be loaded. Reason: {ex.Message}");
                     }
                 }
             }
             Log.Information("Loaded settings.");
         }
     }
     catch (Exception e)
     {
         ExceptionManager.ReportExceptionToUser("Loading settings failed.", e);
     }
 }
Exemplo n.º 11
0
/*
 *              /// <summary>
 *              /// Loaded Assemblies
 *              /// </summary>
 *              public static Dictionary<string, AppDomain> LoadedAssemblies;
 */
        public static void Initialize()
        {
            loadedAssemblies = new List <Assembly>();
            LoadedMods       = new List <ModInfo>();
#if ENV_ANDROID
            CachedMods = new HashSet <string>();
#endif
            DisabledMods        = new HashSet <string>();
            Files               = new List <string>();
            Directories         = new List <string>();
            LabelWidget.Strings = new Dictionary <string, string>();
            ReadZip             = true;
            AutoCleanCache      = true;
            SearchDepth         = 3;
            ErrorHandler        = LogException;
            try
            {
                var str = Combine(ContentManager.Path, "mods.cfg");
                if (File.Exists(str))
                {
                    using (var reader = new StreamReader(str))
                        if (string.Equals(reader.ReadLine(), "Ver 1.1") && (str = reader.ReadLine()) != null)
                        {
                            ReadZip        = str.Contains(nameof(ReadZip));
                            AutoCleanCache = str.Contains(nameof(AutoCleanCache));
                            if (!int.TryParse(reader.ReadLine(), out SearchDepth))
                            {
                                SearchDepth = 3;
                            }
                            do
                            {
                                if ((str = reader.ReadLine()) == null)
                                {
                                    goto loadmods;
                                }
                            }while (!string.Equals(str, "Disabled:"));
                            while ((str = reader.ReadLine()) != null && !string.Equals(str, "Last loaded mods:"))
                            {
                                DisabledMods.Add(str);
                            }
                            do
                            {
                                if ((str = reader.ReadLine()) == null)
                                {
                                    goto loadmods;
                                }
                            }while (!string.Equals(str, "File\tModifyTime"));
                            var notExist = new DateTime(1601, 1, 1).ToLocalTime();
                            while ((str = reader.ReadLine()) != null && str.Length != 0)
                            {
#if ENV_ANDROID
                                var name = str.
#if Bugs
                                           Substring(0,
#else
                                           Remove(
#endif
                                                     str.IndexOf('\t'));
                                var time = File.GetLastWriteTimeUtc(Combine(ContentManager.Path, name));
                                if (time != notExist && time.ToString() == str.Substring(str.IndexOf('\t') + 1))
                                {
                                    CachedMods.Add(name);
                                }
#endif
                            }
                        }
                }
                loadmods:
                EnumerateDirectory(ContentManager.Path, Files, Directories, SearchDepth);
                if (ReadZip)
                {
                    Archives        = new Dictionary <string, ZipArchive>();
                    var enumerator2 = GetFiles(".zip").GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        str = enumerator2.Current;
                        Archives.Add(str, ZipArchive.Open(File.OpenRead(str)));
                    }
                }
                var enumerator = GetEntries(".dll").GetEnumerator();
                while (enumerator.MoveNext())
                {
                    //str = enumerator.Current.Filename;
                    //var domain = AppDomain.CreateDomain(str);
                    //Assembly asm;
                    try
                    {
#if ENV_ANDROID
                        //asm = domain.Load(str);
                        LoadMod(Assembly.LoadFrom(enumerator.Current.Filename, null));
#else
                        var buf = new byte[enumerator.Current.Stream.Length];
                        enumerator.Current.Stream.Read(buf, 0, buf.Length);
                        //asm = domain.Load(buf);
                        LoadMod(Assembly.Load(buf));
#endif
                        //LoadMod(asm);
                        //LoadedAssemblies.Add(str, domain);
                    }
                    catch (Exception e)
                    {
                        ErrorHandler(enumerator.Current, e);
                    }
                }
            }
            catch (Exception e)
            {
                ExceptionManager.ReportExceptionToUser("Initialize failed.", e);
            }
            Log.Information(string.Format("Found {0} files, loaded {1} dlls ({2} mods)", Files.Count, loadedAssemblies.Count, LoadedMods.Count));
            Initialized?.Invoke();
            SaveConfig();
#if ENV_ANDROID
            if (AutoCleanCache)
            {
                CleanCache();
            }
#endif
        }