fix file picker default path crash when it’s not a file extension

This commit is contained in:
pengubow 2025-03-29 23:32:36 +02:00 committed by GitHub
parent 683b603d68
commit c95d09512e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -105,10 +105,14 @@ GEODE_DLL Task<Result<std::filesystem::path>> file::pick(file::PickMode mode, fi
}
NSURL *FileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.file"]];
if (options.defaultPath) {
if (options.defaultPath && !options.defaultPath->parent_path().empty()) {
FileURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:options.defaultPath->c_str()]];
}
else if (options.defaultPath) {
auto FileExtension = [NSString stringWithUTF8String:options.defaultPath->c_str()];
FileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:FileExtension]];
}
// just for the picker not to crash, it gotta have a file to "save" then the writing is handled in the mod once we save the file somewhere
[@"" writeToURL:FileURL atomically:NO encoding:NSUTF8StringEncoding error:nil];