private void step_delete() { if (dellist == null) { FileStream fs = new FileStream(patchfile, FileMode.Open); dellist = new List <DEL>(); while (fs.Position < fs.Length) { CTRL o = read(fs); if (o.act == action.CTRL_DEL) { dellist.Add((DEL)o); break; } } fs.Close(); fs.Dispose(); } current = info.add + info.dff + info.mov; total = gettotal(); UnityEngine.Debug.Log("step_delet"); var iter = dellist.GetEnumerator(); while (iter.MoveNext()) { var o = iter.Current; try { File.Delete(Path.Combine(patchdir_rw, o.name)); }catch (SystemException) { } ++current; } writehead(step.DELETE); }
private CTRL read(FileStream fs) { action act = CTRL.readact(fs); CTRL o = null; switch (act) { case action.CTRL_NEW: o = new NEW(); break; case action.CTRL_DFF: o = new DFF(); break; case action.CTRL_DFX: o = new DFX(); break; case action.CTRL_MOV: o = new MOV(); break; case action.CTRL_DEL: o = new DEL(); break; } o.read(fs); return(o); }
public byte[] patch_content(byte[] old, byte[] patch) { int wr = 0, off = 0; int end = patch.Length; int fsize = CTRL.read32(patch, ref off); byte[] buff = new byte[fsize]; while (off < end) { int act = CTRL.read8(patch, ref off); if (act == (int)action.PATCH_COPY) { int pos, size; pos = CTRL.read32(patch, ref off); size = CTRL.read32(patch, ref off); Buffer.BlockCopy(old, pos, buff, wr, size); wr += size; } else if (act == (int)action.PATCH_INSERT) { int size; size = CTRL.read32(patch, ref off); Buffer.BlockCopy(patch, off, buff, wr, size); off += size; wr += size; } else { return(null); } } return(buff); }
public static CTRL read(byte[] data, ref int off) { action act = CTRL.readact(data, ref off); CTRL o = null; switch (act) { case action.CTRL_NEW: o = new NEW(); break; case action.CTRL_DFF: o = new DFF(); break; case action.CTRL_DFX: o = new DFX(); break; case action.CTRL_MOV: o = new MOV(); break; case action.CTRL_DEL: o = new DEL(); break; } o.read(data, ref off); return(o); }
private void step_patch() { modified = new List <string>(); FileStream fs = new FileStream(patchfile, FileMode.Open); UnityEngine.Debug.Log("step_patch"); current = 0; total = gettotal(); dellist = new List <DEL>(); while (fs.Position < fs.Length) { CTRL o = read(fs); byte[] frombuf = null; string topath = null; switch (o.act) { case action.CTRL_DFF: modified.Add(((DFF)o).name); topath = Path.Combine(patchtmp, ((DFF)o).name); frombuf = readfile_shortname(((DFF)o).name); if (frombuf != null) { patch_content(frombuf, ((DFF)o).patch, topath); } break; case action.CTRL_DFX: modified.Add(((DFX)o).name); topath = Path.Combine(patchtmp, ((DFX)o).name); frombuf = readfile_shortname(((DFX)o).namea); if (frombuf != null) { patch_content(frombuf, ((DFX)o).patch, topath); } break; case action.CTRL_NEW: modified.Add(((NEW)o).name); topath = Path.Combine(patchtmp, ((NEW)o).name); writefile(topath, ((NEW)o).data); break; case action.CTRL_MOV: modified.Add(((MOV)o).name); frombuf = readfile_shortname(((MOV)o).namea); if (frombuf != null) { topath = Path.Combine(patchtmp, ((MOV)o).name); writefile(topath, frombuf); } break; case action.CTRL_DEL: dellist.Add((DEL)o); break; } if (o.act != action.CTRL_DEL) { ++current; } } fs.Close(); fs.Dispose(); writehead(step.PATCH); }
public void patch(string patchpath, string dir) { int offset = 0, end; string tmp = Path.Combine(dir, "_temp"); List <CTRL> second = new List <CTRL>(); byte[] patch = File.ReadAllBytes(patchpath); end = patch.Length; //step1 dff/dfx while (offset < end) { string frompath, topath; byte[] frombuf, tobuf; CTRL o = read(patch, ref offset); switch (o.act) { case action.CTRL_DFF: frompath = Path.Combine(dir, ((DFF)o).name); topath = Path.Combine(tmp, ((DFF)o).name); frombuf = readfile(frompath); tobuf = patch_content(frombuf, ((DFF)o).patch); writefile(topath, tobuf); break; case action.CTRL_DFX: frompath = Path.Combine(dir, ((DFX)o).namea); topath = Path.Combine(tmp, ((DFX)o).name); frombuf = readfile(frompath); tobuf = patch_content(frombuf, ((DFX)o).patch); writefile(topath, tobuf); break; case action.CTRL_NEW: case action.CTRL_MOV: case action.CTRL_DEL: second.Add(o); break; } } //step2 rename/delete/new var iter = second.GetEnumerator(); while (iter.MoveNext()) { byte[] data; string temppath, frompath; var ctrl = iter.Current; switch (ctrl.act) { case action.CTRL_NEW: temppath = Path.Combine(tmp, ((NEW)ctrl).name); writefile(temppath, ((NEW)ctrl).data); break; case action.CTRL_MOV: frompath = Path.Combine(dir, ((MOV)ctrl).namea); temppath = Path.Combine(tmp, ((MOV)ctrl).name); data = readfile(frompath); writefile(temppath, data); break; case action.CTRL_DEL: frompath = Path.Combine(dir, ((DEL)ctrl).name); File.Delete(frompath); break; } } //step3 merge var prefix = tmp.Length + 1; var files = Directory.GetFiles(tmp, "*", SearchOption.AllDirectories).ToList(); var fiter = files.GetEnumerator(); while (fiter.MoveNext()) { string from = fiter.Current; string to = from.Substring(prefix); to = Path.Combine(dir, to); var info = new FileInfo(to); info.Directory.Create(); if (File.Exists(to)) { File.Delete(to); } File.Move(from, to); } //step4 verify //step5 clearnup Directory.Delete(tmp); }