Beispiel #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;
            }
        }
Beispiel #2
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;
            }
        }
Beispiel #3
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;
            }
        }