Skip to content

Commit

Permalink
Better TemporaryDirectory handling via RAII
Browse files Browse the repository at this point in the history
  • Loading branch information
christofmuc committed Jun 25, 2020
1 parent 790baba commit cd852f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions FileHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,25 @@ int FileDateComparatorNewestFirst::compareElements(File const &first, File const
if (first.getLastModificationTime() > second.getLastModificationTime()) return -1;
return 0;
}

TemporaryDirectory::TemporaryDirectory()
{
File tempDir = File::getSpecialLocation(File::tempDirectory);
dir_ = tempDir.getNonexistentChildFile("knobkraft", "tmp");
dir_.createDirectory();
}

TemporaryDirectory::~TemporaryDirectory() {
dir_.deleteRecursively(false);
}

juce::File TemporaryDirectory::asFile()
{
return dir_;
}

std::string TemporaryDirectory::name()
{
return dir_.getFullPathName().toStdString();
}

12 changes: 12 additions & 0 deletions FileHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ class FileDateComparatorNewestFirst {
public:
static int compareElements(File const &first, File const &second);
};

class TemporaryDirectory {
public:
TemporaryDirectory();
virtual ~TemporaryDirectory();

File asFile();
std::string name();

private:
File dir_;
};

0 comments on commit cd852f7

Please sign in to comment.