Exemplo n.º 1
0
        /// <summary>Function to determine if a directory exists or not.</summary>
        /// <param name="path">The path to the directory/</param>
        /// <returns>
        ///   <b>true</b> if the directory exists, <b>false</b> if not.</returns>
        public bool DirectoryExists(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(false);
            }

            path = path.FormatDirectory('/');

            return(_fileSystem.DirectoryExists(path));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to show the tool form.
        /// </summary>
        private void ShowForm()
        {
            FormExtract         _form   = null;
            GorgonTexture2DView texture = null;
            Stream fileStream           = null;
            ExtractSpriteToolSettings settings;
            IGorgonImage image = null;
            IContentFile textureFile;

            CommonServices.BusyService.SetBusy();

            try
            {
                settings = ToolPlugInService.ReadContentSettings <ExtractSpriteToolSettings>(typeof(ExtractSpriteToolPlugIn).FullName);

                if (settings == null)
                {
                    settings = new ExtractSpriteToolSettings();
                }

                textureFile = _fileManager.SelectedFile;
                fileStream  = textureFile.OpenRead();

                texture = GorgonTexture2DView.FromStream(GraphicsContext.Graphics, fileStream, _defaultImageCodec, options: new GorgonTexture2DLoadOptions
                {
                    Name          = "Extractor Texture Atlas",
                    Binding       = TextureBinding.ShaderResource,
                    Usage         = ResourceUsage.Default,
                    IsTextureCube = false
                });

                image = texture.Texture.ToImage();

                fileStream.Dispose();

                if (string.IsNullOrWhiteSpace(settings.LastOutputDir))
                {
                    settings.LastOutputDir = Path.GetDirectoryName(textureFile.Path).FormatDirectory('/');
                }
                else
                {
                    if (!_fileManager.DirectoryExists(settings.LastOutputDir.FormatDirectory('/')))
                    {
                        settings.LastOutputDir = Path.GetDirectoryName(textureFile.Path).FormatDirectory('/');
                    }
                }

                _extractData.Value.Texture   = texture;
                _extractData.Value.SkipEmpty = settings.AllowEmptySpriteSkip;
                _extractData.Value.SkipColor = new GorgonColor(settings.SkipColor);

                var extractViewModel = new Extract();
                extractViewModel.Initialize(new ExtractParameters(settings,
                                                                  _extractData.Value,
                                                                  textureFile,
                                                                  new ExtractorService(GraphicsContext.Renderer2D, _fileManager,
                                                                                       new GorgonV3SpriteBinaryCodec(GraphicsContext.Renderer2D)),
                                                                  new ColorPickerService(),
                                                                  FolderBrowser,
                                                                  CommonServices));

                _form = new FormExtract();
                _form.SetupGraphics(GraphicsContext);
                _form.SetDataContext(extractViewModel);
                _form.ShowDialog(GorgonApplication.MainForm);

                ToolPlugInService.WriteContentSettings(typeof(ExtractSpriteToolPlugIn).FullName, settings);
            }
            catch (Exception ex)
            {
                CommonServices.MessageDisplay.ShowError(ex, Resources.GOREST_ERR_LAUNCH);
            }
            finally
            {
                _form?.Dispose();
                fileStream?.Dispose();
                image?.Dispose();
                texture?.Dispose();
                CommonServices.BusyService.SetIdle();
            }
        }