summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2018-11-12 02:39:52 +0100
committerPetr Mrázek <peterix@gmail.com>2018-11-12 02:39:52 +0100
commit5603133822880d7c00507e2eed26f0b2f5d1a164 (patch)
treeda1c15c1f78e1628674c7fc719482671f0dbbe6c /api/logic/minecraft
parent47b1f9a8609b2491b08e20a592a4a4bf92bcfdf7 (diff)
downloadMultiMC-5603133822880d7c00507e2eed26f0b2f5d1a164.tar
MultiMC-5603133822880d7c00507e2eed26f0b2f5d1a164.tar.gz
MultiMC-5603133822880d7c00507e2eed26f0b2f5d1a164.tar.lz
MultiMC-5603133822880d7c00507e2eed26f0b2f5d1a164.tar.xz
MultiMC-5603133822880d7c00507e2eed26f0b2f5d1a164.zip
GH-2384 when adding mods with the same filename, rotate the files
Current will be disabled and renamed to '$name-old'. Old one, if present, will be removed.
Diffstat (limited to 'api/logic/minecraft')
-rw-r--r--api/logic/minecraft/SimpleModList.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/api/logic/minecraft/SimpleModList.cpp b/api/logic/minecraft/SimpleModList.cpp
index e8583a35..adab5ba4 100644
--- a/api/logic/minecraft/SimpleModList.cpp
+++ b/api/logic/minecraft/SimpleModList.cpp
@@ -145,11 +145,30 @@ bool SimpleModList::installMod(const QString &filename)
return false;
if (type == Mod::MOD_SINGLEFILE || type == Mod::MOD_ZIPFILE || type == Mod::MOD_LITEMOD)
{
- QString newpath = FS::PathCombine(m_dir.path(), fileinfo.fileName());
+ auto newpath = FS::PathCombine(m_dir.path(), fileinfo.fileName());
+ // if it's already there, rename it and disable it. if there was already an old thing, remove it.
if(QFile::exists(newpath))
- QFile::remove(newpath);
+ {
+ auto olddisabledpath = newpath + "-old.disabled";
+ if(QFile::exists(olddisabledpath))
+ {
+ if(!QFile::remove(olddisabledpath))
+ {
+ // FIXME: report error correctly
+ return false;
+ }
+ }
+ if(!QFile::rename(newpath, olddisabledpath))
+ {
+ // FIXME: report error correctly
+ return false;
+ }
+ }
if (!QFile::copy(fileinfo.filePath(), newpath))
+ {
+ // FIXME: report error correctly
return false;
+ }
FS::updateTimestamp(newpath);
m.repath(newpath);
update();