using System; using System.Collections.Generic; using System.IO; using SUISS.Core; using UnityEngine; namespace Inno.DLC { public class DLCManager { public DLCManager(string propertiesFilename) { this._propertiesFilename = propertiesFilename; try { this.ParseConfig(); this.CheckFolder(); this.CheckFiles(); this._enabled = true; } catch (Exception ex) { UnityEngine.Debug.LogError(string.Format("Disabling DLC: {0}", ex.Message)); this._enabled = false; } } public static string AbsolutePath(string name) { return PathHandler.Combine(DLCManager.DLCFolderPath, name); } public DLCGroup GetGroup(string id) { if (this._groups.ContainsKey(id)) { return this._groups[id]; } return this._emptyGroup; } public IList AllGroups { get { return new List(this._groups.Values).AsReadOnly(); } } public bool IsEnabled { get { return this._enabled; } } private static string DLCFolderPath { get { return PathHandler.Combine(Application.persistentDataPath, "dlc"); } } private void ParseConfig() { TextAsset textAsset = Resources.Load(this._propertiesFilename) as TextAsset; if (textAsset != null) { string text = textAsset.text.Trim(); string[] array = text.Split(new char[] { '\n' }); Dictionary>> dictionary = new Dictionary>>(); int num = 0; foreach (string text2 in array) { num++; string text3 = text2.Trim(); if (text3.Length > 0) { int num2 = text3.IndexOf('='); if (num2 >= 0) { string text4 = text3.Substring(0, num2).TrimEnd(new char[0]); string value = text3.Substring(num2 + 1).TrimStart(new char[0]); int num3 = text4.IndexOf('.'); if (num3 >= 0) { string key = text4.Substring(0, num3).TrimEnd(new char[0]); string text5 = text4.Substring(num3 + 1).TrimStart(new char[0]); int num4 = text5.IndexOf('.'); if (num4 >= 0) { string key2 = text5.Substring(0, num4).TrimEnd(new char[0]); string key3 = text5.Substring(num4 + 1).TrimStart(new char[0]); if (!dictionary.ContainsKey(key)) { dictionary[key] = new Dictionary>(); } if (!dictionary[key].ContainsKey(key2)) { dictionary[key][key2] = new Dictionary(); } dictionary[key][key2][key3] = value; } } } else { UnityEngine.Debug.LogWarning(string.Format("Parse error in dlc.properties line {0}: cannot find '=' token.", num)); } } } foreach (KeyValuePair>> keyValuePair in dictionary) { this._groups[keyValuePair.Key] = new DLCGroup(keyValuePair.Key, keyValuePair.Value); } } } private void CheckFolder() { string dlcfolderPath = DLCManager.DLCFolderPath; if (!Directory.Exists(dlcfolderPath)) { Directory.CreateDirectory(dlcfolderPath); } } private void CheckFiles() { foreach (DLCGroup dlcgroup in this._groups.Values) { dlcgroup.CheckFiles(); } } private const string DLCFolder = "dlc"; private string _propertiesFilename; private Dictionary _groups = new Dictionary(); private readonly DLCGroup _emptyGroup = new DLCGroup(string.Empty, new Dictionary>()); private bool _enabled; } }