Exemplo n.º 1
0
 public Patch(INIFile mcpFile, String section)
 {
     Dictionary<String, String> keys = mcpFile.getSectionKeys(section);
     foreach (String sKey in keys.Keys) {
         String value = mcpFile.getKeyString(section, sKey).Trim();
         bool oKey = sKey.StartsWith(Keys[Key.Original], StringComparison.OrdinalIgnoreCase);
         bool pKey = sKey.StartsWith(Keys[Key.Patch], StringComparison.OrdinalIgnoreCase);
         bool aKey = sKey.StartsWith(Keys[Key.Attach], StringComparison.OrdinalIgnoreCase);
         bool dKey = sKey.StartsWith(Keys[Key.Description], StringComparison.OrdinalIgnoreCase);
         if (aKey || oKey || pKey || dKey) {
             value = value.Replace("\t", "\n");
             String comment = mcpFile.getCommentAbove(section, sKey);
             Unit[] units = oKey ? Original : pKey ? Patched : aKey ? Attach : Description;
             List<Unit> array = units != null ? new List<Unit>(units) : new List<Unit>();
             String tag = sKey.Substring(Keys[oKey ? Key.Original : pKey ? Key.Patch : aKey ? Key.Attach : Key.Description].Length).Trim();
             array.Add(aKey || dKey ? new Unit(tag, 0, value, comment) : new Unit(Convert.ToUInt32(tag, 16), value, comment));
             if (oKey) Original = array.ToArray(); else if (pKey) Patched = array.ToArray(); else if (aKey) Attach = array.ToArray();
             else Description = array.ToArray();
             continue;
         }
         foreach (Key key in Keys.Keys) {
             if (sKey.ToLower() == Keys[key].ToLower()) {
                 NumberFormatInfo provider = new NumberFormatInfo();
                 provider.NumberDecimalSeparator = ".";
                 switch (key) {
                     case Key.Checked: { try { Checked = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                     case Key.Parent: { Parent = value; break; }
                     case Key.Version: { try { version = Math.Abs((float)Convert.ToDouble(value, provider)); } catch { } break; }
                     case Key.FileVersion: { try { fileVersion = Math.Abs(Convert.ToInt32(value)); } catch { } break; }
                     case Key.Author: { Author = value; break; }
                     case Key.Removed: { try { Removed = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                     case Key.Expanded: { try { Expanded = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                 }
                 break;
             }
         }
     }
 }