Skip to content

Commit

Permalink
Update renamer to refer to a more accurate filename reference and fai…
Browse files Browse the repository at this point in the history
…l on no extension.

This should mitigate #529 happening.
Also remove a redundant catch as all it did was re-throw the exeption
  • Loading branch information
Cazzar committed Feb 6, 2017
1 parent 3a773a0 commit bcce5b9
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions JMMServer/Utilities/RenameFileHelper.cs
Expand Up @@ -1770,40 +1770,35 @@ public static string GetNewFileName(VideoLocal vid, string script)
}
else
{
try
if (EvaluateTest(thisLine, vid, aniFile, episodes, anime))
{
if (EvaluateTest(thisLine, vid, aniFile, episodes, anime))
{
Debug.WriteLine(string.Format("Line passed: {0}", thisLine));
// if the line has passed the tests, then perform the action
Debug.WriteLine(string.Format("Line passed: {0}", thisLine));
// if the line has passed the tests, then perform the action

string action = GetAction(thisLine);
string action = GetAction(thisLine);

// if the action is fail, we don't want to rename
if (action.ToUpper()
.Trim()
.Equals(Constants.FileRenameReserved.Fail, StringComparison.InvariantCultureIgnoreCase))
return string.Empty;
// if the action is fail, we don't want to rename
if (action.ToUpper()
.Trim()
.Equals(Constants.FileRenameReserved.Fail, StringComparison.InvariantCultureIgnoreCase))
return string.Empty;

PerformActionOnFileName(ref newFileName, action, vid, aniFile, episodes, anime);
}
else
{
Debug.WriteLine(string.Format("Line failed: {0}", thisLine));
}
PerformActionOnFileName(ref newFileName, action, vid, aniFile, episodes, anime);
}
catch (Exception ex)
else
{
throw;
Debug.WriteLine(string.Format("Line failed: {0}", thisLine));
}
}
}

if (string.IsNullOrEmpty(newFileName)) return string.Empty;

// finally add back the extension
string ext = Path.GetExtension(vid.GetBestVideoLocalPlace()?.FilePath ?? vid.FileName); //Prefer VideoLocal_Place as this is more accurate.
if (string.IsNullOrEmpty(ext)) return string.Empty; // fail if we get a blank extension, something went wrong.

return string.Format("{0}{1}", newFileName.Replace("`", "'"), Path.GetExtension(vid.FileName));
// finally add back the extension
return $"{newFileName.Replace("`", "'")}{ext}";
}

private static void PerformActionOnFileName(ref string newFileName, string action, VideoLocal vid,
Expand Down

0 comments on commit bcce5b9

Please sign in to comment.