Skip to content

Commit

Permalink
Adding local changes
Browse files Browse the repository at this point in the history
+ Initial implementation for "game patch through launcher" detection
+ Cache HomePage and SettingsPage navigation
  • Loading branch information
neon-nyan committed Nov 19, 2023
1 parent 7626ce7 commit 5dfd2c5
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ internal partial class StarRailCache : ProgressBase<CacheAssetType, SRAsset>, IC
{
#region Properties
private GameTypeStarRailVersion _innerGameVersionManager { get; set; }
private string _cacheRegionalCheckName = "sprite";
private List<SRAsset> _updateAssetIndex { get; set; }
#endregion

Expand Down
1 change: 1 addition & 0 deletions CollapseLauncher/Classes/ClassesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CollapseLauncher
{
[JsonSourceGenerationOptions(IncludeFields = false, GenerationMode = JsonSourceGenerationMode.Metadata, IgnoreReadOnlyFields = true)]
[JsonSerializable(typeof(RegionResourcePluginValidate))]
[JsonSerializable(typeof(CommunityToolsProperty))]
[JsonSerializable(typeof(AppUpdateVersionProp))]
[JsonSerializable(typeof(RegionResourceProp))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ public string GameOutputLogName
}
protected UIElement ParentUIElement { get; init; }
protected GameVersion GameVersionAPI => new GameVersion(GameAPIProp.data.game.latest.version);
protected GameVersion? PluginVersionAPI
{
get
{
// Return null if the plugin is not exist
if (GameAPIProp.data?.plugins == null || GameAPIProp.data?.plugins?.Count == 0) return null;

// Get the version and convert it into GameVersion
RegionResourcePlugin plugin = GameAPIProp.data?.plugins?.FirstOrDefault();
return new GameVersion(plugin.version);
}
}

protected GameVersion? GameVersionAPIPreload
{
get
Expand Down Expand Up @@ -143,6 +156,31 @@ protected GameVersion? GameVersionInstalled
set => UpdateGameVersion(value ?? GameVersionAPI);
}

protected GameVersion? PluginVersionInstalled
{
get
{
// Return null if the plugin is not exist
if (GameAPIProp.data?.plugins == null || GameAPIProp.data?.plugins?.Count == 0) return null;

// Get the version and convert it into GameVersion
RegionResourcePlugin plugin = GameAPIProp.data?.plugins?.FirstOrDefault();

// Check if the INI has plugin_ID_version key...
string keyName = $"plugin_{plugin.plugin_id}_version";
if (GameIniVersion[_defaultIniVersionSection].ContainsKey(keyName))
{
string val = GameIniVersion[_defaultIniVersionSection][keyName].ToString();
if (string.IsNullOrEmpty(val)) return null;
return new GameVersion(val);
}

// If not, then return as null
return null;
}
set => UpdatePluginVersion(value ?? PluginVersionAPI.Value);
}

// Assign for the Game Delta-Patch properties (if any).
// If there's no Delta-Patch, then set it to null.
protected DeltaPatchProperty GameDeltaPatchProp { get => CheckDeltaPatchUpdate(GameDirPath, GamePreset.ProfileName, GameVersionAPI); }
Expand Down Expand Up @@ -227,6 +265,7 @@ public virtual List<RegionResourceVersion> GetGamePreloadZip()
return returnList;
}


public virtual DeltaPatchProperty GetDeltaPatchInfo() => null;

public virtual bool IsGameHasPreload() => GameAPIProp.data.pre_download_game != null;
Expand All @@ -239,9 +278,12 @@ public virtual bool IsGameVersionMatch()
// If not, then return false to indicate that the game isn't installed.
if (!GameVersionInstalled.HasValue) return false;

// If the game is installed and the version doesn't match, then return to false.
// But if the game version matches, then return to true.
return GameVersionInstalled.Value.IsMatch(GameVersionAPI);
// Ensure if the version of the Plugin is matching. Get the plugin state.
bool isPluginVersionMatch = IsPluginInstalled();

// If the game/plugin is installed and the version doesn't match, then return to false.
// But if the game/plugin version matches, then return to true.
return GameVersionInstalled.Value.IsMatch(GameVersionAPI) && isPluginVersionMatch;
}

public virtual bool IsGameInstalled()
Expand All @@ -259,6 +301,28 @@ public virtual bool IsGameInstalled()
return VendorTypeProp.GameName == GamePreset.InternalGameNameInConfig && execFileInfo.Exists && execFileInfo.Length > 1 << 16;
}

public virtual bool IsPluginInstalled()
{
#if !MHYPLUGINSUPPORT
// TODO: Work on integration of plugin installations on InstallManagerBase
return true;
#else
// Get the pluginVersion
GameVersion? pluginVersion = PluginVersionAPI;

if (pluginVersion != null)
{
// If the installedPluginVersion is null, the return false
GameVersion? installedPluginVersion = PluginVersionInstalled;
if (installedPluginVersion == null) return false;

// Check if the version value is matching
return pluginVersion.Value.IsMatch(installedPluginVersion.Value);
}
return true;
#endif
}

#nullable enable
public virtual string? FindGameInstallationPath(string path)
{
Expand Down Expand Up @@ -344,6 +408,23 @@ public void UpdateGameVersion(GameVersion version, bool saveValue = true)
}
}

public void UpdatePluginVersion(GameVersion version, bool saveValue = true)
{
// If the plugin is empty, ignore it
if (GameAPIProp.data?.plugins == null || GameAPIProp.data?.plugins?.Count == 0) return;

// Get the plugin property and its key name
RegionResourcePlugin plugin = GameAPIProp.data?.plugins?.FirstOrDefault();
string keyName = $"plugin_{plugin.plugin_id}_version";

// Set the value
GameIniVersion[_defaultIniVersionSection][keyName] = version.VersionString;
if (saveValue)
{
SaveGameIni(GameIniVersionPath, GameIniVersion);
}
}

private void InitializeIniProp()
{
GameConfigDirPath = Path.Combine(LauncherConfig.AppGameFolder, GamePreset.ProfileName);
Expand Down
4 changes: 3 additions & 1 deletion CollapseLauncher/Classes/Properties/InnerLauncherConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Hi3Helper;
using CollapseLauncher.Pages;
using Hi3Helper;
using Hi3Helper.Http;
using Hi3Helper.Preset;
using Hi3Helper.Shared.ClassStruct;
Expand Down Expand Up @@ -52,6 +53,7 @@ public enum AppMode
public static AppWindow m_appWindow;
public static OverlappedPresenter m_presenter;
public static MainPage m_mainPage;
public static HomePage m_homePage;
public static bool m_windowSupportCustomTitle = false;
public static Size m_actualMainFrameSize;
public static double m_appDPIScale;
Expand Down
122 changes: 104 additions & 18 deletions CollapseLauncher/Classes/RegionManagement/RegionClasses.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;

Expand All @@ -23,7 +25,7 @@ public static class RegionResourceListHelper
{
public static RegionResourceProp regionBackgroundProp = new RegionResourceProp();
public static HomeMenuPanel regionNewsProp = new HomeMenuPanel();
public static IList<T> Copy<T>(this IList<T> source)
public static List<T> Copy<T>(this List<T> source)
where T : IRegionResourceCopyable<T>
{
if (source == null) return null;
Expand All @@ -45,15 +47,17 @@ public class RegionResourceProp : IRegionResourceCopyable<RegionResourceProp>

public class RegionResourceGame : IRegionResourceCopyable<RegionResourceGame>
{
public List<RegionResourcePlugin> plugins { get; set; }
public RegionResourceLatest game { get; set; }
public RegionResourceLatest pre_download_game { get; set; }
public RegionBackgroundProp adv { get; set; }
public RegionResourceVersion sdk { get; set; }
public IList<RegionSocMedProp> banner { get; set; }
public IList<RegionSocMedProp> icon { get; set; }
public IList<RegionSocMedProp> post { get; set; }
public List<RegionSocMedProp> banner { get; set; }
public List<RegionSocMedProp> icon { get; set; }
public List<RegionSocMedProp> post { get; set; }
public RegionResourceGame Copy() => new RegionResourceGame()
{
plugins = plugins?.Copy(),
game = game?.Copy(),
pre_download_game = pre_download_game?.Copy(),
adv = adv?.Copy(),
Expand All @@ -64,10 +68,35 @@ public class RegionResourceGame : IRegionResourceCopyable<RegionResourceGame>
};
}

public class RegionResourcePlugin : IRegionResourceCopyable<RegionResourcePlugin>
{
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int plugin_id { get; set; }
public string version { get; set; }
public RegionResourceVersion package { get; set; }
public RegionResourcePlugin Copy() => new RegionResourcePlugin()
{
plugin_id = plugin_id,
version = version,
package = package?.Copy()
};
}

public class RegionResourcePluginValidate : IRegionResourceCopyable<RegionResourcePluginValidate>
{
public string path { get; set; }
public string md5 { get; set; }
public RegionResourcePluginValidate Copy() => new RegionResourcePluginValidate()
{
path = path,
md5 = md5
};
}

public class RegionResourceLatest : IRegionResourceCopyable<RegionResourceLatest>
{
public RegionResourceVersion latest { get; set; }
public IList<RegionResourceVersion> diffs { get; set; }
public List<RegionResourceVersion> diffs { get; set; }
public RegionResourceLatest Copy() => new RegionResourceLatest()
{
latest = latest?.Copy(),
Expand All @@ -78,6 +107,7 @@ public class RegionResourceLatest : IRegionResourceCopyable<RegionResourceLatest
public class RegionResourceVersion : IRegionResourceCopyable<RegionResourceVersion>
{
public string version { get; set; }
public string url { get; set; }
public string path { get; set; }
public string decompressed_path { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
Expand All @@ -95,12 +125,15 @@ public class RegionResourceVersion : IRegionResourceCopyable<RegionResourceVersi
public int? channel_id { get; set; }
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public int? sub_channel_id { get; set; }
public IList<RegionResourceVersion> voice_packs { get; set; }
public IList<RegionResourceVersion> segments { get; set; }
public List<RegionResourceVersion> voice_packs { get; set; }
public List<RegionResourceVersion> segments { get; set; }
[JsonConverter(typeof(RegionResourcePluginValidateConverter))]
public List<RegionResourcePluginValidate> validate { get; set; }
public RegionResourceVersion Copy() => new RegionResourceVersion()
{
version = version,
path = path,
url = url,
decompressed_path = decompressed_path,
size = size,
package_size = package_size,
Expand All @@ -110,14 +143,67 @@ public class RegionResourceVersion : IRegionResourceCopyable<RegionResourceVersi
is_recommended_update = is_recommended_update,
entry = entry,
voice_packs = voice_packs?.Copy(),
segments = segments?.Copy()
segments = segments?.Copy(),
validate = validate?.Copy()
};
}

public class RegionResourcePluginValidateConverter : JsonConverter<List<RegionResourcePluginValidate>>
{
public override bool CanConvert(Type type)
{
return true;
}

public override List<RegionResourcePluginValidate> Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
string valueString = EmptiedBackslash(reader.ValueSpan);
List<RegionResourcePluginValidate> returnList = valueString.Deserialize<List<RegionResourcePluginValidate>>(InternalAppJSONContext.Default);

return returnList;
}

private unsafe string EmptiedBackslash(ReadOnlySpan<byte> span)
{
Span<byte> buffer = new byte[span.Length];
int indexIn = 0;
int indexOut = 0;
while (indexIn < span.Length)
{
if (span[indexIn] == '\\')
{
++indexIn;
continue;
}

buffer[indexOut] = span[indexIn];
++indexIn;
++indexOut;
}

fixed (byte* bufferPtr = buffer)
{
return Encoding.UTF8.GetString(bufferPtr, indexOut);
}
}

public override void Write(
Utf8JsonWriter writer,
List<RegionResourcePluginValidate> baseType,
JsonSerializerOptions options)
{

throw new JsonException($"Serializing is not supported!");
}
}

public class HomeMenuPanel : IRegionResourceCopyable<HomeMenuPanel>
{
public IList<MenuPanelProp> sideMenuPanel { get; set; }
public IList<MenuPanelProp> imageCarouselPanel { get; set; }
public List<MenuPanelProp> sideMenuPanel { get; set; }
public List<MenuPanelProp> imageCarouselPanel { get; set; }
public PostCarouselTypes articlePanel { get; set; }
public RegionBackgroundProp eventPanel { get; set; }
public HomeMenuPanel Copy() => new HomeMenuPanel()
Expand All @@ -131,9 +217,9 @@ public class HomeMenuPanel : IRegionResourceCopyable<HomeMenuPanel>

public class PostCarouselTypes : IRegionResourceCopyable<PostCarouselTypes>
{
public IList<RegionSocMedProp> Events { get; set; } = new List<RegionSocMedProp>();
public IList<RegionSocMedProp> Notices { get; set; } = new List<RegionSocMedProp>();
public IList<RegionSocMedProp> Info { get; set; } = new List<RegionSocMedProp>();
public List<RegionSocMedProp> Events { get; set; } = new List<RegionSocMedProp>();
public List<RegionSocMedProp> Notices { get; set; } = new List<RegionSocMedProp>();
public List<RegionSocMedProp> Info { get; set; } = new List<RegionSocMedProp>();
public PostCarouselTypes Copy() => new PostCarouselTypes()
{
Events = Events?.Copy(),
Expand Down Expand Up @@ -171,7 +257,7 @@ public struct MenuPanelProp : IRegionResourceCopyable<MenuPanelProp>
public string Description { get; set; }
public bool IsDescriptionExist => !string.IsNullOrEmpty(Description);
public bool IsQRDescriptionExist => !string.IsNullOrEmpty(QR_Description);
public IList<LinkProp> Links { get; set; }
public List<LinkProp> Links { get; set; }
public bool IsLinksExist => Links?.Any() == true;
public bool ShowLinks => IsLinksExist && Links.Count > 1;
public bool ShowDescription => IsDescriptionExist && !ShowLinks;
Expand Down Expand Up @@ -211,8 +297,8 @@ public struct RegionSocMedProp : IRegionResourceCopyable<RegionSocMedProp>
private string _url;
private string _icon_link;
private string _tittle;
private IList<LinkProp> _links;
private IList<LinkProp> _other_links;
private List<LinkProp> _links;
private List<LinkProp> _other_links;

public string icon_id { get; set; }
public string icon_link
Expand All @@ -239,7 +325,7 @@ public string tittle
public string show_time { get; set; }
public PostCarouselType type { get; set; }

public IList<LinkProp> links
public List<LinkProp> links
{
get => _links;
set
Expand All @@ -252,7 +338,7 @@ public IList<LinkProp> links
}
}

public IList<LinkProp> other_links
public List<LinkProp> other_links
{
get => _other_links;
set
Expand Down
Loading

0 comments on commit 5dfd2c5

Please sign in to comment.