Page 1 of 1

Finding ES2 save file

Posted: Tue May 30, 2017 4:52 pm
by Oscar
Hi there,

Loving ES2 so far! I just had a quick question: at the moment I'm saving and loading all data for my game locally in a file located at: "TestFolder/saveData.txt";

However we're building for mobile devices and are looking to use iCloud to save that data so that it can be used on multiple devices - I was wondering if there was an easy way to find the above file and load the entire document into a string that I can then upload to iCloud?

As far as I can tell there's no ES2 method that allows me to just get the raw data from the .txt file it's been saved into. Any help would be greatly appreciated! And thanks again for a wonderfully easy to use product that worked straight out of the box.

Thanks,
Oscar

Re: Finding ES2 save file

Posted: Wed May 31, 2017 6:25 am
by Joel
Hi Oscar,

By default data is saved in the path returned by Unity's Application.persistentDataPath variable.

You can also use the ES2.LoadRaw method to load a file as bytes, and ES2.SaveRaw to save bytes as a file.

All the best,
Joel

Re: Finding ES2 save file

Posted: Thu Jun 01, 2017 3:04 pm
by Oscar
Hi Joel,

Thanks very much for your help! That seems to work, however after I upload the string to iCloud and then download it on the next launch of the app I get the following error:

FormatException: Invalid character found.
at SaveLoadDataController.OnCloudDataReceivedAction (.iCloudData data) [0x00000] in <filename unknown>:0

This is the point where the string is downloaded from iCloud so I can't even tell you what is inside of the string - Any ideas what might be causing that?
For reference, this is how I get the string to upload (done directly after writing to the file):

Code: Select all

using (ES2Writer writer = ES2Writer.Create (filename)) {
	writer.Write (Lots and lots of lines of this);
	writer.Write (Lots and lots of lines of this);
	writer.Write (Lots and lots of lines of this);
        writer.Save ();
}
var str = System.Text.Encoding.UTF8.GetString (ES2.LoadRaw(filename));
iCloudManager.Instance.setString ("gameData3", str);
I've also tried default encoding too, but no help.

Also just to be totally clear, if I simply use local EasySave save and load it works completely perfectly, there's just something wrong with the formatting / uploading / downloading process that I'm REALLY hoping you can help with.

Thanks in advance,
Oscar

Re: Finding ES2 save file

Posted: Thu Jun 01, 2017 3:08 pm
by Oscar
Oh also - just for future reference, this is the callback for when iCloudData is recieved:

Code: Select all

private void OnCloudDataReceivedAction (iCloudData data) {
		iCloudManager.OnCloudDataReceivedAction -= OnCloudDataReceivedAction;
		waitingForIcloudResponse = false;
		Debug.Log ("EH?!?!?!?!?!?!?!?");
		if(data.IsEmpty) {
			Debug.Log ("Data was Empty");
			Load();
		} else {
			Debug.Log ("BYTES: " + data.bytesValue [0] + data.bytesValue [1]); //This is just to check what values are in there for now - however it never gets here.
			ES2.SaveRaw (data.bytesValue, filename);

			//File.WriteAllText (Application.persistentDataPath + "/" + filename, data.stringValue);
			StartCoroutine (WaitFrameThenLoad ());
		}
	}
None of the Debug Logs are ever hit for some reason.

Thanks again,
Oscar

Re: Finding ES2 save file

Posted: Thu Jun 01, 2017 3:13 pm
by Joel
Hi there,

Converting bytes to a UTF8 string and back again will not work because the bytes will not be the same when you convert them back.

You may be able to use System.Convert.ToBase64String and System.Convert.FromBase64String to convert to and from bytes without the encoding corrupting the data, but you will need to ensure that iCloud does not apply an encoding of it's own.

However, most cloud plugins provide a function which allows you to upload and download bytes rather than strings. If your iCloud plugin has this feature, you should use it.

With regards to none of the Debug.Logs being called: the Debug.Log calls in your function are triggered by code outside the control of Easy Save, so you will need to contact the provider of your plugin to work out why these are not being called.

All the best,
Joel

Re: Finding ES2 save file

Posted: Thu Jun 01, 2017 3:58 pm
by Oscar
Hi Joel,

Thanks for the info - you were completely right! I'd only used strings with iCloud in the past but the plugin I'm using had a different function for uploading bytes and that has instantly worked. Also the reason the Debug Logs weren't being hit was that the data from the string had an invalid format so it exited out - I only put it in a reply to show you how I intended to load the data I received.

Anyways, all working. Thanks for the quick responses and the great product - so easy to use :D

Thanks,
Oscar

Re: Finding ES2 save file

Posted: Thu Jun 01, 2017 4:01 pm
by Joel
Glad to hear that solved your issue Oscar, let me know if you run into any other problems!

All the best,
Joel