private void открытьToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { ai = new AIFile().Read(ofd.FileName, this); LoadData(0); } }
public AIPolicy Read(string filepath, MainForm f) { AIPolicy ai = new AIPolicy(); BinaryReader br = new BinaryReader(new FileStream(filepath, FileMode.Open, FileAccess.Read)); ai.header = br.ReadInt32(); int count = br.ReadInt32(); f.Progress.Maximum = count; for (int i = 0; i < count; ++i) { ++f.Progress.Value; Application.DoEvents(); CPolicyData aic = new CPolicyData(); aic.version = br.ReadInt32(); aic.ID = br.ReadInt32(); int ccount = br.ReadInt32(); for (int j = 0; j < ccount; ++j) { CTriggerData ctd = new CTriggerData(); ctd.version = br.ReadInt32(); ctd.uID = br.ReadInt32(); ctd.bActive = br.ReadBoolean(); ctd.bRun = br.ReadBoolean(); ctd.bAttackValid = br.ReadBoolean(); ctd.szName = br.ReadBytes(128); ctd.rootConditon = LoadCondition(br); int pcount = br.ReadInt32(); for (int k = 0; k < pcount; ++k) { CTriggerDataOperation ctdo = new CTriggerDataOperation(); ctdo.iType = br.ReadInt32(); ctdo.pParam = Operations.Read(br, ctdo.iType, ctd.version); ctdo.iTargetType = br.ReadInt32(); if (ctdo.iTargetType == 6) { ctdo.pTargetParam = br.ReadInt32(); } else { ctdo.pTargetParam = 0; } ctd.listOperation.Add(ctdo); } aic.CTD.Add(ctd); } ai.controllers.Add(aic); } f.Progress.Value = 0; br.Close(); return(ai); }
public void Save(string path, AIPolicy ai, MainForm f) { f.Progress.Maximum = ai.controllers.Count; BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write)); bw.Write(ai.header); bw.Write(ai.controllers.Count); for (int i = 0; i < ai.controllers.Count; ++i) { ++f.Progress.Value; Application.DoEvents(); bw.Write(ai.controllers[i].version); bw.Write(ai.controllers[i].ID); bw.Write(ai.controllers[i].CTD.Count); for (int j = 0; j < ai.controllers[i].CTD.Count; ++j) { bw.Write(ai.controllers[i].CTD[j].version); bw.Write(ai.controllers[i].CTD[j].uID); bw.Write(ai.controllers[i].CTD[j].bActive); bw.Write(ai.controllers[i].CTD[j].bRun); bw.Write(ai.controllers[i].CTD[j].bAttackValid); bw.Write(ai.controllers[i].CTD[j].szName); SaveCondition(bw, ai.controllers[i].CTD[j].rootConditon); bw.Write(ai.controllers[i].CTD[j].listOperation.Count); for (int k = 0; k < ai.controllers[i].CTD[j].listOperation.Count; ++k) { bw.Write(ai.controllers[i].CTD[j].listOperation[k].iType); Operations.Write(bw, ai.controllers[i].CTD[j].listOperation[k].iType, ai.controllers[i].CTD[j].version, ai.controllers[i].CTD[j].listOperation[k].pParam); bw.Write(ai.controllers[i].CTD[j].listOperation[k].iTargetType); if (ai.controllers[i].CTD[j].listOperation[k].iTargetType == 6) { bw.Write(ai.controllers[i].CTD[j].listOperation[k].pTargetParam); } } } } f.Progress.Value = 0; bw.Close(); MessageBox.Show("Сохранено"); }