Ejemplo n.º 1
0
        public async Task ExecuteSelectFile(FileModel model)
        {
            if (model == null)
            {
                return;
            }

            if (State is DockState.AutoHidden or DockState.Hidden)
            {
                return;
            }

            if (canShowPrev)
            {
                PE_SelectedItem = model;
            }
            else
            {
                return;
            }
            PE_MeshPreviewVisible = false;
            IsAudioPreviewVisible = false;
            IsImagePreviewVisible = false;
            IsVideoPreviewVisible = false;

            // check additional changes
            if (model.IsDirectory)
            {
                return;
            }

            if (PE_SelectedItem == null)
            {
                return;
            }
            // string.Equals(model.GetExtension(), ERedExtension.bk2.ToString(), StringComparison.OrdinalIgnoreCase) ||
            if (!(string.Equals(model.GetExtension(), ERedExtension.mesh.ToString(), StringComparison.OrdinalIgnoreCase) ||
                  string.Equals(model.GetExtension(), ERedExtension.wem.ToString(), StringComparison.OrdinalIgnoreCase) ||
                  string.Equals(model.GetExtension(), ERedExtension.xbm.ToString(), StringComparison.OrdinalIgnoreCase) ||
                  Enum.TryParse <EConvertableOutput>(PE_SelectedItem.GetExtension(), out _) ||
                  Enum.TryParse <EUncookExtension>(PE_SelectedItem.GetExtension(), out _)
                  )
                )
            {
                return;
            }

            if (PE_SelectedItem != null)
            {
                if (PE_SelectedItem.GetExtension().Length > 0)
                {
                    //if (string.Equals(PE_SelectedItem.GetExtension(), ERedExtension.bk2.ToString(),
                    //   System.StringComparison.OrdinalIgnoreCase))
                    //{
                    //    IsVideoPreviewVisible = true;
                    //    SetExeCommand?.Invoke("test.exe | test2.bk2 /J /I2 /P");
                    //}


                    if (Enum.IsDefined(typeof(EConvertableOutput), PE_SelectedItem.GetExtension()))
                    {
                        PE_MeshPreviewVisible = true;

                        LoadModel(PE_SelectedItem.FullName);
                    }



                    if (string.Equals(PE_SelectedItem.GetExtension(), ERedExtension.mesh.ToString(),
                                      System.StringComparison.OrdinalIgnoreCase))
                    {
                        PE_MeshPreviewVisible = true;

                        var q = _meshTools.ExportMeshWithoutRigPreviewer(PE_SelectedItem.FullName, Path.Combine(ISettingsManager.GetManagerCacheDir(), "Temp_OBJ"));
                        if (q.Length > 0)
                        {
                            LoadModel(q);
                        }
                    }

                    if (string.Equals(PE_SelectedItem.GetExtension(), ERedExtension.wem.ToString(),
                                      System.StringComparison.OrdinalIgnoreCase))
                    {
                        IsAudioPreviewVisible = true;

                        AddAudioItem(PE_SelectedItem.FullName);
                    }

                    // textures
                    if (Enum.TryParse <EUncookExtension>(PE_SelectedItem.GetExtension(),
                                                         out _))
                    {
                        IsImagePreviewVisible = true;

                        var q = await ImageDecoder.RenderToBitmapSource(PE_SelectedItem.FullName);

                        if (q != null)
                        {
                            var g = BitmapFrame.Create(q);
                            LoadImage(g);
                        }
                    }

                    // xbm
                    if (string.Equals(PE_SelectedItem.GetExtension(), ERedExtension.xbm.ToString(),
                                      System.StringComparison.OrdinalIgnoreCase))
                    {
                        IsImagePreviewVisible = true;
                        var man = ServiceLocator.Default.ResolveType <ModTools>();

                        // convert xbm to dds stream
                        await using var ddsstream  = new MemoryStream();
                        await using var filestream = new FileStream(PE_SelectedItem.FullName,
                                                                    FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, FileOptions.SequentialScan);
                        man.ConvertXbmToDdsStream(filestream, ddsstream, out _);

                        // try loading it in pfim
                        try
                        {
                            var qa = await ImageDecoder.RenderToBitmapSourceDds(ddsstream);

                            if (qa != null)
                            {
                                LoadImage(qa);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            DecideForMeshPreview();
        }