From b0ac1ade7fcde04f15384a329a0eca5ae9ed5065 Mon Sep 17 00:00:00 2001 From: emmauss Date: Tue, 6 Jul 2021 19:07:23 +0000 Subject: [PATCH] Add portable screenshot folder (#2447) * add portable screenshot folder * fix style Co-authored-by: Ac_K Co-authored-by: Ac_K --- Ryujinx/Ui/RendererWidgetBase.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Ryujinx/Ui/RendererWidgetBase.cs b/Ryujinx/Ui/RendererWidgetBase.cs index dee5cbb6c9..d74cfec10c 100644 --- a/Ryujinx/Ui/RendererWidgetBase.cs +++ b/Ryujinx/Ui/RendererWidgetBase.cs @@ -310,7 +310,7 @@ namespace Ryujinx.Ui private unsafe void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e) { - if (e.Data.Length > 0) + if (e.Data.Length > 0 && e.Height > 0 && e.Width > 0) { Task.Run(() => { @@ -318,10 +318,24 @@ namespace Ryujinx.Ui { var currentTime = DateTime.Now; string filename = $"ryujinx_capture_{currentTime.Year}-{currentTime.Month:D2}-{currentTime.Day:D2}_{currentTime.Hour:D2}-{currentTime.Minute:D2}-{currentTime.Second:D2}.png"; - string directory = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "Ryujinx"); - string path = System.IO.Path.Combine(directory, filename); + string directory = AppDataManager.Mode switch + { + AppDataManager.LaunchMode.Portable => System.IO.Path.Combine(AppDataManager.BaseDirPath, "screenshots"), + _ => System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "Ryujinx") + }; - Directory.CreateDirectory(directory); + string path = System.IO.Path.Combine(directory, filename); + + try + { + Directory.CreateDirectory(directory); + } + catch (Exception ex) + { + Logger.Error?.Print(LogClass.Application, $"Failed to create directory at path {directory}. Error : {ex.GetType().Name}", "Screenshot"); + + return; + } Image image = e.IsBgra ? Image.LoadPixelData(e.Data, e.Width, e.Height) : Image.LoadPixelData(e.Data, e.Width, e.Height); @@ -347,6 +361,10 @@ namespace Ryujinx.Ui } }); } + else + { + Logger.Error?.Print(LogClass.Application, $"Screenshot is empty. Size : {e.Data.Length} bytes. Resolution : {e.Width}x{e.Height}", "Screenshot"); + } } public void Render()