It is currently Thu Mar 30, 2017 11:39 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: resources in inside subdirectories
Unread postPosted: Mon Aug 29, 2016 3:10 am 
Offline

Joined: Wed May 04, 2016 6:09 pm
Posts: 71
Hi Nicolas-- I am still having problems getting my resources to be included in the BASIC! compiler.
I have everything under the rfo-basic/data directory in internal memory and the main directories show up but I am pretty sure it isn't including them in my apks. Are subdirectories allowed ?

I tried my voice food diary for example and it didn't include any of of the html icons or sampledb file.

I will try it on my old LG Transpyre. The phone I am having problems with is a Samsung J3 running Android 6.0.1


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Mon Aug 29, 2016 4:18 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5459
Location: Paris, France
Hi Chris, yes subdirectories are allowed. When you select a folder to be included as a resource in the Compiler, all its data is recursively added in the APK (files, subfolders with or w/fo files...)
If you open your apk as a zip file and look inside it, you should see everything is correctly present in assets/<app_folder>/data

Now there's a limitation in the Compiler for 2 things: the html mode and databases (you are not lucky, you use both :oops: )
Both HTML and SQL commands need the files on sdcard, they cannot render (in the case of HTML) or operate (in the case of SQL) files inside the APK.

As you may have noticed, the BASIC! Compiler doesn't have an option to copy resources to SD at startup. This is an intentional choice on my side, to keep the options small in number and to simplify the user's actions.

So for now you need to deal with these resources and copy them to SD yourself, directly in your code...

The GW lib has been modified a few versions back to do that (read the last bullet point from this post). You can adapt the dedicated GW function to your needs and call it for each of your resources.

Just add this routine at the top of your program (you may have to adapt the resource list after "IF isApk()", I only had an old version of the Voice Calorie Counter to get the resource list from):
Code:
FN.DEF IsApk() % return true (1) if we are in apk mode, false (0) otherwise
  FILE.EXISTS Editor, "../source/Sample_Programs\f01_commands.bas"
  FN.RTN (!Editor)
FN.END

FN.DEF PutResOnSd(f$) % make sure the file f$ is on sd-card, else try to copy it from asset
  FILE.EXISTS onSd, f$        % This function is to be used after testing: IF IsApk() THEN ...
  IF !onSd
    BYTE.OPEN r, fid, f$      % open from assets
    IF fid<0 THEN FN.RTN 0    % file does not exist
    PRINT "Unpacking " + f$
    j = IS_IN("/", f$)
    WHILE j % create subfolder hierarchy for this file, if any
      FILE.MKDIR LEFT$(f$, j)
      j = IS_IN("/", f$, j+1)
    REPEAT
    BYTE.COPY fid, f$
  END IF
FN.END

IF IsApk()
  h$ = "html/images/"
  ARRAY.LOAD htmlRes$[], "autoc.png", "graphs.png", "green.png", ~
     "red.png", "remind.png", "scale.png", "star.gif", "yellow.png"
  ARRAY.LENGTH nres, htmlRes$[]
  FOR i=1 TO nres
    PutResOnSd(h$ + htmlRes$[i])
  NEXT
  PutResOnSd("sampledb/samplefooddb.txt")
END IF

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Mon Aug 29, 2016 5:40 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5459
Location: Paris, France
Chris, if the workaround above is too much trouble, should I add an additional (super advanced) option "Dump APK resources to SD-Card" ?
(and autoset it to true in case of HTML and/or SQL commands ?)

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Tue Aug 30, 2016 2:42 pm 
Offline

Joined: Wed May 04, 2016 6:09 pm
Posts: 71
Thanks Nicolas!

I tried your solution and it seems to work really well.. In fact I think my app launches faster since
it takes less time copying the resources over on subsequent runs.

I'm for anything that makes apps launch quicker... I don't think I need the "copy to SD" option at this point but
thanks for offering.

I am pretty sure that the apks are indeed smaller from the rfo-compiler. My voice food diary apk is only 385Kb from the rfo compiler whereas it came out to 586Kb on QuickAPK on my PC (I did not assign an icon yet for the compiler version but I don't think it's that significant). Not sure why there is such a big discrepancy but I would even hazard to say that the rfo-compiler's apks seem to run faster than the PC generated ones.


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Tue Sep 13, 2016 3:36 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 410
Hmm... the only problem with the code is that if I alter an original resource file, I don't think it will
automatically get updated when installing a new apk.

I can check the timestamps and also replace it if the file is newer.


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Tue Sep 13, 2016 5:12 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5459
Location: Paris, France
That's right, you need to deal with the updated html resources yourself, a little tedious.

AFAIK there is no timestamp in Android file system, so you would need to check content of file, or use a hash of the file.

...which makes me think we don't have an MD5() command in BASIC! and it would be very useful!

Another new command in my todo list ;)

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Tue Sep 13, 2016 6:27 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5459
Location: Paris, France
Hmm but hash wouldn't work, because when you try to access a file for read in an APK the precedence is always to check in assets first, then if it doesn't exist, on sd.
It means that if you have a file both on sd and in assets, with same name, it is impossible to access the one on sd (and to calculate its hash).

So I think the preferred method in this case would be to keep a version file somewhere on sd (and *not* in assets) to tell what version of your resources is on sd.
If you don't want the user to interfere with this version file (modify or delete it) I would suggest to store it in the protected space.

Does it make sense somehow? :?

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Tue Sep 13, 2016 11:00 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2785
Location: Colorado, U.S.
Other way around. The file commands always look on the sd first, then assets. If you copy an asset (or resource) to the file system, you can no longer access the asset.

Files in the file system do have timestamps. We don't have a BASIC! command to get at them, but you can use a System command. However, assets and resources do not have timestamps.

We really do need an easier way to access the app-private protected file space.

- Marc


Top
 Profile  
 
 Post subject: Re: resources in inside subdirectories
Unread postPosted: Mon Mar 20, 2017 9:00 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 287
Look also at:

http://rfobasic.freeforums.org/post35796.html#p35796

Gregor


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred