public NDisc(Converter cvt, string sourceFileName) { SourceFileName = sourceFileName; NStream = cvt.NStream; NStream.Initialize(true); _settings = new Settings(NStream.IsGameCube ? DiscType.GameCube : DiscType.Wii); Log = cvt; }
public NDisc(ILog log, Stream stream) { NStream = (stream is NStream) ? (NStream)stream : new NStream(stream); if (!(stream is NStream)) { NStream.Initialize(true); } _settings = new Settings(NStream.IsGameCube ? DiscType.GameCube : DiscType.Wii); Log = log; }
public NStream OpenNStream(bool readAsDisc) { if (!File.Exists(this.FilePath)) { throw new HandledException("SourceFile.Open - '{0}' does not exist.", (this.FilePath) ?? ""); } Stream fs = null; if (!this.IsArchive) { try { fs = this.OpenStream(); NStream nStream = new NStream(new StreamForward(fs, null)); nStream.Initialize(readAsDisc); return(nStream); } catch (Exception ex) { throw new HandledException(ex, "SourceFile.OpenNStream '{0}'", this.FilePath ?? ""); } } else { string arcType = ""; IArchive archive; if (!this.IsSplit) { try { arcType = ((this.AllFiles.Length == 0) ? "" : "multipart ") + "archive"; archive = ArchiveFactory.Open(this.FilePath); //handles multipart archives } catch (Exception ex) { throw new HandledException(ex, "SourceFile.OpenNStream ({0}) '{1}'", arcType, this.FilePath ?? ""); } } else { try { arcType = "split archive"; fs = this.OpenStream(); archive = ArchiveFactory.Open(fs); //handles multipart archives } catch (Exception ex) { throw new HandledException(ex, "SourceFile.OpenNStream ({0}) '{1}'", arcType, this.FilePath ?? ""); } } IArchiveEntry ent; string key = ""; try { //zip uses / path separator rar uses \ int pathLen = string.IsNullOrEmpty(this.Path) ? 0 : this.Path.Length + 1; ent = archive.Entries.FirstOrDefault(e => e.Key.Length == pathLen + this.Name.Length && e.Key.StartsWith(this.Path) && e.Key.EndsWith(this.Name)); if (ent == null) { throw new Exception("Open archive file entry failure"); } key = ent.Key; } catch (Exception ex) { throw new HandledException(ex, "SourceFile.OpenNStream ({0}) '{1}' failed to open entry '{2}'", arcType, this.FilePath ?? "", this.Name ?? ""); } try { if (ent != null) { NStream nStream = new NStream(new StreamForward((long)ent.Size, ent.OpenEntryStream(), archive)); nStream.Initialize(true); return(nStream); } } catch (Exception ex) { throw new HandledException(ex, "SourceFile.OpenNStream ({0}) '{1}' failed to stream entry '{2}'", arcType, this.FilePath ?? "", key ?? ""); } return(null); } }