Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
rebased
Browse files Browse the repository at this point in the history
  • Loading branch information
emmauss committed Feb 27, 2022
1 parent 729f8eb commit feff160
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 64 deletions.
12 changes: 5 additions & 7 deletions Ryujinx.Ava/Common/ApplicationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void Initialize(VirtualFileSystem virtualFileSystem,HorizonClient
}

private static bool TryFindSaveData(string titleName, ulong titleId,
BlitStruct<ApplicationControlProperty> controlHolder, SaveDataFilter filter, out ulong saveDataId)
BlitStruct<ApplicationControlProperty> controlHolder, in SaveDataFilter filter, out ulong saveDataId)
{
saveDataId = default;

Expand Down Expand Up @@ -85,8 +85,8 @@ private static bool TryFindSaveData(string titleName, ulong titleId,

Uid user = new(1, 0); // TODO: Remove Hardcoded value.

result = EnsureApplicationSaveData(_horizonClient.Fs, out _, new ApplicationId(titleId),
ref control, ref user);
result = _horizonClient.Fs.EnsureApplicationSaveData(out _, new LibHac.Ncm.ApplicationId(titleId), in control, in user);


if (result.IsFailure())
{
Expand All @@ -113,12 +113,10 @@ private static bool TryFindSaveData(string titleName, ulong titleId,
return false;
}

public static void OpenSaveDir(SaveDataFilter saveDataFilter, ulong titleId,
public static void OpenSaveDir(in SaveDataFilter saveDataFilter, ulong titleId,
BlitStruct<ApplicationControlProperty> controlData, string titleName)
{
saveDataFilter.SetProgramId(new ProgramId(titleId));

if (!TryFindSaveData(titleName, titleId, controlData, saveDataFilter, out ulong saveDataId))
if (!TryFindSaveData(titleName, titleId, controlData, in saveDataFilter, out ulong saveDataId))
{
return;
}
Expand Down
57 changes: 27 additions & 30 deletions Ryujinx.Ava/Common/ApplicationLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@ public static void LoadApplications(List<string> appDirs,
}
else
{
// Store the ControlFS in variable called controlFs
GetControlFsAndTitleId(pfs, out IFileSystem controlFs, out titleId);

ReadControlData(controlFs, controlHolder.ByteSpan);
if (IsUpdateApplied(titleId, out IFileSystem updatedControlFs))
{
// Replace the original ControlFs by the updated one.
controlFs = updatedControlFs;
}

// Get the title name, title ID, developer name and version number from the NACP
version = IsUpdateApplied(titleId, out string updateVersion) ? updateVersion : controlHolder.Value.DisplayVersion.ToString();
ReadControlData(controlFs, controlHolder.ByteSpan);

GetNameIdDeveloper(ref controlHolder.Value, out titleName, out _, out developer);
GetGameInfomation(ref controlHolder.Value, out titleName, out _, out developer, out version);

// Read the icon from the ControlFS and store it as a byte array
try
Expand Down Expand Up @@ -337,8 +339,8 @@ byte[] Read(long position, int size)
// Get the title name, title ID, developer name and version number from the NACP
version = controlHolder.Value.DisplayVersion.ToString();

GetNameIdDeveloper(ref controlHolder.Value, out titleName, out titleId,
out developer);
GetGameInfomation(ref controlHolder.Value, out titleName, out titleId,
out developer, out version);
}
else
{
Expand Down Expand Up @@ -739,15 +741,15 @@ private static string ConvertSecondsToReadableString(double seconds)
return readableString;
}

private static void GetNameIdDeveloper(ref ApplicationControlProperty controlData, out string titleName,
out string titleId, out string publisher)
private static void GetGameInfomation(ref ApplicationControlProperty controlData, out string titleName,
out string titleId, out string publisher, out string version)
{
Enum.TryParse(_desiredTitleLanguage.ToString(), out TitleLanguage desiredTitleLanguage);

if (controlData.Titles.Length > (int)desiredTitleLanguage)
if (controlData.Title.ItemsRo.Length > (int)desiredTitleLanguage)
{
titleName = controlData.Titles[(int)desiredTitleLanguage].Name.ToString();
publisher = controlData.Titles[(int)desiredTitleLanguage].Publisher.ToString();
titleName = controlData.Title[(int)desiredTitleLanguage].NameString.ToString();
publisher = controlData.Title[(int)desiredTitleLanguage].PublisherString.ToString();
}
else
{
Expand All @@ -757,23 +759,23 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat

if (string.IsNullOrWhiteSpace(titleName))
{
foreach (ApplicationControlTitle controlTitle in controlData.Titles)
foreach (ref readonly var controlTitle in controlData.Title.ItemsRo)
{
if (!((U8Span)controlTitle.Name).IsEmpty())
if (!controlTitle.NameString.IsEmpty())
{
titleName = controlTitle.Name.ToString();
titleName = controlTitle.NameString.ToString();
break;
}
}
}

if (string.IsNullOrWhiteSpace(publisher))
{
foreach (ApplicationControlTitle controlTitle in controlData.Titles)
foreach (ref readonly var controlTitle in controlData.Title.ItemsRo)
{
if (!((U8Span)controlTitle.Publisher).IsEmpty())
if (!controlTitle.PublisherString.IsEmpty())
{
publisher = controlTitle.Publisher.ToString();
publisher = controlTitle.PublisherString.ToString();
break;
}
}
Expand All @@ -783,7 +785,7 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat
{
titleId = controlData.PresenceGroupId.ToString("x16");
}
else if (controlData.SaveDataOwnerId.Value != 0)
else if (controlData.SaveDataOwnerId != 0)
{
titleId = controlData.SaveDataOwnerId.ToString();
}
Expand All @@ -795,10 +797,14 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat
{
titleId = "0000000000000000";
}

version = controlData.DisplayVersionString.ToString();
}

private static bool IsUpdateApplied(string titleId, out string version)
private static bool IsUpdateApplied(string titleId, out IFileSystem updatedControlFs)
{
updatedControlFs = null;

string updatePath = "(unknown)";

try
Expand All @@ -807,14 +813,7 @@ private static bool IsUpdateApplied(string titleId, out string version)

if (patchNca != null && controlNca != null)
{
ApplicationControlProperty controlData = new ApplicationControlProperty();
using var nacpFile = new UniqueRef<IFile>();

controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(ref nacpFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();

nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();

version = controlData.DisplayVersion.ToString();
updatedControlFs = controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);

return true;
}
Expand All @@ -829,8 +828,6 @@ private static bool IsUpdateApplied(string titleId, out string version)
Logger.Warning?.Print(LogClass.Application, $"Your key set is missing a key with the name: {exception.Name}. Errored File: {updatePath}");
}

version = "";

return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TitleUpdateModel
public bool IsNoUpdate { get; }
public ApplicationControlProperty Control { get; }
public string Path { get; }
public string Label => IsNoUpdate ? "No Update" : $"Version {Control.DisplayVersion.ToString()} - {Path}";
public string Label => IsNoUpdate ? "No Update" : $"Version {Control.DisplayVersionString.ToString()} - {Path}";

public TitleUpdateModel(ApplicationControlProperty control, string path, bool isNoUpdate = false)
{
Expand Down
65 changes: 45 additions & 20 deletions Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,21 @@ public void OpenUserSaveDirectory()

if (selection != null)
{
SaveDataFilter filter = new();
filter.SetUserId(new UserId(1, 0));
OpenSaveDirectory(filter, selection);
Task.Run(() =>
{
if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out ulong titleIdNumber))
{
ContentDialogHelper.CreateErrorDialog(_owner,
LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
return;
}
var userId = new LibHac.Fs.UserId((ulong)_owner.AccountManager.LastOpenedUser.UserId.High, (ulong)_owner.AccountManager.LastOpenedUser.UserId.Low);
var saveDataFilter = SaveDataFilter.Make(titleIdNumber, saveType: default, userId, saveDataId: default, index: default);
OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
});
}
}

Expand Down Expand Up @@ -1416,9 +1428,20 @@ public void OpenDeviceSaveDirectory()

if (selection != null)
{
SaveDataFilter filter = new();
filter.SetSaveDataType(SaveDataType.Device);
OpenSaveDirectory(filter, selection);
Task.Run(() =>
{
if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out ulong titleIdNumber))
{
ContentDialogHelper.CreateErrorDialog(_owner,
LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
return;
}
var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Device, userId: default, saveDataId: default, index: default);
OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
});
}
}

Expand All @@ -1428,24 +1451,26 @@ public void OpenBcatSaveDirectory()

if (selection != null)
{
SaveDataFilter filter = new();
filter.SetSaveDataType(SaveDataType.Bcat);
OpenSaveDirectory(filter, selection);
}
}
Task.Run(() =>
{
if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out ulong titleIdNumber))
{
ContentDialogHelper.CreateErrorDialog(_owner,
LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
private void OpenSaveDirectory(SaveDataFilter filter, ApplicationData data)
{
if (!ulong.TryParse(data.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture,
out ulong titleIdNumber))
{
ContentDialogHelper.CreateErrorDialog(_owner,
LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]);
return;
}
return;
var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Bcat, userId: default, saveDataId: default, index: default);
OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber);
});
}
}

Task.Run(() => ApplicationHelper.OpenSaveDir(filter, titleIdNumber, data.ControlHolder, data.TitleName));
private void OpenSaveDirectory(in SaveDataFilter filter, ApplicationData data, ulong titleId)
{
ApplicationHelper.OpenSaveDir(in filter, titleId, data.ControlHolder, data.TitleName);
}

private void ExtractLogo()
Expand Down
4 changes: 2 additions & 2 deletions Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
Items="{Binding TitleUpdates}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="Update" IsChecked="{Binding IsEnabled, Mode=TwoWay}">
<TextBlock Text="{Binding Label}" />
<RadioButton Padding="8, 0" GroupName="Update" IsChecked="{Binding IsEnabled, Mode=TwoWay}">
<Label Margin="0" VerticalAlignment="Center" Content="{Binding Label}" />
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
8 changes: 4 additions & 4 deletions Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ private void SortUpdates()

list.Sort((x, y) =>
{
var v = x.Control.DisplayVersion.ToString();
var u = y.Control.DisplayVersion.ToString();
var v = x.Control.DisplayVersionString.ToString();
var u = y.Control.DisplayVersionString.ToString();
if (string.IsNullOrEmpty(v))
{
Expand All @@ -220,8 +220,8 @@ private void SortUpdates()
return 1;
}
return Version.Parse(x.Control.DisplayVersion.ToString())
.CompareTo(Version.Parse(y.Control.DisplayVersion.ToString())) * -1;
return Version.Parse(x.Control.DisplayVersionString.ToString())
.CompareTo(Version.Parse(y.Control.DisplayVersionString.ToString())) * -1;
});

TitleUpdates.Clear();
Expand Down

0 comments on commit feff160

Please sign in to comment.