apply patch #164 to screenshot path building format

This commit is contained in:
zeromus 2014-08-21 16:17:21 +00:00
parent b95380054e
commit e24720f69d
2 changed files with 53 additions and 43 deletions

View File

@ -342,60 +342,60 @@ public:
void formatname(char *output)
{
// Except 't' for tick and 'r' for random.
const char* strftimeArgs = "AbBcCdDeFgGhHIjmMnpRStTuUVwWxXyYzZ%";
std::string file;
time_t now = time(NULL);
tm *time_struct = localtime(&now);
srand((unsigned int)now);
for(int i = 0; i < MAX_FORMAT;i++)
{
char *c = &screenshotFormat[i];
char tmp[MAX_PATH] = {0};
srand((unsigned)now);
if(*c == '%')
for (char* p = screenshotFormat,
*end = p + sizeof(screenshotFormat); p < end; p++)
{
c = &screenshotFormat[++i];
switch(*c)
if (*p != '%')
{
case 'f':
strcat(tmp, GetRomNameWithoutExtension().c_str());
break;
case 'D':
strftime(tmp, MAX_PATH, "%d", time_struct);
break;
case 'M':
strftime(tmp, MAX_PATH, "%m", time_struct);
break;
case 'Y':
strftime(tmp, MAX_PATH, "%Y", time_struct);
break;
case 'h':
strftime(tmp, MAX_PATH, "%H", time_struct);
break;
case 'm':
strftime(tmp, MAX_PATH, "%M", time_struct);
break;
case 's':
strftime(tmp, MAX_PATH, "%S", time_struct);
break;
case 'r':
sprintf(tmp, "%d", rand() % RAND_MAX);
break;
}
file.append(1, *p);
}
else
{
int j;
for(j=i;j<MAX_FORMAT-i;j++)
if(screenshotFormat[j] != '%')
tmp[j-i]=screenshotFormat[j];
else
break;
tmp[j-i]='\0';
p++;
if (*p == 'f')
{
file.append(GetRomNameWithoutExtension());
}
else if (*p == 'r')
{
file.append(stditoa(rand()));
}
file += tmp;
else if (*p == 't')
{
file.append(stditoa(clock() >> 5));
}
else if (strchr(strftimeArgs, *p))
{
char tmp[MAX_PATH];
char format[] = { '%', *p, NULL };
strftime(tmp, MAX_PATH, format, time_struct);
file.append(tmp);
}
}
}
#ifdef WIN32
// Replace invalid file name character.
{
const char* invalids = "\\/:*?\"<>|";
size_t pos = 0;
while ((pos = file.find_first_of(invalids, pos)) != std::string::npos)
{
file[pos] = '-';
}
}
#endif
strncpy(output, file.c_str(), MAX_PATH);
}

View File

@ -184,7 +184,17 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
ti.hinst = hAppInst;
ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
ti.uId = (UINT_PTR)hwnd;
ti.lpszText = "The format a screenshot should be saved in.\r\n%f\t\t\tFilename\r\n%D\t\t\tDay:Two Digit\r\n%M\t\t\tMonth:Two Digit\r\n%Y\t\t\tYear:Four Digit\r\n%h\t\t\tHour:Two Digit\r\n%m\t\t\tMinute: Two Digit\r\n%s\t\t\tSecond: Two Digit\r\n%r\t\tRandom: Min:0 Max:RAND_MAX";
ti.lpszText =
"The format a screenshot should be saved in.\r\n"
"%f\t\tFilename\r\n"
"%r\t\tRandom: 0 ~ RAND_MAX\r\n"
"%t\t\tTick: Reset on startup\r\n"
"%Y\t\tYear:Four Digit\r\n"
"%m\t\tMonth:Two Digit\r\n"
"%D\t\tDay:Two Digit\r\n"
"%H\t\tHour:Two Digit\r\n"
"%M\t\tMinute: Two Digit\r\n"
"%S\t\tSecond: Two Digit\r\n";
GetClientRect(hwnd, &ti.rect);
SendMessage(toolTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);