コード例 #1
0
ファイル: AssetViewer.cs プロジェクト: Assistant/QuestStopgap
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (_fileProvider != null)
     {
         _fileProvider.Dispose();
     }
 }
コード例 #2
0
ファイル: AssetViewer.cs プロジェクト: Assistant/QuestStopgap
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            ContextMenu cm = new ContextMenu(new MenuItem[]
            {
                new MenuItem("APK", (s, e2) =>
                {
                    OpenFileDialog ofd = new OpenFileDialog()
                    {
                        CheckFileExists = true,
                        Title           = "Open Bundle File",
                        Multiselect     = false
                    };
                    if (ofd.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    CloseStuff();
                    try
                    {
                        _fileProvider = new ApkAssetsFileProvider(ofd.FileName, FileCacheMode.Memory, false);
                        _manager      = new AssetsManager(_fileProvider, BSConst.KnownFiles.AssetsRootPath, BSConst.GetAssetTypeMap());
                        if (_fileProvider.FindFiles("globalgamemanagers").Count > 0)
                        {
                            _manager.GetAssetsFile("globalgamemanagers.assets");
                        }
                        if (_fileProvider.FindFiles("globalgamemanagers.assets*").Count > 0)
                        {
                            _manager.GetAssetsFile("globalgamemanagers.assets");
                        }
                        _manager.FindAndLoadAllAssets();
                        FillAssetsFiles();
                        this.Text = "Assets Explorer - " + Path.GetFileName(ofd.FileName);
                    }
                    catch (Exception ex)
                    {
                        Log.LogErr("Couldn't load APK!", ex);
                        MessageBox.Show("Failed to load!");
                        if (_fileProvider != null)
                        {
                            _fileProvider.Dispose();
                            _fileProvider = null;
                        }
                        return;
                    }
                }),
                new MenuItem("Folder", (s, e2) =>
                {
                    FolderBrowserDialog fbd = new FolderBrowserDialog()
                    {
                        ShowNewFolderButton = false,
                        Description         = "Select Assets Root Folder"
                    };
                    if (fbd.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    CloseStuff();
                    try
                    {
                        _fileProvider = new FolderFileProvider(fbd.SelectedPath, false);
                        _manager      = new AssetsManager(_fileProvider, "", BSConst.GetAssetTypeMap());
                        if (_fileProvider.FindFiles("globalgamemanagers").Count > 0)
                        {
                            _manager.GetAssetsFile("globalgamemanagers.assets");
                        }
                        if (_fileProvider.FindFiles("globalgamemanagers.assets*").Count > 0)
                        {
                            _manager.GetAssetsFile("globalgamemanagers.assets");
                        }
                        _manager.FindAndLoadAllAssets();
                        FillAssetsFiles();
                        this.Text = "Assets Explorer - " + Path.GetFileName(fbd.SelectedPath);
                    }
                    catch (Exception ex)
                    {
                        Log.LogErr("Couldn't load APK!", ex);
                        MessageBox.Show("Failed to load!");
                        if (_fileProvider != null)
                        {
                            _fileProvider.Dispose();
                            _fileProvider = null;
                        }
                        return;
                    }
                }),
                new MenuItem("Bundle", (s, e2) =>
                {
                    OpenFileDialog ofd = new OpenFileDialog()
                    {
                        CheckFileExists = true,
                        Title           = "Open Bundle File",
                        Multiselect     = false
                    };
                    if (ofd.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    CloseStuff();
                    try
                    {
                        _fileProvider = new BundleFileProvider(ofd.FileName, true);
                        _manager      = new AssetsManager(_fileProvider, "", BSConst.GetAssetTypeMap());
                        _manager.FindAndLoadAllAssets();
                        FillAssetsFiles();
                        this.Text = "Assets Explorer - " + Path.GetFileName(ofd.FileName);
                    }
                    catch (Exception ex)
                    {
                        Log.LogErr("Couldn't load bundle!", ex);
                        MessageBox.Show("Failed to load!");
                        if (_fileProvider != null)
                        {
                            _fileProvider.Dispose();
                            _fileProvider = null;
                        }
                        return;
                    }
                })
            });

            cm.Show(btnLoad, new Point(0, btnLoad.Height));
            return;
        }