comparison bindings.c @ 1850:30f2821ffd65

Allow rom directory and rom name in screenshot path. Allow rom name in screenshot name. Remove ability for path variables to contain underscores
author Michael Pavone <pavone@retrodev.com>
date Tue, 23 Apr 2019 23:33:16 -0700
parents 78abbabfd58d
children 508522f08e4d
comparison
equal deleted inserted replaced
1849:6b5147f08846 1850:30f2821ffd65
356 if (allow_content_binds) { 356 if (allow_content_binds) {
357 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; 357 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval;
358 if (!screenshot_base) { 358 if (!screenshot_base) {
359 screenshot_base = "$HOME"; 359 screenshot_base = "$HOME";
360 } 360 }
361 const system_media *media = current_media();
361 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); 362 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
362 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); 363 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
364 vars = tern_insert_ptr(vars, "USERDATA", (char *)get_userdata_dir());
365 vars = tern_insert_ptr(vars, "ROMNAME", media->name);
366 vars = tern_insert_ptr(vars, "ROMDIR", media->dir);
363 screenshot_base = replace_vars(screenshot_base, vars, 1); 367 screenshot_base = replace_vars(screenshot_base, vars, 1);
364 tern_free(vars); 368 tern_free(vars);
369 ensure_dir_exists(screenshot_base);
365 time_t now = time(NULL); 370 time_t now = time(NULL);
366 struct tm local_store; 371 struct tm local_store;
367 char fname_part[256]; 372 char fname_part[256];
368 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval; 373 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval;
369 if (!template) { 374 if (template) {
370 template = "blastem_%c.ppm"; 375 vars = tern_insert_ptr(NULL, "ROMNAME", media->name);
376 template = replace_vars(template, vars, 0);
377 } else {
378 template = strdup("blastem_%c.ppm");
371 } 379 }
372 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store)); 380 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
373 char const *parts[] = {screenshot_base, PATH_SEP, fname_part}; 381 char const *parts[] = {screenshot_base, PATH_SEP, fname_part};
374 char *path = alloc_concat_m(3, parts); 382 char *path = alloc_concat_m(3, parts);
375 free(screenshot_base); 383 free(screenshot_base);
384 free(template);
376 render_save_screenshot(path); 385 render_save_screenshot(path);
377 } 386 }
378 break; 387 break;
379 } 388 }
380 case UI_EXIT: 389 case UI_EXIT: