Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
Latest is now a separated entity, should make updating easier
Browse files Browse the repository at this point in the history
Removed redundant code
  • Loading branch information
Aragas committed Aug 1, 2017
1 parent b14878e commit 3a2055d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
3 changes: 0 additions & 3 deletions P3D-Legacy Launcher/Data/ProfileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ internal class ProfileType

private ProfileType(string name, string exe, string modFolder, string defaultLaunchArgs, Func<Version, bool> isSupportingGameJolt)
{
var t = new ProfileFolder(name, this);
IList<ProfileType> y = new ProfileType[0];

Name = name;
Exe = exe;
ModFolder = modFolder;
Expand Down
23 changes: 15 additions & 8 deletions P3D-Legacy Launcher/Data/ProfilesYaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using P3D.Legacy.Launcher.Storage.Files;
using P3D.Legacy.Launcher.YamlConverters;
using P3D.Legacy.Shared.Extensions;

using YamlDotNet.Serialization;

Expand All @@ -21,34 +20,42 @@ internal class ProfilesYaml : IYamlSettings
[YamlMember(Alias = "SelectedProfileIndex")]
public int SelectedProfileIndex { get; private set; } = 0;
[YamlMember(Alias = "ProfileList")]
public List<ProfileYaml> ProfileList { get; private set; } = new List<ProfileYaml> { ProfileYaml.Default };
public List<ProfileYaml> ProfileList { get; private set; } = new List<ProfileYaml>();

public ProfilesYaml() { }
public ProfilesYaml(int selectedProfileIndex, List<ProfileYaml> profileList) { SelectedProfileIndex = selectedProfileIndex; ProfileList = profileList; }
public ProfilesYaml(int selectedProfileIndex, List<ProfileYaml> profileList)
{
SelectedProfileIndex = selectedProfileIndex;
ProfileList = profileList;
}

public bool IsValid()
{
if (SelectedProfileIndex < 0)
SelectedProfileIndex = 0;
if (SelectedProfileIndex - 1 >= ProfileList.Count)
SelectedProfileIndex = ProfileList.Count;

var index = SelectedProfileIndex > 0 ? SelectedProfileIndex - 1 : SelectedProfileIndex; // Because of Latest

if (ProfileList == null)
return false;

if (!ProfileList.Any())
return false;

if (ProfileList.Count <= SelectedProfileIndex)
if (ProfileList.Count <= index)
return false;

if (SelectedProfileIndex < 0)
return false;

return ProfileList[SelectedProfileIndex].Name != null && ProfileList[SelectedProfileIndex].Version != null;
return ProfileList[index].Name != null && ProfileList[index].Version != null;
}
}

internal class ProfileYaml
{
public static ProfileYaml Default => new ProfileYaml(ProfileType.Game, "Latest", AsyncExtensions.RunSync(async () => await Profile.GetAvailableVersionsAsync(ProfileType.Game)).FirstOrDefault() ?? Profile.NoVersion, string.Empty);


[YamlMember(Alias = "ProfileType")]
public ProfileType ProfileType { get; private set; }

Expand Down
4 changes: 2 additions & 2 deletions P3D-Legacy Launcher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

[assembly: Guid("d2a9c01e-686f-4aea-8b8c-5ae04387f0e0")]

[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
[assembly: AssemblyVersion("1.3.5.0")]
[assembly: AssemblyFileVersion("1.3.5.0")]
18 changes: 14 additions & 4 deletions P3D-Legacy Launcher/Storage/Files/ProfilesFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using P3D.Legacy.Launcher.Data;
using P3D.Legacy.Launcher.Storage.Folders;
using P3D.Legacy.Shared.Extensions;
using P3D.Legacy.Shared.Storage.Folders;

using PCLExt.FileStorage;
Expand All @@ -21,15 +22,17 @@ internal sealed class ProfilesFile : BaseYamlSettingsFile<ProfilesYaml>, IEnumer

internal enum SelectedProfile { Current, First, Last }

private Profile Latest => new Profile(ProfileType.Game, "Latest", AsyncExtensions.RunSync(async () => await Profile.GetAvailableVersionsAsync(ProfileType.Game)).FirstOrDefault() ?? Profile.NoVersion, string.Empty);
private List<Profile> ProfileList { get; set; }

public int SelectedProfileIndex { get; set; }
public Profile CurrentProfile
{
get
{
if (ProfileList.Count <= SelectedProfileIndex)
if (ProfileList.Count <= SelectedProfileIndex) // Because of Latest
SelectedProfileIndex = ProfileList.Count - 1;
return ProfileList.Any() ? ProfileList[SelectedProfileIndex] : null;
return ProfileList.Any() ? ProfileList[SelectedProfileIndex] : null; // Because of Latest
}
}

Expand Down Expand Up @@ -179,11 +182,18 @@ public async Task ReloadAsync(SelectedProfile selectedProfile = SelectedProfile.
}
}

protected override ProfilesYaml ToYaml() => new ProfilesYaml(SelectedProfileIndex, ProfileList.Select(Profile.ToYaml).ToList());
protected override ProfilesYaml ToYaml()
{
ProfileList.Remove(Latest);
return new ProfilesYaml(SelectedProfileIndex, ProfileList.Select(Profile.ToYaml).ToList());
}

protected override void FromYaml(ProfilesYaml profile)
{
SelectedProfileIndex = profile.SelectedProfileIndex;
ProfileList = profile.ProfileList.Select(Profile.FromYaml).ToList();
ProfileList = new List<Profile> {Latest};
profile.ProfileList.RemoveAll(p => p.Name == "Latest"); // Removing old way of keeping latest profile
ProfileList.AddRange(profile.ProfileList.Select(Profile.FromYaml).ToList());
}


Expand Down

0 comments on commit 3a2055d

Please sign in to comment.