fixed #4231: Added "DisableLogging" registry setting

This commit is contained in:
Jaex 2023-01-05 15:31:08 +03:00
parent ce9d3dff76
commit 0e506e7877
6 changed files with 33 additions and 20 deletions

View file

@ -53,6 +53,8 @@ private DebugForm(Logger logger)
rtbDebug.ScrollToCaret(); rtbDebug.ScrollToCaret();
rtbDebug.AddContextMenu(); rtbDebug.AddContextMenu();
btnOpenLogFile.Enabled = !string.IsNullOrEmpty(Logger.LogFilePath);
ShareXResources.ApplyTheme(this); ShareXResources.ApplyTheme(this);
string startupPath = AppDomain.CurrentDomain.BaseDirectory; string startupPath = AppDomain.CurrentDomain.BaseDirectory;

View file

@ -32,20 +32,20 @@ namespace ShareX.HelpersLib
public partial class ErrorForm : Form public partial class ErrorForm : Form
{ {
public bool IsUnhandledException { get; private set; } public bool IsUnhandledException { get; private set; }
public string LogPath { get; private set; } public string LogFilePath { get; private set; }
public string BugReportPath { get; private set; } public string BugReportPath { get; private set; }
public ErrorForm(Exception error, string logPath, string bugReportPath) : this(error.Message, error.ToString(), logPath, bugReportPath) public ErrorForm(Exception error, string logFilePath, string bugReportPath) : this(error.Message, error.ToString(), logFilePath, bugReportPath)
{ {
} }
public ErrorForm(string errorTitle, string errorMessage, string logPath, string bugReportPath, bool unhandledException = true) public ErrorForm(string errorTitle, string errorMessage, string logFilePath, string bugReportPath, bool unhandledException = true)
{ {
InitializeComponent(); InitializeComponent();
ShareXResources.ApplyTheme(this); ShareXResources.ApplyTheme(this);
IsUnhandledException = unhandledException; IsUnhandledException = unhandledException;
LogPath = logPath; LogFilePath = logFilePath;
BugReportPath = bugReportPath; BugReportPath = bugReportPath;
if (IsUnhandledException) if (IsUnhandledException)
@ -58,7 +58,7 @@ public ErrorForm(string errorTitle, string errorMessage, string logPath, string
txtException.SelectionStart = txtException.TextLength; txtException.SelectionStart = txtException.TextLength;
btnSendBugReport.Visible = !string.IsNullOrEmpty(BugReportPath); btnSendBugReport.Visible = !string.IsNullOrEmpty(BugReportPath);
btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogPath) && File.Exists(LogPath); btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogFilePath) && File.Exists(LogFilePath);
btnContinue.Visible = IsUnhandledException; btnContinue.Visible = IsUnhandledException;
btnClose.Visible = IsUnhandledException; btnClose.Visible = IsUnhandledException;
btnOK.Visible = !IsUnhandledException; btnOK.Visible = !IsUnhandledException;
@ -76,7 +76,7 @@ private void btnSendBugReport_Click(object sender, EventArgs e)
private void btnOpenLogFile_Click(object sender, EventArgs e) private void btnOpenLogFile_Click(object sender, EventArgs e)
{ {
FileHelpers.OpenFile(LogPath); FileHelpers.OpenFile(LogFilePath);
} }
private void btnContinue_Click(object sender, EventArgs e) private void btnContinue_Click(object sender, EventArgs e)

View file

@ -55,9 +55,12 @@ public Logger()
public Logger(string logFilePath) public Logger(string logFilePath)
{ {
FileWrite = true; if (!string.IsNullOrEmpty(logFilePath))
LogFilePath = logFilePath; {
FileHelpers.CreateDirectoryFromFilePath(LogFilePath); FileWrite = true;
LogFilePath = logFilePath;
FileHelpers.CreateDirectoryFromFilePath(LogFilePath);
}
} }
protected void OnMessageAdded(string message) protected void OnMessageAdded(string message)

View file

@ -74,16 +74,19 @@ public static void CleanupAsync()
private static void CleanupFolder(string folderPath, string fileNamePattern, int keepFileCount) private static void CleanupFolder(string folderPath, string fileNamePattern, int keepFileCount)
{ {
DirectoryInfo directoryInfo = new DirectoryInfo(folderPath); if (Directory.Exists(folderPath))
IEnumerable<FileInfo> files = directoryInfo.GetFiles(fileNamePattern).
OrderByDescending(f => f.LastWriteTime.Year <= 1601 ? f.CreationTime : f.LastWriteTime).Skip(keepFileCount);
foreach (FileInfo file in files)
{ {
file.Delete(); DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
DebugHelper.WriteLine($"File deleted: {file.FullName}"); IEnumerable<FileInfo> files = directoryInfo.GetFiles(fileNamePattern).
OrderByDescending(f => f.LastWriteTime.Year <= 1601 ? f.CreationTime : f.LastWriteTime).Skip(keepFileCount);
foreach (FileInfo file in files)
{
file.Delete();
DebugHelper.WriteLine($"File deleted: {file.FullName}");
}
} }
} }

View file

@ -209,13 +209,16 @@ public static string LogsFilePath
{ {
get get
{ {
if (SystemOptions.DisableLogging)
{
return null;
}
string fileName = string.Format("ShareX-Log-{0:yyyy-MM}.txt", DateTime.Now); string fileName = string.Format("ShareX-Log-{0:yyyy-MM}.txt", DateTime.Now);
return Path.Combine(LogsFolder, fileName); return Path.Combine(LogsFolder, fileName);
} }
} }
public static string RequestLogsFilePath => Path.Combine(LogsFolder, "ShareX-Request-Logs.txt");
public static string ScreenshotsParentFolder public static string ScreenshotsParentFolder
{ {
get get
@ -510,7 +513,6 @@ private static void CreateParentFolders()
{ {
FileHelpers.CreateDirectory(SettingManager.BackupFolder); FileHelpers.CreateDirectory(SettingManager.BackupFolder);
FileHelpers.CreateDirectory(ImageEffectsFolder); FileHelpers.CreateDirectory(ImageEffectsFolder);
FileHelpers.CreateDirectory(LogsFolder);
FileHelpers.CreateDirectory(ScreenshotsParentFolder); FileHelpers.CreateDirectory(ScreenshotsParentFolder);
FileHelpers.CreateDirectory(ToolsFolder); FileHelpers.CreateDirectory(ToolsFolder);
} }
@ -685,6 +687,7 @@ private static void DebugWriteFlags()
if (IgnoreHotkeyWarning) flags.Add(nameof(IgnoreHotkeyWarning)); if (IgnoreHotkeyWarning) flags.Add(nameof(IgnoreHotkeyWarning));
if (SystemOptions.DisableUpdateCheck) flags.Add(nameof(SystemOptions.DisableUpdateCheck)); if (SystemOptions.DisableUpdateCheck) flags.Add(nameof(SystemOptions.DisableUpdateCheck));
if (SystemOptions.DisableUpload) flags.Add(nameof(SystemOptions.DisableUpload)); if (SystemOptions.DisableUpload) flags.Add(nameof(SystemOptions.DisableUpload));
if (SystemOptions.DisableLogging) flags.Add(nameof(SystemOptions.DisableLogging));
if (PuushMode) flags.Add(nameof(PuushMode)); if (PuushMode) flags.Add(nameof(PuushMode));
string output = string.Join(", ", flags); string output = string.Join(", ", flags);

View file

@ -35,12 +35,14 @@ public static class SystemOptions
public static bool DisableUpdateCheck { get; private set; } public static bool DisableUpdateCheck { get; private set; }
public static bool DisableUpload { get; private set; } public static bool DisableUpload { get; private set; }
public static bool DisableLogging { get; private set; }
public static string PersonalPath { get; private set; } public static string PersonalPath { get; private set; }
public static void UpdateSystemOptions() public static void UpdateSystemOptions()
{ {
DisableUpdateCheck = GetSystemOptionBoolean("DisableUpdateCheck"); DisableUpdateCheck = GetSystemOptionBoolean("DisableUpdateCheck");
DisableUpload = GetSystemOptionBoolean("DisableUpload"); DisableUpload = GetSystemOptionBoolean("DisableUpload");
DisableLogging = GetSystemOptionBoolean("DisableLogging");
PersonalPath = GetSystemOptionString("PersonalPath"); PersonalPath = GetSystemOptionString("PersonalPath");
} }