Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

screenshots: use subdirectories for the date and include the title ID #1488

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions sysmodules/rosalina/source/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <3ds.h>
#include <3ds/os.h>
#include "pmdbgext.h"
#include "menus.h"
#include "menu.h"
#include "draw.h"
Expand Down Expand Up @@ -371,7 +372,8 @@ void RosalinaMenu_TakeScreenshot(void)
IFile file;
Result res = 0;

char filename[64];
char directory[32];
char filename[90];

FS_Archive archive;
FS_ArchiveID archiveId;
Expand All @@ -397,15 +399,6 @@ void RosalinaMenu_TakeScreenshot(void)
Draw_GetCurrentScreenInfo(&bottomWidth, &is3d, false);
Draw_GetCurrentScreenInfo(&topWidth, &is3d, true);

res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, ""));
if(R_SUCCEEDED(res))
{
res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/luma/screenshots"), 0);
if((u32)res == 0xC82044BE) // directory already exists
res = 0;
FSUSER_CloseArchive(archive);
}

u32 seconds, minutes, hours, days, year, month;
u64 milliseconds = osGetTime();
seconds = milliseconds/1000;
Expand Down Expand Up @@ -449,23 +442,51 @@ void RosalinaMenu_TakeScreenshot(void)
days++;
month++;

sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_top.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
TRY(RosalinaMenu_WriteScreenshot(&file, topWidth, true, true));
TRY(IFile_Close(&file));
res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, ""));
if(R_SUCCEEDED(res))
{
sprintf(directory, "/luma/screenshots");
char dirName[16];
#define CREATE_SUBDIR(length, name) do { \
sprintf(dirName, "/%0" #length "lu", name); \
strcat(directory, dirName); \
res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, directory), 0); \
if((u32)res == 0xC82044BE) /* directory already exists */ \
res = 0; \
} while(false)

CREATE_SUBDIR(4, year);
CREATE_SUBDIR(2, month);
CREATE_SUBDIR(2, days);

#undef CREATE_SUBDIR

FSUSER_CloseArchive(archive);
}

sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_bot.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
TRY(RosalinaMenu_WriteScreenshot(&file, bottomWidth, false, true));
TRY(IFile_Close(&file));
FS_ProgramInfo programInfo;
u32 unused;
res = PMDBG_GetCurrentAppInfo(&programInfo, &unused, &unused);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized there's a bug in this approach: screenshots taken of the home menu while software is suspended, and screenshots taken of applets while software is suspended, will result in the wrong title ID written. Is that an issue?


#define WRITE_SCREENSHOT(screenName, screenWidth, top, left) do { \
sprintf( \
filename, \
"%s/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_%016llx_%s.bmp", \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkpoint uses the lower 4 bytes (8 nybbles) of the program's title ID. Should I do the same here?

directory, \
year, month, days, hours, minutes, seconds, milliseconds, \
programInfo.programId, screenName); \
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE)); \
TRY(RosalinaMenu_WriteScreenshot(&file, screenWidth, top, left)); \
TRY(IFile_Close(&file)); \
} while(false)

WRITE_SCREENSHOT("top", topWidth, true, true);
WRITE_SCREENSHOT("bot", bottomWidth, false, true);

if(is3d && (Draw_GetCurrentFramebufferAddress(true, true) != Draw_GetCurrentFramebufferAddress(true, false)))
{
sprintf(filename, "/luma/screenshots/%04lu-%02lu-%02lu_%02lu-%02lu-%02lu.%03llu_top_right.bmp", year, month, days, hours, minutes, seconds, milliseconds);
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
TRY(RosalinaMenu_WriteScreenshot(&file, topWidth, true, false));
TRY(IFile_Close(&file));
}
WRITE_SCREENSHOT("top_right", topWidth, true, false);

#undef WRITE_SCREENSHOT

end:
IFile_Close(&file);
Expand Down