Exemplo n.º 1
0
        private async void BtnImport_Click(object?sender, RoutedEventArgs e)
        {
            if (bundleInst != null)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title = "Open";

                string[] files = await ofd.ShowAsync(this);

                if (files.Length == 0)
                {
                    return;
                }

                string file = files[0];

                if (file == null)
                {
                    return;
                }

                byte[] fileBytes = File.ReadAllBytes(file);
                string fileName  = Path.GetFileName(file);

                newFiles[fileName] = AssetImportExport.CreateBundleReplacer(fileName, true, fileBytes);

                //todo handle overwriting
                comboItems.Add(new ComboBoxItem()
                {
                    Content = fileName,
                    Tag     = comboItems.Count
                });
                comboBox.SelectedIndex = comboItems.Count - 1;
            }
        }
Exemplo n.º 2
0
        private async void BtnExportRaw_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (await FailIfNothingSelected())
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title   = "Save As";
            sfd.Filters = new List <FileDialogFilter>()
            {
                new FileDialogFilter()
                {
                    Name = "Raw Unity Asset", Extensions = new List <string>()
                    {
                        "dat"
                    }
                }
            };
            string file = await sfd.ShowAsync(this);

            if (file != null && file != string.Empty)
            {
                using (FileStream fs = File.OpenWrite(file))
                {
                    AssetImportExport dumper = new AssetImportExport();
                    dumper.DumpRawAsset(fs, assetsFile.file, GetSelectedInfo());
                }
            }
        }
Exemplo n.º 3
0
        private void InfoWindow_Closing(object?sender, System.ComponentModel.CancelEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            InfoWindow window = (InfoWindow)sender;

            if (window.Workspace.fromBundle && window.ChangedAssetsDatas != null)
            {
                List <Tuple <AssetsFileInstance, byte[]> > assetDatas = window.ChangedAssetsDatas;

                //file that user initially selected
                AssetsFileInstance firstFile = window.Workspace.LoadedFiles[0];

                foreach (var tup in assetDatas)
                {
                    AssetsFileInstance fileInstance = tup.Item1;
                    byte[]             assetData    = tup.Item2;

                    string assetName = Path.GetFileName(fileInstance.path);

                    //only modify assets file we opened for now
                    if (fileInstance != firstFile)
                    {
                        continue;
                    }

                    BundleReplacer replacer = AssetImportExport.CreateBundleReplacer(assetName, true, assetData);
                    newFiles[assetName] = replacer;

                    //replace existing assets file in the manager
                    AssetsFileInstance?inst = am.files.FirstOrDefault(i => i.name.ToLower() == assetName.ToLower());
                    string             assetsManagerName;

                    if (inst != null)
                    {
                        assetsManagerName = inst.path;
                        am.files.Remove(inst);
                    }
                    else //shouldn't happen
                    {
                        //we always load bundles from file, so this
                        //should always be somewhere on the disk
                        assetsManagerName = Path.Combine(bundleInst.path, assetName);
                    }

                    MemoryStream assetsStream = new MemoryStream(assetData);
                    am.LoadAssetsFile(assetsStream, assetsManagerName, true);
                }

                changesUnsaved = true;
                changesMade    = true;
            }
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
        private async void BtnExportDump_Click(object?sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (await FailIfNothingSelected())
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title   = "Save As";
            sfd.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 file = await sfd.ShowAsync(this);

            if (file != null && file != string.Empty)
            {
                if (file.EndsWith(".json"))
                {
                    await MessageBoxUtil.ShowDialog(this, "Not implemented", "There's no json dump support yet, sorry. Exporting as .txt anyway.");

                    file = file.Substring(0, file.Length - 5) + ".txt";
                }

                using (FileStream fs = File.OpenWrite(file))
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        AssetImportExport dumper = new AssetImportExport();
                        dumper.DumpTextAsset(sw, GetSelectedField());
                    }
            }
        }
Exemplo n.º 6
0
        private void InfoWindowClosing(object?sender, System.ComponentModel.CancelEventArgs e)
        {
            if (sender == null)
            {
                return;
            }

            InfoWindow window    = (InfoWindow)sender;
            string     assetName = window.AssetsFileName;

            if (window.FinalAssetData != null)
            {
                byte[] assetData = window.FinalAssetData;

                BundleReplacer replacer = AssetImportExport.CreateBundleReplacer(assetName, true, assetData);
                newFiles[assetName] = replacer;

                //replace existing assets file in the manager
                AssetsFileInstance?inst = am.files.FirstOrDefault(i => i.name.ToLower() == assetName.ToLower());
                string             assetsManagerName;

                if (inst != null)
                {
                    assetsManagerName = inst.name;
                    am.files.Remove(inst);
                }
                else //shouldn't happen
                {
                    //we always load bundles from file, so this
                    //should always be somewhere on the disk
                    assetsManagerName = Path.Combine(bundleInst.path, assetName);
                }

                MemoryStream assetsStream = new MemoryStream(assetData);
                am.LoadAssetsFile(assetsStream, assetsManagerName, true);

                modified = true;
            }
        }
Exemplo n.º 7
0
        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;
                    }
            }
        }