Ejemplo n.º 1
0
        public async Task <bool> ExecutePlugin(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 import directory";

            string dir = await ofd.ShowAsync(win);

            if (dir != null && dir != string.Empty)
            {
                ImportBatch            dialog     = new ImportBatch(workspace, selection, dir, ".png");
                List <ImportBatchInfo> batchInfos = await dialog.ShowDialog <List <ImportBatchInfo> >(win);

                bool success = await ImportTextures(win, batchInfos);

                if (success)
                {
                    //some of the assets may not get modified, but
                    //uabe still makes replacers for those anyway
                    foreach (AssetContainer cont in selection)
                    {
                        byte[] savedAsset = cont.TypeInstance.WriteToByteArray();

                        var replacer = new AssetsReplacerFromMemory(
                            0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                        workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetContainer> selection)
        {
            AssetContainer cont = selection[0];

            AssetTypeValueField texBaseField = TextureHelper.GetByteArrayTexture(workspace, cont).GetBaseField();
            TextureFile         texFile      = TextureFile.ReadTextureFile(texBaseField);
            EditDialog          dialog       = new EditDialog(texFile.m_Name, texFile, texBaseField);
            bool saved = await dialog.ShowDialog <bool>(win);

            if (saved)
            {
                byte[] savedAsset = texBaseField.WriteToByteArray();

                var replacer = new AssetsReplacerFromMemory(
                    0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset);

                workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        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);
        }