Merge pull request #328 from bkaankose/hotfix/LogsArchive
Fixing sharing logs
This commit is contained in:
@@ -13,5 +13,6 @@
|
|||||||
|
|
||||||
public const string ClientLogFile = "Client_.log";
|
public const string ClientLogFile = "Client_.log";
|
||||||
public const string ServerLogFile = "Server_.log";
|
public const string ServerLogFile = "Server_.log";
|
||||||
|
public const string LogArchiveFileName = "WinoLogs.zip";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,5 +8,13 @@ namespace Wino.Core.Domain.Interfaces
|
|||||||
Task<string> CopyFileAsync(string sourceFilePath, string destinationFolderPath);
|
Task<string> CopyFileAsync(string sourceFilePath, string destinationFolderPath);
|
||||||
Task<Stream> GetFileStreamAsync(string folderPath, string fileName);
|
Task<Stream> GetFileStreamAsync(string folderPath, string fileName);
|
||||||
Task<string> GetFileContentByApplicationUriAsync(string resourcePath);
|
Task<string> GetFileContentByApplicationUriAsync(string resourcePath);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Zips all existing logs and saves to picked destination folder.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logsFolder">Folder path where logs are stored.</param>
|
||||||
|
/// <param name="destinationFolder">Target path to save the archive file.</param>
|
||||||
|
/// <returns>True if zip is created with at least one item, false if logs are not found.</returns>
|
||||||
|
Task<bool> SaveLogsToFolderAsync(string logsFolder, string destinationFolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
|
using Wino.Core.Domain;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
|
|
||||||
namespace Wino.Core.UWP.Services
|
namespace Wino.Core.UWP.Services
|
||||||
@@ -34,5 +36,27 @@ namespace Wino.Core.UWP.Services
|
|||||||
|
|
||||||
return await createdFile.OpenStreamForWriteAsync();
|
return await createdFile.OpenStreamForWriteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SaveLogsToFolderAsync(string logsFolder, string destinationFolder)
|
||||||
|
{
|
||||||
|
var logFiles = Directory.GetFiles(logsFolder, "*.log");
|
||||||
|
|
||||||
|
if (logFiles.Length == 0) return false;
|
||||||
|
|
||||||
|
using var fileStream = await GetFileStreamAsync(destinationFolder, Constants.LogArchiveFileName);
|
||||||
|
using var archive = new ZipArchive(fileStream, ZipArchiveMode.Create, true);
|
||||||
|
|
||||||
|
foreach (var logFile in logFiles)
|
||||||
|
{
|
||||||
|
using FileStream logFileStream = File.Open(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
|
||||||
|
var zipArchiveEntry = archive.CreateEntry(Path.GetFileName(logFile), CompressionLevel.Fastest);
|
||||||
|
using var zipStream = zipArchiveEntry.Open();
|
||||||
|
|
||||||
|
await logFileStream.CopyToAsync(zipStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Wino.Core.Domain;
|
using Wino.Core.Domain;
|
||||||
|
using Wino.Core.Domain.Enums;
|
||||||
using Wino.Core.Domain.Interfaces;
|
using Wino.Core.Domain.Interfaces;
|
||||||
using Wino.Core.Services;
|
|
||||||
|
|
||||||
namespace Wino.Mail.ViewModels
|
namespace Wino.Mail.ViewModels
|
||||||
{
|
{
|
||||||
public class AboutPageViewModel : BaseViewModel
|
public partial class AboutPageViewModel : BaseViewModel
|
||||||
{
|
{
|
||||||
private readonly IStoreRatingService _storeRatingService;
|
private readonly IStoreRatingService _storeRatingService;
|
||||||
private readonly INativeAppService _nativeAppService;
|
private readonly INativeAppService _nativeAppService;
|
||||||
@@ -22,9 +21,6 @@ namespace Wino.Mail.ViewModels
|
|||||||
public string PrivacyPolicyUrl => "https://www.winomail.app/privacy_policy.html";
|
public string PrivacyPolicyUrl => "https://www.winomail.app/privacy_policy.html";
|
||||||
public string PaypalUrl => "https://paypal.me/bkaankose?country.x=PL&locale.x=en_US";
|
public string PaypalUrl => "https://paypal.me/bkaankose?country.x=PL&locale.x=en_US";
|
||||||
|
|
||||||
public AsyncRelayCommand<object> NavigateCommand { get; set; }
|
|
||||||
public AsyncRelayCommand ShareWinoLogCommand { get; set; }
|
|
||||||
public AsyncRelayCommand ShareProtocolLogCommand { get; set; }
|
|
||||||
public IPreferencesService PreferencesService { get; }
|
public IPreferencesService PreferencesService { get; }
|
||||||
|
|
||||||
public AboutPageViewModel(IStoreRatingService storeRatingService,
|
public AboutPageViewModel(IStoreRatingService storeRatingService,
|
||||||
@@ -42,9 +38,6 @@ namespace Wino.Mail.ViewModels
|
|||||||
_fileService = fileService;
|
_fileService = fileService;
|
||||||
|
|
||||||
PreferencesService = preferencesService;
|
PreferencesService = preferencesService;
|
||||||
NavigateCommand = new AsyncRelayCommand<object>(Navigate);
|
|
||||||
ShareWinoLogCommand = new AsyncRelayCommand(ShareWinoLogAsync);
|
|
||||||
ShareProtocolLogCommand = new AsyncRelayCommand(ShareProtocolLogAsync);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnActivated()
|
protected override void OnActivated()
|
||||||
@@ -70,35 +63,28 @@ namespace Wino.Mail.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task ShareProtocolLogAsync()
|
[RelayCommand]
|
||||||
=> SaveLogInternalAsync(ImapTestService.ProtocolLogFileName);
|
private async Task ShareWinoLogAsync()
|
||||||
|
|
||||||
private Task ShareWinoLogAsync()
|
|
||||||
=> SaveLogInternalAsync(Constants.ClientLogFile);
|
|
||||||
|
|
||||||
private async Task SaveLogInternalAsync(string sourceFileName)
|
|
||||||
{
|
{
|
||||||
var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
|
var appDataFolder = _appInitializerService.ApplicationDataFolderPath;
|
||||||
|
|
||||||
var logFile = Path.Combine(appDataFolder, sourceFileName);
|
|
||||||
|
|
||||||
if (!File.Exists(logFile))
|
|
||||||
{
|
|
||||||
DialogService.InfoBarMessage(Translator.Info_LogsNotFoundTitle, Translator.Info_LogsNotFoundMessage, Core.Domain.Enums.InfoBarMessageType.Warning);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedFolderPath = await DialogService.PickWindowsFolderAsync();
|
var selectedFolderPath = await DialogService.PickWindowsFolderAsync();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(selectedFolderPath)) return;
|
if (string.IsNullOrEmpty(selectedFolderPath)) return;
|
||||||
|
|
||||||
var copiedFilePath = await _fileService.CopyFileAsync(logFile, selectedFolderPath);
|
var areLogsSaved = await _fileService.SaveLogsToFolderAsync(appDataFolder, selectedFolderPath).ConfigureAwait(false);
|
||||||
|
|
||||||
var copiedFileName = Path.GetFileName(copiedFilePath);
|
if (areLogsSaved)
|
||||||
|
{
|
||||||
DialogService.InfoBarMessage(Translator.Info_LogsSavedTitle, string.Format(Translator.Info_LogsSavedMessage, copiedFileName), Core.Domain.Enums.InfoBarMessageType.Success);
|
DialogService.InfoBarMessage(Translator.Info_LogsSavedTitle, string.Format(Translator.Info_LogsSavedMessage, Constants.LogArchiveFileName), InfoBarMessageType.Success);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DialogService.InfoBarMessage(Translator.Info_LogsNotFoundTitle, Translator.Info_LogsNotFoundMessage, InfoBarMessageType.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
private async Task Navigate(object url)
|
private async Task Navigate(object url)
|
||||||
{
|
{
|
||||||
if (url is string stringUrl)
|
if (url is string stringUrl)
|
||||||
|
|||||||
@@ -61,9 +61,9 @@
|
|||||||
</controls:SettingsCard.HeaderIcon>
|
</controls:SettingsCard.HeaderIcon>
|
||||||
<controls:SettingsCard.ActionIcon>
|
<controls:SettingsCard.ActionIcon>
|
||||||
<PathIcon
|
<PathIcon
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
||||||
</controls:SettingsCard.ActionIcon>
|
</controls:SettingsCard.ActionIcon>
|
||||||
</controls:SettingsCard>
|
</controls:SettingsCard>
|
||||||
|
|
||||||
@@ -81,9 +81,9 @@
|
|||||||
</controls:SettingsCard.HeaderIcon>
|
</controls:SettingsCard.HeaderIcon>
|
||||||
<controls:SettingsCard.ActionIcon>
|
<controls:SettingsCard.ActionIcon>
|
||||||
<PathIcon
|
<PathIcon
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
||||||
</controls:SettingsCard.ActionIcon>
|
</controls:SettingsCard.ActionIcon>
|
||||||
</controls:SettingsCard>
|
</controls:SettingsCard>
|
||||||
|
|
||||||
@@ -98,9 +98,9 @@
|
|||||||
</controls:SettingsCard.HeaderIcon>
|
</controls:SettingsCard.HeaderIcon>
|
||||||
<controls:SettingsCard.ActionIcon>
|
<controls:SettingsCard.ActionIcon>
|
||||||
<PathIcon
|
<PathIcon
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
||||||
</controls:SettingsCard.ActionIcon>
|
</controls:SettingsCard.ActionIcon>
|
||||||
</controls:SettingsCard>
|
</controls:SettingsCard>
|
||||||
|
|
||||||
@@ -118,9 +118,9 @@
|
|||||||
</controls:SettingsCard.HeaderIcon>
|
</controls:SettingsCard.HeaderIcon>
|
||||||
<controls:SettingsCard.ActionIcon>
|
<controls:SettingsCard.ActionIcon>
|
||||||
<PathIcon
|
<PathIcon
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
Data="{StaticResource OpenInNewWindowPathIcon}" />
|
||||||
</controls:SettingsCard.ActionIcon>
|
</controls:SettingsCard.ActionIcon>
|
||||||
</controls:SettingsCard>
|
</controls:SettingsCard>
|
||||||
|
|
||||||
@@ -135,17 +135,10 @@
|
|||||||
<controls:SettingsExpander.Items>
|
<controls:SettingsExpander.Items>
|
||||||
<controls:SettingsCard Header="{x:Bind domain:Translator.SettingsEnableLogs_Title}" Description="{x:Bind domain:Translator.SettingsEnableLogs_Description}">
|
<controls:SettingsCard Header="{x:Bind domain:Translator.SettingsEnableLogs_Title}" Description="{x:Bind domain:Translator.SettingsEnableLogs_Description}">
|
||||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||||
<Button Content="Share" Command="{x:Bind ViewModel.ShareWinoLogCommand}" />
|
<Button Content="{x:Bind domain:Translator.Buttons_Share}" Command="{x:Bind ViewModel.ShareWinoLogCommand}" />
|
||||||
<ToggleSwitch IsOn="{x:Bind ViewModel.PreferencesService.IsLoggingEnabled, Mode=TwoWay}" />
|
<ToggleSwitch IsOn="{x:Bind ViewModel.PreferencesService.IsLoggingEnabled, Mode=TwoWay}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</controls:SettingsCard>
|
</controls:SettingsCard>
|
||||||
|
|
||||||
<controls:SettingsCard Header="{x:Bind domain:Translator.SettingsEnableIMAPLogs_Title}" Description="{x:Bind domain:Translator.SettingsEnableIMAPLogs_Description}">
|
|
||||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
|
||||||
<Button Content="{x:Bind domain:Translator.Buttons_Share}" Command="{x:Bind ViewModel.ShareProtocolLogCommand}" />
|
|
||||||
<ToggleSwitch IsOn="{x:Bind ViewModel.PreferencesService.IsMailkitProtocolLoggerEnabled, Mode=TwoWay}" />
|
|
||||||
</StackPanel>
|
|
||||||
</controls:SettingsCard>
|
|
||||||
</controls:SettingsExpander.Items>
|
</controls:SettingsExpander.Items>
|
||||||
</controls:SettingsExpander>
|
</controls:SettingsExpander>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user