From 5a8f8e8d70081c29e0d8d1fd57e92eaaf826eb42 Mon Sep 17 00:00:00 2001 From: coppro Date: Mon, 28 Sep 2009 23:02:54 +0000 Subject: [PATCH] Following a fine MSE tradition of forgetting to svn add new files. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1428 0fc631ac-6414-0410-93d0-97cfa31319b6 --- MakeAM.sh | 2 +- Makefile.am | 2 +- Makefile.in | 2 +- src/util/vcs.cpp | 44 +++++++++++++++++++ src/util/vcs.hpp | 49 +++++++++++++++++++++ src/util/vcs/subversion.cpp | 88 +++++++++++++++++++++++++++++++++++++ src/util/vcs/subversion.hpp | 28 ++++++++++++ 7 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 src/util/vcs.cpp create mode 100644 src/util/vcs.hpp create mode 100644 src/util/vcs/subversion.cpp create mode 100644 src/util/vcs/subversion.hpp diff --git a/MakeAM.sh b/MakeAM.sh index 6c9d75e1..733a208f 100755 --- a/MakeAM.sh +++ b/MakeAM.sh @@ -18,7 +18,7 @@ AM_LDFLAGS = @WX_LIBS@ $(BOOST_LDFLAGS) .hpp.gch: target=`echo $@ | sed "s|.gch$$|.hpp|"`;\ depbase=`echo $$target | sed "s|[^/]*\$$|$(DEPDIR)/&|;s|\\.hpp\$$||"`;\ - $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -c $$target &&\ + $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -x c++-header -c $$target &&\ $(am__mv) $$depbase.Tpch $$depbase.Pch touch $@ .gch.o: diff --git a/Makefile.am b/Makefile.am index a7948b80..efdb7147 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ AM_LDFLAGS = @WX_LIBS@ $(BOOST_LDFLAGS) .hpp.gch: target=`echo $@ | sed "s|.gch$$|.hpp|"`;\ depbase=`echo $$target | sed "s|[^/]*\$$|$(DEPDIR)/&|;s|\\.hpp\$$||"`;\ - $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -c $$target &&\ + $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -x c++-header -c $$target &&\ $(am__mv) $$depbase.Tpch $$depbase.Pch touch $@ .gch.o: diff --git a/Makefile.in b/Makefile.in index c1d0fdaa..0c41ac3f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4318,7 +4318,7 @@ uninstall-am: uninstall-binPROGRAMS .hpp.gch: target=`echo $@ | sed "s|.gch$$|.hpp|"`;\ depbase=`echo $$target | sed "s|[^/]*\$$|$(DEPDIR)/&|;s|\\.hpp\$$||"`;\ - $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -c $$target &&\ + $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpch -x c++-header -c $$target &&\ $(am__mv) $$depbase.Tpch $$depbase.Pch touch $@ .gch.o: diff --git a/src/util/vcs.cpp b/src/util/vcs.cpp new file mode 100644 index 00000000..30b0623d --- /dev/null +++ b/src/util/vcs.cpp @@ -0,0 +1,44 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2009 Twan van Laarhoven and Sean Hunt | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include +#include + +// ----------------------------------------------------------------------------- : Reflection + +template <> +VCSP read_new(Reader& reader) { + // there must be a type specified + String type; + reader.handle(_("type"), type); + if (type == _("none")) return new_intrusive(); + else if (type == _("subversion")) return new_intrusive(); + else if (type.empty()) { + reader.warning(_ERROR_1_("expected key", _("version control system"))); + throw ParseError(_ERROR_("aborting parsing")); + } else { + reader.warning(_ERROR_1_("unsupported version control type", type)); + throw ParseError(_ERROR_("aborting parsing")); + } +} + +IMPLEMENT_REFLECTION(VCS) { + REFLECT_IF_NOT_READING { + String type = _("none"); + REFLECT(type); + } +} + +template <> +void Reader::handle(VCSP& pointer) { + pointer = read_new(*this); + handle(*pointer); +} + +// ----------------------------------------------------------------------------- : EOF diff --git a/src/util/vcs.hpp b/src/util/vcs.hpp new file mode 100644 index 00000000..53280be8 --- /dev/null +++ b/src/util/vcs.hpp @@ -0,0 +1,49 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2009 Twan van Laarhoven and Sean Hunt | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_UTIL_IO_VCS +#define HEADER_UTIL_IO_VCS + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +class VCS; + +DECLARE_POINTER_TYPE(VCS); + +template <> +void Reader::handle(VCSP& pointer); + +// ----------------------------------------------------------------------------- : VCS + +/// Interface to a version control system +/** This allows MSE to interact with various revision control systems directly + * rather than relying on the user to do so. Each method causes the external + * version control system to perform an operation on the specified file name. + * The default implementation just calls the normal file-handling functions. + */ +class VCS : public IntrusivePtrVirtualBase +{ + public: + /// Add a file - it's assumed to already have been created + virtual void addFile (const wxFileName& filename) { + } + /// Rename a file (currently unused) + virtual void moveFile (const wxFileName& source, const wxFileName& destination) { + wxRenameFile(source.GetFullName(), destination.GetFullName()); + } + /// Delete a file right off the disk + virtual void removeFile (const wxFileName& filename) { + wxRemoveFile(filename.GetFullName()); + } + + DECLARE_REFLECTION_VIRTUAL(); +}; + +// ----------------------------------------------------------------------------- : EOF +#endif diff --git a/src/util/vcs/subversion.cpp b/src/util/vcs/subversion.cpp new file mode 100644 index 00000000..3ce2153b --- /dev/null +++ b/src/util/vcs/subversion.cpp @@ -0,0 +1,88 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2009 Twan van Laarhoven and Sean Hunt | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +// ----------------------------------------------------------------------------- : SVN File Manipulation + +void SubversionVCS::addFile(const wxFileName& filename) +{ + String name = filename.GetFullPath(); + const Char* name_c[] = {_("svn"), _("add"), name.c_str(), nullptr}; + switch (wxExecute(const_cast(name_c), wxEXEC_SYNC)) // Yuck, const_cast + { + // Success + case 0: + return; + // Couldn't run SVN + case -1: + handle_error(String(_("Can't run SVN."))); + VCS::addFile(filename); + return; + // SVN error + default: + handle_error(String(_("SVN encountered an error"))); + VCS::addFile(filename); + return; + } +} + +void SubversionVCS::moveFile(const wxFileName& source, const wxFileName& dest) +{ + String source_name = source.GetFullPath(), dest_name = dest.GetFullPath(); + const Char* name_c[] = {_("svn"), _("mv"), source_name.c_str(), dest_name.c_str(), nullptr}; + switch (wxExecute(const_cast(name_c), wxEXEC_SYNC)) // Once again, yuck + { + // Success + case 0: + return; + // Couldn't run SVN + case -1: + handle_error(String(_("Can't run SVN."))); + VCS::moveFile(source, dest); + return; + // SVN error + default: + handle_error(String(_("SVN encountered an error"))); + VCS::moveFile(source, dest); + return; + } +} + +void SubversionVCS::removeFile(const wxFileName& filename) +{ + String name = filename.GetFullPath(); + const Char* name_c[] = {_("svn"), _("rm"), name.c_str(), nullptr}; + handle_warning(String(name_c[0]) + name_c[1] + name_c[2]); + VCS::removeFile(filename); + switch (wxExecute(const_cast(name_c), wxEXEC_SYNC)) // Once again, yuck + { + // Success + case 0: + return; + // Couldn't run SVN + case -1: + handle_error(String(_("Can't run SVN."))); + VCS::removeFile(filename); + return; + // SVN error + default: + handle_error(String(_("SVN encountered an error"))); + VCS::removeFile(filename); + return; + } +} + +IMPLEMENT_REFLECTION(SubversionVCS) { + REFLECT_IF_NOT_READING { + String type = _("subversion"); + REFLECT(type); + } +} +// ----------------------------------------------------------------------------- : EOF diff --git a/src/util/vcs/subversion.hpp b/src/util/vcs/subversion.hpp new file mode 100644 index 00000000..65159e12 --- /dev/null +++ b/src/util/vcs/subversion.hpp @@ -0,0 +1,28 @@ +//+----------------------------------------------------------------------------+ +//| Description: Magic Set Editor - Program to make Magic (tm) cards | +//| Copyright: (C) 2001 - 2009 Twan van Laarhoven and Sean Hunt | +//| License: GNU General Public License 2 or later (see file COPYING) | +//+----------------------------------------------------------------------------+ + +#ifndef HEADER_UTIL_IO_SUBVERSION +#define HEADER_UTIL_IO_SUBVERSION + +// ----------------------------------------------------------------------------- : Includes + +#include +#include + +// ----------------------------------------------------------------------------- : SubversionVCS + +class SubversionVCS : public VCS +{ + public: + virtual void addFile (const wxFileName& filename); + virtual void moveFile (const wxFileName& source, const wxFileName& destination); + virtual void removeFile (const wxFileName& filename); + + DECLARE_REFLECTION(); +}; + +// ----------------------------------------------------------------------------- : EOF +#endif