public string GetString() { if (RawData == null) { return(null); } else { var str = Encoding.UTF8.GetString(RawData); str = ReplaceNewLine.Replace(str, "\r\n"); return(str); } }
private static SwayController LoadSwayController([NotNull] string filePath) { SwayController result = null; const string swayEnds = "_sway"; var manager = new AssetsManager(); manager.LoadFiles(filePath); foreach (var assetFile in manager.assetsFileList) { foreach (var obj in assetFile.Objects) { if (obj.type != ClassIDType.TextAsset) { continue; } var textAsset = obj as TextAsset; if (textAsset == null) { throw new ArgumentNullException(nameof(textAsset), "Sway data is null."); } if (!textAsset.m_Name.EndsWith(swayEnds)) { continue; } var raw = textAsset.m_Script; var str = Encoding.UTF8.GetString(raw); str = ReplaceNewLine.Replace(str, "\n"); result = SwayAsset.Parse(str); break; } } return(result); }
private void BtnSelectCostumesDatabase_Click(object sender, EventArgs e) { ofd.FileName = string.Empty; ofd.CheckFileExists = true; ofd.ValidateNames = true; ofd.ShowReadOnly = false; ofd.ReadOnlyChecked = false; ofd.Filter = "Costume Database (chara_costume_release.json)|chara_costume_release.json|Costume Database (chara_costume_release.unity3d)|chara_costume_release.unity3d"; var r = ofd.ShowDialog(this); if (r == DialogResult.Cancel) { return; } var selectedFilterIndex = ofd.FilterIndex; var filePath = ofd.FileName; string jsonText = null; switch (selectedFilterIndex) { case 1: jsonText = File.ReadAllText(filePath); break; case 2: { var manager = new AssetsManager(); manager.LoadFiles(filePath); foreach (var assetFile in manager.assetsFileList) { foreach (var preloadData in assetFile.Objects) { if (preloadData.type != ClassIDType.TextAsset) { continue; } var textAsset = preloadData as TextAsset; if (textAsset != null) { var raw = textAsset.m_Script; var str = Encoding.UTF8.GetString(raw); str = ReplaceNewLine.Replace(str, Environment.NewLine); jsonText = str; } break; } } if (string.IsNullOrWhiteSpace(jsonText)) { MessageBox.Show("The file selected does not contain costume data.", ApplicationHelper.GetApplicationTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } break; } default: throw new ArgumentOutOfRangeException(nameof(selectedFilterIndex)); } var obj = JsonConvert.DeserializeObject(jsonText); var costumes = new List <(int IdolID, string Idol, string Main, string Variation, string Category, int Number, string DirPost)>(); try { var root = (JObject)obj; var costumeArray = (JArray)root["costumes"]; var idols = MltdConstants.Idols.ToArray(); foreach (var c in costumeArray) { var category = c["category"].Value <string>(); var dirPost = c["dir_post"].Value <string>(); var number = Convert.ToInt32(c["number"].Value <string>()); var charaBase = (JObject)c["characters"]; // Means: "CharacterId","BodyVariation","HeadModelType","HeadCategory","HeadNumber" var charas = (JArray)charaBase["characters"]; foreach (var chara in charas) { var values = (JArray)chara["values"]; var charaResID = values[0].Value <string>(); var variation = values[1].Value <string>(); var charaID = Convert.ToInt32(charaResID.Substring(0, 3)); var charaAbbr = charaResID.Substring(3, 3); var idolIndex = Array.FindIndex(idols, idol => idol.IdolID == charaID); if (idolIndex < 0) { Debug.Print("Failed to find idol with idol ID: {0}, abbr: {1}", charaID, charaAbbr); } var idolName = idols[idolIndex].Name; var entry = (charaID, idolName, charaResID, variation, category, number, dirPost); costumes.Add(entry); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), ApplicationHelper.GetApplicationTitle(), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } costumes.Sort((v1, v2) => { var cr = v1.IdolID.CompareTo(v2.IdolID); if (cr != 0) { return(cr); } cr = string.CompareOrdinal(v1.Main, v2.Main); if (cr != 0) { return(cr); } cr = string.CompareOrdinal(v1.Category, v2.Category); if (cr != 0) { return(cr); } return(v1.Number.CompareTo(v2.Number)); }); txtCostumesDatabasePath.Text = filePath; _costumeList.AddRange(costumes.Select(c => (c.Idol, c.Main, c.Variation, c.Category, c.Number, c.DirPost))); lvwCostumes.Items.Clear(); foreach (var costume in costumes) { var lvi = lvwCostumes.Items.Add(costume.Idol); lvi.SubItems.Add(costume.Main); lvi.SubItems.Add(costume.Variation); lvi.SubItems.Add(costume.Category); lvi.SubItems.Add(costume.Number.ToString()); lvi.SubItems.Add(costume.DirPost); } lvwCostumes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); }