Skip to content

Commit 23f96fc

Browse files
committed
bug: srm uses regasm to register servers. Fixes #193.
2 parents b686031 + 1c473e9 commit 23f96fc

File tree

6 files changed

+154
-205
lines changed

6 files changed

+154
-205
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 2.4.1
2+
3+
- Fixed a bug where the Server Registration Manager could only register servers which were referencing the _same_ version of the SharpShell assembly as the manager itself (#194).
4+
15
## Version 2.4
26

37
- Added `DesktopBackground` and `DirectoryBackground` association types.

SharpShell/SharedAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
// You can specify all the values or you can default the Build and Revision Numbers
1818
// by using the '*' as shown below:
1919
// [assembly: AssemblyVersion("1.0.*")]
20-
[assembly: AssemblyVersion("2.4.0.0")]
21-
[assembly: AssemblyFileVersion("2.4.0.0")]
20+
[assembly: AssemblyVersion("2.4.2.0")]
21+
[assembly: AssemblyFileVersion("2.4.2.0")]
Lines changed: 26 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.Composition.Hosting;
42
using System.IO;
53
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
84
using ServerRegistrationManager.Actions;
95
using ServerRegistrationManager.OutputService;
10-
using SharpShell;
116
using SharpShell.Diagnostics;
7+
using SharpShell.Helpers;
128
using SharpShell.ServerRegistration;
139

1410
namespace ServerRegistrationManager
@@ -55,8 +51,8 @@ public void Run(string[] args)
5551

5652
// Get the verb, target and parameters.
5753
var verb = args[0];
58-
var target = args.Length > 1 ? args[1] : (string)null; // TODO tidy this up.
59-
var parameters = args.Skip(1);
54+
var target = args.Length > 1 ? args[1] : null; // TODO tidy this up.
55+
var parameters = args.Skip(1).ToArray();
6056

6157
//Allow user to override registrationType with -os32 or -os64
6258
if (parameters.Any(p => p.Equals(ParameterOS32, StringComparison.InvariantCultureIgnoreCase)))
@@ -68,7 +64,6 @@ public void Run(string[] args)
6864
registrationType = RegistrationType.OS64Bit;
6965
}
7066

71-
7267
// Based on the verb, perform the action.
7368
if (verb == VerbInstall)
7469
InstallServer(target, registrationType, parameters.Any(p => p == ParameterCodebase));
@@ -97,41 +92,18 @@ private void InstallServer(string path, RegistrationType registrationType, bool
9792
return;
9893
}
9994

100-
// Try and load the server types.
101-
IEnumerable<ISharpShellServer> serverTypes = null;
102-
try
103-
{
104-
serverTypes = LoadServerTypes(path);
105-
}
106-
catch (Exception e)
107-
{
108-
outputService.WriteError("An unhandled exception occured when loading the SharpShell");
109-
outputService.WriteError("Server Types from the specified assembly. Is it a SharpShell");
110-
outputService.WriteError("Server Assembly?");
111-
System.Diagnostics.Trace.Write(e);
112-
Logging.Error("An unhandled exception occured when loading a SharpShell server.", e);
113-
}
95+
var regasm = new RegAsm();
96+
var success = registrationType == RegistrationType.OS32Bit ? regasm.Register32(path, codeBase) : regasm.Register64(path, codeBase);
11497

115-
// Install each server type.
116-
foreach (var serverType in serverTypes)
98+
if (success)
11799
{
118-
// Inform the user we're going to install the server.
119-
outputService.WriteMessage("Preparing to install (" + registrationType + "): " + serverType.DisplayName, true);
120-
121-
// Install the server.
122-
try
123-
{
124-
SharpShell.ServerRegistration.ServerRegistrationManager.InstallServer(serverType, registrationType, codeBase);
125-
SharpShell.ServerRegistration.ServerRegistrationManager.RegisterServer(serverType, registrationType);
126-
}
127-
catch (Exception e)
128-
{
129-
outputService.WriteError("Failed to install and register the server.");
130-
Logging.Error("An unhandled exception occured installing and registering the server " + serverType.DisplayName, e);
131-
continue;
132-
}
133-
134-
outputService.WriteSuccess(" " + serverType.DisplayName + " installed and registered.", true);
100+
outputService.WriteSuccess($" {path} installed and registered.", true);
101+
outputService.WriteMessage(regasm.StandardOutput);
102+
}
103+
else
104+
{
105+
outputService.WriteError($" {path} failed to register.", true);
106+
outputService.WriteError(regasm.StandardError);
135107
}
136108
}
137109

@@ -142,42 +114,18 @@ private void InstallServer(string path, RegistrationType registrationType, bool
142114
/// <param name="registrationType">Type of the registration.</param>
143115
private void UninstallServer(string path, RegistrationType registrationType)
144116
{
145-
// Try and load the server types.
146-
IEnumerable<ISharpShellServer> serverTypes = null;
147-
try
148-
{
149-
serverTypes = LoadServerTypes(path);
150-
}
151-
catch (Exception e)
152-
{
153-
outputService.WriteError("An unhandled exception occured when loading the SharpShell");
154-
outputService.WriteError("Server Types from the specified assembly. Is it a SharpShell");
155-
outputService.WriteError("Server Assembly?");
156-
System.Diagnostics.Trace.Write(e);
157-
Logging.Error("An unhandled exception occured when loading a SharpShell server.", e);
158-
}
117+
var regasm = new RegAsm();
118+
var success = registrationType == RegistrationType.OS32Bit ? regasm.Unregister32(path) : regasm.Unregister64(path);
159119

160-
// Install each server type.
161-
foreach (var serverType in serverTypes)
120+
if (success)
121+
{
122+
outputService.WriteSuccess($" {path} uninstalled.", true);
123+
outputService.WriteMessage(regasm.StandardOutput);
124+
}
125+
else
162126
{
163-
// Inform the user we're going to install the server.
164-
Console.WriteLine("Preparing to uninstall (" + registrationType + "): " + serverType.DisplayName, true);
165-
166-
// Install the server.
167-
try
168-
{
169-
170-
SharpShell.ServerRegistration.ServerRegistrationManager.UnregisterServer(serverType, registrationType);
171-
SharpShell.ServerRegistration.ServerRegistrationManager.UninstallServer(serverType, registrationType);
172-
}
173-
catch (Exception e)
174-
{
175-
outputService.WriteError("Failed to unregister and uninstall the server.");
176-
Logging.Error("An unhandled exception occured un registering and uninstalling the server " + serverType.DisplayName, e);
177-
continue;
178-
}
179-
180-
outputService.WriteSuccess(" " + serverType.DisplayName + " unregistered and uninstalled.", true);
127+
outputService.WriteError($" {path} failed to uninstall.", true);
128+
outputService.WriteError(regasm.StandardError);
181129
}
182130
}
183131

@@ -192,22 +140,7 @@ private void ShowWelcome()
192140
outputService.WriteMessage("========================================");
193141
outputService.WriteMessage("");
194142
}
195-
196-
/// <summary>
197-
/// Loads the server types from an assembly.
198-
/// </summary>
199-
/// <param name="assemblyPath">The assembly path.</param>
200-
/// <returns>The SharpShell Server types from the assembly.</returns>
201-
private static IEnumerable<ISharpShellServer> LoadServerTypes(string assemblyPath)
202-
{
203-
// Create an assembly catalog for the assembly and a container from it.
204-
var catalog = new AssemblyCatalog(Path.GetFullPath(assemblyPath));
205-
var container = new CompositionContainer(catalog);
206-
207-
// Get all exports of type ISharpShellServer.
208-
return container.GetExports<ISharpShellServer>().Select(st => st.Value);
209-
}
210-
143+
211144
private const string VerbHelp = @"help";
212145
private const string VerbInstall = @"install";
213146
private const string VerbUninstall = @"uninstall";
@@ -216,7 +149,7 @@ private static IEnumerable<ISharpShellServer> LoadServerTypes(string assemblyPat
216149

217150
private const string ParameterCodebase = @"-codebase";
218151

219-
private const String ParameterOS32 = @"-os32";
220-
private const String ParameterOS64 = @"-os64";
152+
private const string ParameterOS32 = @"-os32";
153+
private const string ParameterOS64 = @"-os64";
221154
}
222155
}

SharpShell/Tools/ServerRegistrationManager/OutputService/ConsoleOutputService.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using SharpShell.Diagnostics;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -24,21 +25,29 @@ public void WriteMessage(string message, bool log = false)
2425

2526
// Write the message.
2627
Console.WriteLine(message);
28+
29+
// If required, write to the SharpShell log.
30+
if (log)
31+
Logging.Log(message);
2732
}
2833

2934
/// <summary>
3035
/// Writes the success.
3136
/// </summary>
32-
/// <param name="error">The error.</param>
37+
/// <param name="messabe">The message.</param>
3338
/// <param name="log">if set to <c>true</c> [log].</param>
34-
public void WriteSuccess(string error, bool log = false)
39+
public void WriteSuccess(string message, bool log = false)
3540
{
3641
// Set the colour.
3742
Console.ForegroundColor = ConsoleColor.Green;
3843

3944
// Write the message.
40-
Console.WriteLine(error);
41-
Console.ForegroundColor = ConsoleColor.Gray;
45+
Console.WriteLine(message);
46+
Console.ForegroundColor = ConsoleColor.Gray;
47+
48+
// If required, write to the SharpShell log.
49+
if (log)
50+
Logging.Log(message);
4251
}
4352

4453
/// <summary>
@@ -53,7 +62,11 @@ public void WriteError(string error, bool log = false)
5362

5463
// Write the message.
5564
Console.WriteLine(error);
56-
Console.ForegroundColor = ConsoleColor.Gray;
65+
Console.ForegroundColor = ConsoleColor.Gray;
66+
67+
// If required, write to the SharpShell log.
68+
if (log)
69+
Logging.Error(error);
5770
}
5871
}
5972
}

SharpShell/Tools/ServerRegistrationManager/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace ServerRegistrationManager
1010
{
11-
class Program
11+
internal class Program
1212
{
1313
static void Main(string[] args)
1414
{

0 commit comments

Comments
 (0)