public async Task <bool> BatchImport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { 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); foreach (ImportBatchInfo batchInfo in batchInfos) { AssetContainer cont = batchInfo.cont; AssetTypeValueField baseField = workspace.GetBaseField(cont); string file = batchInfo.importFile; byte[] byteData = File.ReadAllBytes(file); baseField.Get("m_Script").GetValue().Set(byteData); byte[] savedAsset = baseField.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); }
public async Task <bool> SingleImport(Window win, AssetWorkspace workspace, List <AssetContainer> selection) { AssetContainer cont = selection[0]; OpenFileDialog ofd = new OpenFileDialog(); AssetTypeValueField baseField = workspace.GetBaseField(cont); ofd.Title = "Open text file"; ofd.Filters = new List <FileDialogFilter>() { new FileDialogFilter() { Name = "TXT file", Extensions = new List <string>() { "txt" } } }; string[] fileList = await ofd.ShowAsync(win); if (fileList.Length == 0) { return(false); } string file = fileList[0]; if (file != null && file != string.Empty) { byte[] byteData = File.ReadAllBytes(file); baseField.Get("m_Script").GetValue().Set(byteData); byte[] savedAsset = baseField.WriteToByteArray(); var replacer = new AssetsReplacerFromMemory( 0, cont.PathId, (int)cont.ClassId, cont.MonoId, savedAsset); workspace.AddReplacer(cont.FileInstance, replacer, new MemoryStream(savedAsset)); } return(false); }
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); }
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); }
public async Task <bool> ExecutePlugin(Window win, AssetWorkspace workspace, List <AssetExternal> selection) { AssetExternal tex = selection[0]; AssetTypeValueField texBaseField = tex.instance.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, tex.info.index, (int)tex.info.curFileType, AssetHelper.GetScriptIndex(tex.file.file, tex.info), savedAsset); workspace.AddReplacer(tex.file, replacer, new MemoryStream(savedAsset)); return(true); } return(false); }