Page 3 of 4

Re: Use Easy Save to download a mp4 file from WWW

Posted: Thu May 18, 2017 7:33 am
by PET
Hey Joel. When I mange a Download, can I specify on what Folder to download to?

Right now I have the posibility to have files on the App Folder, but also on a manual SD Folder that I set up.
So when I finally get to play the videos, I need to know from where... and the easiest solution is to make the app Download to D:/MyVideos/ or to /storage/emulated/0/Movies/

EDIT: It seems that I can if I specify the full path. It works in the Editor at least... I can see my files on the D:/ path... any idea how this would work on Android? The app will have permission.

Re: Use Easy Save to download a mp4 file from WWW

Posted: Thu May 18, 2017 7:55 am
by Joel
A full path will also work on Android, assuming you indeed have permission :)

All the best,
Joel

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 8:13 am
by PET
Hey Joel,

I'm trying to make a new thing. RIght now my app is more of a General App... meaning that it reads all my videos... it goes to a "titlescreen" that has UI buttons for all my videos.
Since I want my app to be more "general", I want a way to have a "text config file" placed somewhere on the device... and that file to tell the App to skipp some stuff, and go directly to load the X video.

Any idea how to do this?

I'm thinking that I can do something like this:

1. Check if config file exists
2. Read the number...
3. Load the video with that number...

Or replace the number with the Video name file or something like that.

The reason why I ask this is that I havn't yet used EasySave to SAVE/LOAD actual config files, butI think this is doable... right?

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 8:34 am
by Joel
Hi there,

This would be very easy with Easy Save, using the ES2.Exists method.

Assuming you want to use an actual text file, rather than a file in Easy Save's binary format, you can use ES2.LoadRaw to get the raw bytes of the file and then use System.Text.Encoding.UTF8.GetString to turn it into a string.

Something along the lines of:
if(ES2.Exists("/Path/To/File/config.txt"))
{
    string fileContents = System.Text.Encoding.UTF8.GetString( ES2.LoadRaw("/Path/To/File/config.txt") );
    // Convert string to int if necessary.
    int myInt = Int32.Parse(fileContents);
    // Now load the video with that number.
    LoadVideo(myInt);
}
Also if you wanted to create the config file at runtime, you can use ES2.SaveRaw to save a string as a file.

All the best,
Joel

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 8:46 am
by PET
Well I used the Save action to create a text config file and it looks like this:

Code: Select all

~	videoName   ÿîñéýMyVideoName{
My guess is that I can replace the "MyVideoName" with any other video name, and it will load like that right? I'm currently trying to make this system. It's pretty fun... I have my text there, I told it my tag... and BAM I already loaded that name into a Playmaker String Variable.

Hmm... something is a bit off. I had a space in my video name like "Video Name" but I want it without the space. So I deleted the space... but not it's also loading that { character ...

EDIT: I will try to use the SaveRaw & LoadRaw. brb :D

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 8:52 am
by Joel
It's not possible to edit files created using Easy Save in a text editor because they're in binary format, so modifying the file in a text editor will apply an encoding to it and corrupt the data.

If you want it to be editable in a text editor, you will need to use ES2.SaveRaw and ES2.LoadRaw. Otherwise you will need to use the ES2.Save method to modify the value in the file.

- Joel

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 9:02 am
by PET
I tried to use Save Raw Base 64 ... in order to create a TXT file that I can modify later... but it's giving an error. Something about size to large.

I did it again with the normal save but I made sure not to put a space in my "name" ... and it worked. Then I renamed it to another video name but again... with no space... and it worked.

I would like it however to have it more simple... maybe something like just a TEXT file with 1 string name and that's it.

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 9:20 am
by Joel
My apologies, I was not aware that you wanted to achieve this using Playmaker actions.

Save Raw Base-64 will save it with Base-64 encoding, which is not editable in a text editor. I've created a Save Raw UTF8 action for you below which will allow you to save a string to a file in UTF8 format, which will be modifiable.
using System;
using UnityEngine;
using System.Collections.Generic;

namespace HutongGames.PlayMaker.Actions
{
	[ActionCategory("Easy Save 2")]
	public class SaveRawUTF8 : FsmStateAction
	{
		[RequiredField]
		[Tooltip("The raw string we want to save to a file.")]
		public FsmString saveValue;
		[Tooltip("The name or absolute path of the file where we want to store our raw string. If the file doesn't exist, it will be created.")]
		public FsmString filename = "defaultFile.txt";
		[Tooltip("This event is called if an error occurs.")]
		public FsmEvent ifError = null;

		public override void Reset()
		{
			saveValue = null;
			base.Reset (); // Ensure that base.Reset() is called when done.
		}

		public override void OnEnter()
		{
			try
			{
				ES2.SaveRaw(System.Text.Encoding.UTF8.GetBytes(saveValue.Value), filename.Value);
				base.OnEnter(); // Ensure that base.OnEnter() is called when done.
				Finish();
			}
			catch(System.Exception e)
			{
				if(ifError != null)
				{
					LogError(e.Message);
					Fsm.Event(ifError);
				}
			}
		}
	}
}
You can then use the normal Load Raw action to load it back.

All the best,
Joel

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 12:31 pm
by PET
Hey Joel,

this is working great so far. I'm curious if I can evolve the Config file some more. Like have on a 2nd line, some other string that I can use for some other things.

Re: Use Easy Save to download a mp4 file from WWW

Posted: Mon May 22, 2017 12:51 pm
by Joel
For this you would need to add newlines after each item in the string you are saving. And then when loading, you would need to split the string at each of the newlines to get an array containing each line of your file.

However, as this is more to do with string manipulation rather than Easy Save you might be better off asking on the Playmaker forums regarding this as I believe they have a number of string manipulation actions of their own.

All the best,
Joel