mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
add saving of screenshots in subfolder
This commit is contained in:
@@ -222,11 +222,9 @@ void config_init()
|
|||||||
memcpy(&gGeneral_config, &gGeneral_config_default, sizeof(general_configuration_t));
|
memcpy(&gGeneral_config, &gGeneral_config_default, sizeof(general_configuration_t));
|
||||||
|
|
||||||
if (strcmp(path, "") != 0){
|
if (strcmp(path, "") != 0){
|
||||||
DWORD dwAttrib = GetFileAttributes(path);
|
if (!osinterface_ensure_directory_exists(path)) {
|
||||||
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { // folder does not exist
|
config_error("Could not create config file (do you have write access to your documents folder?)");
|
||||||
if (!CreateDirectory(path, NULL)) {
|
return;
|
||||||
config_error("Could not create config file (do you have write access to your documents folder?)");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(path, "%s%c%s", path, osinterface_get_path_separator(), "config.ini");
|
sprintf(path, "%s%c%s", path, osinterface_get_path_separator(), "config.ini");
|
||||||
|
|||||||
@@ -440,13 +440,34 @@ char* osinterface_get_orct2_homefolder()
|
|||||||
|
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
|
|
||||||
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path))) { // find home folder
|
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path)))
|
||||||
strcat(path, "\\OpenRCT2");
|
strcat(path, "\\OpenRCT2");
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *osinterface_get_orct2_homesubfolder(const char *subFolder)
|
||||||
|
{
|
||||||
|
char *path = osinterface_get_orct2_homefolder();
|
||||||
|
strcat(path, "\\");
|
||||||
|
strcat(path, subFolder);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
int osinterface_directory_exists(const char *path)
|
||||||
|
{
|
||||||
|
DWORD dwAttrib = GetFileAttributes(path);
|
||||||
|
return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int osinterface_ensure_directory_exists(const char *path)
|
||||||
|
{
|
||||||
|
if (osinterface_directory_exists(path))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return CreateDirectory(path, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
char osinterface_get_path_separator()
|
char osinterface_get_path_separator()
|
||||||
{
|
{
|
||||||
return '\\';
|
return '\\';
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ void osinterface_show_messagebox(char* message);
|
|||||||
char* osinterface_open_directory_browser(char *title);
|
char* osinterface_open_directory_browser(char *title);
|
||||||
|
|
||||||
char* osinterface_get_orct2_homefolder();
|
char* osinterface_get_orct2_homefolder();
|
||||||
|
char *osinterface_get_orct2_homesubfolder(const char *subFolder);
|
||||||
|
int osinterface_directory_exists(const char *path);
|
||||||
|
int osinterface_ensure_directory_exists(const char *path);
|
||||||
|
|
||||||
char osinterface_get_path_separator();
|
char osinterface_get_path_separator();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -60,20 +60,24 @@ void screenshot_check()
|
|||||||
|
|
||||||
static int screenshot_get_next_path(char *path, char *extension)
|
static int screenshot_get_next_path(char *path, char *extension)
|
||||||
{
|
{
|
||||||
char *homePath = osinterface_get_orct2_homefolder();
|
char *screenshotPath = osinterface_get_orct2_homesubfolder("screenshot");
|
||||||
|
if (!osinterface_ensure_directory_exists(screenshotPath)) {
|
||||||
|
fprintf(stderr, "Unable to save screenshots in OpenRCT2 screenshot directory.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < 1000; i++) {
|
for (i = 1; i < 1000; i++) {
|
||||||
RCT2_GLOBAL(0x013CE952, uint16) = i;
|
RCT2_GLOBAL(0x013CE952, uint16) = i;
|
||||||
|
|
||||||
// Glue together path and filename
|
// Glue together path and filename
|
||||||
sprintf(path, "%s%cSCR%d%s", homePath, osinterface_get_path_separator(), i, extension);
|
sprintf(path, "%s%cSCR%d%s", screenshotPath, osinterface_get_path_separator(), i, extension);
|
||||||
|
|
||||||
if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND)
|
if (GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(homePath);
|
free(screenshotPath);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user