Add ability to designate favourite games #2

Also removed default theme
This commit is contained in:
Xpl0itR 2019-09-18 16:35:17 +01:00 committed by unknown
commit 7348d0cdc5
No known key found for this signature in database
GPG key ID: 91798184109676AD
4 changed files with 60 additions and 4091 deletions

View file

@ -84,9 +84,6 @@
<None Update="Config.json"> <None Update="Config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<None Update="Theme.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="RPsupported.dat"> <None Update="RPsupported.dat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

File diff suppressed because it is too large Load diff

View file

@ -34,6 +34,7 @@ namespace Ryujinx.UI
public struct ApplicationData public struct ApplicationData
{ {
public bool Fav;
public byte[] Icon; public byte[] Icon;
public string TitleName; public string TitleName;
public string TitleId; public string TitleId;
@ -322,17 +323,18 @@ namespace Ryujinx.UI
} }
} }
string[] playedData = GetPlayedData(titleId, "00000000000000000000000000000001"); string[] userData = GetUserData(titleId, "00000000000000000000000000000001");
ApplicationData data = new ApplicationData() ApplicationData data = new ApplicationData()
{ {
Fav = bool.Parse(userData[2]),
Icon = applicationIcon, Icon = applicationIcon,
TitleName = titleName, TitleName = titleName,
TitleId = titleId, TitleId = titleId,
Developer = developer, Developer = developer,
Version = version, Version = version,
TimePlayed = playedData[0], TimePlayed = userData[0],
LastPlayed = playedData[1], LastPlayed = userData[1],
FileExt = Path.GetExtension(applicationPath).ToUpper().Remove(0 ,1), FileExt = Path.GetExtension(applicationPath).ToUpper().Remove(0 ,1),
FileSize = (filesize < 1) ? (filesize * 1024).ToString("0.##") + "MB" : filesize.ToString("0.##") + "GB", FileSize = (filesize < 1) ? (filesize * 1024).ToString("0.##") + "MB" : filesize.ToString("0.##") + "GB",
Path = applicationPath, Path = applicationPath,
@ -386,13 +388,14 @@ namespace Ryujinx.UI
return controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None); return controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
} }
private static string[] GetPlayedData(string TitleId, string UserId) private static string[] GetUserData(string TitleId, string UserId)
{ {
try try
{ {
string[] playedData = new string[2]; string[] userData = new string[3];
string savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "nand", "user", "save", "0000000000000000", UserId, TitleId); string savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "GUI", UserId, TitleId);
//Time Played
if (File.Exists(Path.Combine(savePath, "TimePlayed.dat")) == false) if (File.Exists(Path.Combine(savePath, "TimePlayed.dat")) == false)
{ {
Directory.CreateDirectory(savePath); Directory.CreateDirectory(savePath);
@ -401,6 +404,7 @@ namespace Ryujinx.UI
file.Write(Encoding.ASCII.GetBytes("0")); file.Write(Encoding.ASCII.GetBytes("0"));
} }
} }
using (FileStream fs = File.OpenRead(Path.Combine(savePath, "TimePlayed.dat"))) using (FileStream fs = File.OpenRead(Path.Combine(savePath, "TimePlayed.dat")))
{ {
using (StreamReader sr = new StreamReader(fs)) using (StreamReader sr = new StreamReader(fs))
@ -409,23 +413,24 @@ namespace Ryujinx.UI
if (timePlayed < SecondsPerMinute) if (timePlayed < SecondsPerMinute)
{ {
playedData[0] = $"{timePlayed}s"; userData[0] = $"{timePlayed}s";
} }
else if (timePlayed < SecondsPerHour) else if (timePlayed < SecondsPerHour)
{ {
playedData[0] = $"{Math.Round(timePlayed / SecondsPerMinute, 2, MidpointRounding.AwayFromZero)} mins"; userData[0] = $"{Math.Round(timePlayed / SecondsPerMinute, 2, MidpointRounding.AwayFromZero)} mins";
} }
else if (timePlayed < SecondsPerDay) else if (timePlayed < SecondsPerDay)
{ {
playedData[0] = $"{Math.Round(timePlayed / SecondsPerHour , 2, MidpointRounding.AwayFromZero)} hrs"; userData[0] = $"{Math.Round(timePlayed / SecondsPerHour , 2, MidpointRounding.AwayFromZero)} hrs";
} }
else else
{ {
playedData[0] = $"{Math.Round(timePlayed / SecondsPerDay , 2, MidpointRounding.AwayFromZero)} days"; userData[0] = $"{Math.Round(timePlayed / SecondsPerDay , 2, MidpointRounding.AwayFromZero)} days";
} }
} }
} }
//Last Played
if (File.Exists(Path.Combine(savePath, "LastPlayed.dat")) == false) if (File.Exists(Path.Combine(savePath, "LastPlayed.dat")) == false)
{ {
Directory.CreateDirectory(savePath); Directory.CreateDirectory(savePath);
@ -439,15 +444,25 @@ namespace Ryujinx.UI
{ {
using (StreamReader sr = new StreamReader(fs)) using (StreamReader sr = new StreamReader(fs))
{ {
playedData[1] = sr.ReadLine(); userData[1] = sr.ReadLine();
} }
} }
return playedData; //Fav Games
if (File.Exists(Path.Combine(savePath, "Fav.dat")))
{
userData[2] = "true";
}
else
{
userData[2] = "false";
}
return userData;
} }
catch catch
{ {
return new string[] { "Unknown", "Unknown" }; return new string[] { "Unknown", "Unknown", "false" };
} }
} }

View file

@ -181,10 +181,6 @@ namespace Ryujinx.UI
Logger.PrintWarning(LogClass.Application, $"The \"custom_theme_path\" section in \"Config.json\" contains an invalid path: \"{SwitchSettings.SwitchConfig.CustomThemePath}\""); Logger.PrintWarning(LogClass.Application, $"The \"custom_theme_path\" section in \"Config.json\" contains an invalid path: \"{SwitchSettings.SwitchConfig.CustomThemePath}\"");
} }
} }
else
{
cssProvider.LoadFromPath(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Theme.css"));
}
StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, 800); StyleContext.AddProviderForScreen(Gdk.Screen.Default, cssProvider, 800);
} }
@ -199,7 +195,7 @@ namespace Ryujinx.UI
CellRendererToggle favToggle = new CellRendererToggle(); CellRendererToggle favToggle = new CellRendererToggle();
favToggle.Toggled += FavToggle_Toggled; favToggle.Toggled += FavToggle_Toggled;
if (SwitchSettings.SwitchConfig.GuiColumns[0]) { _gameTable.AppendColumn("Fav", favToggle, "active", 0); } if (SwitchSettings.SwitchConfig.GuiColumns[0]) { _gameTable.AppendColumn("Fav", favToggle, "active", 0); }
if (SwitchSettings.SwitchConfig.GuiColumns[1]) { _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1); } if (SwitchSettings.SwitchConfig.GuiColumns[1]) { _gameTable.AppendColumn("Icon", new CellRendererPixbuf(), "pixbuf", 1); }
if (SwitchSettings.SwitchConfig.GuiColumns[2]) { _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2); } if (SwitchSettings.SwitchConfig.GuiColumns[2]) { _gameTable.AppendColumn("Application", new CellRendererText(), "text", 2); }
if (SwitchSettings.SwitchConfig.GuiColumns[3]) { _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3); } if (SwitchSettings.SwitchConfig.GuiColumns[3]) { _gameTable.AppendColumn("Developer", new CellRendererText(), "text", 3); }
@ -234,20 +230,6 @@ namespace Ryujinx.UI
if (SwitchSettings.SwitchConfig.GuiColumns[9]) { pathColumn.SortColumnId = 9; } if (SwitchSettings.SwitchConfig.GuiColumns[9]) { pathColumn.SortColumnId = 9; }
} }
private void FavToggle_Toggled(object o, ToggledArgs args)
{
_tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
if ((bool)_tableStore.GetValue(treeIter, 0))
{
_tableStore.SetValue(treeIter, 0, false);
}
else
{
_tableStore.SetValue(treeIter, 0, true);
}
}
public static void UpdateGameTable() public static void UpdateGameTable()
{ {
_tableStore.Clear(); _tableStore.Clear();
@ -255,7 +237,7 @@ namespace Ryujinx.UI
foreach (ApplicationLibrary.ApplicationData AppData in ApplicationLibrary.ApplicationLibraryData) foreach (ApplicationLibrary.ApplicationData AppData in ApplicationLibrary.ApplicationLibraryData)
{ {
_tableStore.AppendValues(false, new Gdk.Pixbuf(AppData.Icon, 75, 75), $"{AppData.TitleName}\n{AppData.TitleId.ToUpper()}", AppData.Developer, AppData.Version, AppData.TimePlayed, AppData.LastPlayed, AppData.FileExt, AppData.FileSize, AppData.Path); _tableStore.AppendValues(AppData.Fav, new Gdk.Pixbuf(AppData.Icon, 75, 75), $"{AppData.TitleName}\n{AppData.TitleId.ToUpper()}", AppData.Developer, AppData.Version, AppData.TimePlayed, AppData.LastPlayed, AppData.FileExt, AppData.FileSize, AppData.Path);
_tableStore.SetSortFunc(5, TimePlayedSort); _tableStore.SetSortFunc(5, TimePlayedSort);
_tableStore.SetSortFunc(6, LastPlayedSort); _tableStore.SetSortFunc(6, LastPlayedSort);
@ -371,7 +353,7 @@ namespace Ryujinx.UI
try try
{ {
string savePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "nand", "user", "save", "0000000000000000", _userId, _device.System.TitleID); string savePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "GUI", _userId, _device.System.TitleID);
if (File.Exists(System.IO.Path.Combine(savePath, "TimePlayed.dat")) == false) if (File.Exists(System.IO.Path.Combine(savePath, "TimePlayed.dat")) == false)
{ {
@ -424,7 +406,7 @@ namespace Ryujinx.UI
{ {
try try
{ {
string savePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "nand", "user", "save", "0000000000000000", _userId, _device.System.TitleID); string savePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "GUI", _userId, _device.System.TitleID);
double currentPlayTime = 0; double currentPlayTime = 0;
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(savePath, "LastPlayed.dat"))) using (FileStream stream = File.OpenRead(System.IO.Path.Combine(savePath, "LastPlayed.dat")))
@ -486,6 +468,31 @@ namespace Ryujinx.UI
} }
//Events //Events
private void FavToggle_Toggled(object o, ToggledArgs args)
{
_tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
string savePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RyuFS", "GUI", _userId, _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1]);
if ((bool)_tableStore.GetValue(treeIter, 0))
{
_tableStore.SetValue(treeIter, 0, false);
if (File.Exists(System.IO.Path.Combine(savePath, "Fav.dat")))
{
File.Delete(System.IO.Path.Combine(savePath, "Fav.dat"));
}
}
else
{
_tableStore.SetValue(treeIter, 0, true);
if (!File.Exists(System.IO.Path.Combine(savePath, "Fav.dat")))
{
using (File.Create(System.IO.Path.Combine(savePath, "Fav.dat"))) { };
}
}
}
private void Row_Activated(object o, RowActivatedArgs args) private void Row_Activated(object o, RowActivatedArgs args)
{ {
_tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path.ToString())); _tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path.ToString()));
@ -692,6 +699,9 @@ namespace Ryujinx.UI
string aValue = model.GetValue(a, 5).ToString(); string aValue = model.GetValue(a, 5).ToString();
string bValue = model.GetValue(b, 5).ToString(); string bValue = model.GetValue(b, 5).ToString();
if (aValue == "Unknown") { aValue = "0s"; }
if (bValue == "Unknown") { bValue = "0s"; }
if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "mins") if (aValue.Length > 4 && aValue.Substring(aValue.Length - 4) == "mins")
{ {
aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 60).ToString(); aValue = (float.Parse(aValue.Substring(0, aValue.Length - 5)) * 60).ToString();