Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
327 changes: 0 additions & 327 deletions Knossos.NET/Models/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,6 @@ public enum ModSource
local
}

/// <summary>
/// Nebula int values, do not change
/// It is not clear what can each one of the roles do and what not
/// </summary>
public enum ModMemberRole
{
Owner = 0,
Manager = 10,
Uploader = 20,
Tester = 30
}

/*

*/

/// <summary>
/// The "mod class" variables math the json properties for the mod.json file that is located at the root of the mod folder.
/// In order to maintain compatibility with other launchers all properties saved in the mod.json file must be
Expand Down Expand Up @@ -1030,315 +1014,4 @@ public static bool IsMetaUpdate(Mod modA, Mod modB)
return null;
}
}

public class ModMember
{
public ModMemberRole role { get; set; }
public string user { get; set; } = string.Empty;
}

public class ModPackage
{
public string name { get; set; } = string.Empty; // required
public string? notes { get; set; } = string.Empty; // optional
/*
optional, default: "recommended"
A feature can be:
- "required" (always installed with the mod, in fact these are the base files of the mod),
- "recommended" (automatically selected for installation, but the user can skip them),
- "optional" (not automatically selected, but user can add them during the install process)
*/
public string? status { get; set; } // "<required|recommended|optional>"
public ModDependency[]? dependencies { get; set; } = new ModDependency[0];
public string? environment { get; set; } // optional, boolean expression like "windows && X86_64 && (sse || sse2)"
public string? folder { get; set; }
[JsonPropertyName("is_vp")]
public bool isVp { get; set; } // optional, whether Knossos should pack the files in a VP on upload, default: false
public ModFile[]? files { get; set; } = new ModFile[0];
public ModFilelist[]? filelist { get; set; } = new ModFilelist[0];
public List<ModExecutable>? executables { get; set; } = new List<ModExecutable>();// optional
[JsonPropertyName("check_notes")]
public object? checkNotes { get; set; }

/* Knet Only */
/// <summary>
/// used for pkg display in a checkbox.
/// NOT Saved in the json
/// </summary>
[JsonIgnore]
public bool isSelected { get; set; } = false;
/// <summary>
/// used for display (to enable/disabled chkbox) and to enable/disable the package in devmode
/// Saved in the json
/// </summary>
public bool isEnabled { get; set; } = true;
/// <summary>
/// Used to display checkbox tooltip
/// NOT saved in the Json
/// </summary>
[JsonIgnore]
public string tooltip { get; set; } = string.Empty;
/// <summary>
/// Used to indicate a pkg is needed during mod install checkbox selection
/// Used to change checkbox foreground color during mod install/modify display
/// </summary>
[JsonIgnore]
public bool isRequired { get; set; } = false;
[JsonIgnore]
public int buildScore { get; set; } = 0;
}

public class ModDependency
{
public string id { get; set; } = string.Empty; // required
public string? version { get; set; } // required, https://getcomposer.org/doc/01-basic-usage.md#package-versions
public List<string>? packages { get; set; } // optional, specifies which optional and recommended packages are also required

/// <summary>
/// Used to store the original dependency reference during mod.GetMissingDependencies
/// Useful to track down the original pkg this dependency belongs to
/// mod.FindPackageWithDependency()
/// Not saved in Json
/// </summary>
[JsonIgnore]
public ModDependency? originalDependency;

/// <summary>
/// Returns the best installed mod that meets this dependency by semantic version, null if none.
/// Also returns null if the ID is a FSO build.
/// </summary>
/// <returns>Mod or null</returns>
public Mod? SelectMod()
{
var mods = Knossos.GetInstalledModList(id);
Mod? validMod = null;

foreach (var mod in mods)
{

try
{
if (SemanticVersion.SastifiesDependency(version, mod.version))
{
if (validMod == null)
{
validMod = mod;
}
else
{
if (SemanticVersion.Compare(mod.version, validMod.version) > 0)
{
validMod = mod;
}
}
}
} catch (Exception ex)
{
Log.Add(Log.LogSeverity.Error, "Mod.SelectMod()", "Mod: "+mod.title + " " + ex.Message);
}
}
return validMod;
}

/// <summary>
/// Returns the best available mod on nebula that meets this dependency by semantic version, null if none.
/// Takes an optional list with all mods, if passed it will use that list intead of checking the repo.json again
/// </summary>
/// <param name="mods"></param>
/// <returns>Mod or null</returns>
public async Task<Mod?> SelectModNebula(List<Mod>? mods = null)
{
if(mods == null)
{
mods = await Nebula.GetAllModsWithID(id);
}

Mod? validMod = null;

foreach (var mod in mods)
{
if (mod.id == id && SemanticVersion.SastifiesDependency(version, mod.version))
{
if (validMod == null)
{
validMod = mod;
}
else
{
if (mod.type == ModType.engine)
{
var stabilityV = FsoBuild.GetFsoStability(validMod.stability, validMod.id);
var stabilityM = FsoBuild.GetFsoStability(mod.stability, mod.id);
//inverted stability comparison
if (stabilityV > stabilityM || stabilityV == stabilityM && SemanticVersion.Compare(mod.version, validMod.version) > 0)
{
validMod = mod;
}
}
else
{
if (SemanticVersion.Compare(mod.version, validMod.version) > 0)
{
validMod = mod;
}
}
}
}
}

return validMod;
}

/// <summary>
/// Returns the best installed build that meets this dependency by semantic version, null if none.
/// Optional: Only select builds with at least one valid executabl
/// </summary>
/// <returns>FsoBuild or null</returns>
public FsoBuild? SelectBuild(bool onlyWithValidExecutable = false)
{
FsoBuild? validBuild = null;

foreach (var build in Knossos.GetInstalledBuildsList(id, FsoStability.Stable))
{
if ((!onlyWithValidExecutable || onlyWithValidExecutable && build.IsValidBuild()) && SemanticVersion.SastifiesDependency(version, build.version))
{

if (validBuild == null)
{
validBuild = build;
}
else
{
if (SemanticVersion.Compare(build.version, validBuild.version) > 0)
{
validBuild = build;
}
}
}
}

if(validBuild == null)
{
foreach (var build in Knossos.GetInstalledBuildsList(id, FsoStability.RC))
{
if ((!onlyWithValidExecutable || onlyWithValidExecutable && build.IsValidBuild()) && SemanticVersion.SastifiesDependency(version, build.version))
{

if (validBuild == null)
{
validBuild = build;
}
else
{
if (SemanticVersion.Compare(build.version, validBuild.version) > 0)
{
validBuild = build;
}
}
}
}
}

if (validBuild == null)
{
foreach (var build in Knossos.GetInstalledBuildsList(id, FsoStability.Nightly))
{
if ((!onlyWithValidExecutable || onlyWithValidExecutable && build.IsValidBuild()) && SemanticVersion.SastifiesDependency(version, build.version))
{

if (validBuild == null)
{
validBuild = build;
}
else
{
if (SemanticVersion.Compare(build.version, validBuild.version) > 0)
{
validBuild = build;
}
}
}
}
}

if (validBuild == null)
{
foreach (var build in Knossos.GetInstalledBuildsList(id, FsoStability.Custom))
{
if ((!onlyWithValidExecutable || onlyWithValidExecutable && build.IsValidBuild()) && SemanticVersion.SastifiesDependency(version, build.version))
{

if (validBuild == null)
{
validBuild = build;
}
else
{
if (SemanticVersion.Compare(build.version, validBuild.version) > 0)
{
validBuild = build;
}
}
}
}
}

return validBuild;
}

/// <summary>
/// returns id + version
/// </summary>
public override string ToString()
{
return id + " " + version;
}
}

public class ModFile
{
public string? filename { get; set; }
public string? dest { get; set; } // "<destination path>"
public string[]? checksum { get; set; } // sha256, value
public Int64 filesize { get; set; } // Size in bytes
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string[]? urls { get; set; } // The URLs are full URLs (they contain the filename).
}

public class ModFilelist
{
public string? filename { get; set; } // file path
public string? archive { get; set; }
[JsonPropertyName("orig_name")]
public string? origName { get; set; } // name in archive
public string[]? checksum { get; set; } // sha256, value
}

public class ModExecutable
{
public string? file { get; set; } // required, path to the executable (*.exe file on Windows), relative to the mod folder
public string? label { get; set; } // <Fred FastDebug|FRED2|QTFred|QTFred FastDebug|FastDebug|null> optional, should be null for release builds and contain the name for others
public ModProperties? properties { get; set; }

[JsonIgnore]
public int score { get; set; } = 0;
}

/// <summary>
/// This is generated from the enviroment string at runtime
/// </summary>
public class ModProperties
{
public bool x64 { get; set; }
public bool sse2 { get; set; }
public bool avx { get; set; }
public bool avx2 { get; set; }

/* Knossos.NET added */
public bool arm64 { get; set; }
public bool arm32 { get; set; }
public bool riscv32 { get; set; }
public bool riscv64 { get; set; }
public bool other { get; set; }
}
}
Loading