diff options
author | Norbert Preining <preining@logic.at> | 2009-07-05 01:06:47 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2009-07-05 01:06:47 +0000 |
commit | 79364908545806a2e80af2e511bb9982df9c7306 (patch) | |
tree | c985ebb3baff1e43b52c290726ed7e5d6b9674ac /Master/tlpkg/TeXLive/TLWinGoo.pm | |
parent | 657ba4f783aa9b76181bda011b4eef594e7193fa (diff) |
postaction fileassocs: we work now in three modes depending on the setting
of option("fileassocs"):
- == 0 : do not fiddle with fileassocs (but still add/remove filetype!)
- == 1 : do only add/remove if it is the one we created
- == 2 : always recreate the the fileassocs
TLConfig.pm: chnage the type of the fileassoc parameter to n:0..2
git-svn-id: svn://tug.org/texlive/trunk@14103 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TLWinGoo.pm')
-rw-r--r-- | Master/tlpkg/TeXLive/TLWinGoo.pm | 116 |
1 files changed, 98 insertions, 18 deletions
diff --git a/Master/tlpkg/TeXLive/TLWinGoo.pm b/Master/tlpkg/TeXLive/TLWinGoo.pm index 580df89c8e9..1bb81135496 100644 --- a/Master/tlpkg/TeXLive/TLWinGoo.pm +++ b/Master/tlpkg/TeXLive/TLWinGoo.pm @@ -539,17 +539,25 @@ sub reg_delete_recurse { =pod -=item C<register_extension($extension, $file_type)> +=item C<register_extension($mode, $extension, $file_type)> Add registry entry to associate $extension with $file_type. Slashes are flipped where necessary. +If $mode is 0, nothing is actually done. If $mode is 1, only not-present +keys of keys that are matching the given key are (re)created. If $mode +is 2 then keys are (re)created in any case. + =cut sub register_extension { + my $mode = shift; + return if ($mode == 0); + my $extension = shift; $extension = '.'.$extension unless $extension =~ /^\./; # ensure leading dot $extension = uc($extension); + my $file_type = shift; debug("Linking $extension to $file_type\n"); my ($classes_key, $k); @@ -558,50 +566,115 @@ sub register_extension { if ($is_admin) { $classes_key = $Registry -> Open("LMachine/Software/Classes/", {Access => KEY_ALL_ACCESS()}) or die "Cannot open classpath"; - $k = $classes_key->CreateKey($extension); - $k -> ArrayValues(0); - $k -> {"/"} = $file_type; - # delete possibly conflicting value from HKCU/software - $classes_key = $Registry -> Open("CUser/Software/Classes/", - {Access => KEY_ALL_ACCESS()}); - delete $classes_key -> {$extension}; } else { $classes_key = $Registry -> Open("CUser/Software/Classes/", {Access => KEY_ALL_ACCESS()}); + } + + + my $do_create_key = 0; + + if ($mode == 1) { + if (defined($classes_key->{$extension})) { + if (defined($classes_key->{$extension}->{'/'})) { + if ($classes_key->{$extension}->{'/'} eq $file_type) { + debug("register_extension: already same key $extension $file_type present, recreate it\n"); + $do_create_key = 1; + } else { + debug("register_extension: old foreign key" . $classes_key->{$extension}->{'/'} . " found, not changing\n"); + } + } + } else { + debug("register_extension: old key $extension not found, recreating it\n"); + $do_create_key = 1; + } + } elsif ($mode == 2) { + $do_create_key = 1; + } else { + die "Unknown mode $mode for register_extension"; + } + + if ($do_create_key) { $k = $classes_key->CreateKey($extension); $k -> ArrayValues(0); $k -> {"/"} = $file_type; + if (admin()) { + # delete possibly conflicting value from HKCU/software + $classes_key = $Registry -> Open("CUser/Software/Classes/", + {Access => KEY_ALL_ACCESS()}); + delete $classes_key -> {$extension}; + } } } =pod -=item C<unregister_extension($extension)> +=item C<unregister_extension($mode, $extension, $filetype)> Reversal of register_extension. =cut sub unregister_extension { + my $mode = shift; + return if ($mode == 0); + # we don't error check; we just do the best we can. my $extension = shift; + my $filetype = shift; $extension = '.'.$extension unless $extension =~ /^\./; # ensure leading dot $extension = uc($extension); debug("unregistering $extension\n"); - my $classes_key = $Registry -> Open("CUser/Software/Classes/", + + my $classes_key; + + my $HKLMclasses_key = $Registry -> Open("LMachine/Software/Classes/", {Access => KEY_ALL_ACCESS()}); - if ($classes_key) { - reg_delete_recurse ($classes_key, $extension."/"); + my $HKCUclasses_key = $Registry -> Open("CUser/Software/Classes/", + {Access => KEY_ALL_ACCESS()}); + if (admin()) { + $classes_key = $HKLMclasses_key; } else { - debug("Cannot open HKCU classes for write\n"); + $classes_key = $HKCUclasses_key; } - if ($is_admin) { - $classes_key = $Registry -> Open("LMachine/Software/Classes/", - {Access => KEY_ALL_ACCESS()}); - if ($classes_key) { + if ($classes_key) { + my $do_remove_key = 0; + if ($mode == 1) { + if (defined($classes_key->{$extension})) { + if (defined($classes_key->{$extension}->{'/'})) { + if ($classes_key->{$extension}->{'/'} eq $filetype) { + debug("unregister_extension: correct key/value $extension/$filetype found, removing\n"); + $do_remove_key = 1; + } else { + debug("unregister_extension: foreign value for $extension found, keeping it\n"); + } + } else { + $do_remove_key = 1; + } + } else { + # nothing necessary, this key wasn't found + } + } elsif ($mode == 2) { + $do_remove_key = 1; + } else { + die "Unknown mode $mode for unregister_extension"; + } + + if ($do_remove_key) { reg_delete_recurse ($classes_key, $extension."/"); + if (admin()) { + if ($HKCUclasses_key) { + reg_delete_recurse ($HKCUclasses_key, $extension."/"); + } else { + debug("Cannot open HKCU classes for write\n"); + } + } + } + } else { + if (admin()) { + debug("Cannot open HKLM classes for write\n"); } else { - debug("Cannot open HKLM classes for write\n"); + debug("Cannot open HKCU classes for write\n"); } } } @@ -1016,3 +1089,10 @@ sub unregister_uninstaller { # needs a terminal 1 for require to succeed! 1; + +### Local Variables: +### perl-indent-level: 2 +### tab-width: 2 +### indent-tabs-mode: nil +### End: +# vim:set tabstop=2 expandtab: # |