Archive for January, 2008

Unicode to DOS Filenames

DOS is a pain. .NET doesn’t get along too well with DOS either, since everything .NET is Unicode – just like everything, actually.

How to change from Unicode (aka, Kanji characters) to DOS Filenames:

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath, uint cchBuffer);

public static string ToDOSPathName(String longName) {
StringBuilder shortNameBuffer = new StringBuilder(256);
uint bufferSize = (uint)shortNameBuffer.Capacity;

uint result = GetShortPathName(longName, shortNameBuffer, bufferSize);

return shortNameBuffer.ToString();
}

Genpuid troubles

Since there is no managed or open source way to get a PUID for MusicBrainz (Thank you, thank you MusicIP…), you have to call it as an external process. However, since Windows makes all the console-based executables have a character set of SBCSCodePageEncoding, accents get messed up.

After several hours of smashing my head against the wall and venting on GTalk w/ scottp, I finally got it to work:

Encoding.UTF8.GetString(ProcessObj.StandardOutput.CurrentEncoding.GetBytes(“yadda yadda”));

And now it all works. Yay! iBrainz is almost finished…