private string JinnReplaceCommands(string str, MsgStringItem msi) { string cmd; int cnt; int i1, i2; int b; while ((i1 = str.IndexOf('{') + 1) > 0) if ((i2 = str.IndexOf('}', i1)) > -1) { cmd = str.Substring(i1, i2 - i1); switch (cmd[0]) { case 'v': //+ msi.commands.Add(new CommandItem(string.Format("F203{0:x2}01", Convert.ToByte(cmd.Substring(1, cmd.Length - 1))))); break; case 'c': //+ msi.commands.Add(new CommandItem(string.Format("F202{0:x2}01", Convert.ToByte(cmd.Substring(1, cmd.Length - 1))))); break; case 'N': if (cmd == "Name") //+ msi.commands.Add(new CommandItem("F10B")); else goto default; break; case 'V': b = Convert.ToByte(cmd.Substring(5, cmd.Length - 5)); if (b == 1) //+ msi.commands.Add(new CommandItem("F31A01010201")); else if (b == 2) //+ msi.commands.Add(new CommandItem("F31A03010401")); else goto default; break; case 'I': b = Convert.ToByte(cmd.Substring(4, cmd.Length - 4)); if (b == 1) //+ msi.commands.Add(new CommandItem("F31A04010301")); else if (b == 2) //+ msi.commands.Add(new CommandItem("F31A04010501")); else goto default; break; case 'S': if (cmd == "Sayonara") //+ msi.commands.Add(new CommandItem("F22C0101")); else if ((b = cmd.IndexOf(',') + 1) > 0) //+ msi.commands.Add(new CommandItem(string.Format("F31A{0:x2}01{1:x2}01", Convert.ToByte(cmd.Substring(3, b - 4)) + 0x0d, Convert.ToByte(cmd.Substring(b, cmd.Length - b))))); else goto default; break; case 'C': //+ msi.commands.Add(new CommandItem(string.Format("F22E{0:x2}01", Convert.ToByte(cmd.Substring(4, cmd.Length - 4))))); break; case 'P': msi.commands.Add(new CommandItem(string.Format("F21D{0}", cmd.Substring(5, cmd.Length - 5)))); break; case 'T': //+ msi.commands.Add(new CommandItem(string.Format("F219{0:x2}01", Convert.ToByte(cmd.Substring(5, cmd.Length - 5))))); break; case 'H': //+ msi.commands.Add(new CommandItem(string.Format("F214{0:x2}01", Convert.ToByte(cmd.Substring(4, cmd.Length - 4))))); break; default: if (cmd == "LastName") //+ msi.commands.Add(new CommandItem("F10A")); else if (cmd == "FullName") //+ msi.commands.Add(new CommandItem("F10C")); else if (cmd == "Date") //+ msi.commands.Add(new CommandItem("F138")); else throw new ArgumentException(string.Format("Unknown command: {0}", cmd)); break; } str = str.Substring(0, i1 - 1) + CommandItem.CommandChar + str.Substring(++i2, str.Length - i2); } cnt = 0; while ((i1 = str.IndexOf('[') + 1) > 0) if ((i2 = str.IndexOf(']', i1)) > -1) { cmd = str.Substring(i1, i2 - i1); if (cmd.Length % 2 == 0) msi.commands.Add(new CommandItem(cmd)); else throw new ArgumentException(string.Format("Unknown command: {0}", cmd)); str = str.Substring(0, i1 - 1) + CommandItem.CommandChar + str.Substring(++i2, str.Length - i2); cnt++; } if (cnt != str.Length) str += '\n'; return str; }
public void JinnLoadText() { jinnMainState mainState; jinnTextState textState; MsgTextItem mti; MsgStringItem msi; string s = reader.strRead.ReadLine(); int pp; names = new string[0]; mainState = jinnMainState.na; textState = jinnTextState.na; mti = null; msi = null; while (s != null) { //s = System.Text.Encoding.Unicode.GetString(System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.Unicode, System.Text.Encoding.UTF8.GetBytes(s))); if (s.Length > 0) { if (s[0] == '#') mainState = JinnGetMainState(s, mainState); else if (!JinnIsComment(s)) // & s[1] != '/') switch (mainState) { case jinnMainState.files: break; case jinnMainState.texts: switch (textState) { case jinnTextState.names: Array.Resize<string>(ref names, names.Length + 1); names[names.Length - 1] = (s.EndsWith("\\e")) ? s.Substring(0, s.Length - 0x2) : s; break; case jinnTextState.msgs: if (mti.isSelection) { msi.orgText += JinnReplaceCommands((s.EndsWith("\\e")) ? s.Substring(0, s.Length - 0x2) : s, msi); if (s.EndsWith("\\e")) { if (msi.orgText.Length > 0) msi.orgText = msi.orgText.Substring(0, msi.orgText.Length - 0x1); msi.rusText = msi.orgText; mti.strings.Add(msi); mti.ptrCnt = (short)mti.strings.Count; msi = new MsgStringItem(); } } else if ((pp = s.IndexOf("\\p")) > -1) { msi.rusText = JinnReplaceCommands(s.Substring(0, pp), msi); if (msi.rusText.EndsWith("\n")) msi.rusText = msi.rusText.Remove(msi.rusText.Length - 1, 1); if (pp == s.Length - 0x2) msi.commands.Add(new CommandItem("F104")); else if (s[pp + 0x2] == '1') msi.commands.Add(new CommandItem("F110")); else if (s[pp + 0x2] == '2') msi.commands.Add(new CommandItem("F131")); else throw new ArgumentException(string.Format("error in string: {0}", s)); msi.orgText += msi.rusText + CommandItem.CommandChar; msi.rusText = msi.orgText; mti.strings.Add(msi); mti.ptrCnt = (short)mti.strings.Count; msi = new MsgStringItem(); } else if (s == "\\e") { msi.rusText = msi.orgText; mti.strings.Add(msi); mti.ptrCnt = (short)mti.strings.Count; msi = new MsgStringItem(); } else msi.orgText += JinnReplaceCommands(s, msi); break; default: textState = JinnGetTextState(s, textState); if (textState == jinnTextState.msgs) { mti = new MsgTextItem(); mti.textId = JinnGetValue(s, 0).Remove(0, 2); mti.isSelection = JinnGetValue(s, 2)[0] == '1'; if (!mti.isSelection) mti.nameIdx = Convert.ToInt16(JinnGetValue(s, 1)); texts.Add(mti); msi = new MsgStringItem(); break; } break; } //switch (textState) break; default: break; } //switch (mainState) } else textState = jinnTextState.na; s = reader.strRead.ReadLine(); } }