private async void BtnImportRaw_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e) { if (await FailIfNothingSelected()) { return; } OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open"; ofd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "Raw Unity Asset", Extensions = new List <string>() { "dat" } } }; string[] fileList = await ofd.ShowAsync(this); if (fileList.Length == 0) { return; } string file = fileList[0]; if (file != null && file != string.Empty) { using (FileStream fs = File.OpenRead(file)) { AssetFileInfoEx selectedInfo = GetSelectedInfo(); long selectedId = selectedInfo.index; AssetImportExport importer = new AssetImportExport(); byte[] bytes = importer.ImportRawAsset(fs); AssetsReplacer replacer = AssetImportExport.CreateAssetReplacer(assetsFile.file, selectedInfo, bytes); newAssets[selectedId] = replacer; newAssetDatas[selectedId] = new MemoryStream(bytes); SetSelectedFieldModified(); modified = true; } } }
private async void BtnImportDump_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e) { if (await FailIfNothingSelected()) { return; } OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open"; ofd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "UABE text dump", Extensions = new List <string>() { "txt" } }, new FileDialogFilter() { Name = "UABE json dump", Extensions = new List <string>() { "json" } } }; string[] fileList = await ofd.ShowAsync(this); if (fileList.Length == 0) { return; } string file = fileList[0]; if (file != null && file != string.Empty) { if (file.EndsWith(".json")) { await MessageBoxUtil.ShowDialog(this, "Not implemented", "There's no json dump support yet, sorry."); return; } using (FileStream fs = File.OpenRead(file)) using (StreamReader sr = new StreamReader(fs)) { AssetFileInfoEx selectedInfo = GetSelectedInfo(); long selectedId = selectedInfo.index; AssetImportExport importer = new AssetImportExport(); byte[]? bytes = importer.ImportTextAsset(sr); if (bytes == null) { await MessageBoxUtil.ShowDialog(this, "Parse error", "Something went wrong when reading the dump file."); return; } AssetsReplacer replacer = AssetImportExport.CreateAssetReplacer(assetsFile.file, selectedInfo, bytes); newAssets[selectedId] = replacer; newAssetDatas[selectedId] = new MemoryStream(bytes); SetSelectedFieldModified(); modified = true; } } }