Added support for loading icon from .nro files and cleaned up the code a bit

This commit is contained in:
Xpl0itR 2019-06-04 20:50:47 +01:00
commit cf3a6cd993
No known key found for this signature in database
GPG key ID: 91798184109676AD
8 changed files with 130 additions and 53 deletions

View file

@ -1,5 +1,7 @@
using Gtk;
using System;
using System.IO;
using System.Reflection;
namespace Ryujinx
{
@ -9,15 +11,22 @@ namespace Ryujinx
{
Window CSWin = new Window(WindowType.Toplevel);
CSWin.Title = "Control Settings";
CSWin.Icon = new Gdk.Pixbuf("./ryujinx.png");
CSWin.SetDefaultSize(854, 360);
CSWin.Resizable = false;
CSWin.WindowPosition = WindowPosition.Center;
CSWin.SetDefaultSize(854, 360);
VBox box = new VBox(false, 2);
//Load Icon
using (Stream iconstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Ryujinx.ryujinxIcon.png"))
using (StreamReader reader = new StreamReader(iconstream))
{
Gdk.Pixbuf RyujinxIcon = new Gdk.Pixbuf(iconstream);
CSWin.Icon = RyujinxIcon;
}
//settings stuff will replace this block
Label myLabel = new Label { Text = "General Settings" };
Label myLabel = new Label { Text = "Control Settings" };
box.PackStart(myLabel, true, true, 3);
HBox ButtonBox = new HBox(true, 3);

View file

@ -1,5 +1,7 @@
using Gtk;
using System;
using System.IO;
using System.Reflection;
namespace Ryujinx
{
@ -9,13 +11,20 @@ namespace Ryujinx
{
Window GSWin = new Window(WindowType.Toplevel);
GSWin.Title = "General Settings";
GSWin.Icon = new Gdk.Pixbuf("./ryujinx.png");
GSWin.SetDefaultSize(854, 360);
GSWin.Resizable = false;
GSWin.WindowPosition = WindowPosition.Center;
GSWin.SetDefaultSize(854, 360);
VBox box = new VBox(false, 2);
//Load Icon
using (Stream iconstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Ryujinx.ryujinxIcon.png"))
using (StreamReader reader = new StreamReader(iconstream))
{
Gdk.Pixbuf RyujinxIcon = new Gdk.Pixbuf(iconstream);
GSWin.Icon = RyujinxIcon;
}
//settings stuff will replace this block
Label myLabel = new Label { Text = "General Settings" };
box.PackStart(myLabel, true, true, 3);

View file

@ -3,6 +3,8 @@ using GUI = Gtk.Builder.ObjectAttribute;
using Ryujinx.Common.Logging;
using System;
using System.IO;
using System.Reflection;
using System.Text;
namespace Ryujinx
{
@ -12,7 +14,10 @@ namespace Ryujinx
internal ListStore TableStore { get; private set; }
internal static Gdk.Pixbuf RyujinxIcon { get; private set; }
//UI Controls
[GUI] Window MainWin;
[GUI] MenuBar MenuBar;
[GUI] MenuItem LoadApplicationFile;
[GUI] MenuItem LoadApplicationFolder;
@ -42,6 +47,14 @@ namespace Ryujinx
builder.Autoconnect(this);
ApplyTheme();
//Load Icon
using (Stream iconstream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Ryujinx.ryujinxIcon.png"))
using (StreamReader reader = new StreamReader(iconstream))
{
RyujinxIcon = new Gdk.Pixbuf(iconstream);
MainWin.Icon = RyujinxIcon;
}
DeleteEvent += Window_Close;
//disable some buttons
@ -58,13 +71,16 @@ namespace Ryujinx
GameTable.AppendColumn("Path", new CellRendererText(), "text" , 6);
string dat = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GameDirs.dat");
if (File.Exists(dat) == false) { File.Create(dat).Close(); }
string[] GameDirs = File.ReadAllLines(dat);
string[] Games = new string[] { };
foreach (string GameDir in GameDirs)
{
if (Directory.Exists(GameDir) == false) { Logger.PrintError(LogClass.Application, "There is an invalid game directory in \"GameDirs.dat\""); return; }
DirectoryInfo GameDirInfo = new DirectoryInfo(GameDir);
foreach (var Game in GameDirInfo.GetFiles())
{
@ -77,9 +93,11 @@ namespace Ryujinx
}
TableStore = new ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));
foreach (string GamePath in Games)
{
TableStore.AppendValues(new Gdk.Pixbuf("./ryujinx.png", 50, 50), "", "", "", "", "", GamePath);
Gdk.Pixbuf GameIcon = GetIconData(GamePath);
TableStore.AppendValues(GameIcon, "", "", "", "", "", GamePath);
}
GameTable.Model = TableStore;
@ -97,6 +115,44 @@ namespace Ryujinx
StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800);
}
public static Gdk.Pixbuf GetIconData(string filePath)
{
using (FileStream Input = File.Open(filePath, FileMode.Open, FileAccess.Read))
{
BinaryReader Reader = new BinaryReader(Input);
if (System.IO.Path.GetExtension(filePath) == ".nro")
{
Input.Seek(24, SeekOrigin.Begin);
int AssetOffset = Reader.ReadInt32();
byte[] Read(long Position, int Size)
{
Input.Seek(Position, SeekOrigin.Begin);
return Reader.ReadBytes(Size);
}
if (Encoding.ASCII.GetString(Read(AssetOffset, 4)) == "ASET")
{
byte[] IconSectionInfo = Read(AssetOffset + 8, 0x10);
long IconOffset = BitConverter.ToInt64(IconSectionInfo, 0);
long IconSize = BitConverter.ToInt64(IconSectionInfo, 8);
byte[] IconData = Read(AssetOffset + IconOffset, (int)IconSize);
return new Gdk.Pixbuf(IconData, 50, 50);
}
else { return RyujinxIcon; }
}
else
{
return RyujinxIcon; //temp
}
}
}
//Events
private void Row_Activated(object obj, RowActivatedArgs args)
{
TableStore.GetIter(out TreeIter treeiter, new TreePath(args.Path.ToString()));
@ -122,6 +178,7 @@ namespace Ryujinx
device.LoadProgram(path);
break;
}
Destroy();
Application.Quit();
}
@ -158,9 +215,11 @@ namespace Ryujinx
device.LoadProgram(fc.Filename);
break;
}
Destroy();
Application.Quit();
}
fc.Destroy();
}
@ -187,9 +246,11 @@ namespace Ryujinx
Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
device.LoadCart(fc.Filename);
}
Destroy();
Application.Quit();
}
fc.Destroy();
}
@ -224,7 +285,7 @@ namespace Ryujinx
if (fc.Run() == (int)ResponseType.Accept)
{
Console.WriteLine(fc.Filename);
Console.WriteLine(fc.Filename); //temp
}
fc.Destroy();
}
@ -238,7 +299,7 @@ namespace Ryujinx
{
AboutDialog about = new AboutDialog();
about.ProgramName = "Ryujinx";
about.Icon = new Gdk.Pixbuf("ryujinx.png");
about.Icon = RyujinxIcon;
about.Version = "Version x.x.x";
about.Authors = new string[] { "gdkchan", "Ac_K", "LDj3SNuD", "emmauss", "MerryMage", "MS-DOS1999", "Thog", "jD", "BaronKiko", "Dr.Hacknik", "Lordmau5", "(and Xpl0itR did a bit of work too :D)" };
about.Copyright = "Unlicense";

View file

@ -8,7 +8,6 @@
<property name="window_position">center</property>
<property name="default_width">1280</property>
<property name="default_height">745</property>
<property name="icon">ryujinx.png</property>
<property name="gravity">center</property>
<child type="titlebar">
<placeholder/>
@ -172,6 +171,7 @@
<object class="GtkTreeView" id="GameTable">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_clickable">False</property>
<signal name="row-activated" handler="Row_Activated" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection"/>

View file

@ -60,15 +60,15 @@ namespace Ryujinx
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
var app = new Gtk.Application("Ryujinx.Ryujinx", GLib.ApplicationFlags.None);
app.Register(GLib.Cancellable.Current);
var win = new MainMenu(device);
app.AddWindow(win);
app.Register(GLib.Cancellable.Current);
app.AddWindow(win);
win.Show();
Gtk.Application.Run();
}
else
{
if (Directory.Exists(args[0]))
@ -128,7 +128,7 @@ namespace Ryujinx
}
DiscordPresence.Details = $"Playing {device.System.TitleName}";
DiscordPresence.State = string.IsNullOrWhiteSpace(device.System.TitleID) ? string.Empty : device.System.TitleID.ToUpper();
DiscordPresence.State = device.System.TitleID.ToUpper();
DiscordPresence.Assets.LargeImageText = device.System.TitleName;
DiscordPresence.Assets.SmallImageKey = "ryujinx";
DiscordPresence.Assets.SmallImageText = "Ryujinx is an emulator for the Nintendo Switch";

View file

@ -20,6 +20,7 @@
<ItemGroup>
<EmbeddedResource Include="MainMenu.glade" />
<EmbeddedResource Include="ryujinxIcon.png" />
</ItemGroup>
<ItemGroup>
@ -44,9 +45,6 @@
<None Update="RPsupported.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ryujinx.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Theme.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

BIN
Ryujinx/ryujinxIcon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB