Skip to content

Commit

Permalink
- Improved boxart folder detection.
Browse files Browse the repository at this point in the history
- Fixed scaling for 9.5.0+.
  • Loading branch information
KirovAir committed Sep 25, 2019
1 parent bfe484e commit 2f83d4b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
3 changes: 1 addition & 2 deletions TwilightBoxart.UX/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions TwilightBoxart.UX/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void DetectSd()
path = allDrives[0].RootDirectory.FullName;
foreach (var drive in allDrives)
{
if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, "_nds")))
if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, BoxartConfig.MagicDir)))
{
path = drive.RootDirectory.FullName;
break;
Expand Down Expand Up @@ -71,6 +71,9 @@ private void Go()
// UI STUFF
private void SetUx()
{
if (!_isInitialized)
return;

btnBrowseBoxart.Enabled = chkManualBoxartLocation.Checked;

if (!chkManualBoxartLocation.Checked && !string.IsNullOrEmpty(txtSdRoot.Text))
Expand Down Expand Up @@ -113,7 +116,6 @@ private void MainForm_Load(object sender, EventArgs e)
if (!string.IsNullOrEmpty(_config.SdRoot))
{
txtSdRoot.Text = _config.SdRoot;
txtBoxart.Text = _config.GetBoxartPath();
}
else
{
Expand Down Expand Up @@ -174,16 +176,6 @@ private void chkBoxartSize_CheckedChanged(object sender, EventArgs e)
SetUx();
}

private void txtSdRoot_TextChanged(object sender, EventArgs e)
{
SetUx();
}

private void txtBoxart_TextChanged(object sender, EventArgs e)
{
SetUx();
}

private void btnGithub_Click(object sender, EventArgs e)
{
if (MessageBox.Show(BoxartConfig.Credits + Environment.NewLine + Environment.NewLine + "Visit Github now?", "Hello", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
Expand Down
38 changes: 35 additions & 3 deletions TwilightBoxart/BoxartConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class BoxartConfig : IniSettings
public int BoxartHeight { get; set; } = 115;
public bool AdjustAspectRatio { get; set; } = true;


public const string MagicDir = "_nds";
public const string FileName = "TwilightBoxart.ini";
public static string Credits = "TwilightBoxart - Created by KirovAir." + Environment.NewLine + "Loads of love to the devs of TwilightMenu++, LibRetro, GameTDB and the maintainers of the No-Intro DB.";

Expand All @@ -36,6 +36,33 @@ public string GetBoxartPath(string root = "")
return BoxartPath;
}

if (root.Contains(Path.DirectorySeparatorChar.ToString()))
{
try
{
var split = root.Split(Path.DirectorySeparatorChar);
var tmpReplace = "";
for (var i = split.Length; i-- > 0;)
{
tmpReplace = split[i] + Path.DirectorySeparatorChar + tmpReplace;
tmpReplace = tmpReplace.TrimEnd(Path.DirectorySeparatorChar);

// Remove where we are.
var place = root.LastIndexOf(tmpReplace);
if (place == -1)
break;
var correctRoot = root.Remove(place, tmpReplace.Length);

if (Directory.Exists(Path.Combine(correctRoot, MagicDir)))
{
root = correctRoot;
break;
}
}
}
catch { }
}

return Path.Combine(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, BoxartPath.Replace("{sdroot}", "").TrimStart(Path.DirectorySeparatorChar));
}

Expand Down Expand Up @@ -85,13 +112,18 @@ public string GetBoxartPath(string root = "")

public static Dictionary<ConsoleType, Size> AspectRatioMapping = new Dictionary<ConsoleType, Size>
{
// FDS / GBC / GB
{ConsoleType.FamicomDiskSystem, new Size(1, 1)},

{ConsoleType.GameBoy, new Size(1, 1)},
{ConsoleType.GameBoyColor, new Size(1, 1)},

// NES / GEN/MD / SFC / MS/ GG
{ConsoleType.NintendoEntertainmentSystem, new Size(84, 115)},
{ConsoleType.SegaGameGear, new Size(84, 115)},
{ConsoleType.SegaGenesis, new Size(84, 115)},
{ConsoleType.SegaMasterSystem, new Size(84, 115)},
{ConsoleType.SegaGameGear, new Size(84, 115)},

// SNES
{ConsoleType.SuperNintendoEntertainmentSystem, new Size(158, 115)}
};
}
Expand Down
7 changes: 7 additions & 0 deletions TwilightBoxart/Helpers/ImgDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public void DownloadAndResize(string url, string targetFile)

public void SetSizeAdjustedToAspectRatio(Size aspectRatio)
{
if (_width == aspectRatio.Width || _height == aspectRatio.Height)
{
_height = aspectRatio.Height;
_width = aspectRatio.Width;
return;
}

var sourceWidth = aspectRatio.Width;
var sourceHeight = aspectRatio.Height;
var dWidth = _width;
Expand Down
16 changes: 16 additions & 0 deletions TwilightBoxart/Models/Base/Rom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ public static IRom FromFile(string filename)
}
}

//if (filename.ToLower().Contains(".lz77."))
//{
// fs.Seek(0, SeekOrigin.Begin);
// using (var decompressedFileStream = new MemoryStream())
// {
// using (DeflateStream decompressionStream = new DeflateStream(fs, CompressionMode.Decompress))
// {
// decompressionStream.CopyTo(decompressedFileStream);
// }

// decompressedFileStream.Seek(0, SeekOrigin.Begin);
// return FromStream(decompressedFileStream, filename);

// }
//}

return FromStream(fs, filename);
}
}
Expand Down

0 comments on commit 2f83d4b

Please sign in to comment.