public static List <R_modify> ini2list(string inifilename) { try { inireader sfeini = new inireader(inifilename); int TypeNumber = sfeini.ReadIniInt("R_Modify", "TypeNumber"); List <R_modify> R_ini = new List <R_modify>(); for (int num = 0; num < TypeNumber; num++) { R_modify Rmtmp = new R_modify(); Rmtmp.typeName = sfeini.ReadIniString("R_Modify", "TypeName" + num.ToString()); Rmtmp.ListR = new List <R_dataType>(); int TypeDataItem = sfeini.ReadIniInt("R_Modify", "TypeDataItem" + num.ToString()); for (int i = 0; i < TypeDataItem; i++) { string tmpstr = sfeini.ReadIniString("R_Modify", string.Format("data({0},{1})", num, i)); string[] splitstr = tmpstr.Split(' '); R_dataType Rtmp = new R_dataType(); //煞笔般的分割导入 Rtmp.dataNum = splitstr[0].ToString(); Rtmp.dataStructNum = splitstr[1].ToString(); Rtmp.byteNum = splitstr[2].ToString(); Rtmp.isString = splitstr[3].ToString(); Rtmp.isName = splitstr[4].ToString(); Rtmp.dataType = splitstr[5].ToString(); Rtmp.nameStr = splitstr[6].ToString(); Rtmp.DescriptionStr = splitstr[7].ToString(); Rmtmp.ListR.Add(Rtmp); } R_ini.Add(Rmtmp); } return(R_ini); } catch (Exception ee) { return(null); } }
public static List <RdataType> ReadRanger(Stream filegrp, string fileidx, string inifilepath) { //try { List <inilist.R_modify> rini = inilist.ini2list(inifilepath); List <RdataType> RMem = new List <RdataType>(); inireader sfeini = new inireader(inifilepath); string codetype = sfeini.ReadIniString("R_Modify", "StringCodeType", "big5"); //readidx List <int> rindex = new List <int>(); using (FileStream fs = new FileStream(fileidx, FileMode.Open)) using (BinaryReader br = new BinaryReader(fs)) { rindex.Add((int)0); for (int i = 0; i < fs.Length / 4 - 1; i++) { rindex.Add(br.ReadInt32()); } } //calc rini int[] Rlong = new int[rini.Count]; for (int i = 0; i < rini.Count; i++) { for (int j = 0; j < rini[i].ListR.Count; j++) { Rlong[i] += int.Parse(rini[i].ListR[j].dataNum) * int.Parse(rini[i].ListR[j].dataStructNum) * int.Parse(rini[i].ListR[j].byteNum); } } //readgrp //using (FileStream fs = new FileStream(RfilePath.GRPfilename, FileMode.Open)) using (BinaryReader br = new BinaryReader(filegrp)) { rindex.Add((int)filegrp.Length); for (int i = 0; i < rindex.Count - 1; i++) { RdataType Rdata = new RdataType(); Rdata.Rdata0 = new List <Rdata0Type>(); long tmpIndex = (long)rindex[i]; Rdata.TypeName = rini[i].typeName; int tmpRdataNum = (int)(((long)rindex[i + 1] - tmpIndex) / Rlong[i]); for (int rnum = 0; rnum < tmpRdataNum; rnum++) { Rdata0Type Rdata0 = new Rdata0Type(); Rdata0.Rbyte = new List <RbyteType>(); Rdata0.keyNameIndex = -1; for (int ptrRiniIndex = 0; ptrRiniIndex < rini[i].ListR.Count; ptrRiniIndex += 0) { if (rini[i].ListR[ptrRiniIndex].isName == "1") { Rdata0.keyNameIndex = Rdata0.Rbyte.Count; } int tmpdatanum = int.Parse(rini[i].ListR[ptrRiniIndex].dataNum); int tmpdataStructNum = int.Parse(rini[i].ListR[ptrRiniIndex].dataStructNum); for (int j = 0; j < tmpdatanum; j++) { for (int k = 0; k < tmpdataStructNum; k++) { RbyteType Rtmp = new RbyteType(); switch (rini[i].ListR[ptrRiniIndex + k].isString) { //int case "0": Rtmp.dataType = datatypeenum.int_data; Rtmp.data = (int)br.ReadInt16(); break; //str case "1": Rtmp.dataType = datatypeenum.string_data; string dataTradional = string.Empty; switch (codetype.ToLower()) { case "big5": dataTradional = sfeadd.Str.Big5ToUnicode(br.ReadBytes( int.Parse(rini[i].ListR[ptrRiniIndex + k].byteNum)) ).Trim(); break; case "gbk": dataTradional = sfeadd.Str.GBKToUnicode(br.ReadBytes( int.Parse(rini[i].ListR[ptrRiniIndex + k].byteNum)) ).Trim(); break; } //Rtmp.data = sfeadd.Str.TraditionToSimple(dataTradional); Rtmp.data = dataTradional; break; case "2": Rtmp.dataType = datatypeenum.uint_data; Rtmp.data = (uint)br.ReadUInt16(); break; default: break; } Rtmp.dataNum = int.Parse(rini[i].ListR[ptrRiniIndex + k].byteNum); Rtmp.TypeDef = int.Parse(rini[i].ListR[ptrRiniIndex + k].dataType); Rtmp.dataName = string.Format(rini[i].ListR[ptrRiniIndex + k].nameStr, j); Rtmp.descriptionStr = rini[i].ListR[ptrRiniIndex + k].DescriptionStr; Rdata0.Rbyte.Add(Rtmp); tmpIndex += int.Parse(rini[i].ListR[ptrRiniIndex + k].byteNum); } } ptrRiniIndex += int.Parse(rini[i].ListR[ptrRiniIndex].dataStructNum); } Rdata.Rdata0.Add(Rdata0); } RMem.Add(Rdata); } } filegrp.Close(); return(RMem); } //catch { //return null; } }