private bool ParseEffectsFile() { if (!File.Exists(EffectsFile)) { return(false); } string data = File.ReadAllText(EffectsFile); if (data.Length == 0) { return(false); } foreach (string line in data.Split('\n')) { string[] keyValue = line.Split('='); if (keyValue.Length != 2) { continue; } string key = keyValue[0]; string value = keyValue[1]; string[] values = value.Split(','); if (!int.TryParse(values[0], out int enabled)) { return(false); } // Find EffectType from ID EffectType effectType = EffectType._EFFECT_ENUM_MAX; foreach (KeyValuePair <EffectType, EffectInfo> pair in EffectsMap) { if (pair.Value.Id == key) { effectType = pair.Key; break; } } if (!EffectsMap.TryGetValue(effectType, out EffectInfo effectInfo)) { continue; } EffectTimedType effectTimedType = effectInfo.IsShort ? EffectTimedType.TIMED_SHORT : EffectTimedType.TIMED_NORMAL; int effectTimedTime = -1; int effectWeight = 5; int effectPermanent = 0; if (values.Length >= 4) { Enum.TryParse(values[1], out effectTimedType); int.TryParse(values[2], out effectTimedTime); int.TryParse(values[3], out effectWeight); if (values.Length >= 5) { int.TryParse(values[4], out effectPermanent); } } if (effectType != EffectType._EFFECT_ENUM_MAX) { TreeMenuItemsMap[effectType].IsChecked = enabled == 0 ? false : true; EffectDataMap.Add(effectType, new EffectData(effectTimedType, effectTimedTime, effectWeight, effectPermanent != 0)); } } return(true); }
private void ParseEffectsFile() { m_effectsFile.ReadFile(); foreach (string key in m_effectsFile.GetKeys()) { string value = m_effectsFile.ReadValue(key); string[] values = value.Split(','); // Find EffectType from ID EffectType effectType = EffectType._EFFECT_ENUM_MAX; foreach (KeyValuePair <EffectType, EffectInfo> pair in EffectsMap) { if (pair.Value.Id == key) { effectType = pair.Key; break; } } if (!EffectsMap.TryGetValue(effectType, out EffectInfo effectInfo)) { continue; } EffectTimedType effectTimedType = effectInfo.IsShort ? EffectTimedType.TIMED_SHORT : EffectTimedType.TIMED_NORMAL; int effectTimedTime = -1; int effectWeight = 5; bool effectPermanent = false; bool effectExcludedFromVoting = false; string effectCustomName = null; // Compatibility checks, previous versions had less options if (values.Length >= 4) { Enum.TryParse(values[1], out effectTimedType); int.TryParse(values[2], out effectTimedTime); int.TryParse(values[3], out effectWeight); if (values.Length >= 5) { int tmp; int.TryParse(values[4], out tmp); effectPermanent = tmp != 0; if (values.Length >= 6) { int.TryParse(values[5], out tmp); effectExcludedFromVoting = tmp != 0; if (values.Length >= 7) { effectCustomName = values[6] == "0" ? null : values[6]; } } } } if (effectType != EffectType._EFFECT_ENUM_MAX) { int.TryParse(values[0], out int enabled); m_treeMenuItemsMap[effectType].IsChecked = enabled == 0 ? false : true; m_effectDataMap.Add(effectType, new EffectData(effectTimedType, effectTimedTime, effectWeight, effectPermanent, effectExcludedFromVoting, effectCustomName)); } } }
private void ParseEffectsFile() { m_effectsFile.ReadFile(); foreach (string key in m_effectsFile.GetKeys()) { string value = m_effectsFile.ReadValue(key); // Split by comma, ignoring commas in between quotation marks string[] values = Regex.Split(value, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); if (!EffectsMap.TryGetValue(key, out EffectInfo effectInfo)) { continue; } EffectTimedType effectTimedType = effectInfo.IsShort ? EffectTimedType.TimedShort : EffectTimedType.TimedNormal; int effectTimedTime = -1; int effectWeight = 5; bool effectPermanent = false; bool effectExcludedFromVoting = false; string effectCustomName = null; int effectShortcut = 0; // Compatibility checks, previous versions had less options if (values.Length >= 4) { Enum.TryParse(values[1], out effectTimedType); int.TryParse(values[2], out effectTimedTime); int.TryParse(values[3], out effectWeight); if (values.Length >= 5) { int tmp; int.TryParse(values[4], out tmp); effectPermanent = tmp != 0; if (values.Length >= 6) { int.TryParse(values[5], out tmp); effectExcludedFromVoting = tmp != 0; if (values.Length >= 7) { effectCustomName = values[6] == "0" ? null : values[6].Trim('\"'); if (values.Length >= 8) { int.TryParse(values[7], out effectShortcut); } } } } } int.TryParse(values[0], out int enabled); m_treeMenuItemsMap[key].IsChecked = enabled == 0 ? false : true; m_effectDataMap.Add(key, new EffectData(effectTimedType, effectTimedTime, effectWeight, effectPermanent, effectExcludedFromVoting, effectCustomName, effectShortcut)); } }