Exemplo n.º 1
0
 private bool SaveFile(String fileName)
 {
     try { File.Delete(fileName); } catch { return false; }
     List<INIFile.INIVariableDef> defmcp = new List<INIFile.INIVariableDef>();
     List<String[]> comments = new List<String[]>(); //  0 - section, 1 - key, 2 - comment above
     defmcp.Add(INIFile.iniDefEmpty);
     foreach (String section in selections.Sections.Keys) {
         Patch patch = selections.Sections[section];
         if (patch.Checked != new Patch().Checked)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Checked], INIFile.INIVariableType.Dictionary, patch.Checked.ToString()));
         defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Version], INIFile.INIVariableType.Dictionary, patch.Version.ToString()));
         Dictionary<Patch.Key, String> str = new Dictionary<Patch.Key, String> { { Patch.Key.Parent, patch.Parent }, { Patch.Key.Author, patch.Author } };
         foreach (Patch.Key key in str.Keys) if (str[key].Trim().Length > 0)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[key], INIFile.INIVariableType.Dictionary, str[key].Trim()));
         if (patch.FileVersion != new Patch().FileVersion)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.FileVersion], INIFile.INIVariableType.Dictionary, patch.FileVersion.ToString()));
         Dictionary<Patch.Key, Unit[]> array = new Dictionary<Patch.Key, Unit[]> { { Patch.Key.Original, patch.Original }, { Patch.Key.Patch, patch.Patched }, { Patch.Key.Attach, patch.Attach }, { Patch.Key.Description, patch.Description } };
         foreach (Patch.Key key in array.Keys) if (array[key] != null) foreach (Unit unit in array[key]) {
             String[] asm_lines = unit.Asm.Split(new Char[] { '\n' });
             String[] hex_lines = unit.Hex.Split(new Char[] { '\n' });
             String hex = "";
             int comment = 0;
             foreach (String line in hex_lines) hex += (hex.Length > 0 ? "\t" : "") + ((comment = line.IndexOf(INIFile.INIComment)) < 0 ? line : line.Substring(0, comment)).TrimEnd(null);
             if (hex.Trim().Length == 0) continue;
             String variable = Patch.Keys[key] + " " + unit.ToString();
             for (int i = 0; i < asm_lines.Length; i++) if (i == asm_lines.Length - 1 ? asm_lines[i].Trim().Length > 0 : true) comments.Add(new String[3] { section, variable, asm_lines[i] });
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, variable, INIFile.INIVariableType.Dictionary, hex));
         }
         if (patch.Removed != new Patch().Removed)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Removed], INIFile.INIVariableType.Dictionary, patch.Removed.ToString()));
     }
     INIFile mcpFile = new INIFile(fileName, defmcp.ToArray(), Encoding.Default, true);
     mcpFile.initialize();
     foreach (String[] triplet in comments) mcpFile.setCommentAbove(triplet[0], triplet[1], triplet[2]);
     return mcpFile.save();
 }