Index: /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/BasePlugin.pm	(revision 23352)
@@ -565,5 +565,5 @@
 
     elsif ($filename_encoding eq "auto-filesystem-encoding") 
-    {
+    {	
 	# try locale
 	$filename_encoding = $self->locale_encoding();
@@ -740,5 +740,6 @@
 
 # uses locale
-sub get_filesystem_encoding {
+sub get_filesystem_encoding 
+{
 
     my $self = shift(@_);
@@ -748,4 +749,5 @@
 
     eval {
+	# Works for Windows as well, returning the DOS code page in use	
 	use POSIX qw(locale_h);
 	
@@ -788,4 +790,5 @@
 	
     }
+
     return $filesystem_encoding;
 }
@@ -840,18 +843,31 @@
     
     if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
-		# See if we can determine the file system encoding through locale
-		$deduced_filename_encoding = $self->locale_encoding();
-
-		# if locale shows us filesystem is utf8, check to see filename is consistent
-		# => if not, then we have an "alien" filename on our hands
-
-		if ($deduced_filename_encoding =~ m/^utf-?8$/i) {
-			if (!&unicode::check_is_utf8($file)) {
-				# "alien" filename, so revert
-				$deduced_filename_encoding = undef;
-			}
+
+	# Look to file system to provide a character encoding
+
+	# If Windows NTFS, then -- assuming we work with long file names got through
+	# Win32::GetLongFilePath() -- then the underlying file system is UTF16
+
+	if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
+	    # Can do better than working with the DOS character encoding returned by locale	    
+	    $deduced_filename_encoding = "unicode";
+	}
+	else {
+	    # Unix of some form or other
+
+	    # See if we can determine the file system encoding through locale
+	    $deduced_filename_encoding = $self->locale_encoding();
+	
+	    # if locale shows us filesystem is utf8, check to see filename is consistent
+	    # => if not, then we have an "alien" filename on our hands
+	    
+	    if ($deduced_filename_encoding =~ m/^utf-?8$/i) {
+		if (!&unicode::check_is_utf8($file)) {
+		    # "alien" filename, so revert
+		    $deduced_filename_encoding = undef;
 		}
-    }
-    
+	    }
+	}
+    }
     
 #    if (!defined $deduced_filename_encoding || ($deduced_filename_encoding =~ m/^\s*$/)) {
@@ -884,5 +900,5 @@
 sub set_Source_metadata {
     my $self = shift (@_);  
-    my ($doc_obj, $raw_file, $filename_encoding) = @_;
+    my ($doc_obj, $raw_filename, $filename_encoding) = @_;
 
     # 1. Sets the filename (Source) for display encoded as Unicode if possible,
@@ -890,32 +906,55 @@
     # 2. Sets the url ref (SourceFile) to the URL encoded version
     #    of filename for generated files
+    
+    my ($unused_full_rf, $raw_file) = &util::get_full_filenames("", $raw_filename);
 
     my $top_section = $doc_obj->get_top_section();
-    
+
+    my $octet_file = $raw_file;
+
     # UTF-8 version of filename
-	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
-		print STDERR "****** Setting Source Metadata given: $raw_file\n";
-	}
+    if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+	print STDERR "****** Setting Source Metadata given: $octet_file\n";
+    }
+    
+    # Deal with (on Windows) raw filenames that are in their
+    # abbreviated DOS form
+
+    if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
+	if ((defined $filename_encoding) && ($filename_encoding eq "unicode")) {
+	    if (-e $raw_filename) {
+		require Win32;
+		
+##		print STDERR "**** raw filename before LPN: $raw_filename\n";
+		my $unicode_filename = Win32::GetLongPathName($raw_filename);
+		
+		my $unused_full_uf;
+		($unused_full_uf, $octet_file) = &util::get_full_filenames("", $unicode_filename);
+
+##		print STDERR "**** raw filename after LPN: $raw_filename\n";		
+	    }
+	}
+    }
 
     my $url_encoded_filename;
     if (defined $filename_encoding) {
-		# => Generate a pretty print version of filename that is mapped to Unicode
-		
-		# Use filename_encoding to map raw filename to a Perl unicode-aware string 
-		$url_encoded_filename = decode($filename_encoding,$raw_file);		
+	# => Generate a pretty print version of filename that is mapped to Unicode
+	
+	# Use filename_encoding to map raw filename to a Perl unicode-aware string 
+	$url_encoded_filename = decode($filename_encoding,$octet_file);		
     }
     else {
-		# otherwise generate %xx encoded version of filename for char > 127
-		$url_encoded_filename = &unicode::raw_filename_to_url_encoded($raw_file);
-    }
-	
-	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
-		print STDERR "***** saving Source as:             $url_encoded_filename\n";
-	}
-
+	# otherwise generate %xx encoded version of filename for char > 127
+	$url_encoded_filename = &unicode::raw_filename_to_url_encoded($octet_file);
+    }
+    
+    if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+	print STDERR "***** saving Source as:             $url_encoded_filename\n";
+    }
+    
     
     # Source is the UTF8 display name - not necessarily the name of the file on the system
     $doc_obj->set_utf8_metadata_element($top_section, "Source", $url_encoded_filename); 
-
+    
     my $renamed_raw_file = &util::rename_file($raw_file, $self->{'file_rename_method'});
     # If using URL encoding, then SourceFile is the url-reference to url-encoded
@@ -926,7 +965,7 @@
 					$renamed_raw_url);
 
-	if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
-		print STDERR "***** saving SourceFile as:         $renamed_raw_url\n";
-	}
+    if ((defined $ENV{"DEBUG_UNICODE"}) && ($ENV{"DEBUG_UNICODE"})) {
+	print STDERR "***** saving SourceFile as:         $renamed_raw_url\n";
+    }
 }
    
@@ -988,7 +1027,7 @@
  
 
-	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj,$filename_no_path,$filename_encoding);
+    $self->set_Source_metadata($doc_obj,$filename_full_path,$filename_encoding,$filename_full_path);
 
     # plugin specific stuff - what args do we need here??
Index: /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/CONTENTdmPlugin.pm	(revision 23352)
@@ -661,5 +661,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename_full_path));
Index: /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/ConvertBinaryFile.pm	(revision 23352)
@@ -399,5 +399,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
         
     $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
Index: /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/ConvertToRogPlugin.pm	(revision 23352)
@@ -347,5 +347,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+    $self->set_Source_metadata($doc_obj, $conv_filename, $filename_encoding);
     
     if ($self->{'cover_image'}) {
Index: /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/DatabasePlugin.pm	(revision 23352)
@@ -272,6 +272,6 @@
 
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
-    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $db, $filename_encoding);
+	my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
 
 	if ($self->{'cover_image'}) {
Index: /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/HTMLPlugin.pm	(revision 23352)
@@ -318,6 +318,6 @@
 
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
-    my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+	my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
     }
 
Index: /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 23352)
@@ -152,5 +152,12 @@
 sub generate_images {
     my $self = shift(@_);
-    my ($filename_full_path, $filename_no_path, $doc_obj, $section, $filename_encoding) = @_;
+    my ($filename_full_path, $filename_encoded_full_path, $doc_obj, $section, $filename_encoding) = @_;
+
+    my ($unused_fefp,$filename_encoded_no_path)
+	= util::get_full_filenames("",$filename_encoded_full_path);
+
+    # The following is potentially very muddled thinking (but currently seems to work)
+    # generate_images currently called from ImagePlugin and PagedImagePlugin
+    my $filename_no_path = $filename_encoded_no_path; 
 
     # check image magick status
@@ -219,6 +226,7 @@
 #    $self->set_Source_metadata($doc_obj,$url_to_filename_no_path,undef);
 
-    $self->set_Source_metadata($doc_obj,&unicode::url_decode($filename_no_path),
-							   $filename_encoding);
+    my $raw_filename_full_path = &unicode::url_decode($filename_encoded_full_path);
+    $self->set_Source_metadata($doc_obj,$raw_filename_full_path,
+			       $filename_encoding);
 
 
Index: /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/MARCXMLPlugin.pm	(revision 23352)
@@ -227,5 +227,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename, $filename_encoding);
 
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "SourceSegment", "$self->{'record_count'}");
Index: /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/OAIPlugin.pm	(revision 23352)
@@ -297,7 +297,7 @@
     
     my ($filemeta) = $file =~ /([^\\\/]+)$/;
-	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename, $filename_encoding);
 
     $doc_obj->add_utf8_metadata($top_section, "Language", $language);
Index: /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/OpenDocumentPlugin.pm	(revision 23352)
@@ -268,6 +268,6 @@
     my $filename_encoding = $self->deduce_filename_encoding($file_only,$metadata,$plugin_filename_encoding);
 
-    $self->set_Source_metadata($doc_obj, $file_only, $filename_encoding);
-     $doc_obj->set_utf8_metadata_element("", "FileSize", (-s $filename));
+    $self->set_Source_metadata($doc_obj, $filename, $filename_encoding);
+    $doc_obj->set_utf8_metadata_element("", "FileSize", (-s $filename));
      
     # include any metadata passed in from previous plugins 
Index: /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm	(revision 23352)
@@ -426,6 +426,9 @@
     my $result = 0;
     if ($self->{'image_conversion_available'} == 1) {
-	# do we need to convert $filename_no_path to utf8? We are already reading in from a file, what encoding is it in???
-	$result = $self->generate_images($filename_full_path, $filename_no_path, $doc_obj, $section);
+	# do we need to convert $filename_no_path to utf8/url encoded? 
+	# We are already reading in from a file, what encoding is it in???
+	my $url_encoded_full_filename 
+	    = &unicode::raw_filename_to_url_encoded($filename_full_path);
+	$result = $self->generate_images($filename_full_path, $url_encoded_full_filename, $doc_obj, $section);
     }
     #overwrite one set in ImageConverter
@@ -513,5 +516,5 @@
     $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc", $self->{'file_rename_method'});
     # TODO is file filenmae_no_path??
-    $self->set_initial_doc_fields($self->{'doc_obj'}, $self->{'file'}, $self->{'processor'}, $self->{'metadata'});
+    $self->set_initial_doc_fields($self->{'doc_obj'}, $self->{'filename'}, $self->{'processor'}, $self->{'metadata'});
 
     my ($dir, $file) = $self->{'filename'} =~ /^(.*?)([^\/\\]*)$/;
@@ -540,5 +543,5 @@
 sub set_initial_doc_fields {
     my $self = shift(@_);
-    my ($doc_obj, $filename_no_path, $processor, $metadata) = @_;
+    my ($doc_obj, $filename_full_path, $processor, $metadata) = @_;
 
     my $topsection = $doc_obj->get_top_section();
@@ -552,7 +555,7 @@
     }
 
-	my $plugin_filename_encoding = $self->{'filename_encoding'};
-    my $filename_encoding = $self->deduce_filename_encoding($filename_no_path,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+    my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_encoding = $self->deduce_filename_encoding($filename_full_path,$metadata,$plugin_filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
    
     # if we want a header page, we need to add some text into the top section, otherwise this section will become invisible
@@ -620,5 +623,5 @@
 
     my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
-    $self->set_initial_doc_fields($doc_obj, $filename_no_path, $processor, $metadata);
+    $self->set_initial_doc_fields($doc_obj, $filename_full_path, $processor, $metadata);
     my $topsection = $doc_obj->get_top_section();
     open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path\n";
Index: /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm	(revision 23352)
@@ -346,5 +346,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $filename_no_path,$filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_full_path,$filename_encoding);
         
 	$doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
Index: /main/trunk/greenstone2/perllib/plugins/ReadTextFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ReadTextFile.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/ReadTextFile.pm	(revision 23352)
@@ -141,7 +141,7 @@
     $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename_full_path));
 
-	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
 
     $doc_obj->add_utf8_metadata($top_section, "Language", $language);
Index: /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/ReadXMLFile.pm	(revision 23352)
@@ -369,16 +369,17 @@
     my $self = shift(@_);
 
-	my $metadata = $self->{'metadata'};
+    my $metadata = $self->{'metadata'};
+    my $filename_full_path = $self->{'filename'};
 
     # create a new document
-    my $doc_obj = $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc", $self->{'file_rename_method'});
+    my $doc_obj = $self->{'doc_obj'} = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
 
     $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
 
-	my $filename_no_path = $self->{'filename_no_path'};
-	my $plugin_filename_encoding = $self->{'filename_encoding'};
+    my $filename_no_path = $self->{'filename_no_path'};
+    my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($filename_no_path,$metadata,$plugin_filename_encoding);
 
-    $self->set_Source_metadata($doc_obj, $filename_no_path, $filename_encoding);
+    $self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
     
     # do we want other auto metadata here (see BasePlugin.read_into_doc_obj)
Index: /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm	(revision 23351)
+++ /main/trunk/greenstone2/perllib/plugins/SplitTextFile.pm	(revision 23352)
@@ -243,5 +243,5 @@
 	my $plugin_filename_encoding = $self->{'filename_encoding'};
     my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
-	$self->set_Source_metadata($doc_obj, $filemeta, $filename_encoding);
+	$self->set_Source_metadata($doc_obj, $filename_full_path, $filename_encoding);
 
 	$doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "SourceSegment", "$segment");
