Archive

Archive for June, 2009

Opera Unite shareFile problem and solution

WARNING: I’m not very experienced with Opera Unite, the technique presented in this post works for me and doesn’t has to be the best way possible. If you find a better way please let me know.

Opera Unite Version: first release

In Opera Unite all files are on the server and can not be accessed without specify allowing it. But when you share a file using the given APIs opera.webserver.webserver.shareFile(..) method this breaks and becomes unavailable. This seems to be somehow caused be loading the file again while the last download was still running.

As described on http://unitehowto.com/. (Thanks for the great work you are doing)
He found a way to solve this problem, he reloads the scripts on each request but I have thought there has to be an other way.

And I found one while looking through the different examples opera provides with unite. The solution for this problem seems that you have to share and unshare the file on each request. I don’t know if this is a bug or by indent. Opera can you tell us more?

But know I want you to show the solution I came up with.

Everything starts in the window.onload method, this method is called when the service is started. So everything the server has to initialize should be done here.

The first step is to get the webserver and filesystem object. This has nothing to-do specifically with this problem.

var webserver = opera.io.webserver;
var filesystem = opera.io.filesystem;

But the next line is important. You have to mount the the ‘application’ directory.So you have access to the application files.

this.application = filesystem.mountSystemDirectory('application');
webserver.addEventListener('_request', request, false);           

You also have to event Listener for the ‘_request’ event. This event will always be called when a site is requested. In this method we will do the work to make the files available.

And now lets start the most work.

function request(evt) {
    // make alias
    webserver = opera.io.webserver
    var request = evt.connection.request;
    var path = request.uri;

    path = path.substr(webserver.currentServicePath.length, path.length);
    path = path.replace(/\?.*$/, ''); // remove the query path
 
    if (path != "") {
        if (staticFiles[path]) {
            var file = self.application.resolve(staticFiles[path]);
            opera.io.webserver.shareFile(file, path);
            response.closeAndRedispatch();
            opera.io.webserver.unshareFile(file);
            return;
        }
    }

   if (response){
    response.closeAndRedispatch();
   }
}

This is a lot of code so lets get started. We begin the class by getting get webserver, request and the path which was requested.

We now have to remove the current service name from the string. The path has the format

/[serviceName]/[request].

After the service name and query path is removed we have to heck if the path is even contains any data now. If we call the default start site this string will be empty because we haven’t’ requested anything. If the file exists I check in the staticFiles directory if we have a static file defined with the given path. The directory looks like the following,

var staticFiles = { 'imgs/img.jpg': 'sharedFiles/imgs/img.jpg' }

The first element is the path the file should be accessed by the user and the value define the actual path of the file.

If we have defined a static file under the given path we will continue and call application.resolve(..) on the value of the staticFile directory. This gives us the the file we can now share.

for this we call webserver.shareFile(file, path) and feed in the file we just received and the path we generated before.

After the file is shared we call webserver.closeAndRedispatch(). This closes the connection and redispatch the request to the Web server.

After that we just have to unshare the file again. webserver.unshareFile(file) and call return;

But we also have to handle the case if we haven’t defined the static-file the user requested. This is done in the last if(response) block. Here we just webserver.closeAndRedispatch() and let the webserver handle what to do, normally show an 404 Not found error page.

This is everything necessary to get static-files shared without getting the resource broken after some time.

That’s it hope this information is helpful.

Categories: javascript, operaUnite

My Top-3-Developer Tools

The German msdn blog “Softwarehersteller in Deutschland” is asking what are your favorite 3 developer tools and here are mine:

1. Visual Studio + Add-Ins

The first tool I cannot live without is Visual Studio. I always try to use it but sometimes,  in school, I have to use different IDEs .. and then I know again why I love Visual Studio.
Also the Add-Ins available for Visual Studio are so great. I could have listed them as tools as well, but I don’t count them here. Some Add-Ins I’m using a lot are GhostDoc, TortoiseSVN, TestDriven.Net … just to mention some examples.

2. ToDoList – free

The second tool I have chosen is ToDoList. This is a simple but great todo-list management applications.
It has all the features a lot of the expensive tools have, but for free.
The UI isn’t something special but it’s functional and that’s what count.

3. XmlMarker – free

clip_image001XmlMarker is the third tool I have chosen, as I work quite often with xml files.
When the xml-files are small and simple you can manage them in Visual Studio. But when the files get complex and large, as Collada files you can’t deal with them in Visual Studio.
Visual Studio is not designed for those long lines and that much data.

But XmlMarker really handles this great.  This is the best xml-tool I have found and it’s free.

Categories: all

Just some small VS 10 Problems and how-to fix them

Today I just wanted to check some new Add-Ins which added support for Visual Studio 2010 in their latest release.

I wanted to test TestDriven.Net which added support in the 2.22.2468 RTM, Version. Also GhostDoc now supports Visual studio 2010.

Enough commercials for this post :) now it’s time to actually talk about the problems I mentioned and I wanted to write about in the first place.

Problem 1:

The first problem I encountered was that C# intellisense was not showing up for any parameters, it was showing up for everything except parameters. which was really annoying. After some time of searching on google and in the msdn forums I found the solution, here.
This problem was caused by the  Image Insertion Extension, after disabling the extension the problem was solved.

Problem: vs10 intellisense not showing up for parameters
Solution: deactivate/deinstall the Image Insertion extension

Problem 2:

The second problem I had, was that my cursor wasn’t visible in the editor itself. But from time to time it was visible. As i found out this was caused by the RegEx-Editor extension.  After installing a new version this problem was also gone.

Problem: vs10 cursor is not visible
Solution: update RegEx-Editor extension

 

Hope it helps if you had those problems as well.

Categories: all

Some small status updates

First update since a long time, … and I don’t have much to show for now. Currently I’m in the final phase of the school year, this means a lot of exams to learn for and write. Because of that I currently don’t have a lot of time to spend on coding, but only 2 weeks left until all exams are written, than I can spend more time on coding again.

But there are some things I’m working on.

In the past I’ve shown the progress on my D3D11 Engine. Especially on the 3D Content side. After such an long time without working on an actual game, I decided it would finally be time again to work on a new game. 

This game will be a 2D game, simply because when developing a 2D game I can spend more time on the actual code than having to deal with the creation and conversion of 3D files.
I decided to go with an relative easy to program game, a top-down 2D Shooter, because I want to test some different mythologies with this project.
I will try the Agile-Methodology this time, the complete process, not only some parts of it. I will also use Test-Driven-Development as well. 
Also I will try to develop the complete game based on MVC, Model-View-Controller pattern, to see how well it can be used in games.

Lets see how this project will turn out.

This is not everything I’m planning for, as you all know the Dream-Build-Play contest is also taking place this year. I wanted to enter with a new game but currently I don’t have any great idea for a game I would like to enter with…

SlimDX added D3D11 support in their latest release, this is something I want to check out as well.

Visual Studio 2010 also has great support for new type of Add-Ins which directly are integrated into the code view. I have some ideas for Add-Ins I want to see at some point, so I have to try out it as well…

So much I want to do, but so little time…

Categories: all