2 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
3 & eval 'exec perl -w -S $0 $argv:q'
6 # ******************************************************************
9 # ******************************************************************
11 # ******************************************************************
13 # ******************************************************************
20 # ******************************************************************
22 # ******************************************************************
25 my $MPC_ROOT = $FindBin::Bin
;
26 $MPC_ROOT =~ s!/!\\!g;
29 my %types = ('nmake' => ['NMAKE', 'NMAKE'],
30 'bmake' => ['Borland Make', 'Borland Make'],
31 'vc6' => ['DSW', 'DSP'],
32 'vc71' => ['SLN 7.1', 'VCPROJ 7.1'],
33 'vc8' => ['SLN 8.0', 'VCPROJ 8.0'],
34 'vc9' => ['SLN 9.0', 'VCPROJ 9.0'],
35 'vc10' => ['SLN 10.0', 'VCPROJ 10.0'],
36 'vc11' => ['SLN 11.0', 'VCPROJ 11.0'],
37 'vc12' => ['SLN 12.0', 'VCPROJ 12.0'],
38 'vc14' => ['SLN 14.0', 'VCPROJ 14.0'],
39 'vs2017' => ['SLN 2017', 'PROJ 2017'],
40 'vs2019' => ['SLN 2019', 'PROJ 2019'],
41 'wix' => ['WiX', 'WiX Project'],
44 # ******************************************************************
46 # ******************************************************************
50 my $extf = $ext . 'file';
51 $Registry->{"HKEY_CLASSES_ROOT/.$ext/"} = {'/' => $extf};
52 $Registry->{"HKEY_CLASSES_ROOT/$extf/"} = {};
53 $Registry->{"HKEY_CLASSES_ROOT/$extf/DefaultIcon/"} =
54 {'/' => "$MPC_ROOT\\MPC.ico,$num"};
59 my($type, $desc) = @_;
60 my $shell = 'HKEY_CLASSES_ROOT/Directory/shell';
61 my $hash = $Registry->{$shell};
63 ## If there is no shell setting, just create an empty one. However,
64 ## this isn't very likely.
66 $Registry->{$shell} = {};
67 $hash = $Registry->{$shell};
70 ## Create an entry for this project type (vc6, vc7, etc.)
71 my $key = 'MPC' . uc($type) . '/';
72 $hash->{$key} = {'/' => "MPC -> $desc"};
74 ## Now store the command for creating a workspace for this project
77 $hash->{$key} = {'/' => "cmd /c \"cd %L && $MPC_ROOT\\mwc.pl -type $type -recurse || pause\""};
82 my($type, $desc) = @_;
83 my $shell = 'HKEY_CLASSES_ROOT/mwcfile/shell';
84 my $hash = $Registry->{$shell};
86 ## Create the new entry for the mwc files. This is likely to not
89 $Registry->{$shell} = {};
90 $hash = $Registry->{$shell};
93 ## Create an entry for this project type (vc6, vc7, etc.)
94 my $key = 'MPC' . uc($type) . '/';
95 $hash->{$key} = {'/' => "MPC -> $desc"};
97 ## Now store the command for creating a workspace for this project
100 $hash->{$key} = {'/' => "cmd /c \"$MPC_ROOT\\mwc.pl -type $type %L || pause\""};
102 ## Since MPC will create a workspace out of a directory, we want to do
103 ## the same thing for directories too.
104 set_dir_command
($type, $desc);
108 sub set_mpc_command
{
109 my($type, $desc) = @_;
110 my $shell = 'HKEY_CLASSES_ROOT/mpcfile/shell';
111 my $hash = $Registry->{$shell};
113 ## Create the new entry for the mpc files. This is likely to not
115 if (!defined $hash) {
116 $Registry->{$shell} = {};
117 $hash = $Registry->{$shell};
120 ## Create an entry for this project type (vc6, vc7, etc.)
121 my $key = 'MPC' . uc($type) . '/';
122 $hash->{$key} = {'/' => "MPC -> $desc"};
124 ## Now store the command for creating a single project for this project
127 $hash->{$key} = {'/' => "cmd /c \"$MPC_ROOT\\mpc.pl -type $type %L || pause\""};
133 my $val = $Registry->{$key};
135 ## Delete everything associated with this key (recursively traversing
137 if (UNIVERSAL
::isa
($val, 'HASH')) {
138 foreach my $k (keys %$val) {
139 delete_key
($key . $k);
143 ## Now get the key itself.
144 delete $Registry->{$key};
147 # ******************************************************************
149 # ******************************************************************
151 if ($^O
eq 'MSWin32') {
152 ## Pull in the registry modules and import the necessary items.
153 require Win32
::TieRegistry
;
154 Win32
::TieRegistry
->import(TiedRef
=> \
$Registry,
158 ## Currently, no other registry type is supported.
159 print "ERROR: This script will only run on Windows.\n";
163 if (defined $ARGV[0]) {
164 if ($ARGV[0] eq '-r') {
165 ## Get rid of the MPC_ROOT environment variable.
166 delete $Registry->{'HKEY_CURRENT_USER/Environment/MPC_ROOT'};
168 ## Now delete all the keys that this script knows how to make.
169 delete_key
('HKEY_CLASSES_ROOT/.mwc/');
170 delete_key
('HKEY_CLASSES_ROOT/mwcfile/');
171 delete_key
('HKEY_CLASSES_ROOT/.mpc/');
172 delete_key
('HKEY_CLASSES_ROOT/mpcfile/');
173 delete_key
('HKEY_CLASSES_ROOT/.mpb/');
174 delete_key
('HKEY_CLASSES_ROOT/mpbfile/');
176 foreach my $type (keys %types) {
177 delete_key
('HKEY_CLASSES_ROOT/Directory/shell/MPC' . uc($type) . '/');
183 print STDERR
"registry v$version\n",
184 "Usage: ", basename
($0), " [-r]\n\n",
185 " -r Remove MPC related registry keys.\n\n",
186 "Set the MPC_ROOT environment variable to the location of this script.\n",
187 "Also, add context menus for .mwc files and directories.\n";
192 ## Set the MPC_ROOT environment variable.
193 $Registry->{'HKEY_CURRENT_USER/Environment/MPC_ROOT'} = [$MPC_ROOT, 'REG_SZ'];
195 ## Associate the icons with the various MPC file types.
196 set_ext_icon
('mwc', 0);
197 set_ext_icon
('mpc', 1);
198 set_ext_icon
('mpb', 1);
200 ## Create the command settings for each type
201 foreach my $type (keys %types) {
202 set_mwc_command
($type, $types{$type}->[0]);
203 set_mpc_command
($type, $types{$type}->[1]);
206 print "You may need to log out and then ",
207 "log back in for some of these settings to take effect.\n";