public static void Fill(String filePath, TxtEntry[] entries, Dictionary <Int32, String> locationNames)
        {
            if (entries.IsNullOrEmpty())
            {
                return;
            }

            if (filePath.LastIndexOf("Names of Other", StringComparison.OrdinalIgnoreCase) > 0)
            {
                foreach (TxtEntry entry in entries)
                {
                    locationNames[entry.Index] = entry.Value;
                }
            }
            else
            {
                TxtEntry firstEntry = entries[0];
                locationNames[firstEntry.Index] = firstEntry.Value;

                String prefix = firstEntry.Value + '/';
                for (Int32 i = 1; i < entries.Length; i++)
                {
                    TxtEntry entry = entries[i];
                    locationNames[entry.Index] = prefix + entry.Value;
                }
            }
        }
        public TxtEntry[] Build(String name, String[] lines)
        {
            String          postfix = '$' + name + '_';
            List <TxtEntry> entries = new List <TxtEntry>(lines.Length);

            for (Int32 i = 0; i < lines.Length; i++)
            {
                String   key;
                String   line  = GetLine(lines, ref i);
                TxtEntry entry = new TxtEntry {
                    Index = entries.Count, Prefix = postfix
                };
                if (line == String.Empty)
                {
                    entry.Value = String.Empty;
                }
                else if (!Cache.TryGetValue(line, out key))
                {
                    key = StringsFormatter.FormatKeyIndex(postfix, entries.Count);
                    Cache.Add(line, key);
                    entry.Value = FormatValue(name, line);
                }
                else
                {
                    entry.Value = '{' + key + '}';
                }
                entries.Add(entry);
            }
            return(entries.ToArray());
        }
Exemple #3
0
 public static TxtEntry[] Build(String prefix, String[] abilityNames, String[] abilityHelps)
 {
     TxtEntry[] abilities = new TxtEntry[Math.Max(abilityNames.Length, abilityHelps.Length)];
     for (int i = 0; i < abilities.Length; i++)
     {
         String name = i < abilityNames.Length ? abilityNames[i] : String.Empty;
         String help = i < abilityHelps.Length ? abilityHelps[i] : String.Empty;
         abilities[i] = Build(prefix, name, help);
     }
     return(abilities);
 }
Exemple #4
0
 public static TxtEntry[] Build(String prefix, String[] value)
 {
     TxtEntry[] abilities = new TxtEntry[value.Length];
     for (int i = 0; i < abilities.Length; i++)
     {
         abilities[i] = new TxtEntry {
             Prefix = prefix, Value = value[i]
         }
     }
     ;
     return(abilities);
 }
Exemple #5
0
 public static TxtEntry[] Build(String prefix, String[] itemNames, String[] itemHelps, String[] itemBattle)
 {
     TxtEntry[] abilities = new TxtEntry[Math.Max(itemNames.Length, itemHelps.Length)];
     for (int i = 0; i < abilities.Length; i++)
     {
         String name = i < itemNames.Length ? itemNames[i] : String.Empty;
         String help = i < itemHelps.Length ? itemHelps[i] : String.Empty;
         String bttl = i < itemBattle.Length ? itemBattle[i] : String.Empty;
         abilities[i] = Build(prefix, name, help, bttl);
     }
     return(abilities);
 }
 private static void AddEntry(String[] parts, Int32 index, LinkedList <TxtEntry> list)
 {
     if (parts.Length > 1)
     {
         TxtEntry entry = new TxtEntry {
             Prefix = Prefix, Index = index, Value = parts[1]
         };
         list.AddLast(entry);
     }
     else
     {
         list.First.Value.Prefix = Prefix;
         list.First.Value.Index  = index;
     }
 }
Exemple #7
0
        private TxtEntry[] Reverse(String[] general)
        {
            if (general == null)
            {
                return(null);
            }

            TxtEntry[] array = new TxtEntry[general.Length];
            for (Int32 i = 0; i < general.Length; i++)
            {
                array[i] = new TxtEntry {
                    Index = i, Prefix = '{' + general[i] + '}', Value = general[i]
                }
            }
            ;
            return(array);
        }
        private static LinkedList <TxtEntry> GetList(Dictionary <String, LinkedList <TxtEntry> > dic, String fileName)
        {
            LinkedList <TxtEntry> list;

            if (dic.TryGetValue(fileName, out list))
            {
                return(list);
            }

            list = new LinkedList <TxtEntry>();
            dic.Add(fileName, list);

            TxtEntry entry = new TxtEntry {
                Prefix = RootPrefix, Index = dic.Count, Value = fileName
            };

            list.AddLast((TxtEntry)entry);
            return(list);
        }
Exemple #9
0
        public TxtEntry[] Read(out String name)
        {
            using (StreamReader sr = new StreamReader(_input, Encoding.UTF8, true, 4096))
            {
                name = sr.ReadLine();

                if (_formatter is StringsFormatter) // TEMP
                {
                    name = name.Substring(2, name.Length - 4);
                }

                string countStr = sr.ReadLine();
                if (_formatter is StringsFormatter) // TEMP
                {
                    countStr = countStr.Substring(2, countStr.Length - 4);
                }
                int        count  = int.Parse(countStr, CultureInfo.InvariantCulture);
                TxtEntry[] result = new TxtEntry[count];

                int offset = 0;
                for (int i = 0; i < count && !sr.EndOfStream; i++)
                {
                    TxtEntry entry = _formatter.Read(sr);
                    if (entry == null)
                    {
                        offset++;
                        continue;
                    }

                    if (String.IsNullOrEmpty(entry.Prefix))
                    {
                        Log.Warning("Неверная запись [Line: {0}, Value: {1}] в файле: {2}", i, entry, name);
                        offset++;
                        continue;
                    }

                    result[i - offset] = entry;
                }

                return(result);
            }
        }
        public static TxtEntry[] Build(String prefix, String[] itemNames, String[] itemHelps, String[] itemDescriptions)
        {
            List <TxtEntry> abilities = new List <TxtEntry>(80);

            for (Int32 i = 0; i < itemNames.Length; i++)
            {
                String name = i < itemNames.Length ? itemNames[i] : String.Empty;
                if (String.IsNullOrEmpty(name))
                {
                    continue;
                }

                String   help  = i < itemHelps.Length ? itemHelps[i] : String.Empty;
                String   desc  = i < itemDescriptions.Length ? itemDescriptions[i] : String.Empty;
                TxtEntry entry = Build(prefix, name, help, desc);
                entry.Index = i;
                abilities.Add(entry);
            }
            return(abilities.ToArray());
        }
Exemple #11
0
        public void Write(String name, TxtEntry[] entries)
        {
            using (StreamWriter sw = new StreamWriter(_output, Encoding.UTF8, 4096))
            {
                if (_formatter is StringsFormatter) // TEMP
                {
                    sw.WriteLine("/*" + name + "*/");
                    sw.WriteLine("/*" + entries.Length.ToString("D4", CultureInfo.InvariantCulture) + "*/");
                }
                else
                {
                    sw.WriteLine(name);
                    sw.WriteLine(entries.Length.ToString("D4", CultureInfo.InvariantCulture));
                }

                for (Int32 i = 0; i < entries.Length; i++)
                {
                    TxtEntry entry = entries[i];
                    entry.TryUpdateIndex(i);
                    _formatter.Write(sw, entry);
                }
            }
        }
        public TxtEntry Read(StreamReader sr)
        {
            Int32    index  = -1;
            TxtEntry result = new TxtEntry();

            StringBuilder sb     = new StringBuilder(512);
            Boolean       key    = true;
            Boolean       block  = false;
            Boolean       escape = false;
            Int32         line   = 0;

            while (true)
            {
                Int32 value = sr.Read();
                if (value < 0)
                {
                    if (sb.Length == 0)
                    {
                        return(null);
                    }

                    throw Exceptions.CreateException("Неожиданный конец потока.");
                }

                Char ch = (Char)value;
                switch (ch)
                {
                case '\\':
                {
                    if (!block)
                    {
                        continue;
                    }

                    if (escape)
                    {
                        sb.Append('\\');
                        escape = false;
                    }
                    else
                    {
                        escape = true;
                    }
                    break;
                }

                case '"':
                {
                    if (escape)
                    {
                        sb.Append('"');
                        escape = false;
                    }
                    else
                    {
                        if (block)
                        {
                            if (key)
                            {
                                if (sb.Length > 4)
                                {
                                    result.Prefix = sb.ToString(0, sb.Length - 4);
                                }

                                index = Int32.Parse(sb.ToString(sb.Length - 4, 4), CultureInfo.InvariantCulture);
                                key   = false;
                            }
                            else
                            {
                                result.Index = index;
                                result.Value = sb.ToString();
                                return(result);
                            }
                            block     = false;
                            sb.Length = 0;
                        }
                        else
                        {
                            block = true;
                        }
                    }
                    break;
                }

                case '\r':
                {
                    if (!block)
                    {
                        continue;
                    }

                    break;
                }

                case '\n':
                {
                    if (!block)
                    {
                        continue;
                    }

                    line++;
                    break;
                }

                default:
                {
                    if (!block)
                    {
                        continue;
                    }

                    if (escape)
                    {
                        sb.Append('\\');
                        escape = false;
                    }

                    if (line > 0)
                    {
                        for (Int32 i = 0; i < line; i++)
                        {
                            sb.Append('\n');
                        }
                        line = 0;
                    }

                    sb.Append(ch);
                    break;
                }
                }
            }
        }
 public void Write(StreamWriter sw, TxtEntry entry)
 {
     sw.WriteLine("\"{0}\" = \"{1}\";",
                  FormatKeyIndex(entry.Prefix, entry.Index),
                  entry.Value.Replace("\\", "\\\\").Replace("\"", "\\\""));
 }