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">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\pack.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\pack.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\terrain.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

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

View File

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