[hatari-devel] Fwd: Improve directory handling patch

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hello everyone,

I have made my first contribution to the Hatari project : this is an improvement to the interface that allows configuring the folder containing screenshots and videos, covering the "Improve directory handling" section in doc/todo.txt

Initially, I tried to send a pull request on Framagit (by email, as it seems to be the only option available), but it did not work, I received an error message saying "You are not allowed". Perhaps it would be wise to allow PRs, as the Framagit forge supports this feature ? No matter, you will find the patch attached to this email.

I apologize in advance if this contribution does not follow the usual contribution process. I did not find any specific information on this matter and did my best to follow good practices.

If I have missed any details or if modifications are needed, please let me know. I tried to be as thorough as possible, but some things may have escaped my attention.

Thank you in advance for your time and attention.

Best regards,

Frederic Poeydomenge

From 31bdf9580aea1b2514994ae759d8a1386cf8315e Mon Sep 17 00:00:00 2001
Message-Id: <31bdf9580aea1b2514994ae759d8a1386cf8315e.1751880737.git.dyno@xxxxxxxxxxxx>
From: Dyno <dyno@xxxxxxxxxxxx>
Date: Mon, 7 Jul 2025 11:28:15 +0200
Subject: [PATCH] config

---
 doc/todo.txt                 | 11 --------
 src/avi_record.c             | 16 ++++++++++--
 src/configuration.c          | 10 ++++++++
 src/gui-sdl/dlgScreen.c      | 50 ++++++++++++++++++++++++++----------
 src/includes/configuration.h |  1 +
 src/screenSnapShot.c         | 20 +++++++--------
 6 files changed, 71 insertions(+), 37 deletions(-)

diff --git a/doc/todo.txt b/doc/todo.txt
index b7841730..e593772e 100644
--- a/doc/todo.txt
+++ b/doc/todo.txt
@@ -226,16 +226,5 @@ on BerliOS hatari-devel mail thread for more info.)
 		- simpler / faster (LED) overlay handling
 	- Include some fancy zooming routines like 2xSaI or Super-Eagle
 
-- Improve directory handling:
-	- Currently screenshots & anim go always to current dir,
-	  whereas memsave, sound recording, printer & midi & serial &
-	  output and log output go to file specified in config file.
-	  There should be support for setting also anim/screenshot
-	  directory / file name from config file (needs change also
-	  in screenSnapShot.c).
-	- By default the directory config values should be empty in
-	  which case the code will at run-time decide to use current
-	  directory, but not modify the path config setting.
-
 - Add Hatari "fileid" to more files (to ease locating "stolen" code)
   and Git hook to remove trailing whitespace (sed -i 's/[\t ]*$//')?
diff --git a/src/avi_record.c b/src/avi_record.c
index d9c1e003..eceaff9d 100644
--- a/src/avi_record.c
+++ b/src/avi_record.c
@@ -1382,7 +1382,7 @@ static bool	Avi_StartRecording_WithParams ( RECORD_AVI_PARAMS *pAviParams , char
 
 
 	/* We're ok to record */
-	Log_AlertDlg ( LOG_INFO, "AVI recording has been started");
+	Log_AlertDlg ( LOG_INFO, "AVI recording has been started in %s", AviFileName );
 	bRecordingAvi = true;
 
 	return true;
@@ -1501,7 +1501,19 @@ void Avi_SetSurface(SDL_Surface *surf)
 
 bool	Avi_StartRecording_WithConfig ( void )
 {
-	return Avi_StartRecording( ConfigureParams.Video.AviRecordFile ,
+	char aviPath[FILENAME_MAX + 1];
+	if (ConfigureParams.Screen.szScreenShotDir[0])
+	{
+		snprintf(aviPath, sizeof(aviPath), "%s%c%s",
+				ConfigureParams.Screen.szScreenShotDir,
+				PATHSEP,
+				File_Basename(ConfigureParams.Video.AviRecordFile));
+	}
+	else
+	{
+		strcpy(aviPath, ConfigureParams.Video.AviRecordFile);
+	}
+	return Avi_StartRecording( aviPath ,
 				   ConfigureParams.Screen.bCrop ,
 				   ConfigureParams.Video.AviRecordFps == 0 ?
 				     ClocksTimings_GetVBLPerSec ( ConfigureParams.System.nMachineType , nScreenRefreshRate ) :
diff --git a/src/configuration.c b/src/configuration.c
index 6daab2bf..a72d91ec 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -100,6 +100,7 @@ static const struct Config_Tag configs_Screen[] =
 	{ "nZoomFactor", Float_Tag, &ConfigureParams.Screen.nZoomFactor },
 	{ "bUseSdlRenderer", Bool_Tag, &ConfigureParams.Screen.bUseSdlRenderer },
 	{ "ScreenShotFormat", Int_Tag, &ConfigureParams.Screen.ScreenShotFormat },
+	{ "szScreenShotDir", String_Tag, ConfigureParams.Screen.szScreenShotDir },
 	{ "bUseVsync", Bool_Tag, &ConfigureParams.Screen.bUseVsync },
 	{ NULL , Error_Tag, NULL }
 };
@@ -820,6 +821,7 @@ void Configuration_SetDefault(void)
 #else
 	ConfigureParams.Screen.ScreenShotFormat = SCREEN_SNAPSHOT_BMP;
 #endif
+	ConfigureParams.Screen.szScreenShotDir[0] = '\0';
 
 	/* Set defaults for Sound */
 	ConfigureParams.Sound.bEnableMicrophone = true;
@@ -1004,6 +1006,8 @@ void Configuration_Apply(bool bReset)
 	File_CleanFileName(ConfigureParams.HardDisk.szHardDiskDirectories[0]);
 	File_MakeAbsoluteName(ConfigureParams.HardDisk.szHardDiskDirectories[0]);
 	File_MakeAbsoluteName(ConfigureParams.Memory.szMemoryCaptureFileName);
+	if (strlen(ConfigureParams.Screen.szScreenShotDir) > 0)
+		File_MakeAbsoluteName(ConfigureParams.Screen.szScreenShotDir);
 	File_MakeAbsoluteName(ConfigureParams.Sound.szYMCaptureFileName);
 	if (strlen(ConfigureParams.Keyboard.szMappingFileName) > 0)
 		File_MakeAbsoluteName(ConfigureParams.Keyboard.szMappingFileName);
@@ -1052,6 +1056,12 @@ void Configuration_Apply(bool bReset)
 	else
 		DSP_Disable ();
 #endif
+
+	/* Update screenshot path if user specified one */
+	if (ConfigureParams.Screen.szScreenShotDir[0])
+	{
+		Paths_SetScreenShotDir(ConfigureParams.Screen.szScreenShotDir);
+	}
 }
 
 
diff --git a/src/gui-sdl/dlgScreen.c b/src/gui-sdl/dlgScreen.c
index ad73b272..823743ca 100644
--- a/src/gui-sdl/dlgScreen.c
+++ b/src/gui-sdl/dlgScreen.c
@@ -21,6 +21,8 @@ const char DlgScreen_fileid[] = "Hatari dlgScreen.c";
 #include "video.h"
 #include "avi_record.h"
 #include "statusbar.h"
+#include "file.h"
+#include "paths.h"
 
 /* how many pixels to increment VDI mode
  * width/height on each click
@@ -104,12 +106,13 @@ static SGOBJ monitordlg[] =
 #define DLGSCRN_FORMAT_NEO  29
 #define DLGSCRN_FORMAT_XIMG 30
 #define DLGSCRN_CROP        31
-#define DLGSCRN_CAPTURE     32
-#define DLGSCRN_RECANIM     33
-#define DLGSCRN_GPUSCALE    36
-#define DLGSCRN_RESIZABLE   37
-#define DLGSCRN_VSYNC       38
-#define DLGSCRN_EXIT_WINDOW 39
+#define DLGSCRN_CAPTURE_DIR 34
+#define DLGSCRN_CAPTURE     35
+#define DLGSCRN_RECANIM     36
+#define DLGSCRN_GPUSCALE    39
+#define DLGSCRN_RESIZABLE   40
+#define DLGSCRN_VSYNC       41
+#define DLGSCRN_EXIT_WINDOW 42
 
 /* needs to match Frame skip values in windowdlg[]! */
 static const int skip_frames[] = { 0, 1, 2, 4, AUTO_FRAMESKIP_LIMIT };
@@ -117,13 +120,14 @@ static const int skip_frames[] = { 0, 1, 2, 4, AUTO_FRAMESKIP_LIMIT };
 /* Strings for doubled resolution max width and height */
 static char sMaxWidth[5];
 static char sMaxHeight[5];
+static char sScreenShotDir[32];
 
 #define MAX_SIZE_STEP 8
 
 /* The window dialog: */
 static SGOBJ windowdlg[] =
 {
-	{ SGBOX, 0, 0, 0,0, 52,25, NULL },
+	{ SGBOX, 0, 0, 0,0, 52,28, NULL },
 	{ SGBOX,      0, 0,  1,1, 50,10, NULL },
 	{ SGTEXT,     0, 0,  4,2, 20,1, "Hatari screen options" },
 	{ SGCHECKBOX, 0, 0,  4,4, 12,1, "_Fullscreen" },
@@ -150,21 +154,24 @@ static SGOBJ windowdlg[] =
 	{ SGTEXT,     0, 0, 37,9,  4,1, sMaxHeight },
 	{ SGBUTTON,   0, 0, 43,9,  1,1, "\x03", SG_SHORTCUT_DOWN },
 
-	{ SGBOX,      0, 0,  1,12, 50,5, NULL },
+	{ SGBOX,      0, 0,  1,12, 50,8, NULL },
 	{ SGRADIOBUT, 0, 0,  5,13, 5,1, "PNG" },
 	{ SGRADIOBUT, 0, 0, 11,13, 5,1, "BMP" },
 	{ SGRADIOBUT, 0, 0, 17,13, 5,1, "NEO" },
 	{ SGRADIOBUT, 0, 0, 23,13, 5,1, "XIMG" },
 	{ SGCHECKBOX, 0, 0,  5,15, 16,1, "_Crop statusbar" },
+	{ SGTEXT,     0, 0,  5,17, 31,1, "Default screenshot directory:" },
+	{ SGTEXT,     0, 0,  5,18, 34,1, sScreenShotDir },
+	{ SGBUTTON,   0, 0, 38,17,  8,1, "Browse" },
 	{ SGBUTTON,   0, 0, 32,13, 14,1, " _Screenshot " },
 	{ SGBUTTON,   0, 0, 32,15, 14,1, NULL },      /* Record text set later */
 
-	{ SGBOX,      0, 0,  1,18, 50,4, NULL },
-	{ SGTEXT,     0, 0, 20,18, 12,1, "SDL2 options" },
-	{ SGCHECKBOX, 0, 0,  8,20, 20,1, "GPU scal_ing" },
-	{ SGCHECKBOX, 0, 0, 23,20, 20,1, "Resi_zable" },
-	{ SGCHECKBOX, 0, 0, 36,20, 11,1, "_VSync" },
-	{ SGBUTTON, SG_DEFAULT, 0, 17,23, 20,1, "Back to main menu" },
+	{ SGBOX,      0, 0,  1,21, 50,4, NULL },
+	{ SGTEXT,     0, 0, 20,21, 12,1, "SDL2 options" },
+	{ SGCHECKBOX, 0, 0,  8,23, 20,1, "GPU scal_ing" },
+	{ SGCHECKBOX, 0, 0, 23,23, 20,1, "Resi_zable" },
+	{ SGCHECKBOX, 0, 0, 36,23, 11,1, "_VSync" },
+	{ SGBUTTON, SG_DEFAULT, 0, 17,26, 20,1, "Back to main menu" },
 
 	{ SGSTOP, 0, 0, 0,0, 0,0, NULL }
 };
@@ -329,6 +336,7 @@ void Dialog_WindowDlg(void)
 {
 	int maxw, maxh, deskw, deskh, but, skip = 0;
 	unsigned int i;
+	char *selname;
 
 	SDLGui_CenterDlg(windowdlg);
 
@@ -369,6 +377,8 @@ void Dialog_WindowDlg(void)
 	sprintf(sMaxHeight, "%4i", maxh);
 
 	/* Initialize window capture options: */
+	File_CleanFileName(ConfigureParams.Screen.szScreenShotDir);
+	File_ShrinkName(sScreenShotDir, ConfigureParams.Screen.szScreenShotDir, 32);
 
 	windowdlg[DLGSCRN_FORMAT_PNG].state &= ~SG_SELECTED;
 	windowdlg[DLGSCRN_FORMAT_BMP].state &= ~SG_SELECTED;
@@ -434,6 +444,18 @@ void Dialog_WindowDlg(void)
 			sprintf(sMaxHeight, "%4i", maxh);
 			break;
 
+		 case DLGSCRN_CAPTURE_DIR:
+			selname = SDLGui_FileSelect("Screenshot Directory", sScreenShotDir, NULL, true);
+			if (selname)
+			{
+				strcpy(ConfigureParams.Screen.szScreenShotDir, selname);
+				File_CleanFileName(ConfigureParams.Screen.szScreenShotDir);
+				File_ShrinkName(sScreenShotDir, ConfigureParams.Screen.szScreenShotDir, 32);
+				Paths_SetScreenShotDir(ConfigureParams.Screen.szScreenShotDir);
+				free(selname);
+			}
+			break;
+
 		 case DLGSCRN_CAPTURE:
 			DlgScreen_SetScreenShot_Format();		/* Take latest choice into account */
 			Screen_UpdateRect(sdlscrn, 0,0,0,0);
diff --git a/src/includes/configuration.h b/src/includes/configuration.h
index 92a11fd2..0ecf1f6f 100644
--- a/src/includes/configuration.h
+++ b/src/includes/configuration.h
@@ -316,6 +316,7 @@ typedef struct
   bool bUseVsync;
   bool bUseSdlRenderer;
   int ScreenShotFormat;
+  char szScreenShotDir[FILENAME_MAX];
   float nZoomFactor;
   int nSpec512Threshold;
   int nVdiColors;
diff --git a/src/screenSnapShot.c b/src/screenSnapShot.c
index f46a9696..cbd26749 100644
--- a/src/screenSnapShot.c
+++ b/src/screenSnapShot.c
@@ -549,9 +549,9 @@ void ScreenSnapShot_SaveScreen(void)
 	{
 		sprintf(szFileName,"%s/grab%4.4d.bmp", Paths_GetScreenShotDir(), nScreenShots);
 		if (SDL_SaveBMP(sdlscrn, szFileName))
-			fprintf(stderr, "BMP screen dump failed!\n");
+			Log_Printf(LOG_WARN, "BMP screen dump failed!");
 		else
-			fprintf(stderr, "BMP screen dump saved to: %s\n", szFileName);
+			Log_Printf(LOG_INFO, "BMP screen dump saved to: %s", szFileName);
 		free(szFileName);
 		return;
 	}
@@ -562,9 +562,9 @@ void ScreenSnapShot_SaveScreen(void)
 	{
 		sprintf(szFileName,"%s/grab%4.4d.png", Paths_GetScreenShotDir(), nScreenShots);
 		if (ScreenSnapShot_SavePNG(sdlscrn, szFileName) > 0)
-			fprintf(stderr, "PNG screen dump saved to: %s\n", szFileName);
+			Log_Printf(LOG_INFO, "PNG screen dump saved to: %s", szFileName);
 		else
-			fprintf(stderr, "PNG screen dump failed!\n");
+			Log_Printf(LOG_WARN, "PNG screen dump failed!");
 		free(szFileName);
 		return;
 	}
@@ -575,9 +575,9 @@ void ScreenSnapShot_SaveScreen(void)
 	{
 		sprintf(szFileName,"%s/grab%4.4d.neo", Paths_GetScreenShotDir(), nScreenShots);
 		if (ScreenSnapShot_SaveNEO(szFileName) > 0)
-			fprintf(stderr, "NEO screen dump saved to: %s\n", szFileName);
+			Log_Printf(LOG_INFO, "NEO screen dump saved to: %s", szFileName);
 		else
-			fprintf(stderr, "NEO screen dump failed!\n");
+			Log_Printf(LOG_WARN, "NEO screen dump failed!");
 		free(szFileName);
 		return;
 	}
@@ -586,18 +586,18 @@ void ScreenSnapShot_SaveScreen(void)
 	{
 		sprintf(szFileName,"%s/grab%4.4d.ximg", Paths_GetScreenShotDir(), nScreenShots);
 		if (ScreenSnapShot_SaveXIMG(szFileName) > 0)
-			fprintf(stderr, "XMIG screen dump saved to: %s\n", szFileName);
+			Log_Printf(LOG_INFO, "XIMG screen dump saved to: %s", szFileName);
 		else
-			fprintf(stderr, "XIMG screen dump failed!\n");
+			Log_Printf(LOG_WARN, "XIMG screen dump failed!");
 		free(szFileName);
 		return;
 	}
 
 	sprintf(szFileName,"%s/grab%4.4d.bmp", Paths_GetScreenShotDir(), nScreenShots);
 	if (SDL_SaveBMP(sdlscrn, szFileName))
-		fprintf(stderr, "Screen dump failed!\n");
+		Log_Printf(LOG_WARN, "Screen dump failed!");
 	else
-		fprintf(stderr, "Screen dump saved to: %s\n", szFileName);
+		Log_Printf(LOG_INFO, "Screen dump saved to: %s", szFileName);
 
 	free(szFileName);
 }
-- 
2.39.5



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/