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 1 commit
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
66 changes: 42 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 @@ -340,7 +341,10 @@ void RosalinaMenu_TakeScreenshot(void)
IFile file;
Result res = 0;

char filename[64];
char directory[32];
memset(directory, 0, sizeof directory);
char filename[90];
memset(filename, 0, sizeof filename);
ioistired marked this conversation as resolved.
Show resolved Hide resolved

FS_Archive archive;
FS_ArchiveID archiveId;
Expand All @@ -366,15 +370,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 @@ -418,23 +413,46 @@ 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))
{
strcat(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

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));
FSUSER_CloseArchive(archive);
}

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_" screenName ".bmp", directory, year, month, days, hours, minutes, seconds, milliseconds, programInfo.programId); \
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