diff --git a/Ryujinx/ControlSettings.cs b/Ryujinx/ControlSettings.cs index 6a2148ab2a..8f6265e317 100644 --- a/Ryujinx/ControlSettings.cs +++ b/Ryujinx/ControlSettings.cs @@ -1,5 +1,7 @@ using Gtk; using System; +using System.IO; +using System.Reflection; namespace Ryujinx { @@ -7,27 +9,34 @@ namespace Ryujinx { public static void ControlSettingsMenu() { - Window CSWin = new Window(WindowType.Toplevel); - CSWin.Title = "Control Settings"; - CSWin.Icon = new Gdk.Pixbuf("./ryujinx.png"); - CSWin.SetDefaultSize(854, 360); - CSWin.Resizable = false; + Window CSWin = new Window(WindowType.Toplevel); + CSWin.Title = "Control Settings"; + 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); + HBox ButtonBox = new HBox(true, 3); Alignment BoxAlign = new Alignment(1, 0, 0, 0); - Button Save = new Button("Save"); + Button Save = new Button("Save"); Save.Pressed += (o, args) => Save_Pressed(o, args, CSWin); ButtonBox.Add(Save); - Button Cancel = new Button("Cancel"); + Button Cancel = new Button("Cancel"); Cancel.Pressed += (o, args) => Cancel_Pressed(o, args, CSWin); ButtonBox.Add(Cancel); diff --git a/Ryujinx/GeneralSettings.cs b/Ryujinx/GeneralSettings.cs index 8b0b2a2b4a..b874ef632e 100644 --- a/Ryujinx/GeneralSettings.cs +++ b/Ryujinx/GeneralSettings.cs @@ -1,5 +1,7 @@ using Gtk; using System; +using System.IO; +using System.Reflection; namespace Ryujinx { @@ -7,27 +9,34 @@ namespace Ryujinx { public static void GeneralSettingsMenu() { - Window GSWin = new Window(WindowType.Toplevel); - GSWin.Title = "General Settings"; - GSWin.Icon = new Gdk.Pixbuf("./ryujinx.png"); - GSWin.SetDefaultSize(854, 360); - GSWin.Resizable = false; + Window GSWin = new Window(WindowType.Toplevel); + GSWin.Title = "General Settings"; + 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); - HBox ButtonBox = new HBox(true, 3); + HBox ButtonBox = new HBox(true, 3); Alignment BoxAlign = new Alignment(1, 0, 0, 0); - Button Save = new Button("Save"); + Button Save = new Button("Save"); Save.Pressed += (o, args) => Save_Pressed(o, args, GSWin); ButtonBox.Add(Save); - Button Cancel = new Button("Cancel"); + Button Cancel = new Button("Cancel"); Cancel.Pressed += (o, args) => Cancel_Pressed(o, args, GSWin); ButtonBox.Add(Cancel); diff --git a/Ryujinx/MainMenu.cs b/Ryujinx/MainMenu.cs index f3fb37bda1..87eb6bb579 100644 --- a/Ryujinx/MainMenu.cs +++ b/Ryujinx/MainMenu.cs @@ -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; @@ -32,8 +37,8 @@ namespace Ryujinx if (device.System.State.DiscordIntergrationEnabled == true) { - Program.DiscordPresence.Details = "Main Menu"; - Program.DiscordPresence.State = "Idling"; + Program.DiscordPresence.Details = "Main Menu"; + Program.DiscordPresence.State = "Idling"; Program.DiscordPresence.Timestamps = new DiscordRPC.Timestamps(DateTime.UtcNow); Program.DiscordClient.SetPresence(Program.DiscordPresence); @@ -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[] { }; + 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; @@ -87,9 +105,9 @@ namespace Ryujinx public static void ApplyTheme() { - var settings = Settings.Default; - settings.XftRgba = "rgb"; - settings.XftHinting = 1; + var settings = Settings.Default; + settings.XftRgba = "rgb"; + settings.XftHinting = 1; settings.XftHintstyle = "hintfull"; CssProvider css_provider = new CssProvider(); @@ -97,11 +115,49 @@ 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())); string path = (string)TableStore.GetValue(treeiter, 6); - + switch (System.IO.Path.GetExtension(path).ToLowerInvariant()) { case ".xci": @@ -122,6 +178,7 @@ namespace Ryujinx device.LoadProgram(path); break; } + Destroy(); Application.Quit(); } @@ -129,7 +186,7 @@ namespace Ryujinx private void Load_Application_File(object o, EventArgs args) { FileChooserDialog fc = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); - fc.Filter = new FileFilter(); + fc.Filter = new FileFilter(); fc.Filter.AddPattern("*.nsp"); fc.Filter.AddPattern("*.xci"); fc.Filter.AddPattern("*.nca"); @@ -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(); } @@ -219,12 +280,12 @@ namespace Ryujinx private void NFC_Pressed(object o, EventArgs args) { FileChooserDialog fc = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); - fc.Filter = new FileFilter(); + fc.Filter = new FileFilter(); fc.Filter.AddPattern("*.bin"); if (fc.Run() == (int)ResponseType.Accept) { - Console.WriteLine(fc.Filename); + Console.WriteLine(fc.Filename); //temp } fc.Destroy(); } @@ -236,15 +297,15 @@ namespace Ryujinx private void About_Pressed(object o, EventArgs args) { - AboutDialog about = new AboutDialog(); - about.ProgramName = "Ryujinx"; - about.Icon = new Gdk.Pixbuf("ryujinx.png"); - 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"; - about.Comments = "Ryujinx is an emulator for the Nintendo Switch"; - about.Website = "https://github.com/Ryujinx/Ryujinx"; - about.Copyright = "Unlicense"; + AboutDialog about = new AboutDialog(); + about.ProgramName = "Ryujinx"; + 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"; + about.Comments = "Ryujinx is an emulator for the Nintendo Switch"; + about.Website = "https://github.com/Ryujinx/Ryujinx"; + about.Copyright = "Unlicense"; about.WindowPosition = WindowPosition.Center; about.Run(); about.Destroy(); diff --git a/Ryujinx/MainMenu.glade b/Ryujinx/MainMenu.glade index ce631d8fca..afc9708b43 100644 --- a/Ryujinx/MainMenu.glade +++ b/Ryujinx/MainMenu.glade @@ -8,7 +8,6 @@ center 1280 745 - ryujinx.png center @@ -172,6 +171,7 @@ True True + False diff --git a/Ryujinx/Program.cs b/Ryujinx/Program.cs index 44626e3dfe..a414e49630 100644 --- a/Ryujinx/Program.cs +++ b/Ryujinx/Program.cs @@ -36,16 +36,16 @@ namespace Ryujinx Profile.Initialize(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; + AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; if (device.System.State.DiscordIntegrationEnabled == true) { - DiscordClient = new DiscordRpcClient("568815339807309834"); + DiscordClient = new DiscordRpcClient("568815339807309834"); DiscordPresence = new RichPresence { Assets = new Assets { - LargeImageKey = "ryujinx", + LargeImageKey = "ryujinx", LargeImageText = "Ryujinx is an emulator for the Nintendo Switch" } }; @@ -59,16 +59,16 @@ namespace Ryujinx Gtk.Application.Init(); 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); + var win = new MainMenu(device); + app.Register(GLib.Cancellable.Current); - - var win = new MainMenu(device); app.AddWindow(win); - win.Show(); Gtk.Application.Run(); } + else { if (Directory.Exists(args[0])) @@ -127,12 +127,12 @@ namespace Ryujinx DiscordPresence.Assets.LargeImageKey = device.System.TitleID; } - DiscordPresence.Details = $"Playing {device.System.TitleName}"; - DiscordPresence.State = string.IsNullOrWhiteSpace(device.System.TitleID) ? string.Empty : device.System.TitleID.ToUpper(); + DiscordPresence.Details = $"Playing {device.System.TitleName}"; + DiscordPresence.State = device.System.TitleID.ToUpper(); 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.Timestamps = new Timestamps(DateTime.UtcNow); + DiscordPresence.Timestamps = new Timestamps(DateTime.UtcNow); DiscordClient.SetPresence(DiscordPresence); } @@ -194,4 +194,4 @@ namespace Ryujinx } } } -} +} \ No newline at end of file diff --git a/Ryujinx/Ryujinx.csproj b/Ryujinx/Ryujinx.csproj index a8d31a6ed2..3e6e97022b 100644 --- a/Ryujinx/Ryujinx.csproj +++ b/Ryujinx/Ryujinx.csproj @@ -20,6 +20,7 @@ + @@ -44,9 +45,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest diff --git a/Ryujinx/ryujinx.png b/Ryujinx/ryujinx.png deleted file mode 100644 index 9bd88fab59..0000000000 Binary files a/Ryujinx/ryujinx.png and /dev/null differ diff --git a/Ryujinx/ryujinxIcon.png b/Ryujinx/ryujinxIcon.png new file mode 100644 index 0000000000..17716fb3e4 Binary files /dev/null and b/Ryujinx/ryujinxIcon.png differ