Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Android read file with fopen

Author
Message
7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 26th Dec 2012 17:35
I have a problem to port my game on Android, we use tinyxml to read some files and the tinyxml use fopen but seem that the file we pass with the path is not recognized correctly.

In PC and Mac the file are correctly opened but on Android not. The file are all under asset and if i try to open an image file directly i haven't problems but when i need to open the xml file the fopen doesn't found it.

Any solution ?

Thanks a lot.

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 26th Dec 2012 19:22
droid is exstremely case sensetive!

You havent named a file x.png and try to load it with x.Png?
Because droid thinks its two differrent files.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 27th Dec 2012 07:03
The filename is correct i also print it but the fopen doesn't open it and i don't know why. I can open any file of my media if i load them directly with the AppGameKit LoadImage or similar functions but if i use the fopen to open a .xml or .tmx (tiled format) file it doesn't open it.

In some android forum someone say i need the full path but i can't retreive the full path in any way with the command i have and i can't try if is true and work.

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 27th Dec 2012 10:07
Try getting a path to the current (app) dir BEFORE starting AppGameKit and saving it in a string variable. As soon as it starts, AppGameKit will change the current directory to the write folder, and your stuff will not be there.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 27th Dec 2012 10:16
Which command i can use ?

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 27th Dec 2012 12:03
I don't know in VS.

In Pascal:

var
dir : AnsiString;

...
dir := GetCurrentDir;

As I said before, this must be done before initialising AGK.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 27th Dec 2012 12:09
getcwd() might be what you're after.

7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 28th Dec 2012 11:23 Edited at: 28th Dec 2012 14:18
Anyway for me is a mistery and i really want to know how to maske it work.

LoadImage("image.png");

result ok

fopen("image.png");

file not found.

If i use the getcwd() at the beginning of everything i can only get the /, instead if i use it a little after i get the destination folder set by agk but i never 1 time got the data path.

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 29th Dec 2012 22:48
If the file you are trying to open is from the assets folder of a tier 2 app then it cannot be opened with fopen as it is actually zipped up into the .apk file and must use special commands to access it like so

where state->activity is the ANativeActivity pointer and state is the android_app pointer passed into android_main.
7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 30th Dec 2012 19:03
Hi Paul,
thanks a lot for your answer, i will check but what if i move the file inside the Media ? assets/Media ?? From there i can read the images with LoadImage but seem that i still can't read the file with fopen.

Unfortunately i don't know how to avoid the use of fopen also because all the agk commands doesn't allow to open and read a file like the fopen. In iOS we have solved using iOS commands but on Android i really don't know what to do and without the way to load all my level files i can't release the game.

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 30th Dec 2012 19:50
Sounds like you'll have to port TinyXML to Android. I don't envy you that task for sure.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 30th Dec 2012 23:46
Quote: "what if i move the file inside the Media ? assets/Media ?? From there i can read the images with LoadImage but seem that i still can't read the file with fopen"


Everything inside the assets folder is zipped up, including sub directories. LoadImage uses the asset loading code from my previous post to read files from the asset folder. You may be able to use the AppGameKit command OpenToRead to open the file and read the data you need from it.
7RS
11
Years of Service
User Offline
Joined: 10th May 2012
Location:
Posted: 2nd Jan 2013 06:45 Edited at: 3rd Jan 2013 12:09
@Dar13, i already use TinyXML for Android, there aren't differences between Android and PC/Mac version, iOS is different but not Android. As Paul said if the data are all zipped i need to use a command to extract them. I'll try with what Paul suggested.

@Paul
Quote: "AAssetManager* assetManager = state->activity->assetManager;
AAsset* asset = AAssetManager_open(assetManager, szPath, AASSET_MODE_UNKNOWN);"


What i have to include to use this kind of command ? is possible for you to write a very simple example ?

Thanks.

I think i have solved the problem, i wrote my own reader without fopen and now seem to work fine but the game has another problem with an AppGameKit command and i will open another discussion about it.

http://www.7ravenstudios.com
https://www.facebook.com/pages/7-Raven-Studios/102567824318?ref=hl
https://www.facebook.com/groups/391126020940838/
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 3rd Jan 2013 17:59 Edited at: 3rd Jan 2013 18:00
They are part of the NDK command set in
#include <android/native_activity.h>
and
#include <android/asset_manager.h>
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 4th Jan 2013 21:06
Quote: "@Dar13, i already use TinyXML for Android, there aren't differences between Android and PC/Mac version, iOS is different but not Android. As Paul said if the data are all zipped i need to use a command to extract them. I'll try with what Paul suggested."

I know that you were using TinyXML, but you also said it wasn't working because you couldn't get the right file path to the fopen() function. What I meant by porting to Android is that you'd have to replace fopen and the other C functions with Android compatible ones.

Quote: "I think i have solved the problem, i wrote my own reader without fopen and now seem to work fine but the game has another problem with an AppGameKit command and i will open another discussion about it."

What do you mean by wrote your own reader? You created your own XML parser in AppGameKit T2, or you created a way to pass the data to TinyXML somehow?

Login to post a reply

Server time is: 2024-05-07 00:34:48
Your offset time is: 2024-05-07 00:34:48