Disable user template editing if directory not writable

This commit is contained in:
Jack Andersen 2019-05-26 20:38:29 -10:00
parent 28f96e91c2
commit 374d836154
7 changed files with 24 additions and 6 deletions

View File

@ -41,7 +41,7 @@
"url": "https://github.com/jackoalan/LibCommon",
"type": "git",
"head": "dew",
"ref": "7d35c8ce1ee944a3430325ec733b550de48afa12"
"ref": "9b9d4df6477cc9a9e08359e0eea1ceb82f49f1c0"
},
{
"name": "lzo",

View File

@ -13,6 +13,8 @@
using namespace tinyxml2;
TString gDataDir;
bool gResourcesWritable = false;
bool gTemplatesWritable = false;
CResourceStore *gpResourceStore = nullptr;
CResourceStore *gpEditorStore = nullptr;

View File

@ -94,6 +94,8 @@ public:
};
extern TString gDataDir;
extern bool gResourcesWritable;
extern bool gTemplatesWritable;
extern CResourceStore *gpResourceStore;
extern CResourceStore *gpEditorStore;

View File

@ -24,8 +24,16 @@ CPropertyView::CPropertyView(QWidget *pParent)
mpShowNameValidityAction->setChecked(false);
connect(mpShowNameValidityAction, SIGNAL(triggered(bool)), this, SLOT(ToggleShowNameValidity(bool)));
mpEditTemplateAction = new QAction("Edit template", this);
connect(mpEditTemplateAction, SIGNAL(triggered()), this, SLOT(EditPropertyTemplate()));
if (gTemplatesWritable)
{
mpEditTemplateAction = new QAction("Edit template", this);
connect(mpEditTemplateAction, SIGNAL(triggered()), this, SLOT(EditPropertyTemplate()));
}
else
{
mpEditTemplateAction = new QAction("Template files not writable", this);
mpEditTemplateAction->setEnabled(false);
}
mpGenNamesForPropertyAction = new QAction("Generate names for this property", this);
mpGenNamesForSiblingsAction = new QAction(this); // Text set in CreateContextMenu()

View File

@ -989,7 +989,8 @@ void CResourceBrowser::ImportAssetNameMap()
void CResourceBrowser::ExportAssetNames()
{
QString OutFile = UICommon::SaveFileDialog(this, "Export asset name map", "*.xml", *(gDataDir + "resources/gameinfo/"));
QString OutFile = UICommon::SaveFileDialog(this, "Export asset name map", "*.xml",
gResourcesWritable ? *(gDataDir + "resources/gameinfo/") : "");
if (OutFile.isEmpty()) return;
TString OutFileStr = TO_TSTRING(OutFile);

View File

@ -190,7 +190,10 @@ CWorldEditor::CWorldEditor(QWidget *parent)
connect(ui->ActionEditTweaks, SIGNAL(triggered()), mpTweakEditor, SLOT(show()));
connect(ui->ActionEditLayers, SIGNAL(triggered()), this, SLOT(EditLayers()));
connect(ui->ActionGeneratePropertyNames, SIGNAL(triggered()), mpGeneratePropertyNamesDialog, SLOT(show()));
if (gTemplatesWritable)
connect(ui->ActionGeneratePropertyNames, SIGNAL(triggered()), mpGeneratePropertyNamesDialog, SLOT(show()));
else
ui->ActionGeneratePropertyNames->setEnabled(false);
connect(ui->ActionDrawWorld, SIGNAL(triggered()), this, SLOT(ToggleDrawWorld()));
connect(ui->ActionDrawObjects, SIGNAL(triggered()), this, SLOT(ToggleDrawObjects()));

View File

@ -103,8 +103,10 @@ public:
if (!Initialized) UICommon::ErrorMsg(0, "Couldn't open log file. Logging will not work for this session.");
qInstallMessageHandler(QtLogRedirect);
// Locate data directory
// Locate data directory and check write permissions
gDataDir = LocateDataDirectory();
gResourcesWritable = FileUtil::IsDirectoryWritable(gDataDir + "resources");
gTemplatesWritable = FileUtil::IsDirectoryWritable(gDataDir + "templates");
// Create editor resource store
gpEditorStore = new CResourceStore(gDataDir + "resources/");