private void ExecuteConvertAllTexturesTo8BppCommand()
        {
            BusyIndicatorService.Run(dispatcher =>
            {
                string fileName = FileDialogService.GetOpenOptFileName();

                if (fileName == null)
                {
                    return;
                }

                string directory = System.IO.Path.GetDirectoryName(fileName);

                BusyIndicatorService.Notify("Converting all textures to 8 bpp...");

                var message = Messenger.Instance.Notify(new MessageBoxMessage(string.Concat("The textures of all OPTs in \"", directory, "\" will be converted to 8 bpp.\nDo you want to continue?"), "Converting textures", MessageBoxButton.YesNo, MessageBoxImage.Warning));

                if (message.Result != MessageBoxResult.Yes)
                {
                    return;
                }

                foreach (string file in System.IO.Directory.GetFiles(directory, "*.opt"))
                {
                    BusyIndicatorService.Notify(string.Concat("Converting ", System.IO.Path.GetFileName(file), " to 8 bpp..."));

                    OptFile opt = null;

                    try
                    {
                        opt = OptFile.FromFile(file);
                    }
                    catch (System.IO.InvalidDataException)
                    {
                        continue;
                    }

                    if (opt.TexturesBitsPerPixel == 8)
                    {
                        continue;
                    }

                    opt.ConvertTextures32To8();
                    opt.Save(opt.FileName);
                }

                BusyIndicatorService.Notify("Converting all textures to 8 bpp completed.");

                Messenger.Instance.Notify(new MessageBoxMessage("Converting all textures to 8 bpp completed.", "Converting textures"));
            });
        }
Example #2
0
        public static unsafe void WriteOptFunction(IntPtr ptr)
        {
            if (ptr == IntPtr.Zero || _tempOptFile == null || _tempOptFileSize == 0)
            {
                _tempOptFile     = null;
                _tempOptFileSize = 0;
                return;
            }

            using (var stream = new UnmanagedMemoryStream((byte *)ptr, _tempOptFileSize, _tempOptFileSize, FileAccess.Write))
            {
                _tempOptFile.Save(stream, false, false);
            }

            _tempOptFile     = null;
            _tempOptFileSize = 0;
        }