Click here to Skip to main content
15,896,063 members
Articles / Programming Languages / C#

SCSI Library in C# - Burn CDs and DVDs, Access Hard Disks, etc.

Rate me:
Please Sign up or sign in to vote.
4.77/5 (48 votes)
19 Jun 2017Ms-PL6 min read 146.3K   8.1K   146  
Ever wonder how programs like Nero work? They make their own SCSI libraries... like this!
using System;
using System.Collections.Generic;
using Helper;
using System.Diagnostics;

namespace FileSystems.Iso9660
{
	internal static class IsoHelper
	{
		public static uint FromBothByteOrder(ulong value)
		{
			var lower = unchecked((uint)value);
			var upper = unchecked((uint)(value >> 32));
			if (System.BitConverter.IsLittleEndian) { upper = Bits.ReverseBytes(upper); }
			else { lower = Bits.ReverseBytes(lower); }
			if (lower != upper) { throw new ArgumentException("Value is invalid.", "value"); }
			return upper;
		}

		public static ulong ToBothByteOrder(uint value) { return (ulong)value | Bits.ReverseBytes((ulong)value); }

		public static ushort FromBothByteOrder(uint value)
		{
			var lower = unchecked((ushort)value);
			var upper = unchecked((ushort)(value >> 16));
			if (System.BitConverter.IsLittleEndian) { upper = Bits.ReverseBytes(upper); }
			else { lower = Bits.ReverseBytes(lower); }
			if (lower != upper) { throw new ArgumentException("Value is invalid.", "value"); }
			return upper;
		}

		public static uint ToBothByteOrder(ushort value) { return (uint)value | Bits.ReverseBytes((uint)value); }

		public static void StringToPtrAnsi(BufferWithSize buffer, string str, int totalLength, char paddingChar)
		{
			if (str == null) { str = string.Empty; }
			for (int i = 0; i < str.Length; i++)
			{ buffer[i] = (byte)str[i]; }
			for (int i = str.Length; i < totalLength; i++)
			{ buffer[i] = (byte)paddingChar; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions