Beispiel #1
0
                void fillDictionary(Dictionary <string, string> dictionary, string locfilepath, string text_filter, string key_filter)
                {
                    EsfLibraryExtension.IFilter filter = null;
                    if (text_filter != null)
                    {
                        filter = new EsfLibraryExtension.TextFilter(text_filter);
                    }

                    foreach (var vd in locDBs)
                    {
                        try
                        {
                            LocFile locfile = getlocfile(vd, locfilepath);
                            if (filter == null)
                            {
                                locfile.fillDictionary(dictionary, key_filter);
                            }
                            else
                            {
                                locfile.fillDictionary(dictionary, key_filter, filter);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
        public Dictionary <string, string> Text(string version)
        {
            lock (_dataPack)
            {
                var loc_files = _localPack[version].Select(p => p.Root.GetSubdirectory("text")?.GetSubdirectory("db"))
                                .Where(d => d != null)
                                .SelectMany(d => d.Files);

                LocFile result = null;
                foreach (var file in loc_files)
                {
                    byte[] data = file.Data;
                    using (MemoryStream stream = new MemoryStream(data, 0, data.Length))
                    {
                        var locFile = LocCodec.Instance.Decode(stream);
                        if (result == null)
                        {
                            result = locFile;
                        }
                        else
                        {
                            result.Entries.AddRange(locFile.Entries);
                        }
                    }
                }

                // Reverse so older entries have priority so Mod overhauls take effect (I think... :P)
                result?.Entries.Reverse();
                var dict = result?.Entries.Distinct(new LocEntryComparer()).ToDictionary(e => e.Tag, e => e.Localised);

                return(dict);
            }
        }
        public byte[] Process(PackedFile file)
        {
            byte[]       result;
            MemoryStream stream = new MemoryStream();

            using (var writer = new StreamWriter(stream)) {
                LocFile locFile = LocCodec.Instance.Decode(file.Data);
                locFile.Export(writer);
                result = stream.ToArray();
            }
            return(result);
        }
Beispiel #4
0
 public static void fillDictionary(this LocFile locFile, Dictionary <string, string> dictionary, string key_filter)
 {
     foreach (var entry in locFile.Entries)
     {
         string key = entry.Tag;
         if (key_filter != "")
         {
             key = key.Replace(key_filter, "");
         }
         string locstring = entry.Localised;
         dictionary[key] = locstring;
     }
 }
Beispiel #5
0
                LocFile getlocfile(VirtualDirectory locdb, string name)
                {
                    PackEntry  fileEntry   = locdb.GetEntry(name);
                    PackedFile encodedFile = null;

                    if (fileEntry == null)
                    {
                        throw new KeyNotFoundException(name + " not found in localisation database");
                    }
                    encodedFile = (PackedFile)fileEntry;
                    LocFile decodedFile = LocCodec.Instance.Decode(encodedFile.Data);

                    return(decodedFile);
                }
        public Dictionary <string, string> Text(string version, string name)
        {
            var key = $"{version}_{name}";

            lock (_dataPack)
            {
                if (_loadedLocFiles.ContainsKey(key))
                {
                    return(_loadedLocFiles[key]);
                }

                var loc_files = _localPack[version].Select(p => p.Root.GetSubdirectory("text")?.GetSubdirectory("db"))
                                .Where(d => d != null)
                                .SelectMany(d => d.Files.Where(f => f.Name.StartsWith(name)));

                LocFile result = null;
                foreach (var file in loc_files)
                {
                    byte[] data = file.Data;
                    using (MemoryStream stream = new MemoryStream(data, 0, data.Length))
                    {
                        var locFile = LocCodec.Instance.Decode(stream);
                        if (result == null)
                        {
                            result = locFile;
                        }
                        else
                        {
                            result.Entries.AddRange(locFile.Entries);
                        }
                    }
                }

                var dict = result?.Entries.ToDictionary(e => e.Tag.Replace(name + "_", ""), e => e.Localised);

                _loadedLocFiles[key] = dict;

                return(dict);
            }
        }