diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-12-10 07:22:22 +0100 |
commit | aa61bbe9e414648399aff2802df5b587dee1a084 (patch) | |
tree | ff7809bea445bb76c9fd27a3245e1b2cb7c72596 /mmc_updater/src/UpdateDialogGtkFactory.cpp | |
parent | 3f5c46a1c4b27e82976e0067e4ec2d6abfffd9ba (diff) | |
parent | 712b87c643bbd7bc4ed2cfd459d0b9fdb69e5f0d (diff) | |
download | MultiMC-aa61bbe9e414648399aff2802df5b587dee1a084.tar MultiMC-aa61bbe9e414648399aff2802df5b587dee1a084.tar.gz MultiMC-aa61bbe9e414648399aff2802df5b587dee1a084.tar.lz MultiMC-aa61bbe9e414648399aff2802df5b587dee1a084.tar.xz MultiMC-aa61bbe9e414648399aff2802df5b587dee1a084.zip |
Merge branch 'develop' of github.com:MultiMC/MultiMC5 into develop
Conflicts:
CMakeLists.txt
gui/MainWindow.cpp
Diffstat (limited to 'mmc_updater/src/UpdateDialogGtkFactory.cpp')
-rw-r--r-- | mmc_updater/src/UpdateDialogGtkFactory.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/mmc_updater/src/UpdateDialogGtkFactory.cpp b/mmc_updater/src/UpdateDialogGtkFactory.cpp new file mode 100644 index 00000000..313da31a --- /dev/null +++ b/mmc_updater/src/UpdateDialogGtkFactory.cpp @@ -0,0 +1,59 @@ +#include "UpdateDialogGtkFactory.h" + +#include "Log.h" +#include "UpdateDialog.h" +#include "StringUtils.h" + +#include <dlfcn.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> + +class UpdateDialogGtk; + +// GTK updater UI library embedded into +// the updater binary +extern unsigned char libupdatergtk_so[]; +extern unsigned int libupdatergtk_so_len; + +// pointers to helper functions in the GTK updater UI library +UpdateDialogGtk* (*update_dialog_gtk_new)() = 0; + +bool extractFileFromBinary(const char* path, const void* buffer, size_t length) +{ + int fd = open(path,O_CREAT | O_WRONLY | O_TRUNC,0755); + size_t count = write(fd,buffer,length); + if (fd < 0 || count < length) + { + if (fd >= 0) + { + close(fd); + } + return false; + } + close(fd); + return true; +} + +UpdateDialog* UpdateDialogGtkFactory::createDialog() +{ + const char* libPath = "/tmp/libupdatergtk.so"; + + if (!extractFileFromBinary(libPath,libupdatergtk_so,libupdatergtk_so_len)) + { + LOG(Warn,"Failed to load the GTK UI library - " + std::string(strerror(errno))); + return 0; + } + + void* gtkLib = dlopen(libPath,RTLD_LAZY); + if (!gtkLib) + { + LOG(Warn,"Failed to load the GTK UI - " + std::string(dlerror())); + return 0; + } + update_dialog_gtk_new = (UpdateDialogGtk* (*)()) dlsym(gtkLib,"update_dialog_gtk_new"); + return reinterpret_cast<UpdateDialog*>(update_dialog_gtk_new()); +} + |