/// <summary> /// Opens the file stream for the specified KIFINT archive and closes the existing stream if there is one. /// <para/> /// This method does not reopen the stream if the specified KIFINT archive is the currenly open archive. /// </summary> /// <param name="kifint">The KIFINT archive information to open the stream for.</param> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifint"/> is null. /// </exception> public void Open(KifintArchiveInfo kifint) { if (IsKifintOpen(kifint)) { return; // We're already open. } Close(); Stream = File.OpenRead(kifint.FilePath); Kifint = kifint; }
/// <summary> /// Checks to make sure a stream is open, not disposed of, and leads to the KIFINT archive's file path. /// </summary> /// <param name="kifint">The KIFINT archive information to check the stream for.</param> /// <returns>True if the stream is open, not closed, and targets <paramref name="kifint"/>'s file.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="kifint"/> is null. /// </exception> public bool IsKifintOpen(KifintArchiveInfo kifint) { if (kifint == null) { throw new ArgumentNullException(nameof(kifint)); } // Make sure we have the same file stream open and it's not disposed of. // CanRead is used to determine if the stream has been disposed of. string fullPath = Path.GetFullPath(kifint.FilePath); return(Stream != null && Stream.CanRead && string.Compare(Stream.Name, fullPath, true) == 0); }