public async Task <bool> SingleExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { AssetContainer cont = selection[0]; AssetTypeValueField texBaseField = TextureHelper.GetByteArrayTexture(workspace, cont).GetBaseField(); TextureFile texFile = TextureFile.ReadTextureFile(texBaseField); SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Save texture"; sfd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "PNG file", Extensions = new List <string>() { "png" } } }; sfd.InitialFileName = $"{texFile.m_Name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.png"; string file = await sfd.ShowAsync(win); if (file != null && file != string.Empty) { string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}"; //bundle resS if (!GetResSTexture(texFile, cont)) { string resSName = Path.GetFileName(texFile.m_StreamData.path); await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: resS was detected but {resSName} was not found in bundle"); return(false); } byte[] data = TextureHelper.GetRawTextureBytes(texFile, cont.FileInstance); if (data == null) { string resSName = Path.GetFileName(texFile.m_StreamData.path); await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: resS was detected but {resSName} was not found on disk"); return(false); } bool success = TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat); if (!success) { string texFormat = ((TextureFormat)texFile.m_TextureFormat).ToString(); await MessageBoxUtil.ShowDialog(win, "Error", $"[{errorAssetName}]: Failed to decode texture format {texFormat}"); } return(success); } return(false); }
public async Task <bool> BatchExport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { for (int i = 0; i < selection.Count; i++) { selection[i] = new AssetContainer(selection[i], TextureHelper.GetByteArrayTexture(workspace, selection[i])); } OpenFolderDialog ofd = new OpenFolderDialog(); ofd.Title = "Select export directory"; string dir = await ofd.ShowAsync(win); if (dir != null && dir != string.Empty) { StringBuilder errorBuilder = new StringBuilder(); foreach (AssetContainer cont in selection) { string errorAssetName = $"{Path.GetFileName(cont.FileInstance.path)}/{cont.PathId}"; AssetTypeValueField texBaseField = cont.TypeInstance.GetBaseField(); TextureFile texFile = TextureFile.ReadTextureFile(texBaseField); //0x0 texture, usually called like Font Texture or smth if (texFile.m_Width == 0 && texFile.m_Height == 0) { continue; } string file = Path.Combine(dir, $"{texFile.m_Name}-{Path.GetFileName(cont.FileInstance.path)}-{cont.PathId}.png"); //bundle resS if (!GetResSTexture(texFile, cont)) { string resSName = Path.GetFileName(texFile.m_StreamData.path); errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found in bundle"); continue; } byte[] data = TextureHelper.GetRawTextureBytes(texFile, cont.FileInstance); if (data == null) { string resSName = Path.GetFileName(texFile.m_StreamData.path); errorBuilder.AppendLine($"[{errorAssetName}]: resS was detected but {resSName} was not found on disk"); continue; } bool success = TextureImportExport.ExportPng(data, file, texFile.m_Width, texFile.m_Height, (TextureFormat)texFile.m_TextureFormat); if (!success) { string texFormat = ((TextureFormat)texFile.m_TextureFormat).ToString(); errorBuilder.AppendLine($"[{errorAssetName}]: Failed to decode texture format {texFormat}"); continue; } } if (errorBuilder.Length > 0) { string[] firstLines = errorBuilder.ToString().Split('\n').Take(20).ToArray(); string firstLinesStr = string.Join('\n', firstLines); await MessageBoxUtil.ShowDialog(win, "Some errors occurred while exporting", firstLinesStr); } return(true); } return(false); }