Index: libnautilus-private/nautilus-file.c
===================================================================
--- libnautilus-private/nautilus-file.c	(revision 13624)
+++ libnautilus-private/nautilus-file.c	(working copy)
@@ -3230,6 +3230,198 @@
 	return g_themed_icon_new ("text-x-generic");
 }
 
+static GFile *
+nautilis_find_file_insensitive_next (GFile *parent, const gchar *name)
+{
+	GFileEnumerator *children;
+	GFileInfo *info;
+	gchar *filename = NULL, *case_folded_name, *name_collation_key;
+	GFile *file = NULL;
+	
+	g_return_val_if_fail (g_utf8_validate (name, -1, NULL), NULL);
+	
+	case_folded_name = g_utf8_casefold (name, -1);
+	name_collation_key = g_utf8_collate_key (case_folded_name, -1);
+	g_free (case_folded_name);
+	
+	children = g_file_enumerate_children (parent,
+	                                      G_FILE_ATTRIBUTE_STANDARD_NAME,
+	                                      0, NULL, NULL);
+	while ((info = g_file_enumerator_next_file (children, NULL, NULL)))
+	{
+		const gchar *this_name = g_file_info_get_name (info);
+		if (g_utf8_validate (this_name, -1, NULL))
+		{
+			gchar *case_folded, *key;
+			case_folded = g_utf8_casefold (this_name, -1);
+			key = g_utf8_collate_key (case_folded, -1);
+			g_free (case_folded);
+			
+			if (strcmp (key, name_collation_key) == 0)
+				filename = g_strdup (this_name);
+			g_free (key);
+			if (filename)
+				break;
+		}
+	}
+	g_file_enumerator_close (children, NULL, NULL);
+	g_free (name_collation_key);
+	
+	if (filename)
+	{
+		file = g_file_get_child (parent, filename);
+		g_free (filename);
+	}
+	
+	return file;
+}
+
+/* In UNIX, CD-ROMs can be mounted with case-sensitive filesystems. This breaks
+ * icon lookups for CDs that expect to be viewed only in Win32 or Mac OS. This
+ * function attempts to find files case-insensitively. If the path can be found,
+ * a GFile is returned that maps accurately to it. Otherwise, a file with the
+ * originally-cased path is returned.
+ * 
+ * Call like g_file_get_child.
+**/
+static GFile *
+nautilis_find_file_insensitive (GFile *parent, const gchar *name)
+{
+	gchar **split_path;
+	gchar *component;
+	GFile *file = g_file_dup (parent);
+	gint ii;
+	
+	split_path = g_regex_split_simple (G_DIR_SEPARATOR_S, name, 0, 0);
+	
+	for (ii = 0; (component = split_path[ii]); ii++)
+	{
+		GFile *next;
+		if (!(next = nautilis_find_file_insensitive_next (file,
+		                                                  component)))
+		{
+			/* File does not exist */
+			g_object_unref (file);
+			file = NULL;
+			break;
+		}
+		g_object_unref (file);
+		file = next;
+	}
+	g_strfreev (split_path);
+	
+	if (file) return file;
+	return g_file_get_child (parent, name);
+}
+
+static NautilusIconInfo *
+nautilus_find_cdrom_icon (NautilusFile *file)
+{
+	NautilusIconInfo *icon_info = NULL;
+	
+	if (nautilus_file_can_unmount (file))
+	{
+		GFile *volume_root, *autorun_path = NULL;
+		gchar *root_uri, *autorun_contents, *relative_icon_path = NULL;
+		GdkPixbuf *pixbuf;
+		gsize autorun_contents_length;
+		
+		/* Find the mount point of the volume */
+		root_uri = nautilus_file_get_activation_uri (file);
+		volume_root = g_file_new_for_uri (root_uri);
+		g_free (root_uri);
+		
+		if ((autorun_path = nautilis_find_file_insensitive (volume_root,
+		                                                    "autorun.inf")))
+		{
+			/* Check if the disk contains an autorun.inf. I can't find
+			 * any function like a g_file_exists(), so just try to
+			 * open the file and error out
+			**/
+			if (g_file_load_contents (autorun_path, NULL,
+			                          &autorun_contents,
+			                          &autorun_contents_length,
+			                          NULL, NULL))
+			{
+				/* Scan through for an "icon=" line. Can't use GKeyFile,
+				 * because .inf files aren't always valid key files
+				**/
+				GRegex *icon_regex;
+				GMatchInfo *match_info;
+				
+				/* [^,] is because sometimes the icon= line
+				 * has a comma at the end
+				**/
+				icon_regex = g_regex_new ("icon=([^,\\r\\n]+)",
+				                          G_REGEX_CASELESS, 0, NULL);
+				g_regex_match (icon_regex, autorun_contents, 0,
+				               &match_info);
+				
+				/* Even if there are multiple matches, pick only the
+				 * first.
+				**/
+				if (g_match_info_matches (match_info))
+				{
+					gchar *chr;
+					gchar *word = g_match_info_fetch (match_info, 1);
+					
+					/* Replace '\' with '/' */
+					while ((chr = strchr (word, '\\')) != NULL)
+						*chr = '/';
+					
+					/* If the file name's not valid UTF-8,
+					 * don't even try to load it
+					**/
+					if (g_utf8_validate (word, -1, NULL))
+						relative_icon_path = word;
+					else
+						g_free (word);
+				}
+				
+				g_match_info_free (match_info);
+				
+				g_regex_unref (icon_regex);
+				g_free (autorun_contents);
+			}
+			
+			g_object_unref (autorun_path);
+		}
+		
+		if (relative_icon_path)
+		{
+			GFile *icon_file;
+			gchar *full_icon_path;
+			GError *error = NULL;
+			
+			/* Try to load the icon */
+			icon_file = nautilis_find_file_insensitive (volume_root,
+			                                            relative_icon_path);
+			g_free (relative_icon_path);
+			full_icon_path = g_file_get_path (icon_file);
+			g_object_unref (icon_file);
+			
+			if ((pixbuf = gdk_pixbuf_new_from_file (full_icon_path,
+			                                        &error)))
+			{
+				icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf);
+				g_object_unref (pixbuf);
+			}
+			
+			else
+			{
+				g_print ("Error loading CD-ROM icon pixbuf: %s\n", error->message);
+				g_error_free (error);
+			}
+			
+			g_free (full_icon_path);
+		}
+		
+		g_object_unref (volume_root);
+	}
+	
+	return icon_info;
+}
+
 NautilusIconInfo *
 nautilus_file_get_icon (NautilusFile *file,
 			int size,
@@ -3309,7 +3501,10 @@
 			}
 		}
 	}
-
+	
+	if ((icon = nautilus_find_cdrom_icon (file)))
+		return icon;
+	
 	if (file->details->is_thumbnailing &&
 	    flags & NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS)
 		gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
