public static BundleManager LoadBundleManager() { var _settings = ServiceLocator.Default.ResolveType <ISettingsManager>(); var _logger = ServiceLocator.Default.ResolveType <ILoggerService>(); _logger.LogString("Loading Bundle Manager ... ", Logtype.Important); try { if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.BundleManager))) { using (StreamReader file = File.OpenText(Tw3Controller.GetManagerPath(EManagerType.BundleManager))) { JsonSerializer serializer = new JsonSerializer(); serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects; serializer.TypeNameHandling = TypeNameHandling.Auto; bundleManager = (BundleManager)serializer.Deserialize(file, typeof(BundleManager)); } } else { bundleManager = new BundleManager(); bundleManager.LoadAll(Path.GetDirectoryName(_settings.W3ExecutablePath)); using (StreamWriter 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.LogString("Finished loading Bundle Manager.", Logtype.Success); return(bundleManager); }
public static SoundManager LoadSoundManager() { var _settings = ServiceLocator.Default.ResolveType <ISettingsManager>(); var _logger = ServiceLocator.Default.ResolveType <ILoggerService>(); _logger.LogString("Loading Sound Manager ... ", Logtype.Important); try { if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.SoundManager))) { using (StreamReader file = File.OpenText(Tw3Controller.GetManagerPath(EManagerType.SoundManager))) { JsonSerializer serializer = new JsonSerializer(); serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; serializer.PreserveReferencesHandling = PreserveReferencesHandling.Objects; serializer.TypeNameHandling = TypeNameHandling.Auto; soundManager = (SoundManager)serializer.Deserialize(file, typeof(SoundManager)); } } else { soundManager = new SoundManager(); soundManager.LoadAll(Path.GetDirectoryName(_settings.ExecutablePath)); File.WriteAllText(Tw3Controller.GetManagerPath(EManagerType.SoundManager), JsonConvert.SerializeObject(soundManager, Formatting.None, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore, PreserveReferencesHandling = PreserveReferencesHandling.Objects, TypeNameHandling = TypeNameHandling.Auto })); _settings.ManagerVersions[(int)EManagerType.SoundManager] = SoundManager.SerializationVersion; } } catch (System.Exception ex) { if (File.Exists(Tw3Controller.GetManagerPath(EManagerType.SoundManager))) { File.Delete(Tw3Controller.GetManagerPath(EManagerType.SoundManager)); } soundManager = new SoundManager(); soundManager.LoadAll(Path.GetDirectoryName(_settings.ExecutablePath)); } _logger.LogString("Finished loading Sound Manager.", Logtype.Success); return(soundManager); }
public static W3StringManager LoadStringsManager() { var _settings = ServiceLocator.Default.ResolveType <ISettingsManager>(); var _logger = ServiceLocator.Default.ResolveType <ILoggerService>(); _logger.LogString("Loading Strings Manager ... ", Logtype.Important); 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.ExecutablePath)); 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.ExecutablePath)); } _logger.LogString("Finished loading Strings Manager.", Logtype.Success); return(w3StringManager); }