mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-24 01:00:27 +12:00
fixed #4231: Added "DisableLogging" registry setting
This commit is contained in:
parent
ce9d3dff76
commit
0e506e7877
|
@ -53,6 +53,8 @@ private DebugForm(Logger logger)
|
|||
rtbDebug.ScrollToCaret();
|
||||
rtbDebug.AddContextMenu();
|
||||
|
||||
btnOpenLogFile.Enabled = !string.IsNullOrEmpty(Logger.LogFilePath);
|
||||
|
||||
ShareXResources.ApplyTheme(this);
|
||||
|
||||
string startupPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
|
|
@ -32,20 +32,20 @@ namespace ShareX.HelpersLib
|
|||
public partial class ErrorForm : Form
|
||||
{
|
||||
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 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();
|
||||
ShareXResources.ApplyTheme(this);
|
||||
|
||||
IsUnhandledException = unhandledException;
|
||||
LogPath = logPath;
|
||||
LogFilePath = logFilePath;
|
||||
BugReportPath = bugReportPath;
|
||||
|
||||
if (IsUnhandledException)
|
||||
|
@ -58,7 +58,7 @@ public ErrorForm(string errorTitle, string errorMessage, string logPath, string
|
|||
txtException.SelectionStart = txtException.TextLength;
|
||||
|
||||
btnSendBugReport.Visible = !string.IsNullOrEmpty(BugReportPath);
|
||||
btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogPath) && File.Exists(LogPath);
|
||||
btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogFilePath) && File.Exists(LogFilePath);
|
||||
btnContinue.Visible = IsUnhandledException;
|
||||
btnClose.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)
|
||||
{
|
||||
FileHelpers.OpenFile(LogPath);
|
||||
FileHelpers.OpenFile(LogFilePath);
|
||||
}
|
||||
|
||||
private void btnContinue_Click(object sender, EventArgs e)
|
||||
|
|
|
@ -55,9 +55,12 @@ public Logger()
|
|||
|
||||
public Logger(string logFilePath)
|
||||
{
|
||||
FileWrite = true;
|
||||
LogFilePath = logFilePath;
|
||||
FileHelpers.CreateDirectoryFromFilePath(LogFilePath);
|
||||
if (!string.IsNullOrEmpty(logFilePath))
|
||||
{
|
||||
FileWrite = true;
|
||||
LogFilePath = logFilePath;
|
||||
FileHelpers.CreateDirectoryFromFilePath(LogFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnMessageAdded(string message)
|
||||
|
|
|
@ -74,16 +74,19 @@ public static void CleanupAsync()
|
|||
|
||||
private static void CleanupFolder(string folderPath, string fileNamePattern, int keepFileCount)
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
|
||||
|
||||
IEnumerable<FileInfo> files = directoryInfo.GetFiles(fileNamePattern).
|
||||
OrderByDescending(f => f.LastWriteTime.Year <= 1601 ? f.CreationTime : f.LastWriteTime).Skip(keepFileCount);
|
||||
|
||||
foreach (FileInfo file in files)
|
||||
if (Directory.Exists(folderPath))
|
||||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -209,13 +209,16 @@ public static string LogsFilePath
|
|||
{
|
||||
get
|
||||
{
|
||||
if (SystemOptions.DisableLogging)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string fileName = string.Format("ShareX-Log-{0:yyyy-MM}.txt", DateTime.Now);
|
||||
return Path.Combine(LogsFolder, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public static string RequestLogsFilePath => Path.Combine(LogsFolder, "ShareX-Request-Logs.txt");
|
||||
|
||||
public static string ScreenshotsParentFolder
|
||||
{
|
||||
get
|
||||
|
@ -510,7 +513,6 @@ private static void CreateParentFolders()
|
|||
{
|
||||
FileHelpers.CreateDirectory(SettingManager.BackupFolder);
|
||||
FileHelpers.CreateDirectory(ImageEffectsFolder);
|
||||
FileHelpers.CreateDirectory(LogsFolder);
|
||||
FileHelpers.CreateDirectory(ScreenshotsParentFolder);
|
||||
FileHelpers.CreateDirectory(ToolsFolder);
|
||||
}
|
||||
|
@ -685,6 +687,7 @@ private static void DebugWriteFlags()
|
|||
if (IgnoreHotkeyWarning) flags.Add(nameof(IgnoreHotkeyWarning));
|
||||
if (SystemOptions.DisableUpdateCheck) flags.Add(nameof(SystemOptions.DisableUpdateCheck));
|
||||
if (SystemOptions.DisableUpload) flags.Add(nameof(SystemOptions.DisableUpload));
|
||||
if (SystemOptions.DisableLogging) flags.Add(nameof(SystemOptions.DisableLogging));
|
||||
if (PuushMode) flags.Add(nameof(PuushMode));
|
||||
|
||||
string output = string.Join(", ", flags);
|
||||
|
|
|
@ -35,12 +35,14 @@ public static class SystemOptions
|
|||
|
||||
public static bool DisableUpdateCheck { 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 void UpdateSystemOptions()
|
||||
{
|
||||
DisableUpdateCheck = GetSystemOptionBoolean("DisableUpdateCheck");
|
||||
DisableUpload = GetSystemOptionBoolean("DisableUpload");
|
||||
DisableLogging = GetSystemOptionBoolean("DisableLogging");
|
||||
PersonalPath = GetSystemOptionString("PersonalPath");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue