Extract audio and cue sheet from an NRG audio CD image.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.4 KiB

  1. // This file is part of the NRGrip project.
  2. //
  3. // Copyright (c) 2016 Matteo Cypriani <mcy@lm7.fr>
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //! Error type for NRGrip.
  23. use std::error::Error;
  24. use std::ffi;
  25. use std::fmt;
  26. use std::io;
  27. #[derive(Debug)]
  28. pub enum NrgError {
  29. Io(io::Error),
  30. String(ffi::IntoStringError),
  31. NrgFormat(String),
  32. NrgChunkId(String),
  33. NoNrgCue,
  34. FileName(String),
  35. AudioReadError,
  36. AudioWriteError,
  37. }
  38. impl fmt::Display for NrgError {
  39. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  40. match *self {
  41. NrgError::Io(ref err) => err.fmt(f),
  42. NrgError::String(ref err) => err.fmt(f),
  43. NrgError::NrgFormat(ref err) =>
  44. write!(f, "NRG format error: {}", err),
  45. NrgError::NrgChunkId(ref err) =>
  46. write!(f, "NRG chunk ID unknown: {}", err),
  47. NrgError::NoNrgCue => write!(f, "NRG cue sheet chunk absent"),
  48. NrgError::FileName(ref err) =>
  49. write!(f, "Invalid file name: {}", err),
  50. NrgError::AudioReadError => write!(f, "Error reading raw audio"),
  51. NrgError::AudioWriteError => write!(f, "Error writing raw audio"),
  52. }
  53. }
  54. }
  55. impl Error for NrgError {
  56. fn description(&self) -> &str {
  57. match *self {
  58. NrgError::Io(ref err) => err.description(),
  59. NrgError::String(ref err) => err.description(),
  60. NrgError::NrgFormat(_) => "NRG format",
  61. NrgError::NrgChunkId(_) => "NRG chunk ID",
  62. NrgError::NoNrgCue => "No NRG cue",
  63. NrgError::FileName(_) => "File name",
  64. NrgError::AudioReadError => "Audio read error",
  65. NrgError::AudioWriteError => "Audio write error",
  66. }
  67. }
  68. fn cause(&self) -> Option<&Error> {
  69. match *self {
  70. NrgError::Io(ref err) => Some(err),
  71. NrgError::String(ref err) => Some(err),
  72. NrgError::NrgFormat(_) => None,
  73. NrgError::NrgChunkId(_) => None,
  74. NrgError::NoNrgCue => None,
  75. NrgError::FileName(_) => None,
  76. NrgError::AudioReadError => None,
  77. NrgError::AudioWriteError => None,
  78. }
  79. }
  80. }
  81. impl From<io::Error> for NrgError {
  82. fn from(err: io::Error) -> NrgError {
  83. NrgError::Io(err)
  84. }
  85. }
  86. impl From<ffi::IntoStringError> for NrgError {
  87. fn from(err: ffi::IntoStringError) -> NrgError {
  88. NrgError::String(err)
  89. }
  90. }