More fixes

This commit is contained in:
William Moorehouse 2015-06-17 00:10:40 -04:00 committed by Drew DeVault
parent 3c2bb1a225
commit 2ae26f1519
4 changed files with 76 additions and 26 deletions

View File

@ -0,0 +1 @@
Vanilla TrueCraft!

View File

@ -183,6 +183,12 @@
<Content Include="Content\items.png"> <Content Include="Content\items.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\pack.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\pack.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\terrain.png"> <Content Include="Content\terrain.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>

View File

@ -51,14 +51,19 @@ namespace TrueCraft.Core
/// </summary> /// </summary>
public MemoryStream Image { get; private set; } public MemoryStream Image { get; private set; }
/// <summary>
///
/// </summary>
public bool IsCorrupt { get; private set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public TexturePack() public TexturePack()
{ {
Path = TexturePack.DefaultID; Path = TexturePack.DefaultID;
Name = "Default";
Archive = new ZipFile(); Archive = new ZipFile();
Name = "Default";
} }
/// <summary> /// <summary>
@ -68,47 +73,64 @@ namespace TrueCraft.Core
public TexturePack(string path) public TexturePack(string path)
{ {
if (string.IsNullOrEmpty(path) || !File.Exists(path)) if (string.IsNullOrEmpty(path) || !File.Exists(path))
throw new ArgumentException(); MakeDefault();
Path = path; Path = path;
var fileInfo = new FileInfo(path); // A bit weird, but it works. var fileInfo = new FileInfo(path); // A bit weird, but it works.
Name = fileInfo.Name; Name = fileInfo.Name;
Archive = new ZipFile(Path); try { Archive = new ZipFile(path); }
catch { IsCorrupt = true; }
GetPackInfo(); GetPackInfo();
} }
/// <summary>
///
/// </summary>
private void MakeDefault()
{
Path = TexturePack.DefaultID;
Archive = new ZipFile();
Name = "Default";
Image = null;
Description = null;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private void GetPackInfo() private void GetPackInfo()
{ {
foreach (var entry in Archive.Entries) try
{ {
if (entry.FileName == "pack.txt") foreach (var entry in Archive.Entries)
{ {
using (var stream = entry.OpenReader()) if (entry.FileName == "pack.txt")
{ {
using (var reader = new StreamReader(stream)) using (var stream = entry.OpenReader())
Description = reader.ReadToEnd(); {
using (var reader = new StreamReader(stream))
Description = reader.ReadToEnd();
}
} }
} else if (entry.FileName == "pack.png")
else if (entry.FileName == "pack.png")
{
using (var stream = entry.OpenReader())
{ {
// Better way to do this? using (var stream = entry.OpenReader())
var buffer = new byte[entry.UncompressedSize]; {
stream.Read(buffer, 0, buffer.Length); // Better way to do this?
Image = new MemoryStream((int)entry.UncompressedSize); var buffer = new byte[entry.UncompressedSize];
Image.Write(buffer, 0, buffer.Length); stream.Read(buffer, 0, buffer.Length);
Image = new MemoryStream((int)entry.UncompressedSize);
Image.Write(buffer, 0, buffer.Length);
// Fixes 'GLib.GException: Unrecognized image file format' on Linux. // Fixes 'GLib.GException: Unrecognized image file format' on Linux.
Image.Seek(0, SeekOrigin.Begin); Image.Seek(0, SeekOrigin.Begin);
}
} }
} }
} }
catch { IsCorrupt = true; }
} }
} }
} }

View File

@ -13,6 +13,8 @@ namespace TrueCraft.Launcher.Views
public LauncherWindow Window { get; set; } public LauncherWindow Window { get; set; }
public Image DefaultImage { get; set; } public Image DefaultImage { get; set; }
public string DefaultDescription { get; set; } public string DefaultDescription { get; set; }
public Image UnknownImage { get; set; }
public string UnknownDescription { get; set; }
public Label OptionLabel { get; set; } public Label OptionLabel { get; set; }
public Label TexturePackLabel { get; set; } public Label TexturePackLabel { get; set; }
@ -29,8 +31,14 @@ namespace TrueCraft.Launcher.Views
public OptionView(LauncherWindow window) public OptionView(LauncherWindow window)
{ {
DefaultImage = Image.FromFile("Content/default-pack.png"); DefaultImage = Image.FromFile(
DefaultDescription = File.ReadAllText("Content/default-pack.txt"); Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/pack.png"));
DefaultDescription = File.ReadAllText(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/pack.txt"));
UnknownImage = Image.FromFile(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/default-pack.png"));
UnknownDescription = File.ReadAllText(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content/default-pack.txt"));
_texturePacks = new List<TexturePack>(); _texturePacks = new List<TexturePack>();
_lastTexturePack = null; _lastTexturePack = null;
@ -110,17 +118,30 @@ namespace TrueCraft.Launcher.Views
continue; continue;
var texturePack = new TexturePack(zip); var texturePack = new TexturePack(zip);
_texturePacks.Add(texturePack); if (!texturePack.IsCorrupt)
AddTexturePackRow(texturePack); {
_texturePacks.Add(texturePack);
AddTexturePackRow(texturePack);
}
} }
} }
private void AddTexturePackRow(TexturePack pack) private void AddTexturePackRow(TexturePack pack)
{ {
var row = TexturePackStore.AddRow(); var row = TexturePackStore.AddRow();
TexturePackStore.SetValue(row, TexturePackImageField, (pack.Image == null) ? DefaultImage.WithSize(IconSize.Medium) : Image.FromStream(pack.Image).WithSize(IconSize.Medium)); var isDefault = (pack.Path == TexturePack.DefaultID);
TexturePackStore.SetValue(row, TexturePackNameField, pack.Name); if (isDefault)
TexturePackStore.SetValue(row, TexturePackDescField, pack.Description ?? DefaultDescription); {
TexturePackStore.SetValue(row, TexturePackImageField, DefaultImage.WithSize(IconSize.Medium));
TexturePackStore.SetValue(row, TexturePackNameField, pack.Name);
TexturePackStore.SetValue(row, TexturePackDescField, DefaultDescription);
}
else
{
TexturePackStore.SetValue(row, TexturePackImageField, (pack.Image == null) ? UnknownImage.WithSize(IconSize.Medium) : Image.FromStream(pack.Image).WithSize(IconSize.Medium));
TexturePackStore.SetValue(row, TexturePackNameField, pack.Name);
TexturePackStore.SetValue(row, TexturePackDescField, pack.Description ?? UnknownDescription);
}
} }
} }
} }