Skip to content

Instantly share code, notes, and snippets.

@02JanDal
Last active January 3, 2016 00:59
Show Gist options
  • Select an option

  • Save 02JanDal/8386715 to your computer and use it in GitHub Desktop.

Select an option

Save 02JanDal/8386715 to your computer and use it in GitHub Desktop.
Proposal for a backup/sync interface for MultiMC 5
/*
* Possible backends:
* Git: https://projects.kde.org/projects/playground/libs/libqgit2/, http://libgit2.github.com/
* Dropbox: https://www.dropbox.com/developers/core/docs (HTTP)
*/
class SyncVersion : public BaseVersion
{
public:
QString identifier;
QDateTime timestamp;
QString descriptor()
{
return identifier;
}
QString name()
{
return timestamp.toString("ddd MMM d yyyy HH:mm:ss");
}
QString typeString()
{
return QString();
}
};
class EntityBase
{
public:
enum Type
{
InstanceFolder,
Save,
Configs
};
EntityBase(const Type type, const QString &path) : type(type), path(path)
{
}
virtual ~EntityBase();
Type type;
/// What's in here depends on the type. If the type is Save it's the name of a save for example.
QString path;
virtual EntityBase *getChild(const QString &id) = 0;
};
class SyncInterface : public QObject
{
Q_OBJECT
public:
SyncInterface(BaseInstance *instance, QObject *parent = 0) : QObject(parent), m_instance(instance), m_settings(0) {}
virtual ~SyncInterface() {}
void setSettings(SettingsObject *settings)
{
m_settings = settings;
}
SettingsObject *getSettings() const
{
return m_settings;
}
virtual QWidget *getConfigWidget() = 0;
void addRootEntity(EntityBase *entity) = 0;
void removeRootEntity(EntityBase *entity) = 0;
QList<EntityBase *> getRootEntities() = 0;
/**
* Used when rolling back files
*/
virtual BaseVersionList *getVersionList(const EntityBase *entity) = 0;
/// git add/commit/push
virtual bool push(const EntityBase *entity) = 0;
/// git checkout <version>
virtual bool setVersion(const EntityBase *entity, const SyncVersion &version) = 0;
/// git fetch (+ pull if we are on the latest version)
virtual bool pull(const EntityBase *entity) = 0;
protected:
BaseInstance *m_instance;
SettingsObject *m_settings;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment