Skip to content

Commit

Permalink
Doesnt load resources if no images are found
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterwmoss committed Nov 3, 2020
1 parent 37af1a5 commit 3740160
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,4 @@ MainWindow::~MainWindow() {
delete channel;
delete m_file;
delete reload;

system(("rm -f " + QRC_FILE).c_str());
}
10 changes: 7 additions & 3 deletions resgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@

using namespace std;

void read_directory(ofstream *outfile, int depth, string path) {
bool read_directory(ofstream *outfile, int depth, string path) {
int status = false;
for (const auto &entry : filesystem::directory_iterator(path)) {
if (entry.is_directory() && depth < 2)
read_directory(outfile, depth + 1, entry.path());
if (entry.path().string().ends_with(".png")) {
status = true;
*outfile << "<file>" << entry.path().string() << "</file>" << endl;
break;
}
}
return status;
}

void res_gen(string path) {
Expand All @@ -26,14 +29,15 @@ void res_gen(string path) {
outfile << "<!DOCTYPE RCC><RCC version='1.0'>" << endl;
outfile << "<qresource>" << endl;

read_directory(&outfile, 0, path);
bool image_exists = read_directory(&outfile, 0, path);

outfile << "</qresource>" << endl;
outfile << "</RCC>" << endl;

outfile.close();

// Clean up
system(("rcc -binary images.qrc -o " + QRC_FILE).c_str());
if (image_exists)
system(("rcc -binary images.qrc -o " + QRC_FILE).c_str());
system("rm -f images.qrc");
}

0 comments on commit 3740160

Please sign in to comment.