Skip to content

Commit

Permalink
automatically install gtk for windows; code adapted from RGtk2 source…
Browse files Browse the repository at this point in the history
… code
  • Loading branch information
JetteReeg committed Apr 5, 2019
1 parent 8004a62 commit 07437f5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
Binary file modified Model-files/IBCgrassGUI.exe
Binary file not shown.
82 changes: 82 additions & 0 deletions R-files/IBC-grass.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,88 @@ if (!"ggthemes" %in% installed.packages()) install.packages("ggthemes", repos='h
if (!"reshape2" %in% installed.packages()) install.packages("reshape2", repos='http://cran.us.r-project.org', dependencies = T, lib = paste(getwd(), "/Rlibraries", sep=""))
if (!"foreach" %in% installed.packages()) install.packages("foreach", repos='http://cran.us.r-project.org', dependencies = T, lib = paste(getwd(), "/Rlibraries", sep=""))
if (!"doParallel" %in% installed.packages()) install.packages("doParallel", repos='http://cran.us.r-project.org', dependencies = T, lib = paste(getwd(), "/Rlibraries", sep=""))
# install gtk if not already existing...
# checks system
if (.Platform$OS.type == "windows") {
# prüft die dlls
dllpath <- Sys.getenv("RGTK2_GTK2_PATH")
if (!nzchar(dllpath))
dllpath <- file.path(file.path(system.file(package = "RGtk2"), "gtk", .Platform$r_arch), "bin")
#tries to load the necessary dlls
dll <- try(library.dynam("RGtk2", "RGtk2", .libPaths(), DLLpath = dllpath),
silent = getOption("verbose"))
} else dll <- try(library.dynam("RGtk2", "RGtk2", l.libPaths()),
silent = getOption("verbose"))
# if dlls cannot be loaded; download and install them
if (is.character(dll)) {
# required function
.configure_gtk_theme <- function(theme) {
## Only applies to Windows so far
config_path <- file.path(system.file(package = "RGtk2"), "gtk",
.Platform$r_arch, "etc", "gtk-2.0")
dir.create(config_path, recursive = TRUE)
writeLines(sprintf("gtk-theme-name = \"%s\"", theme),
file.path(config_path, "gtkrc"))
}
# install the dependencies
# für windows 32 config..
windows32_config <-
list(
source = FALSE,
gtk_url = "http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.1-20101227_win32.zip",
installer = function(path) {
gtk_path <- file.path(system.file(package = "RGtk2"), "gtk", .Platform$r_arch)
## unzip does this, but we want to see any warnings
dir.create(gtk_path, recursive = TRUE)
unzip(path, exdir = gtk_path)
.configure_gtk_theme("MS-Windows")
}
)

# für windows 64 config
windows64_config <- windows32_config
windows64_config$gtk_url <- "http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip"

# für darwin config
darwin_config <- list(
source = FALSE,
gtk_url = "http://r.research.att.com/libs/GTK_2.24.17-X11.pkg",
installer = function(path) {
system(paste("open", path))
}
)

# für unix config.
unix_config <- NULL

gtk_web <- "http://www.gtk.org"

install_system_dep <- function(dep_name, dep_url, dep_web, installer)
{
path <- file.path(tempdir(), basename(sub("\\?.*", "", dep_url)))
if (download.file(dep_url, path, mode="wb") > 0)
stop("Failed to download ", dep_name)
installer(path)
}

install_all <- function() {
if (.Platform$OS.type == "windows") {
if (.Platform$r_arch == "i386") config <- windows32_config
else config <- windows64_config
} else if (length(grep("darwin", R.version$platform))) {
config <- darwin_config
} else config <- unix_config

if (is.null(config))
stop("This platform is not yet supported by the automatic installer. ",
"Please install GTK+ manually, if necessary. See: ", gtk_web)

install_system_dep("GTK+", config$gtk_url, gtk_web, config$installer)
return()
}

install_all()
}

# load necessary packages
library(RGtk2)
Expand Down
3 changes: 0 additions & 3 deletions Rlibraries/Information.txt

This file was deleted.

0 comments on commit 07437f5

Please sign in to comment.