General

Reply

Level 2

Level 2
petrix18
Posts: 15
Registered: ‎17-05-2011
Message 1 of 15 (667 Views)
Accepted Solution

Problems with v0.99 and reading files

Hi, I was using psm v0.98 and everything was going fine, but this morning I updated it to 0.99 but now my game won't execute because there's a part in the code when I need to read a file to load some assets, the problem is that it throws an exception saying that I don't have permission to open that file. Here is the piece of code that throws the exception:

 

public override MemoryStream Load(string asset)
		{
			if (this[asset] == null)
				return null;

			Resource resource = this[asset];

			/*if (resource.Stream != null)
				return resource.Stream;*/
			
			FileIOPermission ioPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, ASSETS_PACK_BIN_FILE);
        	ioPerm.Demand();
			
			using (BinaryReader reader = new BinaryReader(File.Open (ASSETS_PACK_BIN_FILE, FileMode.Open)))
			{
				reader.BaseStream.Seek(resource.Offset, SeekOrigin.Begin);

				byte[] bytes = reader.ReadBytes((int)resource.Size);

				MemoryStream mem = new MemoryStream(bytes);
				resource.Stream = mem;

				return mem;
			}
		}

 Tell me if you see anything, it's odd because before updating it worked fine :smileyfrustrated: 

 

I added this lines when I saw the exception but it keeps throwing it

FileIOPermission ioPerm = new FileIOPermission(FileIOPermissionAccess.AllAccess, ASSETS_PACK_BIN_FILE);
        	ioPerm.Demand();

 

Please use plain text.

Re: Problems with v0.99 and reading files

Hey Petrix18,

Thank you for taking the time to try out the new SDK and thanks for posting this report. We've identified some issues with this and we'll look into the problems surrounding this. We'll update you should we have any news.

Apologies for the inconvenience.

Best regards,
James
PlayStation®Mobile Dev Team
Please use plain text.

Re: Problems with v0.99 and reading files

Hi:

 

Like you I have the same issue but I found that the folders change to read only automatically James this could be a clue?

 

Cheers,

 

Please use plain text.

Re: Problems with v0.99 and reading files

no it's not the problem. I'm clue less.

Please use plain text.

Re: Problems with v0.99 and reading files

Hi:

 

I fix my problem of access denied changing from :

FileStream stream = new FileStream(froot+file, FileMode.Open);

                BinaryReader reader = new BinaryReader(stream);

 

to this:

 

//FileStream stream = new FileStream(froot+file, FileMode.Open);

                BinaryReader reader = new BinaryReader(File.OpenRead(froot+file));//stream);

 

Hope this helps.

 

Cheers,

Please use plain text.

Level 2

Level 2
petrix18
Posts: 15
Registered: ‎17-05-2011
Message 6 of 15 (575 Views)

Re: Problems with v0.99 and reading files

[ Edited ]

The access problem was solved using your "OpenRead" aproach. but now i have another issue, the file that I want to open has in it (among other things) an xml file. Before the update it worked perfectly, now it throws me an exception at this line XElement doc = XElement.Load(stream);

it says "xmlException invalid data".

any hints on this one?

 

EDIT:

 

I think i'll  create a new post for this new error. Thanks for the answers on this one :smileywink:

Please use plain text.

Re: Problems with v0.99 and reading files

Hi:

 

Great =), About xml: how is the header of your xml file? it's happens in other platforms that sometimes this line is needed: <?xml version="1.0" encoding="UTF-8"?> or sometime has a bad format. I'm not 100% sure.

 

Cheers

Please use plain text.

Re: Problems with v0.99 and reading files

Just to update from my earlier post, we are now enforcing read access only in the /Application/ directory. Unless explicitly stated, File.Open() will open the file with Read and Write access. You should either use File.OpenRead() or explicitly state in the constructor for File.Open that you wish to open it for reading only.
PlayStation®Mobile Dev Team
Please use plain text.

Re: Problems with v0.99 and reading files

Hi:

 

Excellent. Thanks for the advice/notice =).

 

Cheers,

Please use plain text.

Level 2

Level 2
WallyZ21
Posts: 50
Registered: ‎14-12-2011
Message 10 of 15 (394 Views)

Re: Problems with v0.99 and reading files

What if I need read and write access on files? What do I do?
Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。