Subject: | Add codepage support |
Under WinXP, the Regional Settings control panel has two major options: the locale (on the Regional Options tab) and the default language (on the Advance tab). The Win32::Locale module reports the value of the former setting. The attached patch is a prototype to report the value of the latter setting. Put simply, this is the value in
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language.Default
Additionally, Windows records the language that was selected when Windows was installed in
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language.InstallLanguage
These values signify the default encoding used for all non-Unicode Windows applications, including filesystem interaction.
I'd love to see Win32::Codepage become part of the Win32::Locale package, but if that doesn't seem proper, I suppose I could probably package it for CPAN myself as a separate package.
package Win32::Codepage;
use warnings;
use strict;
use Win32::Locale;
our $VERSION = '1.00';
sub _get_lang_reg_key
{
my $langkey;
local $SIG{"__DIE__"} = "";
eval '
use Win32::TieRegistry ();
$langkey = Win32::TieRegistry->new(
"HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Nls/Language",
{ Delimiter => "/" }
);
';
return $langkey;
}
sub get_ms_install_codepage
{
my $key = _get_lang_reg_key() || return;
my $codepage = $key->GetValue("InstallLanguage");
return unless $codepage =~ m/^[0-9a-fA-F]+$/s;
return hex($codepage);
}
sub get_ms_codepage
{
my $key = _get_lang_reg_key() || return;
my $codepage = $key->GetValue("Default");
return unless $codepage =~ m/^[0-9a-fA-F]+$/s;
return hex($codepage);
}
sub get_install_codepage
{
my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_install_codepage() || '' };
return unless $lang;
return $lang;
}
sub get_codepage
{
my $lang = $Win32::Locale::MSLocale2LangTag{ $_[0] || get_ms_codepage() || '' };
return unless $lang;
return $lang;
}
1;