This project is read-only.

Exception when loading bank file

Jan 15, 2013 at 12:07 PM

In PatchBank.cs, Load(Stream stream, int sampleRate), line 70, your code is culture specific:

if (!br.ReadLine(true).Equals("PATCH BANK v" + string.Format("{0:0.000}", BANK_VERSION)))
     throw new Exception();

For german users for example

string.Format("{0:0.000}", 1.0);

will return 1,000 (notice the decimal seperator). You have to use InvariantCulture info to make it work:

var nfi = CultureInfo.InvariantCulture.NumberFormat;
string.Format(nfi, "{0:0.000}", 1.0);

Jan 23, 2013 at 2:08 AM

I've implemented a fix for this by parsing the float from the header and directly comparing it to the constant value.

Jan 24, 2013 at 10:23 AM
Edited Jan 24, 2013 at 10:27 AM

Ok, though this fixes the issue, you are doing things much more complicated than they have to be. Since BANK_VERSION is constant anyway, why not make it a string constant and just do

public const string BANK_VERSION = "PATCH BANK v1.000";

// ... in Load method

Or, if you need the nicer looking format string, do

public const string BANK_VERSION = "1.000";

// ... in Load method

Or, if you need to do more complex checks, use regular expressions like

public const string BANK_VERSION = "1.000";

// ... in Load method
if(!Regex.IsMatch(br.ReadLine(true), BANK_VERSION + "$")) // $ = end of line