commit 634b64049a1db996cb5c4fee5595ab85c860bd99
parent 5567540e24f545807e174126d40ab0b8d0fd7983
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 3 Jan 2016 15:41:08 -0500
protect ReaPack's own remote against tempering
Diffstat:
7 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/src/config.cpp b/src/config.cpp
@@ -54,8 +54,6 @@ Config::Config()
void Config::fillDefaults()
{
- m_remotes.add({"ReaPack",
- "https://github.com/cfillion/reapack/raw/master/index.xml"});
}
void Config::read(const Path &path)
@@ -70,6 +68,8 @@ void Config::read(const Path &path)
readRemotes();
readRegistry();
+
+ restoreSelfRemote();
}
void Config::write()
@@ -78,6 +78,19 @@ void Config::write()
writeRegistry();
}
+void Config::restoreSelfRemote()
+{
+ const char *name = "ReaPack";
+ const char *url = "https://github.com/cfillion/reapack/raw/master/index.xml";
+
+ Remote remote = m_remotes.get(name);
+ remote.setName(name);
+ remote.setUrl(url);
+ remote.protect();
+
+ m_remotes.add(remote);
+}
+
void Config::readRemotes()
{
m_remotesIniSize = getUInt(REMOTES_GRP, SIZE_KEY);
diff --git a/src/config.hpp b/src/config.hpp
@@ -49,6 +49,7 @@ private:
std::string m_path;
void readRemotes();
+ void restoreSelfRemote();
void writeRemotes();
RemoteList m_remotes;
size_t m_remotesIniSize;
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -107,7 +107,7 @@ void Manager::onContextMenu(HWND target, const int x, const int y)
else
menu.enable(enableAction);
- if(!remote.isFrozen())
+ if(!remote.isProtected())
menu.enable(uninstallAction);
}
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -131,7 +131,13 @@ void ReaPack::importRemote()
const Remote existing = remotes->get(remote.name());
if(!existing.isNull()) {
- if(existing.url() == remote.url()) {
+ if(existing.isProtected()) {
+ ShowMessageBox(
+ "This remote is protected and cannot be overwritten.", title, MB_OK);
+
+ return;
+ }
+ else if(existing.url() == remote.url()) {
ShowMessageBox(
"This remote is already configured.\r\n"
"Nothing to do!"
diff --git a/src/remote.cpp b/src/remote.cpp
@@ -68,12 +68,12 @@ auto Remote::fromFile(const string &path, Remote *remote) -> ReadCode
}
Remote::Remote()
- : m_enabled(true), m_frozen(false)
+ : m_enabled(true), m_protected(false)
{
}
Remote::Remote(const string &name, const string &url, const bool enabled)
- : m_enabled(enabled), m_frozen(false)
+ : m_enabled(enabled), m_protected(false)
{
setName(name);
setUrl(url);
diff --git a/src/remote.hpp b/src/remote.hpp
@@ -52,14 +52,14 @@ public:
void setEnabled(const bool enabled) { m_enabled = enabled; }
bool isEnabled() const { return m_enabled; }
- void freeze() { m_frozen = true; }
- bool isFrozen() const { return m_frozen; }
+ void protect() { m_protected = true; }
+ bool isProtected() const { return m_protected; }
private:
std::string m_name;
std::string m_url;
bool m_enabled;
- bool m_frozen;
+ bool m_protected;
};
class RemoteList {
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -15,7 +15,7 @@ TEST_CASE("construct remote", M) {
REQUIRE(remote.name() == "name");
REQUIRE(remote.url() == "url");
REQUIRE(remote.isEnabled());
- REQUIRE_FALSE(remote.isFrozen());
+ REQUIRE_FALSE(remote.isProtected());
}
TEST_CASE("construct invalid remote", M) {
@@ -97,12 +97,12 @@ TEST_CASE("null remote", M) {
}
}
-TEST_CASE("freeze remote", M) {
+TEST_CASE("protect remote", M) {
Remote remote;
- REQUIRE_FALSE(remote.isFrozen());
+ REQUIRE_FALSE(remote.isProtected());
- remote.freeze();
- REQUIRE(remote.isFrozen());
+ remote.protect();
+ REQUIRE(remote.isProtected());
}
TEST_CASE("add remotes to list", M) {