From c6b4e47a504b154b1d726f4ab65502a449ae38ed Mon Sep 17 00:00:00 2001 From: Gabriel Maia Date: Tue, 6 Sep 2016 16:16:18 +0000 Subject: [PATCH] Screenshot: create destination folder if it doesn't exist This ensures the artwork folder is created if it doesn't exist, fixing the remainder of #10928. Signed-off-by: Adrien Destugues --- src/apps/screenshot/ScreenshotWindow.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp index ec70bdf1e3..58a6df371f 100644 --- a/src/apps/screenshot/ScreenshotWindow.cpp +++ b/src/apps/screenshot/ScreenshotWindow.cpp @@ -619,6 +619,22 @@ ScreenshotWindow::_SaveScreenshot() if (path == NULL) return B_ERROR; + BEntry directoryEntry; + directoryEntry.SetTo(path.Path()); + + // create folder if it doesn't exist + // necessary, for example, when the user selects the Artwork folder from + // the list of predefined folders. + if (!directoryEntry.Exists()) { + if (create_directory(path.Path(), 0755) != B_OK) { + return B_ERROR; + } + } else if (!directoryEntry.IsDirectory()) { + // the entry exists but is not a directory. + // not much we can do + return B_ERROR; + } + path.Append(fNameControl->Text()); BEntry entry;