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 "../../core/FsFile.h"
#include <direct.h>
#include <QString>
#include <QDir>
PKG::PKG()
{
@ -73,27 +75,15 @@ bool PKG::extract(const std::string& filepath, const std::string& extractPath, s
std::string name = getEntryNameByType(entry.id);
if (!name.empty())
{
std::size_t pos = name.find("/");//check if we have a directory (assuming we only have 1 level of subdirectories)
if (pos != std::string::npos)
{
//directory found
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;
out.Open(extractPath + name, fsWrite);
out.Write(pkg + entry.offset, entry.size);
out.Close();
QString filepath= QString::fromStdString(extractPath+name);
QDir dir = QFileInfo(filepath).dir();
if (!dir.exists()) {
dir.mkpath(dir.path());
}
FsFile out;
out.Open(extractPath + name, fsWrite);
out.Write(pkg + entry.offset, entry.size);
out.Close();
}
else
{