コード例 #1
0
ファイル: MainForm.cs プロジェクト: wetor/MagesTools
        public bool patchSCX(Dictionary <string, MPKEntry> mpk, string charset, Dictionary <string, dynamic> scx)
        {
            Log("[SCX] 正在应用 SCX 补丁...");
            foreach (KeyValuePair <string, dynamic> kv in scx)
            {
                if (!mpk.ContainsKey(kv.Key))
                {
                    Oops("[SCX] 无法找到文件 " + kv.Key);
                    return(false);
                }
                Log("[SCX] 正在对 " + kv.Key + " 应用补丁...");

                using (var ms = new MemoryStream())
                    using (var reader = new SCXReader(mpk[kv.Key].Data, charset))
                        using (var writer = new SCXWriter(ms, charset))
                        {
                            var sb = new StringBuilder();
                            if (!SCX.ApplyPatch(kv.Value, reader, writer, sb))
                            {
                                Log(sb.ToString());
                                Oops("[SCX] 补丁应用失败");
                                return(false);
                            }
                            mpk[kv.Key].SetData(ms.ToArray());
                        }
            }
            return(true);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: fenggang233/MagesTools
 private void button_scx_apply_Click(object sender, EventArgs e)
 {
     try
     {
         var patch = JSON.ToObject <Dictionary <string, dynamic> >(File.ReadAllText(textBox_scx_patch.Text));
         if (!patch.ContainsKey("data") || !(patch["data"] is Dictionary <string, dynamic> scx))
         {
             throw new Exception("Bad patch file: Key scx not found or not dictionary");
         }
         var    sb      = new StringBuilder();
         string charset = patch["charset_preset"] + patch["charset"];
         foreach (KeyValuePair <string, object> kv in scx)
         {
             string target = Path.Combine(textBox_scx_target.Text, kv.Key);
             if (!File.Exists(target + ".bak"))
             {
                 continue;
             }
             sb.AppendLine("---------- " + kv.Key + " ----------");
             using (var reader = new SCXReader(File.OpenRead(target + ".bak"), charset))
                 using (var writer = new SCXWriter(File.Open(target, FileMode.Create), charset))
                 {
                     if (!SCX.ApplyPatch((IList <object>)kv.Value, reader, writer, sb))
                     {
                         break;
                     }
                 }
         }
         sb.Append("\n");
         textBox_log.Clear();
         textBox_log.AppendText(sb.ToString());
         File.WriteAllText("R:/patch.log", sb.ToString());
     }
     catch (Exception ex) { Oops(ex); }
 }