Skip to content

Commit

Permalink
fix: Permissions for config.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
vasylskorych committed Jul 14, 2024
1 parent 0ddec1b commit cfe72ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
16 changes: 8 additions & 8 deletions DyssolInstallers/Scripts/Main.iss
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ Source: "..\Data\Licenses\*.txt" ; DestDir: "{app}\Licenses"

[Dirs]
Name: "{app}\Licenses"; Flags: uninsalwaysuninstall
Name: "{autoappdata}\{#MyAppName}"; Flags: uninsalwaysuninstall
Name: "{autoappdata}\{#MyAppName}\{code:DirCache}"; Flags: uninsalwaysuninstall
Name: "{autoappdata}\{#MyAppName}\{code:DirCacheDebug}"; Flags: uninsalwaysuninstall
Name: "{autoappdata}\{#MyAppName}"; Flags: uninsalwaysuninstall; Permissions: users-modify
Name: "{autoappdata}\{#MyAppName}\{code:DirCache}"; Flags: uninsalwaysuninstall; Permissions: users-modify
Name: "{autoappdata}\{#MyAppName}\{code:DirCacheDebug}"; Flags: uninsalwaysuninstall; Permissions: users-modify

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Expand All @@ -113,11 +113,11 @@ Type: filesandordirs; Name: "{autoappdata}\{#MyAppName}\{code:DirCache}"
Type: filesandordirs; Name: "{autoappdata}\{#MyAppName}\{code:DirCacheDebug}"

[INI]
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "modelsFolders"; String: "{code:VarIniModelsFolders}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "modelsFoldersActivity"; String: "{code:VarIniFoldersActivity}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "materialsDBPath"; String: "{code:MakeRightSlashes|{app}\Materials.dmdb}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "cachePath"; String: "{autoappdata}\{#MyAppName}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "loadLast"; String: "false"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "modelsFolders"; String: "{code:VarIniModelsFolders}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "modelsFoldersActivity"; String: "{code:VarIniFoldersActivity}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "materialsDBPath"; String: "{code:MakeRightSlashes|{app}\Materials.dmdb}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "cachePath"; String: "{code:MakeRightSlashes|{autoappdata}\{#MyAppName}}"; Flags: createkeyifdoesntexist
Filename: "{autoappdata}\{#MyAppName}\{code:FileConfigIni}"; Section: "General"; Key: "loadLast"; String: "false"; Flags: createkeyifdoesntexist

[Code]
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
Expand Down
24 changes: 14 additions & 10 deletions DyssolMainWindow/Dyssol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ Dyssol::Dyssol(QWidget *parent /*= 0*/, Qt::WindowFlags flags /*= {}*/)
m_Simulator.SetFlowsheet(&m_Flowsheet);

// setup config file
QString settingsPath{};
const auto systemSettingsPath = QFileInfo{ QSettings{ QSettings::IniFormat, QSettings::SystemScope, StrConst::Dyssol_ApplicationName, StrConst::Dyssol_ConfigApp }.fileName() }.absolutePath();
const auto userSettingsPath = QFileInfo{ QSettings{ QSettings::IniFormat, QSettings::UserScope , StrConst::Dyssol_ApplicationName, StrConst::Dyssol_ConfigApp }.fileName() }.absolutePath();
if (std::filesystem::exists(systemSettingsPath.toStdString()))
m_sSettingsPath = systemSettingsPath;
if (std::filesystem::exists(systemSettingsPath.toStdString()) && !FileSystem::IsWriteProtected(systemSettingsPath.toStdWString()))
settingsPath = systemSettingsPath;
else
m_sSettingsPath = userSettingsPath;
settingsPath = userSettingsPath;
// create directory for temporary data if it doesn't exist
if (!std::filesystem::exists(m_sSettingsPath.toStdString()))
std::filesystem::create_directories(m_sSettingsPath.toStdString());
if (!std::filesystem::exists(settingsPath.toStdString()))
std::filesystem::create_directories(settingsPath.toStdString());

const QString globalConfigFile = m_sSettingsPath + "/" + StrConst::Dyssol_ConfigFileName;
const QString globalConfigFile = settingsPath + "/" + StrConst::Dyssol_ConfigFileName;
const QString localConfigFile = QString{ "./" } + StrConst::Dyssol_ConfigFileName;

#ifdef _MSC_VER
const QString currConfigFile = QFile::exists(globalConfigFile) || (!QFile::exists(globalConfigFile) && !FileSystem::IsWriteProtected(FileSystem::FilePath(m_sSettingsPath.toStdWString()))) ?
const QString currConfigFile = QFile::exists(globalConfigFile) || (!QFile::exists(globalConfigFile) && !FileSystem::IsWriteProtected(FileSystem::FilePath(settingsPath.toStdWString()))) ?
globalConfigFile : localConfigFile;
#else
const QString currConfigFile = QFile::exists(localConfigFile) ? localConfigFile : globalConfigFile;
Expand Down Expand Up @@ -334,7 +335,10 @@ void Dyssol::SetupCache()
// set the default cache path to config.ini if it has not been set or does not exist
const QVariant cachePathVar = m_pSettings->value(StrConst::Dyssol_ConfigCachePath);
if (!cachePathVar.isValid() || cachePathVar.toString().isEmpty() || !std::filesystem::exists(cachePathVar.toString().toStdString()))
m_pSettings->setValue(StrConst::Dyssol_ConfigCachePath, m_sSettingsPath);
{
const auto path = QFileInfo{ m_pSettings->fileName() }.absoluteDir().path();
m_pSettings->setValue(StrConst::Dyssol_ConfigCachePath, path);
}

// setup cache path
const QString cachePath = m_pSettings->value(StrConst::Dyssol_ConfigCachePath).toString();
Expand All @@ -343,8 +347,8 @@ void Dyssol::SetupCache()
// check whether the cache path is accessible
if (FileSystem::IsWriteProtected(cachePath.toStdWString()))
{
m_pSavingThread->Block();
m_pLoadingThread->Block();
if (m_pSavingThread) m_pSavingThread->Block();
if (m_pLoadingThread) m_pLoadingThread->Block();
QMessageBox::critical(this, StrConst::Dyssol_MainWindowName, "Unable to access the selected cache path because it is write-protected:\n'" + cachePath + "'\nPlease choose another path using Tools -> Settings -> Change path...\nSaving/loading of flowsheets is blocked until that.");
}

Expand Down
1 change: 0 additions & 1 deletion DyssolMainWindow/Dyssol.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class Dyssol : public QMainWindow
CSimulator m_Simulator; // simulator

QSettings* m_pSettings; // Config file.
QString m_sSettingsPath; // Path to store settings and temporary data, where config file and caches are stored.

CMainWindowHelpHelper* m_helpHelper{}; // Fake window to provide main window with functionality to show help files.
CCalculationSequenceEditor* m_pCalcSequenceEditor;
Expand Down

0 comments on commit cfe72ce

Please sign in to comment.