Open file on different drive (Windows)

#1

I ran into an interesting problem this evening - I tend to have large video files I’d like to load and don’t really want to keep inside my data folder. I’ve always used ofSetDataPathRoot() to set the path to an folder outside the OF project, and then just loaded the files. Generally that’s worked well, but on windows I would occasionally have problems loading my files. After some testing, I see that OF has difficulty loading files from different drives - it ends up looking for something like this: " …\D:\OF_ImageTest\images\fingers.mov" which doesn’t really work.

What (if any) is the preferred in OF way to load files from another location, including other drives?

A second issue, not directly related, but we should probably add more verbose error messages to ofDirectShowPlayer - file path errors display as codec errors with the message “Cannot load video of this file type. Make sure you have codecs installed on your system. OF recommends the free K-Lite Codec pack.”

#2

you can try using

auto result  = ofSystemLoadDialog();
if(result.bSuccess){
cout << result.getPath() << endl;
}

it will open a file load dialog and then print the path to that file. Maybe there’s a typo in your file route.

#3

Can you deal with this? make an issue in github and propose a fix through a pull request? it would be very helpful if you can.
cheers

#4

After some more extensive testing, I’ve explored the issue, learned a few interesting (curious?) things, and at least found an approach that should work for me.

In the past, I’ve generally specified either the files or folder I wanted to load in an XML file. This is so I, or other users / clients could switch the file locations without needed to recompile the app. I’ve generally loaded the path a string from the XML file and then used ofSetDataPathRoot to point Open Frameworks at that folder. On a mac, I think that worked well, and I don’t remember ever having any issues with that approach.

I learned a few interesting things with this test.

OfImage.load takes a const std::filesystem::path& and works fine in all cases.
ofVideoPlayer.load takes a string and gives inconsistent results.

If I use ofSetDataPathRoot to set the path, images will load fine, but videos will only load if they are on the same drive (and will load with a giant relative path).
If I don’t mess with the Data Path, and instead just provide the full file path (* with all the backslashes doubled)
it will load correctly.

and the results here:

and when I trace out the path it actually tried to load for the videos:
[notice ] video path is: ' ..\..\..\..\..\..\..\..\..\OF_testing\fingers.mov'
[notice ] video path is: ' ..\..\..\..\..\..\..\..\..\..\..\D:\OF_testing\fingers.mov'
[ error ] ofDirectShowPlayer: Cannot load video of this file type. Make sure you have codecs installed on your system. OF recommends the free K-Lite Codec pack.
[notice ] video path is: ' D:\OF_testing\fingers.mov'

So I guess my lesson here is don’t use ofSetDataPathRoot and just store the path as a string and append it to the filename to make a full path whenever I want to load something outside of the data folder. I’m not sure why the load methods of OfImage and ofVideoPlayer take different file types, and I’m re-convinced that file paths in windows are completely stupid and backwards.

@roymacdonald thanks for the system dialog example - it helped me notice I wasn’t escaping my backslashes which causes half (but not all) of my headaches. This is the most fun I’ve had since I tried to run some web apps I had written on a Mac on a Linux server and discovered (after many wasted hours) that case sensitivity matters in Linux. I’ll also log an issue in regards to the vague ofDirectShowPlayer error messages.

#5

Hi,
good to know you sorted it out.

I think that this is just a small bug. It didn’t get changed to std::filesystem::path when the rest did.

There are always this small things that can be really obnoxious when dealing with multiple OSes.

Cheers