commit 81465ceefb02af22a8041dc0ec4e1eeb086f431d
parent e188b1ad5e22ac70d880ff82f46cfc46ec0c149c
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 1 Apr 2016 18:41:36 -0400
make "install new packages automatically" an optional feature
Diffstat:
9 files changed, 91 insertions(+), 31 deletions(-)
diff --git a/src/config.cpp b/src/config.cpp
@@ -32,6 +32,7 @@ using namespace std;
static const char *GLOBAL_GRP = "reapack";
static const char *VERSION_KEY = "version";
+static const char *AUTOINSTALL_KEY = "autoInstall";
static const char *SIZE_KEY = "size";
@@ -46,7 +47,7 @@ static string ArrayKey(const string &key, const size_t i)
static const int BUFFER_SIZE = 2083;
Config::Config()
- : m_isFirstRun(false), m_version(0), m_remotesIniSize(0)
+ : m_isFirstRun(false), m_version(0), m_autoInstall(false), m_remotesIniSize(0)
{
}
@@ -84,6 +85,8 @@ void Config::read(const Path &path)
migrate();
+ m_autoInstall = getUInt(GLOBAL_GRP, AUTOINSTALL_KEY) > 0;
+
readRemotes();
restoreSelfRemote();
}
@@ -91,6 +94,7 @@ void Config::read(const Path &path)
void Config::write()
{
setUInt(GLOBAL_GRP, VERSION_KEY, m_version);
+ setUInt(GLOBAL_GRP, AUTOINSTALL_KEY, m_autoInstall);
writeRemotes();
}
diff --git a/src/config.hpp b/src/config.hpp
@@ -32,6 +32,8 @@ public:
void write();
bool isFirstRun() const { return m_isFirstRun; }
+ bool autoInstall() const { return m_autoInstall; }
+ void setAutoInstall(const bool enable) { m_autoInstall = enable; }
RemoteList *remotes() { return &m_remotes; }
private:
@@ -48,6 +50,7 @@ private:
std::string m_path;
bool m_isFirstRun;
size_t m_version;
+ bool m_autoInstall;
void readRemotes();
void restoreSelfRemote();
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -29,10 +29,12 @@
using namespace std;
-enum { ACTION_ENABLE = 80, ACTION_DISABLE, ACTION_UNINSTALL, ACTION_ABOUT };
+enum { ACTION_ENABLE = 80, ACTION_DISABLE, ACTION_UNINSTALL, ACTION_ABOUT,
+ ACTION_AUTOINSTALL };
Manager::Manager(ReaPack *reapack)
- : Dialog(IDD_CONFIG_DIALOG), m_reapack(reapack), m_list(0)
+ : Dialog(IDD_CONFIG_DIALOG),
+ m_reapack(reapack), m_config(reapack->config()), m_list(0)
{
}
@@ -71,6 +73,13 @@ void Manager::onCommand(const short id, short)
case ACTION_UNINSTALL:
uninstall();
break;
+ case ACTION_AUTOINSTALL:
+ m_autoInstall = !m_autoInstall.value_or(m_config->autoInstall());
+ enable(m_apply);
+ break;
+ case IDC_OPTIONS:
+ options();
+ break;
case IDOK:
case IDAPPLY:
if(confirm()) {
@@ -150,7 +159,7 @@ void Manager::refresh()
InhibitControl lock(m_list);
m_list->clear();
- for(const Remote &remote : *m_reapack->config()->remotes()) {
+ for(const Remote &remote : *m_config->remotes()) {
if(!m_uninstall.count(remote))
m_list->addRow(makeRow(remote));
}
@@ -220,6 +229,22 @@ void Manager::about(const int index)
m_reapack->about(getRemote(index), handle());
}
+void Manager::options()
+{
+ RECT rect;
+ GetWindowRect(getControl(IDC_OPTIONS), &rect);
+
+ Menu menu;
+
+ const UINT index = menu.addAction(
+ AUTO_STR("&Install new packages automatically"), ACTION_AUTOINSTALL);
+
+ if(m_autoInstall.value_or(m_config->autoInstall()))
+ menu.check(index);
+
+ menu.show(rect.left, rect.bottom - 1, handle());
+}
+
bool Manager::confirm() const
{
if(m_uninstall.empty())
@@ -241,6 +266,9 @@ bool Manager::confirm() const
void Manager::apply()
{
+ if(m_autoInstall)
+ m_config->setAutoInstall(m_autoInstall.value());
+
for(const auto &pair : m_enableOverrides) {
const Remote &remote = pair.first;
const bool enable = pair.second;
@@ -254,7 +282,7 @@ void Manager::apply()
for(const Remote &remote : m_uninstall)
m_reapack->uninstall(remote);
- m_reapack->config()->write();
+ m_config->write();
m_reapack->runTasks();
}
@@ -283,5 +311,5 @@ Remote Manager::getRemote(const int index) const
const ListView::Row &row = m_list->row(index);
const string &remoteName = from_autostring(row[0]);
- return m_reapack->config()->remotes()->get(remoteName);
+ return m_config->remotes()->get(remoteName);
}
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -22,9 +22,11 @@
#include "listview.hpp"
+#include <boost/optional.hpp>
#include <map>
#include <set>
+class Config;
class ReaPack;
class Remote;
@@ -47,6 +49,7 @@ private:
bool isRemoteEnabled(const Remote &) const;
void uninstall();
void about(int index);
+ void options();
bool confirm() const;
void apply();
@@ -54,10 +57,12 @@ private:
HWND m_apply;
ReaPack *m_reapack;
+ Config *m_config;
ListView *m_list;
std::map<Remote, bool> m_enableOverrides;
std::set<Remote> m_uninstall;
+ boost::optional<bool> m_autoInstall;
};
#endif
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -147,7 +147,7 @@ void ReaPack::synchronizeAll()
return;
for(const Remote &remote : remotes)
- t->synchronize(remote);
+ t->synchronize(remote, m_config->autoInstall());
t->runTasks();
}
@@ -182,7 +182,7 @@ void ReaPack::install(const Version *ver)
if(!hitchhikeTransaction())
return;
- m_transaction->install(ver, true);
+ m_transaction->install(ver);
}
void ReaPack::uninstall(const Remote &remote)
@@ -313,8 +313,9 @@ void ReaPack::about(const Remote &remote, HWND parent)
if(ret == About::InstallResult) {
enable(remote);
- if(m_transaction)
- m_transaction->synchronize(remote);
+
+ if(m_transaction) // transaction is created by enable()
+ m_transaction->synchronize(remote, true);
}
}, parent);
}
diff --git a/src/resource.hpp b/src/resource.hpp
@@ -66,5 +66,6 @@
#define IDC_SELECT 229
#define IDC_UNSELECT 230
#define IDC_ACTION 231
+#define IDC_OPTIONS 232
#endif
diff --git a/src/resource.rc b/src/resource.rc
@@ -34,6 +34,7 @@ BEGIN
CONTROL "", IDC_LIST, WC_LISTVIEW, LVS_REPORT | LVS_SHOWSELALWAYS |
WS_BORDER | WS_TABSTOP, 5, 18, 320, 136
PUSHBUTTON "&Import...", IDC_IMPORT, 5, 160, 45, 14
+ PUSHBUTTON "&Options...", IDC_OPTIONS, 53, 160, 45, 14
DEFPUSHBUTTON "&OK", IDOK, 198, 160, 40, 14
PUSHBUTTON "&Cancel", IDCANCEL, 241, 160, 40, 14
PUSHBUTTON "&Apply", IDAPPLY, 284, 160, 40, 14
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -61,11 +61,10 @@ Transaction::~Transaction()
delete m_registry;
}
-void Transaction::synchronize(const Remote &remote, const bool isUserAction)
+void Transaction::synchronize(const Remote &remote, const bool autoInstall)
{
- // show the report dialog even if no task are ran
- if(isUserAction)
- m_receipt.setEnabled(true);
+ // show the report dialog or "nothing to do" even if no task are ran
+ m_receipt.setEnabled(true);
fetchIndex(remote, [=] {
IndexPtr ri;
@@ -87,12 +86,29 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction)
m_registry->savepoint();
for(const Package *pkg : ri->packages())
- install(pkg->lastVersion(), false);
+ synchronize(pkg, autoInstall);
m_registry->restore();
});
}
+void Transaction::synchronize(const Package *pkg, const bool autoInstall)
+{
+ const auto ®Entry = m_registry->getEntry(pkg);
+
+ if(!regEntry.id && !autoInstall)
+ return;
+
+ const Version *ver = pkg->lastVersion();
+
+ if(regEntry.versionCode == ver->code()) {
+ if(allFilesExists(ver->files()))
+ return; // latest version is really installed, nothing to do here!
+ }
+
+ install(ver, regEntry);
+}
+
void Transaction::fetchIndex(const Remote &remote, const IndexCallback &cb)
{
// add the callback to the list, and start the download if it's the first one
@@ -125,23 +141,22 @@ void Transaction::saveIndex(Download *dl, const string &name)
it->second();
}
-void Transaction::install(const Version *ver, const bool force)
+void Transaction::install(const Version *ver)
{
- m_receipt.setEnabled(true);
+ install(ver, m_registry->getEntry(ver->package()));
+}
- const Package *pkg = ver->package();
- const Registry::Entry ®Entry = m_registry->getEntry(pkg);
+void Transaction::install(const Version *ver,
+ const Registry::Entry ®Entry)
+{
+ m_receipt.setEnabled(true);
- InstallTicket::Type type = InstallTicket::Install;
+ InstallTicket::Type type;
- if(regEntry.id) {
- if(regEntry.versionCode == ver->code()) {
- if(!force && allFilesExists(ver->files()))
- return; // latest version is really installed, nothing to do here!
- }
- else if(regEntry.versionCode < ver->code())
- type = InstallTicket::Upgrade;
- }
+ if(regEntry.id && regEntry.versionCode < ver->code())
+ type = InstallTicket::Upgrade;
+ else
+ type = InstallTicket::Install;
// prevent file conflicts (don't worry, the registry push is reverted later)
try {
@@ -165,7 +180,7 @@ void Transaction::install(const Version *ver, const bool force)
}
// all green! (pronounce with a japanese accent)
- IndexPtr ri = pkg->category()->index()->shared_from_this();
+ IndexPtr ri = ver->package()->category()->index()->shared_from_this();
if(!m_indexes.count(ri))
m_indexes.insert(ri);
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -56,8 +56,8 @@ public:
void onFinish(const VoidSignal::slot_type &slot) { m_onFinish.connect(slot); }
void setCleanupHandler(const CleanupHandler &cb) { m_cleanupHandler = cb; }
- void synchronize(const Remote &, bool userAction = true);
- void install(const Version *, bool force = false);
+ void synchronize(const Remote &, bool autoInstall);
+ void install(const Version *);
void uninstall(const Remote &);
void uninstall(const Registry::Entry &);
void registerAll(const Remote &);
@@ -78,6 +78,8 @@ private:
void fetchIndex(const Remote &, const IndexCallback &cb);
void saveIndex(Download *, const std::string &remoteName);
+ void synchronize(const Package *, bool autoInstall);
+ void install(const Version *, const Registry::Entry &);
void installTicket(const InstallTicket &);
void addTask(Task *);