Changeset 29810


Ignore:
Timestamp:
2015-03-26T14:33:03+13:00 (9 years ago)
Author:
ak19
Message:

trying to connect filenames got in perl to filenames in the metadata file. For windows, there are 2 apis to teh filenames. ansi codepage, and unicode. perl only uses the ansi version. If the unicode filename can't be converted to ansi then you get teh garbled M33~1 type filename. We do GetLongPathName to get the real filename which is returned in unicode. so now, if the short name is the same as teh long name, then we assume its in ansi, and decode using locale, otherwise, assume its in unicode and don't need to decode. this seems to work on windows for the files I have. ned to do a bit more testing, then go back to mac and linux and make sure I haven't mucked them up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r29807 r29810  
    168168sub raw_filename_to_unicode
    169169{
    170     my ($directory, $raw_file) = @_;
     170    my ($directory, $raw_file, $filename_encoding ) = @_;
    171171       
    172     my $unicode_filename = &util::get_dirsep_tail(&util::upgrade_if_dos_filename(&FileUtils::filenameConcatenate($directory, $raw_file), 1));
    173     $unicode_filename = &Encode::decode("utf8", $unicode_filename);
    174     #$unicode_filename = &Encode::decode(locale => $unicode_filename);
    175 
     172    my $unicode_filename = $raw_file;
     173    print STDERR "&&&&&&&&&&&&&& raw file = $unicode_filename ".&unicode::debug_unicode_string($unicode_filename)."\n";
     174    if (($ENV{'GSDLOS'} =~ m/^windows$/i) && ($^O ne "cygwin")) {
     175        print STDERR "windows, upgrading...\n";
     176        $unicode_filename = &util::get_dirsep_tail(&util::upgrade_if_dos_filename(&FileUtils::filenameConcatenate($directory, $raw_file), 0));
     177           
     178       
     179            if ($unicode_filename eq $raw_file) {
     180                print STDERR "long = original\n";
     181                $unicode_filename = &Encode::decode(locale_fs => $unicode_filename);
     182                } else {
     183                    print STDERR "long not equal original\n";
     184                    #$unicode_filename = &Encode::decode("UTF-16le" => $unicode_filename);
     185                    }
     186                   
     187    } else {
     188        print STDERR "not windows, not upgrading. decoding in utf8\n";
     189        $unicode_filename = &Encode::decode("utf-8", $unicode_filename);
     190   
     191       
     192        }
     193    #
     194    #$unicode_filename = &Encode::decode("ascii", $unicode_filename);
     195    #$unicode_filename = &Encode::decode(locale_fs => $unicode_filename);
     196    print STDERR "after decoding = $unicode_filename ".&unicode::debug_unicode_string($unicode_filename)."\n";
    176197    #Does the filenaem have url encoded chars in it?
    177198        if (&unicode::is_url_encoded($unicode_filename)) {
     
    745766    my $long_filename = Win32::GetLongPathName($filename_full_path);
    746767    if (defined $long_filename) {
     768       
     769print STDERR "long anme = $long_filename\n";
     770                   
    747771        $filename_full_path = $long_filename;
    748772    }
    749773    # Make sure initial drive letter is lower-case (to fit in with rest of Greenstone)
    750774    $filename_full_path =~ s/^(.):/\u$1:/;
     775   
    751776    if ((defined $and_encode) && ($and_encode)) {
    752777        $filename_full_path = encode("utf8",$filename_full_path);
Note: See TracChangeset for help on using the changeset viewer.