Added support for loading icon from .nro files and cleaned up the code a bit
This commit is contained in:
parent
d50204c108
commit
cf3a6cd993
8 changed files with 130 additions and 53 deletions
|
@ -1,5 +1,7 @@
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Ryujinx
|
namespace Ryujinx
|
||||||
{
|
{
|
||||||
|
@ -9,15 +11,22 @@ namespace Ryujinx
|
||||||
{
|
{
|
||||||
Window CSWin = new Window(WindowType.Toplevel);
|
Window CSWin = new Window(WindowType.Toplevel);
|
||||||
CSWin.Title = "Control Settings";
|
CSWin.Title = "Control Settings";
|
||||||
CSWin.Icon = new Gdk.Pixbuf("./ryujinx.png");
|
|
||||||
CSWin.SetDefaultSize(854, 360);
|
|
||||||
CSWin.Resizable = false;
|
CSWin.Resizable = false;
|
||||||
CSWin.WindowPosition = WindowPosition.Center;
|
CSWin.WindowPosition = WindowPosition.Center;
|
||||||
|
CSWin.SetDefaultSize(854, 360);
|
||||||
|
|
||||||
VBox box = new VBox(false, 2);
|
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
|
//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);
|
box.PackStart(myLabel, true, true, 3);
|
||||||
|
|
||||||
HBox ButtonBox = new HBox(true, 3);
|
HBox ButtonBox = new HBox(true, 3);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using Gtk;
|
using Gtk;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Ryujinx
|
namespace Ryujinx
|
||||||
{
|
{
|
||||||
|
@ -9,13 +11,20 @@ namespace Ryujinx
|
||||||
{
|
{
|
||||||
Window GSWin = new Window(WindowType.Toplevel);
|
Window GSWin = new Window(WindowType.Toplevel);
|
||||||
GSWin.Title = "General Settings";
|
GSWin.Title = "General Settings";
|
||||||
GSWin.Icon = new Gdk.Pixbuf("./ryujinx.png");
|
|
||||||
GSWin.SetDefaultSize(854, 360);
|
|
||||||
GSWin.Resizable = false;
|
GSWin.Resizable = false;
|
||||||
GSWin.WindowPosition = WindowPosition.Center;
|
GSWin.WindowPosition = WindowPosition.Center;
|
||||||
|
GSWin.SetDefaultSize(854, 360);
|
||||||
|
|
||||||
VBox box = new VBox(false, 2);
|
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
|
//settings stuff will replace this block
|
||||||
Label myLabel = new Label { Text = "General Settings" };
|
Label myLabel = new Label { Text = "General Settings" };
|
||||||
box.PackStart(myLabel, true, true, 3);
|
box.PackStart(myLabel, true, true, 3);
|
||||||
|
|
|
@ -3,6 +3,8 @@ using GUI = Gtk.Builder.ObjectAttribute;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Ryujinx
|
namespace Ryujinx
|
||||||
{
|
{
|
||||||
|
@ -12,7 +14,10 @@ namespace Ryujinx
|
||||||
|
|
||||||
internal ListStore TableStore { get; private set; }
|
internal ListStore TableStore { get; private set; }
|
||||||
|
|
||||||
|
internal static Gdk.Pixbuf RyujinxIcon { get; private set; }
|
||||||
|
|
||||||
//UI Controls
|
//UI Controls
|
||||||
|
[GUI] Window MainWin;
|
||||||
[GUI] MenuBar MenuBar;
|
[GUI] MenuBar MenuBar;
|
||||||
[GUI] MenuItem LoadApplicationFile;
|
[GUI] MenuItem LoadApplicationFile;
|
||||||
[GUI] MenuItem LoadApplicationFolder;
|
[GUI] MenuItem LoadApplicationFolder;
|
||||||
|
@ -42,6 +47,14 @@ namespace Ryujinx
|
||||||
builder.Autoconnect(this);
|
builder.Autoconnect(this);
|
||||||
ApplyTheme();
|
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;
|
DeleteEvent += Window_Close;
|
||||||
|
|
||||||
//disable some buttons
|
//disable some buttons
|
||||||
|
@ -58,13 +71,16 @@ namespace Ryujinx
|
||||||
GameTable.AppendColumn("Path", new CellRendererText(), "text" , 6);
|
GameTable.AppendColumn("Path", new CellRendererText(), "text" , 6);
|
||||||
|
|
||||||
string dat = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GameDirs.dat");
|
string dat = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GameDirs.dat");
|
||||||
|
|
||||||
if (File.Exists(dat) == false) { File.Create(dat).Close(); }
|
if (File.Exists(dat) == false) { File.Create(dat).Close(); }
|
||||||
|
|
||||||
string[] GameDirs = File.ReadAllLines(dat);
|
string[] GameDirs = File.ReadAllLines(dat);
|
||||||
string[] Games = new string[] { };
|
string[] Games = new string[] { };
|
||||||
|
|
||||||
foreach (string GameDir in GameDirs)
|
foreach (string GameDir in GameDirs)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(GameDir) == false) { Logger.PrintError(LogClass.Application, "There is an invalid game directory in \"GameDirs.dat\""); return; }
|
if (Directory.Exists(GameDir) == false) { Logger.PrintError(LogClass.Application, "There is an invalid game directory in \"GameDirs.dat\""); return; }
|
||||||
|
|
||||||
DirectoryInfo GameDirInfo = new DirectoryInfo(GameDir);
|
DirectoryInfo GameDirInfo = new DirectoryInfo(GameDir);
|
||||||
foreach (var Game in GameDirInfo.GetFiles())
|
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));
|
TableStore = new ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));
|
||||||
|
|
||||||
foreach (string GamePath in Games)
|
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;
|
GameTable.Model = TableStore;
|
||||||
|
@ -97,6 +115,44 @@ namespace Ryujinx
|
||||||
StyleContext.AddProviderForScreen(Gdk.Screen.Default, css_provider, 800);
|
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)
|
private void Row_Activated(object obj, RowActivatedArgs args)
|
||||||
{
|
{
|
||||||
TableStore.GetIter(out TreeIter treeiter, new TreePath(args.Path.ToString()));
|
TableStore.GetIter(out TreeIter treeiter, new TreePath(args.Path.ToString()));
|
||||||
|
@ -122,6 +178,7 @@ namespace Ryujinx
|
||||||
device.LoadProgram(path);
|
device.LoadProgram(path);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Destroy();
|
Destroy();
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
}
|
}
|
||||||
|
@ -158,9 +215,11 @@ namespace Ryujinx
|
||||||
device.LoadProgram(fc.Filename);
|
device.LoadProgram(fc.Filename);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Destroy();
|
Destroy();
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fc.Destroy();
|
fc.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,9 +246,11 @@ namespace Ryujinx
|
||||||
Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
|
Logger.PrintInfo(LogClass.Application, "Loading as cart WITHOUT RomFS.");
|
||||||
device.LoadCart(fc.Filename);
|
device.LoadCart(fc.Filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Destroy();
|
Destroy();
|
||||||
Application.Quit();
|
Application.Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fc.Destroy();
|
fc.Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +285,7 @@ namespace Ryujinx
|
||||||
|
|
||||||
if (fc.Run() == (int)ResponseType.Accept)
|
if (fc.Run() == (int)ResponseType.Accept)
|
||||||
{
|
{
|
||||||
Console.WriteLine(fc.Filename);
|
Console.WriteLine(fc.Filename); //temp
|
||||||
}
|
}
|
||||||
fc.Destroy();
|
fc.Destroy();
|
||||||
}
|
}
|
||||||
|
@ -238,7 +299,7 @@ namespace Ryujinx
|
||||||
{
|
{
|
||||||
AboutDialog about = new AboutDialog();
|
AboutDialog about = new AboutDialog();
|
||||||
about.ProgramName = "Ryujinx";
|
about.ProgramName = "Ryujinx";
|
||||||
about.Icon = new Gdk.Pixbuf("ryujinx.png");
|
about.Icon = RyujinxIcon;
|
||||||
about.Version = "Version x.x.x";
|
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.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";
|
about.Copyright = "Unlicense";
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
<property name="window_position">center</property>
|
<property name="window_position">center</property>
|
||||||
<property name="default_width">1280</property>
|
<property name="default_width">1280</property>
|
||||||
<property name="default_height">745</property>
|
<property name="default_height">745</property>
|
||||||
<property name="icon">ryujinx.png</property>
|
|
||||||
<property name="gravity">center</property>
|
<property name="gravity">center</property>
|
||||||
<child type="titlebar">
|
<child type="titlebar">
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
|
@ -172,6 +171,7 @@
|
||||||
<object class="GtkTreeView" id="GameTable">
|
<object class="GtkTreeView" id="GameTable">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
|
<property name="headers_clickable">False</property>
|
||||||
<signal name="row-activated" handler="Row_Activated" swapped="no"/>
|
<signal name="row-activated" handler="Row_Activated" swapped="no"/>
|
||||||
<child internal-child="selection">
|
<child internal-child="selection">
|
||||||
<object class="GtkTreeSelection"/>
|
<object class="GtkTreeSelection"/>
|
||||||
|
|
|
@ -60,15 +60,15 @@ namespace Ryujinx
|
||||||
|
|
||||||
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
||||||
var app = new Gtk.Application("Ryujinx.Ryujinx", GLib.ApplicationFlags.None);
|
var app = new Gtk.Application("Ryujinx.Ryujinx", GLib.ApplicationFlags.None);
|
||||||
app.Register(GLib.Cancellable.Current);
|
|
||||||
|
|
||||||
var win = new MainMenu(device);
|
var win = new MainMenu(device);
|
||||||
app.AddWindow(win);
|
|
||||||
|
|
||||||
|
app.Register(GLib.Cancellable.Current);
|
||||||
|
app.AddWindow(win);
|
||||||
win.Show();
|
win.Show();
|
||||||
|
|
||||||
Gtk.Application.Run();
|
Gtk.Application.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Directory.Exists(args[0]))
|
if (Directory.Exists(args[0]))
|
||||||
|
@ -128,7 +128,7 @@ namespace Ryujinx
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscordPresence.Details = $"Playing {device.System.TitleName}";
|
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.LargeImageText = device.System.TitleName;
|
||||||
DiscordPresence.Assets.SmallImageKey = "ryujinx";
|
DiscordPresence.Assets.SmallImageKey = "ryujinx";
|
||||||
DiscordPresence.Assets.SmallImageText = "Ryujinx is an emulator for the Nintendo Switch";
|
DiscordPresence.Assets.SmallImageText = "Ryujinx is an emulator for the Nintendo Switch";
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="MainMenu.glade" />
|
<EmbeddedResource Include="MainMenu.glade" />
|
||||||
|
<EmbeddedResource Include="ryujinxIcon.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -44,9 +45,6 @@
|
||||||
<None Update="RPsupported.dat">
|
<None Update="RPsupported.dat">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="ryujinx.png">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
<None Update="Theme.css">
|
<None Update="Theme.css">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 52 KiB |
BIN
Ryujinx/ryujinxIcon.png
Normal file
BIN
Ryujinx/ryujinxIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Loading…
Add table
Add a link
Reference in a new issue