public override void ReadRow(SharedTableData.SharedTableEntry keyEntry, CsvReader reader) { if (m_ImportTable == null) { return; } // Get the entry or create one StringTableEntry entry = m_ImportTable.GetEntry(keyEntry.Id) ?? m_ImportTable.AddEntry(keyEntry.Id, string.Empty); // Get the metadata or add one var metadata = entry.GetMetadata <MyCustomDataMetadata>(); if (metadata == null) { metadata = new MyCustomDataMetadata(); entry.AddMetadata(metadata); } if (m_SomeValueIndex != -1) { metadata.someValue = reader.GetField(m_SomeValueIndex); } if (m_SomeOtherValueIndex != -1) { metadata.someOtherValue = reader.GetField <int>(m_SomeOtherValueIndex); } }
static void SplitQuestionnaireRecord(string text, string key, StringTable targetTable, bool overwriteExistingKeys, ref int copiedNew, ref int copiedOverwrite) { string[] splitText = text.Split('{'); if (splitText == null || splitText.Length == 0) { Debug.LogErrorFormat("SplitQuestionnaireRecord() found 0 entries.", key); return; } for (int i = 0; i < splitText.Length; i++) { string itemKey = string.Format("{0}.{1}", key, i); string itemText = splitText[i]; // Discard any empty records and trailing markup end record if (string.IsNullOrEmpty(itemText) || string.Compare(markupEndRecord, itemText) == 0) { continue; } var targetEntry = targetTable.GetEntry(itemKey); if (targetEntry == null) { targetTable.AddEntry(itemKey, itemText); copiedNew++; } else if (targetEntry != null && overwriteExistingKeys) { if (targetTable.RemoveEntry(itemKey)) { targetTable.AddEntry(itemKey, itemText); copiedOverwrite++; } else { Debug.LogErrorFormat("SplitQuestionnaireRecord() could not remove key '{0}'. Overwrite failed.", key); } } } }
static void ImportIntoTables(ITranslationUnitCollection unitCollection, StringTable source, StringTable target, ImportOptions importOptions = null) { var options = importOptions ?? s_DefaultOptions; var sharedTableData = target.SharedData; EditorUtility.SetDirty(sharedTableData); if (importOptions.UpdateSourceTable) { EditorUtility.SetDirty(source); } if (importOptions.UpdateTargetTable) { EditorUtility.SetDirty(target); } for (int i = 0; i < unitCollection.TranslationUnitCount; ++i) { var tu = unitCollection.GetTranslationUnit(i); var sharedTableEntry = GetOrCreateEntryFromTranslationUnit(sharedTableData, tu); AddMetadataCommentsFromNotes(tu, sharedTableEntry.Metadata, NoteType.General, options.ImportNotes); if (options.UpdateSourceTable) { var sourceEntry = source.AddEntry(sharedTableEntry.Id, tu.Source); AddMetadataCommentsFromNotes(tu, sourceEntry, NoteType.Source, options.ImportNotes); } if (options.UpdateTargetTable) { var targetEntry = target.AddEntry(sharedTableEntry.Id, tu.Target); AddMetadataCommentsFromNotes(tu, targetEntry, NoteType.Target, options.ImportNotes); } } // Nested groups if (unitCollection is IGroupCollection groupCollection) { for (int i = 0; i < groupCollection.GroupCount; ++i) { var group = groupCollection.GetGroup(i); ImportIntoTables(group, source, target, options); } } }
public static Task Read(this SourceDemo demo, StringTables frame) { var buf = frame.Buffer; int tables = buf.ReadByte(); for (int i = 0; i < tables; i++) { var name = buf.ReadString(); var table = new StringTable(name); var entries = buf.ReadInt16(); for (int j = 0; j < entries; j++) { var entry = buf.ReadString(); var data = default(byte[]); var version = default(long); var xuid = default(long); var info = default(TableInfoBase); if (buf.ReadBoolean()) { var length = buf.ReadInt16(); data = buf.ReadBytes(length); // TODO if (name == Const.INSTANCE_BASELINE_TABLENAME) { info = new InstanceBaseline() { Id = int.Parse(entry) }; } else if (name == Const.LIGHT_STYLES_TABLENAME) { } else if (name == Const.SERVER_STARTUP_DATA_TABLENAME) { } else if (name == Const.USER_INFO_TABLENAME) { var buf2 = new SourceBufferReader(data); if (demo.GameDirectory == "csgo") { // 8 bytes version = BitConverter.ToInt64(buf2.ReadBytes(8), 0); // 8 bytes xuid = BitConverter.ToInt64(buf2.ReadBytes(8), 0); } else { // 4 bytes version = buf2.ReadInt32(); // 4 bytes xuid = buf2.ReadInt32(); } info = new PlayerInfo() { // 32 bytes Name = Encoding.ASCII.GetString(buf2.ReadBytes(Const.MAX_PLAYER_NAME_LENGTH)).TrimEnd('\0'), // 4 bytes UserId = buf2.ReadInt32(), // 33 bytes Guid = Encoding.ASCII.GetString(buf2.ReadBytes(Const.SIGNED_GUID_LEN + 1)).TrimEnd('\0'), // 4 bytes FriendsId = buf2.ReadInt32(), // 32 bytes FriendsName = Encoding.ASCII.GetString(buf2.ReadBytes(Const.MAX_PLAYER_NAME_LENGTH)).TrimEnd('\0'), // 1 byte Fakeplayer = buf2.ReadBoolean(), // 1 byte IsHltv = buf2.ReadBoolean(), // 16 bytes CustomFiles = new int[4] { buf2.ReadInt32(), buf2.ReadInt32(), buf2.ReadInt32(), buf2.ReadInt32() }, // 2 bytes FilesDownloaded = buf2.ReadChar() }; } } table.AddEntry(new StringTableEntry() { Name = entry, RawData = data, Version = version, Xuid = xuid, Info = info }); } if (buf.ReadBoolean()) { var centries = buf.ReadInt16(); for (var j = 0; j < centries; j++) { var centry = buf.ReadString(); var ddata = default(byte[]); if (buf.ReadBoolean()) { var length = buf.ReadInt16(); ddata = buf.ReadBytes(length); } table.AddClientEntry(new ClientEntry() { Name = centry, RawData = ddata }); } } frame.Tables.Add(table); } return(Task.CompletedTask); }
public static void FromJSON(string apiKey = "", bool download = false) { string downloadUrl = $"https://api.crowdin.com/api/project/{projectIdentifier}/export-file?key={apiKey}"; foreach (StringTableCollection collection in LocalizationEditorSettings.GetStringTableCollections()) { string collectionName = collection.TableCollectionName; List <LocaleIdentifier> cultures = GetCulturesInfo(collection); foreach (var culture in cultures) { if (culture.Code.Equals("en")) { continue; } string folder = Path.Combine(Application.dataPath, $"Locales/{culture.Code}"); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string path = Path.Combine(folder, $"{collectionName}.json"); JSONNode json; if (download) { using (var client = new HttpClient()) { var downloadTask = client.GetAsync($"{downloadUrl}&file={collectionName}.json&language={culture.Code}"); try { downloadTask.Wait(); var stringTask = downloadTask.Result.Content.ReadAsStringAsync(); stringTask.Wait(); json = JSON.Parse(stringTask.Result); } catch (Exception) { // 404 = Import empty, anything else = skip if (downloadTask.Result.StatusCode != System.Net.HttpStatusCode.NotFound) { continue; } json = new JSONObject(); } } } else { json = GetNodeFromFile(path); } StringTable table = (StringTable)collection.GetTable(culture); table.MetadataEntries.Clear(); StringTable tableEnglish = (StringTable)collection.GetTable(CultureInfo.GetCultureInfo("en")); foreach (SharedTableData.SharedTableEntry entry in table.SharedData.Entries) { string key = entry.Key; if (json.HasKey(key)) { table.AddEntry(key, json[key]); } if (table.GetEntry(key) == null || string.IsNullOrEmpty(table.GetEntry(key).Value)) { // Add english as default table.AddEntry(key, tableEnglish.GetEntry(key).Value); } table.GetEntry(key).IsSmart = false; table.GetEntry(key).MetadataEntries.Clear(); table.GetEntry(key).IsSmart = tableEnglish.GetEntry(key).IsSmart; } EditorUtility.SetDirty(table); if (download) { Debug.Log($"Downloaded: {culture.Code} - {collectionName}.json"); } else { Debug.Log($"Loaded: {path}"); } } } AssetDatabase.SaveAssets(); }