mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
Fix launcher crashing if selected texture pack is missing default.png or terrain.png, closes #178. (Thanks Cheesse)
This commit is contained in:
parent
a3c87467ab
commit
73c84ac15e
@ -10,8 +10,10 @@ namespace Launcher {
|
|||||||
public sealed partial class LauncherWindow {
|
public sealed partial class LauncherWindow {
|
||||||
|
|
||||||
internal bool ClassicBackground = false;
|
internal bool ClassicBackground = false;
|
||||||
|
bool fontPng, terrainPng;
|
||||||
|
|
||||||
internal void TryLoadTexturePack() {
|
internal void TryLoadTexturePack() {
|
||||||
|
fontPng = false; terrainPng = false;
|
||||||
Options.Load();
|
Options.Load();
|
||||||
LauncherSkin.LoadFromOptions();
|
LauncherSkin.LoadFromOptions();
|
||||||
if( Options.Get( "nostalgia-classicbg" ) != null )
|
if( Options.Get( "nostalgia-classicbg" ) != null )
|
||||||
@ -25,36 +27,46 @@ namespace Launcher {
|
|||||||
|
|
||||||
if( !File.Exists( texPack ) )
|
if( !File.Exists( texPack ) )
|
||||||
texPack = Path.Combine( texDir, "default.zip" );
|
texPack = Path.Combine( texDir, "default.zip" );
|
||||||
if( !File.Exists( texPack ) )
|
if( !File.Exists( texPack ) ) return;
|
||||||
return;
|
|
||||||
|
|
||||||
|
ExtractTexturePack( texPack );
|
||||||
|
if( !fontPng || !terrainPng ) {
|
||||||
|
texPack = Path.Combine( texDir, "default.zip" );
|
||||||
|
ExtractTexturePack( texPack );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtractTexturePack( string texPack ) {
|
||||||
using( Stream fs = new FileStream( texPack, FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
|
using( Stream fs = new FileStream( texPack, FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
|
||||||
ZipReader reader = new ZipReader();
|
ZipReader reader = new ZipReader();
|
||||||
|
|
||||||
reader.ShouldProcessZipEntry = (f) => f == "default.png" || f == "terrain.png";
|
reader.ShouldProcessZipEntry = (f) => f == "default.png" || f == "terrain.png";
|
||||||
reader.ProcessZipEntry = ProcessZipEntry;
|
reader.ProcessZipEntry = ProcessZipEntry;
|
||||||
reader.Extract( fs );
|
reader.Extract( fs );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
||||||
|
MemoryStream stream = new MemoryStream( data );
|
||||||
|
|
||||||
|
if( filename == "default.png" ) {
|
||||||
|
if( fontPng ) return;
|
||||||
|
Bitmap bmp = new Bitmap( stream );
|
||||||
|
Drawer.SetFontBitmap( bmp );
|
||||||
|
useBitmappedFont = !Options.GetBool( OptionsKey.ArialChatFont, false );
|
||||||
|
fontPng = true;
|
||||||
|
} else if( filename == "terrain.png" ) {
|
||||||
|
if( terrainPng ) return;
|
||||||
|
using( Bitmap bmp = new Bitmap( stream ) )
|
||||||
|
MakeClassicTextures( bmp );
|
||||||
|
terrainPng = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool useBitmappedFont;
|
bool useBitmappedFont;
|
||||||
Bitmap terrainBmp;
|
Bitmap terrainBmp;
|
||||||
FastBitmap terrainPixels;
|
FastBitmap terrainPixels;
|
||||||
const int tileSize = 48;
|
const int tileSize = 48;
|
||||||
|
|
||||||
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
|
|
||||||
MemoryStream stream = new MemoryStream( data );
|
|
||||||
|
|
||||||
if( filename == "default.png" ) {
|
|
||||||
Bitmap bmp = new Bitmap( stream );
|
|
||||||
Drawer.SetFontBitmap( bmp );
|
|
||||||
useBitmappedFont = !Options.GetBool( OptionsKey.ArialChatFont, false );
|
|
||||||
} else if( filename == "terrain.png" ) {
|
|
||||||
using( Bitmap bmp = new Bitmap( stream ) )
|
|
||||||
MakeClassicTextures( bmp );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MakeClassicTextures( Bitmap bmp ) {
|
void MakeClassicTextures( Bitmap bmp ) {
|
||||||
int elemSize = bmp.Width / 16;
|
int elemSize = bmp.Width / 16;
|
||||||
Size size = new Size( tileSize, tileSize );
|
Size size = new Size( tileSize, tileSize );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user