Use portable class library compatible alternatives for some methods.

This commit is contained in:
UnknownShadow200 2015-01-03 13:03:47 +11:00
parent 1ed45db594
commit cceecf2ae7
3 changed files with 19 additions and 5 deletions

View File

@ -25,7 +25,8 @@ namespace Launcher {
public NameComparer( int column ) : base( column ) { }
protected override int Compare( ListViewItem x, ListViewItem y ) {
int value = String.Compare( x.SubItems[col].Text, y.SubItems[col].Text, true );
StringComparison comparison = StringComparison.CurrentCultureIgnoreCase;
int value = String.Compare( x.SubItems[col].Text, y.SubItems[col].Text, comparison );
return Invert ? -value : value;
}
}

View File

@ -68,7 +68,16 @@ namespace ClassicalSharp {
public string ReadString() {
byte[] data = ReadBytes( 64 );
return Encoding.ASCII.GetString( data ).TrimEnd( '\0', ' ' );
return GetAsciiString( data ).TrimEnd( '\0', ' ' );
}
static string GetAsciiString( byte[] data ) {
char[] characters = new char[data.Length];
for( int i = 0; i < data.Length; i++ ) {
byte code = data[i];
characters[i] = code >= 0x80 ? '?' : (char)code;
}
return new String( characters );
}
static string GetTextString( byte[] data ) {

View File

@ -226,10 +226,14 @@ namespace ClassicalSharp {
}
static void WriteString( byte[] buffer, ref int index, string value ) {
for( int i = index; i < index + 64; i++ ) {
buffer[i] = (byte)' ';
int count = Math.Min( value.Length, 64 );
for( int i = 0; i < count; i++ ) {
char c = value[i];
buffer[index + i] = (byte)( c >= '\u0080' ? '?' : c );
}
for( int i = value.Length; i < 64; i++ ) {
buffer[index + i] = (byte)' ';
}
Encoding.ASCII.GetBytes( value, 0, value.Length, buffer, index );
index += 64;
}