Skip to content

Commit 1137bc6

Browse files
committed
Merge branch 'release/7.0.1'
2 parents 9264270 + a302607 commit 1137bc6

File tree

8 files changed

+91
-40
lines changed

8 files changed

+91
-40
lines changed

Papercut.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2D6337D4
2626
EndProject
2727
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Build", ".Build", "{8661B39E-1555-4A2F-B6C2-6442E83DE73D}"
2828
ProjectSection(SolutionItems) = preProject
29+
.dockerignore = .dockerignore
2930
appveyor.yml = appveyor.yml
31+
build-docker.ps1 = build-docker.ps1
32+
build-docker.sh = build-docker.sh
3033
build.cake = build.cake
3134
build.ps1 = build.ps1
32-
build\BuildInformation.cake = build\BuildInformation.cake
3335
Directory.Build.props = Directory.Build.props
36+
Dockerfile = Dockerfile
3437
GitVersion.yml = GitVersion.yml
38+
README.md = README.md
3539
build\ReleaseNotes.cake = build\ReleaseNotes.cake
3640
ReleaseNotes.md = ReleaseNotes.md
37-
.dockerignore = .dockerignore
38-
Dockerfile = Dockerfile
39-
README.md = README.md
40-
build-docker.sh = build-docker.sh
41-
build-docker.ps1 = build-docker.ps1
41+
build\Velopack.cake = build\Velopack.cake
4242
EndProjectSection
4343
EndProject
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Papercut.Infrastructure.Smtp", "src\Papercut.Infrastructure.Smtp\Papercut.Infrastructure.Smtp.csproj", "{873EC485-8E94-4877-8EA7-A7DFE7612E0A}"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Papercut SMTP UI Requires the "WebView2" Microsoft shared system component to be
2929
![Logging View](https://changemakerstudios.us/content/images/2020/07/Papercut-Log.png)
3030

3131
## Papercut SMTP Service
32-
Papercut SMTP has an optional HTTP server to receive emails even when the client is not running. It's installed by default with [Papercut.Setup.exe](https://github.com/ChangemakerStudios/Papercut/releases).
33-
Alternatively, it can be run in an almost portable way by downloading [Papercut.Service.zip](https://github.com/ChangemakerStudios/Papercut/releases), unzipping and [following the service installation instructions](https://github.com/ChangemakerStudios/Papercut/tree/develop/src/Papercut.Service).
32+
Papercut SMTP has an optional HTTP server to receive emails even when the client is not running.
33+
It can be run in an almost portable way by downloading [Papercut.Smtp.Service.*.zip](https://github.com/ChangemakerStudios/Papercut/releases), unzipping, and [following the service installation instructions](https://github.com/ChangemakerStudios/Papercut/tree/develop/src/Papercut.Service).
3434

3535
### Host in Docker
3636

ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## Papercut SMTP v7.0.1 [2024-11-08]
4+
5+
- Fixed Run on Startup broken. (Thanks, [rikrak](https://github.com/rikrak)))
6+
37
## Papercut SMTP v7.0.0 [2024-10-14]
48

59
_NOTE: Uninstall any existing Papercut SMTP installations BEFORE installing this new version._

src/GlobalAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
//------------------------------------------------------------------------------
66
using System.Reflection;
77

8-
[assembly: AssemblyVersion("7.1.0.0")]
9-
[assembly: AssemblyFileVersion("7.1.0.0")]
10-
[assembly: AssemblyInformationalVersion("7.1.0-dev.111+Branch.develop.Sha.c6c2a6557ac3b3a8d1ebd93f45de2ff515018f18")]
8+
[assembly: AssemblyVersion("7.0.0.0")]
9+
[assembly: AssemblyFileVersion("7.0.0.0")]
10+
[assembly: AssemblyInformationalVersion("7.0.0.0")]

src/Papercut.UI/AppLayer/Settings/AppRunOnStartupService.cs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717

1818

19+
using System.IO;
1920
using System.Security;
2021

2122
using Autofac;
@@ -26,28 +27,74 @@
2627
using Papercut.Common.Extensions;
2728
using Papercut.Domain.Application;
2829
using Papercut.Domain.Events;
30+
using Papercut.Domain.LifecycleHooks;
2931
using Papercut.Domain.UiCommands;
3032

3133
namespace Papercut.AppLayer.Settings;
3234

33-
public class AppRunOnStartupService(ILogger logger, IUiCommandHub uiCommandHub) : IEventHandler<SettingsUpdatedEvent>
35+
public class AppRunOnStartupService(ILogger logger, IUiCommandHub uiCommandHub) : IAppLifecycleStarted, IEventHandler<SettingsUpdatedEvent>
3436
{
3537
const string AppStartupKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
3638

39+
public Task OnStartedAsync()
40+
{
41+
if (Properties.Settings.Default.RunOnStartup)
42+
{
43+
// check if we need to migrate....
44+
bool needsMigration = false;
45+
try
46+
{
47+
using var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);
48+
49+
object? legacyAppKey = registryKey?.GetValue(PapercutAppConstants.LegacyName, null);
50+
51+
if (registryKey != null && legacyAppKey != null)
52+
{
53+
needsMigration = true;
54+
55+
logger.Information(
56+
"Migrating App Run on Startup Registry {LegacyKey} to {NewKey}",
57+
$"{AppStartupKey}\\{PapercutAppConstants.LegacyName}",
58+
$"{AppStartupKey}\\{PapercutAppConstants.Name}");
59+
60+
registryKey.DeleteValue(PapercutAppConstants.LegacyName, false);
61+
}
62+
}
63+
catch (Exception ex)
64+
{
65+
logger.Debug(ex, "Failure deleting legacy app key");
66+
}
67+
68+
if (needsMigration)
69+
{
70+
UpdateRunAtStartup();
71+
}
72+
}
73+
74+
return Task.CompletedTask;
75+
}
76+
3777
public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)
3878
{
3979
// check if the setting changed
4080
if (@event.PreviousSettings.RunOnStartup == @event.NewSettings.RunOnStartup)
4181
return Task.CompletedTask;
4282

83+
UpdateRunAtStartup();
84+
85+
return Task.CompletedTask;
86+
}
87+
88+
private bool UpdateRunAtStartup()
89+
{
4390
try
4491
{
45-
var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);
92+
using var registryKey = Registry.CurrentUser.OpenSubKey(AppStartupKey, true);
4693

4794
if (registryKey == null)
4895
{
4996
logger.Error("Failure opening registry key {AppStartupKey}", AppStartupKey);
50-
return Task.CompletedTask;
97+
return true;
5198
}
5299

53100
var applicationName = PapercutAppConstants.Name;
@@ -59,6 +106,17 @@ public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)
59106

60107
if (Properties.Settings.Default.RunOnStartup && !runOnStartup)
61108
{
109+
if (!File.Exists(executablePath))
110+
{
111+
logger.Error(
112+
"App Startup Failure: {ExecutablePath} for Papercut Doesn't Exist -- Run at Startup Disabled",
113+
executablePath);
114+
115+
Properties.Settings.Default.RunOnStartup = false;
116+
117+
return false;
118+
}
119+
62120
// turn on...
63121
logger.Information(
64122
"Setting AppStartup Registry {Key} to Run Papercut at {ExecutablePath}",
@@ -86,7 +144,7 @@ public Task HandleAsync(SettingsUpdatedEvent @event, CancellationToken token)
86144
"Failed");
87145
}
88146

89-
return Task.CompletedTask;
147+
return false;
90148
}
91149

92150
#region Begin Static Container Registrations

src/Papercut.UI/AppLayer/Settings/MergeServerBackendSettings.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,19 @@
2626

2727
namespace Papercut.AppLayer.Settings;
2828

29-
public class MergeServerBackendSettings : IEventHandler<AppProcessExchangeEvent>
29+
public class MergeServerBackendSettings(
30+
MessagePathConfigurator configurator,
31+
IMessageBus messageBus)
32+
: IEventHandler<AppProcessExchangeEvent>
3033
{
31-
readonly MessagePathConfigurator _configurator;
32-
33-
readonly IMessageBus _messageBus;
34-
35-
public MergeServerBackendSettings(MessagePathConfigurator configurator, IMessageBus messageBus)
36-
{
37-
this._configurator = configurator;
38-
this._messageBus = messageBus;
39-
}
40-
4134
public async Task HandleAsync(AppProcessExchangeEvent @event, CancellationToken token)
4235
{
4336
ArgumentNullException.ThrowIfNull(@event);
4437

4538
if (string.IsNullOrWhiteSpace(@event.MessageWritePath))
4639
return;
4740

48-
if (!this._configurator.LoadPaths.Any(s => s.StartsWith(@event.MessageWritePath, StringComparison.OrdinalIgnoreCase)))
41+
if (!configurator.LoadPaths.Any(s => s.StartsWith(@event.MessageWritePath, StringComparison.OrdinalIgnoreCase)))
4942
{
5043
// add it for watching...
5144
Properties.Settings.Default.MessagePaths = $"{Properties.Settings.Default.MessagePaths};{@event.MessageWritePath}";
@@ -60,7 +53,7 @@ public async Task HandleAsync(AppProcessExchangeEvent @event, CancellationToken
6053
Properties.Settings.Default.Port = @event.Port;
6154
Properties.Settings.Default.Save();
6255

63-
await this._messageBus.PublishAsync(new SettingsUpdatedEvent(previousSettings), token);
56+
await messageBus.PublishAsync(new SettingsUpdatedEvent(previousSettings), token);
6457
}
6558

6659
#region Begin Static Container Registrations

src/Papercut.UI/AppLayer/Settings/SaveSettingsOnExitService.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@
2222

2323
namespace Papercut.AppLayer.Settings;
2424

25-
public class SaveSettingsOnExitService : IAppLifecyclePreExit
25+
public class SaveSettingsOnExitService(ILogger logger) : IAppLifecyclePreExit
2626
{
27-
readonly ILogger _logger;
28-
29-
public SaveSettingsOnExitService(ILogger logger)
30-
{
31-
this._logger = logger;
32-
}
33-
3427
public Task<AppLifecycleActionResultType> OnPreExit()
3528
{
3629
try
@@ -44,12 +37,12 @@ public Task<AppLifecycleActionResultType> OnPreExit()
4437
Properties.Settings.Default.MainWindowWidth = 400;
4538
}
4639

47-
this._logger.Debug("Saving Updated Settings...");
40+
logger.Debug("Saving Updated Settings...");
4841
Properties.Settings.Default.Save();
4942
}
5043
catch (Exception ex)
5144
{
52-
this._logger.Error(ex, "Failure Saving Settings File");
45+
logger.Error(ex, "Failure Saving Settings File");
5346
}
5447

5548
return Task.FromResult(AppLifecycleActionResultType.Continue);

src/Papercut.UI/Domain/Application/PapercutAppConstants.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ namespace Papercut.Domain.Application;
2222

2323
public static class PapercutAppConstants
2424
{
25-
internal static string Name { get; } = "Papercut.App";
25+
internal static string Name => "Papercut.Smtp.App";
2626

27-
internal static string ExecutablePath { get; } = Assembly.GetExecutingAssembly().Location;
27+
internal static string LegacyName => "Papercut.App";
28+
29+
internal static string ExecutablePath { get; } =
30+
Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe");
2831
}

0 commit comments

Comments
 (0)