Skip to content

Commit

Permalink
Give error on failing to AVDump.
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Sep 21, 2017
1 parent 60605f9 commit d5e2dee
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions Shoko.Server/Utilities/AVDumpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using NLog;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
using SharpCompress.Readers;
Expand Down Expand Up @@ -97,34 +98,44 @@ public static string DumpFile(int vid)

public static string DumpFile(string file)
{
if (!File.Exists(avdumpDestination) && !GetAndExtractAVDump())
return "Could not find or download AvDump2 CLI";
if (string.IsNullOrEmpty(file))
return "File path cannot be null";
if (!File.Exists(file))
return "Could not find Video File: " + file;
try
{
if (!File.Exists(avdumpDestination) && !GetAndExtractAVDump())
return "Could not find or download AvDump2 CLI";
if (string.IsNullOrEmpty(file))
return "File path cannot be null";
if (!File.Exists(file))
return "Could not find Video File: " + file;

//Create process
Process pProcess = new Process();
pProcess.StartInfo.FileName = avdumpDestination;
//Create process
Process pProcess = new Process();
pProcess.StartInfo.FileName = avdumpDestination;

//strCommandParameters are parameters to pass to program
string fileName = (char)34 + file + (char)34;
//strCommandParameters are parameters to pass to program
string fileName = (char) 34 + file + (char) 34;

pProcess.StartInfo.Arguments =
$@" --Auth={ServerSettings.AniDB_Username}:{ServerSettings.AniDB_AVDumpKey} --LPort={ServerSettings.AniDB_AVDumpClientPort} --PrintEd2kLink -t {fileName}";
pProcess.StartInfo.Arguments =
$@" --Auth={ServerSettings.AniDB_Username}:{ServerSettings.AniDB_AVDumpKey} --LPort={
ServerSettings.AniDB_AVDumpClientPort
} --PrintEd2kLink -t {fileName}";

pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.CreateNoWindow = true;
pProcess.Start();
string strOutput = pProcess.StandardOutput.ReadToEnd();

//Wait for process to finish
pProcess.WaitForExit();
//Wait for process to finish
pProcess.WaitForExit();

return strOutput;
return strOutput;
}
catch (Exception ex)
{
LogManager.GetCurrentClassLogger().Error($"An error occurred while AVDumping the file \"file\":\n{ex}");
return $"An error occurred while AVDumping the file:\n{ex}";
}
}

public static string DumpFile_Mono(string file)
Expand Down

0 comments on commit d5e2dee

Please sign in to comment.