Skip to content

Commit 1d27082

Browse files
authored
ofPathToString to try / catch errors if wstring has impossible characters (#7799)
#changelog #filesystem
1 parent c502a09 commit 1d27082

File tree

11 files changed

+271
-271
lines changed

11 files changed

+271
-271
lines changed

libs/openFrameworks/app/ofAppGLFWWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ void ofAppGLFWWindow::drop_cb(GLFWwindow * windowP_, int numFiles, const char **
13771377
drag.position = { instance->events().getMouseX(), instance->events().getMouseY() };
13781378
drag.files.resize(numFiles);
13791379
for (int i = 0; i < (int)drag.files.size(); i++) {
1380-
drag.files[i] = of::filesystem::path(dropString[i]).string();
1380+
drag.files[i] = dropString[i];
13811381
}
13821382
instance->events().notifyDragEvent(drag);
13831383
}

libs/openFrameworks/events/ofEvents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ enum ofKey{
107107
//-----------------------------------------------
108108
class ofDragInfo {
109109
public:
110-
std::vector<std::string> files;
110+
std::vector<of::filesystem::path> files;
111111
glm::vec2 position;
112112
};
113113

libs/openFrameworks/gl/ofShader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ ofShader & ofShader::operator=(ofShader && mom) {
198198

199199
//--------------------------------------------------------------
200200
bool ofShader::load(const of::filesystem::path & shaderName) {
201-
return load(shaderName.string() + ".vert", shaderName.string() + ".frag");
201+
auto vertFile = shaderName;
202+
auto fragFile = shaderName;
203+
vertFile += ".vert";
204+
fragFile += ".frag";
205+
// return load(shaderName + ".vert", shaderName + ".frag");
206+
return load(vertFile, fragFile);
202207
}
203208

204209
//--------------------------------------------------------------

libs/openFrameworks/graphics/ofImage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ template<typename PixelType>
199199
static bool loadImage(ofPixels_<PixelType> & pix, const of::filesystem::path & _fileName, const ofImageLoadSettings & settings){
200200
ofInitFreeImage();
201201

202-
auto uriStr = _fileName.string();
202+
auto uriStr = ofPathToString(_fileName);
203203
UriUriA uri;
204204
UriParserStateA state;
205205
state.uri = &uri;
@@ -222,7 +222,7 @@ static bool loadImage(ofPixels_<PixelType> & pix, const of::filesystem::path & _
222222
uriFreeUriMembersA(&uri);
223223

224224
if(scheme == "http" || scheme == "https"){
225-
return ofLoadImage(pix, ofLoadURL(_fileName.string()).data);
225+
return ofLoadImage(pix, ofLoadURL(ofPathToString(_fileName)).data);
226226
}
227227

228228
auto fileName = ofToDataPathFS(_fileName, true);

libs/openFrameworks/graphics/ofTrueTypeFont.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ static string linuxFontPathByName(const string & fontname){
370370
#endif
371371

372372
//-----------------------------------------------------------
373-
// FIXME: it makes no sense to have _fontname and filename if filename will be rewritten inside this function
374-
static bool loadFontFace(const of::filesystem::path& _fontname, FT_Face & face, of::filesystem::path & filename, int index){
373+
// FIXME: it seems first parameter is string because it represents the font name only
374+
static bool loadFontFace(const of::filesystem::path & _fontname, FT_Face & face, of::filesystem::path & filename, int index){
375375
auto fontname = _fontname;
376-
filename = ofToDataPathFS(_fontname,true);
376+
filename = ofToDataPathFS(_fontname, true);
377377
int fontID = index;
378378
if(!of::filesystem::exists(filename)){
379379
#ifdef TARGET_LINUX
@@ -403,7 +403,7 @@ static bool loadFontFace(const of::filesystem::path& _fontname, FT_Face & face,
403403
fontname = "Courier New";
404404
}
405405
// FIXME: fs::path in input and output
406-
filename = winFontPathByName(fontname.string());
406+
filename = winFontPathByName(ofPathToString(fontname));
407407
#endif
408408
if(filename == "" ){
409409
ofLogError("ofTrueTypeFont") << "loadFontFace(): couldn't find font " << fontname;
@@ -412,7 +412,7 @@ static bool loadFontFace(const of::filesystem::path& _fontname, FT_Face & face,
412412
ofLogVerbose("ofTrueTypeFont") << "loadFontFace(): " << fontname << " not a file in data loading system font from " << filename;
413413
}
414414
FT_Error err;
415-
err = FT_New_Face( library, filename.string().c_str(), fontID, &face );
415+
err = FT_New_Face( library, ofPathToString(filename).c_str(), fontID, &face );
416416
if (err) {
417417
// simple error table in lieu of full table (see fterrors.h)
418418
string errorString = "unknown freetype";

libs/openFrameworks/sound/ofMediaFoundationSoundPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ ofMediaFoundationSoundPlayer::~ofMediaFoundationSoundPlayer() {
189189
bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path& fileName, bool stream) {
190190
unload();
191191

192-
std::string fileStr = fileName.string();
192+
std::string fileStr = ofPathToString(fileName);
193193
bool bStream = false;
194194
bStream = bStream || ofIsStringInString(fileStr, "http://");
195195
bStream = bStream || ofIsStringInString(fileStr, "https://");

0 commit comments

Comments
 (0)