Possible to use Defold program to open files?


#1

Is it possible to make a Defold program that can open files? As in, you can right-click on a file, select “Open With… My_defold_program.exe”? Or to associate a file extension with the program so you can just double-click on files to open them with it?

If I try it as-is, the program crashes with these errors:

WARNING:DLIB: Config file parse error in file 'D:\...' at line: 1
FATAL:ENGINE: Unable to load project file: 'D:\...' (-4)

#2

Good question. I have no idea. What’s requirements for a “normal” OSX or Windows app to be able to handle an “Open with” command? Can it be achieved with a native extension or do we need to expose more of the app startup lifecycle? (And what’s the use case for this?)


#3

Heh, yeah, I have no idea either!

It seems like (at least on windows) when you run the game .exe, it first opens the ‘game.projectc’ file and tries to use it. You can open other .projectc files with it and it works fine unless that file contains weird or missing information.

I would use this for making better tools with Defold (not an intended purpose, I know). At the moment I want it for my multi-image-viewer, so you can double-click on its save files to start the program and open the file, rather than having to start the program, press ctrl-O, find the file, and open it. It’s just much more convenient. Actually I think I already figured out a hacky solution—I should be able to make save files that are like game.project files, but with my extra save information included.

It would be cool to have this feature for other projects though (where the above method definitely won’t work). For example, what if, with my polygon editor, you could double-click a ‘.convexshape’ file anywhere on your computer and the editor would start up and load the file. That would be nice!

Obviously, Defold isn’t meant for this sort of thing, so this isn’t a feature request, I’m just wondering if it’s possible.


#4

If you specify arguments to the engine, the game.projectc should be last. So, it might be a good thing for you to wrap it in a script which you can call instead, in order to control the cwd and arguments


#5

I too need this for my app idea, however seeing as to how there is no asset, script or builtin method to do in defold, I might have to look into other game engines


#6

What exactly is it you need to do? Perhaps it can be done via a native extension?


#7

I’ve been thinking of making a simple video player, with some fun and unique features.
How do I make my a defold app know that it has been initialized with a file to open?

In windows when you click on a file and open it with your app, the app takes the path to the file as a command parameter like this:

myapp.exe “D://file/path/myfile.jpg”

On android I have no idea how it happens- but I am assuming its similar.

So when we start it like this:

myDefoldApp.exe “D://file/path/myfile.jpg”

It starts AND opens myfile.jpg


#8

@britzl here is some more information on how to do this on android:
https://developer.android.com/training/app-links/deep-linking.html

For windows we can jusy take the command line parameters of the app, I think


#9

And how is that done? What’s the API? It’s probably possible to handle using a native extension. At least for win, osx and Linux.


#10

@britzl
Appgamekit has had this requested as well, and the community made a plugin that does it. Not sure if it will help, but maybe the code in it might contain some hints:
https://forum.thegamecreators.com/thread/219724
Unfortunately the plugin only handles cmd line arguments for windows

Godot on the other hand, which is both free and open source has a special method inside the OS class:
http://docs.godotengine.org/en/stable/classes/class_os.html?highlight=OS#class-os-get-cmdline-args

Perhaps another worthy example

here you go
https://msdn.microsoft.com/en-us/library/17w5ykft.aspx

and
http://www.cplusplus.com/articles/DEN36Up4/

This might help?

How difficult would it be to also get it to work with android apps?


#11

As I said, for desktop it should in theory be easy, but as the original post says, it seems like the engine already checks for additional command line arguments and if those aren’t correct things go wrong.

(GetCommandLine seems to be what’s needed on Windows. NSProcessInfo for OSX. There’s likely something similar for Linux.)

(Android is trickier though as it uses a completely different system. You’d need to modify your manifest file (not hard) but you also need to have access to the main activity of your app, which currently isn’t possible to do.)

To sum things up: Defold isn’t really made for this sort of thing and I’m not sure if it’s something we should focus on improving. I’ll leave that for @sven, @Mathias_Westerdahl and @Johan_Beck-Noren to decide.


#12

Just to reiterate that currently, our command line dictates that the game.project file should be the last argument if you wish to launch the engine with command line. As @britzl mentioned, there are API’s to get the command line in an app in C++.


#13

I added defos.get_parameters() method that helps to read command line application parameters on win, mac and html5.
(More info here https://github.com/subsoap/defos/pull/75 )
As @Mathias_Westerdahl told, it doesn’t help to open the file, but may be useful in some cases.


#14

@AGulev thank you ! Too bad there is still no way of opening files with madeWithDelod.exe :}


#15

You should be able to register file types in most os’es, and with that you should be able to specify command line parameters for the app (google is your friend here on how to set that up)

For instance, a command line then could be “c:/dir/to/myproject/myapp.exe %1 c:/dir/to/myproject/game.projectc”