Opening the custom extension files with JUCE app

Hello everyone,

My program saves its state in an xml file but with custom extension of .etf.
In initialise method of my Main window, JUCEApplication I can parse an .etf file through the cmd.

void initialise (const String& commandLine) override
    {
        // This method is where you should put your application's initialisation code..
        mainWindow.reset (new MainWindow (getApplicationName(),commandLine));
    }

The MainWindow checks that parsed string, and if it is a correct one, it opens it as a File and then tries to get and XmlDocument from it. And it works, it works if I drag an .etf file over my .exe, and it works if I call it from cmd where I first call my .exe file and then the .etf file. But the problem is next, I have configured Windows that .etf files should be directly opened with my .exe file, so that I can just double click on .etf file and make it run .exe, and this wont work. It will actually start the program, it parses the .etf absolute path to my program but when I try to make a XmlDocument I get an error: “not enough input”. What could be the possible reason for this? It is my first time that I do something related to custom extensions and cmd line input.
Any help is more than welcome!
Thanks,
Cila

Have you checked to see what the the commandLine string is when you try to double click and open?

Yes, it is the absolute path of the file which was double clicked

I’m not really sure but stepping meticulously through the debugger is the only way to know what’s going on. I can confirm this does work, as my current Windows software can be opened in this fashion.

I have fixed it, double clicking on the file actually passes the absolute path wrapped in quotations “”, so after I removed them from the start and the end of the commandLine string,it works perfectly. Thanks :slight_smile:

For that, I suggest you to use the String::unquote() method which “does the right thing” (removes them if they are actually there, but does nothing if they are missing) without having to reinvent the wheel yourself

2 Likes

String::unquote(). Brilliant. The amount of times I’ve written stupid code to do this :man_facepalming:

2 Likes