LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: bobjob on September 19, 2010, 20:31:34

Title: [FIXED] AppletLoader temp directory
Post by: bobjob on September 19, 2010, 20:31:34
I have been going through the System properties, and it got me thinking about how the appletLoader handles temporary files.

Currently the applet loader uses "java.io.tmpdir". This works fine for Windows, as the temporary folder is alot more persistent, but on Mac it is cleared each time you restart the computer.

So I was thinking it might be better to use either:
"deployment.user.tmp"
or
check if "deployment.cache.enabled" is true
and check if "deployment.cache.max.size" < 0
then use "deployement.user.cachedir"
and fall back on "java.io.tmpdir".

at least in the case of Mac, Im not sure how linux handles temporary files. It gets annoying having to reload a complete package each time you restart, or log off and change user.

Title: Re: AppletLoader temp directory
Post by: bobjob on September 19, 2010, 21:02:04
I cant find anything on the net, about marking files as java cache, or temp.
Would anyone know a better way of handling this.

For now on Mac Ill just use the "user.home" path, and add an uninstall option.
Title: Re: AppletLoader temp directory
Post by: broumbroum on September 19, 2010, 22:31:28
Hi! I'm publishing applet on all 3 platforms win,mac and linux, and my java api is writing and reading from java.io.tmpdir as it runs. (I don't use AppletLoader, though)
But you're right, tmpdir should stay not persistent. Since I had to deal on my own with loading native libraries and such, java.library.path tells that user.home is valid on every platform so :

.jar -extract-> natives to user.home -loadnative-> run the applet.

I've got an extension handler as well (this is for browser plugin v.1 only):

.jar -copy-> ext.dirs-> run the applet (mac needs reboot of the browser).
on exit -ensure backup-> jars into user.home/.mystoredir/ -delete-> my ext.dirs .jars -delete-> tmp.files
Title: Re: AppletLoader temp directory
Post by: bobjob on September 20, 2010, 02:14:02
.jar -copy-> ext.dirs-> run the applet (mac needs reboot of the browser).
on exit -ensure backup-> jars into user.home/.mystoredir/ -delete-> my ext.dirs .jars -delete-> tmp.files

Its not easy to access the extension dir with Windows.
If your running Windows 7 you need admin permission to put files into program files (were java is located) also once the .jar is loaded into the classpath its not possible to delete it, deleteOnExit doesnt even work. I havnt tested this with a custom classLoader.
Title: Re: AppletLoader temp directory
Post by: broumbroum on September 20, 2010, 03:32:30
windows does have r/w exts.dir disabled, unless you run safari for windows which loads extensions .jar from a r/w folder located in the "virtual store" :
Code: [Select]
USERHOMEDIRECTORY + File.separator + "AppData\\Local\\VirtualStore\\Program Files\\Java\\" + dir + "\\lib\\ext"where dir = "jre6" or *jre7" resp. for java 6 and 7.

Anyway, with the Java 6 plugin 2, all applets could be using the WebStart deployment back-end without much code effort (then extensions directories become useless). As of the new plugin, applet tags may refer to the jnlp meta files to retrieve .jar resources natively.
Title: Re: AppletLoader temp directory
Post by: Matzon on September 20, 2010, 04:36:46
please! do not install into the ext dir! it can cause problems for everyone else.
Title: Re: AppletLoader temp directory
Post by: kappa on September 20, 2010, 15:58:15
"java.io.tmpdir" works really well on linux and windows, especially as it doesn't run into any permissions issues (like scary dialogs and access denied) and is nicely hidden as not to alert (scare) users that suddenly strange files are appearing on their computer (System.getProperty("user.home") is too obvious on windows). This should remain as is IMO.

As I understand it the issue here is mac only in that the temp directory is cleared on restart (was not aware of this). As a solution we can simply check if the appletloader is running on mac and then use a hidden directory location for the cache.

I propose
Code: [Select]
System.getProperty("user.home") + /.lwjglcache
What do you ppl think? (do note I don't have access to mac, so do point out if there's any issue with this solution especially relating to permissions or being too obvious to end users).





please! do not install into the ext dir! it can cause problems for everyone else.
agreed, please do not ever do this, this can cause tons of frustration for application totally unrelated to yours.
Title: Re: AppletLoader temp directory
Post by: ruben01 on September 21, 2010, 05:11:03
On linux "java.io.tmpdir" is /tmp which is also cleaned on every restart so using that as the cache on linux is also a problem.

Title: Re: AppletLoader temp directory
Post by: kappa on September 21, 2010, 08:43:16
On linux "java.io.tmpdir" is /tmp which is also cleaned on every restart so using that as the cache on linux is also a problem.

that's strange, i've used quiet a few distro's but not seen that folder being cleared on restart.
Title: Re: AppletLoader temp directory
Post by: ruben01 on September 21, 2010, 20:56:13
at least on ubuntu by default /tmp is deleted on reboot

it is controlled by the value of the TMPTIME variable in the '/etc/defaults/rcS' file
being 0 delete on reboot, -1 never delete and other values the number of days to keep the files

I am not sure if the other distros use the same config, and what the default values are.

Title: Re: AppletLoader temp directory
Post by: kappa on September 21, 2010, 21:08:59
ok so latest proposal

use the following on all platforms except windows
Code: [Select]
System.getProperty("user.home") + /.lwjglcache
on windows use we continue using
Code: [Select]
System.getProperty("java.io.tmpdir")
comments ?
Title: Re: AppletLoader temp directory
Post by: bobjob on September 23, 2010, 07:24:26
sounds good.

but should it be in a hidden directory?
I assume LWJGL applets are only going to get bigger an bigger.
people will also want to package runtime downloaded resources into the same folder for neatness (Id like to think so anyway).

anyway something to consider
Title: Re: AppletLoader temp directory
Post by: ryanm on September 23, 2010, 10:08:45
but should it be in a hidden directory?
Yes. A million times yes.
Title: Re: AppletLoader temp directory
Post by: kappa on September 23, 2010, 10:39:48
people will also want to package runtime downloaded resources into the same folder for neatness (Id like to think so anyway).

anyway something to consider

agreed it would be neater, but think it should be discouraged, just like its not recommended that you store stuff like your java game data in the same location as your java web start cache. e.g. the inner workings of how the appletloader saves/stores files might need to be changed in the future for some reason (it is gonna be changed for above issue), this could break stuff and cause various conflict with same named files, etc.

Secondly people using a mix of unsigned jar and lwjgl certificate jars, don't need any access to the file system. If you do have signed permission, its pretty trivial to just create your own local storage folder and even put files yourself in the same folder as the lwjgl cache folder if you really need.
Title: Re: AppletLoader temp directory
Post by: kappa on September 30, 2010, 19:36:16
Push for the lwjgl 2.6 is getting close, want to sort this issue out before the release.

so the current plan is to store the cache files on windows
Quote
System.getProperty("java.io.tmpdir")
and on everything else in
Quote
System.getProperty("user.home") + /.lwjglcache

however still feels a bit unclean and too visible to store a lwjgl cache folder in the user.home directory.

What would be the opinion to store it in
Quote
System.getProperty("user.home") + /.java/lwjglcache

I know that it would look and work pretty well on linux and at the same time tuck away the lwjgl cache files nicely and neatly in user java directory (also where java stores its cache files, so would be ideal). Is it the same situation on mac's too?
Title: Re: AppletLoader temp directory
Post by: bobjob on September 30, 2010, 19:39:50
What would be the opinion to store it in
Quote
System.getProperty("user.home") + /.java/lwjglcache
Yeah that sounds like a good idea, also if anyone else wants to use a variation of the applet loader (for non LWJGL use), or are familiar with it, they could also package temp files in the ".java" folder.
Title: Re: AppletLoader temp directory
Post by: kappa on September 30, 2010, 20:19:55
on linux this is a really nice location.

but can any mac users confirm if there is a System.getProperty("user.home")+".java" directory on mac by default?
Title: Re: AppletLoader temp directory
Post by: kappa on October 07, 2010, 20:34:41
ok this issue is now fixed, should be part of lwjgl 2.6.

solution used
Quote
protected String getCacheDir() {
      String cacheDir = System.getProperty("deployment.user.cachedir");
      
      if (cacheDir == null) {
         cacheDir = System.getProperty("java.io.tmpdir");
      }
      
      return cacheDir + File.separator + "lwjglcache";
   }
Title: Re: AppletLoader temp directory
Post by: bobjob on October 08, 2010, 01:05:09
Sound goods, just a few questions?

With that layout, will an end user be able to clean up resources easy enough, if they want to clean up/make space?

"deployment.user.cachedir" returns a value on Windows, I really think that "java.io.tmpdir" is good for windows, what is the benefit of the "deployment.user.cachedir"?

I think your original idea of a hidden folder in the home directory (if not Windows) is better. Wondering If I understood the new version right?
Title: Re: AppletLoader temp directory
Post by: kappa on October 08, 2010, 09:08:02
With that layout, will an end user be able to clean up resources easy enough, if they want to clean up/make space?
Search for 'lwjglcache' folder and delete it would be the easy way. Probably could even make an applet to do it for you (like adobe have a flash control panel on their site to allow clearing cookies and various settings).

"deployment.user.cachedir" returns a value on Windows, I really think that "java.io.tmpdir" is good for windows, what is the benefit of the "deployment.user.cachedir"?
There's not much difference IMO between the two locations on windows, both are equally difficult to find for the average user. Main reason to use "deployment.user.cachedir" is that its a single parameter that can be used on all platforms without getting bogged down in platform specific settings and likely more future proof. Other then that there isn't any big difference, can still be changed if you like.

I think your original idea of a hidden folder in the home directory (if not Windows) is better. Wondering If I understood the new version right?
Yup was the original idea but wasn't sure how it'd be like on Mac, after reading a few documents on the apple site, they actually recommend that application cache be stored at ~/Library/Caches/* so using the above parameter automatically puts cache files in the recommended location.
Title: Re: AppletLoader temp directory
Post by: bobjob on October 08, 2010, 09:22:35
Quote
There's not much difference IMO between the two locations on windows, both are equally difficult to find for the average user. Main reason to use "deployment.user.cachedir" is that its a single parameter that can be used on all platforms without getting bogged down in platform specific settings and likely more future proof. Other then that there isn't any big difference, can still be changed if you like.
The 2 Folder act very different on Windows, If you open the disks Properties and select "Disk Cleanup" or if hard drive space is getting slim it will show a popup its self, you can remove the temporary files (from the temp dir).
Title: Re: AppletLoader temp directory
Post by: kappa on October 08, 2010, 09:40:53
The 2 Folder act very different on Windows, If you open the disks Properties and select "Disk Cleanup" or if hard drive space is getting slim it will show a popup its self, you can remove the temporary files (from the temp dir).
Fair enough, good point. Will change Windows back to using "java.io.tmpdir". Be cool to be able to hook up the files to the java cache so that they can be cleared from the java control panel but don't think their is any easy way to do this.
Title: Re: AppletLoader temp directory
Post by: kappa on October 09, 2010, 12:17:36
ok fixed.