public static void write( it song, string filename ) { byte[] data; try { data = song.pack(); } catch ( Exception e ) { throw new IOException( "it.pack(): " + e.Message ); } FileStream file = null; try { file = new FileStream( filename, FileMode.Create, FileAccess.Write, FileShare.Write); } catch ( Exception e ) { file.Close(); throw new IOException( "(opening out file stream): " + e.Message ); } try { file.Write( data, 0, data.Length ); } catch ( Exception e ) { file.Close(); throw new IOException( "(writing out file stream): " + e.Message ); } return; }
/// <summary> /// Loads an it file into memory, calls <code>it.parse()</code>, then closes the file. /// </summary> /// <param name="filename">Full path to the file being loaded.</param> /// <returns>An instance of the <code>it</code> class, fully loaded with all the information contained in the file.</returns> public static it load( string filename ) { // check if file exists and load it FileStream file = null; try { file = new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read ); } catch ( Exception e ) { throw new IOException( "(opening in file stream): " + e.Message ); } // load file into byte array byte[] data = new byte[ maxSize ]; try { file.Read( data, 0, maxSize ); } catch ( Exception e ) { file.Close(); throw new IOException( "(reading in file stream): " + e.Message ); } it itfile = new it(); // close the file file.Close(); try { itfile.parse( data ); } catch ( Exception e ) { throw new IOException( "it.parse(): " + e.Message ); } return itfile; }
/// <summary> /// Loads an it file into memory, calls <code>it.parse()</code>, then closes the file. /// </summary> /// <param name="filename">Full path to the file being loaded.</param> /// <returns>An instance of the <code>it</code> class, fully loaded with all the information contained in the file.</returns> public static it load(string filename) { // check if file exists and load it FileStream file = null; try { file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (Exception e) { throw new IOException("(opening in file stream): " + e.Message); } // load file into byte array byte[] data = new byte[maxSize]; try { file.Read(data, 0, maxSize); } catch (Exception e) { file.Close(); throw new IOException("(reading in file stream): " + e.Message); } it itfile = new it(); // close the file file.Close(); try { itfile.parse(data); } catch (Exception e) { throw new IOException("it.parse(): " + e.Message); } return(itfile); }
public static void write(it song, string filename) { byte[] data; try { data = song.pack(); } catch (Exception e) { throw new IOException("it.pack(): " + e.Message); } FileStream file = null; try { file = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Write); } catch (Exception e) { file.Close(); throw new IOException("(opening out file stream): " + e.Message); } try { file.Write(data, 0, data.Length); } catch (Exception e) { file.Close(); throw new IOException("(writing out file stream): " + e.Message); } return; }
static int Main(string[] args) { string usage = "Usage: spcom infile outfile [-pitch] [-channels]"; if (args.Length < 2) { Console.WriteLine(usage); return(0); } it song = null; try { song = io.load(args[0]); } catch (Exception e) { Console.WriteLine("io.load(): " + e.Message); return(1); } bool pitch = false; bool channels = false; for (int i = 2; i < args.Length; i++) { if (args[i] == "-pitch" && pitch == false) { try { song.fixPitch(); } catch (Exception e) { Console.WriteLine("song.fixPitch(): " + e.Message); } pitch = true; } if (args[i] == "-channels" && channels == false) { try { song.reduceChannels(); } catch (Exception e) { Console.WriteLine("song.reduceChannels(): " + e.Message); } channels = true; } } try { io.write(song, args[1]); } catch (Exception e) { Console.WriteLine("io.write: " + e.Message); return(1); } return(0); }