summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index d59a886..7b99470 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,12 +10,71 @@
namespace py = boost::python;
namespace fs = boost::filesystem;
+static const std::string UPDATES_DIR = "updates";
+
+/**
+ Given two directories, it merges them by copying new files and
+ directories, and replacing existing files with the ones at the
+ destination
+ */
+void
+mergeDirectories(const fs::path &source,
+ const fs::path &dest)
+{
+ fs::path sourceDir(source);
+ fs::directory_iterator end_iter;
+
+ std::vector<fs::path> files;
+
+ if (fs::exists(sourceDir) && fs::is_directory(sourceDir))
+ {
+ for(fs::directory_iterator dir_iter(sourceDir); dir_iter != end_iter; ++dir_iter)
+ {
+ if (fs::is_regular_file(dir_iter->status()))
+ {
+ auto destFilePath = dest / dir_iter->path().filename();
+ copy_file(dir_iter->path(), destFilePath, fs::copy_option::overwrite_if_exists);
+ }
+ else if (fs::is_directory(dir_iter->status()))
+ {
+ auto currentPath = dir_iter->path();
+ auto pathAtDest = dest / currentPath.filename();
+ if (!fs::exists(pathAtDest))
+ {
+ // This just creates the directory
+ copy_directory(currentPath, pathAtDest);
+ }
+ mergeDirectories(currentPath, pathAtDest);
+ } // Ignore other kind of files for now
+ }
+ }
+}
+
+void
+updateIfNeeded()
+{
+ fs::path updatePath(fs::current_path() / fs::path(UPDATES_DIR));
+ if (fs::exists(updatePath))
+ {
+ std::cout << "Found updates, merging directories before doing anything..."
+ << std::endl;
+ mergeDirectories(updatePath, fs::current_path());
+ fs::remove_all(updatePath);
+ }
+ else
+ {
+ std::cout << "No updates found" << std::endl;
+ }
+}
+
int
main(int argc, char** argv)
{
try {
fs::path full_path(fs::current_path());
+ updateIfNeeded();
+
Py_Initialize();
Py_SetPythonHome(const_cast<char*>(full_path.string().c_str()));