Can save to default file path but can't load

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
kranwe
Posts: 3
Joined: Thu Apr 07, 2016 7:30 am

Can save to default file path but can't load

Post by kranwe »

How I save:

//saving works completely fine. I can see the file in the file system.

Code: Select all

ES2.Save<GameLevelData>(data, "local_levels/someFileName");
Loading a file directly (not a directory) works.

//no errors

Code: Select all

GameLevelData a = ES2.Load<GameLevelData>("local_levels/someFileName");
How I try to load a directory of files:

Code: Select all

var a = ES2.LoadArray<GameLevelData>("local_levels");
var b = ES2.LoadAll("local_levels");
Doing either gives me the following error.

UnauthorizedAccessException: Access to the path 'C:/Users/someuser/AppData/LocalLow/DefaultCompany/GameName/local_levels' is denied.
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:259)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.File.OpenRead (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:363)
System.IO.File.ReadAllBytes (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:538)
ES2FileUtility.ReadAllBytes (System.String path)
ES2FileStream.CreateReadStream ()
ES2FileStream..ctor (.ES2Settings settings, Operation operation)
ES2Stream.Create (.ES2Settings settings, Operation operation)
ES2Reader..ctor (.ES2Settings settings)
ES2Reader.Create (.ES2Settings settings)
ES2.LoadArray[GameLevelData] (System.String identifier)
//Some method calls from my own code base go here


My game basically has a level editor in it. All levels players save go into the same directory.

I want a level selection screen to be able to load all of the levels I saved in the "local_levels" directory into an array of GameLevelData objects.

Am I trying to load directories in the wrong way?

Thanks in advance!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Can save to default file path but can't load

Post by Joel »

Hi there,

It's not possible to load a directory of files as an array. The Load and Save methods expect a path to a file, not to a folder, which is why you get the exception in question.

If you wish to load them as an array, you will need to save them to a file as an array.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
kranwe
Posts: 3
Joined: Thu Apr 07, 2016 7:30 am

Re: Can save to default file path but can't load

Post by kranwe »

Ah. Ok. Thanks for that.
kranwe
Posts: 3
Joined: Thu Apr 07, 2016 7:30 am

Re: Can save to default file path but can't load

Post by kranwe »

Don't know if anyone will ever find this useful...

ES2.GetFiles will return a list of file names in a folder. Those could then be iterated over if you want to load data from a bunch of files.

http://docs.moodkie.com/easy-save-2/api/es2-getfiles/
Locked