Skip to content

Commit 1a3d110

Browse files
committed
Create a unique folder to extract the contents of .mol
Fixes ticket:5786 do not mix the contents of .mol while extracting different versions. Added a boolean parameter to loadEncryptedPackage to skip unziping of .mol
1 parent c83c1ae commit 1a3d110

File tree

7 files changed

+30
-9
lines changed

7 files changed

+30
-9
lines changed

OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ end parseEncryptedPackage;
11691169
function loadEncryptedPackage
11701170
input String fileName;
11711171
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
1172+
input Boolean skipUnzip = false "Skips the unzip of .mol if true. In that case we expect the files are already extracted e.g., because of parseEncryptedPackage() call.";
11721173
output Boolean success;
11731174
external "builtin";
11741175
annotation(Documentation(info="<html>

OMCompiler/Compiler/Script/CevalScript.mo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ algorithm
14681468
case (cache,_,"parseEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::_,_)
14691469
equation
14701470
vals = {};
1471-
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename);
1471+
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename, false);
14721472
if (b) then
14731473
// clear the errors before!
14741474
Error.clearMessages() "Clear messages";
@@ -1479,9 +1479,9 @@ algorithm
14791479
end if;
14801480
then (cache,ValuesUtil.makeArray(vals));
14811481

1482-
case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::_,_)
1482+
case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::Values.BOOL(bval)::_,_)
14831483
equation
1484-
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename);
1484+
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename, bval);
14851485
if (b) then
14861486
execStatReset();
14871487
filename_1 = Testsuite.friendlyPath(filename_1);
@@ -3193,6 +3193,7 @@ end findModelicaPath2;
31933193
protected function unZipEncryptedPackageAndCheckFile
31943194
input String inWorkdir;
31953195
input String filename;
3196+
input Boolean skipUnzip;
31963197
output Boolean success;
31973198
output String outFilename;
31983199
protected
@@ -3203,7 +3204,7 @@ algorithm
32033204
if (System.regularFileExists(filename)) then
32043205
if (Util.endsWith(filename, ".mol")) then
32053206
workdir := if System.directoryExists(inWorkdir) then inWorkdir else System.pwd();
3206-
if (0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
3207+
if (skipUnzip or 0 == System.systemCall("unzip -q -o -d \"" + workdir + "\" \"" + filename + "\"")) then
32073208
s1 := System.basename(filename);
32083209
s2 := Util.removeLast4Char(s1);
32093210
s3 := listGet(Util.stringSplitAtChar(s2," "),1);

OMEdit/OMEditLIB/MainWindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,13 @@ void MainWindow::beforeClosingMainWindow()
630630
}
631631
mFMUDirectoriesList.clear();
632632
}
633+
// Delete the MOL directories
634+
foreach (QString molDirectory, mMOLDirectoriesList) {
635+
if (QDir().exists(molDirectory)) {
636+
Utilities::removeDirectoryRecursivly(molDirectory);
637+
}
638+
}
639+
mMOLDirectoriesList.clear();
633640
delete pSettings;
634641
// delete the OptionsDialog object
635642
OptionsDialog::destroy();

OMEdit/OMEditLIB/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class MainWindow : public QMainWindow
253253
const char* variables);
254254

255255
QList<QString> mFMUDirectoriesList;
256+
QList<QString> mMOLDirectoriesList;
256257
private:
257258
bool mDebug;
258259
bool mTestsuiteRunning;

OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4246,7 +4246,17 @@ void LibraryWidget::openEncrytpedModelicaLibrary(QString fileName, QString encod
42464246
MainWindow::instance()->getStatusBar()->showMessage(QString(Helper::loading).append(": ").append(fileName));
42474247
}
42484248

4249-
QStringList classesList = MainWindow::instance()->getOMCProxy()->parseEncryptedPackage(fileName, Utilities::tempDirectory());
4249+
// create unique directory to extract .mol contents
4250+
QFileInfo fileInfo(fileName);
4251+
QString tempDirectoryPath = Utilities::tempDirectory();
4252+
QString outputDirectory = QString("%1/%2%3").arg(Utilities::tempDirectory(), fileInfo.baseName(), QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
4253+
if (!QDir().exists(outputDirectory)) {
4254+
QDir().mkpath(outputDirectory);
4255+
MainWindow::instance()->mMOLDirectoriesList.append(outputDirectory);
4256+
tempDirectoryPath = outputDirectory;
4257+
}
4258+
4259+
QStringList classesList = MainWindow::instance()->getOMCProxy()->parseEncryptedPackage(fileName, tempDirectoryPath);
42504260
if (!classesList.isEmpty()) {
42514261
if (multipleTopLevelClasses(classesList, fileName)) {
42524262
if (showProgress) {
@@ -4277,7 +4287,8 @@ void LibraryWidget::openEncrytpedModelicaLibrary(QString fileName, QString encod
42774287
pMessageBox->exec();
42784288
} else { // if no conflicting model found then just load the file simply
42794289
// load the encrypted package in OMC
4280-
if (MainWindow::instance()->getOMCProxy()->loadEncryptedPackage(fileName, Utilities::tempDirectory())) {
4290+
// we pass true for skipUnzip as we have alredy extracted mol with parseEncryptedPackage earlier.
4291+
if (MainWindow::instance()->getOMCProxy()->loadEncryptedPackage(fileName, tempDirectoryPath, true)) {
42814292
// create library tree nodes for loaded models
42824293
int progressvalue = 0;
42834294
if (showProgress) {

OMEdit/OMEditLIB/OMC/OMCProxy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,9 +3175,9 @@ QList<QString> OMCProxy::parseEncryptedPackage(QString fileName, QString working
31753175
* \param workingDirectory
31763176
* \return
31773177
*/
3178-
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory)
3178+
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip)
31793179
{
3180-
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory);
3180+
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory, skipUnzip);
31813181
printMessagesStringInternal();
31823182
return result;
31833183
}

OMEdit/OMEditLIB/OMC/OMCProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class OMCProxy : public QObject
265265
QList<QList<QString > > getUses(QString className);
266266
bool buildEncryptedPackage(QString className, bool encrypt = true);
267267
QList<QString> parseEncryptedPackage(QString fileName, QString workingDirectory);
268-
bool loadEncryptedPackage(QString fileName, QString workingDirectory);
268+
bool loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip);
269269
signals:
270270
void commandFinished();
271271
public slots:

0 commit comments

Comments
 (0)