mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-28 17:31:56 +01:00
Improve diagnostics system
Save logs in files. Save logs from different threads in different files.
This commit is contained in:
1 parent
a6d2786749
commit
8434b00fe6
13 files changed
+345
-109
No files matched your search
@@ -13,6 +13,8 @@
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System;
|
||||
@@ -22,6 +24,7 @@ namespace FileConverter
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.ConversionJobs;
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public partial class Application : System.Windows.Application
|
||||
{
|
||||
@@ -90,36 +93,48 @@ namespace FileConverter
|
||||
private void Initialize()
|
||||
{
|
||||
// Load settigns.
|
||||
Diagnostics.Log("Retrieve arguments...");
|
||||
Debug.Log("Load settings...");
|
||||
this.Settings = new Settings();
|
||||
this.Settings.Load();
|
||||
|
||||
// Retrieve arguments.
|
||||
Diagnostics.Log("Retrieve arguments...");
|
||||
Debug.Log("Retrieve arguments...");
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
|
||||
#if (DEBUG)
|
||||
if (args.Length <= 1)
|
||||
{
|
||||
this.debugMode = true;
|
||||
System.Array.Resize(ref args, 5);
|
||||
System.Array.Resize(ref args, 8);
|
||||
args[1] = "--conversion-preset";
|
||||
args[2] = "To Mp3";
|
||||
args[2] = "To Ogg";
|
||||
args[3] = "--verbose";
|
||||
args[4] = @"D:\Test\10 - Get around town (lp version).ogg";
|
||||
|
||||
args[4] = @"D:\Test\TrailerV2 compressed.mkv";
|
||||
args[4] = @"D:\Test\image.png";
|
||||
args[4] = @"E:\Track01.cda";
|
||||
args[4] = @"D:\Test\Track01.mp3";
|
||||
args[5] = @"D:\Test\Track02.mp3";
|
||||
args[6] = @"D:\Test\Track03.mp3";
|
||||
args[7] = @"D:\Test\Track04.mp3";
|
||||
|
||||
System.Array.Resize(ref args, 2);
|
||||
args[1] = "--settings";
|
||||
//System.Array.Resize(ref args, 2);
|
||||
//args[1] = "--settings";
|
||||
|
||||
//System.Array.Resize(ref args, 4);
|
||||
//args[1] = "--conversion-preset";
|
||||
//args[2] = "To Ogg";
|
||||
//args[3] = "--verbose";
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int index = 0; index < args.Length; index++)
|
||||
{
|
||||
string argument = args[index];
|
||||
Diagnostics.Log("Arg{0}: {1}", index, argument);
|
||||
Debug.Log("Arg{0}: {1}", index, argument);
|
||||
}
|
||||
|
||||
Diagnostics.Log(string.Empty);
|
||||
Debug.Log(string.Empty);
|
||||
|
||||
ConversionPreset conversionPreset = null;
|
||||
List<string> filePaths = new List<string>();
|
||||
@@ -147,15 +162,15 @@ namespace FileConverter
|
||||
case "conversion-preset":
|
||||
if (index >= args.Length - 1)
|
||||
{
|
||||
MessageBox.Show(string.Format("Invalid format. (code 0x01)"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Debug.LogError("Invalid format. (code 0x01)");
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
return;
|
||||
}
|
||||
|
||||
conversionPreset = Settings.GetPresetFromName(args[index + 1]);
|
||||
conversionPreset = this.Settings.GetPresetFromName(args[index + 1]);
|
||||
if (conversionPreset == null)
|
||||
{
|
||||
MessageBox.Show(string.Format("Invalid conversion preset '{0}'. (code 0x02)", args[index + 1]), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Debug.LogError("Invalid conversion preset '{0}'. (code 0x02)", args[index + 1]);
|
||||
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +186,7 @@ namespace FileConverter
|
||||
break;
|
||||
|
||||
default:
|
||||
Diagnostics.Log("ERROR ! Unknown option {0}.", parameterTitle);
|
||||
Debug.LogError("Unknown option {0}.", parameterTitle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -183,23 +198,41 @@ namespace FileConverter
|
||||
|
||||
if (conversionPreset == null)
|
||||
{
|
||||
Diagnostics.Log("ERROR ! Can't retrieve the conversion preset from arguments.");
|
||||
Debug.LogError("Can't retrieve the conversion preset from arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create convertion jobs.
|
||||
for (int index = 0; index < filePaths.Count; index++)
|
||||
Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.Name);
|
||||
try
|
||||
{
|
||||
string inputFilePath = filePaths[index];
|
||||
ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset);
|
||||
conversionJob.PrepareConversion(inputFilePath);
|
||||
for (int index = 0; index < filePaths.Count; index++)
|
||||
{
|
||||
string inputFilePath = filePaths[index];
|
||||
ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath);
|
||||
conversionJob.PrepareConversion(inputFilePath);
|
||||
|
||||
this.conversionJobs.Add(conversionJob);
|
||||
this.conversionJobs.Add(conversionJob);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogError(exception.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
Debug.Log("Exit application.");
|
||||
|
||||
Debug.Release();
|
||||
}
|
||||
|
||||
private void ConvertFiles()
|
||||
{
|
||||
for (int index = 0; index < this.conversionJobs.Count; index++)
|
||||
@@ -214,15 +247,15 @@ namespace FileConverter
|
||||
|
||||
if (System.IO.File.Exists(conversionJob.OutputFilePath))
|
||||
{
|
||||
Diagnostics.Log("Success!");
|
||||
Debug.Log("Success!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Diagnostics.Log("Fail!");
|
||||
Debug.Log("Fail!");
|
||||
}
|
||||
}
|
||||
|
||||
Diagnostics.Log("End of job queue.");
|
||||
Debug.Log("End of job queue.");
|
||||
|
||||
#if !DEBUG
|
||||
bool allConversionsSucceed = true;
|
||||
@@ -233,6 +266,7 @@ namespace FileConverter
|
||||
|
||||
if (allConversionsSucceed)
|
||||
{
|
||||
Debug.Log("All conversions succeed.");
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
|
||||
if (this.cancelAutoExit)
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace FileConverter.ConversionJobs
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public class ConversionJob : INotifyPropertyChanged
|
||||
{
|
||||
private float progress = 0f;
|
||||
@@ -159,7 +161,7 @@ namespace FileConverter.ConversionJobs
|
||||
if (!PathHelpers.IsPathValid(this.OutputFilePath))
|
||||
{
|
||||
this.ConversionFailed("Invalid output path generated by output file path template.");
|
||||
Diagnostics.Log(string.Format("Invalid output path generated: {0} from input: {1}.", this.OutputFilePath, this.InputFilePath));
|
||||
Debug.Log(string.Format("Invalid output path generated: {0} from input: {1}.", this.OutputFilePath, this.InputFilePath));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,7 +195,7 @@ namespace FileConverter.ConversionJobs
|
||||
catch (Exception)
|
||||
{
|
||||
this.ConversionFailed("Invalid output path generated by output file path template.");
|
||||
Diagnostics.Log(string.Format("Can't create directories for path {0}", this.OutputFilePath));
|
||||
Debug.Log(string.Format("Can't create directories for path {0}", this.OutputFilePath));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -208,10 +210,10 @@ namespace FileConverter.ConversionJobs
|
||||
catch (Exception exception)
|
||||
{
|
||||
this.ConversionFailed("Can't generate a valid output filename.");
|
||||
Diagnostics.Log(exception.Message);
|
||||
Debug.Log(exception.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.Initialize();
|
||||
|
||||
if (this.State == ConversionState.Unknown)
|
||||
@@ -219,6 +221,8 @@ namespace FileConverter.ConversionJobs
|
||||
this.State = ConversionState.Ready;
|
||||
}
|
||||
|
||||
Debug.Log("Job initialized: Preset: '{0}' Input: {1} Output: {2}", this.ConversionPreset.Name, this.InputFilePath, this.OutputFilePath);
|
||||
|
||||
this.UserState = "In Queue";
|
||||
}
|
||||
|
||||
@@ -234,7 +238,7 @@ namespace FileConverter.ConversionJobs
|
||||
throw new Exception("Invalid conversion state.");
|
||||
}
|
||||
|
||||
Diagnostics.Log("Convert file {0} to {1}.", this.InputFilePath, this.OutputFilePath);
|
||||
Debug.Log("Convert file {0} to {1}.", this.InputFilePath, this.OutputFilePath);
|
||||
|
||||
this.State = ConversionState.InProgress;
|
||||
|
||||
@@ -256,7 +260,7 @@ namespace FileConverter.ConversionJobs
|
||||
|
||||
protected virtual void OnConversionSucceed()
|
||||
{
|
||||
Diagnostics.Log("Conversion Succeed!");
|
||||
Debug.Log("Conversion Succeed!");
|
||||
|
||||
// Apply the input post conversion action.
|
||||
switch (this.InputPostConversionAction)
|
||||
@@ -275,21 +279,21 @@ namespace FileConverter.ConversionJobs
|
||||
|
||||
string newPath = PathHelpers.GenerateUniquePath(archivePath + "\\" + inputFilename);
|
||||
System.IO.File.Move(this.InputFilePath, newPath);
|
||||
Diagnostics.Log("Input file moved in archive folder: '{0}'", newPath);
|
||||
Debug.Log("Input file moved in archive folder: '{0}'", newPath);
|
||||
break;
|
||||
|
||||
case InputPostConversionAction.Delete:
|
||||
System.IO.File.Delete(this.InputFilePath);
|
||||
Diagnostics.Log("Input file deleted: '{0}'", this.initialInputPath);
|
||||
Debug.Log("Input file deleted: '{0}'", this.initialInputPath);
|
||||
break;
|
||||
}
|
||||
|
||||
Diagnostics.Log(string.Empty);
|
||||
Debug.Log(string.Empty);
|
||||
|
||||
this.Progress = 1f;
|
||||
this.State = ConversionState.Done;
|
||||
this.UserState = "Done";
|
||||
Diagnostics.Log("Conversion Done!");
|
||||
Debug.Log("Conversion Done!");
|
||||
}
|
||||
|
||||
protected void ConversionFailed(string exitingMessage)
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace FileConverter.ConversionJobs
|
||||
using WaveLib;
|
||||
using Yeti.MMedia;
|
||||
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public class ConversionJob_ExtractCDA : ConversionJob
|
||||
{
|
||||
private Ripper.CDDrive cdDrive;
|
||||
@@ -112,7 +114,7 @@ namespace FileConverter.ConversionJobs
|
||||
throw new Exception("The conversion preset must be valid.");
|
||||
}
|
||||
|
||||
Diagnostics.Log("Starting CDA extraction.");
|
||||
Debug.Log("Starting CDA extraction.");
|
||||
|
||||
this.UserState = "Extraction";
|
||||
|
||||
@@ -154,9 +156,9 @@ namespace FileConverter.ConversionJobs
|
||||
return;
|
||||
}
|
||||
|
||||
Diagnostics.Log("CDA extracted to {0}.", this.intermediateFilePath);
|
||||
Diagnostics.Log(string.Empty);
|
||||
Diagnostics.Log("Start compression.");
|
||||
Debug.Log("CDA extracted to {0}.", this.intermediateFilePath);
|
||||
Debug.Log(string.Empty);
|
||||
Debug.Log("Start compression.");
|
||||
|
||||
this.UserState = "Conversion";
|
||||
|
||||
@@ -174,8 +176,8 @@ namespace FileConverter.ConversionJobs
|
||||
return;
|
||||
}
|
||||
|
||||
Diagnostics.Log(string.Empty);
|
||||
Diagnostics.Log("Delete intermediate file {0}.", this.intermediateFilePath);
|
||||
Debug.Log(string.Empty);
|
||||
Debug.Log("Delete intermediate file {0}.", this.intermediateFilePath);
|
||||
|
||||
File.Delete(this.intermediateFilePath);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace FileConverter.ConversionJobs
|
||||
return -2;
|
||||
}
|
||||
|
||||
throw new Exception("Unknown VBR bitrate.");
|
||||
throw new Exception("Unknown Ogg VBR bitrate.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace FileConverter.ConversionJobs
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public partial class ConversionJob_FFMPEG : ConversionJob
|
||||
{
|
||||
private readonly Regex durationRegex = new Regex(@"Duration:\s*([0-9][0-9]):([0-9][0-9]):([0-9][0-9])\.([0-9][0-9]),.*bitrate:\s*([0-9]+) kb\/s");
|
||||
@@ -41,7 +43,7 @@ namespace FileConverter.ConversionJobs
|
||||
if (!System.IO.File.Exists(ffmpegPath))
|
||||
{
|
||||
this.ConversionFailed("Can't find ffmpeg executable. You should try to reinstall the application.");
|
||||
Diagnostics.Log("Can't find ffmpeg executable ({0}). Try to reinstall the application.", ffmpegPath);
|
||||
Diagnostics.Debug.Log("Can't find ffmpeg executable ({0}). Try to reinstall the application.", ffmpegPath);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,8 +168,8 @@ namespace FileConverter.ConversionJobs
|
||||
|
||||
this.UserState = "Conversion";
|
||||
|
||||
Diagnostics.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments);
|
||||
Diagnostics.Log(string.Empty);
|
||||
Diagnostics.Debug.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments);
|
||||
Diagnostics.Debug.Log(string.Empty);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -181,7 +183,7 @@ namespace FileConverter.ConversionJobs
|
||||
|
||||
this.ParseFFMPEGOutput(result);
|
||||
|
||||
Diagnostics.Log("ffmpeg output: {0}", result);
|
||||
Diagnostics.Debug.Log("ffmpeg output: {0}", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// <copyright file="Diagnostics.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
public static class Diagnostics
|
||||
{
|
||||
private static List<string> logMessages = new List<string>();
|
||||
private static StringBuilder workingStringBuilder = new StringBuilder();
|
||||
|
||||
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
|
||||
|
||||
public static string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
workingStringBuilder.Clear();
|
||||
for (int index = 0; index < logMessages.Count; index++)
|
||||
{
|
||||
workingStringBuilder.AppendLine(logMessages[index]);
|
||||
}
|
||||
|
||||
return workingStringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string message, params object[] arguments)
|
||||
{
|
||||
Diagnostics.logMessages.Add(string.Format(message, arguments));
|
||||
|
||||
if (StaticPropertyChanged != null)
|
||||
{
|
||||
StaticPropertyChanged(null, new PropertyChangedEventArgs("Content"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// <copyright file="Diagnostics.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter.Diagnostics
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
public static class Debug
|
||||
{
|
||||
private static StringBuilder workingStringBuilder = new StringBuilder();
|
||||
private static string diagnosticsFolderPath;
|
||||
private static Dictionary<int, DiagnosticsData> diagnosticsDataById = new Dictionary<int, DiagnosticsData>();
|
||||
private static int threadCount = 0;
|
||||
|
||||
public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
|
||||
|
||||
static Debug()
|
||||
{
|
||||
string path = PathHelpers.GetUserDataFolderPath();
|
||||
|
||||
// Delete old diagnostics folder.
|
||||
DateTime expirationDate = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
|
||||
string[] diagnosticsDirectories = Directory.GetDirectories(path, "Diagnostics.*");
|
||||
for (int index = 0; index < diagnosticsDirectories.Length; index++)
|
||||
{
|
||||
string directory = diagnosticsDirectories[index];
|
||||
DateTime creationTime = Directory.GetCreationTime(directory);
|
||||
if (creationTime < expirationDate)
|
||||
{
|
||||
Directory.Delete(directory, true);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.diagnosticsFolderPath = Path.Combine(path, "Diagnostics." + Process.GetCurrentProcess().Id);
|
||||
Debug.diagnosticsFolderPath = PathHelpers.GenerateUniquePath(Debug.diagnosticsFolderPath);
|
||||
Directory.CreateDirectory(Debug.diagnosticsFolderPath);
|
||||
}
|
||||
|
||||
public static IEnumerable<DiagnosticsData> Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return Debug.diagnosticsDataById.Values;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
DiagnosticsData diagnosticsData;
|
||||
int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
|
||||
if (!Debug.diagnosticsDataById.TryGetValue(threadId, out diagnosticsData))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
workingStringBuilder.Clear();
|
||||
foreach (string logMessage in diagnosticsData.LogMessages)
|
||||
{
|
||||
workingStringBuilder.AppendLine(logMessage);
|
||||
}
|
||||
|
||||
return workingStringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Log(string message, params object[] arguments)
|
||||
{
|
||||
DiagnosticsData diagnosticsData;
|
||||
|
||||
int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
|
||||
lock (Debug.diagnosticsDataById)
|
||||
{
|
||||
if (!Debug.diagnosticsDataById.TryGetValue(threadId, out diagnosticsData))
|
||||
{
|
||||
diagnosticsData = new DiagnosticsData(Debug.threadCount > 0 ? string.Format("Thread {0}", Debug.threadCount) : "Application");
|
||||
diagnosticsData.Initialize(Debug.diagnosticsFolderPath, threadId);
|
||||
Debug.diagnosticsDataById.Add(threadId, diagnosticsData);
|
||||
Debug.threadCount++;
|
||||
}
|
||||
}
|
||||
|
||||
diagnosticsData.Log(message, arguments);
|
||||
|
||||
if (StaticPropertyChanged != null)
|
||||
{
|
||||
StaticPropertyChanged(null, new PropertyChangedEventArgs("Content"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void LogError(string message, params object[] arguments)
|
||||
{
|
||||
string log = string.Format(message, arguments);
|
||||
|
||||
MessageBox.Show(log, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
Debug.Log("Error: " + message, arguments);
|
||||
}
|
||||
|
||||
public static void Release()
|
||||
{
|
||||
Debug.Log("Diagnostics manager released correctly.");
|
||||
|
||||
foreach (KeyValuePair<int, DiagnosticsData> kvp in Debug.diagnosticsDataById)
|
||||
{
|
||||
kvp.Value.Release();
|
||||
}
|
||||
|
||||
Debug.diagnosticsDataById.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// <copyright file="DiagnosticsData.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace FileConverter.Diagnostics
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
|
||||
public class DiagnosticsData : INotifyPropertyChanged
|
||||
{
|
||||
private List<string> logMessages = new List<string>();
|
||||
private StringBuilder stringBuilder = new StringBuilder();
|
||||
private System.IO.TextWriter logFileWriter;
|
||||
private string name;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public DiagnosticsData(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
this.LogMessages = new ReadOnlyCollection<string>(this.logMessages);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
this.name = value;
|
||||
this.OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Content
|
||||
{
|
||||
get
|
||||
{
|
||||
this.stringBuilder.Clear();
|
||||
foreach (string logMessage in this.LogMessages)
|
||||
{
|
||||
this.stringBuilder.AppendLine(logMessage);
|
||||
}
|
||||
|
||||
return this.stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<string> LogMessages
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public void Initialize(string diagnosticsFolderPath, int id)
|
||||
{
|
||||
string path = Path.Combine(diagnosticsFolderPath, string.Format("Diagnostics{0}.log", id));
|
||||
path = PathHelpers.GenerateUniquePath(path);
|
||||
this.logFileWriter = new StreamWriter(File.Open(path, FileMode.Create));
|
||||
|
||||
this.Log("{0} {1}\n", System.DateTime.Now.ToLongDateString(), System.DateTime.Now.ToLongTimeString());
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
this.logFileWriter.Close();
|
||||
this.logFileWriter = null;
|
||||
}
|
||||
|
||||
public void Log(string message, params object[] arguments)
|
||||
{
|
||||
string log = string.Format(message, arguments);
|
||||
|
||||
this.logMessages.Add(log);
|
||||
this.logFileWriter.WriteLine(log);
|
||||
this.logFileWriter.Flush();
|
||||
|
||||
this.OnPropertyChanged("Content");
|
||||
}
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChangedEventHandler handler = this.PropertyChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettings.cs" />
|
||||
<Compile Include="Diagnostics\DiagnosticsData.cs" />
|
||||
<Compile Include="EncodingMode.cs" />
|
||||
<Compile Include="ConversionPreset\IConversionSettings.cs" />
|
||||
<Compile Include="InputPostConversionAction.cs" />
|
||||
@@ -143,7 +144,7 @@
|
||||
</Compile>
|
||||
<Compile Include="ValueConverters\ConversionStateToBrush.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob.cs" />
|
||||
<Compile Include="Diagnostics.cs" />
|
||||
<Compile Include="Diagnostics\Debug.cs" />
|
||||
<Compile Include="Windows\MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
|
||||
@@ -135,6 +135,19 @@ namespace FileConverter
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetUserDataFolderPath()
|
||||
{
|
||||
string path = System.Environment.GetEnvironmentVariable("LocalAppData");
|
||||
path = System.IO.Path.Combine(path, "FileConverter");
|
||||
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static class InputCategoryNames
|
||||
{
|
||||
public const string Audio = "Audio";
|
||||
|
||||
@@ -14,9 +14,11 @@ namespace FileConverter
|
||||
using System.Security.Principal;
|
||||
using System.Windows;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using Microsoft.Win32;
|
||||
|
||||
using FileConverter.Annotations;
|
||||
using FileConverter.Diagnostics;
|
||||
|
||||
public class Settings : INotifyPropertyChanged, IDataErrorInfo
|
||||
{
|
||||
private const char PresetSeparator = ';';
|
||||
@@ -122,7 +124,7 @@ namespace FileConverter
|
||||
}
|
||||
else
|
||||
{
|
||||
Diagnostics.Log("Default settings not found. You should try to reinstall the application.");
|
||||
Diagnostics.Debug.Log("Default settings not found. You should try to reinstall the application.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +222,7 @@ namespace FileConverter
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Diagnostics.Log(exception.Message);
|
||||
Diagnostics.Debug.Log(exception.Message);
|
||||
}
|
||||
|
||||
if (subKey == null)
|
||||
@@ -273,28 +275,14 @@ namespace FileConverter
|
||||
|
||||
private static string GetUserSettingsFilePath()
|
||||
{
|
||||
string path = Environment.GetEnvironmentVariable("LocalAppData");
|
||||
path = Path.Combine(path, "FileConverter");
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
string path = PathHelpers.GetUserDataFolderPath();
|
||||
path = Path.Combine(path, "Settings.user.xml");
|
||||
return path;
|
||||
}
|
||||
|
||||
private static string GetUserSettingsTemporaryFilePath()
|
||||
{
|
||||
string path = Environment.GetEnvironmentVariable("LocalAppData");
|
||||
path = Path.Combine(path, "FileConverter");
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
string path = PathHelpers.GetUserDataFolderPath();
|
||||
path = Path.Combine(path, "Settings.temp.xml");
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:FileConverter.Windows"
|
||||
xmlns:fileConverter="clr-namespace:FileConverter"
|
||||
xmlns:diagnostics="clr-namespace:FileConverter.Diagnostics"
|
||||
mc:Ignorable="d"
|
||||
Title="Diagnostics" Height="600" Width="800" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
|
||||
<Grid>
|
||||
@@ -13,8 +14,20 @@
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Content="Logs" VerticalAlignment="Top" Height="30" FontSize="16" FontWeight="Bold" />
|
||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
|
||||
<TextBlock Name="Diagnostics" TextWrapping="NoWrap" Text="{Binding Path=(fileConverter:Diagnostics.Content), Mode=OneWay}" FontFamily="Consolas" Foreground="#FF272727"/>
|
||||
</ScrollViewer>
|
||||
|
||||
<TabControl Grid.Row="1" Margin="5" ItemsSource="{Binding Path=(diagnostics:Debug.Data), Mode=OneWay}">
|
||||
<TabControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
</DataTemplate>
|
||||
</TabControl.ItemTemplate>
|
||||
<TabControl.ContentTemplate>
|
||||
<DataTemplate>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
|
||||
<TextBlock Name="Diagnostics" TextWrapping="NoWrap" Text="{Binding Content}" FontFamily="Consolas" Foreground="#FF272727" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"/>
|
||||
</ScrollViewer>
|
||||
</DataTemplate>
|
||||
</TabControl.ContentTemplate>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -52,7 +52,7 @@ namespace FileConverter
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message);
|
||||
Diagnostics.Debug.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace FileConverter
|
||||
}
|
||||
catch (System.Exception exception)
|
||||
{
|
||||
Diagnostics.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message);
|
||||
Diagnostics.Debug.Log("The database of type '" + typeof(T) + "' failed to load the asset. The following exception was raised:\n " + exception.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user