Vendily

Other Game Save Loader

Nov 13th, 2019
210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module RTP
  2.   def self.loadOtherGameDir(dir,title)
  3.     title=title.gsub(/[^\w ]/,"_")
  4.     newdir=dir.gsub(/[\/\\]$/,"")+"/"
  5.     # Convert to UTF-8 because of ANSI function
  6.     newdir+=getUnicodeStringFromAnsi(title)
  7.     ret=safeIsDirectory?(newdir) ? newdir : dir
  8.     return ret
  9.   end
  10.  
  11.   def self.getOtherSaveFileName(fileName,title)
  12.     return getOtherSaveFolder(title).gsub(/[\/\\]$/,"")+"/"+fileName
  13.   end
  14.  
  15.   def self.getOtherSaveFolder(title)
  16.     # XXX: Use "." instead of Dir.pwd because of problems retrieving files if
  17.     # the current directory contains an accent mark
  18.     pwd="."
  19.     # Get the known folder path for saved games
  20.     savedGames=getKnownFolder([
  21.        0x4c5c32ff,0xbb9d,0x43b0,0xb5,0xb4,0x2d,0x72,0xe5,0x4e,0xaa,0xa4])
  22.     if savedGames && savedGames!="" && isDirWritable(savedGames)
  23.       pwd=loadOtherGameDir(savedGames,title)
  24.     end
  25.     if isDirWritable(pwd)
  26.       folder=pwd
  27.     else
  28.       appdata=ENV["LOCALAPPDATA"]
  29.       if isDirWritable(appdata)
  30.         appdata=loadOtherGameDir(appdata,title)
  31.       else
  32.         appdata=ENV["APPDATA"]
  33.         if isDirWritable(appdata)
  34.           appdata=loadOtherGameDir(appdata,title)
  35.         elsif isDirWritable(pwd)
  36.           appdata=pwd
  37.         else
  38.           appdata="."
  39.         end
  40.       end
  41.       folder=appdata
  42.     end
  43.     return folder
  44.   end
  45. end
RAW Paste Data