private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath); int i, status, updatecode, recode; for (i = 0; i < Program.filestatus.Count; i++) { status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString()); fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath); string path = ""; if (i < 4) { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null); } else { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar"; } if (i < 4) { if (listView1.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; })); this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = "处理中..."; this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; })); } if (i > 1) { if (status == 1) { fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i); recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i); if (recode == 0) { updatecode = Program.ChoseVer; } else { updatecode = recode; } } else { updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); } } else { recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); if (recode == 1) { updatecode = Program.ChoseVer; } else { updatecode = recode; } } if (listView1.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].Text = fun.fileupdatcode(updatecode); listView1.Items[i].EnsureVisible(); })); } if (updatecode == 1 || updatecode == -1 || updatecode == 2 || updatecode == 4) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Green; })); } else { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i].SubItems[1].ForeColor = Color.Red; })); } } else { if (listView1.InvokeRequired) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; })); this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = "处理中..."; listView1.Items[i + 1].EnsureVisible(); })); } if (status >= 7) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(status); listView1.Items[i + 1].EnsureVisible(); })); this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100))); fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath); continue; } else { if (Program.ChoseVer == -1) { fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i + 1); if (recode == 0) { updatecode = 1; } else { updatecode = recode; } } else { this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; })); dlcBase = new DLCBase(path); dlcEditor = new DLCEditor(dlcBase); string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null); string[] arr1 = file.Split(';'); foreach (string replacefile in arr1) { fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile); } string oldSfar = dlcBase.fileName; string newSfar = oldSfar + ".tmp"; FileInfo aa = new FileInfo(oldSfar); if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(oldSfar, FileAttributes.Normal); } backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar }); while (backgroundWorkerEditFile.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. if (backgroundWorkerEditFile.CancellationPending) { return; } else { Application.DoEvents(); } } File.Delete(oldSfar); foreach (string replacefile in arr1) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } File.Move(newSfar, oldSfar); updatecode = 2; } this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].Text = fun.fileupdatcode(updatecode); })); if (updatecode == 1 || updatecode == 2) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Green; listView1.Items[i + 1].EnsureVisible(); })); } else { this.Invoke(new MethodInvoker(delegate() { listView1.Items[i + 1].SubItems[1].ForeColor = Color.Red; listView1.Items[i + 1].EnsureVisible(); })); } } } fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath); stdd = status; this.backgroundWorker2.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100))); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { StartPosition : string temp = System.IO.Path.GetTempPath(); fun.SaveRecordFile(temp, "bgm2", ".wma"); string path; int status; fun.logger("开始校验文件", false, System.Windows.Forms.Application.StartupPath); this.Invoke(new MethodInvoker(delegate() { this.label6.Hide(); })); #region MD5计算 for (int FileID = 0; FileID < Program.filecode.Count + 1; FileID++) { this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.progressBar2.Maximum = Program.filecode.Count + 1; if (FileID < 4) { listView1.Items[fun.codetrans(FileID)].SubItems.Add("校验中..."); this.listView1.Items[FileID].UseItemStyleForSubItems = false; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; } else if (FileID > 4) { listView1.Items[fun.codetrans(FileID - 1)].SubItems.Add("校验中..."); listView1.Items[FileID].EnsureVisible(); this.listView1.Items[FileID].UseItemStyleForSubItems = false; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; } Application.DoEvents(); })); if (FileID == 4) { continue; } if (FileID < 4) { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID), "Filename", null); } else { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(FileID - 1)] + "Default.sfar"; } if (!File.Exists(path)) { if (FileID < 4) { this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "核心文件缺失,修复中..."; this.listView1.Items[FileID].UseItemStyleForSubItems = false; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = " 重新校验中..."; Application.DoEvents(); })); } else { Program.filehash.Add(Convert.ToString(FileID), ""); this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Value = FileID; this.label4.Text = Convert.ToString(Math.Ceiling((FileID + 1) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%"; Application.DoEvents(); })); if (FileID > 4) { Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile))); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString()); } else { Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile))); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString()); } this.Invoke(new MethodInvoker(delegate() { if (FileID != 4) { listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status); this.listView1.Items[FileID].UseItemStyleForSubItems = false; if (status == 1 || status == 6) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Black; } else if (status == 2 || status == 4) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Green; } else if (status == 3 || status == 5) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown; } else { listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; } } })); continue; } } Program.filehash.Add(Convert.ToString(FileID), fun.AnyscMD5(path, progressBar1, label3)); #endregion if (FileID > 4) { Program.filestatus.Add(Convert.ToString(FileID - 1), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile))); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString()); #region DLC修复 if (status == 8) { for (int t = 1; t < 4; t++) { if (status != 8) { break; } fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "损坏,第" + Convert.ToString(t) + "次尝试修复中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; progressBar1.Maximum = 100; Application.DoEvents(); })); dlcBase = new DLCBase(path); dlcEditor = new DLCEditor(dlcBase); string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "FileName", null); string[] arr1 = file.Split(';'); foreach (string replacefile in arr1) { fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, FileID - 1); dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID - 1)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile); } string oldSfar = dlcBase.fileName; string newSfar = oldSfar + ".tmp"; backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar }); while (backgroundWorkerEditFile.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. if (backgroundWorkerEditFile.CancellationPending) { return; } else { Application.DoEvents(); } } File.Delete(oldSfar); foreach (string replacefile in arr1) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } File.Move(newSfar, oldSfar); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "重新校验中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3); Program.filestatus[Convert.ToString(FileID - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString()); } if (status == 8) { MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); System.Environment.Exit(0); } } #endregion #region DLC升级 if (status == 3 || status == 5 || ((status == 1 || status == 6) && (Convert.ToInt32(Program.filestatus["1"].ToString()) != 1))) { fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath); if (!Program.updst) { if (bgm) { fun.Pause(std); std = 2; fun.Play(std); } else { std = 2; } } Program.updst = true; this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "升级中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; progressBar1.Maximum = 100; progressBar1.Value = 0; Application.DoEvents(); })); dlcBase = new DLCBase(path); dlcEditor = new DLCEditor(dlcBase); string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "FileName", null); string[] arr1 = file.Split(';'); foreach (string replacefile in arr1) { fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID - 1), "Type", null), Convert.ToInt32(Program.filestatus["1"].ToString()), FileID - 1); dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(FileID - 1)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile); } string oldSfar = dlcBase.fileName; string newSfar = oldSfar + ".tmp"; backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar }); while (backgroundWorkerEditFile.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. if (backgroundWorkerEditFile.CancellationPending) { return; } else { Application.DoEvents(); } } File.Delete(oldSfar); foreach (string replacefile in arr1) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } File.Move(newSfar, oldSfar); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "重新校验中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3); Program.filestatus[Convert.ToString(FileID - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID - 1)].ToString()); } #endregion } else { Program.filestatus.Add(Convert.ToString(FileID), Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile))); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString()); #region 核心文件修复 if (status == 8 && FileID < 4) { for (int t = 1; t < 4; t++) { if (status != 8) { break; } fun.logger("文件" + Convert.ToString(FileID) + "损坏,第" + Convert.ToString(t) + "次尝试修复中...", false, System.Windows.Forms.Application.StartupPath); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "损坏,第" + Convert.ToString(t) + "次尝试修复中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, 1, FileID); this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "重新校验中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3); Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString()); } if (status == 8) { MessageBox.Show("修复失败,请将位于" + System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log 这一日志文件发送到[email protected],便于确定问题所在。感谢支持!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); System.Environment.Exit(0); } } #endregion #region 核心文件升级 if (status == 3 || status == 5) { fun.logger("开始升级文件" + Convert.ToString(FileID), false, System.Windows.Forms.Application.StartupPath); Program.updst = true; this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "升级中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); if (FileID < 3) { fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(FileID), "Type", null), status, FileID); } else { fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, FileID); VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, FileID); File.Delete(path); File.Move(Path.GetFileNameWithoutExtension(path) + ".tmp", path); } this.Invoke(new MethodInvoker(delegate() { listView1.Items[FileID].SubItems[1].Text = "重新校验中..."; listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; Application.DoEvents(); })); Program.filehash[Convert.ToString(FileID)] = fun.AnyscMD5(path, progressBar1, label3); Program.filestatus[Convert.ToString(FileID)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(FileID)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)); status = Convert.ToInt32(Program.filestatus[Convert.ToString(FileID)].ToString()); } #endregion } this.Invoke(new MethodInvoker(delegate() { if (FileID > 4) { listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status); this.listView1.Items[FileID].UseItemStyleForSubItems = false; if (status == 1 || status == 6) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Black; } else if (status == 2 || status == 4) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Green; } else if (status == 3 || status == 5) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown; } else { listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; } } else if (FileID < 4) { listView1.Items[FileID].SubItems[1].Text = fun.codestatustrans(status); this.listView1.Items[FileID].UseItemStyleForSubItems = false; if (status == 1 || status == 6) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Black; } else if (status == 2 || status == 4) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Green; } else if (status == 3 || status == 5) { listView1.Items[FileID].SubItems[1].ForeColor = Color.Brown; } else { listView1.Items[FileID].SubItems[1].ForeColor = Color.Red; } if (status == 1 && FileID == 1) { this.button2.Text = "开始汉化(&S)"; this.radioButton1.Checked = true; } else if ((status == 2 || status == 4) && FileID == 1) { this.button2.Text = "开始还原(&S)"; if (status == 2) { this.radioButton1.Checked = true; } if (status == 4) { this.radioButton2.Checked = true; } this.groupBox3.Enabled = false; } } this.progressBar2.Value = FileID; this.label4.Text = Convert.ToString(Math.Ceiling((FileID) / Convert.ToDouble(Program.filecode.Count) * 100)) + "%"; Application.DoEvents(); })); } #region 输出文件状态信息 StreamWriter sw; sw = File.AppendText(System.Windows.Forms.Application.StartupPath + "\\zh-installlog.log"); sw.WriteLine(DateTime.Now + " 文件状态已确认,内部信息代码如下:"); for (int i = 0; i < Program.filestatus.Count; i++) { sw.WriteLine(" " + "文件:" + Convert.ToString(i) + " " + "状态:" + Program.filestatus[Convert.ToString(i)].ToString()); } sw.Close(); #endregion }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { fun.logger("辅助线程启动", false, System.Windows.Forms.Application.StartupPath); int i, status, updatecode = 0, recode; for (i = 0; i < Program.filestatus.Count; i++) { this.Invoke(new MethodInvoker(delegate() { this.label6.Text = fun.codetrans(i); })); status = Convert.ToInt32(Program.filestatus[Convert.ToString(i)].ToString()); fun.logger("开始处理文件#" + Convert.ToString(i), false, System.Windows.Forms.Application.StartupPath); string path = "", bakpath = "", pathRus = ""; if (i < 4) { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename", null); pathRus = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Filename2", null); } else { path = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar"; bakpath = System.Windows.Forms.Application.StartupPath + Program.filepath[Convert.ToString(i)] + "Default.sfar.mebak"; } if (i < 4) { this.Invoke(new MethodInvoker(delegate() { this.progressBar2.Maximum = 100; progressBar1.Maximum = 100; })); if (i > 1) { if (status == 1 && Program.ChoseVer != -1) { fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), null, status, i); //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i); fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", "COM", status, i); recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i); if (recode == 0) { updatecode = Program.ChoseVer; } else { updatecode = recode; } } else { updatecode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); } } else { if (Program.RusVer == true && (IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null) != "COM")) { File.Delete(pathRus); File.Move(path, path + ".bak"); recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); File.Move(path, pathRus); File.Move(path + ".bak", path); if (recode == 1) { updatecode = Program.ChoseVer; } } else { recode = fun.fileupdate(Path.GetDirectoryName(path), Path.GetFileName(path), IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); if (recode == 1) { updatecode = Program.ChoseVer; } else { updatecode = recode; } } } } else { if (status >= 7) { this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100))); fun.logger("处理完成,结果:" + fun.fileupdatcode(status), false, System.Windows.Forms.Application.StartupPath); continue; } else { if (Program.ChoseVer == -1) { dlcBase = new DLCBase(path); dlcEditor = new DLCEditor(dlcBase); string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null); string[] arr1 = file.Split(';'); foreach (string replacefile in arr1) { fun.fileupdate(Path.GetDirectoryName(path), replacefile, null, -1, i); dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile); } string oldSfar = dlcBase.fileName; string newSfar = oldSfar + ".tmp"; backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar }); while (backgroundWorkerEditFile.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. if (backgroundWorkerEditFile.CancellationPending) { return; } else { Application.DoEvents(); } } File.Delete(oldSfar); foreach (string replacefile in arr1) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } File.Move(newSfar, oldSfar); //Program.filehash[Convert.ToString(i)] = fun.AnyscMD5(path, progressBar1, label3); // Program.filestatus[Convert.ToString(i - 1)] = Convert.ToString(checkfiles.checkfile((string)Program.filehash[Convert.ToString(i)].ToString(), Program.orgfile, Program.repfilehash, Program.chofile, Program.chefile, Program.choupdfile, Program.cheupdfile)); //status = Convert.ToInt32(Program.filestatus[Convert.ToString(i - 1)].ToString()); //fun.fileupdate(Path.GetDirectoryName(path), "Data.pat", IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); //recode = VPatch4cs.DoPatch.Patch(Path.GetDirectoryName(path) + "\\Data.pat", path, Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".tmp", progressBar1, label3, i + 1); //if (recode == 0) updatecode = 1; //else updatecode = recode; } else { if (Program.DLCbak == true && (!File.Exists(bakpath))) { File.Copy(path, bakpath); } this.Invoke(new MethodInvoker(delegate() { this.progressBar1.Value = 0; this.label3.Text = "0%"; })); dlcBase = new DLCBase(path); dlcEditor = new DLCEditor(dlcBase); string file = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName", null); string file2 = IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "FileName2", null); string[] arr1 = file.Split(';'); string[] arr2 = file.Split(';'); int j = 0; foreach (string replacefile in arr1) { fun.fileupdate(Path.GetDirectoryName(path), replacefile, IniFiles.ini.INIGetStringValue(Program.IniPath, Convert.ToString(i), "Type", null), Program.ChoseVer, i); if (Program.RusVer == true) { if (replacefile != "SFXGUI_Fonts_DLC.pcc") { if (File.Exists(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString())) { File.Delete(Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()); } File.Move(Path.GetDirectoryName(path) + "\\" + replacefile, Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()); } dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + arr2[j].ToString(), Path.GetDirectoryName(path) + "\\" + arr2[j].ToString()); j++; } else { dlcEditor.setReplaceFile(Program.filepath[Convert.ToString(i)].ToString().Replace('\\', '/') + replacefile, Path.GetDirectoryName(path) + "\\" + replacefile); } } string oldSfar = dlcBase.fileName; string newSfar = oldSfar + ".tmp"; FileInfo aa = new FileInfo(oldSfar); if ((aa.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { File.SetAttributes(oldSfar, FileAttributes.Normal); } backgroundWorkerEditFile.RunWorkerAsync(new object[1] { newSfar }); while (backgroundWorkerEditFile.IsBusy) { // Keep UI messages moving, so the form remains // responsive during the asynchronous operation. if (backgroundWorkerEditFile.CancellationPending) { return; } else { Application.DoEvents(); } } File.Delete(oldSfar); if (Program.RusVer == true) { foreach (string replacefile in arr2) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } } else { foreach (string replacefile in arr1) { File.Delete(Path.GetDirectoryName(path) + "\\" + replacefile); } } File.Move(newSfar, oldSfar); updatecode = 2; } } } fun.logger("处理完成,结果:" + fun.fileupdatcode(updatecode), false, System.Windows.Forms.Application.StartupPath); stdd = status; this.backgroundWorker1.ReportProgress(Convert.ToInt32(Math.Ceiling((((double)(i + 1) / (double)Program.filestatus.Count)) * 100))); } }
//------------------------- GUI Menu Functions -------------------------- private void openSfarFile(string fileName) { dlcBase = new DLCBase(fileName); dlcEditor = new DLCEditor(dlcBase); TreeNode root = new TreeNode(fileName); root.Name = fileName; TreeNode node = root; treeViewSfar.Nodes.Clear(); treeViewSfar.Nodes.Add(root); foreach (sfarFile entry in dlcBase.fileList) { if (entry.fileName != null) { string filePath = entry.fileName; node = root; System.Diagnostics.Debug.WriteLine("Parsing: " + entry.fileName); string[] pathBits = filePath.Substring(1).Split('/'); for (int i = 0; i < pathBits.Length - 1; i++) { System.Diagnostics.Debug.WriteLine("Parsing pathbit: " + pathBits[i]); node = AddNode(node, pathBits[i]); } //Add the 'file' object to the list TreeNode last = node.Nodes.Add(pathBits[pathBits.Length - 1], pathBits[pathBits.Length - 1]); last.Name = filePath; switch (Path.GetExtension(filePath)) { case ".afc": last.ImageIndex = 3; break; case ".bik": last.ImageIndex = 4; break; case ".tfc": last.ImageIndex = 2; break; default: last.ImageIndex = 1; break; } } } float fileSize; string strFileSize = ""; textBoxNumOfFiles.Text = dlcBase.numOfFiles.ToString(); //show the total uncompressed size setSize(dlcBase.totalUncSize, out fileSize, ref strFileSize); textBoxTotalUncSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture); labelTotalUncBytes.Text = strFileSize; //show the total compressed size setSize(dlcBase.totalComprSize, out fileSize, ref strFileSize); textBoxTotalComprSize.Text = fileSize.ToString("0.0", CultureInfo.InvariantCulture); labelTotalComprBytes.Text = strFileSize; textBoxCRatio.Text = (dlcBase.totalComprSize / (float)dlcBase.totalUncSize * 100).ToString("0.#") + "%"; textBoxFirstEntryOffset.Text = "0x" + dlcBase.entryOffset.ToString("X8"); textBoxFirstBlockOffset.Text = "0x" + dlcBase.blockTableOffset.ToString("X8"); textBoxFirstDataOffset.Text = "0x" + dlcBase.dataOffset.ToString("X8"); //enable the right-click menu for nodes selection treeViewSfar.ContextMenuStrip = contextMenuStripEditor; //clear the previous values; textBoxFullName.Text = ""; textBoxHash.Text = ""; textBoxUncSize.Text = ""; textBoxComprSize.Text = ""; textBoxEntry.Text = ""; textBoxBlockIndex.Text = ""; textBoxDataOffset.Text = ""; toolStripSaveFile.Enabled = false; }
public static void RepackDLCs(bool MakeBackup = true) { if (!repackEnabled) { return; } String[] dlcupdates = GetFilesForRepacking(); if (!Directory.Exists(GetDLCCachePath())) { throw new FileNotFoundException("DLC Cache Path not found"); } if (dlcupdates.Length == 0) { DebugOutput.PrintLn("No updates found!"); return; } List <String> tempdlcupdates = new List <string>(); for (int i = 0; i < dlcupdates.Length; i++) { bool filefound = false; for (int j = 0; j < tempdlcupdates.Count; j++) { if (String.Compare(dlcupdates[i], tempdlcupdates[j]) == 0) { filefound = true; break; } } if (!filefound) { tempdlcupdates.Add(dlcupdates[i]); } } dlcupdates = tempdlcupdates.ToArray(); DebugOutput.PrintLn("Repacking modified DLCs..."); String DLCPath = Path.GetDirectoryName(listpath); string[] DLCs = Directory.EnumerateDirectories(DLCPath, "*", SearchOption.TopDirectoryOnly).ToArray(); for (int i = 0; i < DLCs.Length; i++) { DirectoryInfo dinfo = new DirectoryInfo(DLCs[i]); FileInfo[] files = dinfo.GetFiles(); List <String> updates = new List <string>(); string commonname = Path.GetFileName(DLCs[i]); for (int j = 0; j < dlcupdates.Length; j++) { if (Path.GetFileName(Path.GetDirectoryName(dlcupdates[j])) != commonname) { continue; } for (int k = 0; k < files.Length; k++) { if (String.Compare(files[k].Name, Path.GetFileName(dlcupdates[j]), true) == 0) { updates.Add(dlcupdates[j]); break; } } } if (updates.Count <= 0) { continue; } DebugOutput.PrintLn("DLC Updates found for " + commonname + ". Now fixing PCConsoleTOC.bin and repacking..."); DLCBase dlcbase; try { string[] tempdlc = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(DLCPath), "DLC", commonname), "Default.sfar", SearchOption.AllDirectories); if (tempdlc == null || tempdlc.Length == 0) { throw new FileNotFoundException("DLC File not found!"); } // KFreon: Allow no backup file creation if (MakeBackup) { if (!File.Exists(Path.ChangeExtension(tempdlc[0], ".bak"))) { DebugOutput.PrintLn("DLC backup file not found. Creating..."); File.Copy(tempdlc[0], Path.ChangeExtension(tempdlc[0], ".bak"), true); } } dlcbase = new DLCBase(tempdlc[0]); } catch (FileNotFoundException) { DebugOutput.PrintLn("DLC File Not Found"); continue; } catch { DebugOutput.PrintLn("DLC Opening failed"); continue; } DLCEditor editor = new DLCEditor(dlcbase); String tocpath = null; for (int j = 0; j < files.Length; j++) { if (String.Compare(Path.GetFileName(files[j].Name), "PCConsoleTOC.bin", true) == 0) { DLCTocFix(files[j].FullName); tocpath = files[j].FullName; break; } } for (int j = 0; j < updates.Count; j++) { String tempname = dlcbase.getFullNameOfEntry(updates[j]); if (tempname == null) { throw new FileNotFoundException("Filename not found in DLC's files"); } editor.setReplaceFile(tempname, updates[j]); } // Also add toc.bin String temptoc = dlcbase.getFullNameOfEntry(tocpath); if (temptoc == null) { throw new FileNotFoundException("TOC not found in DLC's files"); } editor.setReplaceFile(temptoc, tocpath); editor.Execute(Path.ChangeExtension(dlcbase.fileName, ".new"), null, Properties.Settings.Default.NumThreads); if (File.Exists(Path.ChangeExtension(dlcbase.fileName, ".new"))) { File.Copy(Path.ChangeExtension(dlcbase.fileName, ".new"), dlcbase.fileName, true); File.Delete(Path.ChangeExtension(dlcbase.fileName, ".new")); } DebugOutput.PrintLn("Finished updating " + commonname, true); } File.Delete(listpath); // Reset the repack file }