This commit is contained in:
Даниил Заикин
2026-06-17 20:44:53 +03:00
parent 9d153773c2
commit b133e7c656
1880 changed files with 244545 additions and 0 deletions
@@ -0,0 +1,17 @@
using System.Reflection;
namespace QFSW.QC
{
/// <summary>
/// A rule for determining which entities should and shouldn't be scanned by Quantum Console for commands.
/// </summary>
public interface IQcScanRule
{
/// <summary>
/// Queries if the entity should be scanned.
/// </summary>
/// <param name="entity">The entity to query.</param>
/// <returns>The result of the rule query.</returns>
ScanRuleResult ShouldScan<T>(T entity) where T : ICustomAttributeProvider;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1eb0eea6fe2ba0c4fa9886af3e1d45e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace QFSW.QC
{
/// <summary>
/// A set of rules for determining which entities should and shouldn't be scanned by Quantum Console for commands.
/// </summary>
public class QuantumScanRuleset
{
private readonly IQcScanRule[] _scanRules;
/// <summary>
/// Creates a Quantum Scan Ruleset with a custom set of scan rules.
/// </summary>
/// <param name="scanRules">The IQcScanRules to use in this Quantum Scan Ruleset.</param>
public QuantumScanRuleset(IEnumerable<IQcScanRule> scanRules)
{
_scanRules = scanRules.ToArray();
}
/// <summary>
/// Creates a Quantum Scan Ruleset with the default injected scan rules
/// </summary>
public QuantumScanRuleset() : this(new InjectionLoader<IQcScanRule>().GetInjectedInstances())
{
}
/// <summary>
/// Queries if the entity should be scanned.
/// </summary>
/// <param name="entity">The entity to query.</param>
/// <returns>If the entity should be scanned.</returns>
public bool ShouldScan<T>(T entity) where T : ICustomAttributeProvider
{
bool shouldScan = true;
foreach (IQcScanRule scanRule in _scanRules)
{
switch (scanRule.ShouldScan(entity))
{
case ScanRuleResult.Accept:
{
break;
}
case ScanRuleResult.Reject:
{
shouldScan = false;
break;
}
case ScanRuleResult.ForceAccept:
{
return true;
}
}
}
return shouldScan;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: baf28bbc8e34dce4a8b0fb2009c296b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5845fa4f0e0444646a93b6d7c8179479
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using System.Reflection;
namespace QFSW.QC.ScanRules
{
public class AssemblyExclusionScanRule : IQcScanRule
{
public ScanRuleResult ShouldScan<T>(T entity) where T : ICustomAttributeProvider
{
if (entity is Assembly assembly)
{
string[] bannedPrefixes = new string[]
{
"System", "Unity", "Microsoft", "Mono.", "mscorlib", "NSubstitute", "JetBrains", "nunit.",
"GeNa."
#if QC_DISABLE_BUILTIN_ALL
, "QFSW.QC"
#elif QC_DISABLE_BUILTIN_EXTRA
, "QFSW.QC.Extra"
#endif
};
string[] bannedAssemblies = new string[]
{
"mcs", "AssetStoreTools",
"Facepunch.Steamworks"
};
string assemblyFullName = assembly.FullName;
foreach (string prefix in bannedPrefixes)
{
if (assemblyFullName.StartsWith(prefix))
{
return ScanRuleResult.Reject;
}
}
string assemblyShortName = assembly.GetName().Name;
foreach (string name in bannedAssemblies)
{
if (assemblyShortName == name)
{
return ScanRuleResult.Reject;
}
}
}
return ScanRuleResult.Accept;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2e69859a6299c144f9abfc102508ec8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
{
"name": "QFSW.QC.ScanRules",
"references": [
"GUID:fb24642277b1db2449da7ac148ce939d"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8dcd70c80f8cde24a8b189460e9c2a06
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,25 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using QFSW.QC.Utilities;
namespace QFSW.QC.ScanRules
{
public class QcIgnoreScanRule : IQcScanRule
{
public ScanRuleResult ShouldScan<T>(T entity) where T : ICustomAttributeProvider
{
if (entity.HasAttribute<QcIgnoreAttribute>(false))
{
return ScanRuleResult.Reject;
}
// Allow compiler generated members as this includes backing fields which may be used by the user
if (!(entity is MemberInfo) && entity.HasAttribute<CompilerGeneratedAttribute>(true))
{
return ScanRuleResult.Reject;
}
return ScanRuleResult.Accept;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8acf993d4de8094da0d60c578420f8e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,27 @@
namespace QFSW.QC
{
/// <summary>
/// The result of querying an entity with a scan rule.
/// </summary>
public enum ScanRuleResult
{
/// <summary>
/// If the entity should be accepted by the scan rule.
/// This is the lowest priority response and should be used when in doubt.
/// </summary>
Accept = 0,
/// <summary>
/// If the entity should be rejected by the scan rule.
/// This takes priority over any other <c>Accept</c> responses.
/// </summary>
Reject = 1,
/// <summary>
/// If the entity should be forcefully accepted by the scan rule.
/// This will be immediate and overrides any other <c>Reject</c> responses.
/// No further scan rules will be considered
/// </summary>
ForceAccept = 2
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1fafe1b921180174da3b1ced5f64056b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: