Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  jars and file reading / writing  (Read 2001 times)
0 Members and 1 Guest are viewing this topic.
Offline misterX

Junior Member




java forever!


« Posted 2004-08-03 05:51:56 »

hi,

i just wondered about this topic lately...
when making any sort of game, it is usual to package it as a jar (and often use it via web start). And once you do it, how can you for example prepare a directory for loading and saving games? or a directory of maps where custom ones can be added later?
Online kevglass

JGO Kernel


Medals: 166
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2004-08-03 08:10:05 »

The general pattern has become using the users home directory (System.getProperty("user.home")) and creating a directory to store stuff in for instance ".MyGameHere".

Kev

Offline misterX

Junior Member




java forever!


« Reply #2 - Posted 2004-08-06 19:09:40 »

well, there is some annoying detail: it won't be properly deleted when deinstalled (via JWS).

Couldn't we directly get the destination repertory of where JWS stores the jars?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #3 - Posted 2004-08-06 19:40:07 »

> loading and saving

I use "muffins" Smiley

They are like cookies but for webstart. Well, they are somewhat odd to handle and there aren't many examples on the net (the most useful site was actually written in korean Roll Eyes).

One of the annoying pitfalls is that you can't overwrite a muffin, which leads to a somewhat odd try/catch structure. Eg you need to delete it each time, but there won't be one on the first run.

I also added a nice method called showURL... it starts the client's default browser with the specified url as parameter.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
import javax.jnlp.*; //you need the webstart toolkit
import java.net.*;
import java.io.*;
[...]
      public boolean showURL(URL url) //this one is pretty nice, too
     {
            try
            {
                  BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
                  return bs.showDocument(url);
            }
            catch(UnavailableServiceException ue)
            {
                  return false;
            }
      }

      public void writeConfig()
      {
            PersistenceService ps;
            BasicService bs;
            URL configURL;
            try
            {
                  ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService");
                  bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
                  URL baseURL = bs.getCodeBase();
                  System.out.println("CodeBase was " + baseURL);
                  configURL = new URL(baseURL, "config");
            }
            catch(Exception e)
            {
                  System.out.println("[E]failed to save configuration");
                  return;
            }
            try
            {
                  ps.delete(configURL);
            }
            catch(Exception e)
            {
                  System.out.println("there wasn't a muffin - first save");
            }
            try
            {
                  ps.create(configURL, 1024); //1024 bytes for our data

                  FileContents fc = ps.get(configURL);
                  DataOutputStream os = new DataOutputStream(fc.getOutputStream(false));
                  os.write[...whatever...]
                  os.flush();
                  os.close();
                  System.out.println("saved configuration");
            }
            catch(Exception e)
            {
                  System.out.println("[L]failed to save configuration");
                  e.printStackTrace();
            }
      }

      public void readConfig()
      {
            try
            {
                  PersistenceService ps = (PersistenceService)ServiceManager.lookup("javax.jnlp.PersistenceService");
                  BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
                  URL baseURL = bs.getCodeBase();
                  URL configURL = new URL(baseURL, "config");
                  FileContents fc = ps.get(configURL);
                  DataInputStream in = new DataInputStream(fc.getInputStream());

                  in.read[...whatever...];
                 
                  in.close();
            }
            catch (Exception e)
            {
                  System.out.println("unable to load settings");
            }
      }
[...]


The muffin location on win9x is here:
<WINDOWS>\<userdata>\Sun\Java\Deployment\javaws\cache\muffins\
(and my program seems to be the only one which uses muffins)

Well, you can't save as much data as you like to. There are some limits and you can gently ask for some more room... haven't grasped the whole concept since the documentation is somewhat fuzzy there.

However, the good thing is that you won't need any permissions for the stuff above.

弾幕 ☆ @mahonnaiseblog
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2004-08-06 19:49:28 »

I forgot to mention that the stuff above only works with programs startet through webstart!

So... get a server for your lan (for less pain Wink). I recommand xampp. It's a nice package with apache, php, mysql and what's not. The setup is a piece of a cake (I mean it). Oh and it's free Smiley

http://www.apachefriends.org/en/xampp.html

Oh and that [E] and [L] thingies in the source above just mean "early" and "late".

弾幕 ☆ @mahonnaiseblog
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2004-08-06 19:49:53 »

Indeed. And I'm convinced that when webstart was announced, this functionality was on the features list - per-application data that was managed *by webstart*. In the end, that seemed to turn out just to be the prefs API (which doesn't quite do that), but I'm sure I saw this feature clearly described in Sun marketing docs Sad.

Or am I dreaming?

Or is there such a thing and I just haven't found it yet? Wink

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #6 - Posted 2004-08-06 20:04:17 »

You posted whilst I was responding Smiley.


Quote
> loading and saving

I use "muffins" Smiley


Is this, then, what I was talking about? The official webstart-encapsulated way of storing config etc? Cool.

The problem is...javax.jnlp isn't included in the JDK (docs). This seems strange, since I would have thought that the packaging system for the main way of distributing apps would be considered a core part of the JDK!

Quote

However, the good thing is that you won't need any permissions for the stuff above.


Ah, yes, that was another one of the features touted...

malloc will be first against the wall when the revolution comes...
Offline misterX

Junior Member




java forever!


« Reply #7 - Posted 2004-08-06 20:14:02 »

again i'm very impressed onyx! bravo!
...but in the same time, it looks extraordinary complex! For one config file, ok, but i guess listing saved games and other game data would be a lot of work, isn't it?  :-/

btw, i didn't understood what you meant with your lan stuff in the second post.  Huh
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #8 - Posted 2004-08-06 20:24:42 »

>The problem is...javax.jnlp isn't included in the JDK (docs).

Yea, well you need that webstart toolkit

>This seems strange, since I would have thought that the
>packaging system for the main way of distributing apps
>would be considered a core part of the JDK!

No, it's not strange.

It's silly. The jnlp jar needed for compilation is... behold... a whopping 7 kilo bytes in size Roll Eyes

Well, that toolkit thingy is somewhere over at suns page (oh oh). Stumbled upon it somewhat accidently. Actively searched for it 2 weeks ago and was unable to find it... aw... I hate the structure of sun's pages.

Btw that jnlp.jar is only needed for compilation. You don't need to include it into your distribution (because webstart has that classes... uhm... Roll Eyes)

@misterX
>but in the same time, it looks extraordinary complex!

Indeed it is. I guess it makes sense to wrap up that stuff a bit, because it usually doesn't matter *where* it fails - just if.

弾幕 ☆ @mahonnaiseblog
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #9 - Posted 2004-08-06 20:37:54 »

Quote
[...]
btw, i didn't understood what you meant with your lan stuff in the second post.  Huh


Ah... uhm...

Well, if you want to start it through webstart it (jnlp+jar(s)) needs to come to your machine through the http protocol. That only works if you have a server and/or webspace somewhere.

However, uploading all the time makes testing really tiresome, therefore it's much better if you have a local webserver either within your lan (=local area network) or on your own machine. Testing is much nicer with xampp (or apache for that matter).

Eg http://onyx.bubblegumcrises.jp/tinyrivers/ is infact just a directory on my harddrive Grin <edit>it's of course only accessable within my lan and not from the outside (the www)</edit>

Btw I picked that domain name, because it can't exist. If it would exist, I won't be able to acess it.

That domain stuff is part of the network configuration. "bubblegumcrises.jp" is the domain and "onyx" is the name of my machine (uh uh how creative).

Well, if you don't need fancy names (hehe) you can aswell just type http://<ip>/subdir or http://localhost/subdir

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline misterX

Junior Member




java forever!


« Reply #10 - Posted 2004-08-06 20:58:35 »

ah, oh, thanks
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #11 - Posted 2004-08-07 08:43:40 »

Two muffin utility classes over there:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=share;action=display;num=1091875312;start=0#0

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (41 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!