#include <mono/utils/mono-uri.h>
#include <mono/metadata/mono-config.h>
#include <mono/utils/mono-digest.h>
+#ifdef PLATFORM_WIN32
+#include <mono/os/util.h>
+#endif
/* the default search path is just MONO_ASSEMBLIES */
static const char*
/* A hastable of thread->assembly list mappings */
static GHashTable *assemblies_loading;
-static gboolean allow_user_gac = FALSE;
-
-#ifdef PLATFORM_WIN32
-
-static void
-init_default_path (void)
-{
- int i;
-
- default_path [0] = g_strdup (MONO_ASSEMBLIES);
- for (i = strlen (MONO_ASSEMBLIES) - 1; i >= 0; i--) {
- if (default_path [0][i] == '/')
- ((char*) default_path [0])[i] = '\\';
- }
-}
-#endif
-
+static char **extra_gac_paths = NULL;
static gchar*
encode_public_tok (const guchar *token, gint32 len)
}
static void
-check_env (void) {
+check_path_env (void) {
const char *path;
char **splitted;
- path = getenv ("MONO_PATH");
+ path = g_getenv ("MONO_PATH");
if (!path)
return;
+
splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
if (assemblies_path)
g_strfreev (assemblies_path);
assemblies_path = splitted;
+ if (g_getenv ("MONO_DEBUG") == NULL)
+ return;
+
+ while (*splitted) {
+ if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
+ g_warning ("'%s' in MONO_PATH doesn't exist or has wrong permissions.", *splitted);
+
+ splitted++;
+ }
+}
+
+static void
+check_extra_gac_path_env (void) {
+ const char *path;
+ char **splitted;
+
+ path = g_getenv ("MONO_GAC_PATH");
+ if (!path)
+ return;
+
+ splitted = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 1000);
+ if (extra_gac_paths)
+ g_strfreev (extra_gac_paths);
+ extra_gac_paths = splitted;
+ if (g_getenv ("MONO_DEBUG") == NULL)
+ return;
+
+ while (*splitted) {
+ if (**splitted && !g_file_test (*splitted, G_FILE_TEST_IS_DIR))
+ g_warning ("'%s' in MONO_GAC_PATH doesn't exist or has wrong permissions.", *splitted);
+
+ splitted++;
+ }
}
static gboolean
default_path [0] = g_strdup (root_dir);
}
+G_CONST_RETURN gchar *
+mono_assembly_getrootdir (void)
+{
+ return default_path [0];
+}
+
/**
* mono_assemblies_init:
*
mono_assemblies_init (void)
{
#ifdef PLATFORM_WIN32
- init_default_path ();
+ mono_set_rootdir ();
#endif
- check_env ();
+ check_path_env ();
+ check_extra_gac_path_env ();
InitializeCriticalSection (&assemblies_mutex);
references [i] = mono_assembly_load (&aname, image->assembly->basedir, status);
}
if (references [i] != NULL){
- if (getenv ("MONO_SILENT_WARNING") == NULL)
+ if (g_getenv ("MONO_SILENT_WARNING") == NULL)
g_printerr ("Compat mode: the request from %s to load %s was remapped (http://www.go-mono.com/remap.html)\n",
image->name, aname.name);
return ass;
}
+static MonoAssembly*
+probe_for_partial_name (const char *basepath, const char *fullname, MonoImageOpenStatus *status)
+{
+ MonoAssembly *res = NULL;
+ gchar *fullpath;
+ GDir *dirhandle;
+ const char* direntry;
+
+ dirhandle = g_dir_open (basepath, 0, NULL);
+ if (!dirhandle)
+ return NULL;
+
+ while ((direntry = g_dir_read_name (dirhandle))) {
+ fullpath = g_build_path (G_DIR_SEPARATOR_S, basepath, direntry, fullname, NULL);
+ res = mono_assembly_open (fullpath, status);
+ g_free (fullpath);
+ if (res)
+ break;
+ }
+ g_dir_close (dirhandle);
+
+ return res;
+}
+
MonoAssembly*
mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *status)
{
MonoAssembly *res;
MonoAssemblyName aname;
- gchar *libpath, *fullpath, *fullname;
- const char* direntry;
- GDir *dirhandle;
+ gchar *fullname, *gacpath;
+ gchar **paths;
memset (&aname, 0, sizeof (MonoAssemblyName));
aname.name = name;
if (res)
return res;
- libpath = g_build_path (G_DIR_SEPARATOR_S, MONO_ASSEMBLIES, "mono", "gac", name, NULL);
+ fullname = g_strdup_printf ("%s.dll", name);
- dirhandle = g_dir_open (libpath, 0, NULL);
- if (!dirhandle)
- return NULL;
+ if (extra_gac_paths) {
+ paths = extra_gac_paths;
+ while (!res && *paths) {
+ gacpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "gac", name, NULL);
+ res = probe_for_partial_name (gacpath, fullname, status);
+ g_free (gacpath);
+ paths++;
+ }
+ }
- fullname = g_strdup_printf ("%s.dll", name);
- while ((direntry = g_dir_read_name (dirhandle))) {
- fullpath = g_build_path (G_DIR_SEPARATOR_S, libpath, direntry, fullname, NULL);
- res = mono_assembly_open (fullpath, status);
- g_free (fullpath);
- if (res)
- break;
+ if (res) {
+ res->in_gac = TRUE;
+ g_free (fullname);
+ return res;
+
}
- g_dir_close (dirhandle);
+
+ gacpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (), "mono", "gac", name, NULL);
+ res = probe_for_partial_name (gacpath, fullname, status);
+ g_free (gacpath);
+
+ if (res)
+ res->in_gac = TRUE;
g_free (fullname);
mono_assembly_load_from_gac (MonoAssemblyName *aname, gchar *filename, MonoImageOpenStatus *status)
{
MonoAssembly *result = NULL;
- gchar *name, *version, *fullpath;
+ gchar *name, *version, *fullpath, *subpath;
gint32 len;
+ gchar **paths;
if (!aname->public_tok_value) {
return NULL;
aname->culture == NULL ? "" : aname->culture,
aname->public_tok_value);
- fullpath = g_build_path (G_DIR_SEPARATOR_S, MONO_ASSEMBLIES, "mono", "gac",
- name, version, filename, NULL);
- result = mono_assembly_open (fullpath, status);
+ subpath = g_build_path (G_DIR_SEPARATOR_S, name, version, filename, NULL);
+ g_free (name);
+ g_free (version);
- g_free (fullpath);
+ if (extra_gac_paths) {
+ paths = extra_gac_paths;
+ while (!result && *paths) {
+ fullpath = g_build_path (G_DIR_SEPARATOR_S, *paths, "gac", subpath, NULL);
+ result = mono_assembly_open (fullpath, status);
+ g_free (fullpath);
+ paths++;
+ }
+ }
- if (!result && allow_user_gac) {
- fullpath = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".mono", "gac",
- name, version, filename, NULL);
- result = mono_assembly_open (fullpath, status);
- g_free (fullpath);
+ if (result) {
+ result->in_gac = TRUE;
+ g_free (subpath);
+ return result;
}
+ fullpath = g_build_path (G_DIR_SEPARATOR_S, mono_assembly_getrootdir (),
+ "mono", "gac", subpath, NULL);
+ result = mono_assembly_open (fullpath, status);
+ g_free (fullpath);
+
if (result)
result->in_gac = TRUE;
- g_free (name);
- g_free (version);
+ g_free (subpath);
return result;
}
return(main_assembly);
}
-void
-mono_assembly_allow_user_gac (gboolean allow)
-{
- allow_user_gac = allow;
-}