public void ClearRip() { if (RipModel != null) { RipModel.Dispose(); RipModel = null; } Data.GuiIssues = null; IssueModel.Clear(); }
public Severity ValidateFlacRip(string arg, string signature, bool allowFileArg, bool prefixDirOnErr) { string newPath = null; string err = null; if (signature != null) { if (signature.Length == 0) { signature = null; } else if (Map1252.ToClean1252FileName(signature.Trim(null)) != signature || signature.Any(Char.IsWhiteSpace)) { ReportLine("Invalid signature '" + signature + "'.", Severity.Error, false); return(Severity.Fatal); } } try { var fInfo = new FileInfo(arg); if (fInfo.Attributes.HasFlag(FileAttributes.Directory)) { newPath = fInfo.FullName; } else if (allowFileArg) { newPath = fInfo.DirectoryName; } else { err = "Not a directory."; } } catch (ArgumentException ex) { err = ex.Message.Trim(null); } catch (DirectoryNotFoundException ex) { err = ex.Message.Trim(null); } catch (IOException ex) { err = ex.Message.Trim(null); } catch (NotSupportedException) { err = "Path is not valid."; } RipModel = new FlacRip.Model(this, newPath, Data.Autoname, signature); if (err != null) { ReportLine(err, Severity.Error, false); SetCurrentFile(null); RipModel.SetStatus(Severity.Error); return(Severity.Error); } RipModel.Bind.IsWip = true; try { RipModel.Validate(); } catch (IOException ex) { err = ex.Message.Trim(null); ReportLine(err); SetCurrentFile(null); RipModel.SetStatus(Severity.Fatal); return(Severity.Fatal); } SetCurrentFile(null); if (RipModel.Bind.Status == Severity.NoIssue && RipModel.Bind.Log == null) { if (RipModel.Bind.Signature != null) { try { var errPath = newPath + Path.DirectorySeparatorChar + Data.NoncompliantName; if (File.Exists(errPath)) { File.Delete(errPath); } } catch (Exception) { /* discard all */ } } RipModel.Bind.IsWip = false; ReportLine(RipModel.Bind.Trailer, Severity.Trivia, false); return(Severity.Trivia); } if (RipModel.Bind.Status >= Severity.Error) { RipModel.CloseFiles(); if (prefixDirOnErr) { var baseName = Path.GetFileName(newPath); if (RipModel.Bind.Signature != null && !baseName.StartsWith("!!") && newPath.Length < 235) { var parentPath = Directory.GetParent(newPath).FullName; var errPath = parentPath + Path.DirectorySeparatorChar + Data.FailPrefix + baseName; try { Directory.Move(newPath, errPath); } catch (Exception) { /* discard all */ } ++consecutiveInvalidations; } } RipModel.Bind.IsWip = false; } if (!RipModel.Bind.IsWip) { SetCurrentFile(null); ReportLine(RipModel.Bind.Trailer, RipModel.Bind.Status, false); } return(RipModel.Bind.Status); }