ES3File.LoadRawString() earse the file

Discussion and help for Easy Save 3
Post Reply
fur
Posts: 9
Joined: Fri Jul 28, 2017 6:12 am

ES3File.LoadRawString() earse the file

Post by fur »

I simply wanna print out the save file for debug, and I find that ES3File.LoadRawString() will earse the file:

Code: Select all

var file = new ES3File("SaveData.es3");
string str = file.LoadRawString();
Debug.Log(str);
Digging into it I saw a .Save() inside LoadRawString(), which seems not neccessary, commenting the line make it work.

Code: Select all

	public byte[] LoadRawBytes()
	{
		if(cache.Count == 0)
			return new byte[0];
		
		using (var ms = new System.IO.MemoryStream ())
		{
			using (var baseWriter = ES3Writer.Create(ms, settings, false, false))
			{
				foreach (var kvp in cache)
					baseWriter.Write(kvp.Key, kvp.Value.type.type, kvp.Value.bytes);
//				baseWriter.Save(false);
			}
			return ms.ToArray();
		}
	}
Is that a bug or?

P.S. just found out may be I should use ES3.LoadRawString(new ES3Settings()) to print the file string instead...but reporting this anyway.

P.S.2 May be it's handy to have ES3.LoadRawString() with no input which simply return the file string of default file? Same to ES3.FileExists()
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3File.LoadRawString() earse the file

Post by Joel »

Hi there,

This is indeed a bug, though not in the way you've described.

The Save() call is necessary as this tells the writer to add certain formatting data (for example, the closing brace of the JSON format). The issue is that the save location of the writer is File, when it should be Memory.

I've also added an overload for ES3.LoadRawBytes/String with no parameters for you. If you PM me your invoice number I'll send over an update with these included.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
fur
Posts: 9
Joined: Fri Jul 28, 2017 6:12 am

Re: ES3File.LoadRawString() earse the file

Post by fur »

Thanks for the quick reply and the fix. I've sent u a PM already.

Also wanted to add that I still need ES3File.LoadRawString() rather than ES3.LoadRawString(), because I sync the saved byte[] from local to iCloud/Play Games. So when I download them I will need to use var serverFile = new ES3File(bytes) and serverFile.LoadRawString() for debug...
fur
Posts: 9
Joined: Fri Jul 28, 2017 6:12 am

Re: ES3File.LoadRawString() earse the file

Post by fur »

Got another minor issue, with JSON format, its perfectly fine when I print the string of a file using ES3.LoadRawString():

Code: Select all

Debug.Log(ES3.LoadRawString(new ES3Settings()));
// Output {"var1":{...}, "var2":{...} ...}
The open and close brackets is absent when Im using ES3File.LoadRawString():

Code: Select all

var file = new ES3File();
Debug.Log(file.LoadRawString());
// Output "var1":{...}, "var2":{...} ...

Is this intended?
User avatar
Joel
Moodkie Staff
Posts: 4848
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3File.LoadRawString() earse the file

Post by Joel »

Hi there,

I've just sent you the fix for both of these issues.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply