예제 #1
0
        public static BundleManager LoadBundleManager()
        {
            var  _settings = ServiceLocator.Default.ResolveType <ISettingsManager>();
            ILog _logger   = LogManager.GetCurrentClassLogger();

            _logger.Info("Loading bundle manager... ");
            try
            {
                if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.BundleManager)))
                {
                    using var file = File.OpenText(Tw3Controller.GetManagerPath(EManagerType.BundleManager));
                    var serializer = new JsonSerializer
                    {
                        ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        TypeNameHandling           = TypeNameHandling.Auto
                    };
                    bundleManager = (BundleManager)serializer.Deserialize(file, typeof(BundleManager));
                }
                else
                {
                    bundleManager = new BundleManager();
                    bundleManager.LoadAll(Path.GetDirectoryName(_settings.W3ExecutablePath));
                    using (var writer = new StreamWriter(
                               new FileStream(Tw3Controller.GetManagerPath(EManagerType.BundleManager), FileMode.Open)))
                    {
                        writer.Write(JsonConvert.SerializeObject(bundleManager, Formatting.None, new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                            PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                            TypeNameHandling           = TypeNameHandling.Auto
                        }));
                    }
                    _settings.ManagerVersions[(int)EManagerType.BundleManager] = BundleManager.SerializationVersion;
                }
            }
            catch (Exception)
            {
                if (File.Exists(GetManagerPath(EManagerType.BundleManager)))
                {
                    File.Delete(GetManagerPath(EManagerType.BundleManager));
                }

                bundleManager = new BundleManager();
                bundleManager.LoadAll(Path.GetDirectoryName(_settings.W3ExecutablePath));
            }
            _logger.Info("Finished loading bundle manager.");
            return(bundleManager);
        }
예제 #2
0
        public static CollisionManager LoadCollisionManager()
        {
            var  _settings = ServiceLocator.Default.ResolveType <ISettingsManager>();
            ILog _logger   = LogManager.GetCurrentClassLogger();

            _logger.Info("Loading collision manager... ");
            try
            {
                if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.CollisionManager)))
                {
                    using var file = File.OpenText(Tw3Controller.GetManagerPath(EManagerType.CollisionManager));
                    var serializer = new JsonSerializer
                    {
                        ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        TypeNameHandling           = TypeNameHandling.Auto
                    };
                    collisionManager = (CollisionManager)serializer.Deserialize(file, typeof(CollisionManager));
                }
                else
                {
                    collisionManager = new CollisionManager();
                    collisionManager.LoadAll(Path.GetDirectoryName(_settings.W3ExecutablePath));
                    File.WriteAllText(Tw3Controller.GetManagerPath(EManagerType.CollisionManager), JsonConvert.SerializeObject(collisionManager, Formatting.None, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling      = ReferenceLoopHandling.Ignore,
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        TypeNameHandling           = TypeNameHandling.Auto
                    }));
                    _settings.ManagerVersions[(int)EManagerType.CollisionManager] = CollisionManager.SerializationVersion;
                }
            }
            catch (System.Exception)
            {
                if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.CollisionManager)))
                {
                    File.Delete(Tw3Controller.GetManagerPath(EManagerType.CollisionManager));
                }

                collisionManager = new CollisionManager();
                collisionManager.LoadAll(Path.GetDirectoryName(_settings.W3ExecutablePath));
            }
            _logger.Info("Finished loading collision manager.");

            return(collisionManager);
        }
예제 #3
0
        public static W3StringManager LoadStringsManager()
        {
            var  _settings = ServiceLocator.Default.ResolveType <ISettingsManager>();
            ILog _logger   = LogManager.GetCurrentClassLogger();

            _logger.Info("Loading strings manager ... ");
            try
            {
                if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.W3StringManager)) && new FileInfo(Tw3Controller.GetManagerPath(EManagerType.W3StringManager)).Length > 0)
                {
                    using var file  = File.Open(Tw3Controller.GetManagerPath(EManagerType.W3StringManager), FileMode.Open);
                    w3StringManager = Serializer.Deserialize <W3StringManager>(file);
                }
                else
                {
                    w3StringManager = new W3StringManager();
                    w3StringManager.Load(_settings.TextLanguage, Path.GetDirectoryName(_settings.W3ExecutablePath));
                    Directory.CreateDirectory(Tw3Controller.ManagerCacheDir);
                    using (var file = File.Open(Tw3Controller.GetManagerPath(EManagerType.W3StringManager), FileMode.Create))
                    {
                        Serializer.Serialize(file, w3StringManager);
                    }

                    _settings.ManagerVersions[(int)EManagerType.W3StringManager] = W3StringManager.SerializationVersion;
                }
            }
            catch (System.Exception)
            {
                if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.W3StringManager)))
                {
                    File.Delete(Tw3Controller.GetManagerPath(EManagerType.W3StringManager));
                }

                w3StringManager = new W3StringManager();
                w3StringManager.Load(_settings.TextLanguage, Path.GetDirectoryName(_settings.W3ExecutablePath));
            }
            _logger.Info("Finished loading strings manager.");
            return(w3StringManager);
        }