simplify directory creating using qt

This commit is contained in:
georgemoralis 2023-02-28 18:44:11 +02:00
parent 2ef7f6fdc3
commit 44e60f779c
1 changed files with 10 additions and 20 deletions

View File

@ -1,6 +1,8 @@
#include "PKG.h" #include "PKG.h"
#include "../../core/FsFile.h" #include "../../core/FsFile.h"
#include <direct.h> #include <direct.h>
#include <QString>
#include <QDir>
PKG::PKG() PKG::PKG()
{ {
@ -73,28 +75,16 @@ bool PKG::extract(const std::string& filepath, const std::string& extractPath, s
std::string name = getEntryNameByType(entry.id); std::string name = getEntryNameByType(entry.id);
if (!name.empty()) if (!name.empty())
{ {
std::size_t pos = name.find("/");//check if we have a directory (assuming we only have 1 level of subdirectories) QString filepath= QString::fromStdString(extractPath+name);
if (pos != std::string::npos) QDir dir = QFileInfo(filepath).dir();
{ if (!dir.exists()) {
//directory found dir.mkpath(dir.path());
std::string dir = name.substr(0, pos+1);//include '/' as well
std::string path = extractPath + dir;
_mkdir(path.c_str());//make dir
std::string file = name.substr(pos + 1);//read filename
FsFile out;
out.Open(path + file, fsWrite);
out.Write(pkg + entry.offset, entry.size);
out.Close();
} }
else
{
FsFile out; FsFile out;
out.Open(extractPath + name, fsWrite); out.Open(extractPath + name, fsWrite);
out.Write(pkg + entry.offset, entry.size); out.Write(pkg + entry.offset, entry.size);
out.Close(); out.Close();
} }
}
else else
{ {
//just print with id //just print with id