Vista-Proof Save System

Introduction
If you are using Vista, you have probably already learned by now that unless you are logged in with administrator permissions, you cannot write or update data in the Programs Files directory. Any user who installs their RPG Maker XP game in this directory will not be able to save their games or update their game option files.

So what are we to do, eh? Yes, Vista is new, and it's a real pain in the arse, but like it or not, it's not going to go away. Best to prepare for the future, I say.

Let the fun begin!

Step 1: Create Game Directory On Startup
The first time that your user runs your game, a directory needs to be created for them that is local to their account. We will use this directory for our save files and any other files that needs to be modified by players.

The following code gets a path to a user's directory. Then it creates a directory for your game. The directory is only created the first time that the user plays the game.

The directory must be local to the user's machine. (which is why I have used the WinAPI below).

1. Open the script editor for your project and go to Main.
2. Add the following code under begin:
  # Get Your Path (WinAPI)
  SHGetFolderPath = Win32API.new("shell32.dll","SHGetFolderPath",["P","I","P","I","P"],"I")
  path = " " * 256
  SHGetFolderPath.call(0,0x0023,0,0,path)
 
  # Define Your Game Folder (use global variables)
  $appPath = path.strip.gsub("\000","") + "\\Game Name"
 
  # Replace backslashes with forward slashes
  $appPath = $appPath.gsub(/\\/, "/")
   
  # Create Your Folders
  if !File.exists?($appPath) 
    Dir.mkdir($appPath)
  end
Expand to see the code.


Note: Notice the reference to 0x0023? This is a constant that points to the user's Application Data directory. On Windows XP, this constant points to this directory: C:\Documents and Settings\All Users\Application Data. The value for this constant changes, depending upon the operating system. This means that there is no need to hard-code anything! If you would like a full list of constants, go here: http://rubyforge.org/pipermail/win32utils-devel/2005-May/000386.html

Step 2: Point Your Save Game Files To The New Directory
Now that you have dynamically created a directory for your user, you need to make sure that your save files write to this directory, and not to your game's directory.

1. In Window_SaveFile, on line 22...

Replace this:
@filename = "Save#{@file_index + 1}.rxdata"
Expand to see the code.


With this:
@filename = $appPath + "/" + "Save#{@file_index + 1}.rxdata"
Expand to see the code.


2. In Scene_Title, on line 49...

Replace this:
if FileTest.exist?("Save#{i+1}.rxdata")
Expand to see the code.


With this:
if FileTest.exist?($appPath + "/" + "Save#{i+1}.rxdata")
Expand to see the code.


3. In Scene_File, around line 110...

Replace this:
return "Save#{file_index + 1}.rxdata"
Expand to see the code.


With this:
return $appPath + "/" + "Save#{file_index + 1}.rxdata"
Expand to see the code.


And that's that! If you have created an options file for your game, follow the same steps for it. :)

Credits
Special credit should be given to Eccid. I wasn't sure how to get the ball rolling onto this one until I saw his save script over at Creation Asylum
If i had vista (Thank god i dont), i would have to check that out. sadly we cant afford (our computer cant run and i dont like) vista, so i cant check it out. it looks cool, though.
Nice to see you're thinking of the future, Lamby. I'm gonna check this, for your sake, just to try it out. My sister is the one with Vista, only buying her laptop a few months ago. Looks nice.

EDIT: Will this work on XP as well?
I don't see why it wouldn't.
This is nice. Not sure why you would'nt be an admin on your own machine, but I guess that's up to mom and dad. :)
jbart321;201815 wrote:
This is nice. Not sure why you would'nt be an admin on your own machine, but I guess that's up to mom and dad. :)



It's also safer to get in the habit of using the computer under a limited user account and only run as administrator when you need to. If you happen to accidentally download a malicious software (virus, adware, spyware, trojan, etc) as an administrator, it will also have administrator priviledges which allows it to do whatever it wants whenever it wants. I, myself, use the Admin account only when installing programs that require administrative rights or if i have any programs that have to run as administrator, and then only if I trust those programs.

Anyway, This is a very nice script. I will definately come in handy.
I always use admin, but this might still come in handy.

PS : I don't have Vista, my PC wouldn't be able to cope playing the Sims 2 with Vista, ya know.
[QUOTE=DraycosGoldaryn;201818]It's also safer to get in the habit of using the computer under a limited user account and only run as administrator when you need to. If you happen to accidentally download a malicious software (virus, adware, spyware, trojan, etc) as an administrator, it will also have administrator priviledges which allows it to do whatever it wants whenever it wants. I, myself, use the Admin account only when installing programs that require administrative rights or if i have any programs that have to run as administrator, and then only if I trust those programs.

Anyway, This is a very nice script. I will definately come in handy.[/QUOTE]

You're right, but I am the Admin of my network and I control what everyone can do who logs in. Vista gives better control over user accounts than XP does, so I can see why you would want to use a limited setup in Vista.
Do I have a strange title scene?
On my line 110 it says: def command_new_game

and I can't find anything similar to what you have for the original line 110.

??? Anyone know what I've missed?
I?m using Vista Home Premium..

And i can save without Problems...And without that Script...

But.. Well done...yes...
Same here. Of course, that may be because I turned UAC off long ago because of other similar issues with other games. *shrug*

And Sims2 runs fine with Vista... to whoever it was who said that originally.
Quote:
Note: Notice the reference to 0x0023? This is a constant that points to the user's Application Data directory. On Windows XP, this constant points to this directory: C:\Documents and Settings\All Users\Application Data. The value for this constant changes, depending upon the operating system. This means that there is no need to hard-code anything!


Instead of the API, you could have used the ENV[] Variable ;) So you don't need the api anything :)
Hey Me, how would you use the ENV[] variable? I'm still kind of new at this deeper stuff...
The ENV hash contains data about your system. For appdata, use ENV['APPDATA']. It should point to "C:\\Documents and Settings\\User\\Application Data". For a full list of what ENV holds, just p ENV :)
this just makes me laugh so hard that we'd NEED something like this. Ah vista, you've made me giggle.

Having said that, good job on this even though i have no intention of using vista.
Still I prefer my Windows XP x64 instead of Vista... XD
Although, it's an interesting script.
BTW, does anybody knows if Enterbrain (or whoever has the official rights of RPG Maker series) will create "RM-Vista"?
I got a question...I'm using the Activation Script and ir changes line 49 of Scene_Title to if FileTest.exist? ("246813579.txt") so what do I do because I'm using Vista and would really need to use this Script.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=20149