GH-1227 protect world from corruption

This commit is contained in:
Petr Mrázek 2015-09-15 22:51:10 +02:00
parent 8d3f13c447
commit 0a187d0ad3
3 changed files with 120 additions and 71 deletions

View File

@ -156,6 +156,9 @@ void WorldListPage::on_mcEditBtn_clicked()
return; return;
} }
if(!worldSafetyNagQuestion())
return;
auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString(); auto fullPath = m_worlds->data(index, WorldList::FolderRole).toString();
#ifdef Q_OS_OSX #ifdef Q_OS_OSX
@ -230,6 +233,25 @@ void WorldListPage::on_addBtn_clicked()
} }
} }
bool WorldListPage::isWorldSafe(QModelIndex)
{
return !m_inst->isRunning();
}
bool WorldListPage::worldSafetyNagQuestion()
{
if(!isWorldSafe(getSelectedWorld()))
{
auto result = QMessageBox::question(this, tr("Copy World"), tr("Changing a world while Minecraft is running is potentially unsafe.\nDo you wish to proceed?"));
if(result == QMessageBox::No)
{
return false;
}
}
return true;
}
void WorldListPage::on_copyBtn_clicked() void WorldListPage::on_copyBtn_clicked()
{ {
QModelIndex index = getSelectedWorld(); QModelIndex index = getSelectedWorld();
@ -237,6 +259,10 @@ void WorldListPage::on_copyBtn_clicked()
{ {
return; return;
} }
if(!worldSafetyNagQuestion())
return;
auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
auto world = (World *) worldVariant.value<void *>(); auto world = (World *) worldVariant.value<void *>();
bool ok = false; bool ok = false;
@ -255,6 +281,10 @@ void WorldListPage::on_renameBtn_clicked()
{ {
return; return;
} }
if(!worldSafetyNagQuestion())
return;
auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); auto worldVariant = m_worlds->data(index, WorldList::ObjectRole);
auto world = (World *) worldVariant.value<void *>(); auto world = (World *) worldVariant.value<void *>();
@ -266,3 +296,8 @@ void WorldListPage::on_renameBtn_clicked()
world->rename(name); world->rename(name);
} }
} }
void WorldListPage::on_refreshBtn_clicked()
{
m_worlds->update();
}

View File

@ -68,6 +68,8 @@ protected:
private: private:
QModelIndex getSelectedWorld(); QModelIndex getSelectedWorld();
bool isWorldSafe(QModelIndex index);
bool worldSafetyNagQuestion();
private: private:
Ui::WorldListPage *ui; Ui::WorldListPage *ui;
@ -84,6 +86,7 @@ private slots:
void on_addBtn_clicked(); void on_addBtn_clicked();
void on_copyBtn_clicked(); void on_copyBtn_clicked();
void on_renameBtn_clicked(); void on_renameBtn_clicked();
void on_refreshBtn_clicked();
void on_viewFolderBtn_clicked(); void on_viewFolderBtn_clicked();
void worldChanged(const QModelIndex &current, const QModelIndex &previous); void worldChanged(const QModelIndex &current, const QModelIndex &previous);
}; };

View File

@ -36,7 +36,86 @@
<string>Tab 1</string> <string>Tab 1</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0"> <item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addBtn">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="separator" native="true"/>
</item>
<item>
<widget class="QPushButton" name="renameBtn">
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyBtn">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="rmWorldBtn">
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mcEditBtn">
<property name="text">
<string>MCEdit</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="separator_2" native="true"/>
</item>
<item>
<widget class="QPushButton" name="copySeedBtn">
<property name="text">
<string>Copy Seed</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="refreshBtn">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="viewFolderBtn">
<property name="text">
<string>&amp;View Folder</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QTreeView" name="worldTreeView"> <widget class="QTreeView" name="worldTreeView">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -61,75 +140,6 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addBtn">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copyBtn">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="renameBtn">
<property name="text">
<string>Rename</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="rmWorldBtn">
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item>
<widget class="LineSeparator" name="separator" native="true"/>
</item>
<item>
<widget class="QPushButton" name="mcEditBtn">
<property name="text">
<string>MCEdit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="copySeedBtn">
<property name="text">
<string>Copy Seed</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="viewFolderBtn">
<property name="text">
<string>&amp;View Folder</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -148,11 +158,12 @@
<tabstop>tabWidget</tabstop> <tabstop>tabWidget</tabstop>
<tabstop>worldTreeView</tabstop> <tabstop>worldTreeView</tabstop>
<tabstop>addBtn</tabstop> <tabstop>addBtn</tabstop>
<tabstop>copyBtn</tabstop>
<tabstop>renameBtn</tabstop> <tabstop>renameBtn</tabstop>
<tabstop>copyBtn</tabstop>
<tabstop>rmWorldBtn</tabstop> <tabstop>rmWorldBtn</tabstop>
<tabstop>mcEditBtn</tabstop> <tabstop>mcEditBtn</tabstop>
<tabstop>copySeedBtn</tabstop> <tabstop>copySeedBtn</tabstop>
<tabstop>refreshBtn</tabstop>
<tabstop>viewFolderBtn</tabstop> <tabstop>viewFolderBtn</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>