Advertisement
Guest User

GML Script - generate_working_directory()

a guest
Apr 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (os_type == os_macosx) {
  2.   /*
  3.     This function will set the working directory to the app bundle's Resources folder
  4.     like GM4Mac 7.5, GMStudio 1.4, GMS 2.x and most Mac apps do, if the executable is in
  5.     an app bundle. If the executable is not in an app bundle, use the getcwd function
  6.    
  7.     ONLY use get_working_directory() for loading read-only included files! When SAVING, use game_save_id
  8.    
  9.     *_bname = base name - removes the full path from the string leaving just the file or folder name
  10.     *_dname = directory name - removes final slash and base name from full path to file or folder name
  11.     *_pname = path name - removes the base name from a full path while keeping the dir and final slash
  12.     *_ename = extension name - includes everything in bname at and following the period if one exists
  13.   */
  14.  
  15.   var success = false;
  16.   var exe_pname = get_program_directory();             // = "/Path/To/YourAppBundle.app/Contents/MacOS/";
  17.   var macos_dname = filename_dir(exe_pname);           // = "/Path/To/YourAppBundle.app/Contents/MacOS";
  18.   var macos_bname = filename_name(macos_dname);        // = "MacOS";
  19.   var contents_dname = filename_dir(macos_dname);      // = "/Path/To/YourAppBundle.app/Contents";
  20.   var contents_bname = filename_name(contents_dname);  // = "Contents";
  21.   var app_dname = filename_dir(contents_dname);        // = "/Path/To/YourAppBundle.app";
  22.   var app_ename = filename_ext(app_dname);             // = ".app";
  23.   var contents_pname = filename_path(macos_dname);     // = "/Path/To/YourAppBundle.app/Contents/";
  24.   var resources_pname = contents_pname + "Resources/"; // = "/Path/To/YourAppBundle.app/Contents/Resources/";
  25.  
  26.   // if "/Path/To/YourAppBundle.app/Contents/MacOS/YourExe" and "/Path/To/YourAppBundle.app/Contents/Resources/" exists
  27.   if (macos_bname == "MacOS" && contents_bname == "Contents" && app_ename == ".app" && directory_exists(resources_pname)) {
  28.     // set working directory to "/Path/To/YourAppBundle.app/Contents/Resources/" and allow loading normal included files
  29.     success = set_working_directory(resources_pname);
  30.   }
  31.  
  32.   /* if (success) show_message("Success!"); else show_message("Failure!");
  33.   get_string_async("The current value of working_directory equals:", get_working_directory()); */
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement