mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Safeguard against file corruption
This is what could be a temporary (or permanent) fix to users trying to delete important files on their computer through JS
This commit is contained in:
parent
5d2fb68924
commit
5d19267d00
2 changed files with 20 additions and 0 deletions
|
@ -39,6 +39,11 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
|
||||||
QString tempDir = path;
|
QString tempDir = path;
|
||||||
tempDir.remove(fileName);
|
tempDir.remove(fileName);
|
||||||
qDebug() << "Temporary directory at: " + tempDir;
|
qDebug() << "Temporary directory at: " + tempDir;
|
||||||
|
if (!isTempDir(tempDir)) {
|
||||||
|
qDebug() << "Temporary directory mismatch; risk of losing files";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString file = unzipFile(path, tempDir);
|
QString file = unzipFile(path, tempDir);
|
||||||
if (file != "") {
|
if (file != "") {
|
||||||
qDebug() << "file to upload: " + file;
|
qDebug() << "file to upload: " + file;
|
||||||
|
@ -52,6 +57,20 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
|
||||||
QDir(tempDir).removeRecursively();
|
QDir(tempDir).removeRecursively();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fix to check that we are only referring to a temporary directory
|
||||||
|
bool FileScriptingInterface::isTempDir(QString tempDir) {
|
||||||
|
QString folderName = "/" + tempDir.section("/", -1);
|
||||||
|
QString tempContainer = tempDir;
|
||||||
|
tempContainer.remove(folderName);
|
||||||
|
QTemporaryDir test;
|
||||||
|
QString testDir = test.path();
|
||||||
|
folderName = "/" + testDir.section("/", -1);
|
||||||
|
QString testContainer = testDir;
|
||||||
|
testContainer.remove(folderName);
|
||||||
|
if (testContainer == tempContainer) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileScriptingInterface::isZippedFbx(QUrl url) {
|
bool FileScriptingInterface::isZippedFbx(QUrl url) {
|
||||||
if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true;
|
if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true;
|
||||||
qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";
|
qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model.";
|
||||||
|
|
|
@ -33,6 +33,7 @@ signals:
|
||||||
void unzipSuccess(QString url);
|
void unzipSuccess(QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool isTempDir(QString tempDir);
|
||||||
QString unzipFile(QString path, QString tempDir);
|
QString unzipFile(QString path, QString tempDir);
|
||||||
void recursiveFileScan(QFileInfo file, QString* dirName);
|
void recursiveFileScan(QFileInfo file, QString* dirName);
|
||||||
void downloadZip(QString path, const QString link);
|
void downloadZip(QString path, const QString link);
|
||||||
|
|
Loading…
Reference in a new issue