Page 1 of 2

Info pages, can they be local?

Posted: 05.05.2006, 10:56
by Stormdancer
Ello all, I'm new to this so be gentle :D

I'm writing an add-on to be used in a Live Action Roleplay, it's for the pilots to use as a navigation program.

I'd love to write a small section of blurb for each of the star systems in the add-on, but the machines it will be loaded up on do not have internet access.

Anyone give me a clue as to whether it's possible to use local html pages for in-engine info clicks? Or how to do it?

I can't get it to work.

Posted: 05.05.2006, 12:23
by Chuft-Captain
I have used the following technique which seems to work...
(using XP and firefox)

1. Open the local page in a browser
2. In the navigation bar of your bowser, highlight/select the address of your page in the address box.
It will look something like this:

Code: Select all

file:///c:/Documents%20and%20Settings/...../info/001.html

3. In the SSC file, paste this into the InfoURL string for an object.
4. Save the SSC and restart Celestia.
5. Select the object, and right-mouse->Info

It should open your local page.

(The key is the "file:///" at the beginning of the path name)

Posted: 05.05.2006, 13:14
by rthorvald
Chuft-Captain wrote:Icode]file:///c:/Documents%20and%20Settings/...../info/001.html[/code]

The problem with this is that it only works in Windows. On other OSes, that line is just gibberish.

I, too really wish for a function for local infourls:
http://celestiaproject.net/forum/viewtopic.php?t=8052
... It would enable us to distribute Add-Ons with customized fact sheets or other information. And no, an online possibility isn??t adequate - many people aren??t online all the time, and besides, it would make for less web traffic for the developer.

But, not unimportant, it is possible to start a Cel or Celx script via the InfoUrl declaration if the user??s mimetypes are set for it. That brings us veeeery close to interactivity with the Add-On designer inside Celestia.

Of course, this too can be done online. But i want to be able to package everything in the box...

- rthorvald

Posted: 05.05.2006, 13:35
by Chuft-Captain
rthorvald wrote:
Chuft-Captain wrote:Icode]file:///c:/Documents%20and%20Settings/...../info/001.html[/code]
The problem with this is that it only works in Windows. On other OSes, that line is just gibberish.
....
Of course, this too can be done online. But i want to be able to package everything in the box...
That too was my motivation for investigating this technique, because I hoped for a way to distribute local documentation with an addon, but I gave up in the end because of the issue of making it portable. (and I don't really want to have to maintain a huge website ad-infinitum for documentation)
In the end, I decided it was not really worth the effort if it wouldn't work on at least Windows/MAC/UNIX/LINUX.

Posted: 05.05.2006, 23:00
by Christophe
This seems trivial to implement. The current directory just has to be prepended to the relative URL when the SSC file is parsed.

The thing is, should that be the default behaviour? are there cases where you'd want relative URLs to be relative to the installation directory (as it is the case now) rather than relative to the directory of the SSC file?

Posted: 06.05.2006, 01:08
by rthorvald
Christophe wrote:The thing is, should that be the default behaviour? are there cases where you'd want relative URLs to be relative to the installation directory (as it is the case now) rather than relative to the directory of the SSC file?


I can??t think of any Add-On where it would be neccecary to point to the installation dir. But sooner or later someone will want to refer to something that needs to be there... Once this function becomes a reality, people will use it for new things we haven??t thought of yet.

But for me, having it relative to the ssc file would be optimal. Isn??t it possible to make it switch it on / off with a symbol in the URL string or something?

Anyway, i will happily take whatever possibility is easy to implement.

- rthorvald

Posted: 06.05.2006, 09:16
by Christophe
Here is a patch:

Code: Select all

Index: src/celengine/solarsys.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/solarsys.cpp,v
retrieving revision 1.58
diff -u -r1.58 solarsys.cpp
--- src/celengine/solarsys.cpp  19 Jul 2005 20:30:56 -0000      1.58
+++ src/celengine/solarsys.cpp  6 May 2006 09:10:38 -0000
@@ -293,8 +293,16 @@
     body->setLifespan(beginning, ending);

     string infoURL;
-    if (planetData->getString("InfoURL", infoURL))
+    if (planetData->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            infoURL = path + "/" + infoURL;
+        }
         body->setInfoURL(infoURL);
+    }

     double albedo = 0.5;
     if (planetData->getNumber("Albedo", albedo))
Index: src/celengine/deepskyobj.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/deepskyobj.cpp,v
retrieving revision 1.8
diff -u -r1.8 deepskyobj.cpp
--- src/celengine/deepskyobj.cpp        21 Nov 2005 09:22:51 -0000      1.8
+++ src/celengine/deepskyobj.cpp        6 May 2006 09:10:38 -0000
@@ -146,8 +146,16 @@
         setAbsoluteMagnitude((float) absMag);

     string infoURL;
-    if (params->getString("InfoURL", infoURL))
+    if (params->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            infoURL = path + "/" + infoURL;
+        }
         setInfoURL(infoURL);
+    }

     return true;
 }


Is it possible under Windows to use an InfoURL of the form : "C:/...." or is the "file:///" required? If it is, then the patch won't work for addons not installed in the main "extras" directory, but that can be fixed easily, just let me know.

Posted: 06.05.2006, 10:28
by Chuft-Captain
Christophe wrote:Is it possible under Windows to use an InfoURL of the form : "C:/...." or is the "file:///" required? If it is, then the patch won't work for addons not installed in the main "extras" directory, but that can be fixed easily, just let me know.

The "file:///" IS required in windows.
That's a good try Cristophe, but I'm not sure if that will still work for web addresses. I think it may break the current HTTP functionality. Have you tested it with an external website address? An absolute website address will have no relation to the current directory or install directory.
Perhaps what is needed is a "InfoBASEURL" tag which could be specified as either a local address OR a web address, for example:

Code: Select all

"file:///C:\Program Files\Celestia"
or
"http://mywebsiteforaddondocumentation.com/"


then the InfoURL could just be the extra relative page address.

Appending them together would give for example:

Code: Select all

WEB:
http://mywebsiteforaddondocumentation.com/addons/spaceshipone/info/001.html

OR

Code: Select all

LOCAL:
file:///file:///C:\Program Files\Celestia\extras\addons\info\001.html


This could work for both local and web base documentation as the creator desired.
Does that make sense?

Posted: 06.05.2006, 13:01
by Christophe
No, it doesn't break the current HTTP functionality, the base path is prepended only if the InfoURL is relative, that is if it doesn't include the colon character.

Code: Select all

   # Some external reference
   InfoURL "http://somesite.com/page.html

   # Local file part of the addon, relative to the directory of the SSC file
   InfoURL "html/page.html"


The following patch takes care of the file:/// part for absolute windows paths.

Code: Select all

Index: src/celengine/solarsys.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/solarsys.cpp,v
retrieving revision 1.58
diff -u -r1.58 solarsys.cpp
--- src/celengine/solarsys.cpp  19 Jul 2005 20:30:56 -0000      1.58
+++ src/celengine/solarsys.cpp  6 May 2006 12:51:23 -0000
@@ -293,8 +293,22 @@
     body->setLifespan(beginning, ending);

     string infoURL;
-    if (planetData->getString("InfoURL", infoURL))
+    if (planetData->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            if (path[1] == ':')
+            {
+                // Absolute Windows path, file:/// is required
+                infoURL = "file:///" + path + "/" + infoURL;
+            } else {
+                infoURL = path + "/" + infoURL;
+            }
+        }
         body->setInfoURL(infoURL);
+    }

     double albedo = 0.5;
     if (planetData->getNumber("Albedo", albedo))
Index: src/celengine/deepskyobj.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/deepskyobj.cpp,v
retrieving revision 1.8
diff -u -r1.8 deepskyobj.cpp
--- src/celengine/deepskyobj.cpp        21 Nov 2005 09:22:51 -0000      1.8
+++ src/celengine/deepskyobj.cpp        6 May 2006 12:51:23 -0000
@@ -146,8 +146,22 @@
         setAbsoluteMagnitude((float) absMag);

     string infoURL;
-    if (params->getString("InfoURL", infoURL))
+    if (params->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            if (path[1] == ':')
+            {
+                // Absolute Windows path, file:/// is required
+                infoURL = "file:///" + path + "/" + infoURL;
+            } else {
+                infoURL = path + "/" + infoURL;
+            }
+        }
         setInfoURL(infoURL);
+    }

     return true;
 }


I don't see how the InfoBASEURL would help, it essentialy brings us back where we started: how is the addon producer supposed to know where the addon has been installed?

Posted: 06.05.2006, 22:08
by Paolo
Thanks GOD... a little amount of C++ from a Celestia developer is flowing again in this forum :!:

:wink:

Posted: 06.05.2006, 22:38
by Christophe
I'm glad those ten lines of C++ made someone happy :-)

And it doesn't even compile... shame on me!

Here is a new patch which includes a fix for deepsky objects under KDE:

Code: Select all

Index: src/celengine/solarsys.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/solarsys.cpp,v
retrieving revision 1.58
diff -u -r1.58 solarsys.cpp
--- src/celengine/solarsys.cpp  19 Jul 2005 20:30:56 -0000      1.58
+++ src/celengine/solarsys.cpp  6 May 2006 22:36:28 -0000
@@ -293,8 +293,20 @@
     body->setLifespan(beginning, ending);

     string infoURL;
-    if (planetData->getString("InfoURL", infoURL))
+    if (planetData->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            if (path[1] == ':')
+                // Absolute Windows path, file:/// is required
+                infoURL = "file:///" + path + "/" + infoURL;
+            else
+                infoURL = path + "/" + infoURL;
+        }
         body->setInfoURL(infoURL);
+    }

     double albedo = 0.5;
     if (planetData->getNumber("Albedo", albedo))
Index: src/celengine/deepskyobj.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celengine/deepskyobj.cpp,v
retrieving revision 1.8
diff -u -r1.8 deepskyobj.cpp
--- src/celengine/deepskyobj.cpp        21 Nov 2005 09:22:51 -0000      1.8
+++ src/celengine/deepskyobj.cpp        6 May 2006 22:36:28 -0000
@@ -146,8 +146,19 @@
         setAbsoluteMagnitude((float) absMag);

     string infoURL;
-    if (params->getString("InfoURL", infoURL))
+    if (params->getString("InfoURL", infoURL))
+    {
+        if (infoURL.find(':') == string::npos)
+        {
+            // Relative URL, the base directory is the current one,
+            // not the main installation directory
+            if (resPath[1] == ':')
+                // Absolute Windows path, file:/// is required
+                infoURL = "file:///" + resPath + "/" + infoURL;
+            else
+                infoURL = resPath + "/" + infoURL;
+        }
         setInfoURL(infoURL);
-
+    }
     return true;
 }
Index: src/celestia/kde/selectionpopup.cpp
===================================================================
RCS file: /cvsroot/celestia/celestia/src/celestia/kde/selectionpopup.cpp,v
retrieving revision 1.12
diff -u -r1.12 selectionpopup.cpp
--- src/celestia/kde/selectionpopup.cpp 2 Feb 2006 23:37:48 -0000       1.12
+++ src/celestia/kde/selectionpopup.cpp 6 May 2006 22:36:28 -0000
@@ -209,6 +209,8 @@
         }
         else if (sel.deepsky() != NULL)
         {
+            url = QString(sel.deepsky()->getInfoURL().c_str());
+            if (url == "")
                 url = QString("http://simbad.u-strasbg.fr/sim-id.pl?protocol=html&Ident=%1")
                       .arg(sim->getUniverse()->getDSOCatalog()->getDSOName(sel.deepsky()).c_str());
         }


Now if I can get some feedback from Windows users, I'll just commit it.

Posted: 06.05.2006, 22:49
by Stormdancer
Wow.
Just wow.

Cheers for the replies guys, though most of that is a little deep for me.

The fictional navigation addon will be running on windows only, so I'll try the

Code: Select all

file:///c:/Documents%20and%20Settings/...../info/001.html
thing on Monday and see how far I get. I'm assuming that I will have to use the full and exact local address each time.
No idea how to even start patching with your code, Christophe.

Since the use I have for this addon is controlled, I can set the local url to my specification, and I only have to do 6 installs, tops.

I'll let you all know how I get on (or come back and bleat for help :D ).

edited to make sense

Posted: 07.05.2006, 13:32
by Chuft-Captain
Christophe wrote:No, it doesn't break the current HTTP functionality, the base path is prepended only if the InfoURL is relative, that is if it doesn't include the colon character.

Code: Select all

   # Some external reference
   InfoURL "http://somesite.com/page.html

   # Local file part of the addon, relative to the directory of the SSC file
   InfoURL "html/page.html"


OK, with this explanation, I now understand your implementation Christophe. You're testing for the presence of the ":" in the "http:", so external web references will always be treated as absolute references, and relative local page references can never contain a ":", unless of course they are specified in full (in which case they will be treated "absolute"-ly :wink:).
I like what you've done Christophe. This will be a nice addition, if and when it can be included in an official release.
Thanks for your efforts.

Posted: 07.05.2006, 23:02
by rthorvald
Christophe wrote:I'm glad those ten lines of C++ made someone happy


Yes, me :-) Thanks!
I hope it goes in the next official release...

- rthorvald

Posted: 03.05.2007, 14:09
by rthorvald
... Are this patch going into 1.5?

- rthorvald

Posted: 03.05.2007, 15:56
by chris
rthorvald wrote:... Are this patch going into 1.5?

- rthorvald


Yes, Christophe's patch has already been committed to CVS and will be in version 1.5.0.

--Chris

Posted: 04.05.2007, 18:43
by rthorvald
chris wrote:Yes, Christophe's patch has already been committed to CVS and will be in version 1.5.0.


Great!
Thanks,

- rthorvald

Posted: 08.05.2007, 14:48
by rthorvald
Hm...
It does not work in 1.5 Pre 1, and not in 1.5 Pre 2 either... Is it not in yet, or am i doing something wrong?

I thought the Addon folder in question would be root, so that:

- If the HTML doc resides in the same dir as the SSC file, the address would be:

"myhtml.html"

... Whereas if i put it in, say, the data folder, the address would be:

"data/myhtml.html"

Neither of these work.

- rthorvald

Posted: 09.05.2007, 23:12
by rthorvald
... Can nobody explain why this does not work in 1.5 Pre 2 (dirkpitts latest build)?

- rthorvald

Posted: 21.05.2007, 14:16
by Christophe
Hi Runar,

I've tested it again under KDE, it does work.

If the ssc and page.html are in the same folder, the following should work:

Code: Select all

InfoURL "page.html"


The problem is probably specific to OSX and the way InfoURLs are handled. You should ask Dirkpitt to look into it.