@@ -42,6 +42,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4242#include " answer.h"
4343#include " printer.h"
4444
45+ #include " osspec.h"
46+
4547const char *MCdialogtypes[] =
4648{
4749 " plain" ,
@@ -492,6 +494,17 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
492494 if (!t_error && !MCSecureModeCanAccessDisk ())
493495 t_error = EE_DISK_NOPERM;
494496
497+ char *t_initial_resolved;
498+ t_initial_resolved = nil;
499+
500+ if (!t_error && t_initial != nil)
501+ {
502+ // IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
503+ t_initial_resolved = MCS_get_canonical_path (t_initial);
504+ if (nil == t_initial_resolved)
505+ t_error == EE_NO_MEMORY;
506+ }
507+
495508 if (!t_error)
496509 {
497510 if (MCsystemFS && MCscreen -> hasfeature ( PLATFORM_FEATURE_OS_FILE_DIALOGS ) )
@@ -503,23 +516,26 @@ Exec_errors MCAnswer::exec_file(MCExecPoint& ep, const char *p_title)
503516 t_options |= MCA_OPTION_PLURAL;
504517
505518 if (t_types != NULL )
506- MCA_file_with_types (ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial , t_options);
519+ MCA_file_with_types (ep, p_title, t_prompt, t_type_strings, t_type_count, t_initial_resolved , t_options);
507520 else
508- MCA_file (ep, p_title, t_prompt, t_filter, t_initial , t_options);
521+ MCA_file (ep, p_title, t_prompt, t_filter, t_initial_resolved , t_options);
509522 }
510523 else
511524 {
512525 MCExecPoint ep2 (ep);
513526 ep2 . clear ();
514527 for (uint4 t_type = 0 ; t_type < t_type_count; ++t_type)
515528 ep2 . concatcstring (t_type_strings[t_type], EC_RETURN, t_type == 0 );
516- t_error = exec_custom (ep, MCfsnamestring, mode == AT_FILE ? " file" : " files" , 5 , p_title, *t_prompt, *t_filter, *t_initial , ep2 . getsvalue () . getstring ());
529+ t_error = exec_custom (ep, MCfsnamestring, mode == AT_FILE ? " file" : " files" , 5 , p_title, *t_prompt, *t_filter, t_initial_resolved , ep2 . getsvalue () . getstring ());
517530 }
518531
519532 if (ep . getsvalue () == MCnullmcstring && t_types == NULL )
520533 MCresult -> sets (MCcancelstring);
521534 }
522535
536+ if (t_initial_resolved != nil)
537+ MCCStringFree (t_initial_resolved);
538+
523539 delete[] t_types;
524540 delete t_type_strings;
525541
@@ -544,6 +560,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
544560 if (!t_error && !MCSecureModeCanAccessDisk ())
545561 t_error = EE_DISK_NOPERM;
546562
563+ char *t_initial_resolved;
564+ t_initial_resolved = nil;
565+
566+ if (!t_error && t_initial != nil)
567+ {
568+ // IM-2014-08-06: [[ Bug 13096 ]] Allow file dialogs to work with relative paths by resolving to absolute
569+ t_initial_resolved = MCS_get_canonical_path (t_initial);
570+ if (nil == t_initial_resolved)
571+ t_error == EE_NO_MEMORY;
572+ }
573+
547574 if (!t_error)
548575 {
549576 unsigned int t_options = 0 ;
@@ -553,14 +580,17 @@ Exec_errors MCAnswer::exec_folder(MCExecPoint& ep, const char *p_title)
553580 t_options |= MCA_OPTION_PLURAL;
554581
555582 if (MCsystemFS)
556- MCA_folder (ep, p_title, t_prompt, t_initial , t_options);
583+ MCA_folder (ep, p_title, t_prompt, t_initial_resolved , t_options);
557584 else
558- t_error = exec_custom (ep, MCfsnamestring, mode == AT_FOLDER ? " folder" : " folders" , 4 , p_title, *t_prompt, NULL , *t_initial );
585+ t_error = exec_custom (ep, MCfsnamestring, mode == AT_FOLDER ? " folder" : " folders" , 4 , p_title, *t_prompt, NULL , t_initial_resolved );
559586
560587 if (ep . getsvalue () == MCnullmcstring)
561588 MCresult -> sets (MCcancelstring);
562589 }
563590
591+ if (t_initial_resolved != nil)
592+ MCCStringFree (t_initial_resolved);
593+
564594 return t_error;
565595}
566596#endif /* MCAnswer::exec_folder */
0 commit comments