Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
218 bj 1
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
2
    & eval 'exec perl -w -S $0 $argv:q'
3
    if 0;
4
 
5
# ******************************************************************
6
#  Author: Chad Elliott
7
#    Date: 12/05/2005
8
#     $Id: registry.pl,v 1.2 2006/02/15 18:44:00 elliott_c Exp $
9
# ******************************************************************
10
 
11
# ******************************************************************
12
# Pragma Section
13
# ******************************************************************
14
 
15
use strict;
16
use FindBin;
17
use FileHandle;
18
use File::Basename;
19
 
20
# ******************************************************************
21
# Data Section
22
# ******************************************************************
23
 
24
my($Registry) = undef;
25
my($MPC_ROOT) = $FindBin::Bin;
26
$MPC_ROOT =~ s!/!\\!g;
27
 
28
my($version) = '$Id: registry.pl,v 1.2 2006/02/15 18:44:00 elliott_c Exp $';
29
$version =~ s/.*\s+(\d+[\.\d]+)\s+.*/$1/;
30
 
31
my(%types) = ('nmake' => 'NMAKE',
32
              'bmake' => 'Borland Make',
33
              'vc6'   => 'DSW',
34
              'vc71'  => 'SLN 7.1',
35
              'vc8'   => 'SLN 8.0',
36
             );
37
 
38
# ******************************************************************
39
# Subroutine Section
40
# ******************************************************************
41
 
42
sub set_ext_icon {
43
  my($ext)  = shift;
44
  my($num)  = shift;
45
  my($extf) = $ext . 'file';
46
  $Registry->{"HKEY_CLASSES_ROOT/.$ext/"} = {'/' => $extf};
47
  $Registry->{"HKEY_CLASSES_ROOT/$extf/"} = {};
48
  $Registry->{"HKEY_CLASSES_ROOT/$extf/DefaultIcon/"} =
49
                           {'/' => "$MPC_ROOT\\MPC.ico,$num"};
50
}
51
 
52
 
53
sub set_dir_command {
54
  my($type)  = shift;
55
  my($desc)  = shift;
56
  my($shell) = 'HKEY_CLASSES_ROOT/Directory/shell';
57
  my($hash)  = $Registry->{$shell};
58
 
59
  if (!defined $hash) {
60
    $Registry->{$shell} = {};
61
    $hash = $Registry->{$shell};
62
  }
63
 
64
  my($key) = 'MPC' . uc($type) . '/';
65
  $hash->{$key} = {'/' => "MPC -> $desc"};
66
 
67
  $key .= 'command/';
68
  $hash->{$key} = {'/' => "cmd /c \"cd %L && $MPC_ROOT\\mwc.pl -type $type -recurse || pause\""};
69
}
70
 
71
 
72
sub set_mwc_command {
73
  my($type)  = shift;
74
  my($desc)  = shift;
75
  my($shell) = 'HKEY_CLASSES_ROOT/mwcfile/shell';
76
  my($hash)  = $Registry->{$shell};
77
 
78
  if (!defined $hash) {
79
    $Registry->{$shell} = {};
80
    $hash = $Registry->{$shell};
81
  }
82
 
83
  my($key) = 'MPC' . uc($type) . '/';
84
  $hash->{$key} = {'/' => "MPC -> $desc"};
85
 
86
  $key .= 'command/';
87
  $hash->{$key} = {'/' => "cmd /c \"$MPC_ROOT\\mwc.pl -type $type %L || pause\""};
88
 
89
  set_dir_command($type, $desc);
90
}
91
 
92
 
93
sub delete_key {
94
  my($key) = shift;
95
  my($val) = $Registry->{$key};
96
 
97
  if (UNIVERSAL::isa($val, 'HASH')) {
98
    foreach my $k (keys %$val) {
99
      delete_key($key . $k);
100
    }
101
  }
102
  delete $Registry->{$key};
103
}
104
 
105
# ******************************************************************
106
# Main Section
107
# ******************************************************************
108
 
109
if ($^O eq 'MSWin32') {
110
  require Win32::TieRegistry;
111
  Win32::TieRegistry->import(TiedRef => \$Registry,
112
                             Delimiter => '/');
113
}
114
else {
115
  print "ERROR: This script will only run on Windows.\n";
116
  exit(1);
117
}
118
 
119
if (defined $ARGV[0]) {
120
  if ($ARGV[0] eq '-r') {
121
    delete $Registry->{'HKEY_CURRENT_USER/Environment/MPC_ROOT'};
122
 
123
    delete_key('HKEY_CLASSES_ROOT/.mwc/');
124
    delete_key('HKEY_CLASSES_ROOT/mwcfile/');
125
    delete_key('HKEY_CLASSES_ROOT/.mpc/');
126
    delete_key('HKEY_CLASSES_ROOT/mpcfile/');
127
    delete_key('HKEY_CLASSES_ROOT/.mpb/');
128
    delete_key('HKEY_CLASSES_ROOT/mpbfile/');
129
 
130
    foreach my $type (keys %types) {
131
      delete_key('HKEY_CLASSES_ROOT/Directory/shell/MPC' . uc($type) . '/');
132
    }
133
  }
134
  else {
135
    print STDERR "registry v$version\n",
136
                 "Usage: ", basename($0), " [-r]\n\n",
137
                 "       -r  Remove MPC related registry keys (this does not work).\n\n",
138
                 "Set the MPC_ROOT environment variable to the location of this script.\n",
139
                 "Also, add context menus for .mwc files and directories.\n";
140
    exit(0);
141
  }
142
}
143
 
144
$Registry->{'HKEY_CURRENT_USER/Environment/MPC_ROOT'} = [$MPC_ROOT, 'REG_SZ'];
145
 
146
set_ext_icon('mwc', 0);
147
set_ext_icon('mpc', 1);
148
set_ext_icon('mpb', 1);
149
 
150
foreach my $type (keys %types) {
151
  set_mwc_command($type, $types{$type});
152
}
153
 
154
print "You may need to log out and then ",
155
      "log back in for these settings to take effect.\n";
156
 
157
exit(0);