diff --git a/desmume/src/path.h b/desmume/src/path.h index 3a233628f..e18724812 100644 --- a/desmume/src/path.h +++ b/desmume/src/path.h @@ -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> 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); } diff --git a/desmume/src/windows/pathsettings.cpp b/desmume/src/windows/pathsettings.cpp index 81d667e08..d394464f7 100644 --- a/desmume/src/windows/pathsettings.cpp +++ b/desmume/src/windows/pathsettings.cpp @@ -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);