using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Xml; namespace fmtxml { public partial class FmtFileToXml { private bool _DoingFields = false; private int NumBoxes = 0; private int NumTexts = 0; private int NumFields = 0; private int CountForLists = 0; public void PsiIniToXml(ref FormatData fmtdata, string path) { string sLine; StreamReader myReader = new StreamReader(path);// Open file while ((sLine = myReader.ReadLine()) != null)// read line-by-line { try { if (sLine.Length > 0) { switch (sLine.Substring(0, 1)) { case "[": if (sLine.Contains("[OBJECT COUNT]")) { // read in the count of objects - these may not be in order, fix this: sLine = myReader.ReadLine(); int indx = sLine.IndexOf("="); string tmp = sLine.Substring(indx + 1, sLine.Length - indx - 1); NumBoxes = Convert.ToInt32(tmp); sLine = myReader.ReadLine(); indx = sLine.IndexOf("="); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); NumTexts = Convert.ToInt32(tmp); sLine = myReader.ReadLine(); indx = sLine.IndexOf("="); tmp = sLine.Substring(indx + 1, sLine.Length -indx - 1); NumFields = Convert.ToInt32(tmp); fmtdata.ProcData.Psi.Boxes = new PsiBox[NumBoxes]; fmtdata.ProcData.Psi.Labels = new PsiLabel[NumTexts]; fmtdata.ProcData.Psi.Fields = new PsiField[NumFields]; break; } if (sLine.Contains("[DIALOG]") || sLine.Contains("[BOXES]") || sLine.Contains("[TEXT]") || sLine.Contains("[FIELDS]")) { _DoingFields = sLine.Contains("[FIELDS]"); CountForLists = 0; break; } break; case ";": break; default: if (sLine.IndexOf("=") >= 0) { AddParam(ref fmtdata, sLine); } break; } } } catch (Exception ex) { Console.WriteLine(string.Format("error parsing .INI file: {0}, message: {1}", path, ex.Message)); } } myReader.Close(); } private void AddParam(ref FormatData fmtdata, string sParam) { int i = sParam.IndexOf("="); string attrname = sParam.Substring(0, i); if (attrname.Contains("SIZE")) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; string sb = sParam.Substring(i + 1, end - i - 1); string[] split = sb.Split(new char[] { ',' }); fmtdata.ProcData.Psi.x = Convert.ToInt32(split[0].Trim()); fmtdata.ProcData.Psi.y = Convert.ToInt32(split[1].Trim()); return; } if (attrname.Contains("FONT")) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; string sb = sParam.Substring(i + 1, end - i - 1); string[] split = sb.Split(new char[] { ',' }); fmtdata.ProcData.Psi.font = split[0].Trim(); return; } if (attrname.Contains("CAPTION")) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; fmtdata.ProcData.Psi.Caption = sParam.Substring(i + 1, end-i-1).Replace("\"",""); return; } if (attrname.Contains("BUTTONSONBOTTOM")) { int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; fmtdata.ProcData.Psi.ButtonsOnBottom = sParam.Substring(i + 1, end - i - 1); return; } if (attrname.Contains("BOX")) { // int end = (sParam.IndexOf(";") > -1) ? sParam.IndexOf(";") : sParam.Length; string sb = sParam.Substring(i + 1, end - i - 1); string[] split = sb.Split(new char[] { ',' }); fmtdata.ProcData.Psi.Boxes[CountForLists].style = split[0].Trim(); fmtdata.ProcData.Psi.Boxes[CountForLists].x = Convert.ToInt32(split[1].Trim()); fmtdata.ProcData.Psi.Boxes[CountForLists].y = Convert.ToInt32(split[2].Trim()); fmtdata.ProcData.Psi.Boxes[CountForLists].width = Convert.ToInt32(split[3].Trim()); fmtdata.ProcData.Psi.Boxes[CountForLists].height = Convert.ToInt32(split[4].Trim()); CountForLists++; return; } if (attrname.Contains("TEXT")) { //