Skip to content

Commit 881c6b2

Browse files
committed
Added configurable naming scheme for screenshots
1 parent ecc0d7e commit 881c6b2

4 files changed

Lines changed: 94 additions & 20 deletions

File tree

include/utility/registry.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ struct SKIF_RegistrySettings {
369369
SKIF_MakeRegKeyWS ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\)",
370370
LR"(Screenshots)" );
371371

372+
KeyValue <std::wstring> regKVScreenshotsPattern =
373+
SKIF_MakeRegKeyWS ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\)",
374+
LR"(Screenshots Pattern)" );
375+
372376
KeyValue <std::wstring> regKVAutoUpdateVersion =
373377
SKIF_MakeRegKeyWS ( LR"(SOFTWARE\Kaldaien\Special K\Viewer\)",
374378
LR"(Auto-Update Version)" );
@@ -470,8 +474,9 @@ struct SKIF_RegistrySettings {
470474
std::wstring wsUpdateChannel = L"Website"; // Default to stable channel
471475
std::wstring wsIgnoreUpdate;
472476
std::wstring wsPathViewer;
473-
std::wstring wsPathScreenshots;
474477
std::wstring wsPathSpecialK;
478+
std::wstring wsPathScreenshots;
479+
std::wstring wsScreenshotsPattern = L"<app>_<date>_<time>";
475480
std::wstring wsAutoUpdateVersion; // Holds the version the auto-updater is trying to install
476481
std::wstring wsDefaultHDRExt = L".png";
477482
std::wstring wsDefaultSDRExt = L".png";

src/tabs/settings.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <utility/gamepad.h>
1717
#include "../../version.h"
1818
#include <tabs/common_ui.h>
19+
#include <ImGuiNotify.hpp>
1920
#include <set>
2021

2122
extern bool allowShortcutCtrlA;
@@ -100,13 +101,76 @@ SKIF_UI_Tab_DrawSettings (void)
100101
ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_SKIF_TextBase)
101102
);
102103
SKIF_ImGui_Spacing ( );
104+
105+
static float folderPosX = 0.0f;
106+
107+
ImGui::TextColored (
108+
ImGui::GetStyleColorVec4(ImGuiCol_SKIF_TextCaption),
109+
"Name Pattern: "
110+
);
111+
112+
constexpr int maxChars = 50;
113+
static char pattern[maxChars] = {};
114+
static bool warnNonUnique = false;
115+
bool savePattern = false;
116+
117+
SK_RunOnce (strncpy_s (pattern, maxChars, SK_WideCharToUTF8 (_registry.wsScreenshotsPattern).data(), _TRUNCATE));
103118

104-
119+
ImGui::SameLine ( );
120+
ImGui::SetCursorPosX(folderPosX);
121+
122+
if (ImGui::InputTextEx ("###PatternInput", "<app>_<date>_<time>", pattern, maxChars, ImVec2(250.0f * SKIF_ImGui_GlobalDPIScale, 0.0f), ImGuiInputTextFlags_EnterReturnsTrue))
123+
savePattern = true;
124+
125+
if (! ImGui::IsItemActive ())
126+
{
127+
if (pattern[0] == '\0')
128+
strncpy (pattern, "<app>_<date>_<time>", maxChars);
129+
}
130+
else if (ImGui::GetIO().KeyCtrl && ImGui::GetKeyData(ImGuiKey_S)->DownDuration == 0.0f)
131+
{
132+
savePattern = true;
133+
134+
if (pattern[0] == '\0')
135+
ImGui::SetWindowFocus (NULL);
136+
}
137+
138+
ImGui::SameLine ( );
139+
140+
ImGui::PushStyleColor (ImGuiCol_Text, ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Success));
141+
if (ImGui::Button (ICON_FA_FLOPPY_DISK))
142+
savePattern = true;
143+
ImGui::PopStyleColor ();
144+
145+
if (savePattern)
146+
{
147+
savePattern = false;
148+
149+
if (pattern[0] == '\0')
150+
strncpy (pattern, "<app>_<date>_<time>", maxChars);
151+
152+
StrTrimA (pattern, " \t\r\n");
153+
_registry.wsScreenshotsPattern = SK_UTF8ToWideChar (pattern);
154+
_registry.regKVScreenshotsPattern.putData (_registry.wsScreenshotsPattern);
155+
156+
ImGui::InsertNotification ({ ImGuiToastType::Success, 1000, "Saved", ""});
157+
}
158+
159+
if ((StrStrA (pattern, "<app>") == NULL && StrStrA (pattern, "<date>") == NULL && StrStrA (pattern, "<time>") == NULL))
160+
{
161+
ImGui::TextColored (ImGui::GetStyleColorVec4 (ImGuiCol_SKIF_Yellow), ICON_FA_TRIANGLE_EXCLAMATION);
162+
ImGui::SameLine ( );
163+
ImGui::Text ("Missing <app>, <date>, and <time>. Any captured shot will overwrite the existing file!");
164+
}
165+
166+
ImGui::Spacing ();
167+
105168
ImGui::TextColored (
106169
ImGui::GetStyleColorVec4(ImGuiCol_SKIF_TextCaption),
107170
"Screenshots Folder: "
108171
);
109172
ImGui::SameLine ( );
173+
folderPosX = ImGui::GetCursorPosX();
110174
if (ImGui::Selectable(_path_cache.skiv_screenshotsA))
111175
{
112176
std::wstring newPath = SKIF_Util_FileExplorer_BrowseForFolder (_path_cache.skiv_screenshots);

src/utility/image.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,43 +1086,45 @@ using namespace DirectX;
10861086
return false;
10871087

10881088
static SKIF_CommonPathsCache& _path_cache = SKIF_CommonPathsCache::GetInstance ( );
1089+
static SKIF_RegistrySettings& _registry = SKIF_RegistrySettings::GetInstance ( );
10891090

10901091
bool isPersistent = (capture_data._mode != CaptureMode_None);
10911092
std::wstring wsPNGPath = (isPersistent) ? _path_cache.skiv_screenshots : _path_cache.skiv_temp;
1092-
std::wstring wsFilename = capture_data._title;
1093-
1094-
wsFilename += L"_";
1093+
std::wstring wsFilename = _registry.wsScreenshotsPattern;
1094+
const std::wstring pApps = L"<app>",
1095+
pDate = L"<date>",
1096+
pTime = L"<time>";
10951097

10961098
if (! isPersistent)
10971099
SKIF_Util_Files_PruneToLatestN (_path_cache.skiv_temp, 10);
10981100

10991101
// DateTime
11001102
SYSTEMTIME st;
1101-
GetLocalTime(&st);
1103+
GetLocalTime (&st);
11021104

1103-
// Buffers for formatted output
1104-
wchar_t dateBuffer[100];
1105-
wchar_t timeBuffer[100];
1105+
if (wsFilename.find (pApps) != std::wstring::npos)
1106+
wsFilename.replace (wsFilename.find (pApps), pApps.length(), capture_data._title);
11061107

11071108
// Get locale-aware date
1108-
if (GetDateFormatEx (LOCALE_NAME_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, dateBuffer, 100, NULL))
1109-
wsFilename += std::wstring(dateBuffer);
1110-
1111-
wsFilename += L"_";
1109+
if (wsFilename.find (pDate) != std::wstring::npos)
1110+
{
1111+
wchar_t dateBuffer[100];
1112+
if (GetDateFormatEx (LOCALE_NAME_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, dateBuffer, 100, NULL))
1113+
wsFilename.replace (wsFilename.find (pDate), pDate.length(), dateBuffer);
1114+
}
11121115

11131116
// Get locale-aware time
1114-
if (GetTimeFormatEx (LOCALE_NAME_USER_DEFAULT, 0, &st, NULL, timeBuffer, 100))
1115-
wsFilename += std::wstring(timeBuffer);
1117+
if (wsFilename.find (pTime) != std::wstring::npos)
1118+
{
1119+
wchar_t timeBuffer[100];
1120+
if (GetTimeFormatEx (LOCALE_NAME_USER_DEFAULT, 0, &st, NULL, timeBuffer, 100))
1121+
wsFilename.replace (wsFilename.find (pTime), pTime.length(), timeBuffer);
1122+
}
11161123

11171124
wsFilename = SKIF_Util_StripInvalidFilenameChars (wsFilename);
11181125

11191126
wsPNGPath += wsFilename + L".png";
11201127

1121-
//PLOG_VERBOSE << wsPNGPath;
1122-
1123-
static SKIF_RegistrySettings& _registry =
1124-
SKIF_RegistrySettings::GetInstance ( );
1125-
11261128
int snipping_tonemap_mode = _registry._SnippingTonemapsHDR;
11271129

11281130
if (_registry._SnippingTonemapsHDR == 2)

src/utility/registry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ SKIF_RegistrySettings::SKIF_RegistrySettings (void)
387387
if (regKVPathScreenshots.hasData(&hKey))
388388
wsPathScreenshots = regKVPathScreenshots .getData (&hKey);
389389

390+
if (regKVScreenshotsPattern.hasData(&hKey))
391+
wsScreenshotsPattern = regKVScreenshotsPattern .getData (&hKey);
392+
390393
if (regKVAutoUpdateVersion.hasData(&hKey))
391394
wsAutoUpdateVersion = regKVAutoUpdateVersion .getData (&hKey);
392395

0 commit comments

Comments
 (0)